From c90f7001b131cc934eca0e30ce02ce6d75046a4a Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Thu, 27 Nov 2014 21:05:45 +1100 Subject: [PATCH] gldisplay: implement runtime GL api filtering Needed so that the pipeline/application can limit the choice of GL api to what it supports --- ext/gl/gstglmixer.c | 24 ++++++++++++++++++++++-- ext/gl/gstglmixer.h | 1 + ext/gl/gstglmosaic.c | 2 ++ ext/gl/gstglvideomixer.c | 3 +++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/ext/gl/gstglmixer.c b/ext/gl/gstglmixer.c index e245bc29fe..66b069ef76 100644 --- a/ext/gl/gstglmixer.c +++ b/ext/gl/gstglmixer.c @@ -152,6 +152,7 @@ static gboolean gst_gl_mixer_propose_allocation (GstGLMixer * mix, GstQuery * decide_query, GstQuery * query) { + GstGLMixerClass *mix_class = GST_GL_MIXER_GET_CLASS (mix); GstBufferPool *pool; GstStructure *config; GstCaps *caps; @@ -192,6 +193,8 @@ gst_gl_mixer_propose_allocation (GstGLMixer * mix, if (!gst_gl_ensure_element_data (mix, &mix->display, &mix->other_context)) return FALSE; + gst_gl_display_filter_gl_api (mix->display, mix_class->supported_gl_api); + if (!mix->context) { mix->context = gst_gl_context_new (mix->display); if (!gst_gl_context_create (mix->context, mix->other_context, &error)) @@ -428,6 +431,7 @@ gst_gl_mixer_sink_query (GstAggregator * agg, GstAggregatorPad * bpad, { gboolean ret = FALSE; GstGLMixer *mix = GST_GL_MIXER (agg); + GstGLMixerClass *mix_class = GST_GL_MIXER_GET_CLASS (mix); GST_TRACE ("QUERY %" GST_PTR_FORMAT, query); @@ -485,6 +489,9 @@ gst_gl_mixer_sink_query (GstAggregator * agg, GstAggregatorPad * bpad, { ret = gst_gl_handle_context_query ((GstElement *) mix, query, &mix->display, &mix->other_context); + if (mix->display) + gst_gl_display_filter_gl_api (mix->display, + mix_class->supported_gl_api); break; } default: @@ -615,7 +622,7 @@ gst_gl_mixer_class_init (GstGLMixerClass * klass) g_type_class_ref (GST_TYPE_GL_MIXER_PAD); klass->set_caps = NULL; - + klass->supported_gl_api = GST_GL_API_ANY; } static void @@ -661,19 +668,26 @@ static void gst_gl_mixer_set_context (GstElement * element, GstContext * context) { GstGLMixer *mix = GST_GL_MIXER (element); + GstGLMixerClass *mix_class = GST_GL_MIXER_GET_CLASS (mix); gst_gl_handle_set_context (element, context, &mix->display, &mix->other_context); + + if (mix->display) + gst_gl_display_filter_gl_api (mix->display, mix_class->supported_gl_api); } static gboolean gst_gl_mixer_activate (GstGLMixer * mix, gboolean active) { + GstGLMixerClass *mix_class = GST_GL_MIXER_GET_CLASS (mix); gboolean result = TRUE; if (active) { if (!gst_gl_ensure_element_data (mix, &mix->display, &mix->other_context)) - result = FALSE; + return FALSE; + + gst_gl_display_filter_gl_api (mix->display, mix_class->supported_gl_api); } return result; @@ -729,12 +743,16 @@ gst_gl_mixer_src_query (GstAggregator * agg, GstQuery * query) { gboolean res = FALSE; GstGLMixer *mix = GST_GL_MIXER (agg); + GstGLMixerClass *mix_class = GST_GL_MIXER_GET_CLASS (mix); switch (GST_QUERY_TYPE (query)) { case GST_QUERY_CONTEXT: { res = gst_gl_handle_context_query ((GstElement *) mix, query, &mix->display, &mix->other_context); + if (mix->display) + gst_gl_display_filter_gl_api (mix->display, + mix_class->supported_gl_api); break; } case GST_QUERY_CAPS: @@ -785,6 +803,8 @@ gst_gl_mixer_decide_allocation (GstGLMixer * mix, GstQuery * query) if (!gst_gl_ensure_element_data (mix, &mix->display, &mix->other_context)) return FALSE; + gst_gl_display_filter_gl_api (mix->display, mixer_class->supported_gl_api); + if (gst_query_find_allocation_meta (query, GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE, &idx)) { GstGLContext *context; diff --git a/ext/gl/gstglmixer.h b/ext/gl/gstglmixer.h index f25c30a32f..4a92d54713 100644 --- a/ext/gl/gstglmixer.h +++ b/ext/gl/gstglmixer.h @@ -76,6 +76,7 @@ struct _GstGLMixer struct _GstGLMixerClass { GstVideoAggregatorClass parent_class; + GstGLAPI supported_gl_api; GstGLMixerSetCaps set_caps; GstGLMixerReset reset; diff --git a/ext/gl/gstglmosaic.c b/ext/gl/gstglmosaic.c index 1274a3dcec..e8daef9f6d 100644 --- a/ext/gl/gstglmosaic.c +++ b/ext/gl/gstglmosaic.c @@ -134,6 +134,8 @@ gst_gl_mosaic_class_init (GstGLMosaicClass * klass) GST_GL_MIXER_CLASS (klass)->set_caps = gst_gl_mosaic_init_shader; GST_GL_MIXER_CLASS (klass)->reset = gst_gl_mosaic_reset; GST_GL_MIXER_CLASS (klass)->process_textures = gst_gl_mosaic_process_textures; + + GST_GL_MIXER_CLASS (klass)->supported_gl_api = GST_GL_API_OPENGL; } static void diff --git a/ext/gl/gstglvideomixer.c b/ext/gl/gstglvideomixer.c index d73bf97150..f16f6d325f 100644 --- a/ext/gl/gstglvideomixer.c +++ b/ext/gl/gstglvideomixer.c @@ -345,6 +345,9 @@ gst_gl_video_mixer_class_init (GstGLVideoMixerClass * klass) vagg_class->update_caps = _update_caps; agg_class->sinkpads_type = GST_TYPE_GL_VIDEO_MIXER_PAD; + + GST_GL_MIXER_CLASS (klass)->supported_gl_api = + GST_GL_API_OPENGL | GST_GL_API_OPENGL3 | GST_GL_API_GLES2; } static void