diff options
author | vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-01-04 19:31:24 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-01-04 19:31:24 +0000 |
commit | d96d17b9c113ac694138224249ff2ce643e961dd (patch) | |
tree | e4057be1bbc1a448d19dea3ce54136e7c97ed188 /src/pdf | |
parent | 4a1362a3c91ae9461a54bf1b04c250b0aa145db4 (diff) |
Remove SkRefPtr
(resubmit of https://codereview.appspot.com/7030059/)
TBR=junov@google.com
Review URL: https://codereview.appspot.com/7030065
git-svn-id: http://skia.googlecode.com/svn/trunk@7030 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/pdf')
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 58 | ||||
-rw-r--r-- | src/pdf/SkPDFDocument.cpp | 6 | ||||
-rw-r--r-- | src/pdf/SkPDFFont.cpp | 151 | ||||
-rw-r--r-- | src/pdf/SkPDFFont.h | 6 | ||||
-rw-r--r-- | src/pdf/SkPDFFormXObject.cpp | 6 | ||||
-rw-r--r-- | src/pdf/SkPDFGraphicState.cpp | 16 | ||||
-rw-r--r-- | src/pdf/SkPDFImage.cpp | 19 | ||||
-rw-r--r-- | src/pdf/SkPDFPage.cpp | 22 | ||||
-rw-r--r-- | src/pdf/SkPDFPage.h | 4 | ||||
-rw-r--r-- | src/pdf/SkPDFShader.cpp | 23 | ||||
-rw-r--r-- | src/pdf/SkPDFStream.cpp | 16 | ||||
-rw-r--r-- | src/pdf/SkPDFStream.h | 4 | ||||
-rw-r--r-- | src/pdf/SkPDFTypes.cpp | 5 | ||||
-rw-r--r-- | src/pdf/SkPDFTypes.h | 2 |
14 files changed, 140 insertions, 198 deletions
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 0de011c63c..7f189aad5f 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -1006,8 +1006,7 @@ SkPDFDict* SkPDFDevice::getResourceDict() { fResourceDict = SkNEW(SkPDFDict); if (fGraphicStateResources.count()) { - SkRefPtr<SkPDFDict> extGState = new SkPDFDict(); - extGState->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFDict> extGState(new SkPDFDict()); for (int i = 0; i < fGraphicStateResources.count(); i++) { SkString nameString("G"); nameString.appendS32(i); @@ -1019,8 +1018,7 @@ SkPDFDict* SkPDFDevice::getResourceDict() { } if (fXObjectResources.count()) { - SkRefPtr<SkPDFDict> xObjects = new SkPDFDict(); - xObjects->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFDict> xObjects(new SkPDFDict()); for (int i = 0; i < fXObjectResources.count(); i++) { SkString nameString("X"); nameString.appendS32(i); @@ -1032,8 +1030,7 @@ SkPDFDict* SkPDFDevice::getResourceDict() { } if (fFontResources.count()) { - SkRefPtr<SkPDFDict> fonts = new SkPDFDict(); - fonts->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFDict> fonts(new SkPDFDict()); for (int i = 0; i < fFontResources.count(); i++) { SkString nameString("F"); nameString.appendS32(i); @@ -1044,8 +1041,7 @@ SkPDFDict* SkPDFDevice::getResourceDict() { } if (fShaderResources.count()) { - SkRefPtr<SkPDFDict> patterns = new SkPDFDict(); - patterns->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFDict> patterns(new SkPDFDict()); for (int i = 0; i < fShaderResources.count(); i++) { SkString nameString("P"); nameString.appendS32(i); @@ -1058,8 +1054,7 @@ SkPDFDict* SkPDFDevice::getResourceDict() { // For compatibility, add all proc sets (only used for output to PS // devices). const char procs[][7] = {"PDF", "Text", "ImageB", "ImageC", "ImageI"}; - SkRefPtr<SkPDFArray> procSets = new SkPDFArray(); - procSets->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFArray> procSets(new SkPDFArray()); procSets->reserve(SK_ARRAY_COUNT(procs)); for (size_t i = 0; i < SK_ARRAY_COUNT(procs); i++) procSets->appendName(procs[i]); @@ -1266,9 +1261,8 @@ void SkPDFDevice::drawFormXObjectWithClip(SkPDFFormXObject* xobject, SkPaint stockPaint; this->drawPaint(draw, stockPaint); SkAutoTUnref<SkPDFFormXObject> maskFormXObject(createFormXObjectFromDevice()); - SkRefPtr<SkPDFGraphicState> sMaskGS = - SkPDFGraphicState::GetSMaskGraphicState(maskFormXObject, invertClip); - sMaskGS->unref(); // SkRefPtr and getSMaskGraphicState both took a ref. + SkAutoTUnref<SkPDFGraphicState> sMaskGS( + SkPDFGraphicState::GetSMaskGraphicState(maskFormXObject, invertClip)); // Draw the xobject with the clip as a mask. ScopedContentEntry content(this, &fExistingClipStack, fExistingClipRegion, @@ -1283,8 +1277,7 @@ void SkPDFDevice::drawFormXObjectWithClip(SkPDFFormXObject* xobject, fXObjectResources.push(xobject); xobject->ref(); - sMaskGS = SkPDFGraphicState::GetNoSMaskGraphicState(); - sMaskGS->unref(); // SkRefPtr and getSMaskGraphicState both took a ref. + sMaskGS.reset(SkPDFGraphicState::GetNoSMaskGraphicState()); SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), &content.entry()->fContent); } @@ -1421,27 +1414,25 @@ void SkPDFDevice::finishContentEntry(const SkXfermode::Mode xfermode, return; } - SkRefPtr<SkPDFGraphicState> sMaskGS; + SkAutoTUnref<SkPDFGraphicState> sMaskGS; if (xfermode == SkXfermode::kSrcIn_Mode || xfermode == SkXfermode::kSrcOut_Mode) { - sMaskGS = SkPDFGraphicState::GetSMaskGraphicState( - dst, xfermode == SkXfermode::kSrcOut_Mode); + sMaskGS.reset(SkPDFGraphicState::GetSMaskGraphicState( + dst, xfermode == SkXfermode::kSrcOut_Mode)); fXObjectResources.push(srcFormXObject.get()); srcFormXObject.get()->ref(); } else { - sMaskGS = SkPDFGraphicState::GetSMaskGraphicState( - srcFormXObject.get(), xfermode == SkXfermode::kDstOut_Mode); + sMaskGS.reset(SkPDFGraphicState::GetSMaskGraphicState( + srcFormXObject.get(), xfermode == SkXfermode::kDstOut_Mode)); // dst already added to fXObjectResources in drawFormXObjectWithClip. } - sMaskGS->unref(); // SkRefPtr and getSMaskGraphicState both took a ref. SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), &inClipContentEntry.entry()->fContent); SkPDFUtils::DrawFormXObject(fXObjectResources.count() - 1, &inClipContentEntry.entry()->fContent); - sMaskGS = SkPDFGraphicState::GetNoSMaskGraphicState(); - sMaskGS->unref(); // SkRefPtr and getSMaskGraphicState both took a ref. + sMaskGS.reset(SkPDFGraphicState::GetNoSMaskGraphicState()); SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), &inClipContentEntry.entry()->fContent); } @@ -1474,7 +1465,7 @@ void SkPDFDevice::populateGraphicStateEntryFromPaint( entry->fShaderIndex = -1; // PDF treats a shader as a color, so we only set one or the other. - SkRefPtr<SkPDFObject> pdfShader; + SkAutoTUnref<SkPDFObject> pdfShader; const SkShader* shader = paint.getShader(); SkColor color = paint.getColor(); if (shader) { @@ -1494,8 +1485,7 @@ void SkPDFDevice::populateGraphicStateEntryFromPaint( fInitialTransform.mapRect(&boundsTemp); boundsTemp.roundOut(&bounds); - pdfShader = SkPDFShader::GetPDFShader(*shader, transform, bounds); - SkSafeUnref(pdfShader.get()); // getShader and SkRefPtr both took a ref + pdfShader.reset(SkPDFShader::GetPDFShader(*shader, transform, bounds)); if (pdfShader.get()) { // pdfShader has been canonicalized so we can directly compare @@ -1504,7 +1494,7 @@ void SkPDFDevice::populateGraphicStateEntryFromPaint( if (resourceIndex < 0) { resourceIndex = fShaderResources.count(); fShaderResources.push(pdfShader.get()); - pdfShader->ref(); + pdfShader.get()->ref(); } entry->fShaderIndex = resourceIndex; } else { @@ -1523,15 +1513,16 @@ void SkPDFDevice::populateGraphicStateEntryFromPaint( } } - SkRefPtr<SkPDFGraphicState> newGraphicState; + SkAutoTUnref<SkPDFGraphicState> newGraphicState; if (color == paint.getColor()) { - newGraphicState = SkPDFGraphicState::GetGraphicStateForPaint(paint); + newGraphicState.reset( + SkPDFGraphicState::GetGraphicStateForPaint(paint)); } else { SkPaint newPaint = paint; newPaint.setColor(color); - newGraphicState = SkPDFGraphicState::GetGraphicStateForPaint(newPaint); + newGraphicState.reset( + SkPDFGraphicState::GetGraphicStateForPaint(newPaint)); } - newGraphicState->unref(); // getGraphicState and SkRefPtr both took a ref. int resourceIndex = addGraphicStateResource(newGraphicState.get()); entry->fGraphicStateIndex = resourceIndex; @@ -1572,13 +1563,12 @@ void SkPDFDevice::updateFont(const SkPaint& paint, uint16_t glyphID, } int SkPDFDevice::getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID) { - SkRefPtr<SkPDFFont> newFont = SkPDFFont::GetFontResource(typeface, glyphID); - newFont->unref(); // getFontResource and SkRefPtr both took a ref. + SkAutoTUnref<SkPDFFont> newFont(SkPDFFont::GetFontResource(typeface, glyphID)); int resourceIndex = fFontResources.find(newFont.get()); if (resourceIndex < 0) { resourceIndex = fFontResources.count(); fFontResources.push(newFont.get()); - newFont->ref(); + newFont.get()->ref(); } return resourceIndex; } diff --git a/src/pdf/SkPDFDocument.cpp b/src/pdf/SkPDFDocument.cpp index 7e064ee19d..c7266d8454 100644 --- a/src/pdf/SkPDFDocument.cpp +++ b/src/pdf/SkPDFDocument.cpp @@ -98,13 +98,11 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) { fDocCatalog->insert("Pages", new SkPDFObjRef(pageTreeRoot))->unref(); /* TODO(vandebo): output intent - SkRefPtr<SkPDFDict> outputIntent = new SkPDFDict("OutputIntent"); - outputIntent->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFDict> outputIntent = new SkPDFDict("OutputIntent"); outputIntent->insert("S", new SkPDFName("GTS_PDFA1"))->unref(); outputIntent->insert("OutputConditionIdentifier", new SkPDFString("sRGB"))->unref(); - SkRefPtr<SkPDFArray> intentArray = new SkPDFArray; - intentArray->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFArray> intentArray = new SkPDFArray; intentArray->append(outputIntent.get()); fDocCatalog->insert("OutputIntent", intentArray.get()); */ diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp index 9a8f13600b..f2b3f53162 100644 --- a/src/pdf/SkPDFFont.cpp +++ b/src/pdf/SkPDFFont.cpp @@ -155,13 +155,12 @@ SkStream* handleType1Stream(SkStream* srcStream, size_t* headerLen, // if the data was NUL terminated so that we can use strstr() to search it. // Make as few copies as possible given these constraints. SkDynamicMemoryWStream dynamicStream; - SkRefPtr<SkMemoryStream> staticStream; + SkAutoTUnref<SkMemoryStream> staticStream; SkData* data = NULL; const uint8_t* src; size_t srcLen; if ((srcLen = srcStream->getLength()) > 0) { - staticStream = new SkMemoryStream(srcLen + 1); - staticStream->unref(); // new and SkRefPtr both took a ref. + staticStream.reset(new SkMemoryStream(srcLen + 1)); src = (const uint8_t*)staticStream->getMemoryBase(); if (srcStream->getMemoryBase() != NULL) { memcpy((void *)src, srcStream->getMemoryBase(), srcLen); @@ -318,8 +317,7 @@ SkPDFArray* composeAdvanceData( break; } case SkAdvancedTypefaceMetrics::WidthRange::kRange: { - SkRefPtr<SkPDFArray> advanceArray = new SkPDFArray(); - advanceArray->unref(); // SkRefPtr and new both took a ref. + SkAutoTUnref<SkPDFArray> advanceArray(new SkPDFArray()); for (int j = 0; j < advanceInfo->fAdvance.count(); j++) appendAdvance(advanceInfo->fAdvance[j], emSize, advanceArray.get()); @@ -530,8 +528,7 @@ static SkPDFStream* generate_tounicode_cmap( append_tounicode_header(&cmap); append_cmap_sections(glyphToUnicode, subset, &cmap); append_cmap_footer(&cmap); - SkRefPtr<SkMemoryStream> cmapStream = new SkMemoryStream(); - cmapStream->unref(); // SkRefPtr and new took a reference. + SkAutoTUnref<SkMemoryStream> cmapStream(new SkMemoryStream()); cmapStream->setData(cmap.copyToData())->unref(); return new SkPDFStream(cmapStream.get()); } @@ -547,9 +544,8 @@ static int get_subset_font_stream(const char* fontName, const SkTypeface* typeface, const SkTDArray<uint32_t>& subset, SkPDFStream** fontStream) { - SkRefPtr<SkStream> fontData = - SkFontHost::OpenStream(SkTypeface::UniqueID(typeface)); - fontData->unref(); // SkRefPtr and OpenStream both took a ref. + SkAutoTUnref<SkStream> fontData( + SkFontHost::OpenStream(SkTypeface::UniqueID(typeface))); int fontSize = fontData->getLength(); @@ -766,11 +762,12 @@ SkPDFFont* SkPDFFont::GetFontResource(SkTypeface* typeface, uint16_t glyphID) { return CanonicalFonts()[relatedFontIndex].fFont; } - SkRefPtr<SkAdvancedTypefaceMetrics> fontMetrics; + SkAutoTUnref<SkAdvancedTypefaceMetrics> fontMetrics; SkPDFDict* relatedFontDescriptor = NULL; if (relatedFontIndex >= 0) { SkPDFFont* relatedFont = CanonicalFonts()[relatedFontIndex].fFont; - fontMetrics = relatedFont->fontInfo(); + fontMetrics.reset(relatedFont->fontInfo()); + SkSafeRef(fontMetrics.get()); relatedFontDescriptor = relatedFont->getFontDescriptor(); // This only is to catch callers who pass invalid glyph ids. @@ -794,18 +791,16 @@ SkPDFFont* SkPDFFont::GetFontResource(SkTypeface* typeface, uint16_t glyphID) { info = SkTBitOr<SkAdvancedTypefaceMetrics::PerGlyphInfo>( info, SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo); #endif - fontMetrics = - SkFontHost::GetAdvancedTypefaceMetrics(fontID, info, NULL, 0); - SkSafeUnref(fontMetrics.get()); // SkRefPtr and Get both took a ref. + fontMetrics.reset( + SkFontHost::GetAdvancedTypefaceMetrics(fontID, info, NULL, 0)); #if defined (SK_SFNTLY_SUBSETTER) - if (fontMetrics && + if (fontMetrics.get() && fontMetrics->fType != SkAdvancedTypefaceMetrics::kTrueType_Font) { // Font does not support subsetting, get new info with advance. info = SkTBitOr<SkAdvancedTypefaceMetrics::PerGlyphInfo>( info, SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo); - fontMetrics = - SkFontHost::GetAdvancedTypefaceMetrics(fontID, info, NULL, 0); - SkSafeUnref(fontMetrics.get()); // SkRefPtr and Get both took a ref + fontMetrics.reset( + SkFontHost::GetAdvancedTypefaceMetrics(fontID, info, NULL, 0)); } #endif } @@ -856,6 +851,8 @@ SkPDFFont::SkPDFFont(SkAdvancedTypefaceMetrics* info, SkTypeface* typeface, fFirstGlyphID(1), fLastGlyphID(info ? info->fLastGlyphID : 0), fFontInfo(info) { + SkSafeRef(typeface); + SkSafeRef(info); if (info == NULL) { fFontType = SkAdvancedTypefaceMetrics::kNotEmbeddable_Font; } else if (info->fMultiMaster) { @@ -906,7 +903,8 @@ void SkPDFFont::setFontInfo(SkAdvancedTypefaceMetrics* info) { if (info == NULL || info == fFontInfo.get()) { return; } - fFontInfo = info; + fFontInfo.reset(info); + SkSafeRef(info); } uint16_t SkPDFFont::firstGlyphID() const { @@ -924,6 +922,7 @@ void SkPDFFont::setLastGlyphID(uint16_t glyphID) { void SkPDFFont::addResource(SkPDFObject* object) { SkASSERT(object != NULL); fResources.push(object); + object->ref(); } SkPDFDict* SkPDFFont::getFontDescriptor() { @@ -931,7 +930,8 @@ SkPDFDict* SkPDFFont::getFontDescriptor() { } void SkPDFFont::setFontDescriptor(SkPDFDict* descriptor) { - fDescriptor = descriptor; + fDescriptor.reset(descriptor); + SkSafeRef(descriptor); } bool SkPDFFont::addCommonFontDescriptorEntries(int16_t defaultWidth) { @@ -1002,9 +1002,9 @@ void SkPDFFont::populateToUnicodeTable(const SkPDFGlyphSet* subset) { if (fFontInfo == NULL || fFontInfo->fGlyphToUnicode.begin() == NULL) { return; } - SkRefPtr<SkPDFStream> pdfCmap = - generate_tounicode_cmap(fFontInfo->fGlyphToUnicode, subset); - addResource(pdfCmap.get()); // Pass reference from new. + SkAutoTUnref<SkPDFStream> pdfCmap( + generate_tounicode_cmap(fFontInfo->fGlyphToUnicode, subset)); + addResource(pdfCmap.get()); insert("ToUnicode", new SkPDFObjRef(pdfCmap.get()))->unref(); } @@ -1039,14 +1039,11 @@ bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) { insertName("BaseFont", fontInfo()->fFontName); insertName("Encoding", "Identity-H"); - SkPDFCIDFont* newCIDFont; - newCIDFont = new SkPDFCIDFont(fontInfo(), typeface(), subset); - - // Pass ref new created to fResources. - addResource(newCIDFont); - SkRefPtr<SkPDFArray> descendantFonts = new SkPDFArray(); - descendantFonts->unref(); // SkRefPtr and new took a reference. - descendantFonts->append(new SkPDFObjRef(newCIDFont))->unref(); + SkAutoTUnref<SkPDFCIDFont> newCIDFont( + new SkPDFCIDFont(fontInfo(), typeface(), subset)); + addResource(newCIDFont.get()); + SkAutoTUnref<SkPDFArray> descendantFonts(new SkPDFArray()); + descendantFonts->append(new SkPDFObjRef(newCIDFont.get()))->unref(); insert("DescendantFonts", descendantFonts.get()); populateToUnicodeTable(subset); @@ -1069,9 +1066,9 @@ SkPDFCIDFont::~SkPDFCIDFont() {} bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, const SkTDArray<uint32_t>* subset) { - SkRefPtr<SkPDFDict> descriptor = new SkPDFDict("FontDescriptor"); - descriptor->unref(); // SkRefPtr and new both took a ref. + SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); setFontDescriptor(descriptor.get()); + addResource(descriptor.get()); switch (getType()) { case SkAdvancedTypefaceMetrics::kTrueType_Font: { @@ -1084,22 +1081,20 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, &rawStream); SkASSERT(fontSize); SkASSERT(rawStream); - SkRefPtr<SkPDFStream> fontStream = rawStream; - // SkRefPtr and new both ref()'d fontStream, pass one. + SkAutoTUnref<SkPDFStream> fontStream(rawStream); addResource(fontStream.get()); fontStream->insertInt("Length1", fontSize); descriptor->insert("FontFile2", - new SkPDFObjRef(fontStream.get()))->unref(); + new SkPDFObjRef(fontStream.get()))->unref(); break; } case SkAdvancedTypefaceMetrics::kCFF_Font: case SkAdvancedTypefaceMetrics::kType1CID_Font: { - SkRefPtr<SkStream> fontData = - SkFontHost::OpenStream(SkTypeface::UniqueID(typeface())); - fontData->unref(); // SkRefPtr and OpenStream both took a ref. - SkRefPtr<SkPDFStream> fontStream = new SkPDFStream(fontData.get()); - // SkRefPtr and new both ref()'d fontStream, pass one. + SkAutoTUnref<SkStream> fontData( + SkFontHost::OpenStream(SkTypeface::UniqueID(typeface()))); + SkAutoTUnref<SkPDFStream> fontStream( + new SkPDFStream(fontData.get())); addResource(fontStream.get()); if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { @@ -1115,9 +1110,6 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, SkASSERT(false); } - addResource(descriptor.get()); - descriptor->ref(); - insert("FontDescriptor", new SkPDFObjRef(descriptor.get()))->unref(); return addCommonFontDescriptorEntries(defaultWidth); } @@ -1132,20 +1124,18 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { subset->exportTo(&glyphIDs); } - SkRefPtr<SkAdvancedTypefaceMetrics> fontMetrics; SkAdvancedTypefaceMetrics::PerGlyphInfo info; info = SkAdvancedTypefaceMetrics::kGlyphNames_PerGlyphInfo; info = SkTBitOr<SkAdvancedTypefaceMetrics::PerGlyphInfo>( info, SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo); uint32_t* glyphs = (glyphIDs.count() == 1) ? NULL : glyphIDs.begin(); uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0; - fontMetrics = + SkAutoTUnref<SkAdvancedTypefaceMetrics> fontMetrics( SkFontHost::GetAdvancedTypefaceMetrics( SkTypeface::UniqueID(typeface()), info, glyphs, - glyphsCount); - SkSafeUnref(fontMetrics.get()); // SkRefPtr and Get both took a ref + glyphsCount)); setFontInfo(fontMetrics.get()); addFontDescriptor(0, &glyphIDs); } else { @@ -1164,8 +1154,7 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { SkASSERT(false); } - SkRefPtr<SkPDFDict> sysInfo = new SkPDFDict; - sysInfo->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFDict> sysInfo(new SkPDFDict); sysInfo->insert("Registry", new SkPDFString("Adobe"))->unref(); sysInfo->insert("Ordering", new SkPDFString("Identity"))->unref(); sysInfo->insertInt("Supplement", 0); @@ -1173,11 +1162,10 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { if (fontInfo()->fGlyphWidths.get()) { int16_t defaultWidth = 0; - SkRefPtr<SkPDFArray> widths = + SkAutoTUnref<SkPDFArray> widths( composeAdvanceData(fontInfo()->fGlyphWidths.get(), fontInfo()->fEmSize, &appendWidth, - &defaultWidth); - widths->unref(); // SkRefPtr and compose both took a reference. + &defaultWidth)); if (widths->size()) insert("W", widths.get()); if (defaultWidth != 0) { @@ -1190,11 +1178,10 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { defaultAdvance.fVerticalAdvance = 0; defaultAdvance.fOriginXDisp = 0; defaultAdvance.fOriginYDisp = 0; - SkRefPtr<SkPDFArray> advances = + SkAutoTUnref<SkPDFArray> advances( composeAdvanceData(fontInfo()->fVerticalMetrics.get(), fontInfo()->fEmSize, &appendVerticalAdvance, - &defaultAdvance); - advances->unref(); // SkRefPtr and compose both took a ref. + &defaultAdvance)); if (advances->size()) insert("W2", advances.get()); if (defaultAdvance.fVerticalAdvance || @@ -1224,31 +1211,27 @@ SkPDFType1Font::SkPDFType1Font(SkAdvancedTypefaceMetrics* info, SkPDFType1Font::~SkPDFType1Font() {} bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { - SkRefPtr<SkPDFDict> descriptor = getFontDescriptor(); - if (descriptor.get() != NULL) { - addResource(descriptor.get()); - descriptor->ref(); - insert("FontDescriptor", new SkPDFObjRef(descriptor.get()))->unref(); + if (getFontDescriptor() != NULL) { + SkPDFDict* descriptor = getFontDescriptor(); + addResource(descriptor); + insert("FontDescriptor", new SkPDFObjRef(descriptor))->unref(); return true; } - descriptor = new SkPDFDict("FontDescriptor"); - descriptor->unref(); // SkRefPtr and new both took a ref. + SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); setFontDescriptor(descriptor.get()); size_t header SK_INIT_TO_AVOID_WARNING; size_t data SK_INIT_TO_AVOID_WARNING; size_t trailer SK_INIT_TO_AVOID_WARNING; - SkRefPtr<SkStream> rawFontData = - SkFontHost::OpenStream(SkTypeface::UniqueID(typeface())); - rawFontData->unref(); // SkRefPtr and OpenStream both took a ref. + SkAutoTUnref<SkStream> rawFontData( + SkFontHost::OpenStream(SkTypeface::UniqueID(typeface()))); SkStream* fontData = handleType1Stream(rawFontData.get(), &header, &data, &trailer); if (fontData == NULL) { return false; } - SkRefPtr<SkPDFStream> fontStream = new SkPDFStream(fontData); - // SkRefPtr and new both ref()'d fontStream, pass one. + SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData)); addResource(fontStream.get()); fontStream->insertInt("Length1", header); fontStream->insertInt("Length2", data); @@ -1256,7 +1239,6 @@ bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { descriptor->insert("FontFile", new SkPDFObjRef(fontStream.get()))->unref(); addResource(descriptor.get()); - descriptor->ref(); insert("FontDescriptor", new SkPDFObjRef(descriptor.get()))->unref(); return addCommonFontDescriptorEntries(defaultWidth); @@ -1297,12 +1279,10 @@ bool SkPDFType1Font::populate(int16_t glyphID) { addWidthInfoFromRange(defaultWidth, widthRangeEntry); - SkRefPtr<SkPDFDict> encoding = new SkPDFDict("Encoding"); - encoding->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFDict> encoding(new SkPDFDict("Encoding")); insert("Encoding", encoding.get()); - SkRefPtr<SkPDFArray> encDiffs = new SkPDFArray; - encDiffs->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFArray> encDiffs(new SkPDFArray); encoding->insert("Differences", encDiffs.get()); encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2); @@ -1317,8 +1297,7 @@ bool SkPDFType1Font::populate(int16_t glyphID) { void SkPDFType1Font::addWidthInfoFromRange( int16_t defaultWidth, const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry) { - SkRefPtr<SkPDFArray> widthArray = new SkPDFArray(); - widthArray->unref(); // SkRefPtr and new both took a ref. + SkAutoTUnref<SkPDFArray> widthArray(new SkPDFArray()); int firstChar = 0; if (widthRangeEntry) { const uint16_t emSize = fontInfo()->fEmSize; @@ -1377,22 +1356,18 @@ bool SkPDFType3Font::populate(int16_t glyphID) { fontMatrix.setScale(SkScalarInvert(1000), -SkScalarInvert(1000)); insert("FontMatrix", SkPDFUtils::MatrixToArray(fontMatrix))->unref(); - SkRefPtr<SkPDFDict> charProcs = new SkPDFDict; - charProcs->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFDict> charProcs(new SkPDFDict); insert("CharProcs", charProcs.get()); - SkRefPtr<SkPDFDict> encoding = new SkPDFDict("Encoding"); - encoding->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFDict> encoding(new SkPDFDict("Encoding")); insert("Encoding", encoding.get()); - SkRefPtr<SkPDFArray> encDiffs = new SkPDFArray; - encDiffs->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFArray> encDiffs(new SkPDFArray); encoding->insert("Differences", encDiffs.get()); encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2); encDiffs->appendInt(1); - SkRefPtr<SkPDFArray> widthArray = new SkPDFArray(); - widthArray->unref(); // SkRefPtr and new both took a ref. + SkAutoTUnref<SkPDFArray> widthArray(new SkPDFArray()); SkIRect bbox = SkIRect::MakeEmpty(); for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) { @@ -1415,13 +1390,11 @@ bool SkPDFType3Font::populate(int16_t glyphID) { SkPDFUtils::PaintPath(paint.getStyle(), path->getFillType(), &content); } - SkRefPtr<SkMemoryStream> glyphStream = new SkMemoryStream(); - glyphStream->unref(); // SkRefPtr and new both took a ref. + SkAutoTUnref<SkMemoryStream> glyphStream(new SkMemoryStream()); glyphStream->setData(content.copyToData())->unref(); - SkRefPtr<SkPDFStream> glyphDescription = - new SkPDFStream(glyphStream.get()); - // SkRefPtr and new both ref()'d charProcs, pass one. + SkAutoTUnref<SkPDFStream> glyphDescription( + new SkPDFStream(glyphStream.get())); addResource(glyphDescription.get()); charProcs->insert(characterName.c_str(), new SkPDFObjRef(glyphDescription.get()))->unref(); diff --git a/src/pdf/SkPDFFont.h b/src/pdf/SkPDFFont.h index f463ed740a..693b911061 100644 --- a/src/pdf/SkPDFFont.h +++ b/src/pdf/SkPDFFont.h @@ -180,7 +180,7 @@ private: FontRec(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID); }; - SkRefPtr<SkTypeface> fTypeface; + SkAutoTUnref<SkTypeface> fTypeface; // The glyph IDs accessible with this font. For Type1 (non CID) fonts, // this will be a subset if the font has more than 255 glyphs. @@ -188,9 +188,9 @@ private: uint16_t fLastGlyphID; // The font info is only kept around after construction for large // Type1 (non CID) fonts that need multiple "fonts" to access all glyphs. - SkRefPtr<SkAdvancedTypefaceMetrics> fFontInfo; + SkAutoTUnref<SkAdvancedTypefaceMetrics> fFontInfo; SkTDArray<SkPDFObject*> fResources; - SkRefPtr<SkPDFDict> fDescriptor; + SkAutoTUnref<SkPDFDict> fDescriptor; SkAdvancedTypefaceMetrics::FontType fFontType; diff --git a/src/pdf/SkPDFFormXObject.cpp b/src/pdf/SkPDFFormXObject.cpp index e148056afe..5e33995b74 100644 --- a/src/pdf/SkPDFFormXObject.cpp +++ b/src/pdf/SkPDFFormXObject.cpp @@ -31,8 +31,7 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) { getResources(&dummy_resourceList); #endif - SkRefPtr<SkStream> content = device->content(); - content->unref(); // SkRefPtr and content() both took a reference. + SkAutoTUnref<SkStream> content(device->content()); setData(content.get()); insertName("Type", "XObject"); @@ -55,8 +54,7 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) { // Right now SkPDFFormXObject is only used for saveLayer, which implies // isolated blending. Do this conditionally if that changes. - SkRefPtr<SkPDFDict> group = new SkPDFDict("Group"); - group->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFDict> group(new SkPDFDict("Group")); group->insertName("S", "Transparency"); group->insert("I", new SkPDFBool(true))->unref(); // Isolated. insert("Group", group.get()); diff --git a/src/pdf/SkPDFGraphicState.cpp b/src/pdf/SkPDFGraphicState.cpp index ec9b0e70b2..c326b3b533 100644 --- a/src/pdf/SkPDFGraphicState.cpp +++ b/src/pdf/SkPDFGraphicState.cpp @@ -113,16 +113,14 @@ SkPDFObject* SkPDFGraphicState::GetInvertFunction() { if (!invertFunction) { // Acrobat crashes if we use a type 0 function, kpdf crashes if we use // a type 2 function, so we use a type 4 function. - SkRefPtr<SkPDFArray> domainAndRange = new SkPDFArray; - domainAndRange->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFArray> domainAndRange(new SkPDFArray); domainAndRange->reserve(2); domainAndRange->appendInt(0); domainAndRange->appendInt(1); static const char psInvert[] = "{1 exch sub}"; - SkRefPtr<SkMemoryStream> psInvertStream = - new SkMemoryStream(&psInvert, strlen(psInvert), true); - psInvertStream->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkMemoryStream> psInvertStream( + new SkMemoryStream(&psInvert, strlen(psInvert), true)); invertFunction = new SkPDFStream(psInvertStream.get()); invertFunction->insertInt("FunctionType", 4); @@ -139,8 +137,7 @@ SkPDFGraphicState* SkPDFGraphicState::GetSMaskGraphicState( // enough that it's not worth canonicalizing. SkAutoMutexAcquire lock(CanonicalPaintsMutex()); - SkRefPtr<SkPDFDict> sMaskDict = new SkPDFDict("Mask"); - sMaskDict->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFDict> sMaskDict(new SkPDFDict("Mask")); sMaskDict->insertName("S", "Alpha"); sMaskDict->insert("G", new SkPDFObjRef(sMask))->unref(); @@ -200,9 +197,8 @@ void SkPDFGraphicState::populateDict() { fPopulated = true; insertName("Type", "ExtGState"); - SkRefPtr<SkPDFScalar> alpha = - new SkPDFScalar(SkScalarDiv(fPaint.getAlpha(), 0xFF)); - alpha->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFScalar> alpha( + new SkPDFScalar(SkScalarDiv(fPaint.getAlpha(), 0xFF))); insert("CA", alpha.get()); insert("ca", alpha.get()); diff --git a/src/pdf/SkPDFImage.cpp b/src/pdf/SkPDFImage.cpp index 429667a5e2..1b93f6e045 100644 --- a/src/pdf/SkPDFImage.cpp +++ b/src/pdf/SkPDFImage.cpp @@ -305,8 +305,7 @@ SkPDFImage::SkPDFImage(SkStream* imageData, const SkBitmap& bitmap, if (!doingAlpha && alphaOnly) { // For alpha only images, we stretch a single pixel of black for // the color/shape part. - SkRefPtr<SkPDFInt> one = new SkPDFInt(1); - one->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFInt> one(new SkPDFInt(1)); insert("Width", one.get()); insert("Height", one.get()); } else { @@ -335,16 +334,12 @@ SkPDFImage::SkPDFImage(SkStream* imageData, const SkBitmap& bitmap, insertInt("BitsPerComponent", bitsPerComp); if (config == SkBitmap::kRGB_565_Config) { - SkRefPtr<SkPDFInt> zeroVal = new SkPDFInt(0); - zeroVal->unref(); // SkRefPtr and new both took a reference. - SkRefPtr<SkPDFScalar> scale5Val = - new SkPDFScalar(SkFloatToScalar(8.2258f)); // 255/2^5-1 - scale5Val->unref(); // SkRefPtr and new both took a reference. - SkRefPtr<SkPDFScalar> scale6Val = - new SkPDFScalar(SkFloatToScalar(4.0476f)); // 255/2^6-1 - scale6Val->unref(); // SkRefPtr and new both took a reference. - SkRefPtr<SkPDFArray> decodeValue = new SkPDFArray(); - decodeValue->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFInt> zeroVal(new SkPDFInt(0)); + SkAutoTUnref<SkPDFScalar> scale5Val( + new SkPDFScalar(SkFloatToScalar(8.2258f))); // 255/2^5-1 + SkAutoTUnref<SkPDFScalar> scale6Val( + new SkPDFScalar(SkFloatToScalar(4.0476f))); // 255/2^6-1 + SkAutoTUnref<SkPDFArray> decodeValue(new SkPDFArray()); decodeValue->reserve(6); decodeValue->append(zeroVal.get()); decodeValue->append(scale5Val.get()); diff --git a/src/pdf/SkPDFPage.cpp b/src/pdf/SkPDFPage.cpp index 717f435356..a18beb156f 100644 --- a/src/pdf/SkPDFPage.cpp +++ b/src/pdf/SkPDFPage.cpp @@ -15,6 +15,7 @@ SkPDFPage::SkPDFPage(SkPDFDevice* content) : SkPDFDict("Page"), fDevice(content) { + SkSafeRef(content); } SkPDFPage::~SkPDFPage() {} @@ -32,10 +33,8 @@ void SkPDFPage::finalizePage(SkPDFCatalog* catalog, bool firstPage, } } - SkRefPtr<SkStream> content = fDevice->content(); - content->unref(); // SkRefPtr and content() both took a reference. - fContentStream = new SkPDFStream(content.get()); - fContentStream->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkStream> content(fDevice->content()); + fContentStream.reset(new SkPDFStream(content.get())); insert("Contents", new SkPDFObjRef(fContentStream.get()))->unref(); } catalog->addObject(fContentStream.get(), firstPage); @@ -67,12 +66,9 @@ void SkPDFPage::GeneratePageTree(const SkTDArray<SkPDFPage*>& pages, // one child. static const int kNodeSize = 8; - SkRefPtr<SkPDFName> kidsName = new SkPDFName("Kids"); - kidsName->unref(); // SkRefPtr and new both took a reference. - SkRefPtr<SkPDFName> countName = new SkPDFName("Count"); - countName->unref(); // SkRefPtr and new both took a reference. - SkRefPtr<SkPDFName> parentName = new SkPDFName("Parent"); - parentName->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFName> kidsName(new SkPDFName("Kids")); + SkAutoTUnref<SkPDFName> countName(new SkPDFName("Count")); + SkAutoTUnref<SkPDFName> parentName(new SkPDFName("Parent")); // curNodes takes a reference to its items, which it passes to pageTree. SkTDArray<SkPDFDict*> curNodes; @@ -95,11 +91,9 @@ void SkPDFPage::GeneratePageTree(const SkTDArray<SkPDFPage*>& pages, } SkPDFDict* newNode = new SkPDFDict("Pages"); - SkRefPtr<SkPDFObjRef> newNodeRef = new SkPDFObjRef(newNode); - newNodeRef->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFObjRef> newNodeRef(new SkPDFObjRef(newNode)); - SkRefPtr<SkPDFArray> kids = new SkPDFArray; - kids->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFArray> kids(new SkPDFArray); kids->reserve(kNodeSize); int count = 0; diff --git a/src/pdf/SkPDFPage.h b/src/pdf/SkPDFPage.h index 8ef909e573..72ba335e66 100644 --- a/src/pdf/SkPDFPage.h +++ b/src/pdf/SkPDFPage.h @@ -91,10 +91,10 @@ public: private: // Multiple pages may reference the content. - SkRefPtr<SkPDFDevice> fDevice; + SkAutoTUnref<SkPDFDevice> fDevice; // Once the content is finalized, put it into a stream for output. - SkRefPtr<SkPDFStream> fContentStream; + SkAutoTUnref<SkPDFStream> fContentStream; }; #endif diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp index db5beb8fc8..7958de38ce 100644 --- a/src/pdf/SkPDFShader.cpp +++ b/src/pdf/SkPDFShader.cpp @@ -612,8 +612,7 @@ SkPDFFunctionShader::SkPDFFunctionShader(SkPDFShader::State* state) return; } - SkRefPtr<SkPDFArray> domain = new SkPDFArray; - domain->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFArray> domain(new SkPDFArray); domain->reserve(4); domain->appendScalar(bbox.fLeft); domain->appendScalar(bbox.fRight); @@ -640,16 +639,14 @@ SkPDFFunctionShader::SkPDFFunctionShader(SkPDFShader::State* state) functionCode = codeFunction(*info); } - SkRefPtr<SkPDFStream> function = makePSFunction(functionCode, domain.get()); - // Pass one reference to fResources, SkRefPtr and new both took a reference. - fResources.push(function.get()); - - SkRefPtr<SkPDFDict> pdfShader = new SkPDFDict; - pdfShader->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFDict> pdfShader(new SkPDFDict); pdfShader->insertInt("ShadingType", 1); pdfShader->insertName("ColorSpace", "DeviceRGB"); pdfShader->insert("Domain", domain.get()); - pdfShader->insert("Function", new SkPDFObjRef(function.get()))->unref(); + + SkPDFStream* function = makePSFunction(functionCode, domain.get()); + pdfShader->insert("Function", new SkPDFObjRef(function))->unref(); + fResources.push(function); // Pass ownership to resource list. insertInt("PatternType", 2); insert("Matrix", SkPDFUtils::MatrixToArray(finalMatrix))->unref(); @@ -825,8 +822,7 @@ SkPDFImageShader::SkPDFImageShader(SkPDFShader::State* state) : fState(state) { } } - SkRefPtr<SkPDFArray> patternBBoxArray = new SkPDFArray; - patternBBoxArray->unref(); // SkRefPtr and new both took a reference. + SkAutoTUnref<SkPDFArray> patternBBoxArray(new SkPDFArray); patternBBoxArray->reserve(4); patternBBoxArray->appendScalar(patternBBox.fLeft); patternBBoxArray->appendScalar(patternBBox.fTop); @@ -834,11 +830,10 @@ SkPDFImageShader::SkPDFImageShader(SkPDFShader::State* state) : fState(state) { patternBBoxArray->appendScalar(patternBBox.fBottom); // Put the canvas into the pattern stream (fContent). - SkRefPtr<SkStream> content = pattern.content(); - content->unref(); // SkRefPtr and content() both took a reference. + SkAutoTUnref<SkStream> content(pattern.content()); + setData(content.get()); pattern.getResources(&fResources, false); - setData(content.get()); insertName("Type", "Pattern"); insertInt("PatternType", 1); insertInt("PaintType", 1); diff --git a/src/pdf/SkPDFStream.cpp b/src/pdf/SkPDFStream.cpp index d113a0b355..38e874ea1b 100644 --- a/src/pdf/SkPDFStream.cpp +++ b/src/pdf/SkPDFStream.cpp @@ -21,19 +21,20 @@ static bool skip_compression(SkPDFCatalog* catalog) { SkPDFStream::SkPDFStream(SkStream* stream) : fState(kUnused_State), fData(stream) { + SkSafeRef(stream); } SkPDFStream::SkPDFStream(SkData* data) : fState(kUnused_State) { SkMemoryStream* stream = new SkMemoryStream; stream->setData(data); - fData = stream; - fData->unref(); // SkRefPtr and new both took a reference. + fData.reset(stream); // Transfer ownership. } SkPDFStream::SkPDFStream(const SkPDFStream& pdfStream) : SkPDFDict(), fState(kUnused_State), - fData(pdfStream.fData) { + fData(pdfStream.fData.get()) { + fData.get()->ref(); bool removeLength = true; // Don't uncompress an already compressed stream, but we could. if (pdfStream.fState == kCompressed_State) { @@ -84,7 +85,8 @@ size_t SkPDFStream::getOutputSize(SkPDFCatalog* catalog, bool indirect) { SkPDFStream::SkPDFStream() : fState(kUnused_State) {} void SkPDFStream::setData(SkStream* stream) { - fData = stream; + fData.reset(stream); + SkSafeRef(stream); } bool SkPDFStream::populate(SkPDFCatalog* catalog) { @@ -96,8 +98,7 @@ bool SkPDFStream::populate(SkPDFCatalog* catalog) { if (compressedData.getOffset() < fData->getLength()) { SkMemoryStream* stream = new SkMemoryStream; stream->setData(compressedData.copyToData())->unref(); - fData = stream; - fData->unref(); // SkRefPtr and new both took a reference. + fData.reset(stream); // Transfer ownership. insertName("Filter", "FlateDecode"); } fState = kCompressed_State; @@ -108,8 +109,7 @@ bool SkPDFStream::populate(SkPDFCatalog* catalog) { } else if (fState == kNoCompression_State && !skip_compression(catalog) && SkFlate::HaveFlate()) { if (!fSubstitute.get()) { - fSubstitute = new SkPDFStream(*this); - fSubstitute->unref(); // SkRefPtr and new both took a reference. + fSubstitute.reset(new SkPDFStream(*this)); catalog->setSubstitute(this, fSubstitute.get()); } return false; diff --git a/src/pdf/SkPDFStream.h b/src/pdf/SkPDFStream.h index b3a7ad34e3..6f7a08eb81 100644 --- a/src/pdf/SkPDFStream.h +++ b/src/pdf/SkPDFStream.h @@ -62,8 +62,8 @@ private: State fState; // TODO(vandebo): Use SkData (after removing deprecated constructor). - SkRefPtr<SkStream> fData; - SkRefPtr<SkPDFStream> fSubstitute; + SkAutoTUnref<SkStream> fData; + SkAutoTUnref<SkPDFStream> fSubstitute; typedef SkPDFDict INHERITED; diff --git a/src/pdf/SkPDFTypes.cpp b/src/pdf/SkPDFTypes.cpp index 7fb1e95532..59250c8534 100644 --- a/src/pdf/SkPDFTypes.cpp +++ b/src/pdf/SkPDFTypes.cpp @@ -73,7 +73,10 @@ void SkPDFObject::GetResourcesHelper(SkTDArray<SkPDFObject*>* resources, } } -SkPDFObjRef::SkPDFObjRef(SkPDFObject* obj) : fObj(obj) {} +SkPDFObjRef::SkPDFObjRef(SkPDFObject* obj) : fObj(obj) { + SkSafeRef(obj); +} + SkPDFObjRef::~SkPDFObjRef() {} void SkPDFObjRef::emitObject(SkWStream* stream, SkPDFCatalog* catalog, diff --git a/src/pdf/SkPDFTypes.h b/src/pdf/SkPDFTypes.h index 28034ef405..03799d0845 100644 --- a/src/pdf/SkPDFTypes.h +++ b/src/pdf/SkPDFTypes.h @@ -112,7 +112,7 @@ public: virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); private: - SkRefPtr<SkPDFObject> fObj; + SkAutoTUnref<SkPDFObject> fObj; typedef SkPDFObject INHERITED; }; |