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

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: tests 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
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 "SkRefCnt.h" 13 #include "SkRefCnt.h"
14 #include "SkScalar.h" 14 #include "SkScalar.h"
15 #include "SkString.h" 15 #include "SkString.h"
16 #include "SkTDArray.h" 16 #include "SkTDArray.h"
17 #include "SkTSet.h" 17 #include "SkTSet.h"
18 #include "SkTypes.h" 18 #include "SkTypes.h"
19 19
20 class SkPDFCatalog; 20 class SkPDFCatalog;
21 class SkWStream; 21 class SkWStream;
22 22
23 class SkPDFObject;
24 typedef SkTSet<SkPDFObject*> SkPDFObjectSet;
mtklein 2015/01/26 23:38:59 I generally prefer writing out the full names of t
hal.canary 2015/02/09 23:35:01 I'm not sure that I need SkTSet. I really need an
25
23 /** \class SkPDFObject 26 /** \class SkPDFObject
24 27
25 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
26 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,
27 which are common in the PDF format. 30 which are common in the PDF format.
28 */ 31 */
29 class SkPDFObject : public SkRefCnt { 32 class SkPDFObject : public SkRefCnt {
30 public: 33 public:
31 SK_DECLARE_INST_COUNT(SkPDFObject) 34 SK_DECLARE_INST_COUNT(SkPDFObject)
32 35
33 /** Subclasses must implement this method to print the object to the 36 /** Subclasses must implement this method to print the object to the
34 * PDF file. 37 * PDF file.
35 * @param catalog The object catalog to use. 38 * @param catalog The object catalog to use.
36 * @param stream The writable output stream to send the output to. 39 * @param stream The writable output stream to send the output to.
37 */ 40 */
38 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) = 0; 41 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) = 0;
39 42
40 /** For non-primitive objects (i.e. objects defined outside this file), 43 /**
41 * this method will add to newResourceObjects any objects that this method 44 * An object's has a resource if it depends, via an indirect
42 * depends on, but not already in knownResourceObjects. This operates 45 * reference on another object. This method recursively adds
43 * recursively so if this object depends on another object and that object 46 * resouces for this object and for its resouces' resouces....
mtklein 2015/01/26 23:38:59 This first sentence doesn't really make sense. Is
hal.canary 2015/02/09 23:35:01 Done.
44 * depends on two more, all three objects will be added.
45 * 47 *
46 * @param knownResourceObjects The set of resources to be ignored. 48 * Ther default implementation does nothing and is therefore
47 * @param newResourceObjects The set to append dependant resources to. 49 * suitable for "leaf" objects.
mtklein 2015/01/26 23:38:59 Instead of writing this note, you could just put t
hal.canary 2015/02/09 23:35:01 You shouldn't put virtuals in a header file.
mtklein 2015/02/09 23:47:17 Why not?
48 */ 50 */
49 virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects, 51 virtual void addResources(SkPDFObjectSet* resourceSet,
mtklein 2015/01/26 23:38:59 Can this method be const ?
50 SkTSet<SkPDFObject*>* newResourceObjects); 52 SkPDFCatalog* catalog);
51
52 /** Static helper function to add a resource to a list. The list takes
53 * a reference.
54 * @param resource The resource to add.
55 * @param list The list to add the resource to.
56 */
57 static void AddResourceHelper(SkPDFObject* resource,
58 SkTDArray<SkPDFObject*>* list);
59
60 /** Static helper function to copy and reference the resources (and all
61 * their subresources) into a new list.
62 * @param resources The resource list.
63 * @param newResourceObjects All the resource objects (recursively) used on
64 * the page are added to this array. This gives
65 * the caller a chance to deduplicate resources
66 * across pages.
67 * @param knownResourceObjects The set of resources to be ignored.
68 */
69 static void GetResourcesHelper(
70 const SkTDArray<SkPDFObject*>* resources,
71 const SkTSet<SkPDFObject*>& knownResourceObjects,
72 SkTSet<SkPDFObject*>* newResourceObjects);
73 53
74 private: 54 private:
75 typedef SkRefCnt INHERITED; 55 typedef SkRefCnt INHERITED;
76 }; 56 };
77 57
78 /** \class SkPDFObjRef 58 /** \class SkPDFObjRef
79 59
80 An indirect reference to a PDF object. 60 An indirect reference to a PDF object.
81 */ 61 */
82 class SkPDFObjRef : public SkPDFObject { 62 class SkPDFObjRef : public SkPDFObject {
83 public: 63 public:
84 SK_DECLARE_INST_COUNT(SkPDFObjRef) 64 SK_DECLARE_INST_COUNT(SkPDFObjRef)
85 65
86 /** Create a reference to an existing SkPDFObject. 66 /** Create a reference to an existing SkPDFObject.
87 * @param obj The object to reference. 67 * @param obj The object to reference.
88 */ 68 */
89 explicit SkPDFObjRef(SkPDFObject* obj); 69 explicit SkPDFObjRef(SkPDFObject* obj);
90 virtual ~SkPDFObjRef(); 70 virtual ~SkPDFObjRef();
91 71
92 // The SkPDFObject interface. 72 // The SkPDFObject interface.
93 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID E; 73 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID E;
74 virtual void addResources(SkPDFObjectSet*, SkPDFCatalog*) SK_OVERRIDE;
94 75
95 private: 76 private:
96 SkAutoTUnref<SkPDFObject> fObj; 77 SkAutoTUnref<SkPDFObject> fObj;
97 78
98 typedef SkPDFObject INHERITED; 79 typedef SkPDFObject INHERITED;
99 }; 80 };
100 81
101 /** \class SkPDFInt 82 /** \class SkPDFInt
102 83
103 An integer object in a PDF. 84 An integer object in a PDF.
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 public: 228 public:
248 SK_DECLARE_INST_COUNT(SkPDFArray) 229 SK_DECLARE_INST_COUNT(SkPDFArray)
249 230
250 /** Create a PDF array. Maximum length is 8191. 231 /** Create a PDF array. Maximum length is 8191.
251 */ 232 */
252 SkPDFArray(); 233 SkPDFArray();
253 virtual ~SkPDFArray(); 234 virtual ~SkPDFArray();
254 235
255 // The SkPDFObject interface. 236 // The SkPDFObject interface.
256 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID E; 237 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID E;
238 virtual void addResources(SkPDFObjectSet*, SkPDFCatalog*) SK_OVERRIDE;
257 239
258 /** The size of the array. 240 /** The size of the array.
259 */ 241 */
260 int size() { return fValue.count(); } 242 int size() { return fValue.count(); }
261 243
262 /** Preallocate space for the given number of entries. 244 /** Preallocate space for the given number of entries.
263 * @param length The number of array slots to preallocate. 245 * @param length The number of array slots to preallocate.
264 */ 246 */
265 void reserve(int length); 247 void reserve(int length);
266 248
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 300
319 /** Create a PDF dictionary with a Type entry. 301 /** Create a PDF dictionary with a Type entry.
320 * @param type The value of the Type entry. 302 * @param type The value of the Type entry.
321 */ 303 */
322 explicit SkPDFDict(const char type[]); 304 explicit SkPDFDict(const char type[]);
323 305
324 virtual ~SkPDFDict(); 306 virtual ~SkPDFDict();
325 307
326 // The SkPDFObject interface. 308 // The SkPDFObject interface.
327 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID E; 309 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID E;
310 virtual void addResources(SkPDFObjectSet*, SkPDFCatalog*) SK_OVERRIDE;
328 311
329 /** The size of the dictionary. 312 /** The size of the dictionary.
330 */ 313 */
331 int size() const; 314 int size() const;
332 315
333 /** Add the value to the dictionary with the given key. Refs value. 316 /** Add the value to the dictionary with the given key. Refs value.
334 * @param key The key for this dictionary entry. 317 * @param key The key for this dictionary entry.
335 * @param value The value for this dictionary entry. 318 * @param value The value for this dictionary entry.
336 * @return The value argument is returned. 319 * @return The value argument is returned.
337 */ 320 */
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 387
405 mutable SkMutex fMutex; // protects modifications to fValue 388 mutable SkMutex fMutex; // protects modifications to fValue
406 SkTDArray<struct Rec> fValue; 389 SkTDArray<struct Rec> fValue;
407 390
408 SkPDFObject* append(SkPDFName* key, SkPDFObject* value); 391 SkPDFObject* append(SkPDFName* key, SkPDFObject* value);
409 392
410 typedef SkPDFObject INHERITED; 393 typedef SkPDFObject INHERITED;
411 }; 394 };
412 395
413 #endif 396 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698