fix: black window on screen capture when content protection is enabled (#31385)

Co-authored-by: Micha Hanselmann <mhanselmann@microsoft.com>
This commit is contained in:
trop[bot]
2021-10-12 09:09:10 +09:00
committed by GitHub
parent b5c81db591
commit 55e6ce81e0

View File

@@ -1125,8 +1125,17 @@ void NativeWindowViews::SetIgnoreMouseEvents(bool ignore, bool forward) {
void NativeWindowViews::SetContentProtection(bool enable) {
#if defined(OS_WIN)
HWND hwnd = GetAcceleratedWidget();
if (!layered_) {
// Workaround to prevent black window on screen capture after hiding and
// showing the BrowserWindow.
LONG ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE);
ex_style |= WS_EX_LAYERED;
::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style);
layered_ = true;
}
DWORD affinity = enable ? WDA_EXCLUDEFROMCAPTURE : WDA_NONE;
::SetWindowDisplayAffinity(GetAcceleratedWidget(), affinity);
::SetWindowDisplayAffinity(hwnd, affinity);
#endif
}