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
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 @@
SkClipStack fExistingClipStack;
SkRegion fExistingClipRegion;
SkPDFArray* fAnnotations;
- SkRefPtr<SkPDFDict> fResourceDict;
+ SkPDFDict* fResourceDict;
SkTDArray<SkPDFGraphicState*> fGraphicStateResources;
SkTDArray<SkPDFObject*> fXObjectResources;
@@ -221,7 +221,7 @@
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 @@
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 9906d5b..929ca10 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -453,8 +453,9 @@
~ScopedContentEntry() {
if (fContentEntry) {
- fDevice->finishContentEntry(fXfermode, fDstFormXObject.get());
+ fDevice->finishContentEntry(fXfermode, fDstFormXObject);
}
+ SkSafeUnref(fDstFormXObject);
}
ContentEntry* entry() { return fContentEntry; }
@@ -462,10 +463,11 @@
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 @@
fFontResources.unrefAll();
fShaderResources.unrefAll();
SkSafeUnref(fAnnotations);
+ SkSafeUnref(fResourceDict);
if (clearFontUsage) {
fFontGlyphUsage->reset();
@@ -998,9 +1001,8 @@
}
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 @@
procSets->appendName(procs[i]);
fResourceDict->insert("ProcSet", procSets.get());
}
- return fResourceDict.get();
+ return fResourceDict;
}
void SkPDFDevice::getResources(SkTDArray<SkPDFObject*>* resourceList,
@@ -1224,15 +1226,14 @@
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 @@
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 @@
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 @@
const SkMatrix& matrix,
const SkPaint& paint,
bool hasText,
- SkRefPtr<SkPDFFormXObject>* dst) {
+ SkPDFFormXObject** dst) {
+ *dst = NULL;
if (clipRegion.isEmpty()) {
return NULL;
}
@@ -1336,7 +1335,7 @@
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 @@
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 @@
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);