diff options
author | Raph Levien <raph@google.com> | 2016-04-06 15:19:34 -0700 |
---|---|---|
committer | Raph Levien <raph@google.com> | 2016-04-08 08:26:38 -0700 |
commit | aaa4e3470270496e6eb80704eadecb2cb7c56bf0 (patch) | |
tree | 29621172855331d3db82dc28f0c784b9f0e44d9a /include | |
parent | 9afcc6e2bd4d89e4e1deb6e18c3c4daca4e114fd (diff) | |
download | android_frameworks_minikin-aaa4e3470270496e6eb80704eadecb2cb7c56bf0.tar.gz android_frameworks_minikin-aaa4e3470270496e6eb80704eadecb2cb7c56bf0.tar.bz2 android_frameworks_minikin-aaa4e3470270496e6eb80704eadecb2cb7c56bf0.zip |
Avoid copying of font table data
The hb_font_t object holds on to tables of font data, acquired through
the MinikinFont::GetTable interface, which is based on copying data
into caller-owned buffers. Now that we're caching lots of hb_font_t's,
the cost of these buffers is significant.
This patch moves to a different interface, inspired by HarfBuzz's
hb_reference_table API, where the font can provide a pointer to the
actual font data (which will often be mmap'ed, so it doesn't even
consume physical RAM).
Bug: 27860101
Change-Id: Id766ab16a8d342bf7322a90e076e801271d527d4
Diffstat (limited to 'include')
-rw-r--r-- | include/minikin/MinikinFont.h | 22 | ||||
-rw-r--r-- | include/minikin/MinikinFontFreeType.h | 5 |
2 files changed, 23 insertions, 4 deletions
diff --git a/include/minikin/MinikinFont.h b/include/minikin/MinikinFont.h index 5c0ab0f..0298235 100644 --- a/include/minikin/MinikinFont.h +++ b/include/minikin/MinikinFont.h @@ -94,6 +94,9 @@ struct MinikinRect { class MinikinFontFreeType; +// Callback for freeing data +typedef void (*MinikinDestroyFunc) (void* data); + class MinikinFont : public MinikinRefCounted { public: virtual ~MinikinFont(); @@ -104,8 +107,23 @@ public: virtual void GetBounds(MinikinRect* bounds, uint32_t glyph_id, const MinikinPaint &paint) const = 0; - // If buf is NULL, just update size - virtual bool GetTable(uint32_t tag, uint8_t *buf, size_t *size) = 0; + virtual const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy) = 0; + + // Override if font can provide access to raw data + virtual const void* GetFontData() const { + return nullptr; + } + + // Override if font can provide access to raw data + virtual size_t GetFontSize() const { + return 0; + } + + // Override if font can provide access to raw data. + // Returns index within OpenType collection + virtual int GetFontIndex() const { + return 0; + } virtual int32_t GetUniqueId() const = 0; diff --git a/include/minikin/MinikinFontFreeType.h b/include/minikin/MinikinFontFreeType.h index a957d12..535c249 100644 --- a/include/minikin/MinikinFontFreeType.h +++ b/include/minikin/MinikinFontFreeType.h @@ -48,8 +48,9 @@ public: void GetBounds(MinikinRect* bounds, uint32_t glyph_id, const MinikinPaint& paint) const; - // If buf is NULL, just update size - bool GetTable(uint32_t tag, uint8_t *buf, size_t *size); + const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy); + + // TODO: provide access to raw data, as an optimization. int32_t GetUniqueId() const; |