Add dirty-state tracking to hb_font_t
authorBehdad Esfahbod <behdad@behdad.org>
Fri, 3 Feb 2017 18:58:09 +0000 (10:58 -0800)
committerBehdad Esfahbod <behdad@behdad.org>
Fri, 3 Feb 2017 18:58:09 +0000 (10:58 -0800)
src/hb-font-private.hh
src/hb-font.cc

index 53671d7..fbb16a0 100644 (file)
@@ -116,6 +116,16 @@ struct hb_font_t {
   void              *user_data;
   hb_destroy_func_t  destroy;
 
+  enum dirty_t {
+    NOTHING    = 0x0000,
+    FACE       = 0x0001,
+    PARENT     = 0x0002,
+    FUNCS      = 0x0004,
+    SCALE      = 0x0008,
+    PPEM       = 0x0010,
+    VARIATIONS = 0x0020,
+  } dirty;
+
   struct hb_shaper_data_t shaper_data;
 
 
@@ -543,6 +553,8 @@ struct hb_font_t {
   }
 };
 
+HB_MARK_AS_FLAG_T (hb_font_t::dirty_t);
+
 #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS
 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, font);
 #include "hb-shaper-list.hh"
index db3ffcc..cc0e6c3 100644 (file)
@@ -1196,6 +1196,8 @@ hb_font_get_empty (void)
     NULL, /* user_data */
     NULL, /* destroy */
 
+    hb_font_t::NOTHING, /* dirty_bits */
+
     {
 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
 #include "hb-shaper-list.hh"
@@ -1348,6 +1350,11 @@ hb_font_set_parent (hb_font_t *font,
   if (!parent)
     parent = hb_font_get_empty ();
 
+  if (parent == font->parent)
+    return;
+
+  font->dirty |= font->PARENT;
+
   hb_font_t *old = font->parent;
 
   font->parent = hb_font_reference (parent);
@@ -1393,6 +1400,8 @@ hb_font_set_face (hb_font_t *font,
   if (font->face == face)
     return;
 
+  font->dirty |= font->FACE;
+
   hb_face_t *old = font->face;
 
   font->face = hb_face_reference (face);
@@ -1446,6 +1455,8 @@ hb_font_set_funcs (hb_font_t         *font,
   if (!klass)
     klass = hb_font_funcs_get_empty ();
 
+  font->dirty |= font->FUNCS;
+
   hb_font_funcs_reference (klass);
   hb_font_funcs_destroy (font->klass);
   font->klass = klass;
@@ -1501,6 +1512,11 @@ hb_font_set_scale (hb_font_t *font,
   if (font->immutable)
     return;
 
+  if (font->x_scale == x_scale && font->y_scale == y_scale)
+    return;
+
+  font->dirty |= font->SCALE;
+
   font->x_scale = x_scale;
   font->y_scale = y_scale;
 }
@@ -1542,6 +1558,11 @@ hb_font_set_ppem (hb_font_t *font,
   if (font->immutable)
     return;
 
+  if (font->x_ppem == x_ppem && font->y_ppem == y_ppem)
+    return;
+
+  font->dirty |= font->PPEM;
+
   font->x_ppem = x_ppem;
   font->y_ppem = y_ppem;
 }
@@ -1574,6 +1595,15 @@ _hb_font_adopt_var_coords_normalized (hb_font_t *font,
                                      int *coords, /* 2.14 normalized */
                                      unsigned int coords_length)
 {
+  if (font->num_coords == coords_length &&
+      0 == memcmp (font->coords, coords, coords_length * sizeof (coords[0])))
+  {
+    free (coords);
+    return;
+  }
+
+  font->dirty |= font->VARIATIONS;
+
   free (font->coords);
 
   font->coords = coords;