[gtk+] gsk: add a has_color boolean to text nodes



commit 440e5340539e1e58bc0633716ac09355adf54332
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Sep 2 11:06:20 2017 -0400

    gsk: add a has_color boolean to text nodes
    
    Currently, this information is not used since cairo_show_glyphs
    deals with color glyphs for us. But when we get to uploading
    glyphs to a texture atlas, we will need it to do the right thing.
    
    We don't look at individual glyphs here, but just whether the
    font has the has-color flag set. In practice, all glyphs in
    such a font will be color glyphs, and we can avoid loading all
    the glyphs this way.

 gsk/gskrendernodeimpl.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index 2d04bb3..0b0981e 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -26,6 +26,8 @@
 #include "gskroundedrectprivate.h"
 #include "gsktextureprivate.h"
 
+#include <cairo-ft.h>
+
 static gboolean
 check_variant_type (GVariant *variant,
                     const char *type_string,
@@ -3810,6 +3812,7 @@ struct _GskTextNode
   GskRenderNode render_node;
 
   PangoFont *font;
+  gboolean has_color;
   PangoGlyphString *glyphs;
   GdkRGBA color;
   int x_offset;
@@ -4009,6 +4012,23 @@ static const GskRenderNodeClass GSK_TEXT_NODE_CLASS = {
   gsk_text_node_deserialize
 };
 
+static gboolean
+font_has_color_glyphs (PangoFont *font)
+{
+  cairo_scaled_font_t *scaled_font;
+  gboolean has_color = FALSE;
+
+  scaled_font = pango_cairo_font_get_scaled_font ((PangoCairoFont *)font);
+  if (cairo_scaled_font_get_type (scaled_font) == CAIRO_FONT_TYPE_FT)
+    {
+      FT_Face ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
+      has_color = (FT_HAS_COLOR (ft_face) != 0);
+      cairo_ft_scaled_font_unlock_face (scaled_font);
+    }
+
+  return has_color;
+}
+
 GskRenderNode *
 gsk_text_node_new (PangoFont        *font,
                    PangoGlyphString *glyphs,
@@ -4031,6 +4051,8 @@ gsk_text_node_new (PangoFont        *font,
   self->base_x = base_x;
   self->base_y = base_y;
 
+  self->has_color = font_has_color_glyphs (font);
+
   pango_glyph_string_extents (glyphs, font, &ink_rect, NULL);
   pango_extents_to_pixels (&ink_rect, NULL);
 


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