[gtk/wip/matthiasc/opbuffer] gl: Slightly rework the icon cache api



commit 671ab517ae0ec2ad077e9acae1d34eefc7bd1ae9
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Oct 15 07:51:05 2019 -0400

    gl: Slightly rework the icon cache api
    
    Return a pointer to the IconData struct. This is
    closer to the glyph cache api, and will allow us
    to add similar shortcuts. For now, just store
    texture coords in the form we need, avoiding
    converting them over and over.

 gsk/gl/gskgliconcache.c        | 40 ++++++++++++++--------------------------
 gsk/gl/gskgliconcacheprivate.h | 13 +++++++++++--
 gsk/gl/gskglrenderer.c         | 29 ++++++++++++++---------------
 3 files changed, 39 insertions(+), 43 deletions(-)
---
diff --git a/gsk/gl/gskgliconcache.c b/gsk/gl/gskgliconcache.c
index 318c87fb0c..7f2e30257e 100644
--- a/gsk/gl/gskgliconcache.c
+++ b/gsk/gl/gskgliconcache.c
@@ -7,15 +7,6 @@
 
 #define MAX_FRAME_AGE (5 * 60)
 
-typedef struct
-{
-  graphene_rect_t texture_rect;
-  GskGLTextureAtlas *atlas;
-  int frame_age; /* Number of frames this icon is unused */
-  guint used: 1;
-  GdkTexture *source_texture;
-} IconData;
-
 static void
 icon_data_free (gpointer p)
 {
@@ -92,9 +83,9 @@ gsk_gl_icon_cache_begin_frame (GskGLIconCache *self,
         {
           if (icon_data->used)
             {
-              const int w = icon_data->texture_rect.size.width  * icon_data->atlas->width;
-              const int h = icon_data->texture_rect.size.height * icon_data->atlas->height;
-              gsk_gl_texture_atlas_mark_unused (icon_data->atlas, w + 2, h + 2);
+              const int width = gdk_texture_get_width (icon_data->source_texture);
+              const int height = gdk_texture_get_height (icon_data->source_texture);
+              gsk_gl_texture_atlas_mark_unused (icon_data->atlas, width + 2, height + 2);
               icon_data->used = FALSE;
             }
 
@@ -108,8 +99,7 @@ gsk_gl_icon_cache_begin_frame (GskGLIconCache *self,
 void
 gsk_gl_icon_cache_lookup_or_add (GskGLIconCache  *self,
                                  GdkTexture      *texture,
-                                 int             *out_texture_id,
-                                 graphene_rect_t *out_texture_rect)
+                                 const IconData **out_icon_data)
 {
   IconData *icon_data = g_hash_table_lookup (self->icons, texture);
 
@@ -118,15 +108,14 @@ gsk_gl_icon_cache_lookup_or_add (GskGLIconCache  *self,
       icon_data->frame_age = 0;
       if (!icon_data->used)
         {
-          const int w = icon_data->texture_rect.size.width  * icon_data->atlas->width;
-          const int h = icon_data->texture_rect.size.height * icon_data->atlas->height;
+          const int width = gdk_texture_get_width (texture);
+          const int height = gdk_texture_get_height (texture);
 
-          gsk_gl_texture_atlas_mark_used (icon_data->atlas, w + 2, h + 2);
+          gsk_gl_texture_atlas_mark_used (icon_data->atlas, width + 2, height + 2);
           icon_data->used = TRUE;
         }
 
-      *out_texture_id = icon_data->atlas->texture_id;
-      *out_texture_rect = icon_data->texture_rect;
+      *out_icon_data = icon_data;
       return;
     }
 
@@ -146,12 +135,12 @@ gsk_gl_icon_cache_lookup_or_add (GskGLIconCache  *self,
     icon_data->atlas = atlas;
     icon_data->frame_age = 0;
     icon_data->used = TRUE;
+    icon_data->texture_id = atlas->texture_id;
     icon_data->source_texture = g_object_ref (texture);
-    graphene_rect_init (&icon_data->texture_rect,
-                        (float)(packed_x + 1) / atlas->width,
-                        (float)(packed_y + 1) / atlas->height,
-                        (float)width / atlas->width,
-                        (float)height / atlas->height);
+    icon_data->x = (float)(packed_x + 1) / atlas->width;
+    icon_data->y = (float)(packed_y + 1) / atlas->width;
+    icon_data->x2 = icon_data->x + (float)width / atlas->width;
+    icon_data->y2 = icon_data->y + (float)height / atlas->height;
 
     g_hash_table_insert (self->icons, texture, icon_data);
 
@@ -231,8 +220,7 @@ gsk_gl_icon_cache_lookup_or_add (GskGLIconCache  *self,
 
     gdk_gl_context_pop_debug_group (gdk_gl_context_get_current ());
 
-    *out_texture_id = atlas->texture_id;
-    *out_texture_rect = icon_data->texture_rect;
+    *out_icon_data = icon_data;
 
     cairo_surface_destroy (surface);
 
diff --git a/gsk/gl/gskgliconcacheprivate.h b/gsk/gl/gskgliconcacheprivate.h
index 5785871bf2..4f90b7c6f0 100644
--- a/gsk/gl/gskgliconcacheprivate.h
+++ b/gsk/gl/gskgliconcacheprivate.h
@@ -20,6 +20,16 @@ typedef struct
 
 } GskGLIconCache;
 
+typedef struct
+{
+  float x, y, x2, y2;
+  GskGLTextureAtlas *atlas;
+  int frame_age; /* Number of frames this icon is unused */
+  guint used: 1;
+  int texture_id;
+  GdkTexture *source_texture;
+} IconData;
+
 GskGLIconCache * gsk_gl_icon_cache_new            (GdkDisplay *display,
                                                    GskGLTextureAtlases *atlases);
 GskGLIconCache * gsk_gl_icon_cache_ref            (GskGLIconCache        *self);
@@ -28,7 +38,6 @@ void             gsk_gl_icon_cache_begin_frame    (GskGLIconCache        *self,
                                                    GPtrArray             *removed_atlases);
 void             gsk_gl_icon_cache_lookup_or_add  (GskGLIconCache        *self,
                                                    GdkTexture            *texture,
-                                                   int                   *out_texture_id,
-                                                   graphene_rect_t       *out_texture_rect);
+                                                   const IconData       **out_icon_data);
 
 #endif
diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c
index 3ed1f302b0..9bfdeaf6ee 100644
--- a/gsk/gl/gskglrenderer.c
+++ b/gsk/gl/gskglrenderer.c
@@ -827,36 +827,35 @@ upload_texture (GskGLRenderer *self,
                 GdkTexture    *texture,
                 TextureRegion *out_region)
 {
-  int texture_id;
-
   if (texture->width <= 128 &&
       texture->height <= 128 &&
       !GDK_IS_GL_TEXTURE (texture))
     {
-      graphene_rect_t trect;
+      const IconData *icon_data;
 
       gsk_gl_icon_cache_lookup_or_add (self->icon_cache,
                                        texture,
-                                       &texture_id,
-                                       &trect);
-      out_region->x = trect.origin.x;
-      out_region->y = trect.origin.y;
-      out_region->x2 = out_region->x + trect.size.width;
-      out_region->y2 = out_region->y + trect.size.height;
+                                       &icon_data);
+
+      out_region->texture_id = icon_data->texture_id;
+      out_region->x = icon_data->x;
+      out_region->y = icon_data->y;
+      out_region->x2 = icon_data->x2;
+      out_region->y2 = icon_data->y2;
     }
   else
     {
-      texture_id = gsk_gl_driver_get_texture_for_texture (self->gl_driver,
-                                                          texture,
-                                                          GL_LINEAR,
-                                                          GL_LINEAR);
+      out_region->texture_id =
+          gsk_gl_driver_get_texture_for_texture (self->gl_driver,
+                                                 texture,
+                                                 GL_LINEAR,
+                                                 GL_LINEAR);
+
       out_region->x  = 0;
       out_region->y  = 0;
       out_region->x2 = 1;
       out_region->y2 = 1;
     }
-
-  out_region->texture_id = texture_id;
 }
 
 static inline void


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