[Cogl] [PATCH 4/4] cogl-gst: Don't advertise the GLSL caps if GLSL not supported
Neil Roberts
neil at linux.intel.com
Tue Feb 26 12:07:39 PST 2013
The renderers now have a flag to specify whether they need GLSL
support. If so then they will be missed out when building the caps if
the context does not support GLSL. Building the caps is now delayed
until the cogl context is set.
---
cogl-gst/cogl-gst-video-sink.c | 72 +++++++++++++++++++++++++++---------------
1 file changed, 47 insertions(+), 25 deletions(-)
diff --git a/cogl-gst/cogl-gst-video-sink.c b/cogl-gst/cogl-gst-video-sink.c
index 47d87c6..5bbd651 100644
--- a/cogl-gst/cogl-gst-video-sink.c
+++ b/cogl-gst/cogl-gst-video-sink.c
@@ -85,6 +85,11 @@ typedef enum
COGL_GST_I420,
}CoglGstVideoFormat;
+typedef enum
+{
+ COGL_GST_RENDERER_NEEDS_GLSL = (1 << 0)
+} CoglGstRendererFlag;
+
typedef struct _CoglGstSource
{
GSource source;
@@ -170,13 +175,6 @@ cogl_gst_source_push (CoglGstSource *gst_source,
g_main_context_wakeup (priv->g_ctx);
}
-
-void
-cogl_gst_video_sink_set_context (CoglGstVideoSink *vt, CoglContext *ctx)
-{
- vt->priv->ctx = ctx;
-}
-
void
cogl_gst_set_shader_hook (CoglGstVideoSink *sink, CoglSnippetHook hook)
{
@@ -497,7 +495,7 @@ static CoglGstRenderer yv12_glsl_renderer =
{
"YV12 glsl",
COGL_GST_YV12,
- 0,
+ COGL_GST_RENDERER_NEEDS_GLSL,
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("YV12")),
cogl_gst_yv12_glsl_init,
cogl_gst_dummy_deinit,
@@ -516,7 +514,7 @@ static CoglGstRenderer i420_glsl_renderer =
{
"I420 glsl",
COGL_GST_I420,
- 0,
+ COGL_GST_RENDERER_NEEDS_GLSL,
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420")),
cogl_gst_i420_glsl_init,
cogl_gst_dummy_deinit,
@@ -551,7 +549,7 @@ static CoglGstRenderer ayuv_glsl_renderer =
{
"AYUV glsl",
COGL_GST_AYUV,
- 0,
+ COGL_GST_RENDERER_NEEDS_GLSL,
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV")),
cogl_gst_ayuv_glsl_init,
cogl_gst_dummy_deinit,
@@ -559,23 +557,25 @@ static CoglGstRenderer ayuv_glsl_renderer =
};
static GSList*
-cogl_gst_build_renderers_list (void)
+cogl_gst_build_renderers_list (CoglContext *ctx)
{
GSList *list = NULL;
+ CoglBool has_glsl;
int i;
-
- CoglGstRenderer *renderers[] =
+ static CoglGstRenderer * const renderers[] =
{
&rgb24_renderer,
&rgb32_renderer,
&yv12_glsl_renderer,
&i420_glsl_renderer,
- &ayuv_glsl_renderer,
- NULL
+ &ayuv_glsl_renderer
};
- for (i = 0; i < 5; i++)
- list = g_slist_prepend (list, renderers[i]);
+ has_glsl = cogl_has_feature (ctx, COGL_FEATURE_ID_GLSL);
+
+ for (i = 0; i < G_N_ELEMENTS (renderers); i++)
+ if (has_glsl || !(renderers[i]->flags & COGL_GST_RENDERER_NEEDS_GLSL))
+ list = g_slist_prepend (list, renderers[i]);
return list;
}
@@ -605,6 +605,34 @@ cogl_gst_build_caps (GSList *renderers)
return caps;
}
+void
+cogl_gst_video_sink_set_context (CoglGstVideoSink *vt, CoglContext *ctx)
+{
+ CoglGstVideoSinkPrivate *priv = vt->priv;
+
+ if (ctx)
+ ctx = cogl_object_ref (ctx);
+
+ if (priv->ctx)
+ {
+ cogl_object_unref (priv->ctx);
+ g_slist_free (priv->renderers);
+ priv->renderers = NULL;
+ if (priv->caps)
+ {
+ gst_caps_unref (priv->caps);
+ priv->caps = NULL;
+ }
+ }
+
+ if (ctx)
+ {
+ priv->ctx = ctx;
+ priv->renderers = cogl_gst_build_renderers_list (priv->ctx);
+ priv->caps = cogl_gst_build_caps (priv->renderers);
+ }
+}
+
static CoglGstRenderer*
cogl_gst_find_renderer_by_format (CoglGstVideoSink *sink,
CoglGstVideoFormat format)
@@ -650,8 +678,6 @@ cogl_gst_video_sink_init (CoglGstVideoSink *sink,
sink->priv->loop = g_main_loop_new (NULL, TRUE);
sink->priv->g_ctx = g_main_loop_get_context (sink->priv->loop);
- priv->renderers = cogl_gst_build_renderers_list ();
- priv->caps = cogl_gst_build_caps (priv->renderers);
priv->renderer_state = COGL_GST_RENDERER_STOPPED;
priv->hook = COGL_SNIPPET_HOOK_FRAGMENT;
}
@@ -798,13 +824,9 @@ cogl_gst_video_sink_dispose (GObject *object)
static void
cogl_gst_video_sink_finalize (GObject *object)
{
- CoglGstVideoSink *self;
- CoglGstVideoSinkPrivate *priv;
-
- self = COGL_GST_VIDEO_SINK (object);
- priv = self->priv;
+ CoglGstVideoSink *self = COGL_GST_VIDEO_SINK (object);
- g_slist_free (priv->renderers);
+ cogl_gst_video_sink_set_context (self, NULL);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
--
1.7.11.3.g3c3efa5
More information about the Cogl
mailing list