| 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 "SkBitmap.h" | |
| 11 #include "SkPDFGraphicState.h" | 10 #include "SkPDFGraphicState.h" |
| 12 #include "SkPDFShader.h" | 11 #include "SkPDFShader.h" |
| 13 #include "SkPixelSerializer.h" | 12 #include "SkPixelSerializer.h" |
| 14 #include "SkTDArray.h" | 13 #include "SkTDArray.h" |
| 15 #include "SkTHash.h" | 14 #include "SkTHash.h" |
| 15 #include "SkBitmapKey.h" |
| 16 | 16 |
| 17 class SkPDFFont; | 17 class SkPDFFont; |
| 18 class SkPaint; | 18 class SkPaint; |
| 19 class SkImage; | 19 class SkImage; |
| 20 | 20 |
| 21 class SkBitmapKey { | |
| 22 public: | |
| 23 SkBitmapKey() : fSubset(SkIRect::MakeEmpty()), fGenID(0) {} | |
| 24 explicit SkBitmapKey(const SkBitmap& bm) | |
| 25 : fSubset(bm.getSubset()), fGenID(bm.getGenerationID()) {} | |
| 26 bool operator==(const SkBitmapKey& rhs) const { | |
| 27 return fGenID == rhs.fGenID && fSubset == rhs.fSubset; | |
| 28 } | |
| 29 | |
| 30 private: | |
| 31 SkIRect fSubset; | |
| 32 uint32_t fGenID; | |
| 33 }; | |
| 34 | |
| 35 /** | 21 /** |
| 36 * The SkPDFCanon canonicalizes objects across PDF pages(SkPDFDevices). | 22 * The SkPDFCanon canonicalizes objects across PDF pages |
| 23 * (SkPDFDevices) and across draw calls. |
| 37 * | 24 * |
| 38 * The PDF backend works correctly if: | 25 * The PDF backend works correctly if: |
| 39 * - There is no more than one SkPDFCanon for each thread. | 26 * - There is no more than one SkPDFCanon for each thread. |
| 40 * - Every SkPDFDevice is given a pointer to a SkPDFCanon on creation. | 27 * - Every SkPDFDevice is given a pointer to a SkPDFCanon on creation. |
| 41 * - All SkPDFDevices in a document share the same SkPDFCanon. | 28 * - All SkPDFDevices in a document share the same SkPDFCanon. |
| 42 * The SkDocument_PDF class makes this happen by owning a single | 29 * The SkPDFDocument class makes this happen by owning a single |
| 43 * SkPDFCanon. | 30 * SkPDFCanon. |
| 44 * | 31 * |
| 45 * The addFoo() methods will ref the Foo; the canon's destructor will | 32 * The addFoo() methods will ref the Foo; the canon's destructor will |
| 46 * call foo->unref() on all of these objects. | 33 * call foo->unref() on all of these objects. |
| 47 * | 34 * |
| 48 * The findFoo() methods do not change the ref count of the Foo | 35 * The findFoo() methods do not change the ref count of the Foo |
| 49 * objects. | 36 * objects. |
| 50 */ | 37 */ |
| 51 class SkPDFCanon : SkNoncopyable { | 38 class SkPDFCanon : SkNoncopyable { |
| 52 public: | 39 public: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 68 | 55 |
| 69 SkPDFAlphaFunctionShader* findAlphaShader(const SkPDFShader::State&) const; | 56 SkPDFAlphaFunctionShader* findAlphaShader(const SkPDFShader::State&) const; |
| 70 void addAlphaShader(SkPDFAlphaFunctionShader*); | 57 void addAlphaShader(SkPDFAlphaFunctionShader*); |
| 71 | 58 |
| 72 SkPDFImageShader* findImageShader(const SkPDFShader::State&) const; | 59 SkPDFImageShader* findImageShader(const SkPDFShader::State&) const; |
| 73 void addImageShader(SkPDFImageShader*); | 60 void addImageShader(SkPDFImageShader*); |
| 74 | 61 |
| 75 const SkPDFGraphicState* findGraphicState(const SkPDFGraphicState&) const; | 62 const SkPDFGraphicState* findGraphicState(const SkPDFGraphicState&) const; |
| 76 void addGraphicState(const SkPDFGraphicState*); | 63 void addGraphicState(const SkPDFGraphicState*); |
| 77 | 64 |
| 78 SkPDFObject* findPDFBitmap(const SkImage* image) const; | 65 sk_sp<SkPDFObject> findPDFBitmap(SkBitmapKey key) const; |
| 79 void addPDFBitmap(uint32_t imageUniqueID, SkPDFObject*); | 66 void addPDFBitmap(SkBitmapKey key, sk_sp<SkPDFObject>); |
| 80 const SkImage* bitmapToImage(const SkBitmap&); | |
| 81 | 67 |
| 82 SkTHashMap<uint32_t, bool> fCanEmbedTypeface; | 68 SkTHashMap<uint32_t, bool> fCanEmbedTypeface; |
| 83 | 69 |
| 84 SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer.get(
); } | 70 SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer.get(
); } |
| 85 void setPixelSerializer(SkPixelSerializer* ps) { fPixelSerializer.reset(ps)
; } | 71 void setPixelSerializer(SkPixelSerializer* ps) { fPixelSerializer.reset(ps)
; } |
| 86 | 72 |
| 87 sk_sp<SkPDFStream> makeInvertFunction(); | 73 sk_sp<SkPDFStream> makeInvertFunction(); |
| 88 sk_sp<SkPDFDict> makeNoSmaskGraphicState(); | 74 sk_sp<SkPDFDict> makeNoSmaskGraphicState(); |
| 89 sk_sp<SkPDFArray> makeRangeObject(); | 75 sk_sp<SkPDFArray> makeRangeObject(); |
| 90 | 76 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 112 } | 98 } |
| 113 struct Hash { | 99 struct Hash { |
| 114 uint32_t operator()(const WrapGS& w) const { | 100 uint32_t operator()(const WrapGS& w) const { |
| 115 SkASSERT(w.fPtr); | 101 SkASSERT(w.fPtr); |
| 116 return w.fPtr->hash(); | 102 return w.fPtr->hash(); |
| 117 } | 103 } |
| 118 }; | 104 }; |
| 119 }; | 105 }; |
| 120 SkTHashSet<WrapGS, WrapGS::Hash> fGraphicStateRecords; | 106 SkTHashSet<WrapGS, WrapGS::Hash> fGraphicStateRecords; |
| 121 | 107 |
| 122 SkTHashMap<SkBitmapKey, const SkImage*> fBitmapToImageMap; | 108 // TODO(halcanary): make SkTHashMap<K, sk_sp<V>> work correctly. |
| 123 SkTHashMap<uint32_t /*ImageUniqueID*/, SkPDFObject*> fPDFBitmapMap; | 109 SkTHashMap<SkBitmapKey, SkPDFObject*> fPDFBitmapMap; |
| 124 | 110 |
| 125 sk_sp<SkPixelSerializer> fPixelSerializer; | 111 sk_sp<SkPixelSerializer> fPixelSerializer; |
| 126 sk_sp<SkPDFStream> fInvertFunction; | 112 sk_sp<SkPDFStream> fInvertFunction; |
| 127 sk_sp<SkPDFDict> fNoSmaskGraphicState; | 113 sk_sp<SkPDFDict> fNoSmaskGraphicState; |
| 128 sk_sp<SkPDFArray> fRangeObject; | 114 sk_sp<SkPDFArray> fRangeObject; |
| 129 }; | 115 }; |
| 130 #endif // SkPDFCanon_DEFINED | 116 #endif // SkPDFCanon_DEFINED |
| OLD | NEW |