From 1c48a7ef06b82ef9ca013066d1fb3c6fda82aa0c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 25 Aug 2018 23:54:06 -0700 Subject: [PATCH] [ot-font] Cache tables on face, not font --- src/hb-ot-cmap-table.hh | 1 + src/hb-ot-face.cc | 2 + src/hb-ot-face.hh | 55 ++++++++++++++++++++++---- src/hb-ot-font.cc | 75 +++--------------------------------- src/hb-ot-layout-gsubgpos.hh | 1 + src/hb-ot-layout.hh | 1 - 6 files changed, 58 insertions(+), 77 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index dce298138..6ff23e3d3 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -1017,6 +1017,7 @@ struct cmap { inline void init (hb_face_t *face) { + /* TODO Switch to using table from face->ot.table. */ this->blob = hb_sanitize_context_t().reference_table (face); const cmap *table = this->blob->as (); const CmapSubtableFormat14 *subtable_uvs = nullptr; diff --git a/src/hb-ot-face.cc b/src/hb-ot-face.cc index 819a90008..121037f83 100644 --- a/src/hb-ot-face.cc +++ b/src/hb-ot-face.cc @@ -156,6 +156,7 @@ _hb_ot_face_data_create (hb_face_t *face) return nullptr; data->table.init0 (face); + data->accel.init0 (face); const OT::GSUB &gsub = *data->table.GSUB; const OT::GPOS &gpos = *data->table.GPOS; @@ -199,6 +200,7 @@ _hb_ot_face_data_destroy (hb_ot_face_data_t *data) free (data->gsub_accels); free (data->gpos_accels); + data->accel.fini (); data->table.fini (); free (data); diff --git a/src/hb-ot-face.hh b/src/hb-ot-face.hh index ade14f4a6..25d830d10 100644 --- a/src/hb-ot-face.hh +++ b/src/hb-ot-face.hh @@ -34,6 +34,13 @@ #include "hb-machinery.hh" #include "hb-set-digest.hh" +#include "hb-ot-cmap-table.hh" +#include "hb-ot-glyf-table.hh" +#include "hb-ot-hmtx-table.hh" +#include "hb-ot-kern-table.hh" +#include "hb-ot-post-table.hh" +#include "hb-ot-color-cbdt-table.hh" + /* * hb_ot_face_data_t @@ -98,13 +105,7 @@ HB_OT_LAYOUT_TABLES struct hb_ot_face_data_t { - unsigned int gsub_lookup_count; - unsigned int gpos_lookup_count; - - hb_ot_layout_lookup_accelerator_t *gsub_accels; - hb_ot_layout_lookup_accelerator_t *gpos_accels; - - /* Various non-shaping tables. */ + /* All the president's tables. */ struct tables_t { HB_INTERNAL void init0 (hb_face_t *face); @@ -127,6 +128,46 @@ struct hb_ot_face_data_t HB_OT_LAYOUT_TABLES #undef HB_OT_LAYOUT_TABLE } table; + + struct accelerator_t + { + inline void init0 (hb_face_t *face) + { + this->face = face; + cmap.init0 (); + h_metrics.init0 (); + v_metrics.init0 (); + glyf.init0 (); + cbdt.init0 (); + post.init0 (); + kern.init0 (); + } + inline void fini (void) + { + cmap.fini (); + h_metrics.fini (); + v_metrics.fini (); + glyf.fini (); + cbdt.fini (); + post.fini (); + kern.fini (); + } + + hb_face_t *face; /* MUST be JUST before the lazy loaders. */ + hb_face_lazy_loader_t<1, OT::cmap::accelerator_t> cmap; + hb_face_lazy_loader_t<2, OT::hmtx::accelerator_t> h_metrics; + hb_face_lazy_loader_t<3, OT::vmtx::accelerator_t> v_metrics; + hb_face_lazy_loader_t<4, OT::glyf::accelerator_t> glyf; + hb_face_lazy_loader_t<5, OT::CBDT::accelerator_t> cbdt; + hb_face_lazy_loader_t<6, OT::post::accelerator_t> post; + hb_face_lazy_loader_t<7, OT::kern::accelerator_t> kern; + } accel; + + /* More accelerators. Merge into previous. */ + unsigned int gsub_lookup_count; + unsigned int gpos_lookup_count; + hb_ot_layout_lookup_accelerator_t *gsub_accels; + hb_ot_layout_lookup_accelerator_t *gpos_accels; }; diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 1ec6423ec..60af5fb19 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -30,73 +30,10 @@ #include "hb-font.hh" #include "hb-machinery.hh" - -#include "hb-ot-cmap-table.hh" -#include "hb-ot-glyf-table.hh" -#include "hb-ot-hmtx-table.hh" -#include "hb-ot-kern-table.hh" -#include "hb-ot-post-table.hh" - -#include "hb-ot-color-cbdt-table.hh" +#include "hb-ot-face.hh" -struct hb_ot_font_t -{ - inline void init0 (hb_face_t *face) - { - this->face = face; - cmap.init0 (); - h_metrics.init0 (); - v_metrics.init0 (); - glyf.init0 (); - cbdt.init0 (); - post.init0 (); - kern.init0 (); - } - inline void fini (void) - { - cmap.fini (); - h_metrics.fini (); - v_metrics.fini (); - glyf.fini (); - cbdt.fini (); - post.fini (); - kern.fini (); - } - - hb_face_t *face; /* MUST be JUST before the lazy loaders. */ - hb_face_lazy_loader_t<1, OT::cmap::accelerator_t> cmap; - hb_face_lazy_loader_t<2, OT::hmtx::accelerator_t> h_metrics; - hb_face_lazy_loader_t<3, OT::vmtx::accelerator_t> v_metrics; - hb_face_lazy_loader_t<4, OT::glyf::accelerator_t> glyf; - hb_face_lazy_loader_t<5, OT::CBDT::accelerator_t> cbdt; - hb_face_lazy_loader_t<6, OT::post::accelerator_t> post; - hb_face_lazy_loader_t<7, OT::kern::accelerator_t> kern; -}; - - -static hb_ot_font_t * -_hb_ot_font_create (hb_face_t *face) -{ - hb_ot_font_t *ot_font = (hb_ot_font_t *) calloc (1, sizeof (hb_ot_font_t)); - - if (unlikely (!ot_font)) - return nullptr; - - ot_font->init0 (face); - - return ot_font; -} - -static void -_hb_ot_font_destroy (void *data) -{ - hb_ot_font_t *ot_font = (hb_ot_font_t *) data; - - ot_font->fini (); - - free (ot_font); -} +typedef hb_ot_face_data_t::accelerator_t hb_ot_font_t; static hb_bool_t @@ -281,10 +218,10 @@ _hb_ot_get_font_funcs (void) void hb_ot_font_set_funcs (hb_font_t *font) { - hb_ot_font_t *ot_font = _hb_ot_font_create (font->face); - if (unlikely (!ot_font)) - return; + if (unlikely (!hb_ot_shaper_face_data_ensure (font->face))) return; + hb_ot_font_t *ot_font = &hb_ot_face_data (font->face)->accel; + /* Load them lazies. We access them with get_relaxed() for performance. */ ot_font->cmap.get (); ot_font->h_metrics.get (); ot_font->v_metrics.get (); @@ -292,5 +229,5 @@ hb_ot_font_set_funcs (hb_font_t *font) hb_font_set_funcs (font, _hb_ot_get_font_funcs (), ot_font, - _hb_ot_font_destroy); + nullptr); } diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 76a7e2532..d21c3dea0 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -32,6 +32,7 @@ #include "hb.hh" #include "hb-buffer.hh" #include "hb-map.hh" +#include "hb-ot-face.hh" #include "hb-ot-layout-gdef-table.hh" #include "hb-set.hh" diff --git a/src/hb-ot-layout.hh b/src/hb-ot-layout.hh index 2790aecbf..fcc0998f5 100644 --- a/src/hb-ot-layout.hh +++ b/src/hb-ot-layout.hh @@ -34,7 +34,6 @@ #include "hb-font.hh" #include "hb-buffer.hh" #include "hb-open-type.hh" -#include "hb-ot-face.hh" /* Private API corresponding to hb-ot-layout.h: */