소스 검색

libobs-winrt: Use native cursor draw for WGC

We were performing a custom cursor draw for WGC, which we attempted
because we thought we could bring back hardware cursor responsiveness,
but MS says that it won't. Since the custom draw was bugged to cause
black screens anyway, just use the native cursor draw for now.
jpark37 5 년 전
부모
커밋
d4a607a3c2
1개의 변경된 파일10개의 추가작업 그리고 60개의 파일을 삭제
  1. 10 60
      libobs-winrt/winrt-capture.cpp

+ 10 - 60
libobs-winrt/winrt-capture.cpp

@@ -137,58 +137,6 @@ struct winrt_capture {
 	BOOL active;
 	struct winrt_capture *next;
 
-	void draw_cursor()
-	{
-		CURSORINFO ci{};
-		ci.cbSize = sizeof(CURSORINFO);
-		if (!GetCursorInfo(&ci))
-			return;
-
-		if (!(ci.flags & CURSOR_SHOWING))
-			return;
-
-		HICON icon = CopyIcon(ci.hCursor);
-		if (!icon)
-			return;
-
-		ICONINFO ii;
-		if (GetIconInfo(icon, &ii)) {
-			POINT win_pos{};
-			if (window) {
-				if (client_area) {
-					ClientToScreen(window, &win_pos);
-				} else {
-					RECT window_rect;
-					if (DwmGetWindowAttribute(
-						    window,
-						    DWMWA_EXTENDED_FRAME_BOUNDS,
-						    &window_rect,
-						    sizeof(window_rect)) ==
-					    S_OK) {
-						win_pos.x = window_rect.left;
-						win_pos.y = window_rect.top;
-					}
-				}
-			}
-
-			POINT pos;
-			pos.x = ci.ptScreenPos.x - (int)ii.xHotspot - win_pos.x;
-			pos.y = ci.ptScreenPos.y - (int)ii.yHotspot - win_pos.y;
-
-			HDC hdc = (HDC)gs_texture_get_dc(texture);
-
-			DrawIconEx(hdc, pos.x, pos.y, icon, 0, 0, 0, NULL,
-				   DI_NORMAL);
-
-			gs_texture_release_dc(texture);
-
-			DeleteObject(ii.hbmColor);
-			DeleteObject(ii.hbmMask);
-		}
-
-		DestroyIcon(icon);
-	}
-
 	void on_closed(
 		winrt::Windows::Graphics::Capture::GraphicsCaptureItem const &,
 		winrt::Windows::Foundation::IInspectable const &)
@@ -256,10 +204,6 @@ struct winrt_capture {
 					frame_surface.get());
 			}
 
-			if (capture_cursor && cursor_visible) {
-				draw_cursor();
-			}
-
 			texture_written = true;
 		}
 
@@ -342,9 +286,9 @@ static void winrt_capture_device_loss_rebuild(void *device_void, void *data)
 	const winrt::Windows::Graphics::Capture::GraphicsCaptureSession session =
 		frame_pool.CreateCaptureSession(item);
 
-	/* disable cursor capture if possible since ours performs better */
 	if (winrt_capture_cursor_toggle_supported())
-		session.IsCursorCaptureEnabled(false);
+		session.IsCursorCaptureEnabled(capture->capture_cursor &&
+					       capture->cursor_visible);
 
 	capture->item = item;
 	capture->device = device;
@@ -425,12 +369,13 @@ try {
 	const BOOL cursor_toggle_supported =
 		winrt_capture_cursor_toggle_supported();
 	if (cursor_toggle_supported)
-		session.IsCursorCaptureEnabled(false);
+		session.IsCursorCaptureEnabled(cursor);
 
 	struct winrt_capture *capture = new winrt_capture{};
 	capture->window = window;
 	capture->client_area = client_area;
 	capture->capture_cursor = cursor && cursor_toggle_supported;
+	capture->cursor_visible = cursor;
 	capture->item = item;
 	capture->device = device;
 	d3d_device->GetImmediateContext(&capture->context);
@@ -523,7 +468,12 @@ extern "C" EXPORT BOOL winrt_capture_active(const struct winrt_capture *capture)
 extern "C" EXPORT void winrt_capture_show_cursor(struct winrt_capture *capture,
 						 BOOL visible)
 {
-	capture->cursor_visible = visible;
+	if (capture->capture_cursor) {
+		if (capture->cursor_visible != visible) {
+			capture->session.IsCursorCaptureEnabled(visible);
+			capture->cursor_visible = visible;
+		}
+	}
 }
 
 extern "C" EXPORT void winrt_capture_render(struct winrt_capture *capture,