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

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

Issue 966863002: PDF: Canon now owns a reference to all interned objects (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 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
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 "SkPDFShader.h" 10 #include "SkPDFShader.h"
11 #include "SkTDArray.h" 11 #include "SkTDArray.h"
12 12
13 class SkBitmap; 13 class SkBitmap;
14 class SkPDFFont; 14 class SkPDFFont;
15 class SkPDFGraphicState; 15 class SkPDFGraphicState;
16 class SkPDFBitmap; 16 class SkPDFBitmap;
17 class SkPaint; 17 class SkPaint;
18 18
19 /** 19 /**
20 * The SkPDFCanon canonicalizes objects across PDF pages(SkPDFDevices). 20 * The SkPDFCanon canonicalizes objects across PDF pages(SkPDFDevices).
21 * 21 *
22 * The PDF backend works correctly if: 22 * The PDF backend works correctly if:
23 * - There is no more than one SkPDFCanon for each thread. 23 * - There is no more than one SkPDFCanon for each thread.
24 * - Every SkPDFDevice is given a pointer to a SkPDFCanon on creation. 24 * - Every SkPDFDevice is given a pointer to a SkPDFCanon on creation.
25 * - All SkPDFDevices in a document share the same SkPDFCanon. 25 * - All SkPDFDevices in a document share the same SkPDFCanon.
26 * The SkDocument_PDF class makes this happen by owning a single 26 * The SkDocument_PDF class makes this happen by owning a single
27 * SkPDFCanon. 27 * SkPDFCanon.
28 * 28 *
29 * Note that this class does not create, delete, reference or 29 * The addFoo() methods take a reference to a Foo; the canon's
30 * dereference the SkPDFObject objects that it indexes. It is up to 30 * destructor will call foo->unref() on all of these objects.
31 * the caller to manage the lifetime of these objects.
32 */ 31 */
33 class SkPDFCanon : SkNoncopyable { 32 class SkPDFCanon : SkNoncopyable {
34 public: 33 public:
35 SkPDFCanon(); 34 ~SkPDFCanon() { this->reset(); }
36 ~SkPDFCanon(); 35
36 // reset to original setting, unrefs all objects.
37 void reset();
37 38
38 // Returns exact match if there is one. If not, it returns NULL. 39 // Returns exact match if there is one. If not, it returns NULL.
39 // If there is no exact match, but there is a related font, we 40 // If there is no exact match, but there is a related font, we
40 // still return NULL, but also set *relatedFont. 41 // still return NULL, but also set *relatedFont.
41 SkPDFFont* findFont(uint32_t fontID, 42 SkPDFFont* findFont(uint32_t fontID,
42 uint16_t glyphID, 43 uint16_t glyphID,
43 SkPDFFont** relatedFont) const; 44 SkPDFFont** relatedFont) const;
44 void addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID); 45 void addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID);
45 void removeFont(SkPDFFont*);
46 46
47 SkPDFFunctionShader* findFunctionShader(const SkPDFShader::State&) const; 47 SkPDFFunctionShader* findFunctionShader(const SkPDFShader::State&) const;
48 void addFunctionShader(SkPDFFunctionShader*); 48 void addFunctionShader(SkPDFFunctionShader*);
49 void removeFunctionShader(SkPDFFunctionShader*);
50 49
51 SkPDFAlphaFunctionShader* findAlphaShader(const SkPDFShader::State&) const; 50 SkPDFAlphaFunctionShader* findAlphaShader(const SkPDFShader::State&) const;
52 void addAlphaShader(SkPDFAlphaFunctionShader*); 51 void addAlphaShader(SkPDFAlphaFunctionShader*);
53 void removeAlphaShader(SkPDFAlphaFunctionShader*);
54 52
55 SkPDFImageShader* findImageShader(const SkPDFShader::State&) const; 53 SkPDFImageShader* findImageShader(const SkPDFShader::State&) const;
56 void addImageShader(SkPDFImageShader*); 54 void addImageShader(SkPDFImageShader*);
57 void removeImageShader(SkPDFImageShader*);
58 55
59 SkPDFGraphicState* findGraphicState(const SkPaint&) const; 56 SkPDFGraphicState* findGraphicState(const SkPaint&) const;
60 void addGraphicState(SkPDFGraphicState*); 57 void addGraphicState(SkPDFGraphicState*);
61 void removeGraphicState(SkPDFGraphicState*);
62 58
63 SkPDFBitmap* findBitmap(const SkBitmap&) const; 59 SkPDFBitmap* findBitmap(const SkBitmap&) const;
64 void addBitmap(SkPDFBitmap*); 60 void addBitmap(SkPDFBitmap*);
65 void removeBitmap(SkPDFBitmap*);
66
67 void assertEmpty() const {
68 SkASSERT(fFontRecords.isEmpty());
69 SkASSERT(fFunctionShaderRecords.isEmpty());
70 SkASSERT(fAlphaShaderRecords.isEmpty());
71 SkASSERT(fImageShaderRecords.isEmpty());
72 SkASSERT(fGraphicStateRecords.isEmpty());
73 SkASSERT(fBitmapRecords.isEmpty());
74 }
75 61
76 private: 62 private:
77 struct FontRec { 63 struct FontRec {
78 SkPDFFont* fFont; 64 SkPDFFont* fFont;
79 uint32_t fFontID; 65 uint32_t fFontID;
80 uint16_t fGlyphID; 66 uint16_t fGlyphID;
81 }; 67 };
82 SkTDArray<FontRec> fFontRecords; 68 SkTDArray<FontRec> fFontRecords;
83 69
84 SkTDArray<SkPDFFunctionShader*> fFunctionShaderRecords; 70 SkTDArray<SkPDFFunctionShader*> fFunctionShaderRecords;
85 71
86 SkTDArray<SkPDFAlphaFunctionShader*> fAlphaShaderRecords; 72 SkTDArray<SkPDFAlphaFunctionShader*> fAlphaShaderRecords;
87 73
88 SkTDArray<SkPDFImageShader*> fImageShaderRecords; 74 SkTDArray<SkPDFImageShader*> fImageShaderRecords;
89 75
90 SkTDArray<SkPDFGraphicState*> fGraphicStateRecords; 76 SkTDArray<SkPDFGraphicState*> fGraphicStateRecords;
91 77
92 SkTDArray<SkPDFBitmap*> fBitmapRecords; 78 SkTDArray<SkPDFBitmap*> fBitmapRecords;
93 }; 79 };
94 #endif // SkPDFCanon_DEFINED 80 #endif // SkPDFCanon_DEFINED
OLDNEW
« src/pdf/SkPDFBitmap.cpp ('K') | « src/pdf/SkPDFBitmap.cpp ('k') | src/pdf/SkPDFCanon.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698