From fc641d09e5a1a9f7fae369ae06a8b96089faf57b Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Thu, 20 Sep 2012 17:52:20 +0000 Subject: [PATCH] remove all SkRefPtr from SkPDFDevice.h Review URL: https://codereview.appspot.com/6542049 git-svn-id: http://skia.googlecode.com/svn/trunk@5609 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/pdf/SkPDFDevice.h | 6 +++--- src/pdf/SkPDFDevice.cpp | 43 +++++++++++++++++++++---------------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/include/pdf/SkPDFDevice.h b/include/pdf/SkPDFDevice.h index 8804987..6d86226 100644 --- a/include/pdf/SkPDFDevice.h +++ b/include/pdf/SkPDFDevice.h @@ -187,7 +187,7 @@ private: SkClipStack fExistingClipStack; SkRegion fExistingClipRegion; SkPDFArray* fAnnotations; - SkRefPtr fResourceDict; + SkPDFDict* fResourceDict; SkTDArray fGraphicStateResources; SkTDArray fXObjectResources; @@ -221,7 +221,7 @@ private: void init(); void cleanUp(bool clearFontUsage); - void createFormXObjectFromDevice(SkRefPtr* xobject); + SkPDFFormXObject* createFormXObjectFromDevice(); // Clear the passed clip from all existing content entries. void clearClipFromContent(const SkClipStack* clipStack, @@ -240,7 +240,7 @@ private: const SkMatrix& matrix, const SkPaint& paint, bool hasText, - SkRefPtr* dst); + SkPDFFormXObject** dst); void finishContentEntry(SkXfermode::Mode xfermode, SkPDFFormXObject* dst); bool isContentEmpty(); diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 9906d5b..929ca10 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -453,8 +453,9 @@ public: ~ScopedContentEntry() { if (fContentEntry) { - fDevice->finishContentEntry(fXfermode, fDstFormXObject.get()); + fDevice->finishContentEntry(fXfermode, fDstFormXObject); } + SkSafeUnref(fDstFormXObject); } ContentEntry* entry() { return fContentEntry; } @@ -462,10 +463,11 @@ private: SkPDFDevice* fDevice; ContentEntry* fContentEntry; SkXfermode::Mode fXfermode; - SkRefPtr fDstFormXObject; + SkPDFFormXObject* fDstFormXObject; void init(const SkClipStack* clipStack, const SkRegion& clipRegion, const SkMatrix& matrix, const SkPaint& paint, bool hasText) { + fDstFormXObject = NULL; if (paint.getXfermode()) { paint.getXfermode()->asMode(&fXfermode); } @@ -564,6 +566,7 @@ void SkPDFDevice::cleanUp(bool clearFontUsage) { fFontResources.unrefAll(); fShaderResources.unrefAll(); SkSafeUnref(fAnnotations); + SkSafeUnref(fResourceDict); if (clearFontUsage) { fFontGlyphUsage->reset(); @@ -998,9 +1001,8 @@ void SkPDFDevice::setDrawingArea(DrawingArea drawingArea) { } SkPDFDict* SkPDFDevice::getResourceDict() { - if (fResourceDict.get() == NULL) { - fResourceDict = new SkPDFDict; - fResourceDict->unref(); // SkRefPtr and new both took a reference. + if (NULL == fResourceDict) { + fResourceDict = SkNEW(SkPDFDict); if (fGraphicStateResources.count()) { SkRefPtr extGState = new SkPDFDict(); @@ -1062,7 +1064,7 @@ SkPDFDict* SkPDFDevice::getResourceDict() { procSets->appendName(procs[i]); fResourceDict->insert("ProcSet", procSets.get()); } - return fResourceDict.get(); + return fResourceDict; } void SkPDFDevice::getResources(SkTDArray* resourceList, @@ -1224,15 +1226,14 @@ bool SkPDFDevice::handleAnnotations(const SkRect& r, const SkMatrix& matrix, return p.isNoDrawAnnotation(); } -void SkPDFDevice::createFormXObjectFromDevice( - SkRefPtr* xobject) { - *xobject = new SkPDFFormXObject(this); - (*xobject)->unref(); // SkRefPtr and new both took a reference. +SkPDFFormXObject* SkPDFDevice::createFormXObjectFromDevice() { + SkPDFFormXObject* xobject = SkNEW_ARGS(SkPDFFormXObject, (this)); // We always draw the form xobjects that we create back into the device, so // we simply preserve the font usage instead of pulling it out and merging // it back in later. cleanUp(false); // Reset this device to have no content. init(); + return xobject; } void SkPDFDevice::clearClipFromContent(const SkClipStack* clipStack, @@ -1240,11 +1241,10 @@ void SkPDFDevice::clearClipFromContent(const SkClipStack* clipStack, if (clipRegion.isEmpty() || isContentEmpty()) { return; } - SkRefPtr curContent; - createFormXObjectFromDevice(&curContent); + SkAutoTUnref curContent(createFormXObjectFromDevice()); // Redraw what we already had, but with the clip as a mask. - drawFormXObjectWithClip(curContent.get(), clipStack, clipRegion, true); + drawFormXObjectWithClip(curContent, clipStack, clipRegion, true); } void SkPDFDevice::drawFormXObjectWithClip(SkPDFFormXObject* xobject, @@ -1264,11 +1264,9 @@ void SkPDFDevice::drawFormXObjectWithClip(SkPDFFormXObject* xobject, draw.fClipStack = clipStack; SkPaint stockPaint; this->drawPaint(draw, stockPaint); - SkRefPtr maskFormXObject; - createFormXObjectFromDevice(&maskFormXObject); + SkAutoTUnref maskFormXObject(createFormXObjectFromDevice()); SkRefPtr sMaskGS = - SkPDFGraphicState::GetSMaskGraphicState(maskFormXObject.get(), - invertClip); + SkPDFGraphicState::GetSMaskGraphicState(maskFormXObject, invertClip); sMaskGS->unref(); // SkRefPtr and getSMaskGraphicState both took a ref. // Draw the xobject with the clip as a mask. @@ -1295,7 +1293,8 @@ ContentEntry* SkPDFDevice::setUpContentEntry(const SkClipStack* clipStack, const SkMatrix& matrix, const SkPaint& paint, bool hasText, - SkRefPtr* dst) { + SkPDFFormXObject** dst) { + *dst = NULL; if (clipRegion.isEmpty()) { return NULL; } @@ -1336,7 +1335,7 @@ ContentEntry* SkPDFDevice::setUpContentEntry(const SkClipStack* clipStack, if (isContentEmpty()) { return NULL; } else { - createFormXObjectFromDevice(dst); + *dst = createFormXObjectFromDevice(); } } // TODO(vandebo): Figure out how/if we can handle the following modes: @@ -1399,9 +1398,9 @@ void SkPDFDevice::finishContentEntry(const SkXfermode::Mode xfermode, SkClipStack clipStack = contentEntries->fState.fClipStack; SkRegion clipRegion = contentEntries->fState.fClipRegion; - SkRefPtr srcFormXObject; + SkAutoTUnref srcFormXObject; if (!isContentEmpty()) { - createFormXObjectFromDevice(&srcFormXObject); + srcFormXObject.reset(createFormXObjectFromDevice()); } drawFormXObjectWithClip(dst, &clipStack, clipRegion, true); @@ -1427,7 +1426,7 @@ void SkPDFDevice::finishContentEntry(const SkXfermode::Mode xfermode, sMaskGS = SkPDFGraphicState::GetSMaskGraphicState( dst, xfermode == SkXfermode::kSrcOut_Mode); fXObjectResources.push(srcFormXObject.get()); - srcFormXObject->ref(); + srcFormXObject.get()->ref(); } else { sMaskGS = SkPDFGraphicState::GetSMaskGraphicState( srcFormXObject.get(), xfermode == SkXfermode::kDstOut_Mode); -- 2.7.4