From 94598e6c1780df926c8de7c261124663518e22c3 Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Fri, 13 Dec 2013 18:44:16 +0000 Subject: video-sink: use a shader cache Cogl currently doesn't garbage collect its shader programs so introduce a local cache to avoid leaking. https://bugzilla.gnome.org/show_bug.cgi?id=720408 --- clutter-gst/clutter-gst-video-sink.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/clutter-gst/clutter-gst-video-sink.c b/clutter-gst/clutter-gst-video-sink.c index 5b25e78..2c8f75a 100644 --- a/clutter-gst/clutter-gst-video-sink.c +++ b/clutter-gst/clutter-gst-video-sink.c @@ -683,6 +683,28 @@ _create_cogl_program (const char *source) return program; } +static CoglHandle +_get_cached_cogl_program (const char *source) +{ + static GHashTable *program_cache = NULL; + CoglHandle handle; + + if (G_UNLIKELY (program_cache == NULL)) { + program_cache = g_hash_table_new_full (g_str_hash, g_str_equal, + NULL, (GDestroyNotify) cogl_handle_unref); + } + + handle = (CoglHandle) g_hash_table_lookup (program_cache, (gpointer) source); + if (handle == COGL_INVALID_HANDLE) { + handle = _create_cogl_program (source); + g_hash_table_insert (program_cache, + (gpointer) source, + (gpointer) cogl_handle_ref (handle)); + } + + return handle; +} + static void _create_template_material (ClutterGstVideoSink * sink, const char *source, gboolean set_uniforms, int n_layers) @@ -697,7 +719,7 @@ _create_template_material (ClutterGstVideoSink * sink, template = cogl_material_new (); if (source) { - CoglHandle program = _create_cogl_program (source); + CoglHandle program = _get_cached_cogl_program (source); if (set_uniforms) { unsigned int location; -- cgit v1.2.1