summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLionel Landwerlin <llandwerlin@gmail.com>2013-12-13 18:44:16 +0000
committerLionel Landwerlin <llandwerlin@gmail.com>2013-12-13 18:44:16 +0000
commit94598e6c1780df926c8de7c261124663518e22c3 (patch)
tree493472e5b203486854cc2fe6583f6553ef24d472
parent624cbd5787295370c4c73852c83d0c1abc506e3e (diff)
downloadclutter-gst-94598e6c1780df926c8de7c261124663518e22c3.tar.gz
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
-rw-r--r--clutter-gst/clutter-gst-video-sink.c24
1 files changed, 23 insertions, 1 deletions
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;