[gtk/wip/matthiasc/shared-glyph-cache: 32/41] gl: Don't leak texture atlases



commit f37274dbb0155bccb0da9c9d2d8ec9192fd6d5c9
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jun 2 15:11:11 2019 +0000

    gl: Don't leak texture atlases
    
    We need to free the texture atlases, and the
    textures backing them.

 gsk/gl/gskgliconcache.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
---
diff --git a/gsk/gl/gskgliconcache.c b/gsk/gl/gskgliconcache.c
index 95dc3d722b..6b7e8c5fbd 100644
--- a/gsk/gl/gskgliconcache.c
+++ b/gsk/gl/gskgliconcache.c
@@ -20,6 +20,17 @@ icon_data_free (gpointer p)
   g_free (p);
 }
 
+static void
+free_atlas (gpointer v)
+{
+  GskGLTextureAtlas *atlas = v;
+
+  g_assert (atlas->image.texture_id == 0);
+  gsk_gl_texture_atlas_free (atlas);
+
+  g_free (atlas);
+}
+
 void
 gsk_gl_icon_cache_init (GskGLIconCache *self,
                         GskRenderer    *renderer,
@@ -28,7 +39,7 @@ gsk_gl_icon_cache_init (GskGLIconCache *self,
   self->renderer = renderer;
   self->gl_driver = gl_driver;
 
-  self->atlases = g_ptr_array_new ();
+  self->atlases = g_ptr_array_new_with_free_func ((GDestroyNotify)free_atlas);
   self->icons = g_hash_table_new_full (NULL, NULL, NULL, icon_data_free);
 }
 
@@ -41,7 +52,14 @@ gsk_gl_icon_cache_free (GskGLIconCache *self)
     {
       GskGLTextureAtlas *atlas = g_ptr_array_index (self->atlases, i);
 
+      if (atlas->image.texture_id != 0)
+        {
+          gsk_gl_image_destroy (&atlas->image, self->gl_driver);
+          atlas->image.texture_id = 0;
+        }
+
       gsk_gl_texture_atlas_free (atlas);
+
       g_free (atlas);
     }
   g_ptr_array_free (self->atlases, TRUE);
@@ -92,6 +110,12 @@ gsk_gl_icon_cache_begin_frame (GskGLIconCache *self)
                 g_hash_table_iter_remove (&iter);
             }
 
+          if (atlas->image.texture_id != 0)
+            {
+              gsk_gl_image_destroy (&atlas->image, self->gl_driver);
+              atlas->image.texture_id = 0;
+            }
+
           g_ptr_array_remove_index_fast (self->atlases, i);
           i --; /* Check the current index again */
         }


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