From 2a006c112743e07ce258ca223631fc19233f5ddc Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Wed, 19 Sep 2012 17:05:55 +0000 Subject: [PATCH] begin to skiafy PDF headers : removing use of SkRefPtr Review URL: https://codereview.appspot.com/6526050 git-svn-id: http://skia.googlecode.com/svn/trunk@5596 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/pdf/SkPDFDevice.h | 11 ++++++----- src/pdf/SkPDFDevice.cpp | 21 +++++++++------------ src/pdf/SkPDFFormXObject.cpp | 2 +- src/pdf/SkPDFPage.cpp | 8 ++++---- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/include/pdf/SkPDFDevice.h b/include/pdf/SkPDFDevice.h index c01a383..8804987 100644 --- a/include/pdf/SkPDFDevice.h +++ b/include/pdf/SkPDFDevice.h @@ -139,13 +139,14 @@ public: */ SK_API const SkTDArray& getFontResources() const; - /** Returns the media box for this device. + /** Returns a copy of the media box for this device. The caller is required + * to unref() this when it is finished. */ - SK_API SkRefPtr getMediaBox() const; + SK_API SkPDFArray* copyMediaBox() const; - /** Get the annotations from this page. + /** Get the annotations from this page, or NULL if there are none. */ - SK_API SkRefPtr getAnnotations() const; + SK_API SkPDFArray* getAnnotations() const { return fAnnotations; } /** Returns a SkStream with the page contents. The caller is responsible for a reference to the returned value. @@ -185,7 +186,7 @@ private: SkMatrix fInitialTransform; SkClipStack fExistingClipStack; SkRegion fExistingClipRegion; - SkRefPtr fAnnotations; + SkPDFArray* fAnnotations; SkRefPtr fResourceDict; SkTDArray fGraphicStateResources; diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 7b774b7..9906d5b 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -546,6 +546,7 @@ SkPDFDevice::~SkPDFDevice() { } void SkPDFDevice::init() { + fAnnotations = NULL; fResourceDict = NULL; fContentEntries.reset(); fLastContentEntry = NULL; @@ -562,6 +563,8 @@ void SkPDFDevice::cleanUp(bool clearFontUsage) { fXObjectResources.unrefAll(); fFontResources.unrefAll(); fShaderResources.unrefAll(); + SkSafeUnref(fAnnotations); + if (clearFontUsage) { fFontGlyphUsage->reset(); } @@ -1103,12 +1106,11 @@ const SkTDArray& SkPDFDevice::getFontResources() const { return fFontResources; } -SkRefPtr SkPDFDevice::getMediaBox() const { - SkRefPtr zero = new SkPDFInt(0); - zero->unref(); // SkRefPtr and new both took a reference. +SkPDFArray* SkPDFDevice::copyMediaBox() const { + // should this be a singleton? + SkAutoTUnref zero(SkNEW_ARGS(SkPDFInt, (0))); - SkRefPtr mediaBox = new SkPDFArray(); - mediaBox->unref(); // SkRefPtr and new both took a reference. + SkPDFArray* mediaBox = SkNEW(SkPDFArray); mediaBox->reserve(4); mediaBox->append(zero.get()); mediaBox->append(zero.get()); @@ -1117,10 +1119,6 @@ SkRefPtr SkPDFDevice::getMediaBox() const { return mediaBox; } -SkRefPtr SkPDFDevice::getAnnotations() const { - return SkRefPtr(fAnnotations); -} - SkStream* SkPDFDevice::content() const { SkMemoryStream* result = new SkMemoryStream; result->setData(this->copyContentToData())->unref(); @@ -1196,9 +1194,8 @@ bool SkPDFDevice::handleAnnotations(const SkRect& r, const SkMatrix& matrix, SkRect translatedRect; transform.mapRect(&translatedRect, r); - if (fAnnotations.get() == NULL) { - fAnnotations = new SkPDFArray; - fAnnotations->unref(); // Both new and SkRefPtr took a reference. + if (NULL == fAnnotations) { + fAnnotations = SkNEW(SkPDFArray); } SkAutoTUnref annotation(new SkPDFDict("Annot")); annotation->insertName("Subtype", "Link"); diff --git a/src/pdf/SkPDFFormXObject.cpp b/src/pdf/SkPDFFormXObject.cpp index c32ea44..c1e2192 100644 --- a/src/pdf/SkPDFFormXObject.cpp +++ b/src/pdf/SkPDFFormXObject.cpp @@ -28,7 +28,7 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) { insertName("Type", "XObject"); insertName("Subtype", "Form"); - insert("BBox", device->getMediaBox().get()); + SkSafeUnref(this->insert("BBox", device->copyMediaBox())); insert("Resources", device->getResourceDict()); // We invert the initial transform and apply that to the xobject so that diff --git a/src/pdf/SkPDFPage.cpp b/src/pdf/SkPDFPage.cpp index 5a9254d..717f435 100644 --- a/src/pdf/SkPDFPage.cpp +++ b/src/pdf/SkPDFPage.cpp @@ -23,12 +23,12 @@ void SkPDFPage::finalizePage(SkPDFCatalog* catalog, bool firstPage, SkTDArray* resourceObjects) { if (fContentStream.get() == NULL) { insert("Resources", fDevice->getResourceDict()); - insert("MediaBox", fDevice->getMediaBox().get()); + SkSafeUnref(this->insert("MediaBox", fDevice->copyMediaBox())); if (!SkToBool(catalog->getDocumentFlags() & SkPDFDocument::kNoLinks_Flags)) { - SkRefPtr annots = fDevice->getAnnotations(); - if (annots.get() && annots->size() > 0) { - insert("Annots", annots.get()); + SkPDFArray* annots = fDevice->getAnnotations(); + if (annots && annots->size() > 0) { + insert("Annots", annots); } } -- 2.7.4