[gtk/wip/chergert/glproto: 281/493] fix texture lifecycle management
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/glproto: 281/493] fix texture lifecycle management
- Date: Fri, 19 Feb 2021 02:25:13 +0000 (UTC)
commit d59e2a2285ee0c87936faa93ccfdbcde0ce661bf
Author: Christian Hergert <chergert redhat com>
Date: Thu Jan 28 13:34:33 2021 -0800
fix texture lifecycle management
gsk/next/gskgldriver.c | 22 ++++++++++++++--------
gsk/next/gskgldriverprivate.h | 2 +-
gsk/next/gskgltexturepool.c | 12 ++++++++++++
3 files changed, 27 insertions(+), 9 deletions(-)
---
diff --git a/gsk/next/gskgldriver.c b/gsk/next/gskgldriver.c
index 231ca3c4f3..a2c707709d 100644
--- a/gsk/next/gskgldriver.c
+++ b/gsk/next/gskgldriver.c
@@ -871,13 +871,17 @@ void
gsk_next_driver_release_texture (GskNextDriver *self,
GskGLTexture *texture)
{
+ guint texture_id;
+
g_return_if_fail (GSK_IS_NEXT_DRIVER (self));
g_return_if_fail (texture != NULL);
- g_hash_table_remove (self->textures,
- GUINT_TO_POINTER (texture->texture_id));
- remove_texture_key_for_id (self, texture->texture_id);
+ texture_id = texture->texture_id;
+
+ if (texture_id > 0)
+ remove_texture_key_for_id (self, texture_id);
+ g_hash_table_steal (self->textures, GUINT_TO_POINTER (texture_id));
gsk_gl_texture_pool_put (&self->texture_pool, texture);
}
@@ -1246,17 +1250,19 @@ gsk_next_driver_slice_texture (GskNextDriver *self,
t->n_slices = *out_n_slices = n_slices;
}
-void
+GskGLTexture *
gsk_next_driver_mark_texture_permanent (GskNextDriver *self,
guint texture_id)
{
GskGLTexture *t;
- g_return_if_fail (GSK_IS_NEXT_DRIVER (self));
- g_return_if_fail (texture_id > 0);
+ g_return_val_if_fail (GSK_IS_NEXT_DRIVER (self), NULL);
+ g_return_val_if_fail (texture_id > 0, NULL);
if ((t = g_hash_table_lookup (self->textures, GUINT_TO_POINTER (texture_id))))
t->permanent = TRUE;
+
+ return t;
}
void
@@ -1268,8 +1274,8 @@ gsk_next_driver_release_texture_by_id (GskNextDriver *self,
g_return_if_fail (GSK_IS_NEXT_DRIVER (self));
g_return_if_fail (texture_id > 0);
+ remove_texture_key_for_id (self, texture_id);
+
if ((texture = g_hash_table_lookup (self->textures, GUINT_TO_POINTER (texture_id))))
gsk_next_driver_release_texture (self, texture);
- else
- remove_texture_key_for_id (self, texture_id);
}
diff --git a/gsk/next/gskgldriverprivate.h b/gsk/next/gskgldriverprivate.h
index 12bc7a4fed..c133ac1056 100644
--- a/gsk/next/gskgldriverprivate.h
+++ b/gsk/next/gskgldriverprivate.h
@@ -158,7 +158,7 @@ void gsk_next_driver_release_texture (GskNextDriver *
GskGLTexture *texture);
void gsk_next_driver_release_texture_by_id (GskNextDriver *self,
guint texture_id);
-void gsk_next_driver_mark_texture_permanent(GskNextDriver *self,
+GskGLTexture *gsk_next_driver_mark_texture_permanent(GskNextDriver *self,
guint texture_id);
void gsk_next_driver_slice_texture (GskNextDriver *self,
GdkTexture *texture,
diff --git a/gsk/next/gskgltexturepool.c b/gsk/next/gskgltexturepool.c
index 49bc7c19e4..18654a7a00 100644
--- a/gsk/next/gskgltexturepool.c
+++ b/gsk/next/gskgltexturepool.c
@@ -31,6 +31,11 @@ gsk_gl_texture_free (GskGLTexture *texture)
{
if (texture != NULL)
{
+ g_return_if_fail (texture->width_link.prev == NULL);
+ g_return_if_fail (texture->width_link.next == NULL);
+ g_return_if_fail (texture->height_link.prev == NULL);
+ g_return_if_fail (texture->height_link.next == NULL);
+
if (texture->user)
g_clear_pointer (&texture->user, gdk_texture_clear_render_data);
@@ -83,6 +88,7 @@ gsk_gl_texture_pool_put (GskGLTexturePool *self,
g_return_if_fail (self != NULL);
g_return_if_fail (texture != NULL);
+ g_return_if_fail (texture->user == NULL);
g_return_if_fail (texture->width_link.prev == NULL);
g_return_if_fail (texture->width_link.next == NULL);
g_return_if_fail (texture->width_link.data == texture);
@@ -90,6 +96,12 @@ gsk_gl_texture_pool_put (GskGLTexturePool *self,
g_return_if_fail (texture->height_link.next == NULL);
g_return_if_fail (texture->height_link.data == texture);
+ if (texture->permanent)
+ {
+ gsk_gl_texture_free (texture);
+ return;
+ }
+
sibling = NULL;
for (GList *iter = self->by_width.head;
iter != NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]