diff --git a/src/OT/Var/VARC/VARC.cc b/src/OT/Var/VARC/VARC.cc index 1a22f1d81..d55e6227f 100644 --- a/src/OT/Var/VARC/VARC.cc +++ b/src/OT/Var/VARC/VARC.cc @@ -134,7 +134,7 @@ VarComponent::get_path_at (const hb_varc_context_t &c, hb_array_t coords, hb_transform_t<> total_transform, hb_ubytes_t total_record, - hb_scalar_cache_t *cache) const + _hb_scalar_cache_t *cache) const { const unsigned char *end = total_record.arrayZ + total_record.length; const unsigned char *record = total_record.arrayZ; @@ -183,7 +183,7 @@ VarComponent::get_path_at (const hb_varc_context_t &c, unsigned conditionIndex; READ_UINT32VAR (conditionIndex); const auto &condition = (&VARC+VARC.conditionList)[conditionIndex]; - auto instancer = MultiItemVarStoreInstancer(&varStore, nullptr, coords, cache); + auto instancer = MultiItemVarStoreInstancer (&varStore, nullptr, coords, cache); show = condition.evaluate (coords.arrayZ, coords.length, &instancer); } @@ -338,7 +338,7 @@ VARC::get_path_at (const hb_varc_context_t &c, hb_array_t coords, hb_transform_t<> transform, hb_codepoint_t parent_glyph, - hb_scalar_cache_t *parent_cache) const + _hb_scalar_cache_t *parent_cache) const { // Don't recurse on the same glyph. unsigned idx = glyph == parent_glyph ? @@ -394,10 +394,10 @@ VARC::get_path_at (const hb_varc_context_t &c, hb_ubytes_t record = (this+glyphRecords)[idx]; - hb_scalar_cache_t static_cache; - hb_scalar_cache_t *cache = parent_cache ? - parent_cache : - (this+varStore).create_cache (&static_cache); + _hb_scalar_cache_t static_cache; + _hb_scalar_cache_t *cache = parent_cache ? + parent_cache : + (this+varStore).create_cache (&static_cache); transform.scale (c.font->x_multf, c.font->y_multf); diff --git a/src/OT/Var/VARC/VARC.hh b/src/OT/Var/VARC/VARC.hh index 719302c93..5d9c672a4 100644 --- a/src/OT/Var/VARC/VARC.hh +++ b/src/OT/Var/VARC/VARC.hh @@ -67,7 +67,7 @@ struct VarComponent hb_array_t coords, hb_transform_t<> transform, hb_ubytes_t record, - hb_scalar_cache_t *cache = nullptr) const; + _hb_scalar_cache_t *cache = nullptr) const; }; struct VarCompositeGlyph @@ -78,7 +78,7 @@ struct VarCompositeGlyph hb_array_t coords, hb_transform_t<> transform, hb_ubytes_t record, - hb_scalar_cache_t *cache) + _hb_scalar_cache_t *cache) { while (record) { @@ -106,7 +106,7 @@ struct VARC hb_array_t coords, hb_transform_t<> transform = HB_TRANSFORM_IDENTITY, hb_codepoint_t parent_gid = HB_CODEPOINT_INVALID, - hb_scalar_cache_t *parent_cache = nullptr) const; + _hb_scalar_cache_t *parent_cache = nullptr) const; bool get_path (hb_font_t *font, diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 5c0533aad..7da14bbc0 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -2540,7 +2540,8 @@ struct SparseVarRegionAxis DEFINE_SIZE_STATIC (8); }; -struct hb_scalar_cache_t +template +struct _hb_scalar_cache_t { private: static constexpr unsigned STATIC_LENGTH = 16; @@ -2549,17 +2550,17 @@ struct hb_scalar_cache_t static constexpr float DIVISOR = 1.f / MULTIPLIER; public: - hb_scalar_cache_t () : length (STATIC_LENGTH) { clear (); } + _hb_scalar_cache_t () : length (STATIC_LENGTH) { clear (); } - hb_scalar_cache_t (const hb_scalar_cache_t&) = delete; - hb_scalar_cache_t (hb_scalar_cache_t&&) = delete; - hb_scalar_cache_t& operator= (const hb_scalar_cache_t&) = delete; - hb_scalar_cache_t& operator= (hb_scalar_cache_t&&) = delete; + _hb_scalar_cache_t (const _hb_scalar_cache_t&) = delete; + _hb_scalar_cache_t (_hb_scalar_cache_t&&) = delete; + _hb_scalar_cache_t& operator= (const _hb_scalar_cache_t&) = delete; + _hb_scalar_cache_t& operator= (_hb_scalar_cache_t&&) = delete; - static hb_scalar_cache_t *create (unsigned int count, - hb_scalar_cache_t *scratch_cache = nullptr) + static _hb_scalar_cache_t *create (unsigned int count, + _hb_scalar_cache_t *scratch_cache = nullptr) { - if (!count) return (hb_scalar_cache_t *) &Null(hb_scalar_cache_t); + if (!count) return (_hb_scalar_cache_t *) &Null(_hb_scalar_cache_t); if (scratch_cache && count <= scratch_cache->length) { @@ -2567,8 +2568,8 @@ struct hb_scalar_cache_t return scratch_cache; } - auto *cache = (hb_scalar_cache_t *) hb_malloc (sizeof (hb_scalar_cache_t) - sizeof (static_values) + sizeof (static_values[0]) * count); - if (unlikely (!cache)) return (hb_scalar_cache_t *) &Null(hb_scalar_cache_t); + auto *cache = (_hb_scalar_cache_t *) hb_malloc (sizeof (_hb_scalar_cache_t) - sizeof (static_values) + sizeof (static_values[0]) * count); + if (unlikely (!cache)) return (_hb_scalar_cache_t *) &Null(_hb_scalar_cache_t); cache->length = count; cache->clear (); @@ -2576,10 +2577,10 @@ struct hb_scalar_cache_t return cache; } - static void destroy (hb_scalar_cache_t *cache, - hb_scalar_cache_t *scratch_cache = nullptr) + static void destroy (_hb_scalar_cache_t *cache, + _hb_scalar_cache_t *scratch_cache = nullptr) { - if (cache != &Null(hb_scalar_cache_t) && cache != scratch_cache) + if (cache != &Null(_hb_scalar_cache_t) && cache != scratch_cache) hb_free (cache); } @@ -2632,11 +2633,15 @@ struct hb_scalar_cache_t *cached_value = roundf(value * MULTIPLIER); } + using type_t = std::conditional_t, int>; + private: unsigned length; - mutable hb_atomic_t static_values[STATIC_LENGTH]; + mutable type_t static_values[STATIC_LENGTH]; }; +using hb_scalar_cache_t = _hb_scalar_cache_t; + struct VarRegionList { private: @@ -2663,6 +2668,7 @@ struct VarRegionList } public: + template HB_ALWAYS_INLINE float evaluate (unsigned int region_index, const int *coords, unsigned int coord_len, @@ -2821,6 +2827,7 @@ struct SparseVariationRegion : Array16Of struct SparseVarRegionList { + template HB_ALWAYS_INLINE float evaluate (unsigned int region_index, const int *coords, unsigned int coord_len, @@ -2876,6 +2883,7 @@ struct VarData + itemCount * get_row_size (); } + template float _get_delta (unsigned int inner, const int *coords, unsigned int coord_count, const VarRegionList ®ions, @@ -2923,6 +2931,7 @@ struct VarData return delta; } + template HB_ALWAYS_INLINE float get_delta (unsigned int inner, const int *coords, unsigned int coord_count, @@ -3246,6 +3255,7 @@ struct MultiVarData + StructAfter (regionIndices).get_size (); } + template void get_delta (unsigned int inner, const int *coords, unsigned int coord_count, const SparseVarRegionList ®ions, @@ -3288,6 +3298,7 @@ struct ItemVariationStore { friend struct item_variations_t; + template hb_scalar_cache_t *create_cache () const { #ifdef HB_NO_VAR @@ -3296,12 +3307,14 @@ struct ItemVariationStore return hb_scalar_cache_t::create ((this+regions).regionCount); } + template static void destroy_cache (hb_scalar_cache_t *cache) { hb_scalar_cache_t::destroy (cache); } private: + template float get_delta (unsigned int outer, unsigned int inner, const int *coords, unsigned int coord_count, hb_scalar_cache_t *cache = nullptr) const @@ -3320,6 +3333,7 @@ struct ItemVariationStore } public: + template float get_delta (unsigned int index, const int *coords, unsigned int coord_count, hb_scalar_cache_t *cache = nullptr) const @@ -3328,6 +3342,7 @@ struct ItemVariationStore unsigned int inner = index & 0xFFFF; return get_delta (outer, inner, coords, coord_count, cache); } + template float get_delta (unsigned int index, hb_array_t coords, hb_scalar_cache_t *cache = nullptr) const @@ -3538,6 +3553,7 @@ struct ItemVariationStore struct MultiItemVariationStore { + template hb_scalar_cache_t *create_cache (hb_scalar_cache_t *static_cache = nullptr) const { #ifdef HB_NO_VAR @@ -3549,6 +3565,7 @@ struct MultiItemVariationStore return hb_scalar_cache_t::create (count, static_cache); } + template static void destroy_cache (hb_scalar_cache_t *cache, hb_scalar_cache_t *static_cache = nullptr) { @@ -3556,6 +3573,7 @@ struct MultiItemVariationStore } private: + template void get_delta (unsigned int outer, unsigned int inner, const int *coords, unsigned int coord_count, hb_array_t out, @@ -3576,6 +3594,7 @@ struct MultiItemVariationStore } public: + template void get_delta (unsigned int index, const int *coords, unsigned int coord_count, hb_array_t out, @@ -3585,6 +3604,7 @@ struct MultiItemVariationStore unsigned int inner = index & 0xFFFF; get_delta (outer, inner, coords, coord_count, out, cache); } + template void get_delta (unsigned int index, hb_array_t coords, hb_array_t out, @@ -3847,8 +3867,11 @@ struct ItemVarStoreInstancer hb_scalar_cache_t *cache; }; +template struct MultiItemVarStoreInstancer { + using hb_scalar_cache_t = _hb_scalar_cache_t; + MultiItemVarStoreInstancer (const MultiItemVariationStore *varStore, const DeltaSetIndexMap *varIdxMap, hb_array_t coords, @@ -4903,6 +4926,7 @@ struct VariationDevice private: + template float get_delta (hb_font_t *font, const ItemVariationStore &store, hb_scalar_cache_t *store_cache = nullptr) const