| 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 | 7 |
| 8 #include "SkImage.h" |
| 8 #include "SkPDFBitmap.h" | 9 #include "SkPDFBitmap.h" |
| 9 #include "SkPDFCanon.h" | 10 #include "SkPDFCanon.h" |
| 10 #include "SkPDFFont.h" | 11 #include "SkPDFFont.h" |
| 11 #include "SkPDFShader.h" | 12 #include "SkPDFShader.h" |
| 12 | 13 |
| 13 //////////////////////////////////////////////////////////////////////////////// | 14 //////////////////////////////////////////////////////////////////////////////// |
| 14 | 15 |
| 15 void SkPDFCanon::reset() { | 16 void SkPDFCanon::reset() { |
| 16 for (int i = 0; i < fFontRecords.count(); ++i) { | 17 for (int i = 0; i < fFontRecords.count(); ++i) { |
| 17 fFontRecords[i].fFont->unref(); | 18 fFontRecords[i].fFont->unref(); |
| 18 } | 19 } |
| 19 fFontRecords.reset(); | 20 fFontRecords.reset(); |
| 20 fFunctionShaderRecords.unrefAll(); | 21 fFunctionShaderRecords.unrefAll(); |
| 21 fFunctionShaderRecords.reset(); | 22 fFunctionShaderRecords.reset(); |
| 22 fAlphaShaderRecords.unrefAll(); | 23 fAlphaShaderRecords.unrefAll(); |
| 23 fAlphaShaderRecords.reset(); | 24 fAlphaShaderRecords.reset(); |
| 24 fImageShaderRecords.unrefAll(); | 25 fImageShaderRecords.unrefAll(); |
| 25 fImageShaderRecords.reset(); | 26 fImageShaderRecords.reset(); |
| 26 fGraphicStateRecords.foreach ([](WrapGS w) { w.fPtr->unref(); }); | 27 fGraphicStateRecords.foreach ([](WrapGS w) { w.fPtr->unref(); }); |
| 27 fGraphicStateRecords.reset(); | 28 fGraphicStateRecords.reset(); |
| 28 fBitmapRecords.unrefAll(); | 29 |
| 29 fBitmapRecords.reset(); | 30 fBitmapToImageMap.foreachValue(SkSafeUnref<const SkImage>); |
| 31 fBitmapToImageMap.reset(); |
| 32 |
| 33 fPDFBitmapMap.foreachValue(SkSafeUnref<SkPDFObject>); |
| 34 fPDFBitmapMap.reset(); |
| 30 } | 35 } |
| 31 | 36 |
| 32 //////////////////////////////////////////////////////////////////////////////// | 37 //////////////////////////////////////////////////////////////////////////////// |
| 33 | 38 |
| 34 template <class T> T* assert_ptr(T* p) { SkASSERT(p); return p; } | 39 template <class T> T* assert_ptr(T* p) { SkASSERT(p); return p; } |
| 35 | 40 |
| 36 // requires `bool T::equals(const U&) const` | 41 // requires `bool T::equals(const U&) const` |
| 37 template <typename T, typename U> | 42 template <typename T, typename U> |
| 38 T* find_item(const SkTDArray<T*>& ptrArray, const U& object) { | 43 T* find_item(const SkTDArray<T*>& ptrArray, const U& object) { |
| 39 for (int i = 0; i < ptrArray.count(); ++i) { | 44 for (int i = 0; i < ptrArray.count(); ++i) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 119 |
| 115 void SkPDFCanon::addGraphicState(const SkPDFGraphicState* state) { | 120 void SkPDFCanon::addGraphicState(const SkPDFGraphicState* state) { |
| 116 SkASSERT(state); | 121 SkASSERT(state); |
| 117 WrapGS w(SkRef(state)); | 122 WrapGS w(SkRef(state)); |
| 118 SkASSERT(!fGraphicStateRecords.contains(w)); | 123 SkASSERT(!fGraphicStateRecords.contains(w)); |
| 119 fGraphicStateRecords.add(w); | 124 fGraphicStateRecords.add(w); |
| 120 } | 125 } |
| 121 | 126 |
| 122 //////////////////////////////////////////////////////////////////////////////// | 127 //////////////////////////////////////////////////////////////////////////////// |
| 123 | 128 |
| 124 SkPDFBitmap* SkPDFCanon::findBitmap(const SkBitmap& bm) const { | 129 SkPDFObject* SkPDFCanon::findPDFBitmap(const SkImage* image) const { |
| 125 return find_item(fBitmapRecords, bm); | 130 SkPDFObject** ptr = fPDFBitmapMap.find(image->uniqueID()); |
| 131 return ptr ? *ptr : nullptr; |
| 126 } | 132 } |
| 127 | 133 |
| 128 void SkPDFCanon::addBitmap(SkPDFBitmap* pdfBitmap) { | 134 void SkPDFCanon::addPDFBitmap(uint32_t imageUniqueID, SkPDFObject* pdfBitmap) { |
| 129 fBitmapRecords.push(SkRef(pdfBitmap)); | 135 fPDFBitmapMap.set(imageUniqueID, SkRef(pdfBitmap)); |
| 130 } | 136 } |
| 137 |
| 138 const SkImage* SkPDFCanon::bitmapToImage(const SkBitmap& bm) { |
| 139 // reference remains owned by the fBitmapToImageMap! |
| 140 SkBitmapKey key(bm); |
| 141 if (const SkImage** img = fBitmapToImageMap.find(key)) { |
| 142 return *img; |
| 143 } |
| 144 return *fBitmapToImageMap.set(key, SkImage::NewFromBitmap(bm)); |
| 145 } |
| OLD | NEW |