| OLD | NEW |
| 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 will ref the Foo; the canon's destructor will |
| 30 * dereference the SkPDFObject objects that it indexes. It is up to | 30 * call foo->unref() on all of these objects. |
| 31 * the caller to manage the lifetime of these objects. | 31 * |
| 32 * The findFoo() methods do not change the ref count of the Foo |
| 33 * objects. |
| 32 */ | 34 */ |
| 33 class SkPDFCanon : SkNoncopyable { | 35 class SkPDFCanon : SkNoncopyable { |
| 34 public: | 36 public: |
| 35 SkPDFCanon(); | 37 ~SkPDFCanon() { this->reset(); } |
| 36 ~SkPDFCanon(); | 38 |
| 39 // reset to original setting, unrefs all objects. |
| 40 void reset(); |
| 37 | 41 |
| 38 // Returns exact match if there is one. If not, it returns NULL. | 42 // 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 | 43 // If there is no exact match, but there is a related font, we |
| 40 // still return NULL, but also set *relatedFont. | 44 // still return NULL, but also set *relatedFont. |
| 41 SkPDFFont* findFont(uint32_t fontID, | 45 SkPDFFont* findFont(uint32_t fontID, |
| 42 uint16_t glyphID, | 46 uint16_t glyphID, |
| 43 SkPDFFont** relatedFont) const; | 47 SkPDFFont** relatedFont) const; |
| 44 void addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID); | 48 void addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID); |
| 45 void removeFont(SkPDFFont*); | |
| 46 | 49 |
| 47 SkPDFFunctionShader* findFunctionShader(const SkPDFShader::State&) const; | 50 SkPDFFunctionShader* findFunctionShader(const SkPDFShader::State&) const; |
| 48 void addFunctionShader(SkPDFFunctionShader*); | 51 void addFunctionShader(SkPDFFunctionShader*); |
| 49 void removeFunctionShader(SkPDFFunctionShader*); | |
| 50 | 52 |
| 51 SkPDFAlphaFunctionShader* findAlphaShader(const SkPDFShader::State&) const; | 53 SkPDFAlphaFunctionShader* findAlphaShader(const SkPDFShader::State&) const; |
| 52 void addAlphaShader(SkPDFAlphaFunctionShader*); | 54 void addAlphaShader(SkPDFAlphaFunctionShader*); |
| 53 void removeAlphaShader(SkPDFAlphaFunctionShader*); | |
| 54 | 55 |
| 55 SkPDFImageShader* findImageShader(const SkPDFShader::State&) const; | 56 SkPDFImageShader* findImageShader(const SkPDFShader::State&) const; |
| 56 void addImageShader(SkPDFImageShader*); | 57 void addImageShader(SkPDFImageShader*); |
| 57 void removeImageShader(SkPDFImageShader*); | |
| 58 | 58 |
| 59 SkPDFGraphicState* findGraphicState(const SkPaint&) const; | 59 SkPDFGraphicState* findGraphicState(const SkPaint&) const; |
| 60 void addGraphicState(SkPDFGraphicState*); | 60 void addGraphicState(SkPDFGraphicState*); |
| 61 void removeGraphicState(SkPDFGraphicState*); | |
| 62 | 61 |
| 63 SkPDFBitmap* findBitmap(const SkBitmap&) const; | 62 SkPDFBitmap* findBitmap(const SkBitmap&) const; |
| 64 void addBitmap(SkPDFBitmap*); | 63 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 | 64 |
| 76 private: | 65 private: |
| 77 struct FontRec { | 66 struct FontRec { |
| 78 SkPDFFont* fFont; | 67 SkPDFFont* fFont; |
| 79 uint32_t fFontID; | 68 uint32_t fFontID; |
| 80 uint16_t fGlyphID; | 69 uint16_t fGlyphID; |
| 81 }; | 70 }; |
| 82 SkTDArray<FontRec> fFontRecords; | 71 SkTDArray<FontRec> fFontRecords; |
| 83 | 72 |
| 84 SkTDArray<SkPDFFunctionShader*> fFunctionShaderRecords; | 73 SkTDArray<SkPDFFunctionShader*> fFunctionShaderRecords; |
| 85 | 74 |
| 86 SkTDArray<SkPDFAlphaFunctionShader*> fAlphaShaderRecords; | 75 SkTDArray<SkPDFAlphaFunctionShader*> fAlphaShaderRecords; |
| 87 | 76 |
| 88 SkTDArray<SkPDFImageShader*> fImageShaderRecords; | 77 SkTDArray<SkPDFImageShader*> fImageShaderRecords; |
| 89 | 78 |
| 90 SkTDArray<SkPDFGraphicState*> fGraphicStateRecords; | 79 SkTDArray<SkPDFGraphicState*> fGraphicStateRecords; |
| 91 | 80 |
| 92 SkTDArray<SkPDFBitmap*> fBitmapRecords; | 81 SkTDArray<SkPDFBitmap*> fBitmapRecords; |
| 93 }; | 82 }; |
| 94 #endif // SkPDFCanon_DEFINED | 83 #endif // SkPDFCanon_DEFINED |
| OLD | NEW |