[PDF] Clean up ref counting.
authorvandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 1 Feb 2011 22:19:44 +0000 (22:19 +0000)
committervandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 1 Feb 2011 22:19:44 +0000 (22:19 +0000)
Return ref'd objs where possible enabling removal of many SkRefPtr<> variables.

Review URL: http://codereview.appspot.com/4029051

git-svn-id: http://skia.googlecode.com/svn/trunk@750 2bbb7eff-a529-9590-31e7-b0007b416f81

15 files changed:
include/pdf/SkPDFCatalog.h
include/pdf/SkPDFFormXObject.h
include/pdf/SkPDFImage.h
include/pdf/SkPDFStream.h
include/pdf/SkPDFTypes.h
src/pdf/SkPDFCatalog.cpp
src/pdf/SkPDFDevice.cpp
src/pdf/SkPDFDocument.cpp
src/pdf/SkPDFFont.cpp
src/pdf/SkPDFFormXObject.cpp
src/pdf/SkPDFGraphicState.cpp
src/pdf/SkPDFImage.cpp
src/pdf/SkPDFPage.cpp
src/pdf/SkPDFStream.cpp
src/pdf/SkPDFTypes.cpp

index 60f9791..f004a1d 100644 (file)
@@ -35,11 +35,12 @@ public:
     SkPDFCatalog();
     ~SkPDFCatalog();
 
-    /** Add the passed object to the catalog.
+    /** Add the passed object to the catalog.  Refs obj.
      *  @param obj         The object to add.
      *  @param onFirstPage Is the object on the first page.
+     *  @return The obj argument is returned.
      */
-    void addObject(SkPDFObject* obj, bool onFirstPage);
+    SkPDFObject* addObject(SkPDFObject* obj, bool onFirstPage);
 
     /** Inform the catalog of the object's position in the final stream.
      *  The object should already have been added to the catalog.  Returns
index 288a449..6a16709 100644 (file)
@@ -52,17 +52,19 @@ public:
     virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
     virtual void getResources(SkTDArray<SkPDFObject*>* resourceList);
 
-    /** Add the value to the stream dictionary with the given key.
+    /** Add the value to the stream dictionary with the given key.  Refs value.
      *  @param key   The key for this dictionary entry.
      *  @param value The value for this dictionary entry.
+     *  @return The value argument is returned.
      */
-    void insert(SkPDFName* key, SkPDFObject* value);
+    SkPDFObject* insert(SkPDFName* key, SkPDFObject* value);
 
-    /** Add the value to the stream dictionary with the given key.
+    /** Add the value to the stream dictionary with the given key.  Refs value.
      *  @param key   The text of the key for this dictionary entry.
      *  @param value The value for this dictionary entry.
+     *  @return The value argument is returned.
      */
-    void insert(const char key[], SkPDFObject* value);
+    SkPDFObject* insert(const char key[], SkPDFObject* value);
 
 private:
     SkString fContent;
index 9b4e4f9..7966e99 100644 (file)
@@ -49,10 +49,11 @@ public:
 
     virtual ~SkPDFImage();
 
-    /** Add a Soft Mask (alpha or shape channel) to the image.
+    /** Add a Soft Mask (alpha or shape channel) to the image.  Refs mask.
      *  @param mask A gray scale image representing the mask.
+     *  @return The mask argument is returned.
      */
-    void addSMask(SkPDFImage* mask);
+    SkPDFImage* addSMask(SkPDFImage* mask);
 
     // The SkPDFObject interface.
     virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
@@ -76,17 +77,19 @@ private:
     SkPDFImage(SkStream* imageData, const SkBitmap& bitmap,
                const SkIRect& srcRect, bool alpha, const SkPaint& paint);
 
-    /** Add the value to the stream dictionary with the given key.
+    /** Add the value to the stream dictionary with the given key.  Refs value.
      *  @param key   The key for this dictionary entry.
      *  @param value The value for this dictionary entry.
+     *  @return The value argument is returned.
      */
-    void insert(SkPDFName* key, SkPDFObject* value);
+    SkPDFObject* insert(SkPDFName* key, SkPDFObject* value);
 
-    /** Add the value to the stream dictionary with the given key.
+    /** Add the value to the stream dictionary with the given key.  Refs value.
      *  @param key   The text of the key for this dictionary entry.
      *  @param value The value for this dictionary entry.
+     *  @return The value argument is returned.
      */
-    void insert(const char key[], SkPDFObject* value);
+    SkPDFObject* insert(const char key[], SkPDFObject* value);
 };
 
 #endif
index 10a40b6..5310b4e 100644 (file)
@@ -43,17 +43,19 @@ public:
                             bool indirect);
     virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
 
-    /** Add the value to the stream dictionary with the given key.
+    /** Add the value to the stream dictionary with the given key.  Refs value.
      *  @param key   The key for this dictionary entry.
      *  @param value The value for this dictionary entry.
+     *  @return The value argument is returned.
      */
-    void insert(SkPDFName* key, SkPDFObject* value);
+    SkPDFObject* insert(SkPDFName* key, SkPDFObject* value);
 
-    /** Add the value to the stream dictionary with the given key.
+    /** Add the value to the stream dictionary with the given key.  Refs value.
      *  @param key   The text of the key for this dictionary entry.
      *  @param value The value for this dictionary entry.
+     *  @return The value argument is returned.
      */
-    void insert(const char key[], SkPDFObject* value);
+    SkPDFObject* insert(const char key[], SkPDFObject* value);
 
 private:
     SkPDFDict fDict;
index fc9b62c..7d59634 100644 (file)
@@ -253,16 +253,18 @@ public:
      */
     SkPDFObject* getAt(int index) { return fValue[index]; }
 
-    /** Set the object at the given offset in the array.
+    /** Set the object at the given offset in the array. Ref's value.
      *  @param index The index into the array to set.
      *  @param value The value to add to the array.
+     *  @return The value argument is returned.
      */
-    void setAt(int index, SkPDFObject* value);
+    SkPDFObject* setAt(int index, SkPDFObject* value);
 
-    /** Append the object to the end of the array.
+    /** Append the object to the end of the array and increments its ref count.
      *  @param value The value to add to the array.
+     *  @return The value argument is returned.
      */
-    void append(SkPDFObject* value);
+    SkPDFObject* append(SkPDFObject* value);
 
 private:
     static const int kMaxLen = 8191;
@@ -295,18 +297,20 @@ public:
      */
     int size() { return fValue.count(); }
 
-    /** Add the value to the dictionary with the given key.
+    /** Add the value to the dictionary with the given key.  Refs value.
      *  @param key   The key for this dictionary entry.
      *  @param value The value for this dictionary entry.
+     *  @return The value argument is returned.
      */
-    void insert(SkPDFName* key, SkPDFObject* value);
+    SkPDFObject* insert(SkPDFName* key, SkPDFObject* value);
 
-    /** Add the value to the dictionary with the given key.  The method will
-     *  create the SkPDFName object.
+    /** Add the value to the dictionary with the given key.  Refs value.  The
+     *  method will create the SkPDFName object.
      *  @param key   The text of the key for this dictionary entry.
      *  @param value The value for this dictionary entry.
+     *  @return The value argument is returned.
      */
