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
parent 693cdb47cd
commit 8d5ba8d96a
3 changed files with 23 additions and 11 deletions

View 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

View 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];
@ -88,25 +91,35 @@
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
@ -129,11 +142,8 @@
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];

View 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];