Bläddra i källkod

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.
jpark37 4 år sedan
förälder
incheckning
2e82a6c7e8
2 ändrade filer med 41 tillägg och 1 borttagningar
  1. 40 0
      libobs-winrt/winrt-capture.cpp
  2. 1 1
      libobs-winrt/winrt-dispatch.cpp

+ 40 - 0
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<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();

+ 1 - 1
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()