cgl/calayer: use a callback instead of hardcoding the draw functionality
authorMatthew Waters <matthew@centricular.com>
Wed, 28 Jan 2015 06:16:14 +0000 (17:16 +1100)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 9 Dec 2017 19:31:53 +0000 (19:31 +0000)
gst-libs/gst/gl/cocoa/gstglcaopengllayer.h
gst-libs/gst/gl/cocoa/gstglcaopengllayer.m
gst-libs/gst/gl/cocoa/gstglwindow_cocoa.m

index c68b456..d55520d 100644 (file)
@@ -40,6 +40,7 @@ G_BEGIN_DECLS
   gpointer draw_data;
   GDestroyNotify draw_notify;
 }
+- (void) setDrawCallback:(GstGLWindowCB)cb data:(gpointer)a notify:(GDestroyNotify)notify;
 - (id) initWithGstGLContext: (GstGLContextCocoa *)context;
 - (void) resize: (NSRect)bounds;
 @end
index c360bc1..42afd88 100644 (file)
@@ -29,6 +29,9 @@
 
 @implementation GstGLCAOpenGLLayer
 - (void)dealloc {
+  if (self->draw_notify)
+    self->draw_notify (self->draw_data);
+
   GST_TRACE ("dealloc GstGLCAOpenGLLayer %p context %p", self, self->gst_gl_context);
 
   [super dealloc];
   return self->gl_context;
 }
 
+- (void)releaseCGLContext:(CGLContextObj)glContext {
+  CGLReleaseContext (glContext);
+}
+
+- (void)setDrawCallback:(GstGLWindowCB)cb data:(gpointer)data notify:(GDestroyNotify)notify {
+  g_return_if_fail (cb);
+
+  if (self->draw_notify)
+    self->draw_notify (self->draw_data);
+
+  self->draw_cb = cb;
+  self->draw_data = data;
+  self->draw_notify = notify;
+}
+
 - (void)resize:(NSRect)bounds {
   const GstGLFuncs *gl = ((GstGLContext *)self->gst_gl_context)->gl_vtable;
 
   gl->GetIntegerv (GL_VIEWPORT, self->expected_dims);
 }
 
-- (void)releaseCGLContext:(CGLContextObj)glContext {
-  CGLReleaseContext (glContext);
-}
-
 - (void)drawInCGLContext:(CGLContextObj)glContext
                pixelFormat:(CGLPixelFormatObj)pixelFormat
             forLayerTime:(CFTimeInterval)interval
              displayTime:(const CVTimeStamp *)timeStamp {
-  GstGLWindow *window = gst_gl_context_get_window (GST_GL_CONTEXT (self->gst_gl_context));
   const GstGLFuncs *gl = ((GstGLContext *)self->gst_gl_context)->gl_vtable;
   gint ca_viewport[4];
 
-  GST_LOG ("CAOpenGLLayer drawing with window %p cgl context %p", window, glContext);
+  GST_LOG ("CAOpenGLLayer drawing with cgl context %p", glContext);
 
   /* attempt to get the correct viewport back due to CA being too smart
    * and messing around with it so center the expected viewport into
 
   gl->Viewport (result.x, result.y, result.w, result.h);
 
-  if (window) {
-    gst_gl_window_cocoa_draw_thread (GST_GL_WINDOW_COCOA (window));
-
-    gst_object_unref (window);
-  }
+  if (self->draw_cb)
+    self->draw_cb (self->draw_data);
 
   /* flushes the buffer */
   [super drawInCGLContext:glContext pixelFormat:pixelFormat forLayerTime:interval displayTime:timeStamp];
index 7cc8020..b84e007 100644 (file)
@@ -469,6 +469,7 @@ close_window_cb (gpointer data)
   [self setLayer:layerContent];
   [self setWantsLayer:YES];
   self->layer = (GstGLCAOpenGLLayer *)layerContent;
+  [self->layer setDrawCallback:(GstGLWindowCB)gst_gl_window_cocoa_draw_thread data:window notify:NULL];
 
   [self setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawOnSetNeedsDisplay];