From f4debfb34f1a450cf360cc0b04771fc46ea4d2a9 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 26 Feb 2025 18:43:34 -0700 Subject: [PATCH] [hvgl] Use a scratch pad Towards malloc-free drawing. --- src/hb-aat-var-hvgl-table.cc | 6 +++--- src/hb-aat-var-hvgl-table.hh | 25 +++++++++++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/hb-aat-var-hvgl-table.cc b/src/hb-aat-var-hvgl-table.cc index a256ae004..52c1feb39 100644 --- a/src/hb-aat-var-hvgl-table.cc +++ b/src/hb-aat-var-hvgl-table.cc @@ -91,7 +91,7 @@ PartShape::get_path_at (const struct hvgl &hvgl, hb_draw_session_t &draw_session, hb_array_t coords, hb_array_t> transforms, - hb_vector_t &scratch, + hb_hvgl_scratch_t &scratch, signed *nodes_left, signed *edges_left, signed depth_left) const @@ -104,7 +104,7 @@ PartShape::get_path_at (const struct hvgl &hvgl, const auto &coordinates = StructAfter (padding, this); auto a = coordinates.get_coords (segmentCount); - auto &v = scratch; + auto &v = scratch.points; #ifdef __BYTE_ORDER constexpr bool le = __BYTE_ORDER == __LITTLE_ENDIAN; @@ -540,7 +540,7 @@ PartComposite::get_path_at (const struct hvgl &hvgl, hb_draw_session_t &draw_session, hb_array_t coords, hb_array_t> transforms, - hb_vector_t &scratch, + hb_hvgl_scratch_t &scratch, signed *nodes_left, signed *edges_left, signed depth_left) const diff --git a/src/hb-aat-var-hvgl-table.hh b/src/hb-aat-var-hvgl-table.hh index 0cca99a99..e6684f6d8 100644 --- a/src/hb-aat-var-hvgl-table.hh +++ b/src/hb-aat-var-hvgl-table.hh @@ -18,6 +18,13 @@ namespace AAT { using namespace OT; +struct hb_hvgl_scratch_t +{ + hb_vector_t coords_f; + hb_vector_t> transforms; + hb_vector_t points; +}; + struct hvgl; namespace hvgl_impl { @@ -103,7 +110,7 @@ struct PartShape hb_draw_session_t &draw_session, hb_array_t coords, hb_array_t> transforms, - hb_vector_t &scratch, + hb_hvgl_scratch_t &scratch, signed *nodes_left, signed *edges_left, signed depth_left) const; @@ -330,7 +337,7 @@ struct PartComposite hb_draw_session_t &draw_session, hb_array_t coords, hb_array_t> transforms, - hb_vector_t &scratch, + hb_hvgl_scratch_t &scratch, signed *nodes_left, signed *edges_left, signed depth_left) const; @@ -407,7 +414,7 @@ struct Part hb_draw_session_t &draw_session, hb_array_t coords, hb_array_t> transforms, - hb_vector_t &scratch, + hb_hvgl_scratch_t &scratch, signed *nodes_left, signed *edges_left, signed depth_left) const @@ -512,7 +519,7 @@ struct hvgl hb_draw_session_t &draw_session, hb_array_t coords, hb_array_t> transforms, - hb_vector_t &scratch, + hb_hvgl_scratch_t &scratch, signed *nodes_left, signed *edges_left, signed depth_left) const @@ -557,14 +564,17 @@ struct hvgl const auto &parts = StructAtOffset (this, partsOff); const auto &part = parts.get (gid, partCount); - hb_vector_t coords_f; + hb_hvgl_scratch_t scratch; + + auto &coords_f = scratch.coords_f; + coords_f.resize_exact (part.get_total_num_axes ()); if (unlikely (coords_f.in_error ())) return true; unsigned count = hb_min (coords.length, coords_f.length); for (unsigned i = 0; i < count; i++) coords_f.arrayZ[i] = double (coords.arrayZ[i]) * (1. / (1 << 14)); - hb_vector_t> transforms; + auto &transforms = scratch.transforms; unsigned total_num_parts = part.get_total_num_parts (); transforms.resize_exact (total_num_parts); if (unlikely (transforms.in_error ())) return true; @@ -580,8 +590,7 @@ struct hvgl return true; } - hb_vector_t scratch; - scratch.alloc (128); + scratch.points.alloc (128); return get_part_path_at (gid, draw_session, coords_f, transforms, scratch, nodes_left, edges_left, depth_left); }