Add dirty-state tracking to hb_font_t

This commit is contained in:
Behdad Esfahbod 2017-02-03 10:58:09 -08:00
parent 95808bad2c
commit 2171f48b4b
2 changed files with 42 additions and 0 deletions

View File

@ -116,6 +116,16 @@ struct hb_font_t {
void *user_data; void *user_data;
hb_destroy_func_t destroy; 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; 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_DATA_CREATE_FUNC_EXTRA_ARGS
#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, font); #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, font);
#include "hb-shaper-list.hh" #include "hb-shaper-list.hh"

View File

@ -1196,6 +1196,8 @@ hb_font_get_empty (void)
NULL, /* user_data */ NULL, /* user_data */
NULL, /* destroy */ NULL, /* destroy */
hb_font_t::NOTHING, /* dirty_bits */
{ {
#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID, #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
#include "hb-shaper-list.hh" #include "hb-shaper-list.hh"
@ -1348,6 +1350,11 @@ hb_font_set_parent (hb_font_t *font,
if (!parent) if (!parent)
parent = hb_font_get_empty (); parent = hb_font_get_empty ();
if (parent == font->parent)
return;
font->dirty |= font->PARENT;
hb_font_t *old = font->parent; hb_font_t *old = font->parent;
font->parent = hb_font_reference (parent); font->parent = hb_font_reference (parent);
@ -1393,6 +1400,8 @@ hb_font_set_face (hb_font_t *font,
if (font->face == face) if (font->face == face)
return; return;
font->dirty |= font->FACE;
hb_face_t *old = font->face; hb_face_t *old = font->face;
font->face = hb_face_reference (face); font->face = hb_face_reference (face);
@ -1446,6 +1455,8 @@ hb_font_set_funcs (hb_font_t *font,
if (!klass) if (!klass)
klass = hb_font_funcs_get_empty (); klass = hb_font_funcs_get_empty ();
font->dirty |= font->FUNCS;
hb_font_funcs_reference (klass); hb_font_funcs_reference (klass);
hb_font_funcs_destroy (font->klass); hb_font_funcs_destroy (font->klass);
font->klass = klass; font->klass = klass;
@ -1501,6 +1512,11 @@ hb_font_set_scale (hb_font_t *font,
if (font->immutable) if (font->immutable)
return; return;
if (font->x_scale == x_scale && font->y_scale == y_scale)
return;
font->dirty |= font->SCALE;
font->x_scale = x_scale; font->x_scale = x_scale;
font->y_scale = y_scale; font->y_scale = y_scale;
} }
@ -1542,6 +1558,11 @@ hb_font_set_ppem (hb_font_t *font,
if (font->immutable) if (font->immutable)
return; return;
if (font->x_ppem == x_ppem && font->y_ppem == y_ppem)
return;
font->dirty |= font->PPEM;
font->x_ppem = x_ppem; font->x_ppem = x_ppem;
font->y_ppem = y_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 */ int *coords, /* 2.14 normalized */
unsigned int coords_length) 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); free (font->coords);
font->coords = coords; font->coords = coords;