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

Issue 870333002: Simplify reference management in SkPDF (Closed)

Created:
5 years, 11 months ago by hal.canary
Modified:
5 years, 10 months ago
Reviewers:
mtklein
CC:
reviews_skia.org
Base URL:
https://skia.googlesource.com/skia.git@master
Target Ref:
refs/heads/master
Project:
skia
Visibility:
Public.

Description

Simplify reference management in SkPDF Prior to this change, SkPDFObject subclasses were required to track their resources separately from the document structure. (An object has a resource if it depends, via an indirect reference, on another object). This led to a lot of extra code to duplicate effort. I replace the getResources() function with the much simpler addResources() function. I only define a non-trivial addResources() method on arrays, dictionaries, and indirect object references. All other specialized classes simply rely on their parent class's implementation. SkPDFObject::addResources() works by recursively walking the directed graph of object (direct and indirect) references and adding resources to a set. It doesn't matter that there are closed loops in the graph, since we check the set before walking down a branch. - Add SkPDFObject::addResources() virtual function, with four implementations - Remove SkPDFObject::getResources() virtual function and all implementations. - Remove SkPDFObject::GetResourcesHelper() - Remove SkPDFObject::AddResourceHelper() - In SkPDFCatalog::findObjectIndex(), add an object to the catalog if it doesn't exist yet. - SkPDFCatalog::setSubstitute() no longer sets up resources - SkPDFDocument.cpp no longer needs the Streamer object - SkPDFDocument.cpp calls fDocCatalog->addResources to build the resource list. - SkPDFFont::addResource() removed - All SkPDF-::fResource sets removed (they are redundant). - removed SkPDFImage::addSMask() function - SkPDFResourceDict::getReferencedResources() removed. Motivation: this removes quite a bit of code and makes the objects slightly slimmer in memory. Most importantly, this will lead the way towards removing SkPDFObject's inheritance from SkRefCnt, which will greatly simplify everything. Testing: I usually test changes to the PDF backend by comparing checksums of PDF files rendered from GMs and SKPs before and after the change. This change both re-orders and re-numbers the indirect PDF objects. I used the qpdf program to normalize the PDFs and then compared the normalized outputs from before and after the change; they matched. Committed: https://skia.googlesource.com/skia/+/bf799cd228282431e6311900dd383083f8af7164

Patch Set 1 : tests #

Total comments: 14

Patch Set 2 : 2015-02-09 (Monday) 18:34:40 EST #

Patch Set 3 : 2015-02-10 (Tuesday) 11:05:24 EST #

Total comments: 2

Patch Set 4 : remove extrannious struct #

Patch Set 5 : make #

Unified diffs Side-by-side diffs Delta from patch set Stats (+89 lines, -399 lines) Patch
M src/pdf/SkPDFCatalog.h View 1 2 3 4 4 chunks +4 lines, -15 lines 0 comments Download
M src/pdf/SkPDFCatalog.cpp View 1 2 3 4 5 chunks +7 lines, -43 lines 0 comments Download
M src/pdf/SkPDFDocument.cpp View 1 2 3 4 5 chunks +19 lines, -66 lines 0 comments Download
M src/pdf/SkPDFFont.h View 3 chunks +0 lines, -7 lines 0 comments Download
M src/pdf/SkPDFFont.cpp View 11 chunks +0 lines, -21 lines 0 comments Download
M src/pdf/SkPDFFormXObject.h View 1 chunk +0 lines, -6 lines 0 comments Download
M src/pdf/SkPDFFormXObject.cpp View 3 chunks +1 line, -16 lines 0 comments Download
M src/pdf/SkPDFGraphicState.h View 1 3 chunks +0 lines, -6 lines 0 comments Download
M src/pdf/SkPDFGraphicState.cpp View 1 3 chunks +1 line, -18 lines 0 comments Download
M src/pdf/SkPDFImage.h View 2 chunks +0 lines, -12 lines 0 comments Download
M src/pdf/SkPDFImage.cpp View 2 chunks +2 lines, -19 lines 0 comments Download
M src/pdf/SkPDFPage.cpp View 2 chunks +1 line, -5 lines 0 comments Download
M src/pdf/SkPDFResourceDict.h View 1 chunk +0 lines, -14 lines 0 comments Download
M src/pdf/SkPDFResourceDict.cpp View 1 chunk +0 lines, -21 lines 0 comments Download
M src/pdf/SkPDFShader.h View 3 chunks +0 lines, -6 lines 0 comments Download
M src/pdf/SkPDFShader.cpp View 4 chunks +0 lines, -19 lines 0 comments Download
M src/pdf/SkPDFTypes.h View 1 2 5 chunks +12 lines, -31 lines 0 comments Download
M src/pdf/SkPDFTypes.cpp View 1 2 3 4 4 chunks +30 lines, -32 lines 0 comments Download
M tests/PDFPrimitivesTest.cpp View 1 2 3 4 4 chunks +12 lines, -42 lines 0 comments Download

Messages

