mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 20:21:24 +00:00
gl/calayer: provide a current wrapped GstGLContext for callbacks
So that the draw and resize callbacks can get the current GstGLContext.
This commit is contained in:
parent
18b9519a66
commit
e8e84cf6b3
2 changed files with 35 additions and 0 deletions
|
@ -35,6 +35,7 @@ G_BEGIN_DECLS
|
||||||
CGLContextObj gl_context;
|
CGLContextObj gl_context;
|
||||||
|
|
||||||
@private
|
@private
|
||||||
|
GstGLContext *draw_context;
|
||||||
CGRect last_bounds;
|
CGRect last_bounds;
|
||||||
gint expected_dims[4];
|
gint expected_dims[4];
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,9 @@
|
||||||
if (self->draw_notify)
|
if (self->draw_notify)
|
||||||
self->draw_notify (self->draw_data);
|
self->draw_notify (self->draw_data);
|
||||||
|
|
||||||
|
if (self->draw_context)
|
||||||
|
gst_object_unref (self->draw_context);
|
||||||
|
|
||||||
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];
|
||||||
|
@ -86,8 +89,10 @@ _context_ready (gpointer data)
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat {
|
- (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat {
|
||||||
|
GstGLDisplay *display;
|
||||||
CGLContextObj external_context = NULL;
|
CGLContextObj external_context = NULL;
|
||||||
CGLError ret;
|
CGLError ret;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
if (self->gst_gl_context)
|
if (self->gst_gl_context)
|
||||||
external_context = (CGLContextObj) gst_gl_context_get_gl_context (GST_GL_CONTEXT (self->gst_gl_context));
|
external_context = (CGLContextObj) gst_gl_context_get_gl_context (GST_GL_CONTEXT (self->gst_gl_context));
|
||||||
|
@ -98,8 +103,35 @@ _context_ready (gpointer data)
|
||||||
ret = CGLCreateContext (pixelFormat, external_context, &self->gl_context);
|
ret = CGLCreateContext (pixelFormat, external_context, &self->gl_context);
|
||||||
if (ret != kCGLNoError) {
|
if (ret != kCGLNoError) {
|
||||||
GST_ERROR ("failed to create CGL context in CAOpenGLLayer with share context %p: %s", external_context, CGLErrorString(ret));
|
GST_ERROR ("failed to create CGL context in CAOpenGLLayer with share context %p: %s", external_context, CGLErrorString(ret));
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (self->draw_context)
|
||||||
|
gst_object_unref (self->draw_context);
|
||||||
|
|
||||||
|
display = gst_gl_context_get_display (GST_GL_CONTEXT (self->gst_gl_context));
|
||||||
|
self->draw_context = gst_gl_context_new_wrapped (display,
|
||||||
|
(guintptr) self->gl_context, GST_GL_PLATFORM_CGL,
|
||||||
|
gst_gl_display_get_gl_api (display));
|
||||||
|
gst_object_unref (display);
|
||||||
|
|
||||||
|
if (!self->draw_context) {
|
||||||
|
GST_ERROR ("failed to create wrapped context");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (kCGLNoError != CGLSetCurrentContext (self->gl_context)) {
|
||||||
|
GST_ERROR ("failed set cgl context %p current", self->gl_context);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_gl_context_activate (self->draw_context, TRUE);
|
||||||
|
if (!gst_gl_context_fill_info (self->draw_context, &error)) {
|
||||||
|
GST_ERROR ("failed to fill wrapped context information: %s", error->message);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
gst_gl_context_activate (self->draw_context, FALSE);
|
||||||
|
|
||||||
return self->gl_context;
|
return self->gl_context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,6 +183,7 @@ _context_ready (gpointer data)
|
||||||
* the CA viewport set up on entry to this function */
|
* the CA viewport set up on entry to this function */
|
||||||
gl->GetIntegerv (GL_VIEWPORT, ca_viewport);
|
gl->GetIntegerv (GL_VIEWPORT, ca_viewport);
|
||||||
|
|
||||||
|
gst_gl_context_activate (self->draw_context, TRUE);
|
||||||
if (self->last_bounds.size.width != self.bounds.size.width
|
if (self->last_bounds.size.width != self.bounds.size.width
|
||||||
|| self->last_bounds.size.height != self.bounds.size.height) {
|
|| self->last_bounds.size.height != self.bounds.size.height) {
|
||||||
if (self->resize_cb) {
|
if (self->resize_cb) {
|
||||||
|
@ -185,6 +218,7 @@ _context_ready (gpointer data)
|
||||||
|
|
||||||
if (self->draw_cb)
|
if (self->draw_cb)
|
||||||
self->draw_cb (self->draw_data);
|
self->draw_cb (self->draw_data);
|
||||||
|
gst_gl_context_activate (self->draw_context, FALSE);
|
||||||
|
|
||||||
/* flushes the buffer */
|
/* flushes the buffer */
|
||||||
[super drawInCGLContext:glContext pixelFormat:pixelFormat forLayerTime:interval displayTime:timeStamp];
|
[super drawInCGLContext:glContext pixelFormat:pixelFormat forLayerTime:interval displayTime:timeStamp];
|
||||||
|
|
Loading…
Reference in a new issue