From 6addb1930013ebb2f984045141650fd7afcfa90f Mon Sep 17 00:00:00 2001 From: "edisonn@google.com" Date: Tue, 2 Apr 2013 15:33:08 +0000 Subject: resubmit https://code.google.com/p/skia/source/detail?r=7883 (in the meantime we added capability to collect minidump and callstack if buildbot fails with heap coruption in windows, and a NPE bug was fixed in SkPDFDocument, when document was destroyed without ever beeing used and a field was NULL + a few minor conflicts have been resolved) git-svn-id: http://skia.googlecode.com/svn/trunk@8487 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/pdf/SkPDFCatalog.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'src/pdf/SkPDFCatalog.cpp') diff --git a/src/pdf/SkPDFCatalog.cpp b/src/pdf/SkPDFCatalog.cpp index 49c0404974..8690b3eaea 100644 --- a/src/pdf/SkPDFCatalog.cpp +++ b/src/pdf/SkPDFCatalog.cpp @@ -171,12 +171,16 @@ void SkPDFCatalog::setSubstitute(SkPDFObject* original, fSubstituteMap.append(1, &newMapping); // Add resource objects of substitute object to catalog. - SkTDArray* targetList = getSubstituteList(onFirstPage); - int existingSize = targetList->count(); - newMapping.fSubstitute->getResources(targetList); - for (int i = existingSize; i < targetList->count(); ++i) { - addObject((*targetList)[i], onFirstPage); - } + SkTSet* targetSet = getSubstituteList(onFirstPage); + SkTSet newResourceObjects; + newMapping.fSubstitute->getResources(*targetSet, &newResourceObjects); + for (int i = 0; i < newResourceObjects.count(); ++i) { + addObject(newResourceObjects[i], onFirstPage); + } + // mergeInto returns the number of duplicates. + // If there are duplicates, there is a bug and we mess ref counting. + SkDEBUGCODE(int duplicates =) targetSet->mergeInto(newResourceObjects); + SkASSERT(duplicates == 0); } SkPDFObject* SkPDFCatalog::getSubstituteObject(SkPDFObject* object) { @@ -190,22 +194,22 @@ SkPDFObject* SkPDFCatalog::getSubstituteObject(SkPDFObject* object) { off_t SkPDFCatalog::setSubstituteResourcesOffsets(off_t fileOffset, bool firstPage) { - SkTDArray* targetList = getSubstituteList(firstPage); + SkTSet* targetSet = getSubstituteList(firstPage); off_t offsetSum = fileOffset; - for (int i = 0; i < targetList->count(); ++i) { - offsetSum += setFileOffset((*targetList)[i], offsetSum); + for (int i = 0; i < targetSet->count(); ++i) { + offsetSum += setFileOffset((*targetSet)[i], offsetSum); } return offsetSum - fileOffset; } void SkPDFCatalog::emitSubstituteResources(SkWStream *stream, bool firstPage) { - SkTDArray* targetList = getSubstituteList(firstPage); - for (int i = 0; i < targetList->count(); ++i) { - (*targetList)[i]->emit(stream, this, true); + SkTSet* targetSet = getSubstituteList(firstPage); + for (int i = 0; i < targetSet->count(); ++i) { + (*targetSet)[i]->emit(stream, this, true); } } -SkTDArray* SkPDFCatalog::getSubstituteList(bool firstPage) { +SkTSet* SkPDFCatalog::getSubstituteList(bool firstPage) { return firstPage ? &fSubstituteResourcesFirstPage : &fSubstituteResourcesRemaining; } -- cgit v1.2.3