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

Side by Side Diff: src/pdf/SkPDFTypes.h

Issue 870333002: Simplify reference management in SkPDF (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make Created 5 years, 10 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 unified diff | Download patch
« no previous file with comments | « src/pdf/SkPDFShader.cpp ('k') | src/pdf/SkPDFTypes.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2010 The Android Open Source Project 3 * Copyright 2010 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkPDFTypes_DEFINED 10 #ifndef SkPDFTypes_DEFINED
11 #define SkPDFTypes_DEFINED 11 #define SkPDFTypes_DEFINED
12 12
13 #include "SkMutex.h" 13 #include "SkMutex.h"
14 #include "SkRefCnt.h" 14 #include "SkRefCnt.h"
15 #include "SkScalar.h" 15 #include "SkScalar.h"
16 #include "SkString.h" 16 #include "SkString.h"
17 #include "SkTDArray.h" 17 #include "SkTDArray.h"
18 #include "SkTSet.h" 18 #include "SkTSet.h"
19 #include "SkTypes.h" 19 #include "SkTypes.h"
20 20
21 class SkPDFCatalog; 21 class SkPDFCatalog;
22 class SkWStream; 22 class SkWStream;
23 23
24 class SkPDFObject;
25
24 /** \class SkPDFObject 26 /** \class SkPDFObject
25 27
26 A PDF Object is the base class for primitive elements in a PDF file. A 28 A PDF Object is the base class for primitive elements in a PDF file. A
27 common subtype is used to ease the use of indirect object references, 29 common subtype is used to ease the use of indirect object references,
28 which are common in the PDF format. 30 which are common in the PDF format.
29 */ 31 */
30 class SkPDFObject : public SkRefCnt { 32 class SkPDFObject : public SkRefCnt {
31 public: 33 public:
32 SK_DECLARE_INST_COUNT(SkPDFObject) 34 SK_DECLARE_INST_COUNT(SkPDFObject)
33 35
34 /** Subclasses must implement this method to print the object to the 36 /** Subclasses must implement this method to print the object to the
35 * PDF file. 37 * PDF file.
36 * @param catalog The object catalog to use. 38 * @param catalog The object catalog to use.
37 * @param stream The writable output stream to send the output to. 39 * @param stream The writable output stream to send the output to.
38 */ 40 */
41 // TODO(halcanary): make this method const
39 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) = 0; 42 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) = 0;
40 43
41 /** For non-primitive objects (i.e. objects defined outside this file), 44 /**
42 * this method will add to newResourceObjects any objects that this method 45 * Adds all transitive dependencies of this object to resourceSet.
43 * depends on, but not already in knownResourceObjects. This operates
44 * recursively so if this object depends on another object and that object
45 * depends on two more, all three objects will be added.
46 * 46 *
47 * @param knownResourceObjects The set of resources to be ignored. 47 * @param catalog Implementations should respect the catalog's
48 * @param newResourceObjects The set to append dependant resources to. 48 * object substitution map.
49 */ 49 */
50 virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects, 50 virtual void addResources(SkTSet<SkPDFObject*>* resourceSet,
51 SkTSet<SkPDFObject*>* newResourceObjects); 51 SkPDFCatalog* catalog) const {}
52
53 /** Static helper function to add a resource to a list. The list takes
54 * a reference.
55 * @param resource The resource to add.
56 * @param list The list to add the resource to.
57 */
58 static void AddResourceHelper(SkPDFObject* resource,
59 SkTDArray<SkPDFObject*>* list);
60
61 /** Static helper function to copy and reference the resources (and all
62 * their subresources) into a new list.
63 * @param resources The resource list.
64 * @param newResourceObjects All the resource objects (recursively) used on
65 * the page are added to this array. This gives
66 * the caller a chance to deduplicate resources
67 * across pages.
68 * @param knownResourceObjects The set of resources to be ignored.
69 */
70 static void GetResourcesHelper(
71 const SkTDArray<SkPDFObject*>* resources,
72 const SkTSet<SkPDFObject*>& knownResourceObjects,
73 SkTSet<SkPDFObject*>* newResourceObjects);
74 52
75 private: 53 private:
76 typedef SkRefCnt INHERITED; 54 typedef SkRefCnt INHERITED;
77 }; 55 };
78 56
79 /** \class SkPDFObjRef 57 /** \class SkPDFObjRef
80 58
81 An indirect reference to a PDF object. 59 An indirect reference to a PDF object.
82 */ 60 */
83 class SkPDFObjRef : public SkPDFObject { 61 class SkPDFObjRef : public SkPDFObject {
84 public: 62 public:
85 SK_DECLARE_INST_COUNT(SkPDFObjRef) 63 SK_DECLARE_INST_COUNT(SkPDFObjRef)
86 64
87 /** Create a reference to an existing SkPDFObject. 65 /** Create a reference to an existing SkPDFObject.
88 * @param obj The object to reference. 66 * @param obj The object to reference.
89 */ 67 */
90 explicit SkPDFObjRef(SkPDFObject* obj); 68 explicit SkPDFObjRef(SkPDFObject* obj);
91 virtual ~SkPDFObjRef(); 69 virtual ~SkPDFObjRef();
92 70
93 // The SkPDFObject interface. 71 // The SkPDFObject interface.
94 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID E; 72 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID E;
73 virtual void addResources(SkTSet<SkPDFObject*>*, SkPDFCatalog*) const SK_OVE RRIDE;
95 74
96 private: 75 private:
97 SkAutoTUnref<SkPDFObject> fObj; 76 SkAutoTUnref<SkPDFObject> fObj;
98 77
99 typedef SkPDFObject INHERITED; 78 typedef SkPDFObject INHERITED;
100 }; 79 };
101 80
102 /** \class SkPDFInt 81 /** \class SkPDFInt
103 82
104 An integer object in a PDF. 83 An integer object in a PDF.
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 public: 227 public:
249 SK_DECLARE_INST_COUNT(SkPDFArray) 228 SK_DECLARE_INST_COUNT(SkPDFArray)
250 229
251 /** Create a PDF array. Maximum length is 8191. 230 /** Create a PDF array. Maximum length is 8191.
252 */ 231 */
253 SkPDFArray(); 232 SkPDFArray();
254 virtual ~SkPDFArray(); 233 virtual ~SkPDFArray();
255 234
256 // The SkPDFObject interface. 235 // The SkPDFObject interface.
257 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID E; 236 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID E;
237 virtual void addResources(SkTSet<SkPDFObject*>*, SkPDFCatalog*) const SK_OVE RRIDE;
258 238
259 /** The size of the array. 239 /** The size of the array.
260 */ 240 */
261 int size() { return fValue.count(); } 241 int size() { return fValue.count(); }
262 242
263 /** Preallocate space for the given number of entries. 243 /** Preallocate space for the given number of entries.
264 * @param length The number of array slots to preallocate. 244 * @param length The number of array slots to preallocate.
265 */ 245 */
266 void reserve(int length); 246 void reserve(int length);
267 247
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 299
320 /** Create a PDF dictionary with a Type entry. 300 /** Create a PDF dictionary with a Type entry.
321 * @param type The value of the Type entry. 301 * @param type The value of the Type entry.
322 */ 302 */
323 explicit SkPDFDict(const char type[]); 303 explicit SkPDFDict(const char type[]);
324 304
325 virtual ~SkPDFDict(); 305 virtual ~SkPDFDict();
326 306
327 // The SkPDFObject interface. 307 // The SkPDFObject interface.
328 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID E; 308 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID E;
309 virtual void addResources(SkTSet<SkPDFObject*>*, SkPDFCatalog*) const SK_OVE RRIDE;
329 310
330 /** The size of the dictionary. 311 /** The size of the dictionary.
331 */ 312 */
332 int size() const; 313 int size() const;
333 314
334 /** Add the value to the dictionary with the given key. Refs value. 315 /** Add the value to the dictionary with the given key. Refs value.
335 * @param key The key for this dictionary entry. 316 * @param key The key for this dictionary entry.
336 * @param value The value for this dictionary entry. 317 * @param value The value for this dictionary entry.
337 * @return The value argument is returned. 318 * @return The value argument is returned.
338 */ 319 */
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 386
406 mutable SkMutex fMutex; // protects modifications to fValue 387 mutable SkMutex fMutex; // protects modifications to fValue
407 SkTDArray<struct Rec> fValue; 388 SkTDArray<struct Rec> fValue;
408 389
409 SkPDFObject* append(SkPDFName* key, SkPDFObject* value); 390 SkPDFObject* append(SkPDFName* key, SkPDFObject* value);
410 391
411 typedef SkPDFObject INHERITED; 392 typedef SkPDFObject INHERITED;
412 }; 393 };
413 394
414 #endif 395 #endif
OLDNEW
« no previous file with comments | « src/pdf/SkPDFShader.cpp ('k') | src/pdf/SkPDFTypes.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698