[gtk/wip/chergert/const-glyph-cache] gl: avoid copying GskGLCachedGlyph in lookup



commit e32c992886a5179d2990cdd440f1d8fa73414411
Author: Christian Hergert <chergert redhat com>
Date:   Wed Oct 9 14:27:48 2019 -0700

    gl: avoid copying GskGLCachedGlyph in lookup
    
    This saves a minor amount of CPU time by avoiding the copy of structure
    on each lookup (which is short-lived).

 gsk/gl/gskglglyphcache.c        | 22 +++++++++++-----------
 gsk/gl/gskglglyphcacheprivate.h |  2 +-
 gsk/gl/gskglrenderer.c          | 24 ++++++++++++------------
 3 files changed, 24 insertions(+), 24 deletions(-)
---
diff --git a/gsk/gl/gskglglyphcache.c b/gsk/gl/gskglglyphcache.c
index 81e9481944..5e31369057 100644
--- a/gsk/gl/gskglglyphcache.c
+++ b/gsk/gl/gskglglyphcache.c
@@ -256,14 +256,14 @@ add_to_cache (GskGLGlyphCache  *self,
 #define PHASE(x) ((int)(floor (4 * (x + 0.125)) - 4 * floor (x + 0.125)))
 
 gboolean
-gsk_gl_glyph_cache_lookup (GskGLGlyphCache  *cache,
-                           PangoFont        *font,
-                           PangoGlyph        glyph,
-                           float             x,
-                           float             y,
-                           float             scale,
-                           GskGLDriver      *driver,
-                           GskGLCachedGlyph *cached_glyph_out)
+gsk_gl_glyph_cache_lookup (GskGLGlyphCache         *cache,
+                           PangoFont               *font,
+                           PangoGlyph               glyph,
+                           float                    x,
+                           float                    y,
+                           float                    scale,
+                           GskGLDriver             *driver,
+                           const GskGLCachedGlyph **cached_glyph_out)
 {
   GskGLCachedGlyph *value;
   guint xshift = PHASE (x);
@@ -333,15 +333,15 @@ gsk_gl_glyph_cache_lookup (GskGLGlyphCache  *cache,
           value->draw_height * key->scale / 1024 > 0)
         add_to_cache (cache, key, driver, value);
 
-      *cached_glyph_out = *value;
+      *cached_glyph_out = value;
       g_hash_table_insert (cache->hash_table, key, value);
     }
   else
     {
-      *cached_glyph_out = *value;
+      *cached_glyph_out = value;
     }
 
-  return cached_glyph_out->atlas != NULL;
+  return (*cached_glyph_out)->atlas != NULL;
 }
 
 void
diff --git a/gsk/gl/gskglglyphcacheprivate.h b/gsk/gl/gskglglyphcacheprivate.h
index ee1912c3a6..8d669df6e1 100644
--- a/gsk/gl/gskglglyphcacheprivate.h
+++ b/gsk/gl/gskglglyphcacheprivate.h
@@ -61,6 +61,6 @@ gboolean                 gsk_gl_glyph_cache_lookup          (GskGLGlyphCache
                                                              float                   y,
                                                              float                   scale,
                                                              GskGLDriver            *driver,
-                                                             GskGLCachedGlyph       *cached_glyph_out);
+                                                             const GskGLCachedGlyph **cached_glyph_out);
 
 #endif
diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c
index 25b4c9b420..118b67c0ec 100644
--- a/gsk/gl/gskglrenderer.c
+++ b/gsk/gl/gskglrenderer.c
@@ -584,7 +584,7 @@ render_text_node (GskGLRenderer   *self,
   for (i = 0; i < num_glyphs; i++)
     {
       const PangoGlyphInfo *gi = &glyphs[i];
-      GskGLCachedGlyph glyph;
+      const GskGLCachedGlyph *glyph;
       float glyph_x, glyph_y, glyph_w, glyph_h;
       float tx, ty, tx2, ty2;
       double cx;
@@ -606,23 +606,23 @@ render_text_node (GskGLRenderer   *self,
                                  &glyph);
 
       /* e.g. whitespace */
-      if (glyph.draw_width <= 0 || glyph.draw_height <= 0)
+      if (glyph->draw_width <= 0 || glyph->draw_height <= 0)
         goto next;
 
-      if (glyph.texture_id == 0)
+      if (glyph->texture_id == 0)
         goto next;
 
-      ops_set_texture (builder, glyph.texture_id);
+      ops_set_texture (builder, glyph->texture_id);
 
-      tx  = glyph.tx;
-      ty  = glyph.ty;
-      tx2 = tx + glyph.tw;
-      ty2 = ty + glyph.th;
+      tx  = glyph->tx;
+      ty  = glyph->ty;
+      tx2 = tx + glyph->tw;
+      ty2 = ty + glyph->th;
 
-      glyph_x = floor (x + cx + 0.125) + glyph.draw_x;
-      glyph_y = floor (y + cy + 0.125) + glyph.draw_y;
-      glyph_w = glyph.draw_width;
-      glyph_h = glyph.draw_height;
+      glyph_x = floor (x + cx + 0.125) + glyph->draw_x;
+      glyph_y = floor (y + cy + 0.125) + glyph->draw_y;
+      glyph_w = glyph->draw_width;
+      glyph_h = glyph->draw_height;
 
       ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
         { { glyph_x,           glyph_y           }, { tx,  ty  }, },


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