diff options
author | 2012-09-20 17:52:20 +0000 | |
---|---|---|
committer | 2012-09-20 17:52:20 +0000 | |
commit | fc641d09e5a1a9f7fae369ae06a8b96089faf57b (patch) | |
tree | 7250df877f7ddcb529b39c4b0386ec9e998f476b | |
parent | bc5cbfe4ed0f8dcee9c186365ab62bbff59d67b7 (diff) |
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
-rw-r--r-- | include/pdf/SkPDFDevice.h | 6 | ||||
-rw-r--r-- | 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 8804987bc2..6d8622699c 100644 --- a/include/pdf/SkPDFDevice.h +++ b/include/pdf/SkPDFDevice.h @@ -187,7 +187,7 @@ private: SkClipStack fExistingClipStack; SkRegion fExistingClipRegion; SkPDFArray* fAnnotations; - SkRefPtr<SkPDFDict> fResourceDict; + SkPDFDict* fResourceDict; SkTDArray<SkPDFGraphicState*> fGraphicStateResources; SkTDArray<SkPDFObject*> fXObjectResources; @@ -221,7 +221,7 @@ private: void init(); void cleanUp(bool clearFontUsage); - void createFormXObjectFromDevice(SkRefPtr<SkPDFFormXObject>* 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<SkPDFFormXObject>* 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 9906d5b3a2..929ca10508 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<SkPDFFormXObject> 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<SkPDFDict> 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<SkPDFObject*>* resourceList, @@ -1224,15 +1226,14 @@ bool SkPDFDevice::handleAnnotations(const SkRect& r, const SkMatrix& matrix, return p.isNoDrawAnnotation(); } -void SkPDFDevice::createFormXObjectFromDevice( - SkRefPtr<SkPDFFormXObject>* 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<SkPDFFormXObject> curContent; - createFormXObjectFromDevice(&curContent); + SkAutoTUnref<SkPDFFormXObject> 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<SkPDFFormXObject> maskFormXObject; - createFormXObjectFromDevice(&maskFormXObject); + SkAutoTUnref<SkPDFFormXObject> maskFormXObject(createFormXObjectFromDevice()); SkRefPtr<SkPDFGraphicState> 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<SkPDFFormXObject>* 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<SkPDFFormXObject> srcFormXObject; + SkAutoTUnref<SkPDFFormXObject> 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); |