@@ -218,20 +218,84 @@ static void gst_vulkan_window_cocoa_set_window_handle (GstVulkanWindow * window,
218
218
return TRUE ;
219
219
}
220
220
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)
223
247
{
248
+ GstVulkanCococa_CreateMacOSSurfaceCtx * ctx = data;
249
+ GstVulkanWindow *window = ctx->window ;
224
250
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
+ {
228
265
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;
229
272
230
273
info.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
231
274
info.pNext = NULL ;
232
275
info.flags = 0 ;
233
276
info.pView = priv->internal_view ;
234
277
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
+
235
299
if (!window_cocoa->CreateMacOSSurface )
236
300
window_cocoa->CreateMacOSSurface =
237
301
gst_vulkan_instance_get_proc_address (window->display ->instance ,
@@ -242,9 +306,7 @@ static void gst_vulkan_window_cocoa_set_window_handle (GstVulkanWindow * window,
242
306
return VK_NULL_HANDLE;
243
307
}
244
308
245
- err =
246
- window_cocoa->CreateMacOSSurface (window->display ->instance ->instance , &info,
247
- NULL , &ret);
309
+ err = _gst_vulkan_cocoa_create_macos_surface (window, &ret);
248
310
if (gst_vulkan_error_to_g_error (err, error, " vkCreateMacOSSurfaceMVK" ) < 0 )
249
311
return VK_NULL_HANDLE;
250
312
0 commit comments