| Index: src/pdf/SkPDFCanon.cpp
|
| diff --git a/src/pdf/SkPDFCanon.cpp b/src/pdf/SkPDFCanon.cpp
|
| index 8bbe835028d0742333418a0e07eef7cefce8907d..eda255051ad66d54d6d733bfd8cae03356b2c38a 100644
|
| --- a/src/pdf/SkPDFCanon.cpp
|
| +++ b/src/pdf/SkPDFCanon.cpp
|
| @@ -13,24 +13,27 @@
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
|
|
| -SkPDFCanon::SkPDFCanon() {}
|
| -
|
| -SkPDFCanon::~SkPDFCanon() {}
|
| +void SkPDFCanon::reset() {
|
| + for (int i = 0; i < fFontRecords.count(); ++i) {
|
| + fFontRecords[i].fFont->unref();
|
| + }
|
| + fFontRecords.reset();
|
| + fFunctionShaderRecords.unrefAll();
|
| + fFunctionShaderRecords.reset();
|
| + fAlphaShaderRecords.unrefAll();
|
| + fAlphaShaderRecords.reset();
|
| + fImageShaderRecords.unrefAll();
|
| + fImageShaderRecords.reset();
|
| + fGraphicStateRecords.unrefAll();
|
| + fGraphicStateRecords.reset();
|
| + fBitmapRecords.unrefAll();
|
| + fBitmapRecords.reset();
|
| +}
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
|
|
| template <class T> T* assert_ptr(T* p) { SkASSERT(p); return p; }
|
|
|
| -template <typename T>
|
| -bool remove_item(SkTDArray<T>* array, const T& elem) {
|
| - int i = array->find(elem);
|
| - if (i >= 0) {
|
| - array->removeShuffle(i);
|
| - return true;
|
| - }
|
| - return false;
|
| -}
|
| -
|
| // requires `bool T::equals(const U&) const`
|
| template <typename T, typename U>
|
| T* find_item(const SkTDArray<T*>& ptrArray, const U& object) {
|
| @@ -66,21 +69,11 @@ SkPDFFont* SkPDFCanon::findFont(uint32_t fontID,
|
|
|
| void SkPDFCanon::addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID) {
|
| SkPDFCanon::FontRec* rec = fFontRecords.push();
|
| - rec->fFont = font;
|
| + rec->fFont = SkRef(font);
|
| rec->fFontID = fontID;
|
| rec->fGlyphID = fGlyphID;
|
| }
|
|
|
| -void SkPDFCanon::removeFont(SkPDFFont* pdfFont) {
|
| - for (int i = 0; i < fFontRecords.count(); i++) {
|
| - if (fFontRecords[i].fFont == pdfFont) {
|
| - fFontRecords.removeShuffle(i);
|
| - return;
|
| - }
|
| - }
|
| - // Not all SkPDFFonts are added to the Canon.
|
| -}
|
| -
|
| ////////////////////////////////////////////////////////////////////////////////
|
|
|
| SkPDFFunctionShader* SkPDFCanon::findFunctionShader(
|
| @@ -88,10 +81,7 @@ SkPDFFunctionShader* SkPDFCanon::findFunctionShader(
|
| return find_item(fFunctionShaderRecords, state);
|
| }
|
| void SkPDFCanon::addFunctionShader(SkPDFFunctionShader* pdfShader) {
|
| - fFunctionShaderRecords.push(assert_ptr(pdfShader));
|
| -}
|
| -void SkPDFCanon::removeFunctionShader(SkPDFFunctionShader* pdfShader) {
|
| - SkAssertResult(remove_item(&fFunctionShaderRecords, pdfShader));
|
| + fFunctionShaderRecords.push(SkRef(pdfShader));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -101,10 +91,7 @@ SkPDFAlphaFunctionShader* SkPDFCanon::findAlphaShader(
|
| return find_item(fAlphaShaderRecords, state);
|
| }
|
| void SkPDFCanon::addAlphaShader(SkPDFAlphaFunctionShader* pdfShader) {
|
| - fAlphaShaderRecords.push(assert_ptr(pdfShader));
|
| -}
|
| -void SkPDFCanon::removeAlphaShader(SkPDFAlphaFunctionShader* pdfShader) {
|
| - SkAssertResult(remove_item(&fAlphaShaderRecords, pdfShader));
|
| + fAlphaShaderRecords.push(SkRef(pdfShader));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -115,11 +102,7 @@ SkPDFImageShader* SkPDFCanon::findImageShader(
|
| }
|
|
|
| void SkPDFCanon::addImageShader(SkPDFImageShader* pdfShader) {
|
| - fImageShaderRecords.push(assert_ptr(pdfShader));
|
| -}
|
| -
|
| -void SkPDFCanon::removeImageShader(SkPDFImageShader* pdfShader) {
|
| - SkAssertResult(remove_item(&fImageShaderRecords, pdfShader));
|
| + fImageShaderRecords.push(SkRef(pdfShader));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -129,11 +112,7 @@ SkPDFGraphicState* SkPDFCanon::findGraphicState(const SkPaint& paint) const {
|
| }
|
|
|
| void SkPDFCanon::addGraphicState(SkPDFGraphicState* state) {
|
| - fGraphicStateRecords.push(assert_ptr(state));
|
| -}
|
| -
|
| -void SkPDFCanon::removeGraphicState(SkPDFGraphicState* pdfGraphicState) {
|
| - SkAssertResult(remove_item(&fGraphicStateRecords, pdfGraphicState));
|
| + fGraphicStateRecords.push(SkRef(state));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -143,9 +122,5 @@ SkPDFBitmap* SkPDFCanon::findBitmap(const SkBitmap& bm) const {
|
| }
|
|
|
| void SkPDFCanon::addBitmap(SkPDFBitmap* pdfBitmap) {
|
| - fBitmapRecords.push(assert_ptr(pdfBitmap));
|
| -}
|
| -
|
| -void SkPDFCanon::removeBitmap(SkPDFBitmap* pdfBitmap) {
|
| - SkAssertResult(remove_item(&fBitmapRecords, pdfBitmap));
|
| + fBitmapRecords.push(SkRef(pdfBitmap));
|
| }
|
|
|