[gtk/wip/chergert/glproto: 269/493] free textures back into the texture pool




commit 5d74bf0383adc6d1461f7592e737051c3fc8db88
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 27 16:07:15 2021 -0800

    free textures back into the texture pool

 gsk/next/gskgldriver.c      | 13 ++++++++++++-
 gsk/next/gskgltexturepool.c | 16 ++++++++++++----
 2 files changed, 24 insertions(+), 5 deletions(-)
---
diff --git a/gsk/next/gskgldriver.c b/gsk/next/gskgldriver.c
index fa8845cdbf..a2db9b8855 100644
--- a/gsk/next/gskgldriver.c
+++ b/gsk/next/gskgldriver.c
@@ -95,6 +95,7 @@ remove_texture_key_for_id (GskNextDriver *self,
   g_assert (GSK_IS_NEXT_DRIVER (self));
   g_assert (texture_id > 0);
 
+  /* g_hash_table_remove() will cause @key to be freed */
   if (g_hash_table_steal_extended (self->texture_id_to_key,
                                    GUINT_TO_POINTER (texture_id),
                                    NULL,
@@ -131,8 +132,18 @@ gsk_next_driver_collect_unused_textures (GskNextDriver *self,
 
       if (t->last_used_in_frame < watermark)
         {
+          g_hash_table_iter_steal (&iter);
+
+          g_assert (t->width_link.prev == NULL);
+          g_assert (t->width_link.next == NULL);
+          g_assert (t->width_link.data == t);
+          g_assert (t->height_link.prev == NULL);
+          g_assert (t->height_link.next == NULL);
+          g_assert (t->height_link.data == t);
+
+          /* Steal this texture and put it back into the pool */
           remove_texture_key_for_id (self, t->texture_id);
-          g_hash_table_iter_remove (&iter);
+          gsk_gl_texture_pool_put (&self->texture_pool, t);
         }
     }
 
diff --git a/gsk/next/gskgltexturepool.c b/gsk/next/gskgltexturepool.c
index e3a70bf91b..3df7856a05 100644
--- a/gsk/next/gskgltexturepool.c
+++ b/gsk/next/gskgltexturepool.c
@@ -71,11 +71,18 @@ void
 gsk_gl_texture_pool_put (GskGLTexturePool *self,
                          GskGLTexture     *texture)
 {
-  GList *sibling = NULL;
+  GList *sibling;
 
   g_return_if_fail (self != NULL);
   g_return_if_fail (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->width_link.data == texture);
+  g_return_if_fail (texture->height_link.prev == NULL);
+  g_return_if_fail (texture->height_link.next == NULL);
+  g_return_if_fail (texture->height_link.data == texture);
+
+  sibling = NULL;
   for (GList *iter = self->by_width.head;
        iter != NULL;
        iter = iter->next)
@@ -92,7 +99,8 @@ gsk_gl_texture_pool_put (GskGLTexturePool *self,
 
   g_queue_insert_after_link (&self->by_width, sibling, &texture->width_link);
 
-  for (GList *iter = self->by_width.head;
+  sibling = NULL;
+  for (GList *iter = self->by_height.head;
        iter != NULL;
        iter = iter->next)
     {
@@ -106,7 +114,7 @@ gsk_gl_texture_pool_put (GskGLTexturePool *self,
       sibling = iter;
     }
 
-  g_queue_insert_after_link (&self->by_width, sibling, &texture->width_link);
+  g_queue_insert_after_link (&self->by_height, sibling, &texture->height_link);
 }
 
 GskGLTexture *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]