summaryrefslogtreecommitdiff
path: root/gsk/gsktexture.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2016-11-16 05:37:20 +0100
committerBenjamin Otte <otte@redhat.com>2016-11-16 17:36:33 +0100
commit48e7f4191fae6fdaf048e858694aa1d8e0b08673 (patch)
treea46b0e3a35560707190f49f9babaf931ffda0603 /gsk/gsktexture.c
parent40565fb0308ba2e8a91a853af024bff49bd84a38 (diff)
downloadgtk+-48e7f4191fae6fdaf048e858694aa1d8e0b08673.tar.gz
gsktexture: Allow attaching render data to textures
This allows renderers (or anyone really) to attach "render data" to textures. Only the first render data sticks. You can gsk_texture_set_render_data() with the key you will use to look the data up again, and if no data has been set yet, yours will be set. You can retrieve this data via gsk_texture_get_render_data() later on. If your data has been cleared, NULL will be returned. When gsk_texture_clear_render_data() is called (which the texture will call when it is finalized), your destory notify will be called and you have to release your render data. The GL driver uses this to attach texture ids to GskTextures.
Diffstat (limited to 'gsk/gsktexture.c')
-rw-r--r--gsk/gsktexture.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/gsk/gsktexture.c b/gsk/gsktexture.c
index 8ccfcbac1a..ceb36b2e50 100644
--- a/gsk/gsktexture.c
+++ b/gsk/gsktexture.c
@@ -35,6 +35,7 @@
#include "gsktextureprivate.h"
#include "gskdebugprivate.h"
+#include "gskrenderer.h"
/**
* GskTexture: (ref-func gsk_texture_ref) (unref-func gsk_texture_unref)
@@ -49,6 +50,8 @@ G_DEFINE_BOXED_TYPE(GskTexture, gsk_texture, gsk_texture_ref, gsk_texture_unref)
static void
gsk_texture_finalize (GskTexture *self)
{
+ gsk_texture_clear_render_data (self);
+
self->klass->finalize (self);
g_free (self);
@@ -278,3 +281,41 @@ gsk_texture_download (GskTexture *texture)
return texture->klass->download (texture);
}
+gboolean
+gsk_texture_set_render_data (GskTexture *self,
+ gpointer key,
+ gpointer data,
+ GDestroyNotify notify)
+{
+ g_return_val_if_fail (data != NULL, FALSE);
+
+ if (self->render_key != NULL)
+ return FALSE;
+
+ self->render_key = key;
+ self->render_data = data;
+ self->render_notify = notify;
+
+ return TRUE;
+}
+
+void
+gsk_texture_clear_render_data (GskTexture *self)
+{
+ if (self->render_notify)
+ self->render_notify (self->render_data);
+
+ self->render_key = NULL;
+ self->render_data = NULL;
+ self->render_notify = NULL;
+}
+
+gpointer
+gsk_texture_get_render_data (GskTexture *self,
+ gpointer key)
+{
+ if (self->render_key != key)
+ return NULL;
+
+ return self->render_data;
+}