From 136097901b6e36f09765fec36261bba8465c6038 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 23 Apr 2024 14:40:21 -0600 Subject: [PATCH] [VarStoreInstancer] Add cache argument Not used by any clients currently (which are COLR and VARC). --- src/OT/Var/VARC/VARC.cc | 2 +- src/hb-ot-layout-common.hh | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/OT/Var/VARC/VARC.cc b/src/OT/Var/VARC/VARC.cc index 326edf2e5..ecb407e8c 100644 --- a/src/OT/Var/VARC/VARC.cc +++ b/src/OT/Var/VARC/VARC.cc @@ -144,7 +144,7 @@ VarComponent::get_path_at (hb_font_t *font, auto &VARC = *font->face->table.VARC; auto &varStore = &VARC+VARC.varStore; - auto instancer = MultiItemVarStoreInstancer(&varStore, nullptr, coords); + auto instancer = MultiItemVarStoreInstancer(&varStore, nullptr, coords, cache); #define READ_UINT32VAR(name) \ HB_STMT_START { \ diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 0ac1434e2..2bed56275 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -3715,11 +3715,11 @@ struct DeltaSetIndexMap struct ItemVarStoreInstancer { - // TODO Add varStore cache? ItemVarStoreInstancer (const ItemVariationStore *varStore, const DeltaSetIndexMap *varIdxMap, - hb_array_t coords) : - varStore (varStore), varIdxMap (varIdxMap), coords (coords) + hb_array_t coords, + VarRegionList::cache_t *cache = nullptr) : + varStore (varStore), varIdxMap (varIdxMap), coords (coords), cache (cache) { if (!varStore) varStore = &Null(ItemVariationStore); @@ -3731,20 +3731,27 @@ struct ItemVarStoreInstancer { return (*this) (varIdx); } float operator() (uint32_t varIdx, unsigned short offset = 0) const - { return coords ? varStore->get_delta (varIdxMap ? varIdxMap->map (VarIdx::add (varIdx, offset)) : varIdx + offset, coords) : 0.f; } + { + if (varIdxMap) + varIdx = varIdxMap->map (VarIdx::add (varIdx, offset)); + else + varIdx += offset; + return coords ? varStore->get_delta (varIdx, coords, cache) : 0.f; + } const ItemVariationStore *varStore; const DeltaSetIndexMap *varIdxMap; hb_array_t coords; + VarRegionList::cache_t *cache; }; struct MultiItemVarStoreInstancer { - // TODO Add varStore cache? MultiItemVarStoreInstancer (const MultiItemVariationStore *varStore, const DeltaSetIndexMap *varIdxMap, - hb_array_t coords) : - varStore (varStore), varIdxMap (varIdxMap), coords (coords) + hb_array_t coords, + SparseVarRegionList::cache_t *cache = nullptr) : + varStore (varStore), varIdxMap (varIdxMap), coords (coords), cache (cache) { if (!varStore) varStore = &Null(MultiItemVariationStore); @@ -3762,7 +3769,13 @@ struct MultiItemVarStoreInstancer void operator() (hb_array_t out, uint32_t varIdx, unsigned short offset = 0) const { if (coords) - varStore->get_delta (varIdxMap ? varIdxMap->map (VarIdx::add (varIdx, offset)) : varIdx + offset, coords, out); + { + if (varIdxMap) + varIdx = varIdxMap->map (VarIdx::add (varIdx, offset)); + else + varIdx += offset; + varStore->get_delta (varIdx, coords, out, cache); + } else for (unsigned i = 0; i < out.length; i++) out.arrayZ[i] = 0.f; @@ -3771,6 +3784,7 @@ struct MultiItemVarStoreInstancer const MultiItemVariationStore *varStore; const DeltaSetIndexMap *varIdxMap; hb_array_t coords; + SparseVarRegionList::cache_t *cache; };