From f97d1ea23521a92ff57e659f6078b66dcf7e79b5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 27 Mar 2024 11:38:58 -0600 Subject: [PATCH] [varc] Reuse x_deltas and y_deltas vectors Going to revert since it has minimal improvement with lots of piping through. --- src/OT/Var/VARC/VARC.cc | 7 +++++-- src/OT/Var/VARC/VARC.hh | 27 +++++++++++++++++++++------ src/OT/glyf/Glyph.hh | 5 +++++ src/OT/glyf/glyf.hh | 14 ++++++++++---- src/hb-ot-var-gvar-table.hh | 9 +++++++-- 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/OT/Var/VARC/VARC.cc b/src/OT/Var/VARC/VARC.cc index 2b0655747..7104d5499 100644 --- a/src/OT/Var/VARC/VARC.cc +++ b/src/OT/Var/VARC/VARC.cc @@ -135,7 +135,9 @@ VarComponent::get_path_at (hb_font_t *font, hb_set_t *visited, signed *edges_left, signed depth_left, - VarRegionList::cache_t *cache) const + VarRegionList::cache_t *cache, + hb_vector_t *x_deltas_cache, + hb_vector_t *y_deltas_cache) const { auto &VARC = *font->face->table.VARC; const unsigned char *end = total_record.arrayZ + total_record.length; @@ -327,7 +329,8 @@ VarComponent::get_path_at (hb_font_t *font, VARC.get_path_at (font, gid, transformer_session, component_coords, parent_gid, - visited, edges_left, depth_left - 1); + visited, edges_left, depth_left - 1, + x_deltas_cache, y_deltas_cache); } #undef PROCESS_TRANSFORM_COMPONENTS diff --git a/src/OT/Var/VARC/VARC.hh b/src/OT/Var/VARC/VARC.hh index 31e280546..da3d3238a 100644 --- a/src/OT/Var/VARC/VARC.hh +++ b/src/OT/Var/VARC/VARC.hh @@ -50,7 +50,9 @@ struct VarComponent hb_set_t *visited, signed *edges_left, signed depth_left, - VarRegionList::cache_t *cache = nullptr) const; + VarRegionList::cache_t *cache = nullptr, + hb_vector_t *x_deltas_cache = nullptr, + hb_vector_t *y_deltas_cache = nullptr) const; }; struct VarCompositeGlyph @@ -64,15 +66,25 @@ struct VarCompositeGlyph hb_set_t *visited, signed *edges_left, signed depth_left, - VarRegionList::cache_t *cache = nullptr) + VarRegionList::cache_t *cache = nullptr, + hb_vector_t *x_deltas_cache = nullptr, + hb_vector_t *y_deltas_cache = nullptr) { + hb_vector_t x_deltas_stack; + hb_vector_t y_deltas_stack; + if (x_deltas_cache == nullptr) + x_deltas_cache = &x_deltas_stack; + if (y_deltas_cache == nullptr) + y_deltas_cache = &y_deltas_stack; + while (record) { const VarComponent &comp = * (const VarComponent *) (record.arrayZ); record = comp.get_path_at (font, glyph, draw_session, coords, record, - visited, edges_left, depth_left, cache); + visited, edges_left, depth_left, + cache, x_deltas_cache, y_deltas_cache); } } }; @@ -93,7 +105,9 @@ struct VARC hb_codepoint_t parent_glyph = HB_CODEPOINT_INVALID, hb_set_t *visited = nullptr, signed *edges_left = nullptr, - signed depth_left = HB_MAX_NESTING_LEVEL) const + signed depth_left = HB_MAX_NESTING_LEVEL, + hb_vector_t *x_deltas_cache = nullptr, + hb_vector_t *y_deltas_cache = nullptr) const { hb_set_t stack_set; if (visited == nullptr) @@ -108,7 +122,7 @@ struct VARC (this+coverage).get_coverage (glyph); if (idx == NOT_COVERED) { - if (!font->face->table.glyf->get_path_at (font, glyph, draw_session, coords)) + if (!font->face->table.glyf->get_path_at (font, glyph, draw_session, coords, x_deltas_cache, y_deltas_cache)) #ifndef HB_NO_CFF if (!font->face->table.cff2->get_path_at (font, glyph, draw_session, coords)) if (!font->face->table.cff1->get_path (font, glyph, draw_session)) // Doesn't have variations @@ -138,7 +152,8 @@ struct VARC draw_session, coords, record, visited, edges_left, depth_left, - cache); + cache, + x_deltas_cache, y_deltas_cache); (this+varStore).destroy_cache (cache); diff --git a/src/OT/glyf/Glyph.hh b/src/OT/glyf/Glyph.hh index e69db96ff..5a0c8c74b 100644 --- a/src/OT/glyf/Glyph.hh +++ b/src/OT/glyf/Glyph.hh @@ -312,6 +312,8 @@ struct Glyph bool use_my_metrics = true, bool phantom_only = false, hb_array_t coords = hb_array_t (), + hb_vector_t *x_deltas_cache = nullptr, + hb_vector_t *y_deltas_cache = nullptr, hb_map_t *current_glyphs = nullptr, unsigned int depth = 0, unsigned *edge_count = nullptr) const @@ -391,6 +393,7 @@ struct Glyph glyf_accelerator.gvar->apply_deltas_to_points (gid, coords, points.as_array ().sub_array (old_length), + x_deltas_cache, y_deltas_cache, phantom_only && type == SIMPLE); #endif @@ -433,6 +436,8 @@ struct Glyph use_my_metrics, phantom_only, coords, + x_deltas_cache, + y_deltas_cache, current_glyphs, depth + 1, edge_count))) diff --git a/src/OT/glyf/glyf.hh b/src/OT/glyf/glyf.hh index f346ae05d..7a9a5d01f 100644 --- a/src/OT/glyf/glyf.hh +++ b/src/OT/glyf/glyf.hh @@ -206,7 +206,9 @@ struct glyf_accelerator_t protected: template bool get_points (hb_font_t *font, hb_codepoint_t gid, T consumer, - hb_array_t coords = hb_array_t ()) const + hb_array_t coords = hb_array_t (), + hb_vector_t *x_deltas_cache = nullptr, + hb_vector_t *y_deltas_cache = nullptr) const { if (!coords) coords = hb_array (font->coords, font->num_coords); @@ -220,7 +222,8 @@ struct glyf_accelerator_t contour_point_vector_t all_points; bool phantom_only = !consumer.is_consuming_contour_points (); - if (unlikely (!glyph_for_gid (gid).get_points (font, *this, all_points, nullptr, nullptr, nullptr, true, true, phantom_only, coords))) + if (unlikely (!glyph_for_gid (gid).get_points (font, *this, all_points, nullptr, nullptr, nullptr, true, true, phantom_only, coords, + x_deltas_cache, y_deltas_cache))) return false; unsigned count = all_points.length; @@ -414,8 +417,11 @@ struct glyf_accelerator_t bool get_path_at (hb_font_t *font, hb_codepoint_t gid, hb_draw_session_t &draw_session, - hb_array_t coords) const - { return get_points (font, gid, glyf_impl::path_builder_t (font, draw_session), coords); } + hb_array_t coords, + hb_vector_t *x_deltas_cache = nullptr, + hb_vector_t *y_deltas_cache = nullptr) const + { return get_points (font, gid, glyf_impl::path_builder_t (font, draw_session), coords, + x_deltas_cache, y_deltas_cache); } #ifndef HB_NO_VAR const gvar_accelerator_t *gvar; diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index b4f1495d1..f042cbfaa 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -623,10 +623,17 @@ struct gvar bool apply_deltas_to_points (hb_codepoint_t glyph, hb_array_t coords, const hb_array_t points, + hb_vector_t *x_deltas_cache = nullptr, + hb_vector_t *y_deltas_cache = nullptr, bool phantom_only = false) const { if (unlikely (glyph >= glyphCount)) return true; + hb_vector_t x_deltas_stack; + hb_vector_t y_deltas_stack; + hb_vector_t &x_deltas = x_deltas_cache ? *x_deltas_cache : x_deltas_stack; + hb_vector_t &y_deltas = y_deltas_cache ? *y_deltas_cache : y_deltas_stack; + hb_bytes_t var_data_bytes = table->get_glyph_var_data_bytes (table.get_blob (), glyphCount, glyph); if (!var_data_bytes.as ()->has_data ()) return true; hb_vector_t shared_indices; @@ -650,8 +657,6 @@ struct gvar hb_array_t shared_tuples = (table+table->sharedTuples).as_array (table->sharedTupleCount * num_coords); hb_vector_t private_indices; - hb_vector_t x_deltas; - hb_vector_t y_deltas; unsigned count = points.length; bool flush = false; do