[gtk/subpixel-positioning: 2/3] gl: implement subpixel positioning
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/subpixel-positioning: 2/3] gl: implement subpixel positioning
- Date: Thu, 25 Jul 2019 21:56:55 +0000 (UTC)
commit a49a8ead0e83838a623575aa652644ebcc34e083
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Jul 25 17:37:14 2019 -0400
gl: implement subpixel positioning
Pass the glyph position into the glyph caching functions,
not just the glyph index. This allows us to cache different
images for different subpixel positions.
gsk/gl/gskglglyphcache.c | 16 ++++++++++++----
gsk/gl/gskglglyphcacheprivate.h | 4 ++++
gsk/gl/gskglrenderer.c | 4 +++-
3 files changed, 19 insertions(+), 5 deletions(-)
---
diff --git a/gsk/gl/gskglglyphcache.c b/gsk/gl/gskglglyphcache.c
index 14ff40e453..faa5752352 100644
--- a/gsk/gl/gskglglyphcache.c
+++ b/gsk/gl/gskglglyphcache.c
@@ -82,6 +82,8 @@ glyph_cache_equal (gconstpointer v1, gconstpointer v2)
return key1->font == key2->font &&
key1->glyph == key2->glyph &&
+ key1->xshift == key2->xshift &&
+ key1->yshift == key2->yshift &&
key1->scale == key2->scale;
}
@@ -90,7 +92,7 @@ glyph_cache_hash (gconstpointer v)
{
const GlyphCacheKey *key = v;
- return GPOINTER_TO_UINT (key->font) ^ key->glyph ^ key->scale;
+ return GPOINTER_TO_UINT (key->font) ^ key->glyph ^ (key->xshift << 24) ^ (key->yshift << 26) ^ key->scale;
}
static void
@@ -147,10 +149,10 @@ render_glyph (GlyphCacheKey *key,
glyph_info.glyph = key->glyph;
glyph_info.geometry.width = value->draw_width * 1024;
if (key->glyph & PANGO_GLYPH_UNKNOWN_FLAG)
- glyph_info.geometry.x_offset = 0;
+ glyph_info.geometry.x_offset = key->xshift * 256;
else
- glyph_info.geometry.x_offset = - value->draw_x * 1024;
- glyph_info.geometry.y_offset = - value->draw_y * 1024;
+ glyph_info.geometry.x_offset = key->xshift * 256 - value->draw_x * 1024;
+ glyph_info.geometry.y_offset = key->yshift * 256 - value->draw_y * 1024;
glyph_string.num_glyphs = 1;
glyph_string.glyphs = &glyph_info;
@@ -272,10 +274,14 @@ gsk_gl_glyph_cache_get_texture (GskGLDriver *driver,
upload_glyph (&key, value);
}
+#define PHASE(x) ((x % PANGO_SCALE) * 4 / PANGO_SCALE)
+
gboolean
gsk_gl_glyph_cache_lookup (GskGLGlyphCache *cache,
PangoFont *font,
PangoGlyph glyph,
+ int x,
+ int y,
float scale,
GskGLCachedGlyph *cached_glyph_out)
{
@@ -285,6 +291,8 @@ gsk_gl_glyph_cache_lookup (GskGLGlyphCache *cache,
&(GlyphCacheKey) {
.font = font,
.glyph = glyph,
+ .xshift = PHASE (x),
+ .yshift = PHASE (y),
.scale = (guint)(scale * 1024)
});
diff --git a/gsk/gl/gskglglyphcacheprivate.h b/gsk/gl/gskglglyphcacheprivate.h
index 72fce67539..2f6b4956e7 100644
--- a/gsk/gl/gskglglyphcacheprivate.h
+++ b/gsk/gl/gskglglyphcacheprivate.h
@@ -22,6 +22,8 @@ typedef struct
{
PangoFont *font;
PangoGlyph glyph;
+ guint xshift;
+ guint yshift;
guint scale; /* times 1024 */
} GlyphCacheKey;
@@ -55,6 +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 scale,
GskGLCachedGlyph *cached_glyph_out);
void gsk_gl_glyph_cache_get_texture (GskGLDriver *driver,
diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c
index e77a9892cd..142c4bf0bc 100644
--- a/gsk/gl/gskglrenderer.c
+++ b/gsk/gl/gskglrenderer.c
@@ -595,6 +595,8 @@ render_text_node (GskGLRenderer *self,
gsk_gl_glyph_cache_lookup (self->glyph_cache,
(PangoFont *)font,
gi->glyph,
+ x_position + gi->geometry.x_offset,
+ gi->geometry.y_offset,
text_scale,
&glyph);
@@ -614,7 +616,7 @@ render_text_node (GskGLRenderer *self,
}
cx = (double)(x_position + gi->geometry.x_offset) / PANGO_SCALE;
- cy = (double)(gi->geometry.y_offset) / PANGO_SCALE;
+ cy = (double) gi->geometry.y_offset / PANGO_SCALE;
ops_set_texture (builder, glyph.texture_id);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]