Revert r7883
authoredisonn@google.com <edisonn@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 27 Feb 2013 17:46:09 +0000 (17:46 +0000)
committeredisonn@google.com <edisonn@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 27 Feb 2013 17:46:09 +0000 (17:46 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@7884 2bbb7eff-a529-9590-31e7-b0007b416f81

21 files changed:
gyp/pdf.gyp
include/pdf/SkPDFDevice.h
include/pdf/SkPDFDocument.h
src/pdf/SkPDFCatalog.cpp
src/pdf/SkPDFCatalog.h
src/pdf/SkPDFDevice.cpp
src/pdf/SkPDFDocument.cpp
src/pdf/SkPDFFont.cpp
src/pdf/SkPDFFont.h
src/pdf/SkPDFFormXObject.cpp
src/pdf/SkPDFFormXObject.h
src/pdf/SkPDFGraphicState.cpp
src/pdf/SkPDFGraphicState.h
src/pdf/SkPDFImage.cpp
src/pdf/SkPDFImage.h
src/pdf/SkPDFPage.cpp
src/pdf/SkPDFPage.h
src/pdf/SkPDFShader.cpp
src/pdf/SkPDFTypes.cpp
src/pdf/SkPDFTypes.h
tests/PDFPrimitivesTest.cpp

index 081df01afdcceff690b3f5903cee53259466527e..7b3b9ea0d20ab062b6bbda41091d606ea9d34f1e 100644 (file)
@@ -12,7 +12,6 @@
       'include_dirs': [
         '../include/config',
         '../include/core',
-        '../include/images',
         '../include/pdf',
         '../src/core', # needed to get SkGlyphCache.h and SkTextFormatParams.h
         '../src/utils', # needed to get SkBitSet.h
@@ -44,7 +43,6 @@
         '../src/pdf/SkPDFTypes.h',
         '../src/pdf/SkPDFUtils.cpp',
         '../src/pdf/SkPDFUtils.h',
-        '../src/pdf/SkTSet.h',
       ],
       # This section makes all targets that depend on this target
       # #define SK_SUPPORT_PDF and have access to the pdf header files.
index f42ecb81f6909d3bc65b5989bdde5ad09e923aca..a13d6175c70157d9b6ab77ffae2fa9074f380bb3 100644 (file)
@@ -29,7 +29,6 @@ class SkPDFGraphicState;
 class SkPDFObject;
 class SkPDFShader;
 class SkPDFStream;
-template <typename T> class SK_API SkTSet;
 
 // Private classes.
 struct ContentEntry;
@@ -131,19 +130,12 @@ public:
     SK_API SkPDFDict* getResourceDict();
 
     /** Get the list of resources (PDF objects) used on this page.
-     *  This method will add to newResourceObjects any objects that this method
-     *  depends on, but not already in knownResourceObjects. This might operate
-     *  recursively so if this object depends on another object and that object
-     *  depends on two more, all three objects will be added.
-     *
-     *  @param knownResourceObjects  The set of resources to be ignored.
-     *  @param newResourceObjects  The set to append dependant resources to.
+     *  @param resourceList A list to append the resources to.
      *  @param recursive    If recursive is true, get the resources of the
      *                      device's resources recursively. (Useful for adding
      *                      objects to the catalog.)
      */
-    SK_API void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
-                             SkTSet<SkPDFObject*>* newResourceObjects,
+    SK_API void getResources(SkTDArray<SkPDFObject*>* resourceList,
                              bool recursive) const;
 
     /** Get the fonts used on this device.
index 443e8c23a46a7480aa256d227530cbadfac9bd1a..167634e0fe6b942d5388c26e13b1620fa02d9042 100644 (file)
@@ -21,7 +21,6 @@ class SkPDFDict;
 class SkPDFPage;
 class SkPDFObject;
 class SkWStream;
-template <typename T> class SK_API SkTSet;
 
 /** \class SkPDFDocument
 
@@ -77,8 +76,7 @@ private:
     SkTDArray<SkPDFPage*> fPages;
     SkTDArray<SkPDFDict*> fPageTree;
     SkPDFDict* fDocCatalog;
-    SkTSet<SkPDFObject*>* fFirstPageResources;
-    SkTSet<SkPDFObject*>* fOtherPageResources;
+    SkTDArray<SkPDFObject*> fPageResources;
     SkTDArray<SkPDFObject*> fSubstitutes;
     int fSecondPageFirstResourceIndex;
 
index a5a5a0e3d1aba6772d088bd7f3dd6a5d55167f3a..c0f6fb03b9b6ad6b35fc6467d5a67b32973ecc9e 100644 (file)
@@ -168,15 +168,12 @@ void SkPDFCatalog::setSubstitute(SkPDFObject* original,
     fSubstituteMap.append(1, &newMapping);
 
     // Add resource objects of substitute object to catalog.
-    SkTSet<SkPDFObject*>* targetSet = getSubstituteList(onFirstPage);
-    SkTSet<SkPDFObject*> newResourceObjects;
-    newMapping.fSubstitute->getResources(*targetSet, &newResourceObjects);
-    for (int i = 0; i < newResourceObjects.count(); ++i) {
-        addObject(newResourceObjects[i], onFirstPage);
-    }
-    // mergeInto returns the numbr of duplicates.
-    // If there are duplicates, there is a bug and we mess ref counting.
-    SkASSERT(targetSet->mergeInto(newResourceObjects) == 0);
+    SkTDArray<SkPDFObject*>* targetList = getSubstituteList(onFirstPage);
+    int existingSize = targetList->count();
+    newMapping.fSubstitute->getResources(targetList);
+    for (int i = existingSize; i < targetList->count(); ++i) {
+        addObject((*targetList)[i], onFirstPage);
+    }
 }
 
 SkPDFObject* SkPDFCatalog::getSubstituteObject(SkPDFObject* object) {
@@ -190,22 +187,22 @@ SkPDFObject* SkPDFCatalog::getSubstituteObject(SkPDFObject* object) {
 
 off_t SkPDFCatalog::setSubstituteResourcesOffsets(off_t fileOffset,
                                                   bool firstPage) {
-    SkTSet<SkPDFObject*>* targetSet = getSubstituteList(firstPage);
+    SkTDArray<SkPDFObject*>* targetList = getSubstituteList(firstPage);
     off_t offsetSum = fileOffset;
-    for (int i = 0; i < targetSet->count(); ++i) {
-        offsetSum += setFileOffset((*targetSet)[i], offsetSum);
+    for (int i = 0; i < targetList->count(); ++i) {
+        offsetSum += setFileOffset((*targetList)[i], offsetSum);
     }
     return offsetSum - fileOffset;
 }
 
 void SkPDFCatalog::emitSubstituteResources(SkWStream *stream, bool firstPage) {
-    SkTSet<SkPDFObject*>* targetSet = getSubstituteList(firstPage);
-    for (int i = 0; i < targetSet->count(); ++i) {
-        (*targetSet)[i]->emit(stream, this, true);
+    SkTDArray<SkPDFObject*>* targetList = getSubstituteList(firstPage);
+    for (int i = 0; i < targetList->count(); ++i) {
+        (*targetList)[i]->emit(stream, this, true);
     }
 }
 
-SkTSet<SkPDFObject*>* SkPDFCatalog::getSubstituteList(bool firstPage) {
+SkTDArray<SkPDFObject*>* SkPDFCatalog::getSubstituteList(bool firstPage) {
     return firstPage ? &fSubstituteResourcesFirstPage :
                        &fSubstituteResourcesRemaining;
 }
index c7c6d6e2995652f0c0c8260381bbfe4d1feaaf15..d5825ace5ae602ec99b276e726624e1797de82e6 100644 (file)
@@ -115,8 +115,8 @@ private:
 
     // TODO(arthurhsu): Make this a hash if it's a performance problem.
     SkTDArray<SubstituteMapping> fSubstituteMap;
-    SkTSet<SkPDFObject*> fSubstituteResourcesFirstPage;
-    SkTSet<SkPDFObject*> fSubstituteResourcesRemaining;
+    SkTDArray<SkPDFObject*> fSubstituteResourcesFirstPage;
+    SkTDArray<SkPDFObject*> fSubstituteResourcesRemaining;
 
     // Number of objects on the first page.
     uint32_t fFirstPageCount;
@@ -131,7 +131,7 @@ private:
 
     int assignObjNum(SkPDFObject* obj);
 
-    SkTSet<SkPDFObject*>* getSubstituteList(bool firstPage);
+    SkTDArray<SkPDFObject*>* getSubstituteList(bool firstPage);
 };
 
 #endif
index 7fb6db0e611edcb8a8bba42d0c378627c882626a..aabc6b3bcca37e4a6d8d24f5ddf659601f671829 100644 (file)
@@ -32,7 +32,6 @@
 #include "SkTemplates.h"
 #include "SkTypeface.h"
 #include "SkTypes.h"
-#include "SkTSet.h"
 
 // Utility functions
 
@@ -1176,57 +1175,39 @@ SkPDFDict* SkPDFDevice::getResourceDict() {
     return fResourceDict;
 }
 
-void SkPDFDevice::getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
-                               SkTSet<SkPDFObject*>* newResourceObjects,
+void SkPDFDevice::getResources(SkTDArray<SkPDFObject*>* resourceList,
                                bool recursive) const {
-    // TODO: reserve not correct if we need to recursively explore.
-    newResourceObjects->setReserve(newResourceObjects->count() +
-                                   fGraphicStateResources.count() +
-                                   fXObjectResources.count() +
-                                   fFontResources.count() +
-                                   fShaderResources.count());
+    resourceList->setReserve(resourceList->count() +
+                             fGraphicStateResources.count() +
+                             fXObjectResources.count() +
+                             fFontResources.count() +
+                             fShaderResources.count());
     for (int i = 0; i < fGraphicStateResources.count(); i++) {
-        if (!knownResourceObjects.contains(fGraphicStateResources[i]) &&
-                !newResourceObjects->contains(fGraphicStateResources[i])) {
-            newResourceObjects->add(fGraphicStateResources[i]);
-            fGraphicStateResources[i]->ref();
-            if (recursive) {
-                fGraphicStateResources[i]->getResources(knownResourceObjects, 
-                                                        newResourceObjects);
-            }
+        resourceList->push(fGraphicStateResources[i]);
+        fGraphicStateResources[i]->ref();
+        if (recursive) {
+            fGraphicStateResources[i]->getResources(resourceList);
         }
     }
     for (int i = 0; i < fXObjectResources.count(); i++) {
-        if (!knownResourceObjects.contains(fXObjectResources[i]) &&
-                !newResourceObjects->contains(fXObjectResources[i])) {
-            newResourceObjects->add(fXObjectResources[i]);
-            fXObjectResources[i]->ref();
-            if (recursive) {
-                fXObjectResources[i]->getResources(knownResourceObjects, 
-                                                   newResourceObjects);
-            }
+        resourceList->push(fXObjectResources[i]);
+        fXObjectResources[i]->ref();
+        if (recursive) {
+            fXObjectResources[i]->getResources(resourceList);
         }
     }
     for (int i = 0; i < fFontResources.count(); i++) {
-        if (!knownResourceObjects.contains(fFontResources[i]) &&
-                !newResourceObjects->contains(fFontResources[i])) {
-            newResourceObjects->add(fFontResources[i]);
-            fFontResources[i]->ref();
-            if (recursive) {
-                fFontResources[i]->getResources(knownResourceObjects, 
-                                                newResourceObjects);
-            }
+        resourceList->push(fFontResources[i]);
+        fFontResources[i]->ref();
+        if (recursive) {
+            fFontResources[i]->getResources(resourceList);
         }
     }
     for (int i = 0; i < fShaderResources.count(); i++) {
-        if (!knownResourceObjects.contains(fShaderResources[i]) &&
-                !newResourceObjects->contains(fShaderResources[i])) {
-            newResourceObjects->add(fShaderResources[i]);
-            fShaderResources[i]->ref();
-            if (recursive) {
-                fShaderResources[i]->getResources(knownResourceObjects, 
-                                                  newResourceObjects);
-            }
+        resourceList->push(fShaderResources[i]);
+        fShaderResources[i]->ref();
+        if (recursive) {
+            fShaderResources[i]->getResources(resourceList);
         }
     }
 }
index fc0928616d05aada60fc2e8976170b2a30e5d3c7..c7266d8454bc7cd714b8aa5430560da81c8f1a83 100644 (file)
 #include "SkPDFPage.h"
 #include "SkPDFTypes.h"
 #include "SkStream.h"
-#include "SkTSet.h"
 
-static void addResourcesToCatalog(bool firstPage,
-                                  SkTSet<SkPDFObject*>* resourceSet,
-                                  SkPDFCatalog* catalog) {
-    for (int i = 0; i < resourceSet->count(); i++) {
-        catalog->addObject((*resourceSet)[i], firstPage);
+// Add the resources, starting at firstIndex to the catalog, removing any dupes.
+// A hash table would be really nice here.
+static void addResourcesToCatalog(int firstIndex, bool firstPage,
+                          SkTDArray<SkPDFObject*>* resourceList,
+                          SkPDFCatalog* catalog) {
+    for (int i = firstIndex; i < resourceList->count(); i++) {
+        int index = resourceList->find((*resourceList)[i]);
+        if (index != i) {
+            (*resourceList)[i]->unref();
+            resourceList->removeShuffle(i);
+            i--;
+        } else {
+            catalog->addObject((*resourceList)[i], firstPage);
+        }
     }
 }
 
@@ -49,12 +57,11 @@ static void perform_font_subsetting(SkPDFCatalog* catalog,
 
 SkPDFDocument::SkPDFDocument(Flags flags)
         : fXRefFileOffset(0),
+          fSecondPageFirstResourceIndex(0),
           fTrailerDict(NULL) {
     fCatalog.reset(new SkPDFCatalog(flags));
     fDocCatalog = SkNEW_ARGS(SkPDFDict, ("Catalog"));
     fCatalog->addObject(fDocCatalog, true);
-    fFirstPageResources = NULL;
-    fOtherPageResources = NULL;
 }
 
 SkPDFDocument::~SkPDFDocument() {
@@ -66,14 +73,11 @@ SkPDFDocument::~SkPDFDocument() {
         fPageTree[i]->clear();
     }
     fPageTree.safeUnrefAll();
-    fFirstPageResources->safeUnrefAll();
-    fOtherPageResources->safeUnrefAll();
+    fPageResources.safeUnrefAll();
     fSubstitutes.safeUnrefAll();
 
     fDocCatalog->unref();
     SkSafeUnref(fTrailerDict);
-    SkDELETE(fFirstPageResources);
-    SkDELETE(fOtherPageResources);
 }
 
 bool SkPDFDocument::emitPDF(SkWStream* stream) {
@@ -86,9 +90,6 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
         }
     }
 
-    fFirstPageResources = SkNEW(SkTSet<SkPDFObject*>);
-    fOtherPageResources = SkNEW(SkTSet<SkPDFObject*>);
-
     // We haven't emitted the document before if fPageTree is empty.
     if (fPageTree.isEmpty()) {
         SkPDFDict* pageTreeRoot;
@@ -107,35 +108,15 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
         */
 
         bool firstPage = true;
-        /* The references returned in newResources are transfered to
-         * fFirstPageResources or fOtherPageResources depending on firstPage and
-         * knownResources doesn't have a reference but just relies on the other
-         * two sets to maintain a reference.
-         */
-        SkTSet<SkPDFObject*> knownResources;
-
-        // mergeInto returns the number of duplicates.
-        // If there are duplicates, there is a bug and we mess ref counting.
-        int duplicates = 0;
-        knownResources.mergeInto(*fFirstPageResources);
         for (int i = 0; i < fPages.count(); i++) {
-            if (i == 1) {
+            int resourceCount = fPageResources.count();
+            fPages[i]->finalizePage(fCatalog.get(), firstPage, &fPageResources);
+            addResourcesToCatalog(resourceCount, firstPage, &fPageResources,
+                                  fCatalog.get());
+            if (i == 0) {
                 firstPage = false;
-                duplicates = knownResources.mergeInto(*fOtherPageResources);
-            }
-            SkTSet<SkPDFObject*> newResources;
-            fPages[i]->finalizePage(
-                fCatalog.get(), firstPage, knownResources, &newResources);
-            addResourcesToCatalog(firstPage, &newResources, fCatalog.get());
-            if (firstPage) {
-                duplicates = fFirstPageResources->mergeInto(newResources);
-            } else {
-                duplicates = fOtherPageResources->mergeInto(newResources);
+                fSecondPageFirstResourceIndex = fPageResources.count();
             }
-            SkASSERT(duplicates == 0);             
-
-            duplicates = knownResources.mergeInto(newResources);
-            SkASSERT(duplicates == 0); 
         }
 
         // Build font subsetting info before proceeding.
@@ -147,8 +128,8 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
         fileOffset += fCatalog->setFileOffset(fPages[0], fileOffset);
         fileOffset += fPages[0]->getPageSize(fCatalog.get(),
                 (size_t) fileOffset);
-        for (int i = 0; i < fFirstPageResources->count(); i++) {
-            fileOffset += fCatalog->setFileOffset((*fFirstPageResources)[i],
+        for (int i = 0; i < fSecondPageFirstResourceIndex; i++) {
+            fileOffset += fCatalog->setFileOffset(fPageResources[i],
                                                   fileOffset);
         }
         // Add the size of resources of substitute objects used on page 1.
@@ -166,9 +147,11 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
             fileOffset += fPages[i]->getPageSize(fCatalog.get(), fileOffset);
         }
 
-        for (int i = 0; i < fOtherPageResources->count(); i++) {
-            fileOffset += fCatalog->setFileOffset(
-                (*fOtherPageResources)[i], fileOffset);
+        for (int i = fSecondPageFirstResourceIndex;
+                 i < fPageResources.count();
+                 i++) {
+            fileOffset += fCatalog->setFileOffset(fPageResources[i],
+                                                  fileOffset);
         }
 
         fileOffset += fCatalog->setSubstituteResourcesOffsets(fileOffset,
@@ -180,8 +163,8 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
     fDocCatalog->emitObject(stream, fCatalog.get(), true);
     fPages[0]->emitObject(stream, fCatalog.get(), true);
     fPages[0]->emitPage(stream, fCatalog.get());
-    for (int i = 0; i < fFirstPageResources->count(); i++) {
-        (*fFirstPageResources)[i]->emit(stream, fCatalog.get(), true);
+    for (int i = 0; i < fSecondPageFirstResourceIndex; i++) {
+        fPageResources[i]->emit(stream, fCatalog.get(), true);
     }
     fCatalog->emitSubstituteResources(stream, true);
     // TODO(vandebo): Support linearized format
@@ -198,8 +181,10 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
         fPages[i]->emitPage(stream, fCatalog.get());
     }
 
-    for (int i = 0; i < fOtherPageResources->count(); i++) {
-        (*fOtherPageResources)[i]->emit(stream, fCatalog.get(), true);
+    for (int i = fSecondPageFirstResourceIndex;
+            i < fPageResources.count();
+            i++) {
+        fPageResources[i]->emit(stream, fCatalog.get(), true);
     }
 
     fCatalog->emitSubstituteResources(stream, false);
index af58ac76a3f2a6f919606beea7af07c064281997..89b4fc9ac7d25f4a611cfaaf63b5285b47d651b9 100644 (file)
@@ -716,9 +716,8 @@ SkPDFFont::~SkPDFFont() {
     fResources.unrefAll();
 }
 
-void SkPDFFont::getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
-                             SkTSet<SkPDFObject*>* newResourceObjects) {
-    GetResourcesHelper(&fResources, knownResourceObjects, newResourceObjects);
+void SkPDFFont::getResources(SkTDArray<SkPDFObject*>* resourceList) {
+    GetResourcesHelper(&fResources, resourceList);
 }
 
 SkTypeface* SkPDFFont::typeface() {
index d3aae891796f40b7393765cd16c9a6d7774d4651..693b911061ab2d692682e0fe0a1cd8375abdfe9a 100644 (file)
@@ -81,8 +81,7 @@ class SkPDFFont : public SkPDFDict {
 public:
     virtual ~SkPDFFont();
 
-    virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
-                              SkTSet<SkPDFObject*>* newResourceObjects);
+    virtual void getResources(SkTDArray<SkPDFObject*>* resourceList);
 
     /** Returns the typeface represented by this class. Returns NULL for the
      *  default typeface.
index 884e6db2e4a1535c20d6f1dd62e87e637eceb2c1..5e33995b74f897028cee16735bc3f2fc4158eba3 100644 (file)
@@ -20,8 +20,16 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) {
     // We don't want to keep around device because we'd have two copies
     // of content, so reference or copy everything we need (content and
     // resources).
-    SkTSet<SkPDFObject*> emptySet;
-    device->getResources(emptySet, &fResources, false);
+    device->getResources(&fResources, false);
+
+    // Fail fast if in the tree of resources a child references a parent.
+    // If there is an issue, getResources will end up consuming all memory.
+    // TODO: A better approach might be for all SkPDFObject to keep track
+    // of possible cycles.
+#ifdef SK_DEBUG
+    SkTDArray<SkPDFObject*> dummy_resourceList;
+    getResources(&dummy_resourceList);
+#endif
 
     SkAutoTUnref<SkStream> content(device->content());
     setData(content.get());
@@ -56,10 +64,6 @@ SkPDFFormXObject::~SkPDFFormXObject() {
     fResources.unrefAll();
 }
 
-void SkPDFFormXObject::getResources(
-        const SkTSet<SkPDFObject*>& knownResourceObjects,
-        SkTSet<SkPDFObject*>* newResourceObjects) {
-    GetResourcesHelper(&fResources.toArray(),
-                       knownResourceObjects,
-                       newResourceObjects);
+void SkPDFFormXObject::getResources(SkTDArray<SkPDFObject*>* resourceList) {
+    GetResourcesHelper(&fResources, resourceList);
 }
index b1a6f7425d65176105a3d06ebb5285f1a29fc236..0c49152a1bfbe3fb5b42d4de6aef48b1f7437820 100644 (file)
@@ -39,11 +39,10 @@ public:
     virtual ~SkPDFFormXObject();
 
     // The SkPDFObject interface.
-    virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
-                              SkTSet<SkPDFObject*>* newResourceObjects);
+    virtual void getResources(SkTDArray<SkPDFObject*>* resourceList);
 
 private:
-    SkTSet<SkPDFObject*> fResources;
+    SkTDArray<SkPDFObject*> fResources;
 };
 
 #endif
index 61929b34f11cde0e2910fbf7c2ad50a48859f720..558deb7fdf5f100be6cfd701175e64432f867e81 100644 (file)
@@ -59,10 +59,8 @@ SkPDFGraphicState::~SkPDFGraphicState() {
     fResources.unrefAll();
 }
 
-void SkPDFGraphicState::getResources(
-        const SkTSet<SkPDFObject*>& knownResourceObjects,
-        SkTSet<SkPDFObject*>* newResourceObjects) {
-    GetResourcesHelper(&fResources, knownResourceObjects, newResourceObjects);
+void SkPDFGraphicState::getResources(SkTDArray<SkPDFObject*>* resourceList) {
+    GetResourcesHelper(&fResources, resourceList);
 }
 
 void SkPDFGraphicState::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
index 64f34f8744ad65d3e8dd976ed13dc6745fc1785e..af017372769000a01f7a0d84d5222dbdf5b03659 100644 (file)
@@ -30,8 +30,7 @@ class SkPDFGraphicState : public SkPDFDict {
 public:
     virtual ~SkPDFGraphicState();
 
-    virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
-                              SkTSet<SkPDFObject*>* newResourceObjects);
+    virtual void getResources(SkTDArray<SkPDFObject*>* resourceList);
 
     // Override emitObject and getOutputSize so that we can populate
     // the dictionary on demand.
index 9c57fba02964fef2b6b7f4281b5229dfd33128f5..1b93f6e045a167de2926f73cf798c8a4d9975577 100644 (file)
@@ -287,9 +287,8 @@ SkPDFImage* SkPDFImage::addSMask(SkPDFImage* mask) {
     return mask;
 }
 
-void SkPDFImage::getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
-                              SkTSet<SkPDFObject*>* newResourceObjects) {
-    GetResourcesHelper(&fResources, knownResourceObjects, newResourceObjects);
+void SkPDFImage::getResources(SkTDArray<SkPDFObject*>* resourceList) {
+    GetResourcesHelper(&fResources, resourceList);
 }
 
 SkPDFImage::SkPDFImage(SkStream* imageData, const SkBitmap& bitmap,
index 69aa7da72a31555e1ea167c108c4a2d06b9ab17f..48b0157da997544ef09ae5ad547cfe9a19239228 100644 (file)
@@ -49,8 +49,7 @@ public:
     SkPDFImage* addSMask(SkPDFImage* mask);
 
     // The SkPDFObject interface.
-    virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
-                              SkTSet<SkPDFObject*>* newResourceObjects);
+    virtual void getResources(SkTDArray<SkPDFObject*>* resourceList);
 
 private:
     SkTDArray<SkPDFObject*> fResources;
index cad109948f29b27464cff712e1e17c90ff57d8b8..f47f8ffd46a6d7f1cae7129db80ee0e67adda8b1 100644 (file)
@@ -21,8 +21,7 @@ SkPDFPage::SkPDFPage(SkPDFDevice* content)
 SkPDFPage::~SkPDFPage() {}
 
 void SkPDFPage::finalizePage(SkPDFCatalog* catalog, bool firstPage,
-                             const SkTSet<SkPDFObject*>& knownResourceObjects,
-                             SkTSet<SkPDFObject*>* newResourceObjects) {
+                             SkTDArray<SkPDFObject*>* resourceObjects) {
     if (fContentStream.get() == NULL) {
         insert("Resources", fDevice->getResourceDict());
         SkSafeUnref(this->insert("MediaBox", fDevice->copyMediaBox()));
@@ -39,7 +38,7 @@ void SkPDFPage::finalizePage(SkPDFCatalog* catalog, bool firstPage,
         insert("Contents", new SkPDFObjRef(fContentStream.get()))->unref();
     }
     catalog->addObject(fContentStream.get(), firstPage);
-    fDevice->getResources(knownResourceObjects, newResourceObjects, true);
+    fDevice->getResources(resourceObjects, true);
 }
 
 off_t SkPDFPage::getPageSize(SkPDFCatalog* catalog, off_t fileOffset) {
index 17fd437623fca8e2fbf03320535e3b067a34d485..72ba335e66c5bf828cdfd7a66c08d3ba22a32c70 100644 (file)
@@ -40,15 +40,13 @@ public:
      *  that the page is part of.
      *  @param catalog         The catalog to add page content objects to.
      *  @param firstPage       Indicate if this is the first page of a document.
-     *  @param newResourceObjects All the resource objects (recursively) used on
+     *  @param resourceObjects All the resource objects (recursively) used on
      *                         the page are added to this array.  This gives
      *                         the caller a chance to deduplicate resources
      *                         across pages.
-     *  @param knownResourceObjects  The set of resources to be ignored.
      */
     void finalizePage(SkPDFCatalog* catalog, bool firstPage,
-                      const SkTSet<SkPDFObject*>& knownResourceObjects,
-                      SkTSet<SkPDFObject*>* newResourceObjects);
+                      SkTDArray<SkPDFObject*>* resourceObjects);
 
     /** Determine the size of the page content and store to the catalog
      *  the offsets of all nonresource-indirect objects that make up the page
index b3e57cb95130cccbf5b6b0a159c8dde4e1e19e55..7958de38ceee391b166a29871a16b52f0245898b 100644 (file)
@@ -425,11 +425,8 @@ public:
 
     virtual bool isValid() { return fResources.count() > 0; }
 
-    void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
-                      SkTSet<SkPDFObject*>* newResourceObjects) {
-        GetResourcesHelper(&fResources,
-                           knownResourceObjects,
-                           newResourceObjects);
+    void getResources(SkTDArray<SkPDFObject*>* resourceList) {
+        GetResourcesHelper(&fResources, resourceList);
     }
 
 private:
@@ -451,15 +448,12 @@ public:
 
     virtual bool isValid() { return size() > 0; }
 
-    void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
-                      SkTSet<SkPDFObject*>* newResourceObjects) {
-        GetResourcesHelper(&fResources.toArray(),
-                           knownResourceObjects,
-                           newResourceObjects);
+    void getResources(SkTDArray<SkPDFObject*>* resourceList) {
+        GetResourcesHelper(&fResources, resourceList);
     }
 
 private:
-    SkTSet<SkPDFObject*> fResources;
+    SkTDArray<SkPDFObject*> fResources;
     SkAutoTDelete<const SkPDFShader::State> fState;
 };
 
@@ -838,7 +832,7 @@ SkPDFImageShader::SkPDFImageShader(SkPDFShader::State* state) : fState(state) {
     // Put the canvas into the pattern stream (fContent).
     SkAutoTUnref<SkStream> content(pattern.content());
     setData(content.get());
-    pattern.getResources(fResources, &fResources, false);
+    pattern.getResources(&fResources, false);
 
     insertName("Type", "Pattern");
     insertInt("PatternType", 1);
index 6c7120b0d79dc66d0da1d0f14b2bef7a50c6497a..59250c85346c86d3feb5f19d143b5318552dfd72 100644 (file)
@@ -41,8 +41,7 @@ size_t SkPDFObject::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
     return buffer.getOffset();
 }
 
-void SkPDFObject::getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
-                               SkTSet<SkPDFObject*>* newResourceObjects) {}
+void SkPDFObject::getResources(SkTDArray<SkPDFObject*>* resourceList) {}
 
 void SkPDFObject::emitIndirectObject(SkWStream* stream, SkPDFCatalog* catalog) {
     catalog->emitObjectNumber(stream, this);
@@ -62,21 +61,14 @@ void SkPDFObject::AddResourceHelper(SkPDFObject* resource,
     resource->ref();
 }
 
-void SkPDFObject::GetResourcesHelper(
-        const SkTDArray<SkPDFObject*>* resources,
-        const SkTSet<SkPDFObject*>& knownResourceObjects,
-        SkTSet<SkPDFObject*>* newResourceObjects) {
+void SkPDFObject::GetResourcesHelper(SkTDArray<SkPDFObject*>* resources,
+                                     SkTDArray<SkPDFObject*>* result) {
     if (resources->count()) {
-        newResourceObjects->setReserve(
-            newResourceObjects->count() + resources->count());
+        result->setReserve(result->count() + resources->count());
         for (int i = 0; i < resources->count(); i++) {
-            if (!knownResourceObjects.contains((*resources)[i]) &&
-                    !newResourceObjects->contains((*resources)[i])) {
-                newResourceObjects->add((*resources)[i]);
-                (*resources)[i]->ref();
-                (*resources)[i]->getResources(knownResourceObjects,
-                                              newResourceObjects);
-            }
+            result->push((*resources)[i]);
+            (*resources)[i]->ref();
+            (*resources)[i]->getResources(result);
         }
     }
 }
index 49fbbde072ffb7968be4bcdf568bcfab3c3fa491..03799d0845cf44c3d10ce832fe5edabfe97fe9b6 100644 (file)
@@ -14,7 +14,6 @@
 #include "SkScalar.h"
 #include "SkString.h"
 #include "SkTDArray.h"
-#include "SkTSet.h"
 #include "SkTypes.h"
 
 class SkPDFCatalog;
@@ -39,16 +38,13 @@ public:
     virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
 
     /** For non-primitive objects (i.e. objects defined outside this file),
-     *  this method will add to newResourceObjects any objects that this method
-     *  depends on, but not already in knownResourceObjects. This operates
-     *  recursively so if this object depends on another object and that object
-     *  depends on two more, all three objects will be added.
-     *
-     *  @param knownResourceObjects  The set of resources to be ignored.
-     *  @param newResourceObjects  The set to append dependant resources to.
+     *  this method will add to resourceList any objects that this method
+     *  depends on.  This operates recursively so if this object depends on
+     *  another object and that object depends on two more, all three objects
+     *  will be added.
+     *  @param resourceList  The list to append dependant resources to.
      */
-    virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
-                              SkTSet<SkPDFObject*>* newResourceObjects);
+    virtual void getResources(SkTDArray<SkPDFObject*>* resourceList);
 
     /** Emit this object unless the catalog has a substitute object, in which
      *  case emit that.
@@ -78,16 +74,10 @@ public:
     /** Static helper function to copy and reference the resources (and all
      *   their subresources) into a new list.
      * @param resources The resource list.
-     * @param newResourceObjects All the resource objects (recursively) used on
-     *                         the page are added to this array.  This gives
-     *                         the caller a chance to deduplicate resources
-     *                         across pages.
-     * @param knownResourceObjects  The set of resources to be ignored.
-     */
-    static void GetResourcesHelper(
-            const SkTDArray<SkPDFObject*>* resources,
-            const SkTSet<SkPDFObject*>& knownResourceObjects,
-            SkTSet<SkPDFObject*>* newResourceObjects);
+     * @param result    The list to add to.
+     */
+    static void GetResourcesHelper(SkTDArray<SkPDFObject*>* resources,
+                                   SkTDArray<SkPDFObject*>* result);
 
 protected:
     /** Subclasses must implement this method to print the object to the
index 8041a8f389ffd69cb245d172b3e3d5f1585c407c..6e7d61676decc081b140b90bbe21356984756ed7 100644 (file)
 
 class SkPDFTestDict : public SkPDFDict {
 public:
-  virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
-                            SkTSet<SkPDFObject*>* newResourceObjects) {
+    void getResources(SkTDArray<SkPDFObject*>* resourceList) {
+        resourceList->setReserve(resourceList->count() + fResources.count());
         for (int i = 0; i < fResources.count(); i++) {
-            newResourceObjects->add(fResources[i]);
+            resourceList->push(fResources[i]);
             fResources[i]->ref();
         }
     }