Cache FreeType glyph masks may need current color.
If a FreeType font has glyphs which may need the current color this is
non-changing information, so calculate it once at and cache it. This
information is needed on evert time a scaler context rec is created and
adding the overhead of looking through the font data (especially the
extra indirections from a ttc) can take a bit of time.
Bug: b/206120675
Change-Id: I92f2083a6bbd673fc148347c4e04ed81a441c3ba
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/474059
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index 5cc4676..536201b 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -1628,7 +1628,11 @@
}
bool SkTypeface_FreeType::onGlyphMaskNeedsCurrentColor() const {
- return this->getTableSize(SkSetFourByteTag('C', 'O', 'L', 'R')) > 0;
+ fGlyphMasksMayNeedCurrentColorOnce([this]{
+ static constexpr SkFourByteTag COLRTag = SkSetFourByteTag('C', 'O', 'L', 'R');
+ fGlyphMasksMayNeedCurrentColor = this->getTableSize(COLRTag) > 0;
+ });
+ return fGlyphMasksMayNeedCurrentColor;
}
int SkTypeface_FreeType::onGetVariationDesignPosition(
diff --git a/src/ports/SkFontHost_FreeType_common.h b/src/ports/SkFontHost_FreeType_common.h
index 3cd2a83..5e6539f 100644
--- a/src/ports/SkFontHost_FreeType_common.h
+++ b/src/ports/SkFontHost_FreeType_common.h
@@ -147,6 +147,9 @@
mutable SkSharedMutex fC2GCacheMutex;
mutable SkCharToGlyphCache fC2GCache;
+ mutable SkOnce fGlyphMasksMayNeedCurrentColorOnce;
+ mutable bool fGlyphMasksMayNeedCurrentColor;
+
using INHERITED = SkTypeface;
};