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

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

Issue 1775143002: Revert of SkPDF: Add sk_sp setters; .release() becomes std::move() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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 * Copyright 2010 The Android Open Source Project 2 * Copyright 2010 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #ifndef SkPDFTypes_DEFINED 9 #ifndef SkPDFTypes_DEFINED
10 #define SkPDFTypes_DEFINED 10 #define SkPDFTypes_DEFINED
(...skipping 21 matching lines...) Expand all
32 which are common in the PDF format. 32 which are common in the PDF format.
33 33
34 */ 34 */
35 class SkPDFObject : public SkRefCnt { 35 class SkPDFObject : public SkRefCnt {
36 public: 36 public:
37 /** Subclasses must implement this method to print the object to the 37 /** Subclasses must implement this method to print the object to the
38 * PDF file. 38 * PDF file.
39 * @param catalog The object catalog to use. 39 * @param catalog The object catalog to use.
40 * @param stream The writable output stream to send the output to. 40 * @param stream The writable output stream to send the output to.
41 */ 41 */
42 // TODO(halcanary): make this method const
42 virtual void emitObject(SkWStream* stream, 43 virtual void emitObject(SkWStream* stream,
43 const SkPDFObjNumMap& objNumMap, 44 const SkPDFObjNumMap& objNumMap,
44 const SkPDFSubstituteMap& substitutes) const = 0; 45 const SkPDFSubstituteMap& substitutes) const = 0;
45 46
46 /** 47 /**
47 * Adds all transitive dependencies of this object to the 48 * Adds all transitive dependencies of this object to the
48 * catalog. Implementations should respect the catalog's object 49 * catalog. Implementations should respect the catalog's object
49 * substitution map. 50 * substitution map.
50 */ 51 */
51 virtual void addResources(SkPDFObjNumMap* catalog, 52 virtual void addResources(SkPDFObjNumMap* catalog,
52 const SkPDFSubstituteMap& substitutes) const {} 53 const SkPDFSubstituteMap& substitutes) const {}
53 54
54 private: 55 private:
55 typedef SkRefCnt INHERITED; 56 typedef SkRefCnt INHERITED;
56 }; 57 };
57 58
58 //////////////////////////////////////////////////////////////////////////////// 59 ////////////////////////////////////////////////////////////////////////////////
59 60
60 /** 61 /**
61 A SkPDFUnion is a non-virtualized implementation of the 62 A SkPDFUnion is a non-virtualized implementation of the
62 non-compound, non-specialized PDF Object types: Name, String, 63 non-compound, non-specialized PDF Object types: Name, String,
63 Number, Boolean. 64 Number, Boolean.
64 */ 65 */
65 class SkPDFUnion { 66 class SkPDFUnion {
66 public: 67 public:
68 // u.move() is analogous to std::move(u). It returns an rvalue.
69 SkPDFUnion move() { return static_cast<SkPDFUnion&&>(*this); }
67 // Move contstructor and assignemnt operator destroy the argument 70 // Move contstructor and assignemnt operator destroy the argument
68 // and steal their references (if needed). 71 // and steal their references (if needed).
69 SkPDFUnion(SkPDFUnion&& other); 72 SkPDFUnion(SkPDFUnion&& other);
70 SkPDFUnion& operator=(SkPDFUnion&& other); 73 SkPDFUnion& operator=(SkPDFUnion&& other);
71 74
72 ~SkPDFUnion(); 75 ~SkPDFUnion();
73 76
74 /** The following nine functions are the standard way of creating 77 /** The following nine functions are the standard way of creating
75 SkPDFUnion objects. */ 78 SkPDFUnion objects. */
76 79
77 static SkPDFUnion Int(int32_t); 80 static SkPDFUnion Int(int32_t);
78 81
79 static SkPDFUnion Int(size_t v) { return SkPDFUnion::Int(SkToS32(v)); } 82 static SkPDFUnion Int(size_t v) { return SkPDFUnion::Int(SkToS32(v)); }
80 83
81 static SkPDFUnion Bool(bool); 84 static SkPDFUnion Bool(bool);
82 85
83 static SkPDFUnion Scalar(SkScalar); 86 static SkPDFUnion Scalar(SkScalar);
84 87
85 /** These two functions do NOT take ownership of char*, and do NOT 88 /** These two functions do NOT take ownership of ptr, and do NOT
86 copy the string. Suitable for passing in static const 89 copy the string. Suitable for passing in static const
87 strings. For example: 90 strings. For example:
88 SkPDFUnion n = SkPDFUnion::Name("Length"); 91 SkPDFUnion n = SkPDFUnion::Name("Length");
89 SkPDFUnion u = SkPDFUnion::String("Identity"); */ 92 SkPDFUnion u = SkPDFUnion::String("Identity"); */
90 93
91 /** SkPDFUnion::Name(const char*) assumes that the passed string 94 /** SkPDFUnion::Name(const char*) assumes that the passed string
92 is already a valid name (that is: it has no control or 95 is already a valid name (that is: it has no control or
93 whitespace characters). This will not copy the name. */ 96 whitespace characters). This will not copy the name. */
94 static SkPDFUnion Name(const char*); 97 static SkPDFUnion Name(const char*);
95 98
96 /** SkPDFUnion::String will encode the passed string. This will 99 /** SkPDFUnion::String will encode the passed string. This will
97 not copy the name. */ 100 not copy the name. */
98 static SkPDFUnion String(const char*); 101 static SkPDFUnion String(const char*);
99 102
100 /** SkPDFUnion::Name(const SkString&) does not assume that the 103 /** SkPDFUnion::Name(const SkString&) does not assume that the
101 passed string is already a valid name and it will escape the 104 passed string is already a valid name and it will escape the
102 string. */ 105 string. */
103 static SkPDFUnion Name(const SkString&); 106 static SkPDFUnion Name(const SkString&);
104 107
105 /** SkPDFUnion::String will encode the passed string. */ 108 /** SkPDFUnion::String will encode the passed string. */
106 static SkPDFUnion String(const SkString&); 109 static SkPDFUnion String(const SkString&);
107 110
108 static SkPDFUnion Object(sk_sp<SkPDFObject>); 111 /** This function DOES take ownership of the object. E.g.
109 static SkPDFUnion ObjRef(sk_sp<SkPDFObject>); 112 auto dict = sk_make_sp<SkPDFDict>();
113 dict->insert(.....);
114 SkPDFUnion u = SkPDFUnion::Object(dict.detach()) */
115 static SkPDFUnion Object(SkPDFObject*);
116
117 /** This function DOES take ownership of the object. E.g.
118 sk_sp<SkPDFBitmap> image(
119 SkPDFBitmap::Create(fCanon, bitmap));
120 SkPDFUnion u = SkPDFUnion::ObjRef(image.detach()) */
121 static SkPDFUnion ObjRef(SkPDFObject*);
110 122
111 /** These two non-virtual methods mirror SkPDFObject's 123 /** These two non-virtual methods mirror SkPDFObject's
112 corresponding virtuals. */ 124 corresponding virtuals. */
113 void emitObject(SkWStream*, 125 void emitObject(SkWStream*,
114 const SkPDFObjNumMap&, 126 const SkPDFObjNumMap&,
115 const SkPDFSubstituteMap&) const; 127 const SkPDFSubstituteMap&) const;
116 void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const; 128 void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const;
117 129
118 bool isName() const; 130 bool isName() const;
119 131
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 #if 0 // Enable if needed. 167 #if 0 // Enable if needed.
156 /** This class is a SkPDFUnion with SkPDFObject virtuals attached. 168 /** This class is a SkPDFUnion with SkPDFObject virtuals attached.
157 The only use case of this is when a non-compound PDF object is 169 The only use case of this is when a non-compound PDF object is
158 referenced indirectly. */ 170 referenced indirectly. */
159 class SkPDFAtom final : public SkPDFObject { 171 class SkPDFAtom final : public SkPDFObject {
160 public: 172 public:
161 void emitObject(SkWStream* stream, 173 void emitObject(SkWStream* stream,
162 const SkPDFObjNumMap& objNumMap, 174 const SkPDFObjNumMap& objNumMap,
163 const SkPDFSubstituteMap& substitutes) final; 175 const SkPDFSubstituteMap& substitutes) final;
164 void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const final; 176 void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const final;
165 SkPDFAtom(SkPDFUnion&& v) : fValue(std::move(v) {} 177 SkPDFAtom(SkPDFUnion&& v) : fValue(v.move()) {}
166 178
167 private: 179 private:
168 const SkPDFUnion fValue; 180 const SkPDFUnion fValue;
169 typedef SkPDFObject INHERITED; 181 typedef SkPDFObject INHERITED;
170 }; 182 };
171 #endif // 0 183 #endif // 0
172 184
173 //////////////////////////////////////////////////////////////////////////////// 185 ////////////////////////////////////////////////////////////////////////////////
174 186
175 /** \class SkPDFArray 187 /** \class SkPDFArray
(...skipping 28 matching lines...) Expand all
204 /** Appends a value to the end of the array. 216 /** Appends a value to the end of the array.
205 * @param value The value to add to the array. 217 * @param value The value to add to the array.
206 */ 218 */
207 void appendInt(int32_t); 219 void appendInt(int32_t);
208 void appendBool(bool); 220 void appendBool(bool);
209 void appendScalar(SkScalar); 221 void appendScalar(SkScalar);
210 void appendName(const char[]); 222 void appendName(const char[]);
211 void appendName(const SkString&); 223 void appendName(const SkString&);
212 void appendString(const char[]); 224 void appendString(const char[]);
213 void appendString(const SkString&); 225 void appendString(const SkString&);
214 void appendObject(sk_sp<SkPDFObject>); 226 /** appendObject and appendObjRef take ownership of the passed object */
215 void appendObjRef(sk_sp<SkPDFObject>); 227 void appendObject(SkPDFObject*);
228 void appendObjRef(SkPDFObject*);
216 229
217 private: 230 private:
218 SkTDArray<SkPDFUnion> fValues; 231 SkTDArray<SkPDFUnion> fValues;
219 void append(SkPDFUnion&& value); 232 void append(SkPDFUnion&& value);
220 typedef SkPDFObject INHERITED; 233 typedef SkPDFObject INHERITED;
221 }; 234 };
222 235
223 /** \class SkPDFDict 236 /** \class SkPDFDict
224 237
225 A dictionary object in a PDF. 238 A dictionary object in a PDF.
(...skipping 15 matching lines...) Expand all
241 void emitObject(SkWStream* stream, 254 void emitObject(SkWStream* stream,
242 const SkPDFObjNumMap& objNumMap, 255 const SkPDFObjNumMap& objNumMap,
243 const SkPDFSubstituteMap& substitutes) const override; 256 const SkPDFSubstituteMap& substitutes) const override;
244 void addResources(SkPDFObjNumMap*, 257 void addResources(SkPDFObjNumMap*,
245 const SkPDFSubstituteMap&) const override; 258 const SkPDFSubstituteMap&) const override;
246 259
247 /** The size of the dictionary. 260 /** The size of the dictionary.
248 */ 261 */
249 int size() const; 262 int size() const;
250 263
251 /** Add the value to the dictionary with the given key. 264 /** Add the value to the dictionary with the given key. Takes
265 * ownership of the object.
252 * @param key The text of the key for this dictionary entry. 266 * @param key The text of the key for this dictionary entry.
253 * @param value The value for this dictionary entry. 267 * @param value The value for this dictionary entry.
254 */ 268 */
255 void insertObject(const char key[], sk_sp<SkPDFObject>); 269 void insertObject(const char key[], SkPDFObject* value);
256 void insertObject(const SkString& key, sk_sp<SkPDFObject>); 270 void insertObject(const SkString& key, SkPDFObject* value);
257 void insertObjRef(const char key[], sk_sp<SkPDFObject>); 271 void insertObjRef(const char key[], SkPDFObject* value);
258 void insertObjRef(const SkString& key, sk_sp<SkPDFObject>); 272 void insertObjRef(const SkString& key, SkPDFObject* value);
259 273
260 /** Add the value to the dictionary with the given key. 274 /** Add the value to the dictionary with the given key.
261 * @param key The text of the key for this dictionary entry. 275 * @param key The text of the key for this dictionary entry.
262 * @param value The value for this dictionary entry. 276 * @param value The value for this dictionary entry.
263 */ 277 */
264 void insertBool(const char key[], bool value); 278 void insertBool(const char key[], bool value);
265 void insertInt(const char key[], int32_t value); 279 void insertInt(const char key[], int32_t value);
266 void insertInt(const char key[], size_t value); 280 void insertInt(const char key[], size_t value);
267 void insertScalar(const char key[], SkScalar value); 281 void insertScalar(const char key[], SkScalar value);
268 void insertName(const char key[], const char nameValue[]); 282 void insertName(const char key[], const char nameValue[]);
(...skipping 27 matching lines...) Expand all
296 /** \class SkPDFSharedStream 310 /** \class SkPDFSharedStream
297 311
298 This class takes an asset and assumes that it is backed by 312 This class takes an asset and assumes that it is backed by
299 long-lived shared data (for example, an open file 313 long-lived shared data (for example, an open file
300 descriptor). That is: no memory savings can be made by holding on 314 descriptor). That is: no memory savings can be made by holding on
301 to a compressed version instead. 315 to a compressed version instead.
302 */ 316 */
303 class SkPDFSharedStream final : public SkPDFObject { 317 class SkPDFSharedStream final : public SkPDFObject {
304 public: 318 public:
305 // Takes ownership of asset. 319 // Takes ownership of asset.
306 SkPDFSharedStream(SkStreamAsset* data) 320 SkPDFSharedStream(SkStreamAsset* data) : fAsset(data), fDict(new SkPDFDict) { SkASSERT(data); }
307 : fAsset(data), fDict(new SkPDFDict) { SkASSERT(data); }
308 SkPDFDict* dict() { return fDict.get(); } 321 SkPDFDict* dict() { return fDict.get(); }
309 void emitObject(SkWStream*, 322 void emitObject(SkWStream*,
310 const SkPDFObjNumMap&, 323 const SkPDFObjNumMap&,
311 const SkPDFSubstituteMap&) const override; 324 const SkPDFSubstituteMap&) const override;
312 void addResources(SkPDFObjNumMap*, 325 void addResources(SkPDFObjNumMap*,
313 const SkPDFSubstituteMap&) const override; 326 const SkPDFSubstituteMap&) const override;
314 327
315 private: 328 private:
316 SkAutoTDelete<SkStreamAsset> fAsset; 329 SkAutoTDelete<SkStreamAsset> fAsset;
317 sk_sp<SkPDFDict> fDict; 330 sk_sp<SkPDFDict> fDict;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 }; 393 };
381 394
382 #ifdef SK_PDF_IMAGE_STATS 395 #ifdef SK_PDF_IMAGE_STATS
383 extern SkAtomic<int> gDrawImageCalls; 396 extern SkAtomic<int> gDrawImageCalls;
384 extern SkAtomic<int> gJpegImageObjects; 397 extern SkAtomic<int> gJpegImageObjects;
385 extern SkAtomic<int> gRegularImageObjects; 398 extern SkAtomic<int> gRegularImageObjects;
386 extern void SkPDFImageDumpStats(); 399 extern void SkPDFImageDumpStats();
387 #endif // SK_PDF_IMAGE_STATS 400 #endif // SK_PDF_IMAGE_STATS
388 401
389 #endif 402 #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