[gtk/glyph-cache-fixes] gl: Glyph cache fixes



commit 545f91ab4180da3cdb8f37582dd5808602d2deb2
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jul 30 22:21:52 2019 -0400

    gl: Glyph cache fixes
    
    Pass the full location to the glyph cache lookup.
    This makes the output much closer to the ciro renderer.

 gsk/gl/gskglglyphcache.c        | 19 +++++++++----------
 gsk/gl/gskglglyphcacheprivate.h |  4 ++--
 gsk/gl/gskglrenderer.c          | 14 +++++++-------
 3 files changed, 18 insertions(+), 19 deletions(-)
---
diff --git a/gsk/gl/gskglglyphcache.c b/gsk/gl/gskglglyphcache.c
index a33a1357aa..ff87229b56 100644
--- a/gsk/gl/gskglglyphcache.c
+++ b/gsk/gl/gskglglyphcache.c
@@ -237,7 +237,7 @@ add_to_cache (GskGLGlyphCache  *self,
       value->texture_id = gsk_gl_driver_create_texture (driver, width, height);
 
       gsk_gl_driver_bind_source_texture (driver, value->texture_id);
-      gsk_gl_driver_init_texture_empty (driver, value->texture_id, GL_NEAREST, GL_NEAREST);
+      gsk_gl_driver_init_texture_empty (driver, value->texture_id, GL_LINEAR, GL_LINEAR);
 
       value->tx = 0.0f;
       value->ty = 0.0f;
@@ -245,18 +245,17 @@ add_to_cache (GskGLGlyphCache  *self,
       value->th = 1.0f;
     }
 
-
   upload_glyph (key, value);
 }
 
-#define PHASE(x) ((x % PANGO_SCALE) * 4 / PANGO_SCALE)
+#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,
-                           int               x,
-                           int               y,
+                           float             x,
+                           float             y,
                            float             scale,
                            GskGLDriver      *driver,
                            GskGLCachedGlyph *cached_glyph_out)
@@ -264,6 +263,7 @@ gsk_gl_glyph_cache_lookup (GskGLGlyphCache  *cache,
   GskGLCachedGlyph *value;
   guint xshift = PHASE (x);
   guint yshift = PHASE (y);
+  const guint key_scale = (guint)(scale * 1024);
 
   value = g_hash_table_lookup (cache->hash_table,
                                &(GlyphCacheKey) {
@@ -271,7 +271,7 @@ gsk_gl_glyph_cache_lookup (GskGLGlyphCache  *cache,
                                  .glyph = glyph,
                                  .xshift = xshift,
                                  .yshift = yshift,
-                                 .scale = (guint)(scale * 1024)
+                                 .scale = key_scale
                                });
 
   if (value)
@@ -298,7 +298,6 @@ gsk_gl_glyph_cache_lookup (GskGLGlyphCache  *cache,
     {
       GlyphCacheKey *key;
       PangoRectangle ink_rect;
-      const guint key_scale = (guint)(scale * 1024);
 
       pango_font_get_glyph_extents (font, glyph, &ink_rect, NULL);
       pango_extents_to_pixels (&ink_rect, NULL);
@@ -322,11 +321,11 @@ gsk_gl_glyph_cache_lookup (GskGLGlyphCache  *cache,
       key->glyph = glyph;
       key->xshift = xshift;
       key->yshift = yshift;
-      key->scale =  key_scale;
+      key->scale = key_scale;
 
       if (key->scale > 0 &&
-          ink_rect.width * key->scale > 0 &&
-          ink_rect.height * key->scale > 0)
+          value->draw_width * key->scale / 1024 > 0 &&
+          value->draw_height * key->scale / 1024 > 0)
         add_to_cache (cache, key, driver, value);
 
       *cached_glyph_out = *value;
diff --git a/gsk/gl/gskglglyphcacheprivate.h b/gsk/gl/gskglglyphcacheprivate.h
index 0859798907..ee1912c3a6 100644
--- a/gsk/gl/gskglglyphcacheprivate.h
+++ b/gsk/gl/gskglglyphcacheprivate.h
@@ -57,8 +57,8 @@ void                     gsk_gl_glyph_cache_begin_frame     (GskGLGlyphCache
 gboolean                 gsk_gl_glyph_cache_lookup          (GskGLGlyphCache        *self,
                                                              PangoFont              *font,
                                                              PangoGlyph              glyph,
-                                                             int                     x,
-                                                             int                     y,
+                                                             float                   x,
+                                                             float                   y,
                                                              float                   scale,
                                                              GskGLDriver            *driver,
                                                              GskGLCachedGlyph       *cached_glyph_out);
diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c
index b2fee7872f..c932ef783a 100644
--- a/gsk/gl/gskglrenderer.c
+++ b/gsk/gl/gskglrenderer.c
@@ -592,11 +592,14 @@ render_text_node (GskGLRenderer   *self,
       if (gi->glyph == PANGO_GLYPH_EMPTY)
         continue;
 
+      cx = (double)(x_position + gi->geometry.x_offset) / PANGO_SCALE;
+      cy = (double)(gi->geometry.y_offset) / PANGO_SCALE;
+
       gsk_gl_glyph_cache_lookup (self->glyph_cache,
                                  (PangoFont *)font,
                                  gi->glyph,
-                                 x * PANGO_SCALE + x_position + gi->geometry.x_offset,
-+                                y * PANGO_SCALE + gi->geometry.y_offset,
+                                 x + cx,
++                                y + cy,
                                  text_scale,
                                  self->gl_driver,
                                  &glyph);
@@ -608,9 +611,6 @@ render_text_node (GskGLRenderer   *self,
       if (glyph.texture_id == 0)
         goto next;
 
-      cx = (x_position + gi->geometry.x_offset) / PANGO_SCALE;
-      cy = gi->geometry.y_offset / PANGO_SCALE;
-
       ops_set_texture (builder, glyph.texture_id);
 
       tx  = glyph.tx;
@@ -618,8 +618,8 @@ render_text_node (GskGLRenderer   *self,
       tx2 = tx + glyph.tw;
       ty2 = ty + glyph.th;
 
-      glyph_x = x + cx + glyph.draw_x;
-      glyph_y = y + cy + glyph.draw_y;
+      glyph_x = floor (x + cx) + glyph.draw_x;
+      glyph_y = floor (y + cy) + glyph.draw_y;
       glyph_w = glyph.draw_width;
       glyph_h = glyph.draw_height;
 


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