aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-04 18:11:21 +0000
committerGravatar vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-04 18:11:21 +0000
commit6eb549e8ca3d88d7536859fd5aa3343fc3011f2f (patch)
treed97411a5a61648e62f2e23e6139982681b9fa6d1
parente8a76ae8edc4f90456f9d8f90e56bf97f2657f3a (diff)
Revert "Remove SkRefPtr" - r7021
samplecode/ still needs to be updated. Review URL: https://codereview.appspot.com/7032048 git-svn-id: http://skia.googlecode.com/svn/trunk@7022 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--include/core/SkRefCnt.h32
-rw-r--r--src/pdf/SkPDFDevice.cpp58
-rw-r--r--src/pdf/SkPDFDocument.cpp6
-rw-r--r--src/pdf/SkPDFFont.cpp151
-rw-r--r--src/pdf/SkPDFFont.h6
-rw-r--r--src/pdf/SkPDFFormXObject.cpp6
-rw-r--r--src/pdf/SkPDFGraphicState.cpp16
-rw-r--r--src/pdf/SkPDFImage.cpp19
-rw-r--r--src/pdf/SkPDFPage.cpp22
-rw-r--r--src/pdf/SkPDFPage.h4
-rw-r--r--src/pdf/SkPDFShader.cpp23
-rw-r--r--src/pdf/SkPDFStream.cpp16
-rw-r--r--src/pdf/SkPDFStream.h4
-rw-r--r--src/pdf/SkPDFTypes.cpp5
-rw-r--r--src/pdf/SkPDFTypes.h2
-rw-r--r--tests/PDFPrimitivesTest.cpp102
-rw-r--r--tests/UtilsTest.cpp30
17 files changed, 325 insertions, 177 deletions
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h
index 17d77de288..21ed0efec3 100644
--- a/include/core/SkRefCnt.h
+++ b/include/core/SkRefCnt.h
@@ -229,5 +229,37 @@ private:
SkRefCnt* fObj;
};
+/** Wrapper class for SkRefCnt pointers. This manages ref/unref of a pointer to
+ a SkRefCnt (or subclass) object.
+ */
+template <typename T> class SkRefPtr {
+public:
+ SkRefPtr() : fObj(NULL) {}
+ SkRefPtr(T* obj) : fObj(obj) { SkSafeRef(fObj); }
+ SkRefPtr(const SkRefPtr& o) : fObj(o.fObj) { SkSafeRef(fObj); }
+ ~SkRefPtr() { SkSafeUnref(fObj); }
+
+ SkRefPtr& operator=(const SkRefPtr& rp) {
+ SkRefCnt_SafeAssign(fObj, rp.fObj);
+ return *this;
+ }
+ SkRefPtr& operator=(T* obj) {
+ SkRefCnt_SafeAssign(fObj, obj);
+ return *this;
+ }
+
+ T* get() const { return fObj; }
+ T& operator*() const { return *fObj; }
+ T* operator->() const { return fObj; }
+
+ typedef T* SkRefPtr::*unspecified_bool_type;
+ operator unspecified_bool_type() const {
+ return fObj ? &SkRefPtr::fObj : NULL;
+ }
+
+private:
+ T* fObj;
+};
+
#endif
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index 7f189aad5f..0de011c63c 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -1006,7 +1006,8 @@ SkPDFDict* SkPDFDevice::getResourceDict() {
fResourceDict = SkNEW(SkPDFDict);
if (fGraphicStateResources.count()) {
- SkAutoTUnref<SkPDFDict> extGState(new SkPDFDict());
+ SkRefPtr<SkPDFDict> extGState = new SkPDFDict();
+ extGState->unref(); // SkRefPtr and new both took a reference.
for (int i = 0; i < fGraphicStateResources.count(); i++) {
SkString nameString("G");
nameString.appendS32(i);
@@ -1018,7 +1019,8 @@ SkPDFDict* SkPDFDevice::getResourceDict() {
}
if (fXObjectResources.count()) {
- SkAutoTUnref<SkPDFDict> xObjects(new SkPDFDict());
+ SkRefPtr<SkPDFDict> xObjects = new SkPDFDict();
+ xObjects->unref(); // SkRefPtr and new both took a reference.
for (int i = 0; i < fXObjectResources.count(); i++) {
SkString nameString("X");
nameString.appendS32(i);
@@ -1030,7 +1032,8 @@ SkPDFDict* SkPDFDevice::getResourceDict() {
}
if (fFontResources.count()) {
- SkAutoTUnref<SkPDFDict> fonts(new SkPDFDict());
+ SkRefPtr<SkPDFDict> fonts = new SkPDFDict();
+ fonts->unref(); // SkRefPtr and new both took a reference.
for (int i = 0; i < fFontResources.count(); i++) {
SkString nameString("F");
nameString.appendS32(i);
@@ -1041,7 +1044,8 @@ SkPDFDict* SkPDFDevice::getResourceDict() {
}
if (fShaderResources.count()) {
- SkAutoTUnref<SkPDFDict> patterns(new SkPDFDict());
+ SkRefPtr<SkPDFDict> patterns = new SkPDFDict();
+ patterns->unref(); // SkRefPtr and new both took a reference.
for (int i = 0; i < fShaderResources.count(); i++) {
SkString nameString("P");
nameString.appendS32(i);
@@ -1054,7 +1058,8 @@ 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"};
- SkAutoTUnref<SkPDFArray> procSets(new SkPDFArray());
+ SkRefPtr<SkPDFArray> procSets = new SkPDFArray();
+ procSets->unref(); // SkRefPtr and new both took a reference.
procSets->reserve(SK_ARRAY_COUNT(procs));
for (size_t i = 0; i < SK_ARRAY_COUNT(procs); i++)
procSets->appendName(procs[i]);
@@ -1261,8 +1266,9 @@ void SkPDFDevice::drawFormXObjectWithClip(SkPDFFormXObject* xobject,
SkPaint stockPaint;
this->drawPaint(draw, stockPaint);
SkAutoTUnref<SkPDFFormXObject> maskFormXObject(createFormXObjectFromDevice());
- SkAutoTUnref<SkPDFGraphicState> sMaskGS(
- SkPDFGraphicState::GetSMaskGraphicState(maskFormXObject, invertClip));
+ SkRefPtr<SkPDFGraphicState> sMaskGS =
+ SkPDFGraphicState::GetSMaskGraphicState(maskFormXObject, invertClip);
+ sMaskGS->unref(); // SkRefPtr and getSMaskGraphicState both took a ref.
// Draw the xobject with the clip as a mask.
ScopedContentEntry content(this, &fExistingClipStack, fExistingClipRegion,
@@ -1277,7 +1283,8 @@ void SkPDFDevice::drawFormXObjectWithClip(SkPDFFormXObject* xobject,
fXObjectResources.push(xobject);
xobject->ref();
- sMaskGS.reset(SkPDFGraphicState::GetNoSMaskGraphicState());
+ sMaskGS = SkPDFGraphicState::GetNoSMaskGraphicState();
+ sMaskGS->unref(); // SkRefPtr and getSMaskGraphicState both took a ref.
SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()),
&content.entry()->fContent);
}
@@ -1414,25 +1421,27 @@ void SkPDFDevice::finishContentEntry(const SkXfermode::Mode xfermode,
return;
}
- SkAutoTUnref<SkPDFGraphicState> sMaskGS;
+ SkRefPtr<SkPDFGraphicState> sMaskGS;
if (xfermode == SkXfermode::kSrcIn_Mode ||
xfermode == SkXfermode::kSrcOut_Mode) {
- sMaskGS.reset(SkPDFGraphicState::GetSMaskGraphicState(
- dst, xfermode == SkXfermode::kSrcOut_Mode));
+ sMaskGS = SkPDFGraphicState::GetSMaskGraphicState(
+ dst, xfermode == SkXfermode::kSrcOut_Mode);
fXObjectResources.push(srcFormXObject.get());
srcFormXObject.get()->ref();
} else {
- sMaskGS.reset(SkPDFGraphicState::GetSMaskGraphicState(
- srcFormXObject.get(), xfermode == SkXfermode::kDstOut_Mode));
+ sMaskGS = 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.reset(SkPDFGraphicState::GetNoSMaskGraphicState());
+ sMaskGS = SkPDFGraphicState::GetNoSMaskGraphicState();
+ sMaskGS->unref(); // SkRefPtr and getSMaskGraphicState both took a ref.
SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()),
&inClipContentEntry.entry()->fContent);
}
@@ -1465,7 +1474,7 @@ void SkPDFDevice::populateGraphicStateEntryFromPaint(
entry->fShaderIndex = -1;
// PDF treats a shader as a color, so we only set one or the other.
- SkAutoTUnref<SkPDFObject> pdfShader;
+ SkRefPtr<SkPDFObject> pdfShader;
const SkShader* shader = paint.getShader();
SkColor color = paint.getColor();
if (shader) {
@@ -1485,7 +1494,8 @@ void SkPDFDevice::populateGraphicStateEntryFromPaint(
fInitialTransform.mapRect(&boundsTemp);
boundsTemp.roundOut(&bounds);
- pdfShader.reset(SkPDFShader::GetPDFShader(*shader, transform, bounds));
+ pdfShader = SkPDFShader::GetPDFShader(*shader, transform, bounds);
+ SkSafeUnref(pdfShader.get()); // getShader and SkRefPtr both took a ref
if (pdfShader.get()) {
// pdfShader has been canonicalized so we can directly compare
@@ -1494,7 +1504,7 @@ void SkPDFDevice::populateGraphicStateEntryFromPaint(
if (resourceIndex < 0) {
resourceIndex = fShaderResources.count();
fShaderResources.push(pdfShader.get());
- pdfShader.get()->ref();
+ pdfShader->ref();
}
entry->fShaderIndex = resourceIndex;
} else {
@@ -1513,16 +1523,15 @@ void SkPDFDevice::populateGraphicStateEntryFromPaint(
}
}
- SkAutoTUnref<SkPDFGraphicState> newGraphicState;
+ SkRefPtr<SkPDFGraphicState> newGraphicState;
if (color == paint.getColor()) {
- newGraphicState.reset(
- SkPDFGraphicState::GetGraphicStateForPaint(paint));
+ newGraphicState = SkPDFGraphicState::GetGraphicStateForPaint(paint);
} else {
SkPaint newPaint = paint;
newPaint.setColor(color);
- newGraphicState.reset(
- SkPDFGraphicState::GetGraphicStateForPaint(newPaint));
+ newGraphicState = SkPDFGraphicState::GetGraphicStateForPaint(newPaint);
}
+ newGraphicState->unref(); // getGraphicState and SkRefPtr both took a ref.
int resourceIndex = addGraphicStateResource(newGraphicState.get());
entry->fGraphicStateIndex = resourceIndex;
@@ -1563,12 +1572,13 @@ void SkPDFDevice::updateFont(const SkPaint& paint, uint16_t glyphID,
}
int SkPDFDevice::getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID) {
- SkAutoTUnref<SkPDFFont> newFont(SkPDFFont::GetFontResource(typeface, glyphID));
+ SkRefPtr<SkPDFFont> newFont = SkPDFFont::GetFontResource(typeface, glyphID);
+ newFont->unref(); // getFontResource and SkRefPtr both took a ref.
int resourceIndex = fFontResources.find(newFont.get());
if (resourceIndex < 0) {
resourceIndex = fFontResources.count();
fFontResources.push(newFont.get());
- newFont.get()->ref();
+ newFont->ref();
}
return resourceIndex;
}
diff --git a/src/pdf/SkPDFDocument.cpp b/src/pdf/SkPDFDocument.cpp
index c7266d8454..7e064ee19d 100644
--- a/src/pdf/SkPDFDocument.cpp
+++ b/src/pdf/SkPDFDocument.cpp
@@ -98,11 +98,13 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
fDocCatalog->insert("Pages", new SkPDFObjRef(pageTreeRoot))->unref();
/* TODO(vandebo): output intent
- SkAutoTUnref<SkPDFDict> outputIntent = new SkPDFDict("OutputIntent");
+ SkRefPtr<SkPDFDict> outputIntent = new SkPDFDict("OutputIntent");
+ outputIntent->unref(); // SkRefPtr and new both took a reference.
outputIntent->insert("S", new SkPDFName("GTS_PDFA1"))->unref();
outputIntent->insert("OutputConditionIdentifier",
new SkPDFString("sRGB"))->unref();
- SkAutoTUnref<SkPDFArray> intentArray = new SkPDFArray;
+ SkRefPtr<SkPDFArray> intentArray = new SkPDFArray;
+ intentArray->unref(); // SkRefPtr and new both took a reference.
intentArray->append(outputIntent.get());
fDocCatalog->insert("OutputIntent", intentArray.get());
*/
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index f2b3f53162..9a8f13600b 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -155,12 +155,13 @@ 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;
- SkAutoTUnref<SkMemoryStream> staticStream;
+ SkRefPtr<SkMemoryStream> staticStream;
SkData* data = NULL;
const uint8_t* src;
size_t srcLen;
if ((srcLen = srcStream->getLength()) > 0) {
- staticStream.reset(new SkMemoryStream(srcLen + 1));
+ staticStream = new SkMemoryStream(srcLen + 1);
+ staticStream->unref(); // new and SkRefPtr both took a ref.
src = (const uint8_t*)staticStream->getMemoryBase();
if (srcStream->getMemoryBase() != NULL) {
memcpy((void *)src, srcStream->getMemoryBase(), srcLen);
@@ -317,7 +318,8 @@ SkPDFArray* composeAdvanceData(
break;
}
case SkAdvancedTypefaceMetrics::WidthRange::kRange: {
- SkAutoTUnref<SkPDFArray> advanceArray(new SkPDFArray());
+ SkRefPtr<SkPDFArray> advanceArray = new SkPDFArray();
+ advanceArray->unref(); // SkRefPtr and new both took a ref.
for (int j = 0; j < advanceInfo->fAdvance.count(); j++)
appendAdvance(advanceInfo->fAdvance[j], emSize,
advanceArray.get());
@@ -528,7 +530,8 @@ static SkPDFStream* generate_tounicode_cmap(
append_tounicode_header(&cmap);
append_cmap_sections(glyphToUnicode, subset, &cmap);
append_cmap_footer(&cmap);
- SkAutoTUnref<SkMemoryStream> cmapStream(new SkMemoryStream());
+ SkRefPtr<SkMemoryStream> cmapStream = new SkMemoryStream();
+ cmapStream->unref(); // SkRefPtr and new took a reference.
cmapStream->setData(cmap.copyToData())->unref();
return new SkPDFStream(cmapStream.get());
}
@@ -544,8 +547,9 @@ static int get_subset_font_stream(const char* fontName,
const SkTypeface* typeface,
const SkTDArray<uint32_t>& subset,
SkPDFStream** fontStream) {
- SkAutoTUnref<SkStream> fontData(
- SkFontHost::OpenStream(SkTypeface::UniqueID(typeface)));
+ SkRefPtr<SkStream> fontData =
+ SkFontHost::OpenStream(SkTypeface::UniqueID(typeface));
+ fontData->unref(); // SkRefPtr and OpenStream both took a ref.
int fontSize = fontData->getLength();
@@ -762,12 +766,11 @@ SkPDFFont* SkPDFFont::GetFontResource(SkTypeface* typeface, uint16_t glyphID) {
return CanonicalFonts()[relatedFontIndex].fFont;
}
- SkAutoTUnref<SkAdvancedTypefaceMetrics> fontMetrics;
+ SkRefPtr<SkAdvancedTypefaceMetrics> fontMetrics;
SkPDFDict* relatedFontDescriptor = NULL;
if (relatedFontIndex >= 0) {
SkPDFFont* relatedFont = CanonicalFonts()[relatedFontIndex].fFont;
- fontMetrics.reset(relatedFont->fontInfo());
- SkSafeRef(fontMetrics.get());
+ fontMetrics = relatedFont->fontInfo();
relatedFontDescriptor = relatedFont->getFontDescriptor();
// This only is to catch callers who pass invalid glyph ids.
@@ -791,16 +794,18 @@ SkPDFFont* SkPDFFont::GetFontResource(SkTypeface* typeface, uint16_t glyphID) {
info = SkTBitOr<SkAdvancedTypefaceMetrics::PerGlyphInfo>(
info, SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo);
#endif
- fontMetrics.reset(
- SkFontHost::GetAdvancedTypefaceMetrics(fontID, info, NULL, 0));
+ fontMetrics =
+ SkFontHost::GetAdvancedTypefaceMetrics(fontID, info, NULL, 0);
+ SkSafeUnref(fontMetrics.get()); // SkRefPtr and Get both took a ref.
#if defined (SK_SFNTLY_SUBSETTER)
- if (fontMetrics.get() &&
+ if (fontMetrics &&
fontMetrics->fType != SkAdvancedTypefaceMetrics::kTrueType_Font) {
// Font does not support subsetting, get new info with advance.
info = SkTBitOr<SkAdvancedTypefaceMetrics::PerGlyphInfo>(
info, SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo);
- fontMetrics.reset(
- SkFontHost::GetAdvancedTypefaceMetrics(fontID, info, NULL, 0));
+ fontMetrics =
+ SkFontHost::GetAdvancedTypefaceMetrics(fontID, info, NULL, 0);
+ SkSafeUnref(fontMetrics.get()); // SkRefPtr and Get both took a ref
}
#endif
}
@@ -851,8 +856,6 @@ 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) {
@@ -903,8 +906,7 @@ void SkPDFFont::setFontInfo(SkAdvancedTypefaceMetrics* info) {
if (info == NULL || info == fFontInfo.get()) {
return;
}
- fFontInfo.reset(info);
- SkSafeRef(info);
+ fFontInfo = info;
}
uint16_t SkPDFFont::firstGlyphID() const {
@@ -922,7 +924,6 @@ void SkPDFFont::setLastGlyphID(uint16_t glyphID) {
void SkPDFFont::addResource(SkPDFObject* object) {
SkASSERT(object != NULL);
fResources.push(object);
- object->ref();
}
SkPDFDict* SkPDFFont::getFontDescriptor() {
@@ -930,8 +931,7 @@ SkPDFDict* SkPDFFont::getFontDescriptor() {
}
void SkPDFFont::setFontDescriptor(SkPDFDict* descriptor) {
- fDescriptor.reset(descriptor);
- SkSafeRef(descriptor);
+ fDescriptor = 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;
}
- SkAutoTUnref<SkPDFStream> pdfCmap(
- generate_tounicode_cmap(fFontInfo->fGlyphToUnicode, subset));
- addResource(pdfCmap.get());
+ SkRefPtr<SkPDFStream> pdfCmap =
+ generate_tounicode_cmap(fFontInfo->fGlyphToUnicode, subset);
+ addResource(pdfCmap.get()); // Pass reference from new.
insert("ToUnicode", new SkPDFObjRef(pdfCmap.get()))->unref();
}
@@ -1039,11 +1039,14 @@ bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) {
insertName("BaseFont", fontInfo()->fFontName);
insertName("Encoding", "Identity-H");
- SkAutoTUnref<SkPDFCIDFont> newCIDFont(
- new SkPDFCIDFont(fontInfo(), typeface(), subset));
- addResource(newCIDFont.get());
- SkAutoTUnref<SkPDFArray> descendantFonts(new SkPDFArray());
- descendantFonts->append(new SkPDFObjRef(newCIDFont.get()))->unref();
+ 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();
insert("DescendantFonts", descendantFonts.get());
populateToUnicodeTable(subset);
@@ -1066,9 +1069,9 @@ SkPDFCIDFont::~SkPDFCIDFont() {}
bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
const SkTDArray<uint32_t>* subset) {
- SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor"));
+ SkRefPtr<SkPDFDict> descriptor = new SkPDFDict("FontDescriptor");
+ descriptor->unref(); // SkRefPtr and new both took a ref.
setFontDescriptor(descriptor.get());
- addResource(descriptor.get());
switch (getType()) {
case SkAdvancedTypefaceMetrics::kTrueType_Font: {
@@ -1081,20 +1084,22 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
&rawStream);
SkASSERT(fontSize);
SkASSERT(rawStream);
- SkAutoTUnref<SkPDFStream> fontStream(rawStream);
+ SkRefPtr<SkPDFStream> fontStream = rawStream;
+ // SkRefPtr and new both ref()'d fontStream, pass one.
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: {
- SkAutoTUnref<SkStream> fontData(
- SkFontHost::OpenStream(SkTypeface::UniqueID(typeface())));
- SkAutoTUnref<SkPDFStream> fontStream(
- new SkPDFStream(fontData.get()));
+ 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.
addResource(fontStream.get());
if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) {
@@ -1110,6 +1115,9 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
SkASSERT(false);
}
+ addResource(descriptor.get());
+ descriptor->ref();
+
insert("FontDescriptor", new SkPDFObjRef(descriptor.get()))->unref();
return addCommonFontDescriptorEntries(defaultWidth);
}
@@ -1124,18 +1132,20 @@ 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;
- SkAutoTUnref<SkAdvancedTypefaceMetrics> fontMetrics(
+ fontMetrics =
SkFontHost::GetAdvancedTypefaceMetrics(
SkTypeface::UniqueID(typeface()),
info,
glyphs,
- glyphsCount));
+ glyphsCount);
+ SkSafeUnref(fontMetrics.get()); // SkRefPtr and Get both took a ref
setFontInfo(fontMetrics.get());
addFontDescriptor(0, &glyphIDs);
} else {
@@ -1154,7 +1164,8 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) {
SkASSERT(false);
}
- SkAutoTUnref<SkPDFDict> sysInfo(new SkPDFDict);
+ SkRefPtr<SkPDFDict> sysInfo = new SkPDFDict;
+ sysInfo->unref(); // SkRefPtr and new both took a reference.
sysInfo->insert("Registry", new SkPDFString("Adobe"))->unref();
sysInfo->insert("Ordering", new SkPDFString("Identity"))->unref();
sysInfo->insertInt("Supplement", 0);
@@ -1162,10 +1173,11 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) {
if (fontInfo()->fGlyphWidths.get()) {
int16_t defaultWidth = 0;
- SkAutoTUnref<SkPDFArray> widths(
+ SkRefPtr<SkPDFArray> widths =
composeAdvanceData(fontInfo()->fGlyphWidths.get(),
fontInfo()->fEmSize, &appendWidth,
- &defaultWidth));
+ &defaultWidth);
+ widths->unref(); // SkRefPtr and compose both took a reference.
if (widths->size())
insert("W", widths.get());
if (defaultWidth != 0) {
@@ -1178,10 +1190,11 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) {
defaultAdvance.fVerticalAdvance = 0;
defaultAdvance.fOriginXDisp = 0;
defaultAdvance.fOriginYDisp = 0;
- SkAutoTUnref<SkPDFArray> advances(
+ SkRefPtr<SkPDFArray> advances =
composeAdvanceData(fontInfo()->fVerticalMetrics.get(),
fontInfo()->fEmSize, &appendVerticalAdvance,
- &defaultAdvance));
+ &defaultAdvance);
+ advances->unref(); // SkRefPtr and compose both took a ref.
if (advances->size())
insert("W2", advances.get());
if (defaultAdvance.fVerticalAdvance ||
@@ -1211,27 +1224,31 @@ SkPDFType1Font::SkPDFType1Font(SkAdvancedTypefaceMetrics* info,
SkPDFType1Font::~SkPDFType1Font() {}
bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) {
- if (getFontDescriptor() != NULL) {
- SkPDFDict* descriptor = getFontDescriptor();
- addResource(descriptor);
- insert("FontDescriptor", new SkPDFObjRef(descriptor))->unref();
+ SkRefPtr<SkPDFDict> descriptor = getFontDescriptor();
+ if (descriptor.get() != NULL) {
+ addResource(descriptor.get());
+ descriptor->ref();
+ insert("FontDescriptor", new SkPDFObjRef(descriptor.get()))->unref();
return true;
}
- SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor"));
+ descriptor = new SkPDFDict("FontDescriptor");
+ descriptor->unref(); // SkRefPtr and new both took a ref.
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;
- SkAutoTUnref<SkStream> rawFontData(
- SkFontHost::OpenStream(SkTypeface::UniqueID(typeface())));
+ SkRefPtr<SkStream> rawFontData =
+ SkFontHost::OpenStream(SkTypeface::UniqueID(typeface()));
+ rawFontData->unref(); // SkRefPtr and OpenStream both took a ref.
SkStream* fontData = handleType1Stream(rawFontData.get(), &header, &data,
&trailer);
if (fontData == NULL) {
return false;
}
- SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData));
+ SkRefPtr<SkPDFStream> fontStream = new SkPDFStream(fontData);
+ // SkRefPtr and new both ref()'d fontStream, pass one.
addResource(fontStream.get());
fontStream->insertInt("Length1", header);
fontStream->insertInt("Length2", data);
@@ -1239,6 +1256,7 @@ 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);
@@ -1279,10 +1297,12 @@ bool SkPDFType1Font::populate(int16_t glyphID) {
addWidthInfoFromRange(defaultWidth, widthRangeEntry);
- SkAutoTUnref<SkPDFDict> encoding(new SkPDFDict("Encoding"));
+ SkRefPtr<SkPDFDict> encoding = new SkPDFDict("Encoding");
+ encoding->unref(); // SkRefPtr and new both took a reference.
insert("Encoding", encoding.get());
- SkAutoTUnref<SkPDFArray> encDiffs(new SkPDFArray);
+ SkRefPtr<SkPDFArray> encDiffs = new SkPDFArray;
+ encDiffs->unref(); // SkRefPtr and new both took a reference.
encoding->insert("Differences", encDiffs.get());
encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2);
@@ -1297,7 +1317,8 @@ bool SkPDFType1Font::populate(int16_t glyphID) {
void SkPDFType1Font::addWidthInfoFromRange(
int16_t defaultWidth,
const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry) {
- SkAutoTUnref<SkPDFArray> widthArray(new SkPDFArray());
+ SkRefPtr<SkPDFArray> widthArray = new SkPDFArray();
+ widthArray->unref(); // SkRefPtr and new both took a ref.
int firstChar = 0;
if (widthRangeEntry) {
const uint16_t emSize = fontInfo()->fEmSize;
@@ -1356,18 +1377,22 @@ bool SkPDFType3Font::populate(int16_t glyphID) {
fontMatrix.setScale(SkScalarInvert(1000), -SkScalarInvert(1000));
insert("FontMatrix", SkPDFUtils::MatrixToArray(fontMatrix))->unref();
- SkAutoTUnref<SkPDFDict> charProcs(new SkPDFDict);
+ SkRefPtr<SkPDFDict> charProcs = new SkPDFDict;
+ charProcs->unref(); // SkRefPtr and new both took a reference.
insert("CharProcs", charProcs.get());
- SkAutoTUnref<SkPDFDict> encoding(new SkPDFDict("Encoding"));
+ SkRefPtr<SkPDFDict> encoding = new SkPDFDict("Encoding");
+ encoding->unref(); // SkRefPtr and new both took a reference.
insert("Encoding", encoding.get());
- SkAutoTUnref<SkPDFArray> encDiffs(new SkPDFArray);
+ SkRefPtr<SkPDFArray> encDiffs = new SkPDFArray;
+ encDiffs->unref(); // SkRefPtr and new both took a reference.
encoding->insert("Differences", encDiffs.get());
encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2);
encDiffs->appendInt(1);
- SkAutoTUnref<SkPDFArray> widthArray(new SkPDFArray());
+ SkRefPtr<SkPDFArray> widthArray = new SkPDFArray();
+ widthArray->unref(); // SkRefPtr and new both took a ref.
SkIRect bbox = SkIRect::MakeEmpty();
for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) {
@@ -1390,11 +1415,13 @@ bool SkPDFType3Font::populate(int16_t glyphID) {
SkPDFUtils::PaintPath(paint.getStyle(), path->getFillType(),
&content);
}
- SkAutoTUnref<SkMemoryStream> glyphStream(new SkMemoryStream());
+ SkRefPtr<SkMemoryStream> glyphStream = new SkMemoryStream();
+ glyphStream->unref(); // SkRefPtr and new both took a ref.
glyphStream->setData(content.copyToData())->unref();
- SkAutoTUnref<SkPDFStream> glyphDescription(
- new SkPDFStream(glyphStream.get()));
+ SkRefPtr<SkPDFStream> glyphDescription =
+ new SkPDFStream(glyphStream.get());
+ // SkRefPtr and new both ref()'d charProcs, pass one.
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 693b911061..f463ed740a 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);
};
- SkAutoTUnref<SkTypeface> fTypeface;
+ SkRefPtr<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.
- SkAutoTUnref<SkAdvancedTypefaceMetrics> fFontInfo;
+ SkRefPtr<SkAdvancedTypefaceMetrics> fFontInfo;
SkTDArray<SkPDFObject*> fResources;
- SkAutoTUnref<SkPDFDict> fDescriptor;
+ SkRefPtr<SkPDFDict> fDescriptor;
SkAdvancedTypefaceMetrics::FontType fFontType;
diff --git a/src/pdf/SkPDFFormXObject.cpp b/src/pdf/SkPDFFormXObject.cpp
index 5e33995b74..e148056afe 100644
--- a/src/pdf/SkPDFFormXObject.cpp
+++ b/src/pdf/SkPDFFormXObject.cpp
@@ -31,7 +31,8 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) {
getResources(&dummy_resourceList);
#endif
- SkAutoTUnref<SkStream> content(device->content());
+ SkRefPtr<SkStream> content = device->content();
+ content->unref(); // SkRefPtr and content() both took a reference.
setData(content.get());
insertName("Type", "XObject");
@@ -54,7 +55,8 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) {
// Right now SkPDFFormXObject is only used for saveLayer, which implies
// isolated blending. Do this conditionally if that changes.
- SkAutoTUnref<SkPDFDict> group(new SkPDFDict("Group"));
+ SkRefPtr<SkPDFDict> group = new SkPDFDict("Group");
+ group->unref(); // SkRefPtr and new both took a reference.
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 c326b3b533..ec9b0e70b2 100644
--- a/src/pdf/SkPDFGraphicState.cpp
+++ b/src/pdf/SkPDFGraphicState.cpp
@@ -113,14 +113,16 @@ 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.
- SkAutoTUnref<SkPDFArray> domainAndRange(new SkPDFArray);
+ SkRefPtr<SkPDFArray> domainAndRange = new SkPDFArray;
+ domainAndRange->unref(); // SkRefPtr and new both took a reference.
domainAndRange->reserve(2);
domainAndRange->appendInt(0);
domainAndRange->appendInt(1);
static const char psInvert[] = "{1 exch sub}";
- SkAutoTUnref<SkMemoryStream> psInvertStream(
- new SkMemoryStream(&psInvert, strlen(psInvert), true));
+ SkRefPtr<SkMemoryStream> psInvertStream =
+ new SkMemoryStream(&psInvert, strlen(psInvert), true);
+ psInvertStream->unref(); // SkRefPtr and new both took a reference.
invertFunction = new SkPDFStream(psInvertStream.get());
invertFunction->insertInt("FunctionType", 4);
@@ -137,7 +139,8 @@ SkPDFGraphicState* SkPDFGraphicState::GetSMaskGraphicState(
// enough that it's not worth canonicalizing.
SkAutoMutexAcquire lock(CanonicalPaintsMutex());
- SkAutoTUnref<SkPDFDict> sMaskDict(new SkPDFDict("Mask"));
+ SkRefPtr<SkPDFDict> sMaskDict = new SkPDFDict("Mask");
+ sMaskDict->unref(); // SkRefPtr and new both took a reference.
sMaskDict->insertName("S", "Alpha");
sMaskDict->insert("G", new SkPDFObjRef(sMask))->unref();
@@ -197,8 +200,9 @@ void SkPDFGraphicState::populateDict() {
fPopulated = true;
insertName("Type", "ExtGState");
- SkAutoTUnref<SkPDFScalar> alpha(
- new SkPDFScalar(SkScalarDiv(fPaint.getAlpha(), 0xFF)));
+ SkRefPtr<SkPDFScalar> alpha =
+ new SkPDFScalar(SkScalarDiv(fPaint.getAlpha(), 0xFF));
+ alpha->unref(); // SkRefPtr and new both took a reference.
insert("CA", alpha.get());
insert("ca", alpha.get());
diff --git a/src/pdf/SkPDFImage.cpp b/src/pdf/SkPDFImage.cpp
index 1b93f6e045..429667a5e2 100644
--- a/src/pdf/SkPDFImage.cpp
+++ b/src/pdf/SkPDFImage.cpp
@@ -305,7 +305,8 @@ 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.
- SkAutoTUnref<SkPDFInt> one(new SkPDFInt(1));
+ SkRefPtr<SkPDFInt> one = new SkPDFInt(1);
+ one->unref(); // SkRefPtr and new both took a reference.
insert("Width", one.get());
insert("Height", one.get());
} else {
@@ -334,12 +335,16 @@ SkPDFImage::SkPDFImage(SkStream* imageData, const SkBitmap& bitmap,
insertInt("BitsPerComponent", bitsPerComp);
if (config == SkBitmap::kRGB_565_Config) {
- 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());
+ 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.
decodeValue->reserve(6);
decodeValue->append(zeroVal.get());
decodeValue->append(scale5Val.get());
diff --git a/src/pdf/SkPDFPage.cpp b/src/pdf/SkPDFPage.cpp
index a18beb156f..717f435356 100644
--- a/src/pdf/SkPDFPage.cpp
+++ b/src/pdf/SkPDFPage.cpp
@@ -15,7 +15,6 @@
SkPDFPage::SkPDFPage(SkPDFDevice* content)
: SkPDFDict("Page"),
fDevice(content) {
- SkSafeRef(content);
}
SkPDFPage::~SkPDFPage() {}
@@ -33,8 +32,10 @@ void SkPDFPage::finalizePage(SkPDFCatalog* catalog, bool firstPage,
}
}
- SkAutoTUnref<SkStream> content(fDevice->content());
- fContentStream.reset(new SkPDFStream(content.get()));
+ 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.
insert("Contents", new SkPDFObjRef(fContentStream.get()))->unref();
}
catalog->addObject(fContentStream.get(), firstPage);
@@ -66,9 +67,12 @@ void SkPDFPage::GeneratePageTree(const SkTDArray<SkPDFPage*>& pages,
// one child.
static const int kNodeSize = 8;
- SkAutoTUnref<SkPDFName> kidsName(new SkPDFName("Kids"));
- SkAutoTUnref<SkPDFName> countName(new SkPDFName("Count"));
- SkAutoTUnref<SkPDFName> parentName(new SkPDFName("Parent"));
+ 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.
// curNodes takes a reference to its items, which it passes to pageTree.
SkTDArray<SkPDFDict*> curNodes;
@@ -91,9 +95,11 @@ void SkPDFPage::GeneratePageTree(const SkTDArray<SkPDFPage*>& pages,
}
SkPDFDict* newNode = new SkPDFDict("Pages");
- SkAutoTUnref<SkPDFObjRef> newNodeRef(new SkPDFObjRef(newNode));
+ SkRefPtr<SkPDFObjRef> newNodeRef = new SkPDFObjRef(newNode);
+ newNodeRef->unref(); // SkRefPtr and new both took a reference.
- SkAutoTUnref<SkPDFArray> kids(new SkPDFArray);
+ SkRefPtr<SkPDFArray> kids = new SkPDFArray;
+ kids->unref(); // SkRefPtr and new both took a reference.
kids->reserve(kNodeSize);
int count = 0;
diff --git a/src/pdf/SkPDFPage.h b/src/pdf/SkPDFPage.h
index 72ba335e66..8ef909e573 100644
--- a/src/pdf/SkPDFPage.h
+++ b/src/pdf/SkPDFPage.h
@@ -91,10 +91,10 @@ public:
private:
// Multiple pages may reference the content.
- SkAutoTUnref<SkPDFDevice> fDevice;
+ SkRefPtr<SkPDFDevice> fDevice;
// Once the content is finalized, put it into a stream for output.
- SkAutoTUnref<SkPDFStream> fContentStream;
+ SkRefPtr<SkPDFStream> fContentStream;
};
#endif
diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp
index 7958de38ce..db5beb8fc8 100644
--- a/src/pdf/SkPDFShader.cpp
+++ b/src/pdf/SkPDFShader.cpp
@@ -612,7 +612,8 @@ SkPDFFunctionShader::SkPDFFunctionShader(SkPDFShader::State* state)
return;
}
- SkAutoTUnref<SkPDFArray> domain(new SkPDFArray);
+ SkRefPtr<SkPDFArray> domain = new SkPDFArray;
+ domain->unref(); // SkRefPtr and new both took a reference.
domain->reserve(4);
domain->appendScalar(bbox.fLeft);
domain->appendScalar(bbox.fRight);
@@ -639,14 +640,16 @@ SkPDFFunctionShader::SkPDFFunctionShader(SkPDFShader::State* state)
functionCode = codeFunction(*info);
}
- SkAutoTUnref<SkPDFDict> pdfShader(new SkPDFDict);
+ 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.
pdfShader->insertInt("ShadingType", 1);
pdfShader->insertName("ColorSpace", "DeviceRGB");
pdfShader->insert("Domain", domain.get());
-
- SkPDFStream* function = makePSFunction(functionCode, domain.get());
- pdfShader->insert("Function", new SkPDFObjRef(function))->unref();
- fResources.push(function); // Pass ownership to resource list.
+ pdfShader->insert("Function", new SkPDFObjRef(function.get()))->unref();
insertInt("PatternType", 2);
insert("Matrix", SkPDFUtils::MatrixToArray(finalMatrix))->unref();
@@ -822,7 +825,8 @@ SkPDFImageShader::SkPDFImageShader(SkPDFShader::State* state) : fState(state) {
}
}
- SkAutoTUnref<SkPDFArray> patternBBoxArray(new SkPDFArray);
+ SkRefPtr<SkPDFArray> patternBBoxArray = new SkPDFArray;
+ patternBBoxArray->unref(); // SkRefPtr and new both took a reference.
patternBBoxArray->reserve(4);
patternBBoxArray->appendScalar(patternBBox.fLeft);
patternBBoxArray->appendScalar(patternBBox.fTop);
@@ -830,10 +834,11 @@ SkPDFImageShader::SkPDFImageShader(SkPDFShader::State* state) : fState(state) {
patternBBoxArray->appendScalar(patternBBox.fBottom);
// Put the canvas into the pattern stream (fContent).
- SkAutoTUnref<SkStream> content(pattern.content());
- setData(content.get());
+ SkRefPtr<SkStream> content = pattern.content();
+ content->unref(); // SkRefPtr and content() both took a reference.
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 38e874ea1b..d113a0b355 100644
--- a/src/pdf/SkPDFStream.cpp
+++ b/src/pdf/SkPDFStream.cpp
@@ -21,20 +21,19 @@ 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.reset(stream); // Transfer ownership.
+ fData = stream;
+ fData->unref(); // SkRefPtr and new both took a reference.
}
SkPDFStream::SkPDFStream(const SkPDFStream& pdfStream)
: SkPDFDict(),
fState(kUnused_State),
- fData(pdfStream.fData.get()) {
- fData.get()->ref();
+ fData(pdfStream.fData) {
bool removeLength = true;
// Don't uncompress an already compressed stream, but we could.
if (pdfStream.fState == kCompressed_State) {
@@ -85,8 +84,7 @@ size_t SkPDFStream::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
SkPDFStream::SkPDFStream() : fState(kUnused_State) {}
void SkPDFStream::setData(SkStream* stream) {
- fData.reset(stream);
- SkSafeRef(stream);
+ fData = stream;
}
bool SkPDFStream::populate(SkPDFCatalog* catalog) {
@@ -98,7 +96,8 @@ bool SkPDFStream::populate(SkPDFCatalog* catalog) {
if (compressedData.getOffset() < fData->getLength()) {
SkMemoryStream* stream = new SkMemoryStream;
stream->setData(compressedData.copyToData())->unref();
- fData.reset(stream); // Transfer ownership.
+ fData = stream;
+ fData->unref(); // SkRefPtr and new both took a reference.
insertName("Filter", "FlateDecode");
}
fState = kCompressed_State;
@@ -109,7 +108,8 @@ bool SkPDFStream::populate(SkPDFCatalog* catalog) {
} else if (fState == kNoCompression_State && !skip_compression(catalog) &&
SkFlate::HaveFlate()) {
if (!fSubstitute.get()) {
- fSubstitute.reset(new SkPDFStream(*this));
+ fSubstitute = new SkPDFStream(*this);
+ fSubstitute->unref(); // SkRefPtr and new both took a reference.
catalog->setSubstitute(this, fSubstitute.get());
}
return false;
diff --git a/src/pdf/SkPDFStream.h b/src/pdf/SkPDFStream.h
index 6f7a08eb81..b3a7ad34e3 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).
- SkAutoTUnref<SkStream> fData;
- SkAutoTUnref<SkPDFStream> fSubstitute;
+ SkRefPtr<SkStream> fData;
+ SkRefPtr<SkPDFStream> fSubstitute;
typedef SkPDFDict INHERITED;
diff --git a/src/pdf/SkPDFTypes.cpp b/src/pdf/SkPDFTypes.cpp
index 59250c8534..7fb1e95532 100644
--- a/src/pdf/SkPDFTypes.cpp
+++ b/src/pdf/SkPDFTypes.cpp
@@ -73,10 +73,7 @@ void SkPDFObject::GetResourcesHelper(SkTDArray<SkPDFObject*>* resources,
}
}
-SkPDFObjRef::SkPDFObjRef(SkPDFObject* obj) : fObj(obj) {
- SkSafeRef(obj);
-}
-
+SkPDFObjRef::SkPDFObjRef(SkPDFObject* obj) : fObj(obj) {}
SkPDFObjRef::~SkPDFObjRef() {}
void SkPDFObjRef::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
diff --git a/src/pdf/SkPDFTypes.h b/src/pdf/SkPDFTypes.h
index 03799d0845..28034ef405 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:
- SkAutoTUnref<SkPDFObject> fObj;
+ SkRefPtr<SkPDFObject> fObj;
typedef SkPDFObject INHERITED;
};
diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp
index 42fc133b3c..5cbb9057be 100644
--- a/tests/PDFPrimitivesTest.cpp
+++ b/tests/PDFPrimitivesTest.cpp
@@ -94,9 +94,11 @@ static void SimpleCheckObjectOutput(skiatest::Reporter* reporter,
static void TestPDFStream(skiatest::Reporter* reporter) {
char streamBytes[] = "Test\nFoo\tBar";
- SkAutoTUnref<SkMemoryStream> streamData(new SkMemoryStream(
- streamBytes, strlen(streamBytes), true));
- SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData.get()));
+ SkRefPtr<SkMemoryStream> streamData = new SkMemoryStream(
+ streamBytes, strlen(streamBytes), true);
+ streamData->unref(); // SkRefPtr and new both took a reference.
+ SkRefPtr<SkPDFStream> stream = new SkPDFStream(streamData.get());
+ stream->unref(); // SkRefPtr and new both took a reference.
SimpleCheckObjectOutput(
reporter, stream.get(),
"<</Length 12\n>> stream\nTest\nFoo\tBar\nendstream");
@@ -112,7 +114,8 @@ static void TestPDFStream(skiatest::Reporter* reporter) {
"with an uncompressed string.";
SkAutoDataUnref streamData2(SkData::NewWithCopy(streamBytes2,
strlen(streamBytes2)));
- SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData2.get()));
+ SkRefPtr<SkPDFStream> stream = new SkPDFStream(streamData2.get());
+ stream->unref(); // SkRefPtr and new both took a reference.
SkDynamicMemoryWStream compressedByteStream;
SkFlate::Deflate(streamData2.get(), &compressedByteStream);
@@ -143,11 +146,13 @@ static void TestPDFStream(skiatest::Reporter* reporter) {
static void TestCatalog(skiatest::Reporter* reporter) {
SkPDFCatalog catalog((SkPDFDocument::Flags)0);
- SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1));
- SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2));
- SkAutoTUnref<SkPDFInt> int3(new SkPDFInt(3));
- int1.get()->ref();
- SkAutoTUnref<SkPDFInt> int1Again(int1.get());
+ SkRefPtr<SkPDFInt> int1 = new SkPDFInt(1);
+ int1->unref(); // SkRefPtr and new both took a reference.
+ SkRefPtr<SkPDFInt> int2 = new SkPDFInt(2);
+ int2->unref(); // SkRefPtr and new both took a reference.
+ SkRefPtr<SkPDFInt> int3 = new SkPDFInt(3);
+ int3->unref(); // SkRefPtr and new both took a reference.
+ SkRefPtr<SkPDFInt> int1Again(int1.get());
catalog.addObject(int1.get(), false);
catalog.addObject(int2.get(), false);
@@ -168,9 +173,12 @@ static void TestCatalog(skiatest::Reporter* reporter) {
}
static void TestObjectRef(skiatest::Reporter* reporter) {
- SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1));
- SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2));
- SkAutoTUnref<SkPDFObjRef> int2ref(new SkPDFObjRef(int2.get()));
+ SkRefPtr<SkPDFInt> int1 = new SkPDFInt(1);
+ int1->unref(); // SkRefPtr and new both took a reference.
+ SkRefPtr<SkPDFInt> int2 = new SkPDFInt(2);
+ int2->unref(); // SkRefPtr and new both took a reference.
+ SkRefPtr<SkPDFObjRef> int2ref = new SkPDFObjRef(int2.get());
+ int2ref->unref(); // SkRefPtr and new both took a reference.
SkPDFCatalog catalog((SkPDFDocument::Flags)0);
catalog.addObject(int1.get(), false);
@@ -187,11 +195,16 @@ static void TestObjectRef(skiatest::Reporter* reporter) {
}
static void TestSubstitute(skiatest::Reporter* reporter) {
- SkAutoTUnref<SkPDFTestDict> proxy(new SkPDFTestDict());
- SkAutoTUnref<SkPDFTestDict> stub(new SkPDFTestDict());
- SkAutoTUnref<SkPDFInt> int33(new SkPDFInt(33));
- SkAutoTUnref<SkPDFDict> stubResource(new SkPDFDict());
- SkAutoTUnref<SkPDFInt> int44(new SkPDFInt(44));
+ SkRefPtr<SkPDFTestDict> proxy = new SkPDFTestDict();
+ proxy->unref(); // SkRefPtr and new both took a reference.
+ SkRefPtr<SkPDFTestDict> stub = new SkPDFTestDict();
+ stub->unref(); // SkRefPtr and new both took a reference.
+ SkRefPtr<SkPDFInt> int33 = new SkPDFInt(33);
+ int33->unref(); // SkRefPtr and new both took a reference.
+ SkRefPtr<SkPDFDict> stubResource = new SkPDFDict();
+ stubResource->unref(); // SkRefPtr and new both took a reference.
+ SkRefPtr<SkPDFInt> int44 = new SkPDFInt(44);
+ int44->unref(); // SkRefPtr and new both took a reference.
stub->insert("Value", int33.get());
stubResource->insert("InnerValue", int44.get());
@@ -218,74 +231,89 @@ static void TestSubstitute(skiatest::Reporter* reporter) {
}
static void TestPDFPrimitives(skiatest::Reporter* reporter) {
- SkAutoTUnref<SkPDFInt> int42(new SkPDFInt(42));
+ SkRefPtr<SkPDFInt> int42 = new SkPDFInt(42);
+ int42->unref(); // SkRefPtr and new both took a reference.
SimpleCheckObjectOutput(reporter, int42.get(), "42");
- SkAutoTUnref<SkPDFScalar> realHalf(new SkPDFScalar(SK_ScalarHalf));
+ SkRefPtr<SkPDFScalar> realHalf = new SkPDFScalar(SK_ScalarHalf);
+ realHalf->unref(); // SkRefPtr and new both took a reference.
SimpleCheckObjectOutput(reporter, realHalf.get(), "0.5");
#if defined(SK_SCALAR_IS_FLOAT)
- SkAutoTUnref<SkPDFScalar> bigScalar(new SkPDFScalar(110999.75f));
+ SkRefPtr<SkPDFScalar> bigScalar = new SkPDFScalar(110999.75f);
+ bigScalar->unref(); // SkRefPtr and new both took a reference.
#if !defined(SK_ALLOW_LARGE_PDF_SCALARS)
SimpleCheckObjectOutput(reporter, bigScalar.get(), "111000");
#else
SimpleCheckObjectOutput(reporter, bigScalar.get(), "110999.75");
- SkAutoTUnref<SkPDFScalar> biggerScalar(new SkPDFScalar(50000000.1));
+ SkRefPtr<SkPDFScalar> biggerScalar = new SkPDFScalar(50000000.1);
+ biggerScalar->unref(); // SkRefPtr and new both took a reference.
SimpleCheckObjectOutput(reporter, biggerScalar.get(), "50000000");
- SkAutoTUnref<SkPDFScalar> smallestScalar(new SkPDFScalar(1.0/65536));
+ SkRefPtr<SkPDFScalar> smallestScalar = new SkPDFScalar(1.0/65536);
+ smallestScalar->unref(); // SkRefPtr and new both took a reference.
SimpleCheckObjectOutput(reporter, smallestScalar.get(), "0.00001526");
#endif
#endif
- SkAutoTUnref<SkPDFString> stringSimple(
- new SkPDFString("test ) string ( foo"));
+ SkRefPtr<SkPDFString> stringSimple = new SkPDFString("test ) string ( foo");
+ stringSimple->unref(); // SkRefPtr and new both took a reference.
SimpleCheckObjectOutput(reporter, stringSimple.get(),
"(test \\) string \\( foo)");
- SkAutoTUnref<SkPDFString> stringComplex(
- new SkPDFString("\ttest ) string ( foo"));
+ SkRefPtr<SkPDFString> stringComplex =
+ new SkPDFString("\ttest ) string ( foo");
+ stringComplex->unref(); // SkRefPtr and new both took a reference.
SimpleCheckObjectOutput(reporter, stringComplex.get(),
"<0974657374202920737472696E67202820666F6F>");
- SkAutoTUnref<SkPDFName> name(new SkPDFName("Test name\twith#tab"));
+ SkRefPtr<SkPDFName> name = new SkPDFName("Test name\twith#tab");
+ name->unref(); // SkRefPtr and new both took a reference.
const char expectedResult[] = "/Test#20name#09with#23tab";
CheckObjectOutput(reporter, name.get(), expectedResult,
strlen(expectedResult), false, false);
- SkAutoTUnref<SkPDFName> escapedName(new SkPDFName("A#/%()<>[]{}B"));
+ SkRefPtr<SkPDFName> escapedName = new SkPDFName("A#/%()<>[]{}B");
+ escapedName->unref(); // SkRefPtr and new both took a reference.
const char escapedNameExpected[] = "/A#23#2F#25#28#29#3C#3E#5B#5D#7B#7DB";
CheckObjectOutput(reporter, escapedName.get(), escapedNameExpected,
strlen(escapedNameExpected), false, false);
// Test that we correctly handle characters with the high-bit set.
const unsigned char highBitCString[] = {0xDE, 0xAD, 'b', 'e', 0xEF, 0};
- SkAutoTUnref<SkPDFName> highBitName(
- new SkPDFName((const char*)highBitCString));
+ SkRefPtr<SkPDFName> highBitName = new SkPDFName((const char*)highBitCString);
+ highBitName->unref(); // SkRefPtr and new both took a reference.
const char highBitExpectedResult[] = "/#DE#ADbe#EF";
CheckObjectOutput(reporter, highBitName.get(), highBitExpectedResult,
strlen(highBitExpectedResult), false, false);
- SkAutoTUnref<SkPDFArray> array(new SkPDFArray);
+ SkRefPtr<SkPDFArray> array = new SkPDFArray;
+ array->unref(); // SkRefPtr and new both took a reference.
SimpleCheckObjectOutput(reporter, array.get(), "[]");
array->append(int42.get());
SimpleCheckObjectOutput(reporter, array.get(), "[42]");
array->append(realHalf.get());
SimpleCheckObjectOutput(reporter, array.get(), "[42 0.5]");
- SkAutoTUnref<SkPDFInt> int0(new SkPDFInt(0));
+ SkRefPtr<SkPDFInt> int0 = new SkPDFInt(0);
+ int0->unref(); // SkRefPtr and new both took a reference.
array->append(int0.get());
SimpleCheckObjectOutput(reporter, array.get(), "[42 0.5 0]");
- SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1));
+ SkRefPtr<SkPDFInt> int1 = new SkPDFInt(1);
+ int1->unref(); // SkRefPtr and new both took a reference.
array->setAt(0, int1.get());
SimpleCheckObjectOutput(reporter, array.get(), "[1 0.5 0]");
- SkAutoTUnref<SkPDFDict> dict(new SkPDFDict);
+ SkRefPtr<SkPDFDict> dict = new SkPDFDict;
+ dict->unref(); // SkRefPtr and new both took a reference.
SimpleCheckObjectOutput(reporter, dict.get(), "<<>>");
- SkAutoTUnref<SkPDFName> n1(new SkPDFName("n1"));
+ SkRefPtr<SkPDFName> n1 = new SkPDFName("n1");
+ n1->unref(); // SkRefPtr and new both took a reference.
dict->insert(n1.get(), int42.get());
SimpleCheckObjectOutput(reporter, dict.get(), "<</n1 42\n>>");
- SkAutoTUnref<SkPDFName> n2(new SkPDFName("n2"));
- SkAutoTUnref<SkPDFName> n3(new SkPDFName("n3"));
+ SkRefPtr<SkPDFName> n2 = new SkPDFName("n2");
+ n2->unref(); // SkRefPtr and new both took a reference.
+ SkRefPtr<SkPDFName> n3 = new SkPDFName("n3");
+ n3->unref(); // SkRefPtr and new both took a reference.
dict->insert(n2.get(), realHalf.get());
dict->insert(n3.get(), array.get());
SimpleCheckObjectOutput(reporter, dict.get(),
diff --git a/tests/UtilsTest.cpp b/tests/UtilsTest.cpp
index 7f27f7e78e..1c2f870d1f 100644
--- a/tests/UtilsTest.cpp
+++ b/tests/UtilsTest.cpp
@@ -27,6 +27,35 @@ private:
SK_DEFINE_INST_COUNT(RefClass)
+static void test_refptr(skiatest::Reporter* reporter) {
+ RefClass* r0 = new RefClass(0);
+
+ SkRefPtr<RefClass> rc0;
+ REPORTER_ASSERT(reporter, rc0.get() == NULL);
+ REPORTER_ASSERT(reporter, !rc0);
+
+ SkRefPtr<RefClass> rc1;
+ REPORTER_ASSERT(reporter, rc0 == rc1);
+ REPORTER_ASSERT(reporter, rc0.get() != r0);
+
+ rc0 = r0;
+ REPORTER_ASSERT(reporter, rc0);
+ REPORTER_ASSERT(reporter, rc0 != rc1);
+ REPORTER_ASSERT(reporter, rc0.get() == r0);
+
+ rc1 = rc0;
+ REPORTER_ASSERT(reporter, rc1);
+ REPORTER_ASSERT(reporter, rc0 == rc1);
+ REPORTER_ASSERT(reporter, rc0.get() == r0);
+
+ rc0 = NULL;
+ REPORTER_ASSERT(reporter, rc0.get() == NULL);
+ REPORTER_ASSERT(reporter, !rc0);
+ REPORTER_ASSERT(reporter, rc0 != rc1);
+
+ r0->unref();
+}
+
static void test_autounref(skiatest::Reporter* reporter) {
RefClass obj(0);
REPORTER_ASSERT(reporter, 1 == obj.getRefCnt());
@@ -149,6 +178,7 @@ static void TestUTF(skiatest::Reporter* reporter) {
test_utf16(reporter);
test_search(reporter);
+ test_refptr(reporter);
test_autounref(reporter);
}