From 930dde396de168160e0ad5f8c0876bcb2bf06dea Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Fri, 22 Oct 2021 21:16:28 +0900 Subject: [PATCH] fix: black window on screen capture when content protection is enabled (#31550) Co-authored-by: Micha Hanselmann --- shell/browser/native_window_views.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 8e9228e7e21a3..64ce33b54b0d4 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -1108,8 +1108,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 }