gl: Slightly rework the icon cache api
authorMatthias Clasen <mclasen@redhat.com>
Tue, 15 Oct 2019 11:51:05 +0000 (07:51 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 15 Oct 2019 23:44:26 +0000 (19:44 -0400)
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
gsk/gl/gskgliconcacheprivate.h
gsk/gl/gskglrenderer.c

index fc518b88513c0e1623aa7f02f415b9cf44751f84..6c0315db1c124e1eebeee3a90c291acfdb8fbbad 100644 (file)
@@ -7,15 +7,6 @@
 
 #define MAX_FRAME_AGE 60
 
-typedef struct
-{
-  graphene_rect_t texture_rect;
-  GskGLTextureAtlas *atlas;
-  GdkTexture *source_texture;
-  guint accessed : 1;
-  guint used     : 1;
-} IconData;
-
 static void
 icon_data_free (gpointer p)
 {
@@ -100,9 +91,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;
                 }
             }
@@ -117,8 +108,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);
 
@@ -126,16 +116,15 @@ gsk_gl_icon_cache_lookup_or_add (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;
+          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;
         }
       icon_data->accessed = TRUE;
 
-      *out_texture_id = icon_data->atlas->texture_id;
-      *out_texture_rect = icon_data->texture_rect;
+      *out_icon_data = icon_data;
       return;
     }
 
@@ -155,12 +144,12 @@ gsk_gl_icon_cache_lookup_or_add (GskGLIconCache  *self,
     icon_data->atlas = atlas;
     icon_data->accessed = TRUE;
     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);
 
@@ -240,8 +229,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);
 
index 367e08ceb47a0f3a2689241bb431c71d0a58488b..e076278a4eee0936f48690f97e9b82c0e72f5e2c 100644 (file)
@@ -21,6 +21,16 @@ typedef struct
   int timestamp;
 } GskGLIconCache;
 
+typedef struct
+{
+  float x, y, x2, y2;
+  GskGLTextureAtlas *atlas;
+  guint used     : 1;
+  guint accessed : 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);
@@ -29,7 +39,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
index 886b9fdc4e51360acb4cfce315667c59659da95a..98246225053aa07e93a65b857926a4e91c55ac1b 100644 (file)
@@ -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