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.
master
jpark37 2021-01-14 19:09:08 -08:00 committed by Jim
parent 71d5451670
commit 2e82a6c7e8
2 changed files with 41 additions and 1 deletions

View File

@ -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<winrt_capture *>(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();

View File

@ -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()