Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(845)

Unified Diff: src/pdf/SkPDFCatalog.cpp

Issue 870333002: Simplify reference management in SkPDF (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tests Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/pdf/SkPDFCatalog.cpp
diff --git a/src/pdf/SkPDFCatalog.cpp b/src/pdf/SkPDFCatalog.cpp
index 5fd0f7619c94de36402b9392978232db86727bca..2b51a4f10c4ea5c83c0a75da94dcfcabd0ce7958 100644
--- a/src/pdf/SkPDFCatalog.cpp
+++ b/src/pdf/SkPDFCatalog.cpp
@@ -56,7 +56,7 @@ size_t SkPDFCatalog::getObjectNumberSize(SkPDFObject* obj) {
return buffer.getOffset();
}
-int SkPDFCatalog::findObjectIndex(SkPDFObject* obj) const {
+int SkPDFCatalog::findObjectIndex(SkPDFObject* obj) {
mtklein 2015/01/26 23:38:59 Seems like this wants a new name, lookupOrAdd?
hal.canary 2015/02/09 23:35:01 I'm going to heavily refactor this class in a late
for (int i = 0; i < fCatalog.count(); i++) {
if (fCatalog[i].fObject == obj) {
return i;
@@ -68,7 +68,9 @@ int SkPDFCatalog::findObjectIndex(SkPDFObject* obj) const {
return findObjectIndex(fSubstituteMap[i].fOriginal);
}
}
- return -1;
+ struct Rec newEntry(obj, false);
+ fCatalog.append(1, &newEntry);
+ return fCatalog.count() - 1;
}
int SkPDFCatalog::assignObjNum(SkPDFObject* obj) {
@@ -150,35 +152,8 @@ void SkPDFCatalog::setSubstitute(SkPDFObject* original,
}
}
#endif
- // Check if the original is on first page.
- bool onFirstPage = false;
- for (int i = 0; i < fCatalog.count(); ++i) {
- if (fCatalog[i].fObject == original) {
- onFirstPage = fCatalog[i].fOnFirstPage;
- break;
- }
-#if defined(SK_DEBUG)
- if (i == fCatalog.count() - 1) {
- SkASSERT(false); // original not in catalog
- return;
- }
-#endif
- }
-
SubstituteMapping newMapping(original, substitute);
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 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,7 +165,3 @@ SkPDFObject* SkPDFCatalog::getSubstituteObject(SkPDFObject* object) {
return object;
}
-SkTSet<SkPDFObject*>* SkPDFCatalog::getSubstituteList(bool firstPage) {
- return firstPage ? &fSubstituteResourcesFirstPage :
- &fSubstituteResourcesRemaining;
-}
« no previous file with comments | « src/pdf/SkPDFCatalog.h ('k') | src/pdf/SkPDFDocument.cpp » ('j') | src/pdf/SkPDFGraphicState.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698