Use atomic ints for upem and num_glyphs on face

This commit is contained in:
Behdad Esfahbod 2018-11-13 11:54:33 -05:00
parent 9579ed9755
commit fc44dea341
5 changed files with 31 additions and 21 deletions

View File

@ -49,7 +49,8 @@ struct lcar
unsigned int *caret_count /* IN/OUT */,
hb_position_t *caret_array /* OUT */) const
{
const OffsetTo<LigCaretClassEntry>* entry_offset = lookup.get_value (glyph, font->face->num_glyphs);
const OffsetTo<LigCaretClassEntry>* entry_offset = lookup.get_value (glyph,
font->face->get_num_glyphs ());
const LigCaretClassEntry& array = entry_offset ? this+*entry_offset : Null (LigCaretClassEntry);
if (caret_count && *caret_count)
{

View File

@ -87,8 +87,8 @@ DEFINE_NULL_INSTANCE (hb_face_t) =
nullptr, /* destroy */
0, /* index */
1000, /* upem */
0, /* num_glyphs */
HB_ATOMIC_INT_INIT (1000), /* upem */
HB_ATOMIC_INT_INIT (0), /* num_glyphs */
{
#define HB_SHAPER_IMPLEMENT(shaper) HB_ATOMIC_PTR_INIT (HB_SHAPER_DATA_INVALID),
@ -129,7 +129,7 @@ hb_face_create_for_tables (hb_reference_table_func_t reference_table_func,
face->user_data = user_data;
face->destroy = destroy;
face->num_glyphs = (unsigned int) -1;
face->num_glyphs.set_relaxed (-1);
face->table.init0 (face);
@ -445,7 +445,7 @@ hb_face_set_upem (hb_face_t *face,
if (hb_object_is_immutable (face))
return;
face->upem = upem;
face->upem.set_relaxed (upem);
}
/**
@ -480,7 +480,7 @@ hb_face_set_glyph_count (hb_face_t *face,
if (hb_object_is_immutable (face))
return;
face->num_glyphs = glyph_count;
face->num_glyphs.set_relaxed (glyph_count);
}
/**

View File

@ -49,8 +49,8 @@ struct hb_face_t
hb_destroy_func_t destroy;
unsigned int index; /* Face index in a collection, zero-based. */
mutable unsigned int upem; /* Units-per-EM. */
mutable unsigned int num_glyphs; /* Number of glyphs. */
mutable hb_atomic_int_t upem; /* Units-per-EM. */
mutable hb_atomic_int_t num_glyphs; /* Number of glyphs. */
struct hb_shaper_data_t shaper_data; /* Various shaper data. */
@ -80,21 +80,25 @@ struct hb_face_t
inline HB_PURE_FUNC unsigned int get_upem (void) const
{
if (unlikely (!upem))
load_upem ();
return upem;
unsigned int ret = upem.get_relaxed ();
if (unlikely (!ret))
{
return load_upem ();
}
return ret;
}
inline unsigned int get_num_glyphs (void) const
{
if (unlikely (num_glyphs == (unsigned int) -1))
load_num_glyphs ();
return num_glyphs;
unsigned int ret = num_glyphs.get_relaxed ();
if (unlikely (ret == (unsigned int) -1))
return load_num_glyphs ();
return ret;
}
private:
HB_INTERNAL void load_upem (void) const;
HB_INTERNAL void load_num_glyphs (void) const;
HB_INTERNAL unsigned int load_upem (void) const;
HB_INTERNAL unsigned int load_num_glyphs (void) const;
};
DECLARE_NULL_INSTANCE (hb_face_t);

View File

@ -249,7 +249,7 @@ struct sbix
/* Convert to font units. */
if (strike_ppem)
{
double scale = font->face->upem / (double) strike_ppem;
double scale = font->face->get_upem () / (double) strike_ppem;
extents->x_bearing = round (extents->x_bearing * scale);
extents->y_bearing = round (extents->y_bearing * scale);
extents->width = round (extents->width * scale);

View File

@ -46,21 +46,26 @@ DEFINE_NULL_NAMESPACE_BYTES (OT, RangeRecord) = {0x00,0x01, 0x00,0x00, 0x00, 0x0
const unsigned char _hb_Null_AAT_Lookup[2] = {0xFF, 0xFF};
void
unsigned int
hb_face_t::load_num_glyphs (void) const
{
hb_sanitize_context_t c = hb_sanitize_context_t ();
c.set_num_glyphs (0); /* So we don't recurse ad infinitum. */
hb_blob_t *maxp_blob = c.reference_table<OT::maxp> (this);
const OT::maxp *maxp_table = maxp_blob->as<OT::maxp> ();
num_glyphs = maxp_table->get_num_glyphs ();
unsigned int ret = maxp_table->get_num_glyphs ();
num_glyphs.set_relaxed (ret);
hb_blob_destroy (maxp_blob);
return ret;
}
void
unsigned int
hb_face_t::load_upem (void) const
{
upem = table.head->get_upem ();
unsigned int ret = table.head->get_upem ();
upem.set_relaxed (ret);
return ret;
}
#endif