Chromium Code Reviews| 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 "SkImage.h" |
| 9 #include "SkPDFBitmap.h" | 9 #include "SkPDFBitmap.h" |
| 10 #include "SkPDFCanon.h" | 10 #include "SkPDFCanon.h" |
| 11 #include "SkPDFFont.h" | 11 #include "SkPDFFont.h" |
| 12 | 12 |
| 13 //////////////////////////////////////////////////////////////////////////////// | 13 //////////////////////////////////////////////////////////////////////////////// |
| 14 | 14 |
| 15 void SkPDFCanon::reset() { | 15 SkPDFCanon::~SkPDFCanon() { |
| 16 for (int i = 0; i < fFontRecords.count(); ++i) { | |
| 17 fFontRecords[i].fFont->unref(); | |
| 18 } | |
| 19 fFontRecords.reset(); | |
| 20 | |
| 21 fFunctionShaderRecords.reset(); | |
| 22 fAlphaShaderRecords.reset(); | |
| 23 fImageShaderRecords.reset(); | |
| 24 | |
| 25 // TODO(halcanary): make SkTHashSet work nicely with sk_sp<>, | 16 // TODO(halcanary): make SkTHashSet work nicely with sk_sp<>, |
| 26 // or use std::unordered_set<> | 17 // or use std::unordered_set<> |
| 27 fGraphicStateRecords.foreach ([](WrapGS w) { w.fPtr->unref(); }); | 18 fGraphicStateRecords.foreach ([](WrapGS w) { w.fPtr->unref(); }); |
| 28 fGraphicStateRecords.reset(); | 19 fGraphicStateRecords.reset(); |
| 29 | 20 |
| 30 fPDFBitmapMap.foreach([](SkBitmapKey, SkPDFObject** p) { (*p)->unref(); }); | 21 fPDFBitmapMap.foreach([](SkBitmapKey, SkPDFObject** p) { (*p)->unref(); }); |
| 31 fPDFBitmapMap.reset(); | 22 } |
|
bungeman-skia
2016/08/17 18:56:04
Not clear why this reset is being removed but not
hal.canary
2016/08/17 19:29:49
Done.
| |
| 23 | |
| 24 void SkPDFCanon::reset() { | |
| 25 this->~SkPDFCanon(); | |
| 26 new (this)SkPDFCanon; | |
| 32 } | 27 } |
| 33 | 28 |
| 34 //////////////////////////////////////////////////////////////////////////////// | 29 //////////////////////////////////////////////////////////////////////////////// |
| 35 | |
| 36 SkPDFFont* SkPDFCanon::findFont(uint32_t fontID, | |
| 37 uint16_t glyphID, | |
| 38 SkPDFFont** relatedFontPtr) const { | |
| 39 SkASSERT(relatedFontPtr); | |
| 40 | |
| 41 SkPDFFont* relatedFont = nullptr; | |
| 42 for (int i = 0; i < fFontRecords.count(); ++i) { | |
| 43 SkPDFFont::Match match = SkPDFFont::IsMatch( | |
| 44 fFontRecords[i].fFont, fFontRecords[i].fFontID, | |
| 45 fFontRecords[i].fGlyphID, fontID, glyphID); | |
| 46 if (SkPDFFont::kExact_Match == match) { | |
| 47 return fFontRecords[i].fFont; | |
| 48 } else if (!relatedFont && SkPDFFont::kRelated_Match == match) { | |
| 49 relatedFont = fFontRecords[i].fFont; | |
| 50 } | |
| 51 } | |
| 52 *relatedFontPtr = relatedFont; // May still be nullptr. | |
| 53 return nullptr; | |
| 54 } | |
| 55 | |
| 56 void SkPDFCanon::addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID) { | |
| 57 SkPDFCanon::FontRec* rec = fFontRecords.push(); | |
| 58 rec->fFont = SkRef(font); | |
| 59 rec->fFontID = fontID; | |
| 60 rec->fGlyphID = fGlyphID; | |
| 61 } | |
| 62 | |
| 63 //////////////////////////////////////////////////////////////////////////////// | |
| 64 | 30 |
| 65 template <typename T> | 31 template <typename T> |
| 66 sk_sp<SkPDFObject> find_shader(const SkTArray<T>& records, | 32 sk_sp<SkPDFObject> find_shader(const SkTArray<T>& records, |
| 67 const SkPDFShader::State& state) { | 33 const SkPDFShader::State& state) { |
| 68 for (const T& record : records) { | 34 for (const T& record : records) { |
| 69 if (record.fShaderState == state) { | 35 if (record.fShaderState == state) { |
| 70 return record.fShaderObject; | 36 return record.fShaderObject; |
| 71 } | 37 } |
| 72 } | 38 } |
| 73 return nullptr; | 39 return nullptr; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 fNoSmaskGraphicState = SkPDFGraphicState::MakeNoSmaskGraphicState(); | 109 fNoSmaskGraphicState = SkPDFGraphicState::MakeNoSmaskGraphicState(); |
| 144 return fNoSmaskGraphicState; | 110 return fNoSmaskGraphicState; |
| 145 } | 111 } |
| 146 sk_sp<SkPDFArray> SkPDFCanon::makeRangeObject() { | 112 sk_sp<SkPDFArray> SkPDFCanon::makeRangeObject() { |
| 147 if (fRangeObject) { | 113 if (fRangeObject) { |
| 148 return fRangeObject; | 114 return fRangeObject; |
| 149 } | 115 } |
| 150 fRangeObject = SkPDFShader::MakeRangeObject(); | 116 fRangeObject = SkPDFShader::MakeRangeObject(); |
| 151 return fRangeObject; | 117 return fRangeObject; |
| 152 } | 118 } |
| OLD | NEW |