cgl/calayer: use a callback instead of hardcoding the draw functionality

This commit is contained in:
Matthew Waters 2015-01-28 17:16:14 +11:00 committed by Tim-Philipp Müller
parent 0cfeddbd05
commit 698f1236a4
3 changed files with 23 additions and 11 deletions

View file

@ -40,6 +40,7 @@ G_BEGIN_DECLS
gpointer draw_data; gpointer draw_data;
GDestroyNotify draw_notify; GDestroyNotify draw_notify;
} }
- (void) setDrawCallback:(GstGLWindowCB)cb data:(gpointer)a notify:(GDestroyNotify)notify;
- (id) initWithGstGLContext: (GstGLContextCocoa *)context; - (id) initWithGstGLContext: (GstGLContextCocoa *)context;
- (void) resize: (NSRect)bounds; - (void) resize: (NSRect)bounds;
@end @end

View file

@ -29,6 +29,9 @@
@implementation GstGLCAOpenGLLayer @implementation GstGLCAOpenGLLayer
- (void)dealloc { - (void)dealloc {
if (self->draw_notify)
self->draw_notify (self->draw_data);
GST_TRACE ("dealloc GstGLCAOpenGLLayer %p context %p", self, self->gst_gl_context); GST_TRACE ("dealloc GstGLCAOpenGLLayer %p context %p", self, self->gst_gl_context);
[super dealloc]; [super dealloc];
@ -88,25 +91,35 @@
return self->gl_context; 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 { - (void)resize:(NSRect)bounds {
const GstGLFuncs *gl = ((GstGLContext *)self->gst_gl_context)->gl_vtable; const GstGLFuncs *gl = ((GstGLContext *)self->gst_gl_context)->gl_vtable;
gl->GetIntegerv (GL_VIEWPORT, self->expected_dims); gl->GetIntegerv (GL_VIEWPORT, self->expected_dims);
} }
- (void)releaseCGLContext:(CGLContextObj)glContext {
CGLReleaseContext (glContext);
}
- (void)drawInCGLContext:(CGLContextObj)glContext - (void)drawInCGLContext:(CGLContextObj)glContext
pixelFormat:(CGLPixelFormatObj)pixelFormat pixelFormat:(CGLPixelFormatObj)pixelFormat
forLayerTime:(CFTimeInterval)interval forLayerTime:(CFTimeInterval)interval
displayTime:(const CVTimeStamp *)timeStamp { 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; const GstGLFuncs *gl = ((GstGLContext *)self->gst_gl_context)->gl_vtable;
gint ca_viewport[4]; 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 /* attempt to get the correct viewport back due to CA being too smart
* and messing around with it so center the expected viewport into * and messing around with it so center the expected viewport into
@ -129,11 +142,8 @@
gl->Viewport (result.x, result.y, result.w, result.h); gl->Viewport (result.x, result.y, result.w, result.h);
if (window) { if (self->draw_cb)
gst_gl_window_cocoa_draw_thread (GST_GL_WINDOW_COCOA (window)); self->draw_cb (self->draw_data);
gst_object_unref (window);
}
/* flushes the buffer */ /* flushes the buffer */
[super drawInCGLContext:glContext pixelFormat:pixelFormat forLayerTime:interval displayTime:timeStamp]; [super drawInCGLContext:glContext pixelFormat:pixelFormat forLayerTime:interval displayTime:timeStamp];

View file

@ -469,6 +469,7 @@ close_window_cb (gpointer data)
[self setLayer:layerContent]; [self setLayer:layerContent];
[self setWantsLayer:YES]; [self setWantsLayer:YES];
self->layer = (GstGLCAOpenGLLayer *)layerContent; self->layer = (GstGLCAOpenGLLayer *)layerContent;
[self->layer setDrawCallback:(GstGLWindowCB)gst_gl_window_cocoa_draw_thread data:window notify:NULL];
[self setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawOnSetNeedsDisplay]; [self setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawOnSetNeedsDisplay];