From 2e82a6c7e8e8311f2b555c844a773e7fc928fe3d Mon Sep 17 00:00:00 2001 From: jpark37 Date: Thu, 14 Jan 2021 19:09:08 -0800 Subject: [PATCH] libobs-winrt: Disable WGC border on insider SDK Functionality is coming in a future Windows update to disable the yellow border when using WGC. Add code now to opt in. Will require SDK upgrade later for OBS build. winrt::apartment_type::multi_threaded is necessary to dodge assert for calling get() on RequestAccessAsync result. Don't think I will ever fully understand COM apartments. --- libobs-winrt/winrt-capture.cpp | 40 +++++++++++++++++++++++++++++++++ libobs-winrt/winrt-dispatch.cpp | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/libobs-winrt/winrt-capture.cpp b/libobs-winrt/winrt-capture.cpp index d2e7c5fa4..3cc14e7b1 100644 --- a/libobs-winrt/winrt-capture.cpp +++ b/libobs-winrt/winrt-capture.cpp @@ -240,6 +240,24 @@ static void winrt_capture_device_loss_release(void *data) capture->item = nullptr; } +#ifdef NTDDI_WIN10_FE +static bool winrt_capture_border_toggle_supported() +try { + return winrt::Windows::Foundation::Metadata::ApiInformation:: + IsPropertyPresent( + L"Windows.Graphics.Capture.GraphicsCaptureSession", + L"IsBorderRequired"); +} catch (const winrt::hresult_error &err) { + blog(LOG_ERROR, "winrt_capture_border_toggle_supported (0x%08X): %ls", + err.to_abi(), err.message().c_str()); + return false; +} catch (...) { + blog(LOG_ERROR, "winrt_capture_border_toggle_supported (0x%08X)", + winrt::to_hresult()); + return false; +} +#endif + static void winrt_capture_device_loss_rebuild(void *device_void, void *data) { winrt_capture *capture = static_cast(data); @@ -286,6 +304,17 @@ static void winrt_capture_device_loss_rebuild(void *device_void, void *data) const winrt::Windows::Graphics::Capture::GraphicsCaptureSession session = frame_pool.CreateCaptureSession(item); +#ifdef NTDDI_WIN10_FE + if (winrt_capture_border_toggle_supported()) { + winrt::Windows::Graphics::Capture::GraphicsCaptureAccess:: + RequestAccessAsync( + winrt::Windows::Graphics::Capture:: + GraphicsCaptureAccessKind::Borderless) + .get(); + session.IsBorderRequired(false); + } +#endif + if (winrt_capture_cursor_toggle_supported()) session.IsCursorCaptureEnabled(capture->capture_cursor && capture->cursor_visible); @@ -369,6 +398,17 @@ try { const winrt::Windows::Graphics::Capture::GraphicsCaptureSession session = frame_pool.CreateCaptureSession(item); +#ifdef NTDDI_WIN10_FE + if (winrt_capture_border_toggle_supported()) { + winrt::Windows::Graphics::Capture::GraphicsCaptureAccess:: + RequestAccessAsync( + winrt::Windows::Graphics::Capture:: + GraphicsCaptureAccessKind::Borderless) + .get(); + session.IsBorderRequired(false); + } +#endif + /* disable cursor capture if possible since ours performs better */ const BOOL cursor_toggle_supported = winrt_capture_cursor_toggle_supported(); diff --git a/libobs-winrt/winrt-dispatch.cpp b/libobs-winrt/winrt-dispatch.cpp index 02b7a9fa0..5f5e59a55 100644 --- a/libobs-winrt/winrt-dispatch.cpp +++ b/libobs-winrt/winrt-dispatch.cpp @@ -1,6 +1,6 @@ extern "C" EXPORT void winrt_initialize() { - winrt::init_apartment(winrt::apartment_type::single_threaded); + winrt::init_apartment(winrt::apartment_type::multi_threaded); } extern "C" EXPORT void winrt_uninitialize()