[gtk/matthiasc/color-profiles: 101/111] ngl: Don't leak textures




commit c425d318f0a8586b2f622e68f8f594aa8405b4d4
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Oct 2 12:06:28 2021 -0400

    ngl: Don't leak textures
    
    When we linearize a GL texture, we need to keep
    track of the result as a texture to be freed
    eventually.

 gsk/ngl/gskngldriver.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/gsk/ngl/gskngldriver.c b/gsk/ngl/gskngldriver.c
index 224b5bd672..e791ced04c 100644
--- a/gsk/ngl/gskngldriver.c
+++ b/gsk/ngl/gskngldriver.c
@@ -814,9 +814,9 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
                              int           mag_filter)
 {
   GdkGLContext *context;
-  GdkTexture *downloaded_texture;
+  GdkTexture *downloaded_texture = NULL;
+  guint texture_id = 0;
   GskNglTexture *t;
-  guint texture_id;
   int height;
   int width;
   int format;
@@ -826,6 +826,8 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
   g_return_val_if_fail (GSK_IS_NGL_COMMAND_QUEUE (self->command_queue), 0);
 
   context = self->command_queue->context;
+  width = gdk_texture_get_width (texture);
+  height = gdk_texture_get_height (texture);
 
   format = GL_RGBA8;
 
@@ -857,9 +859,6 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
                */
               gdk_gl_context_make_current (context);
 
-              width = gdk_texture_get_width (texture);
-              height = gdk_texture_get_height (texture);
-
               gsk_ngl_driver_create_render_target (self,
                                                    width, height,
                                                    format,
@@ -886,7 +885,18 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
 
               gsk_ngl_command_queue_bind_framebuffer (self->command_queue, prev_fbo);
 
-              return gsk_ngl_driver_release_render_target (self, target, FALSE);
+              texture_id = gsk_ngl_driver_release_render_target (self, target, FALSE);
+
+              t = gsk_ngl_texture_new (texture_id,
+                                       width, height, format, min_filter, mag_filter,
+                                       self->current_frame_id);
+
+              /* Use gsk_ngl_texture_free() as destroy notify here since we are
+               * not inserting this GskNglTexture into self->textures!
+               */
+              gdk_texture_set_render_data (texture, self, t, (GDestroyNotify)gsk_ngl_texture_free);
+
+              return texture_id;
             }
         }
       else
@@ -905,6 +915,8 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
       downloaded_texture = gdk_texture_download_texture (texture);
     }
 
+  g_assert (downloaded_texture && !texture_id);
+
   /* The download_texture() call may have switched the GL context. Make sure
    * the right context is at work again. */
   gdk_gl_context_make_current (context);
@@ -920,6 +932,8 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
                                                      min_filter,
                                                      mag_filter);
 
+  g_clear_object (&downloaded_texture);
+
   t = gsk_ngl_texture_new (texture_id,
                            width, height, format, min_filter, mag_filter,
                            self->current_frame_id);
@@ -932,8 +946,6 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
   gdk_gl_context_label_object_printf (context, GL_TEXTURE, t->texture_id,
                                       "GdkTexture<%p> %d", texture, t->texture_id);
 
-  g_clear_object (&downloaded_texture);
-
   return texture_id;
 }
 


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