gl/calayer: only start drawing if the parent gl context is ready
authorMatthew Waters <matthew@centricular.com>
Tue, 17 Feb 2015 05:41:17 +0000 (16:41 +1100)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 9 Dec 2017 19:31:54 +0000 (19:31 +0000)
otherwise we may try to use GstGLFuncs * that hasn't been set yet

gst-libs/gst/gl/cocoa/gstglcaopengllayer.h
gst-libs/gst/gl/cocoa/gstglcaopengllayer.m

index 17e385b..53a14d8 100644 (file)
@@ -46,6 +46,7 @@ G_BEGIN_DECLS
   gpointer resize_data;
   GDestroyNotify resize_notify;
 
+  gint can_draw;
 }
 - (void) setDrawCallback:(GstGLWindowCB)cb data:(gpointer)a notify:(GDestroyNotify)notify;
 - (void) setResizeCallback:(GstGLWindowResizeCB)cb data:(gpointer)a notify:(GDestroyNotify)notify;
index d6148d1..d9fd2e2 100644 (file)
   [super dealloc];
 }
 
+static void
+_context_ready (gpointer data)
+{
+  GstGLCAOpenGLLayer *ca_layer = data;
+
+  g_atomic_int_set (&ca_layer->can_draw, 1);
+}
+
 - (id)initWithGstGLContext:(GstGLContextCocoa *)parent_gl_context {
   [super init];
 
@@ -46,6 +54,9 @@
   self.asynchronous = YES;
   self.needsDisplayOnBoundsChange = YES;
 
+  gst_gl_window_send_message_async (GST_GL_CONTEXT (parent_gl_context)->window,
+      (GstGLWindowCB) _context_ready, self, NULL);
+
   return self;
 }
 
   self->resize_notify = notify;
 }
 
+- (BOOL)canDrawInCGLContext:(CGLContextObj)glContext
+               pixelFormat:(CGLPixelFormatObj)pixelFormat
+            forLayerTime:(CFTimeInterval)interval
+             displayTime:(const CVTimeStamp *)timeStamp {
+  return g_atomic_int_get (&self->can_draw);
+}
+
 - (void)drawInCGLContext:(CGLContextObj)glContext
                pixelFormat:(CGLPixelFormatObj)pixelFormat
             forLayerTime:(CFTimeInterval)interval