[COLR] Optimize NoVariation codepath

This commit is contained in:
Behdad Esfahbod 2025-02-18 20:28:48 -07:00
parent 4c263ecd00
commit 01f02f55a1
3 changed files with 25 additions and 21 deletions

View file

@ -2136,12 +2136,16 @@ struct COLR
const ItemVariationStore &get_var_store () const
{ return colr->get_var_store (); }
const ItemVariationStore *get_var_store_ptr () const
{ return colr->get_var_store_ptr (); }
bool has_delta_set_index_map () const
{ return colr->has_delta_set_index_map (); }
const DeltaSetIndexMap &get_delta_set_index_map () const
{ return colr->get_delta_set_index_map (); }
const DeltaSetIndexMap *get_delta_set_index_map_ptr () const
{ return colr->get_delta_set_index_map_ptr (); }
private:
hb_blob_ptr_t<COLR> colr;
@ -2234,9 +2238,13 @@ struct COLR
const DeltaSetIndexMap &get_delta_set_index_map () const
{ return has_delta_set_index_map () && hb_barrier () ? this+varIdxMap : Null (DeltaSetIndexMap); }
const DeltaSetIndexMap *get_delta_set_index_map_ptr () const
{ return has_delta_set_index_map () && hb_barrier () ? &(this+varIdxMap) : nullptr; }
const ItemVariationStore &get_var_store () const
{ return has_var_store () && hb_barrier () ? this+varStore : Null (ItemVariationStore); }
const ItemVariationStore *get_var_store_ptr () const
{ return has_var_store () && hb_barrier () ? &(this+varStore) : nullptr; }
const ClipList &get_clip_list () const
{ return has_clip_list () && hb_barrier () ? this+clipList : Null (ClipList); }
@ -2484,9 +2492,9 @@ struct COLR
* after instancing */
if (!subset_varstore (c, colr_prime)) return_trace (false);
ItemVarStoreInstancer instancer (&(get_var_store ()),
&(get_delta_set_index_map ()),
c->plan->normalized_coords.as_array ());
ItemVarStoreInstancer instancer (get_var_store_ptr (),
get_delta_set_index_map_ptr (),
c->plan->normalized_coords.as_array ());
if (!colr_prime->baseGlyphList.serialize_subset (c, baseGlyphList, this, instancer))
return_trace (false);
@ -2515,8 +2523,8 @@ struct COLR
get_extents (hb_font_t *font, hb_codepoint_t glyph, hb_glyph_extents_t *extents) const
{
ItemVarStoreInstancer instancer (&(get_var_store ()),
&(get_delta_set_index_map ()),
ItemVarStoreInstancer instancer (get_var_store_ptr (),
get_delta_set_index_map_ptr (),
hb_array (font->coords, font->num_coords));
if (get_clip (glyph, extents, instancer))
@ -2577,9 +2585,9 @@ struct COLR
bool
paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data, unsigned int palette_index, hb_color_t foreground, bool clip = true) const
{
ItemVarStoreInstancer instancer (&(get_var_store ()),
&(get_delta_set_index_map ()),
hb_array (font->coords, font->num_coords));
ItemVarStoreInstancer instancer (get_var_store_ptr (),
get_delta_set_index_map_ptr (),
hb_array (font->coords, font->num_coords));
hb_paint_context_t c (this, funcs, data, font, palette_index, foreground, instancer);
hb_decycler_node_t node (c.glyphs_decycler);

View file

@ -290,11 +290,6 @@ typedef Index NameID;
struct VarIdx : HBUINT32 {
static constexpr unsigned NO_VARIATION = 0xFFFFFFFFu;
static_assert (NO_VARIATION == HB_OT_LAYOUT_NO_VARIATIONS_INDEX, "");
static uint32_t add (uint32_t i, unsigned short v)
{
if (i == NO_VARIATION) return i;
return i + v;
}
VarIdx& operator = (uint32_t i) { HBUINT32::operator= (i); return *this; }
};
DECLARE_NULL_NAMESPACE_BYTES (OT, VarIdx);

View file

@ -3741,11 +3741,13 @@ struct ItemVarStoreInstancer
float operator() (uint32_t varIdx, unsigned short offset = 0) const
{
if (!coords || varIdx == VarIdx::NO_VARIATION)
return 0.f;
varIdx += offset;
if (varIdxMap)
varIdx = varIdxMap->map (VarIdx::add (varIdx, offset));
else
varIdx += offset;
return coords ? varStore->get_delta (varIdx, coords, cache) : 0.f;
varIdx = varIdxMap->map (varIdx);
return varStore->get_delta (varIdx, coords, cache);
}
const ItemVariationStore *varStore;
@ -3777,12 +3779,11 @@ struct MultiItemVarStoreInstancer
void operator() (hb_array_t<float> out, uint32_t varIdx, unsigned short offset = 0) const
{
if (coords)
if (coords && varIdx != VarIdx::NO_VARIATION)
{
varIdx += offset;
if (varIdxMap)
varIdx = varIdxMap->map (VarIdx::add (varIdx, offset));
else
varIdx += offset;
varIdx = varIdxMap->map (varIdx);
varStore->get_delta (varIdx, coords, out, cache);
}
else