Total messages: 30 (10 generated)
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/870333002/1
5 years, 11 months ago (2015-01-25 01:15:05 UTC) #2
commit-bot: I haz the power
Note for Reviewers: The CQ is waiting for an approval. If you believe that the ...
5 years, 11 months ago (2015-01-25 01:15:06 UTC) #3
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/870333002/20001
5 years, 11 months ago (2015-01-25 13:54:56 UTC) #6
commit-bot: I haz the power
Note for Reviewers: The CQ is waiting for an approval. If you believe that the ...
5 years, 11 months ago (2015-01-25 13:54:57 UTC) #7
hal.canary
PTAL. ## test code ## #!/bin/sh : ${SKIA_SRC_DIR:=${HOME}/src/skia} : ${SKIA_BUILD_DIR:=${HOME}/build/skia/gcc} : ${SKIA_BUILD_TYPE:=Release} SKIA_BUILD="${SKIA_BUILD_DIR}/${SKIA_BUILD_TYPE}" git checkout ...
5 years, 11 months ago (2015-01-25 18:08:25 UTC) #11
mtklein
https://codereview.chromium.org/870333002/diff/20001/src/pdf/SkPDFCatalog.cpp File src/pdf/SkPDFCatalog.cpp (right): https://codereview.chromium.org/870333002/diff/20001/src/pdf/SkPDFCatalog.cpp#newcode59 src/pdf/SkPDFCatalog.cpp:59: int SkPDFCatalog::findObjectIndex(SkPDFObject* obj) { Seems like this wants a ...
5 years, 11 months ago (2015-01-26 23:39:00 UTC) #12
hal.canary
https://codereview.chromium.org/870333002/diff/20001/src/pdf/SkPDFCatalog.cpp File src/pdf/SkPDFCatalog.cpp (right): https://codereview.chromium.org/870333002/diff/20001/src/pdf/SkPDFCatalog.cpp#newcode59 src/pdf/SkPDFCatalog.cpp:59: int SkPDFCatalog::findObjectIndex(SkPDFObject* obj) { On 2015/01/26 23:38:59, mtklein wrote: ...
5 years, 10 months ago (2015-02-09 23:35:01 UTC) #13
mtklein
https://codereview.chromium.org/870333002/diff/20001/src/pdf/SkPDFTypes.h File src/pdf/SkPDFTypes.h (right): https://codereview.chromium.org/870333002/diff/20001/src/pdf/SkPDFTypes.h#newcode49 src/pdf/SkPDFTypes.h:49: * suitable for "leaf" objects. On 2015/02/09 23:35:01, Hal ...
5 years, 10 months ago (2015-02-09 23:47:17 UTC) #14
hal.canary
On 2015/02/09 23:47:17, mtklein wrote: > https://codereview.chromium.org/870333002/diff/20001/src/pdf/SkPDFTypes.h > File src/pdf/SkPDFTypes.h (right): > > https://codereview.chromium.org/870333002/diff/20001/src/pdf/SkPDFTypes.h#newcode49 > ...
5 years, 10 months ago (2015-02-09 23:56:55 UTC) #15
mtklein
> Quoting from Chromium's style guide: "Stop inlining virtual methods. You can't > inline virtual ...
5 years, 10 months ago (2015-02-09 23:59:18 UTC) #16
hal.canary
On 2015/02/09 23:59:18, mtklein wrote: > > Quoting from Chromium's style guide: "Stop inlining virtual ...
5 years, 10 months ago (2015-02-10 00:42:20 UTC) #17
mtklein
> "A function defined entirely inside a class definition, ... is always inline" Okay, so ...
5 years, 10 months ago (2015-02-10 14:02:41 UTC) #18
hal.canary
done
5 years, 10 months ago (2015-02-10 16:05:42 UTC) #19
mtklein
lgtm https://codereview.chromium.org/870333002/diff/60001/src/pdf/SkPDFCatalog.cpp File src/pdf/SkPDFCatalog.cpp (right): https://codereview.chromium.org/870333002/diff/60001/src/pdf/SkPDFCatalog.cpp#newcode65 src/pdf/SkPDFCatalog.cpp:65: struct Rec newEntry(obj, false); drop struct? This is ...
5 years, 10 months ago (2015-02-10 17:25:53 UTC) #20
hal.canary
One last round of correctness tests, then I'll land. https://codereview.chromium.org/870333002/diff/60001/src/pdf/SkPDFCatalog.cpp File src/pdf/SkPDFCatalog.cpp (right): https://codereview.chromium.org/870333002/diff/60001/src/pdf/SkPDFCatalog.cpp#newcode65 src/pdf/SkPDFCatalog.cpp:65: ...
5 years, 10 months ago (2015-02-10 17:44:59 UTC) #22
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/870333002/80001
5 years, 10 months ago (2015-02-10 18:13:31 UTC) #24
commit-bot: I haz the power
Try jobs failed on following builders: Test-Ubuntu13.10-GCE-NoGPU-x86_64-Release-Shared-Trybot on client.skia (JOB_FAILED, http://build.chromium.org/p/client.skia/builders/Test-Ubuntu13.10-GCE-NoGPU-x86_64-Release-Shared-Trybot/builds/2000)
5 years, 10 months ago (2015-02-10 18:18:11 UTC) #26
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/870333002/100001
5 years, 10 months ago (2015-02-10 21:18:13 UTC) #28
commit-bot: I haz the power
Committed patchset #5 (id:100001) as https://skia.googlesource.com/skia/+/bf799cd228282431e6311900dd383083f8af7164
5 years, 10 months ago (2015-02-10 21:32:14 UTC) #29
hal.canary
5 years, 10 months ago (2015-02-10 21:33:15 UTC) #30
Message was sent while issue was closed.
Note:  I changed 

   void SkPDFCatalog::emitObjectNumber(SkWStream*, SkPDFObject*) 	  

to

    int32_t SkPDFCatalog::getObjectNumber(SkPDFObject*)

to simplify unit tests.

Powered by Google App Engine
This is Rietveld 408576698