-    void insert(const char key[], SkPDFObject* value);
+    SkPDFObject* insert(const char key[], SkPDFObject* value);
 
     /** Remove all entries from the dictionary.
      */
index 7979b70..493cbbe 100644 (file)
@@ -27,7 +27,7 @@ SkPDFCatalog::SkPDFCatalog()
 
 SkPDFCatalog::~SkPDFCatalog() {}
 
-void SkPDFCatalog::addObject(SkPDFObject* obj, bool onFirstPage) {
+SkPDFObject* SkPDFCatalog::addObject(SkPDFObject* obj, bool onFirstPage) {
     SkASSERT(findObjectIndex(obj) == -1);
     SkASSERT(fNextFirstPageObjNum == 0);
     if (onFirstPage)
@@ -35,6 +35,7 @@ void SkPDFCatalog::addObject(SkPDFObject* obj, bool onFirstPage) {
 
     struct Rec newEntry(obj, onFirstPage);
     fCatalog.append(1, &newEntry);
+    return obj;
 }
 
 size_t SkPDFCatalog::setFileOffset(SkPDFObject* obj, size_t offset) {
index 3ca7409..c022482 100644 (file)
@@ -465,12 +465,9 @@ const SkRefPtr<SkPDFDict>& SkPDFDevice::getResourceDict() {
             for (int i = 0; i < fGraphicStateResources.count(); i++) {
                 SkString nameString("G");
                 nameString.appendS32(i);
-                SkRefPtr<SkPDFName> name = new SkPDFName(nameString);
-                name->unref();  // SkRefPtr and new both took a reference.
-                SkRefPtr<SkPDFObjRef> gsRef =
-                    new SkPDFObjRef(fGraphicStateResources[i]);
-                gsRef->unref();  // SkRefPtr and new both took a reference.
-                extGState->insert(name.get(), gsRef.get());
+                extGState->insert(
+                        nameString.c_str(),
+                        new SkPDFObjRef(fGraphicStateResources[i]))->unref();
             }
             fResourceDict->insert("ExtGState", extGState.get());
         }
@@ -481,12 +478,9 @@ const SkRefPtr<SkPDFDict>& SkPDFDevice::getResourceDict() {
             for (int i = 0; i < fXObjectResources.count(); i++) {
                 SkString nameString("X");
                 nameString.appendS32(i);
-                SkRefPtr<SkPDFName> name = new SkPDFName(nameString);
-                name->unref();  // SkRefPtr and new both took a reference.
-                SkRefPtr<SkPDFObjRef> xObjRef =
-                    new SkPDFObjRef(fXObjectResources[i]);
-                xObjRef->unref();  // SkRefPtr and new both took a reference.
-                xObjects->insert(name.get(), xObjRef.get());
+                xObjects->insert(
+                        nameString.c_str(),
+                        new SkPDFObjRef(fXObjectResources[i]))->unref();
             }
             fResourceDict->insert("XObject", xObjects.get());
         }
@@ -497,12 +491,8 @@ const SkRefPtr<SkPDFDict>& SkPDFDevice::getResourceDict() {
             for (int i = 0; i < fFontResources.count(); i++) {
                 SkString nameString("F");
                 nameString.appendS32(i);
-                SkRefPtr<SkPDFName> name = new SkPDFName(nameString);
-                name->unref();  // SkRefPtr and new both took a reference.
-                SkRefPtr<SkPDFObjRef> fontRef =
-                    new SkPDFObjRef(fFontResources[i]);
-                fontRef->unref();  // SkRefPtr and new both took a reference.
-                fonts->insert(name.get(), fontRef.get());
+                fonts->insert(nameString.c_str(),
+                              new SkPDFObjRef(fFontResources[i]))->unref();
             }
             fResourceDict->insert("Font", fonts.get());
         }
@@ -513,11 +503,8 @@ const SkRefPtr<SkPDFDict>& SkPDFDevice::getResourceDict() {
         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++) {
-            SkRefPtr<SkPDFName> entry = new SkPDFName(procs[i]);
-            entry->unref();  // SkRefPtr and new both took a reference.
-            procSets->append(entry.get());
-        }
+        for (size_t i = 0; i < SK_ARRAY_COUNT(procs); i++)
+            procSets->append(new SkPDFName(procs[i]))->unref();
         fResourceDict->insert("ProcSet", procSets.get());
     }
     return fResourceDict;
@@ -548,17 +535,14 @@ void SkPDFDevice::getResources(SkTDArray<SkPDFObject*>* resourceList) const {
 SkRefPtr<SkPDFArray> SkPDFDevice::getMediaBox() const {
     SkRefPtr<SkPDFInt> zero = new SkPDFInt(0);
     zero->unref();  // SkRefPtr and new both took a reference.
-    SkRefPtr<SkPDFInt> width = new SkPDFInt(fWidth);
-    width->unref();  // SkRefPtr and new both took a reference.
-    SkRefPtr<SkPDFInt> height = new SkPDFInt(fHeight);
-    height->unref();  // SkRefPtr and new both took a reference.
+
     SkRefPtr<SkPDFArray> mediaBox = new SkPDFArray();
     mediaBox->unref();  // SkRefPtr and new both took a reference.
     mediaBox->reserve(4);
     mediaBox->append(zero.get());
     mediaBox->append(zero.get());
-    mediaBox->append(width.get());
-    mediaBox->append(height.get());
+    mediaBox->append(new SkPDFInt(fWidth))->unref();
+    mediaBox->append(new SkPDFInt(fHeight))->unref();
     return mediaBox;
 }
 
index 77a9fdb..79ce9f3 100644 (file)
@@ -62,20 +62,14 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
         SkPDFDict* pageTreeRoot;
         SkPDFPage::generatePageTree(fPages, &fCatalog, &fPageTree,
                                     &pageTreeRoot);
-        SkRefPtr<SkPDFObjRef> pageTreeRootRef = new SkPDFObjRef(pageTreeRoot);
-        pageTreeRootRef->unref();  // SkRefPtr and new both took a reference.
-        fDocCatalog->insert("Pages", pageTreeRootRef.get());
+        fDocCatalog->insert("Pages", new SkPDFObjRef(pageTreeRoot))->unref();
 
         /* TODO(vandebo) output intent
         SkRefPtr<SkPDFDict> outputIntent = new SkPDFDict("OutputIntent");
         outputIntent->unref();  // SkRefPtr and new both took a reference.
-        SkRefPtr<SkPDFName> intentSubtype = new SkPDFName("GTS_PDFA1");
-        intentSubtype->unref();  // SkRefPtr and new both took a reference.
-        outputIntent->insert("S", intentSubtype.get());
-        SkRefPtr<SkPDFString> intentIdentifier = new SkPDFString("sRGB");
-        intentIdentifier->unref();  // SkRefPtr and new both took a reference.
+        outputIntent->insert("S", new SkPDFName("GTS_PDFA1"))->unref();
         outputIntent->insert("OutputConditionIdentifier",
-                             intentIdentifier.get());
+                             new SkPDFString("sRGB"))->unref();
         SkRefPtr<SkPDFArray> intentArray = new SkPDFArray;
         intentArray->unref();  // SkRefPtr and new both took a reference.
         intentArray->append(outputIntent.get());
@@ -179,17 +173,11 @@ void SkPDFDocument::emitFooter(SkWStream* stream, int64_t objCount) {
         fTrailerDict = new SkPDFDict();
         fTrailerDict->unref();  // SkRefPtr and new both took a reference.
 
-        SkPDFInt* objCountInt = new SkPDFInt(objCount);
-        fTrailerDict->insert("Size", objCountInt);
-        objCountInt->unref();  // insert took a ref and we're done with it.
-
         // TODO(vandebo) Linearized format will take a Prev entry too.
-
-        SkPDFObjRef* docCatalogRef = new SkPDFObjRef(fDocCatalog.get());
-        fTrailerDict->insert("Root", docCatalogRef);
-        docCatalogRef->unref();  // insert took a ref and we're done with it.
-
         // TODO(vandebo) PDF/A requires an ID entry.
+        fTrailerDict->insert("Size", new SkPDFInt(objCount))->unref();
+        fTrailerDict->insert("Root",
+                             new SkPDFObjRef(fDocCatalog.get()))->unref();
     }
 
     stream->writeText("trailer\n");
index e39530c..1ef71b9 100644 (file)
@@ -221,23 +221,23 @@ SkStream* handleType1Stream(SkStream* srcStream, size_t* headerLen,
     return NULL;
 }
 
-void appendWidth(const int& width, SkPDFArray* array) {
-    SkRefPtr<SkPDFInt> widthInt = new SkPDFInt(width);
-    widthInt->unref();  // SkRefPtr and new both took a reference.
-    array->append(widthInt.get());
+SkPDFArray* appendWidth(const int& width, SkPDFArray* array) {
+    array->append(new SkPDFInt(width))->unref();
+    return array;
 }
 
-void appendVerticalAdvance(const SkPDFTypefaceInfo::VerticalMetric& advance,
-                           SkPDFArray* array) {
+SkPDFArray* appendVerticalAdvance(
+        const SkPDFTypefaceInfo::VerticalMetric& advance, SkPDFArray* array) {
     appendWidth(advance.fVerticalAdvance, array);
     appendWidth(advance.fOriginXDisp, array);
     appendWidth(advance.fOriginYDisp, array);
+    return array;
 }
 
 template <typename Data>
 SkPDFArray* composeAdvanceData(
         SkPDFTypefaceInfo::AdvanceMetric<Data>* advanceInfo,
-        void (*appendAdvance)(const Data& advance, SkPDFArray* array),
+        SkPDFArray* (*appendAdvance)(const Data& advance, SkPDFArray* array),
         Data* defaultAdvance) {
     SkPDFArray* result = new SkPDFArray();
     for (; advanceInfo != NULL; advanceInfo = advanceInfo->fNext.get()) {
@@ -252,24 +252,14 @@ SkPDFArray* composeAdvanceData(
                 advanceArray->unref();  // SkRefPtr and new both took a ref.
                 for (int j = 0; j < advanceInfo->fAdvance.count(); j++)
                     appendAdvance(advanceInfo->fAdvance[j], advanceArray.get());
-                SkRefPtr<SkPDFInt> rangeStart =
-                    new SkPDFInt(advanceInfo->fStartId);
-                rangeStart->unref();  // SkRefPtr and new both took a reference.
-                result->append(rangeStart.get());
+                result->append(new SkPDFInt(advanceInfo->fStartId))->unref();
                 result->append(advanceArray.get());
                 break;
             }
             case SkPDFTypefaceInfo::WidthRange::kRun: {
                 SkASSERT(advanceInfo->fAdvance.count() == 1);
-                SkRefPtr<SkPDFInt> rangeStart =
-                    new SkPDFInt(advanceInfo->fStartId);
-                rangeStart->unref();  // SkRefPtr and new both took a reference.
-                result->append(rangeStart.get());
-
-                SkRefPtr<SkPDFInt> rangeEnd = new SkPDFInt(advanceInfo->fEndId);
-                rangeEnd->unref();  // SkRefPtr and new both took a reference.
-                result->append(rangeEnd.get());
-
+                result->append(new SkPDFInt(advanceInfo->fStartId))->unref();
+                result->append(new SkPDFInt(advanceInfo->fEndId))->unref();
                 appendAdvance(advanceInfo->fAdvance[0], result);
                 break;
             }
@@ -460,66 +450,39 @@ SkPDFFont::SkPDFFont(class SkPDFTypefaceInfo* fontInfo, uint32_t fontID,
 }
 
 void SkPDFFont::populateType0Font() {
-    fMultiByteGlyphs = true;
-
-    SkRefPtr<SkPDFName> subType = new SkPDFName("Type0");
-    subType->unref();  // SkRefPtr and new both took a reference.
-    insert("Subtype", subType.get());
-
-    SkRefPtr<SkPDFName> baseFont = new SkPDFName(fFontInfo.get()->fFontName);
-    baseFont->unref();  // SkRefPtr and new both took a reference.
-    insert("BaseFont", baseFont.get());
-
-    SkRefPtr<SkPDFName> encoding = new SkPDFName("Identity-H");
-    encoding->unref();  // SkRefPtr and new both took a reference.
-    insert("Encoding", encoding.get());
-
     // TODO(vandebo) add a ToUnicode mapping.
+    fMultiByteGlyphs = true;
 
-    SkRefPtr<SkPDFFont> cidFont = new SkPDFFont(fFontInfo.get(),
-                                                fFontID, 1, true, NULL);
-    fResources.push(cidFont.get());  // 2 refs: SkRefPtr, new. Pass one.
+    insert("Subtype", new SkPDFName("Type0"))->unref();
+    insert("BaseFont", new SkPDFName(fFontInfo.get()->fFontName))->unref();
+    insert("Encoding",  new SkPDFName("Identity-H"))->unref();
 
     SkRefPtr<SkPDFArray> descendantFonts = new SkPDFArray();
     descendantFonts->unref();  // SkRefPtr and new took a reference.
-    SkRefPtr<SkPDFObjRef> cidFontRef = new SkPDFObjRef(cidFont.get());
-    cidFontRef->unref();  // SkRefPtr and new both took a reference.
-    descendantFonts->append(cidFontRef.get());
+
+    // Pass ref new created to fResources.
+    fResources.push(new SkPDFFont(fFontInfo.get(), fFontID, 1, true, NULL));
+    descendantFonts->append(new SkPDFObjRef(fResources.top()))->unref();
     insert("DescendantFonts", descendantFonts.get());
 }
 
 void SkPDFFont::populateCIDFont() {
     fMultiByteGlyphs = true;
 
-    SkRefPtr<SkPDFName> subType;
+    insert("BaseFont", new SkPDFName(fFontInfo.get()->fFontName))->unref();
+
     if (fFontInfo.get()->fType == SkPDFTypefaceInfo::kType1CID_Font)
-        subType = new SkPDFName("CIDFontType0");
+        insert("Subtype", new SkPDFName("CIDFontType0"))->unref();
     else if (fFontInfo.get()->fType == SkPDFTypefaceInfo::kTrueType_Font)
-        subType = new SkPDFName("CIDFontType2");
+        insert("Subtype", new SkPDFName("CIDFontType2"))->unref();
     else
         SkASSERT(false);
-    subType->unref();  // SkRefPtr and new both took a reference.
-    insert("Subtype", subType.get());
-
-    SkRefPtr<SkPDFName> baseFont = new SkPDFName(fFontInfo.get()->fFontName);
-    baseFont->unref();  // SkRefPtr and new both took a reference.
-    insert("BaseFont", baseFont.get());
 
     SkRefPtr<SkPDFDict> sysInfo = new SkPDFDict;
     sysInfo->unref();  // SkRefPtr and new both took a reference.
-
-    SkRefPtr<SkPDFString> adobeString = new SkPDFString("Adobe");
-    adobeString->unref();  // SkRefPtr and new both took a reference.
-    sysInfo->insert("Registry", adobeString.get());
-
-    SkRefPtr<SkPDFString> identityString = new SkPDFString("Identity");
-    identityString->unref();  // SkRefPtr and new both took a reference.
-    sysInfo->insert("Ordering", identityString.get());
-
-    SkRefPtr<SkPDFInt> supplement = new SkPDFInt(0);
-    supplement->unref();  // SkRefPtr and new both took a reference.
-    sysInfo->insert("Supplement", supplement.get());
-
+    sysInfo->insert("Registry", new SkPDFString("Adobe"))->unref();
+    sysInfo->insert("Ordering", new SkPDFString("Identity"))->unref();
+    sysInfo->insert("Supplement", new SkPDFInt(0))->unref();
     insert("CIDSystemInfo", sysInfo.get());
 
     addFontDescriptor(0);
@@ -533,11 +496,7 @@ void SkPDFFont::populateCIDFont() {
         if (widths->size())
             insert("W", widths.get());
         if (defaultWidth != 0) {
-            SkRefPtr<SkPDFInt> defaultWidthInt =
-                new SkPDFInt(defaultWidth);
-            // SkRefPtr and compose both took a reference.
-            defaultWidthInt->unref();
-            insert("DW", defaultWidthInt.get());
+            insert("DW", new SkPDFInt(defaultWidth))->unref();
         }
     }
     if (fFontInfo.get()->fVerticalMetrics.get()) {
@@ -554,12 +513,8 @@ void SkPDFFont::populateCIDFont() {
         if (defaultAdvance.fVerticalAdvance ||
                 defaultAdvance.fOriginXDisp ||
                 defaultAdvance.fOriginYDisp) {
-            SkRefPtr<SkPDFArray> defaultAdvanceArray = new SkPDFArray;
-            // SkRefPtr and compose both took a reference.
-            defaultAdvanceArray->unref();
-            appendVerticalAdvance(defaultAdvance,
-                                  defaultAdvanceArray.get());
-            insert("DW2", defaultAdvanceArray.get());
+            insert("DW2", appendVerticalAdvance(defaultAdvance,
+                                                new SkPDFArray))->unref();
         }
     }
 }
@@ -594,13 +549,8 @@ bool SkPDFFont::populateType1Font(uint16_t firstGlyphID, uint16_t lastGlyphID) {
     fFirstGlyphID = firstGlyphID;
     fLastGlyphID = lastGlyphID;
 
-    SkRefPtr<SkPDFName> subType = new SkPDFName("Type1");
-    subType->unref();  // SkRefPtr and new both took a reference.
-    insert("Subtype", subType.get());
-
-    SkRefPtr<SkPDFName> baseFont = new SkPDFName(fFontInfo.get()->fFontName);
-    baseFont->unref();  // SkRefPtr and new both took a reference.
-    insert("BaseFont", baseFont.get());
+    insert("Subtype", new SkPDFName("Type1"))->unref();
+    insert("BaseFont", new SkPDFName(fFontInfo.get()->fFontName))->unref();
 
     SkRefPtr<SkPDFArray> widthArray = new SkPDFArray();
     widthArray->unref();  // SkRefPtr and new both took a ref.
@@ -623,15 +573,9 @@ bool SkPDFFont::populateType1Font(uint16_t firstGlyphID, uint16_t lastGlyphID) {
         appendWidth(defaultWidth, widthArray.get());
     }
     insert("Widths", widthArray.get());
-
-    SkRefPtr<SkPDFInt> firstCharInt = new SkPDFInt(firstChar);
-    firstCharInt->unref();  // SkRefPtr and new both took a reference.
-    insert("FirstChar", firstCharInt.get());
-
-    SkRefPtr<SkPDFInt> lastChar =
-        new SkPDFInt(firstChar + widthArray->size() - 1);
-    lastChar->unref();  // SkRefPtr and new both took a reference.
-    insert("LastChar", lastChar.get());
+    insert("FirstChar", new SkPDFInt(firstChar))->unref();
+    insert("LastChar",
+           new SkPDFInt(firstChar + widthArray->size() - 1))->unref();
 
     SkRefPtr<SkPDFDict> encoding = new SkPDFDict("Encoding");
     encoding->unref();  // SkRefPtr and new both took a reference.
@@ -642,14 +586,10 @@ bool SkPDFFont::populateType1Font(uint16_t firstGlyphID, uint16_t lastGlyphID) {
     encoding->insert("Differences", encDiffs.get());
 
     encDiffs->reserve(fLastGlyphID - fFirstGlyphID + 2);
-    SkRefPtr<SkPDFInt> startID = new SkPDFInt(1);
-    startID->unref();  // SkRefPtr and new both took a reference.
-    encDiffs->append(startID.get());
+    encDiffs->append(new SkPDFInt(1))->unref();
     for (int gID = fFirstGlyphID; gID <= fLastGlyphID; gID++) {
-        SkRefPtr<SkPDFName> glyphName =
-            new SkPDFName(fFontInfo.get()->fGlyphNames->get()[gID]);
-        glyphName->unref();  // SkRefPtr and new both took a reference.
-        encDiffs->append(glyphName.get());
+        encDiffs->append(
+            new SkPDFName(fFontInfo.get()->fGlyphNames->get()[gID]))->unref();
     }
 
     if (fFontInfo.get()->fLastGlyphID <= 255)
@@ -666,9 +606,7 @@ bool SkPDFFont::addFontDescriptor(int defaultWidth) {
     if (fDescriptor.get() != NULL) {
         fResources.push(fDescriptor.get());
         fDescriptor->ref();
-        SkRefPtr<SkPDFObjRef> descRef = new SkPDFObjRef(fDescriptor.get());
-        descRef->unref();  // SkRefPtr and new both took a reference.
-        insert("FontDescriptor", descRef.get());
+        insert("FontDescriptor", new SkPDFObjRef(fDescriptor.get()))->unref();
         return true;
     }
 
@@ -688,20 +626,11 @@ bool SkPDFFont::addFontDescriptor(int defaultWidth) {
             SkRefPtr<SkPDFStream> fontStream = new SkPDFStream(fontData);
             // SkRefPtr and new both ref()'d fontStream, pass one.
             fResources.push(fontStream.get());
-
-            SkRefPtr<SkPDFInt> headerLen = new SkPDFInt(header);
-            headerLen->unref();  // SkRefPtr and new both took a reference.
-            fontStream->insert("Length1", headerLen.get());
-            SkRefPtr<SkPDFInt> dataLen = new SkPDFInt(data);
-            dataLen->unref();  // SkRefPtr and new both took a reference.
-            fontStream->insert("Length2", dataLen.get());
-            SkRefPtr<SkPDFInt> trailerLen = new SkPDFInt(trailer);
-            trailerLen->unref();  // SkRefPtr and new both took a reference.
-            fontStream->insert("Length3", trailerLen.get());
-
-            SkRefPtr<SkPDFObjRef> streamRef = new SkPDFObjRef(fontStream.get());
-            streamRef->unref();  // SkRefPtr and new both took a reference.
-            fDescriptor->insert("FontFile", streamRef.get());
+            fontStream->insert("Length1", new SkPDFInt(header))->unref();
+            fontStream->insert("Length2", new SkPDFInt(data))->unref();
+            fontStream->insert("Length3", new SkPDFInt(trailer))->unref();
+            fDescriptor->insert("FontFile",
+                                new SkPDFObjRef(fontStream.get()))->unref();
             break;
         }
         case SkPDFTypefaceInfo::kTrueType_Font: {
@@ -711,13 +640,10 @@ bool SkPDFFont::addFontDescriptor(int defaultWidth) {
             // SkRefPtr and new both ref()'d fontStream, pass one.
             fResources.push(fontStream.get());
 
-            SkRefPtr<SkPDFInt> length = new SkPDFInt(fontData->getLength());
-            length->unref();  // SkRefPtr and new both took a reference.
-            fontStream->insert("Length1", length.get());
-
-            SkRefPtr<SkPDFObjRef> streamRef = new SkPDFObjRef(fontStream.get());
-            streamRef->unref();  // SkRefPtr and new both took a reference.
-            fDescriptor->insert("FontFile2", streamRef.get());
+            fontStream->insert("Length1",
+                               new SkPDFInt(fontData->getLength()))->unref();
+            fDescriptor->insert("FontFile2",
+                                new SkPDFObjRef(fontStream.get()))->unref();
             break;
         }
         case SkPDFTypefaceInfo::kCFF_Font:
@@ -728,17 +654,14 @@ bool SkPDFFont::addFontDescriptor(int defaultWidth) {
             // SkRefPtr and new both ref()'d fontStream, pass one.
             fResources.push(fontStream.get());
 
-            SkRefPtr<SkPDFName> subtype;
-            if (fFontInfo.get()->fType == SkPDFTypefaceInfo::kCFF_Font)
-                subtype = new SkPDFName("Type1C");
-            else
-                subtype = new SkPDFName("CIDFontType0c");
-            subtype->unref();  // SkRefPtr and new both took a reference.
-            fontStream->insert("Subtype", subtype.get());
-
-            SkRefPtr<SkPDFObjRef> streamRef = new SkPDFObjRef(fontStream.get());
-            streamRef->unref();  // SkRefPtr and new both took a reference.
-            fDescriptor->insert("FontFile3", streamRef.get());
+            if (fFontInfo.get()->fType == SkPDFTypefaceInfo::kCFF_Font) {
+                fontStream->insert("Subtype", new SkPDFName("Type1C"))->unref();
+            } else {
+                fontStream->insert("Subtype",
+                        new SkPDFName("CIDFontType0c"))->unref();
+            }
+            fDescriptor->insert("FontFile3",
+                                new SkPDFObjRef(fontStream.get()))->unref();
             break;
         }
         default:
@@ -747,63 +670,36 @@ bool SkPDFFont::addFontDescriptor(int defaultWidth) {
 
     fResources.push(fDescriptor.get());
     fDescriptor->ref();
-    SkRefPtr<SkPDFObjRef> descRef = new SkPDFObjRef(fDescriptor.get());
-    descRef->unref();  // SkRefPtr and new both took a reference.
-    insert("FontDescriptor", descRef.get());
-
-    SkRefPtr<SkPDFName> fontName =
-        new SkPDFName(fFontInfo.get()->fFontName);
-    fontName->unref();  // SkRefPtr and new both took a reference.
-    fDescriptor->insert("FontName", fontName.get());
-
-    SkRefPtr<SkPDFInt> flags = new SkPDFInt(fFontInfo.get()->fStyle);
-    flags->unref();  // SkRefPtr and new both took a reference.
-    fDescriptor->insert("Flags", flags.get());
+    insert("FontDescriptor", new SkPDFObjRef(fDescriptor.get()))->unref();
+
+    fDescriptor->insert("FontName",
+                        new SkPDFName(fFontInfo.get()->fFontName))->unref();
+    fDescriptor->insert("Flags",
+                        new SkPDFInt(fFontInfo.get()->fStyle))->unref();
+    fDescriptor->insert("Ascent",
+                        new SkPDFScalar(fFontInfo.get()->fAscent))->unref();
+    fDescriptor->insert("Descent",
+                        new SkPDFScalar(fFontInfo.get()->fDescent))->unref();
+    fDescriptor->insert("CapHeight",
+                        new SkPDFScalar(fFontInfo.get()->fCapHeight))->unref();
+    fDescriptor->insert("StemV",
+                        new SkPDFScalar(fFontInfo.get()->fStemV))->unref();
+    fDescriptor->insert("ItalicAngle",
+                        new SkPDFInt(fFontInfo.get()->fItalicAngle))->unref();
 
     SkIRect glyphBBox = fFontInfo.get()->fBBox;
     SkRefPtr<SkPDFArray> bbox = new SkPDFArray;
     bbox->unref();  // SkRefPtr and new both took a reference.
     bbox->reserve(4);
-    SkRefPtr<SkPDFInt> bboxXMin = new SkPDFInt(glyphBBox.fLeft);
-    bboxXMin->unref();  // SkRefPtr and new both took a reference.
-    bbox->append(bboxXMin.get());
-    SkRefPtr<SkPDFInt> bboxYMin = new SkPDFInt(glyphBBox.fBottom);
-    bboxYMin->unref();  // SkRefPtr and new both took a reference.
-    bbox->append(bboxYMin.get());
-    SkRefPtr<SkPDFInt> bboxXMax = new SkPDFInt(glyphBBox.fRight);
-    bboxXMax->unref();  // SkRefPtr and new both took a reference.
-    bbox->append(bboxXMax.get());
-    SkRefPtr<SkPDFInt> bboxYMax = new SkPDFInt(glyphBBox.fTop);
-    bboxYMax->unref();  // SkRefPtr and new both took a reference.
-    bbox->append(bboxYMax.get());
+    bbox->append(new SkPDFInt(glyphBBox.fLeft))->unref();
+    bbox->append(new SkPDFInt(glyphBBox.fBottom))->unref();
+    bbox->append(new SkPDFInt(glyphBBox.fRight))->unref();
+    bbox->append(new SkPDFInt(glyphBBox.fTop))->unref();
     fDescriptor->insert("FontBBox", bbox.get());
 
-    SkRefPtr<SkPDFInt> italicAngle =
-        new SkPDFInt(fFontInfo.get()->fItalicAngle);
-    italicAngle->unref();  // SkRefPtr and new both took a reference.
-    fDescriptor->insert("ItalicAngle", italicAngle.get());
-
-    SkRefPtr<SkPDFScalar> ascent = new SkPDFScalar(fFontInfo.get()->fAscent);
-    ascent->unref();  // SkRefPtr and new both took a reference.
-    fDescriptor->insert("Ascent", ascent.get());
-
-    SkRefPtr<SkPDFScalar> descent = new SkPDFScalar(fFontInfo.get()->fDescent);
-    descent->unref();  // SkRefPtr and new both took a reference.
-    fDescriptor->insert("Descent", descent.get());
-
-    SkRefPtr<SkPDFScalar> capHeight =
-        new SkPDFScalar(fFontInfo.get()->fCapHeight);
-    capHeight->unref();  // SkRefPtr and new both took a reference.
-    fDescriptor->insert("CapHeight", capHeight.get());
-
-    SkRefPtr<SkPDFScalar> stemV = new SkPDFScalar(fFontInfo.get()->fStemV);
-    stemV->unref();  // SkRefPtr and new both took a reference.
-    fDescriptor->insert("StemV", stemV.get());
-
     if (defaultWidth > 0) {
-        SkRefPtr<SkPDFInt> defaultWidthInt = new SkPDFInt(defaultWidth);
-        defaultWidthInt->unref();  // SkRefPtr and new both took a reference.
-        fDescriptor->insert("MissingWidth", defaultWidthInt.get());
+        fDescriptor->insert("MissingWidth",
+                            new SkPDFInt(defaultWidth))->unref();
     }
     return true;
 }
index 8587ea6..186c228 100644 (file)
@@ -31,14 +31,8 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device, const SkMatrix& matrix)
     fStream = new SkPDFStream(stream_data);
     fStream->unref();  // SkRefPtr and new both took a reference.
 
-    SkRefPtr<SkPDFName> typeValue = new SkPDFName("XObject");
-    typeValue->unref();  // SkRefPtr and new both took a reference.
-    insert("Type", typeValue.get());
-
-    SkRefPtr<SkPDFName> subTypeValue = new SkPDFName("Form");
-    subTypeValue->unref();  // SkRefPtr and new both took a reference.
-    insert("Subtype", subTypeValue.get());
-
+    insert("Type", new SkPDFName("XObject"))->unref();
+    insert("Subtype", new SkPDFName("Form"))->unref();
     insert("BBox", device->getMediaBox().get());
     insert("Resources", device->getResourceDict().get());
 
@@ -48,11 +42,8 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device, const SkMatrix& matrix)
         transformArray->reserve(6);
         SkScalar transform[6];
         SkAssertResult(matrix.pdfTransform(transform));
-        for (size_t i = 0; i < SK_ARRAY_COUNT(transform); i++) {
-            SkRefPtr<SkPDFScalar> val = new SkPDFScalar(transform[i]);
-            val->unref();  // SkRefPtr and new both took a reference.
-            transformArray->append(val.get());
-        }
+        for (size_t i = 0; i < SK_ARRAY_COUNT(transform); i++)
+            transformArray->append(new SkPDFScalar(transform[i]))->unref();
         insert("Matrix", transformArray.get());
     }
 }
@@ -78,10 +69,10 @@ void SkPDFFormXObject::getResources(SkTDArray<SkPDFObject*>* resourceList) {
     fDevice->getResources(resourceList);
 }
 
-void SkPDFFormXObject::insert(SkPDFName* key, SkPDFObject* value) {
-    fStream->insert(key, value);
+SkPDFObject* SkPDFFormXObject::insert(SkPDFName* key, SkPDFObject* value) {
+    return fStream->insert(key, value);
 }
 
-void SkPDFFormXObject::insert(const char key[], SkPDFObject* value) {
-    fStream->insert(key, value);
+SkPDFObject* SkPDFFormXObject::insert(const char key[], SkPDFObject* value) {
+    return fStream->insert(key, value);
 }
index 8cc8314..ff55941 100644 (file)
@@ -79,9 +79,7 @@ SkPDFGraphicState::SkPDFGraphicState(const SkPaint& paint)
 void SkPDFGraphicState::populateDict() {
     if (!fPopulated) {
         fPopulated = true;
-        SkRefPtr<SkPDFName> typeName = new SkPDFName("ExtGState");
-        typeName->unref();  // SkRefPtr and new both took a reference.
-        insert("Type", typeName.get());
+        insert("Type", new SkPDFName("ExtGState"))->unref();
 
         SkRefPtr<SkPDFScalar> alpha =
             new SkPDFScalar(fPaint.getAlpha() * SkScalarInvert(0xFF));
@@ -89,36 +87,23 @@ void SkPDFGraphicState::populateDict() {
         insert("CA", alpha.get());
         insert("ca", alpha.get());
 
-        SkASSERT(SkPaint::kButt_Cap == 0);
-        SkASSERT(SkPaint::kRound_Cap == 1);
-        SkASSERT(SkPaint::kSquare_Cap == 2);
+        SK_COMPILE_ASSERT(SkPaint::kButt_Cap == 0, paint_cap_mismatch);
+        SK_COMPILE_ASSERT(SkPaint::kRound_Cap == 1, paint_cap_mismatch);
+        SK_COMPILE_ASSERT(SkPaint::kSquare_Cap == 2, paint_cap_mismatch);
+        SK_COMPILE_ASSERT(SkPaint::kCapCount == 3, paint_cap_mismatch);
         SkASSERT(fPaint.getStrokeCap() >= 0 && fPaint.getStrokeCap() <= 2);
-        SkRefPtr<SkPDFInt> strokeCap = new SkPDFInt(fPaint.getStrokeCap());
-        strokeCap->unref();  // SkRefPtr and new both took a reference.
-        insert("LC", strokeCap.get());
+        insert("LC", new SkPDFInt(fPaint.getStrokeCap()))->unref();
 
-        SkASSERT(SkPaint::kMiter_Join == 0);
-        SkASSERT(SkPaint::kRound_Join == 1);
-        SkASSERT(SkPaint::kBevel_Join == 2);
+        SK_COMPILE_ASSERT(SkPaint::kMiter_Join == 0, paint_join_mismatch);
+        SK_COMPILE_ASSERT(SkPaint::kRound_Join == 1, paint_join_mismatch);
+        SK_COMPILE_ASSERT(SkPaint::kBevel_Join == 2, paint_join_mismatch);
+        SK_COMPILE_ASSERT(SkPaint::kJoinCount == 3, paint_join_mismatch);
         SkASSERT(fPaint.getStrokeJoin() >= 0 && fPaint.getStrokeJoin() <= 2);
-        SkRefPtr<SkPDFInt> strokeJoin = new SkPDFInt(fPaint.getStrokeJoin());
-        strokeJoin->unref();  // SkRefPtr and new both took a reference.
-        insert("LJ", strokeJoin.get());
+        insert("LJ", new SkPDFInt(fPaint.getStrokeJoin()))->unref();
 
-        SkRefPtr<SkPDFScalar> strokeWidth =
-            new SkPDFScalar(fPaint.getStrokeWidth());
-        strokeWidth->unref();  // SkRefPtr and new both took a reference.
-        insert("LW", strokeWidth.get());
-
-        SkRefPtr<SkPDFScalar> strokeMiterLimit = new SkPDFScalar(
-            fPaint.getStrokeMiter());
-        strokeMiterLimit->unref();  // SkRefPtr and new both took a reference.
-        insert("ML", strokeMiterLimit.get());
-
-        // Turn on automatic stroke adjustment.
-        SkRefPtr<SkPDFBool> trueVal = new SkPDFBool(true);
-        trueVal->unref();  // SkRefPtr and new both took a reference.
-        insert("SA", trueVal.get());
+        insert("LW", new SkPDFScalar(fPaint.getStrokeWidth()))->unref();
+        insert("ML", new SkPDFScalar(fPaint.getStrokeMiter()))->unref();
+        insert("SA", new SkPDFBool(true))->unref();  // Auto stroke adjustment.
     }
 }
 
index f3f7592..65e78b0 100644 (file)
@@ -220,17 +220,9 @@ void extractImageData(const SkBitmap& bitmap, const SkIRect& srcRect,
 SkPDFArray* makeIndexedColorSpace(SkColorTable* table) {
     SkPDFArray* result = new SkPDFArray();
     result->reserve(4);
-    SkRefPtr<SkPDFName> indexedName = new SkPDFName("Indexed");
-    indexedName->unref();  // SkRefPtr and new both took a reference.
-    result->append(indexedName.get());
-
-    SkRefPtr<SkPDFName> rgbName = new SkPDFName("DeviceRGB");
-    rgbName->unref();  // SkRefPtr and new both took a reference.
-    result->append(rgbName.get());
-
-    SkRefPtr<SkPDFInt> countValue = new SkPDFInt(table->count() - 1);
-    countValue->unref();  // SkRefPtr and new both took a reference.
-    result->append(countValue.get());
+    result->append(new SkPDFName("Indexed"))->unref();
+    result->append(new SkPDFName("DeviceRGB"))->unref();;
+    result->append(new SkPDFInt(table->count() - 1))->unref();
 
     // Potentially, this could be represented in fewer bytes with a stream.
     // Max size as a string is 1.5k.
@@ -243,9 +235,7 @@ SkPDFArray* makeIndexedColorSpace(SkColorTable* table) {
         buf[2] = SkGetPackedB32(color);
         index.append(buf, 3);
     }
-    SkRefPtr<SkPDFString> indexValue = new SkPDFString(index);
-    indexValue->unref();  // SkRefPtr and new both took a reference.
-    result->append(indexValue.get());
+    result->append(new SkPDFString(index))->unref();
     return result;
 }
 
@@ -272,10 +262,8 @@ SkPDFImage* SkPDFImage::CreateImage(const SkBitmap& bitmap,
         new SkPDFImage(imageData, bitmap, srcRect, false, paint);
 
     if (alphaData != NULL) {
-        SkRefPtr<SkPDFImage> alphaImage =
-            new SkPDFImage(alphaData, bitmap, srcRect, true, paint);
-        alphaImage->unref();  // SkRefPtr and new both took a reference.
-        image->addSMask(alphaImage.get());
+        image->addSMask(new SkPDFImage(alphaData, bitmap, srcRect, true,
+                                       paint))->unref();
     }
     return image;
 }
@@ -284,13 +272,11 @@ SkPDFImage::~SkPDFImage() {
     fResources.unrefAll();
 }
 
-void SkPDFImage::addSMask(SkPDFImage* mask) {
+SkPDFImage* SkPDFImage::addSMask(SkPDFImage* mask) {
     fResources.push(mask);
     mask->ref();
-
-    SkRefPtr<SkPDFObjRef> maskRef = new SkPDFObjRef(mask);
-    maskRef->unref();  // SkRefPtr and new both took a reference.
-    insert("SMask", maskRef.get());
+    insert("SMask", new SkPDFObjRef(mask))->unref();
+    return mask;
 }
 
 void SkPDFImage::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
@@ -325,46 +311,35 @@ SkPDFImage::SkPDFImage(SkStream* imageData, const SkBitmap& bitmap,
     fStream = new SkPDFStream(imageData);
     fStream->unref();  // SkRefPtr and new both took a reference.
 
-    SkRefPtr<SkPDFName> typeValue = new SkPDFName("XObject");
-    typeValue->unref();  // SkRefPtr and new both took a reference.
-    insert("Type", typeValue.get());
-
-    SkRefPtr<SkPDFName> subTypeValue = new SkPDFName("Image");
-    subTypeValue->unref();  // SkRefPtr and new both took a reference.
-    insert("Subtype", subTypeValue.get());
-
     SkBitmap::Config config = bitmap.getConfig();
     bool alphaOnly = (config == SkBitmap::kA1_Config ||
                       config == SkBitmap::kA8_Config);
 
-    SkRefPtr<SkPDFInt> widthValue;
-    SkRefPtr<SkPDFInt> heightValue;
+    insert("Type", new SkPDFName("XObject"))->unref();
+    insert("Subtype", new SkPDFName("Image"))->unref();
+
     if (!doingAlpha && alphaOnly) {
         // For alpha only images, we stretch a single pixel of black for
         // the color/shape part.
-        widthValue = new SkPDFInt(1);
-        heightValue = widthValue.get();
+        SkRefPtr<SkPDFInt> one = new SkPDFInt(1);
+        one->unref();  // SkRefPtr and new both took a reference.
+        insert("Width", one.get());
+        insert("Height", one.get());
     } else {
-        widthValue = new SkPDFInt(srcRect.width());
-        heightValue = new SkPDFInt(srcRect.height());
-        heightValue->unref();  // SkRefPtr and new both took a reference.
+        insert("Width", new SkPDFInt(srcRect.width()))->unref();
+        insert("Height", new SkPDFInt(srcRect.height()))->unref();
     }
-    widthValue->unref();  // SkRefPtr and new both took a reference.
-    insert("Width", widthValue.get());
-    insert("Height", heightValue.get());
 
     // if (!image mask) {
-    SkRefPtr<SkPDFObject> colorSpaceValue;
     if (doingAlpha || alphaOnly) {
-        colorSpaceValue = new SkPDFName("DeviceGray");
+        insert("ColorSpace", new SkPDFName("DeviceGray"))->unref();
     } else if (config == SkBitmap::kIndex8_Config ||
         config == SkBitmap::kRLE_Index8_Config) {
-        colorSpaceValue = makeIndexedColorSpace(bitmap.getColorTable());
+        insert("ColorSpace",
+               makeIndexedColorSpace(bitmap.getColorTable()))->unref();
     } else {
-        colorSpaceValue = new SkPDFName("DeviceRGB");
+        insert("ColorSpace", new SkPDFName("DeviceRGB"))->unref();
     }
-    colorSpaceValue->unref();  // SkRefPtr and new both took a reference.
-    insert("ColorSpace", colorSpaceValue.get());
     // }
 
     int bitsPerComp = 8;
@@ -372,9 +347,7 @@ SkPDFImage::SkPDFImage(SkStream* imageData, const SkBitmap& bitmap,
         bitsPerComp = 4;
     else if (doingAlpha && config == SkBitmap::kA1_Config)
         bitsPerComp = 1;
-    SkRefPtr<SkPDFInt> bitsPerCompValue = new SkPDFInt(bitsPerComp);
-    bitsPerCompValue->unref();  // SkRefPtr and new both took a reference.
-    insert("BitsPerComponent", bitsPerCompValue.get());
+    insert("BitsPerComponent", new SkPDFInt(bitsPerComp))->unref();
 
     if (config == SkBitmap::kRGB_565_Config) {
         SkRefPtr<SkPDFInt> zeroVal = new SkPDFInt(0);
@@ -396,10 +369,10 @@ SkPDFImage::SkPDFImage(SkStream* imageData, const SkBitmap& bitmap,
     }
 }
 
-void SkPDFImage::insert(SkPDFName* key, SkPDFObject* value) {
-    fStream->insert(key, value);
+SkPDFObject* SkPDFImage::insert(SkPDFName* key, SkPDFObject* value) {
+    return fStream->insert(key, value);
 }
 
-void SkPDFImage::insert(const char key[], SkPDFObject* value) {
-    fStream->insert(key, value);
+SkPDFObject* SkPDFImage::insert(const char key[], SkPDFObject* value) {
+    return fStream->insert(key, value);
 }
index e96f0a1..98d7682 100644 (file)
@@ -38,10 +38,7 @@ void SkPDFPage::finalizePage(SkPDFCatalog* catalog, bool firstPage,
         contentStream->unref();  // SkRefPtr and new both took a reference.
         fContentStream = new SkPDFStream(contentStream.get());
         fContentStream->unref();  // SkRefPtr and new both took a reference.
-        SkRefPtr<SkPDFObjRef> contentRef =
-            new SkPDFObjRef(fContentStream.get());
-        contentRef->unref();  // SkRefPtr and new both took a reference.
-        insert("Contents", contentRef.get());
+        insert("Contents", new SkPDFObjRef(fContentStream.get()))->unref();
     }
     catalog->addObject(fContentStream.get(), firstPage);
     fDevice->getResources(resourceObjects);
@@ -102,9 +99,7 @@ void SkPDFPage::generatePageTree(const SkTDArray<SkPDFPage*>& pages,
             int count = 0;
             for (; i < curNodes.count() && count < kNodeSize; i++, count++) {
                 curNodes[i]->insert(parentName.get(), newNodeRef.get());
-                SkRefPtr<SkPDFObjRef> nodeRef = new SkPDFObjRef(curNodes[i]);
-                nodeRef->unref();  // SkRefPtr and new both took a reference.
-                kids->append(nodeRef.get());
+                kids->append(new SkPDFObjRef(curNodes[i]))->unref();
 
                 // TODO(vandebo) put the objects in strict access order.
                 // Probably doesn't matter because they are so small.
@@ -117,9 +112,7 @@ void SkPDFPage::generatePageTree(const SkTDArray<SkPDFPage*>& pages,
             }
 
             newNode->insert(kidsName.get(), kids.get());
-            SkRefPtr<SkPDFInt> countVal = new SkPDFInt(count);
-            countVal->unref();  // SkRefPtr and new both took a reference.
-            newNode->insert(countName.get(), countVal.get());
+            newNode->insert(countName.get(), new SkPDFInt(count))->unref();
             nextRoundNodes.push(newNode);  // Transfer reference.
         }
 
index cbba068..9e9859b 100644 (file)
@@ -26,19 +26,13 @@ SkPDFStream::SkPDFStream(SkStream* stream) {
     if (SkFlate::HaveFlate() &&
             fCompressedData.getOffset() < stream->getLength()) {
         fLength = fCompressedData.getOffset();
-
-        SkRefPtr<SkPDFName> flateFilter = new SkPDFName("FlateDecode");
-        flateFilter->unref();  // SkRefPtr and new both took a reference.
-        fDict.insert("Filter", flateFilter.get());
+        fDict.insert("Filter", new SkPDFName("FlateDecode"))->unref();
     } else {
         fCompressedData.reset();
         fPlainData = stream;
         fLength = fPlainData->getLength();
     }
-
-    SkRefPtr<SkPDFInt> lenValue = new SkPDFInt(fLength);
-    lenValue->unref();  // SkRefPtr and new both took a reference.
-    fDict.insert("Length", lenValue.get());
+    fDict.insert("Length", new SkPDFInt(fLength))->unref();
 }
 
 SkPDFStream::~SkPDFStream() {
@@ -66,10 +60,10 @@ size_t SkPDFStream::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
         strlen(" stream\n\nendstream") + fLength;
 }
 
-void SkPDFStream::insert(SkPDFName* key, SkPDFObject* value) {
-    fDict.insert(key, value);
+SkPDFObject* SkPDFStream::insert(SkPDFName* key, SkPDFObject* value) {
+    return fDict.insert(key, value);
 }
 
-void SkPDFStream::insert(const char key[], SkPDFObject* value) {
-    fDict.insert(key, value);
+SkPDFObject* SkPDFStream::insert(const char key[], SkPDFObject* value) {
+    return fDict.insert(key, value);
 }
index 506b86d..cc1735e 100644 (file)
@@ -254,25 +254,25 @@ void SkPDFArray::reserve(int length) {
     fValue.setReserve(length);
 }
 
-void SkPDFArray::setAt(int offset, SkPDFObject* value) {
+SkPDFObject* SkPDFArray::setAt(int offset, SkPDFObject* value) {
     SkASSERT(offset < fValue.count());
     SkSafeUnref(fValue[offset]);
     fValue[offset] = value;
     SkSafeRef(fValue[offset]);
+    return value;
 }
 
-void SkPDFArray::append(SkPDFObject* value) {
+SkPDFObject* SkPDFArray::append(SkPDFObject* value) {
     SkASSERT(fValue.count() < kMaxLen);
     SkSafeRef(value);
     fValue.push(value);
+    return value;
 }
 
 SkPDFDict::SkPDFDict() {}
 
 SkPDFDict::SkPDFDict(const char type[]) {
-    SkRefPtr<SkPDFName> typeName = new SkPDFName(type);
-    typeName->unref();  // SkRefPtr and new both took a reference.
-    insert("Type", typeName.get());
+    insert("Type", new SkPDFName(type))->unref();
 }
 
 SkPDFDict::~SkPDFDict() {
@@ -306,18 +306,19 @@ size_t SkPDFDict::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
     return result;
 }
 
-void SkPDFDict::insert(SkPDFName* key, SkPDFObject* value) {
+SkPDFObject* SkPDFDict::insert(SkPDFName* key, SkPDFObject* value) {
     struct Rec* newEntry = fValue.append();
     newEntry->key = key;
     SkSafeRef(newEntry->key);
     newEntry->value = value;
     SkSafeRef(newEntry->value);
+    return value;
 }
 
-void SkPDFDict::insert(const char key[], SkPDFObject* value) {
+SkPDFObject* SkPDFDict::insert(const char key[], SkPDFObject* value) {
     SkRefPtr<SkPDFName> keyName = new SkPDFName(key);
     keyName->unref();  // SkRefPtr and new both took a reference.
-    insert(keyName.get(), value);
+    return insert(keyName.get(), value);
 }
 
 void SkPDFDict::clear() {