浏览代码

win-capture: Determine D3D11 usage once per run

The device type (OBS renderer) cannot change without restarting OBS, so
we should only have to check if we're using D3D11 once instead of
checking every time a new display capture or window capture source is
created.
Ryan Foster 4 年之前
父节点
当前提交
2f3c0911fa

+ 3 - 5
plugins/win-capture/duplicator-monitor-capture.c

@@ -306,6 +306,8 @@ static bool load_winrt_imports(struct winrt_exports *exports, void *module,
 	return success;
 }
 
+extern bool graphics_uses_d3d11;
+
 static void *duplicator_capture_create(obs_data_t *settings,
 				       obs_source_t *source)
 {
@@ -316,11 +318,7 @@ static void *duplicator_capture_create(obs_data_t *settings,
 
 	pthread_mutex_init(&capture->update_mutex, NULL);
 
-	obs_enter_graphics();
-	const bool uses_d3d11 = gs_get_device_type() == GS_DEVICE_DIRECT3D_11;
-	obs_leave_graphics();
-
-	if (uses_d3d11) {
+	if (graphics_uses_d3d11) {
 		static const char *const module = "libobs-winrt";
 		capture->winrt_module = os_dlopen(module);
 		if (capture->winrt_module &&

+ 5 - 3
plugins/win-capture/plugin-main.c

@@ -68,6 +68,8 @@ void wait_for_hook_initialization(void)
 
 void init_hook_files(void);
 
+bool graphics_uses_d3d11 = false;
+
 bool obs_module_load(void)
 {
 	struct win_version_info ver;
@@ -85,14 +87,14 @@ bool obs_module_load(void)
 	win8_or_above = ver.major > 6 || (ver.major == 6 && ver.minor >= 2);
 
 	obs_enter_graphics();
+	graphics_uses_d3d11 = gs_get_device_type() == GS_DEVICE_DIRECT3D_11;
+	obs_leave_graphics();
 
-	if (win8_or_above && gs_get_device_type() == GS_DEVICE_DIRECT3D_11)
+	if (win8_or_above && graphics_uses_d3d11)
 		obs_register_source(&duplicator_capture_info);
 	else
 		obs_register_source(&monitor_capture_info);
 
-	obs_leave_graphics();
-
 	obs_register_source(&window_capture_info);
 
 	char *config_path = obs_module_config_path(NULL);

+ 3 - 5
plugins/win-capture/window-capture.c

@@ -236,6 +236,8 @@ static bool load_winrt_imports(struct winrt_exports *exports, void *module,
 	return success;
 }
 
+extern bool graphics_uses_d3d11;
+
 static void *wc_create(obs_data_t *settings, obs_source_t *source)
 {
 	struct window_capture *wc = bzalloc(sizeof(struct window_capture));
@@ -243,11 +245,7 @@ static void *wc_create(obs_data_t *settings, obs_source_t *source)
 
 	pthread_mutex_init(&wc->update_mutex, NULL);
 
-	obs_enter_graphics();
-	const bool uses_d3d11 = gs_get_device_type() == GS_DEVICE_DIRECT3D_11;
-	obs_leave_graphics();
-
-	if (uses_d3d11) {
+	if (graphics_uses_d3d11) {
 		static const char *const module = "libobs-winrt";
 		wc->winrt_module = os_dlopen(module);
 		if (wc->winrt_module &&