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
This commit is contained in:
parent
20982bf2c8
commit
1f557a502b
@ -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 */
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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__ */
|
||||
|
Loading…
Reference in New Issue
Block a user