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

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

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 | « no previous file | src/pdf/SkPDFCanon.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 #ifndef SkPDFCanon_DEFINED 7 #ifndef SkPDFCanon_DEFINED
8 #define SkPDFCanon_DEFINED 8 #define SkPDFCanon_DEFINED
9 9
10 #include "SkPDFGraphicState.h" 10 #include "SkPDFGraphicState.h"
11 #include "SkPDFShader.h" 11 #include "SkPDFShader.h"
12 #include "SkPixelSerializer.h" 12 #include "SkPixelSerializer.h"
13 #include "SkTDArray.h" 13 #include "SkTDArray.h"
14 #include "SkTHash.h" 14 #include "SkTHash.h"
15 #include "SkBitmapKey.h" 15 #include "SkBitmapKey.h"
16 16
17 class SkAdvancedTypefaceMetrics;
18 class SkPDFFont; 17 class SkPDFFont;
19 18
20 /** 19 /**
21 * The SkPDFCanon canonicalizes objects across PDF pages 20 * The SkPDFCanon canonicalizes objects across PDF pages
22 * (SkPDFDevices) and across draw calls. 21 * (SkPDFDevices) and across draw calls.
23 * 22 *
24 * The PDF backend works correctly if: 23 * The PDF backend works correctly if:
25 * - There is no more than one SkPDFCanon for each thread. 24 * - There is no more than one SkPDFCanon for each thread.
26 * - Every SkPDFDevice is given a pointer to a SkPDFCanon on creation. 25 * - Every SkPDFDevice is given a pointer to a SkPDFCanon on creation.
27 * - All SkPDFDevices in a document share the same SkPDFCanon. 26 * - All SkPDFDevices in a document share the same SkPDFCanon.
28 * The SkPDFDocument class makes this happen by owning a single 27 * The SkPDFDocument class makes this happen by owning a single
29 * SkPDFCanon. 28 * SkPDFCanon.
30 * 29 *
31 * The addFoo() methods will ref the Foo; the canon's destructor will 30 * The addFoo() methods will ref the Foo; the canon's destructor will
32 * call foo->unref() on all of these objects. 31 * call foo->unref() on all of these objects.
33 * 32 *
34 * The findFoo() methods do not change the ref count of the Foo 33 * The findFoo() methods do not change the ref count of the Foo
35 * objects. 34 * objects.
36 */ 35 */
37 class SkPDFCanon : SkNoncopyable { 36 class SkPDFCanon : SkNoncopyable {
38 public: 37 public:
39 ~SkPDFCanon(); 38 ~SkPDFCanon() { this->reset(); }
40 39
41 // reset to original setting, unrefs all objects. 40 // reset to original setting, unrefs all objects.
42 void reset(); 41 void reset();
43 42
43 // Returns exact match if there is one. If not, it returns nullptr.
44 // If there is no exact match, but there is a related font, we
45 // still return nullptr, but also set *relatedFont.
46 SkPDFFont* findFont(uint32_t fontID,
47 uint16_t glyphID,
48 SkPDFFont** relatedFont) const;
49 void addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID);
50
44 sk_sp<SkPDFObject> findFunctionShader(const SkPDFShader::State&) const; 51 sk_sp<SkPDFObject> findFunctionShader(const SkPDFShader::State&) const;
45 void addFunctionShader(sk_sp<SkPDFObject>, SkPDFShader::State); 52 void addFunctionShader(sk_sp<SkPDFObject>, SkPDFShader::State);
46 53
47 sk_sp<SkPDFObject> findAlphaShader(const SkPDFShader::State&) const; 54 sk_sp<SkPDFObject> findAlphaShader(const SkPDFShader::State&) const;
48 void addAlphaShader(sk_sp<SkPDFObject>, SkPDFShader::State); 55 void addAlphaShader(sk_sp<SkPDFObject>, SkPDFShader::State);
49 56
50 sk_sp<SkPDFObject> findImageShader(const SkPDFShader::State&) const; 57 sk_sp<SkPDFObject> findImageShader(const SkPDFShader::State&) const;
51 void addImageShader(sk_sp<SkPDFObject>, SkPDFShader::State); 58 void addImageShader(sk_sp<SkPDFObject>, SkPDFShader::State);
52 59
53 const SkPDFGraphicState* findGraphicState(const SkPDFGraphicState&) const; 60 const SkPDFGraphicState* findGraphicState(const SkPDFGraphicState&) const;
54 void addGraphicState(const SkPDFGraphicState*); 61 void addGraphicState(const SkPDFGraphicState*);
55 62
56 sk_sp<SkPDFObject> findPDFBitmap(SkBitmapKey key) const; 63 sk_sp<SkPDFObject> findPDFBitmap(SkBitmapKey key) const;
57 void addPDFBitmap(SkBitmapKey key, sk_sp<SkPDFObject>); 64 void addPDFBitmap(SkBitmapKey key, sk_sp<SkPDFObject>);
58 65
59 SkTHashMap<uint32_t, SkAdvancedTypefaceMetrics*> fTypefaceMetrics; 66 SkTHashMap<uint32_t, bool> fCanEmbedTypeface;
60 SkTHashMap<uint32_t, SkPDFDict*> fFontDescriptors;
61 SkTHashMap<uint64_t, SkPDFFont*> fFontMap;
62 67
63 SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer.get( ); } 68 SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer.get( ); }
64 void setPixelSerializer(sk_sp<SkPixelSerializer> ps) { 69 void setPixelSerializer(sk_sp<SkPixelSerializer> ps) {
65 fPixelSerializer = std::move(ps); 70 fPixelSerializer = std::move(ps);
66 } 71 }
67 72
68 sk_sp<SkPDFStream> makeInvertFunction(); 73 sk_sp<SkPDFStream> makeInvertFunction();
69 sk_sp<SkPDFDict> makeNoSmaskGraphicState(); 74 sk_sp<SkPDFDict> makeNoSmaskGraphicState();
70 sk_sp<SkPDFArray> makeRangeObject(); 75 sk_sp<SkPDFArray> makeRangeObject();
71 76
72 private: 77 private:
78 struct FontRec {
79 SkPDFFont* fFont;
80 uint32_t fFontID;
81 uint16_t fGlyphID;
82 };
83 SkTDArray<FontRec> fFontRecords;
84
73 struct ShaderRec { 85 struct ShaderRec {
74 SkPDFShader::State fShaderState; 86 SkPDFShader::State fShaderState;
75 sk_sp<SkPDFObject> fShaderObject; 87 sk_sp<SkPDFObject> fShaderObject;
76 ShaderRec(SkPDFShader::State s, sk_sp<SkPDFObject> o) 88 ShaderRec(SkPDFShader::State s, sk_sp<SkPDFObject> o)
77 : fShaderState(std::move(s)), fShaderObject(std::move(o)) {} 89 : fShaderState(std::move(s)), fShaderObject(std::move(o)) {}
78 }; 90 };
79 SkTArray<ShaderRec> fFunctionShaderRecords; 91 SkTArray<ShaderRec> fFunctionShaderRecords;
80 SkTArray<ShaderRec> fAlphaShaderRecords; 92 SkTArray<ShaderRec> fAlphaShaderRecords;
81 SkTArray<ShaderRec> fImageShaderRecords; 93 SkTArray<ShaderRec> fImageShaderRecords;
82 94
(...skipping 16 matching lines...) Expand all
99 111
100 // TODO(halcanary): make SkTHashMap<K, sk_sp<V>> work correctly. 112 // TODO(halcanary): make SkTHashMap<K, sk_sp<V>> work correctly.
101 SkTHashMap<SkBitmapKey, SkPDFObject*> fPDFBitmapMap; 113 SkTHashMap<SkBitmapKey, SkPDFObject*> fPDFBitmapMap;
102 114
103 sk_sp<SkPixelSerializer> fPixelSerializer; 115 sk_sp<SkPixelSerializer> fPixelSerializer;
104 sk_sp<SkPDFStream> fInvertFunction; 116 sk_sp<SkPDFStream> fInvertFunction;
105 sk_sp<SkPDFDict> fNoSmaskGraphicState; 117 sk_sp<SkPDFDict> fNoSmaskGraphicState;
106 sk_sp<SkPDFArray> fRangeObject; 118 sk_sp<SkPDFArray> fRangeObject;
107 }; 119 };
108 #endif // SkPDFCanon_DEFINED 120 #endif // SkPDFCanon_DEFINED
OLDNEW
« no previous file with comments | « no previous file | src/pdf/SkPDFCanon.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698