From 9db3beb721bc472211220576a3ae7957fba21e18 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 25 Jul 2022 19:42:58 +0000 Subject: [PATCH] [repacker] include LookupList size when calculating size of 16bit space for ext promotion decisions. --- src/graph/graph.hh | 4 ++++ src/graph/gsubgpos-graph.cc | 5 ++++- src/graph/gsubgpos-graph.hh | 10 ++++++++-- src/hb-repacker.hh | 6 +++++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/graph/graph.hh b/src/graph/graph.hh index df845da9d..5c5b5a44a 100644 --- a/src/graph/graph.hh +++ b/src/graph/graph.hh @@ -111,6 +111,10 @@ struct graph_t return priority >= 3; } + size_t table_size () const { + return obj.tail - obj.head; + } + int64_t modified_distance (unsigned order) const { // TODO(garretrieger): once priority is high enough, should try diff --git a/src/graph/gsubgpos-graph.cc b/src/graph/gsubgpos-graph.cc index 12f44f83f..d12e52fee 100644 --- a/src/graph/gsubgpos-graph.cc +++ b/src/graph/gsubgpos-graph.cc @@ -34,11 +34,14 @@ make_extension_context_t::make_extension_context_t (hb_tag_t table_tag_, : table_tag (table_tag_), graph (graph_), buffer (buffer_), + lookup_list_index (0), lookups () { GSTAR* gstar = graph::GSTAR::graph_to_gstar (graph_); - if (gstar) + if (gstar) { gstar->find_lookups (graph, lookups); + lookup_list_index = gstar->get_lookup_list_index (graph_); + } unsigned extension_size = OT::ExtensionFormat1::static_size; buffer.alloc (num_non_ext_subtables () * extension_size); diff --git a/src/graph/gsubgpos-graph.hh b/src/graph/gsubgpos-graph.hh index 73abc3e70..80fffaf50 100644 --- a/src/graph/gsubgpos-graph.hh +++ b/src/graph/gsubgpos-graph.hh @@ -40,6 +40,7 @@ struct make_extension_context_t hb_tag_t table_tag; graph_t& graph; hb_vector_t& buffer; + unsigned lookup_list_index; hb_hashmap_t lookups; HB_INTERNAL make_extension_context_t (hb_tag_t table_tag_, @@ -224,12 +225,17 @@ struct GSTAR : public OT::GSUBGPOS } } + unsigned get_lookup_list_index (graph_t& graph) + { + return graph.index_for_offset (graph.root_idx (), + get_lookup_list_field_offset()); + } + template void find_lookups (graph_t& graph, hb_hashmap_t& lookups /* OUT */) { - unsigned lookup_list_idx = graph.index_for_offset (graph.root_idx (), - get_lookup_list_field_offset()); + unsigned lookup_list_idx = get_lookup_list_index (graph); const LookupList* lookupList = (const LookupList*) graph.object (lookup_list_idx).head; diff --git a/src/hb-repacker.hh b/src/hb-repacker.hh index af7017af6..d22245845 100644 --- a/src/hb-repacker.hh +++ b/src/hb-repacker.hh @@ -74,6 +74,8 @@ bool _promote_extensions_if_needed (graph::make_extension_context_t& ext_context // TODO(garretrieger): also support extension promotion during iterative resolution phase, then // we can use a less conservative threshold here. + if (!ext_context.lookups) return true; + hb_vector_t> lookup_sizes; lookup_sizes.alloc (ext_context.lookups.get_population ()); @@ -88,7 +90,9 @@ bool _promote_extensions_if_needed (graph::make_extension_context_t& ext_context lookup_sizes.qsort (compare_sizes); - size_t accumlated_bytes = 0; + size_t accumlated_bytes = + ext_context.graph.vertices_[ext_context.lookup_list_index].table_size (); + for (auto p : lookup_sizes) { unsigned lookup_index = p.first;