Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: src/pdf/SkPDFCanon.cpp

Issue 2251813006: Revert of SkPDF: cache metrics once. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pdf/SkPDFCanon.h ('k') | src/pdf/SkPDFDocument.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkImage.h" 8 #include "SkImage.h"
9 #include "SkPDFBitmap.h" 9 #include "SkPDFBitmap.h"
10 #include "SkPDFCanon.h" 10 #include "SkPDFCanon.h"
11 #include "SkPDFFont.h" 11 #include "SkPDFFont.h"
12 12
13 //////////////////////////////////////////////////////////////////////////////// 13 ////////////////////////////////////////////////////////////////////////////////
14 14
15 namespace { 15 void SkPDFCanon::reset() {
16 template <typename K, typename V> struct UnrefValue { 16 for (int i = 0; i < fFontRecords.count(); ++i) {
17 void operator()(K, V** v) { (*v)->unref(); } 17 fFontRecords[i].fFont->unref();
18 }; 18 }
19 } 19 fFontRecords.reset();
20 20
21 SkPDFCanon::~SkPDFCanon() { 21 fFunctionShaderRecords.reset();
22 fAlphaShaderRecords.reset();
23 fImageShaderRecords.reset();
24
22 // TODO(halcanary): make SkTHashSet work nicely with sk_sp<>, 25 // TODO(halcanary): make SkTHashSet work nicely with sk_sp<>,
23 // or use std::unordered_set<> 26 // or use std::unordered_set<>
24 fGraphicStateRecords.foreach ([](WrapGS w) { w.fPtr->unref(); }); 27 fGraphicStateRecords.foreach ([](WrapGS w) { w.fPtr->unref(); });
25 fPDFBitmapMap.foreach(UnrefValue<SkBitmapKey, SkPDFObject>()); 28 fGraphicStateRecords.reset();
26 fTypefaceMetrics.foreach(UnrefValue<uint32_t, SkAdvancedTypefaceMetrics>());
27 fFontDescriptors.foreach(UnrefValue<uint32_t, SkPDFDict>());
28 fFontMap.foreach(UnrefValue<uint64_t, SkPDFFont>());
29 }
30 29
31 void SkPDFCanon::reset() { 30 fPDFBitmapMap.foreach([](SkBitmapKey, SkPDFObject** p) { (*p)->unref(); });
32 this->~SkPDFCanon(); 31 fPDFBitmapMap.reset();
33 new (this)SkPDFCanon;
34 } 32 }
35 33
36 //////////////////////////////////////////////////////////////////////////////// 34 ////////////////////////////////////////////////////////////////////////////////
35
36 SkPDFFont* SkPDFCanon::findFont(uint32_t fontID,
37 uint16_t glyphID,
38 SkPDFFont** relatedFontPtr) const {
39 SkASSERT(relatedFontPtr);
40
41 SkPDFFont* relatedFont = nullptr;
42 for (int i = 0; i < fFontRecords.count(); ++i) {
43 SkPDFFont::Match match = SkPDFFont::IsMatch(
44 fFontRecords[i].fFont, fFontRecords[i].fFontID,
45 fFontRecords[i].fGlyphID, fontID, glyphID);
46 if (SkPDFFont::kExact_Match == match) {
47 return fFontRecords[i].fFont;
48 } else if (!relatedFont && SkPDFFont::kRelated_Match == match) {
49 relatedFont = fFontRecords[i].fFont;
50 }
51 }
52 *relatedFontPtr = relatedFont; // May still be nullptr.
53 return nullptr;
54 }
55
56 void SkPDFCanon::addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID) {
57 SkPDFCanon::FontRec* rec = fFontRecords.push();
58 rec->fFont = SkRef(font);
59 rec->fFontID = fontID;
60 rec->fGlyphID = fGlyphID;
61 }
62
63 ////////////////////////////////////////////////////////////////////////////////
37 64
38 template <typename T> 65 template <typename T>
39 sk_sp<SkPDFObject> find_shader(const SkTArray<T>& records, 66 sk_sp<SkPDFObject> find_shader(const SkTArray<T>& records,
40 const SkPDFShader::State& state) { 67 const SkPDFShader::State& state) {
41 for (const T& record : records) { 68 for (const T& record : records) {
42 if (record.fShaderState == state) { 69 if (record.fShaderState == state) {
43 return record.fShaderObject; 70 return record.fShaderObject;
44 } 71 }
45 } 72 }
46 return nullptr; 73 return nullptr;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 fNoSmaskGraphicState = SkPDFGraphicState::MakeNoSmaskGraphicState(); 143 fNoSmaskGraphicState = SkPDFGraphicState::MakeNoSmaskGraphicState();
117 return fNoSmaskGraphicState; 144 return fNoSmaskGraphicState;
118 } 145 }
119 sk_sp<SkPDFArray> SkPDFCanon::makeRangeObject() { 146 sk_sp<SkPDFArray> SkPDFCanon::makeRangeObject() {
120 if (fRangeObject) { 147 if (fRangeObject) {
121 return fRangeObject; 148 return fRangeObject;
122 } 149 }
123 fRangeObject = SkPDFShader::MakeRangeObject(); 150 fRangeObject = SkPDFShader::MakeRangeObject();
124 return fRangeObject; 151 return fRangeObject;
125 } 152 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFCanon.h ('k') | src/pdf/SkPDFDocument.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698