Skip to content

Commit a9e447d

Browse files
tbeloquihavardgraff
authored andcommitted
vulkan: fixed main thread checker warning
CreateMacOSSurface should only be called from the main thread.
1 parent 241072e commit a9e447d

File tree

1 file changed

+70
-8
lines changed

1 file changed

+70
-8
lines changed

subprojects/gst-plugins-bad/gst-libs/gst/vulkan/cocoa/gstvkwindow_cocoa.m

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,20 +218,84 @@ static void gst_vulkan_window_cocoa_set_window_handle (GstVulkanWindow * window,
218218
return TRUE;
219219
}
220220

221-
static VkSurfaceKHR
222-
gst_vulkan_window_cocoa_get_surface (GstVulkanWindow * window, GError ** error)
221+
typedef struct
222+
{
223+
VkResult result;
224+
VkSurfaceKHR surface;
225+
VkMacOSSurfaceCreateInfoMVK * info;
226+
GstVulkanWindow * window;
227+
228+
GMutex mutex;
229+
GCond cond;
230+
gboolean called;
231+
} GstVulkanCococa_CreateMacOSSurfaceCtx;
232+
233+
static void
234+
_gst_vulkan_cocoa_wait_for_createmacossurface (GstVulkanCococa_CreateMacOSSurfaceCtx * ctx)
235+
{
236+
g_mutex_lock (&ctx->mutex);
237+
while (!ctx->called)
238+
g_cond_wait(&ctx->cond, &ctx->mutex);
239+
g_mutex_unlock (&ctx->mutex);
240+
241+
g_mutex_clear (&ctx->mutex);
242+
g_cond_clear (&ctx->cond);
243+
}
244+
245+
static void
246+
_gst_vulkan_cocoa_create_macos_surface_on_main_thread (gpointer data)
223247
{
248+
GstVulkanCococa_CreateMacOSSurfaceCtx * ctx = data;
249+
GstVulkanWindow *window = ctx->window;
224250
GstVulkanWindowCocoa *window_cocoa = GST_VULKAN_WINDOW_COCOA (window);
225-
GstVulkanWindowCocoaPrivate *priv = GET_PRIV (window_cocoa);
226-
VkMacOSSurfaceCreateInfoMVK info = { 0, };
227-
VkSurfaceKHR ret;
251+
252+
ctx->result =
253+
window_cocoa->CreateMacOSSurface (window->display->instance->instance, ctx->info,
254+
NULL, &ctx->surface);
255+
256+
g_mutex_lock (&ctx->mutex);
257+
ctx->called = TRUE;
258+
g_cond_signal (&ctx->cond);
259+
g_mutex_unlock (&ctx->mutex);
260+
}
261+
262+
static VkResult
263+
_gst_vulkan_cocoa_create_macos_surface (GstVulkanWindow *window, VkSurfaceKHR * surface)
264+
{
228265
VkResult err;
266+
VkMacOSSurfaceCreateInfoMVK info = { 0, };
267+
268+
GstVulkanWindowCocoa *window_cocoa = GST_VULKAN_WINDOW_COCOA (window);
269+
GstVulkanWindowCocoaPrivate *priv = GET_PRIV (window_cocoa);
270+
271+
GstVulkanCococa_CreateMacOSSurfaceCtx ctx;
229272

230273
info.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
231274
info.pNext = NULL;
232275
info.flags = 0;
233276
info.pView = priv->internal_view;
234277

278+
memset(&ctx, 0, sizeof(GstVulkanCococa_CreateMacOSSurfaceCtx));
279+
g_mutex_init (&ctx.mutex);
280+
g_cond_init (&ctx.cond);
281+
ctx.info = &info;
282+
ctx.window = window;
283+
284+
_gst_vulkan_cocoa_invoke_on_main ((GstVulkanWindowFunc) _gst_vulkan_cocoa_create_macos_surface_on_main_thread, &ctx, NULL);
285+
_gst_vulkan_cocoa_wait_for_createmacossurface (&ctx);
286+
287+
*surface = ctx.surface;
288+
289+
return ctx.result;
290+
}
291+
292+
static VkSurfaceKHR
293+
gst_vulkan_window_cocoa_get_surface (GstVulkanWindow * window, GError ** error)
294+
{
295+
GstVulkanWindowCocoa *window_cocoa = GST_VULKAN_WINDOW_COCOA (window);
296+
VkSurfaceKHR ret;
297+
VkResult err;
298+
235299
if (!window_cocoa->CreateMacOSSurface)
236300
window_cocoa->CreateMacOSSurface =
237301
gst_vulkan_instance_get_proc_address (window->display->instance,
@@ -242,9 +306,7 @@ static void gst_vulkan_window_cocoa_set_window_handle (GstVulkanWindow * window,
242306
return VK_NULL_HANDLE;
243307
}
244308

245-
err =
246-
window_cocoa->CreateMacOSSurface (window->display->instance->instance, &info,
247-
NULL, &ret);
309+
err = _gst_vulkan_cocoa_create_macos_surface (window, &ret);
248310
if (gst_vulkan_error_to_g_error (err, error, "vkCreateMacOSSurfaceMVK") < 0)
249311
return VK_NULL_HANDLE;
250312

0 commit comments

Comments
 (0)