aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf/SkPDFCanon.cpp
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2016-08-18 09:52:48 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-18 09:52:48 -0700
commitcee13425b5cd862189d1e5d7cf8f258bccae5f5d (patch)
treec09f3eef817ed91d8c5efdcfa09053203c1cb00e /src/pdf/SkPDFCanon.cpp
parent7c1235457f7ef69d3bde48306e9be528718da7e6 (diff)
SkPDF: cache metrics once.
Motivation: drawText can look up unicode mapping at draw time to see if ActualText should be used after crrev.com/2084533004 lands. For each SkTypeface, only call getAdvancedTypefaceMetrics() once per document. Cache the result in the SkPDFCanon, indexed by SkFontID. Also cache PDF FontDescriptors in the canon, also indexed by SkFontID (Type1 fonts only). Simplify PDF font lookup, map SkFontID+SkGlyphID into a uint64_t. Map that uint64_t to SkPDFFonts. Remove SkPDFCanon::findFont(), SkPDFCanon::addFont(), SkPDFFont::IsMatch(), and enum SkPDFFont::Match. SkPDFFont no longer holds on to ref of SkAdvancedTypefaceMetrics. Instead, SkPDFFont::GetFontResource() and SkPDFFont::getFontSubset() get metrics from canon. SkPDFFont multybite bool is now a function of type. GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2253993002 CQ_INCLUDE_TRYBOTS=master.client.skia:Test-Win-MSVC-GCE-CPU-AVX2-x86_64-Release-GDI-Trybot,Test-Win-MSVC-GCE-CPU-AVX2-x86_64-Debug-GDI-Trybot Review-Url: https://codereview.chromium.org/2253993002
Diffstat (limited to 'src/pdf/SkPDFCanon.cpp')
-rw-r--r--src/pdf/SkPDFCanon.cpp53
1 files changed, 13 insertions, 40 deletions
diff --git a/src/pdf/SkPDFCanon.cpp b/src/pdf/SkPDFCanon.cpp
index 3dcf4e9f0f..a804d6b47b 100644
--- a/src/pdf/SkPDFCanon.cpp
+++ b/src/pdf/SkPDFCanon.cpp
@@ -12,52 +12,25 @@
////////////////////////////////////////////////////////////////////////////////
-void SkPDFCanon::reset() {
- for (int i = 0; i < fFontRecords.count(); ++i) {
- fFontRecords[i].fFont->unref();
- }
- fFontRecords.reset();
-
- fFunctionShaderRecords.reset();
- fAlphaShaderRecords.reset();
- fImageShaderRecords.reset();
+namespace {
+template <typename K, typename V> struct UnrefValue {
+ void operator()(K, V** v) { SkSafeUnref(*v); }
+};
+}
+SkPDFCanon::~SkPDFCanon() {
// TODO(halcanary): make SkTHashSet work nicely with sk_sp<>,
// or use std::unordered_set<>
fGraphicStateRecords.foreach ([](WrapGS w) { w.fPtr->unref(); });
- fGraphicStateRecords.reset();
-
- fPDFBitmapMap.foreach([](SkBitmapKey, SkPDFObject** p) { (*p)->unref(); });
- fPDFBitmapMap.reset();
+ fPDFBitmapMap.foreach(UnrefValue<SkBitmapKey, SkPDFObject>());
+ fTypefaceMetrics.foreach(UnrefValue<uint32_t, SkAdvancedTypefaceMetrics>());
+ fFontDescriptors.foreach(UnrefValue<uint32_t, SkPDFDict>());
+ fFontMap.foreach(UnrefValue<uint64_t, SkPDFFont>());
}
-////////////////////////////////////////////////////////////////////////////////
-
-SkPDFFont* SkPDFCanon::findFont(uint32_t fontID,
- uint16_t glyphID,
- SkPDFFont** relatedFontPtr) const {
- SkASSERT(relatedFontPtr);
-
- SkPDFFont* relatedFont = nullptr;
- for (int i = 0; i < fFontRecords.count(); ++i) {
- SkPDFFont::Match match = SkPDFFont::IsMatch(
- fFontRecords[i].fFont, fFontRecords[i].fFontID,
- fFontRecords[i].fGlyphID, fontID, glyphID);
- if (SkPDFFont::kExact_Match == match) {
- return fFontRecords[i].fFont;
- } else if (!relatedFont && SkPDFFont::kRelated_Match == match) {
- relatedFont = fFontRecords[i].fFont;
- }
- }
- *relatedFontPtr = relatedFont; // May still be nullptr.
- return nullptr;
-}
-
-void SkPDFCanon::addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID) {
- SkPDFCanon::FontRec* rec = fFontRecords.push();
- rec->fFont = SkRef(font);
- rec->fFontID = fontID;
- rec->fGlyphID = fGlyphID;
+void SkPDFCanon::reset() {
+ this->~SkPDFCanon();
+ new (this)SkPDFCanon;
}
////////////////////////////////////////////////////////////////////////////////