feat: support exclude from capture on Windows (#24274)

* feat: support exclude from capture on Windows

Check for WDA_EXCLUDEFROMCAPTURE support, and fallback to WDA_MONITOR. Windows versions that support exclude from capture will exclude the window entirely when `setContentProtection` is enabled similar to how Mac behaves. Fall back to `WDA_MONITOR` for windows verisions that do not support.

This flag is mentioned at the very end of a Microsoft blog post here: https://blogs.windows.com/windowsdeveloper/2019/09/16/new-ways-to-do-screen-capture/
Use WDA_EXCLUDEFROMCAPTURE for content protection on windows

Starting with Windows 10, version 2004 this will exclude a window similar to the expected behavior on mac. It is safe to use WDA_EXCLUDEFROMCAPTURE on older Windows versions, as it will still behave as if WDA_MONITOR is applied.
https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/issues/64#issuecomment-697074762

See the docs here: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowdisplayaffinity

* docs: update setContentProtection docs

Update `setContentProtection` docs with `WDA_EXCLUDEFROMCAPTURE` info. This is to support screen capture fully excluding a particular window instead of showing it as a black screen.
This commit is contained in:
Ben Russert 2020-10-16 05:02:49 -06:00 committed by GitHub
parent 55fdc1795c
commit bf68405a2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View file

@ -1734,7 +1734,9 @@ events.
Prevents the window contents from being captured by other apps. Prevents the window contents from being captured by other apps.
On macOS it sets the NSWindow's sharingType to NSWindowSharingNone. On macOS it sets the NSWindow's sharingType to NSWindowSharingNone.
On Windows it calls SetWindowDisplayAffinity with `WDA_MONITOR`. On Windows it calls SetWindowDisplayAffinity with `WDA_EXCLUDEFROMCAPTURE`.
For Windows 10 version 2004 and up the window will be removed from capture entirely,
older Windows versions behave as if `WDA_MONITOR` is applied capturing a black window.
#### `win.setFocusable(focusable)` _macOS_ _Windows_ #### `win.setFocusable(focusable)` _macOS_ _Windows_

View file

@ -1003,7 +1003,7 @@ void NativeWindowViews::SetIgnoreMouseEvents(bool ignore, bool forward) {
void NativeWindowViews::SetContentProtection(bool enable) { void NativeWindowViews::SetContentProtection(bool enable) {
#if defined(OS_WIN) #if defined(OS_WIN)
DWORD affinity = enable ? WDA_MONITOR : WDA_NONE; DWORD affinity = enable ? WDA_EXCLUDEFROMCAPTURE : WDA_NONE;
::SetWindowDisplayAffinity(GetAcceleratedWidget(), affinity); ::SetWindowDisplayAffinity(GetAcceleratedWidget(), affinity);
#endif #endif
} }