[mutter] cogl/context: Add API to create named pipelines
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] cogl/context: Add API to create named pipelines
- Date: Mon, 31 Aug 2020 16:05:39 +0000 (UTC)
commit 1f557a502bc1cd0b0421124888cc0ec1def6a070
Author: Robert Mader <robert mader posteo de>
Date: Mon Aug 10 14:24:58 2020 +0200
cogl/context: Add API to create named pipelines
In certain situations it's desirable to keep pipelines around for
the whole lifetime of the session. In order to not leak them and
properly clean them up on shutdown, introduce a new mechanism to
create named pipelines that are bound to their correstponding
context and may be used across file boundries.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1372
cogl/cogl/cogl-context-private.h | 2 ++
cogl/cogl/cogl-context.c | 30 ++++++++++++++++++++++++++++++
cogl/cogl/cogl-context.h | 33 +++++++++++++++++++++++++++++++++
3 files changed, 65 insertions(+)
---
diff --git a/cogl/cogl/cogl-context-private.h b/cogl/cogl/cogl-context-private.h
index 2d68793a04..74206a4449 100644
--- a/cogl/cogl/cogl-context-private.h
+++ b/cogl/cogl/cogl-context-private.h
@@ -256,6 +256,8 @@ struct _CoglContext
CoglPollSource *fences_poll_source;
CoglList fences;
+ GHashTable *named_pipelines;
+
/* This defines a list of function pointers that Cogl uses from
either GL or GLES. All functions are accessed indirectly through
these pointers rather than linking to them directly */
diff --git a/cogl/cogl/cogl-context.c b/cogl/cogl/cogl-context.c
index c05123580e..1275439b65 100644
--- a/cogl/cogl/cogl-context.c
+++ b/cogl/cogl/cogl-context.c
@@ -308,6 +308,9 @@ cogl_context_new (CoglDisplay *display,
_cogl_list_init (&context->fences);
+ context->named_pipelines =
+ g_hash_table_new_full (NULL, NULL, NULL, cogl_object_unref);
+
return context;
}
@@ -382,6 +385,9 @@ _cogl_context_free (CoglContext *context)
cogl_object_unref (context->display);
+ g_hash_table_remove_all (context->named_pipelines);
+ g_hash_table_destroy (context->named_pipelines);
+
g_free (context);
}
@@ -472,3 +478,27 @@ cogl_context_format_supports_upload (CoglContext *ctx,
{
return ctx->texture_driver->format_supports_upload (ctx, format);
}
+
+void
+cogl_context_set_named_pipeline (CoglContext *context,
+ CoglPipelineKey *key,
+ CoglPipeline *pipeline)
+{
+ if (pipeline)
+ {
+ g_debug ("Adding named pipeline %s", *key);
+ g_hash_table_insert (context->named_pipelines, (gpointer) key, pipeline);
+ }
+ else
+ {
+ g_debug ("Removing named pipeline %s", *key);
+ g_hash_table_remove (context->named_pipelines, (gpointer) key);
+ }
+}
+
+CoglPipeline *
+cogl_context_get_named_pipeline (CoglContext *context,
+ CoglPipelineKey *key)
+{
+ return g_hash_table_lookup (context->named_pipelines, key);
+}
diff --git a/cogl/cogl/cogl-context.h b/cogl/cogl/cogl-context.h
index e5882e7dd4..1baa4145ef 100644
--- a/cogl/cogl/cogl-context.h
+++ b/cogl/cogl/cogl-context.h
@@ -44,6 +44,7 @@ typedef struct _CoglContext CoglContext;
#include <cogl/cogl-defines.h>
#include <cogl/cogl-display.h>
+#include <cogl/cogl-pipeline.h>
#include <cogl/cogl-primitive.h>
#include <glib-object.h>
@@ -367,6 +368,38 @@ cogl_get_graphics_reset_status (CoglContext *context);
COGL_EXPORT gboolean
cogl_context_is_hardware_accelerated (CoglContext *context);
+typedef const char * const CoglPipelineKey;
+
+/**
+ * cogl_context_set_named_pipeline:
+ * @context: a #CoglContext pointer
+ * @key: a #CoglPipelineKey pointer
+ * @pipeline: (nullable): a #CoglPipeline to associate with the @context and
+ * @key
+ *
+ * Associate a #CoglPipeline with a @context and @key. This will not take a new
+ * reference to the @pipeline, but will unref all associated pipelines when
+ * the @context gets destroyed. Similarly, if a pipeline gets overwritten,
+ * it will get unreffed as well.
+ */
+COGL_EXPORT void
+cogl_context_set_named_pipeline (CoglContext *context,
+ CoglPipelineKey *key,
+ CoglPipeline *pipeline);
+
+/**
+ * cogl_context_get_named_pipeline:
+ * @context: a #CoglContext pointer
+ * @key: a #CoglPipelineKey pointer
+ *
+ * Return value: (transfer none): The #CoglPipeline associated with the
+ * given @context and @key, or %NULL if no such #CoglPipeline
+ * was found.
+ */
+COGL_EXPORT CoglPipeline *
+cogl_context_get_named_pipeline (CoglContext *context,
+ CoglPipelineKey *key);
+
G_END_DECLS
#endif /* __COGL_CONTEXT_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]