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

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

Issue 1227913008: SkPDF: Memory improvements for PDF Streams (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-19 (Wednesday) 17:47:45 EDT Created 5 years, 4 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/SkPDFStream.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
11 11
12 #include "SkRefCnt.h" 12 #include "SkRefCnt.h"
13 #include "SkScalar.h" 13 #include "SkScalar.h"
14 #include "SkStream.h"
14 #include "SkString.h" 15 #include "SkString.h"
15 #include "SkTDArray.h" 16 #include "SkTDArray.h"
16 #include "SkTHash.h" 17 #include "SkTHash.h"
17 #include "SkTypes.h" 18 #include "SkTypes.h"
18 19
19 class SkPDFObjNumMap; 20 class SkPDFObjNumMap;
20 class SkPDFObject; 21 class SkPDFObject;
21 class SkPDFSubstituteMap; 22 class SkPDFSubstituteMap;
22 class SkWStream;
23 23
24 /** \class SkPDFObject 24 /** \class SkPDFObject
25 25
26 A PDF Object is the base class for primitive elements in a PDF file. A 26 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, 27 common subtype is used to ease the use of indirect object references,
28 which are common in the PDF format. 28 which are common in the PDF format.
29 29
30 */ 30 */
31 class SkPDFObject : public SkRefCnt { 31 class SkPDFObject : public SkRefCnt {
32 public: 32 public:
33
34
35 /** Subclasses must implement this method to print the object to the 33 /** Subclasses must implement this method to print the object to the
36 * PDF file. 34 * PDF file.
37 * @param catalog The object catalog to use. 35 * @param catalog The object catalog to use.
38 * @param stream The writable output stream to send the output to. 36 * @param stream The writable output stream to send the output to.
39 */ 37 */
40 // TODO(halcanary): make this method const 38 // TODO(halcanary): make this method const
41 virtual void emitObject(SkWStream* stream, 39 virtual void emitObject(SkWStream* stream,
42 const SkPDFObjNumMap& objNumMap, 40 const SkPDFObjNumMap& objNumMap,
43 const SkPDFSubstituteMap& substitutes) const = 0; 41 const SkPDFSubstituteMap& substitutes) const = 0;
44 42
(...skipping 25 matching lines...) Expand all
70 SkPDFUnion(SkPDFUnion&& other); 68 SkPDFUnion(SkPDFUnion&& other);
71 SkPDFUnion& operator=(SkPDFUnion&& other); 69 SkPDFUnion& operator=(SkPDFUnion&& other);
72 70
73 ~SkPDFUnion(); 71 ~SkPDFUnion();
74 72
75 /** The following nine functions are the standard way of creating 73 /** The following nine functions are the standard way of creating
76 SkPDFUnion objects. */ 74 SkPDFUnion objects. */
77 75
78 static SkPDFUnion Int(int32_t); 76 static SkPDFUnion Int(int32_t);
79 77
80 static SkPDFUnion Int(size_t); 78 static SkPDFUnion Int(size_t v) { return SkPDFUnion::Int(SkToS32(v)); }
81 79
82 static SkPDFUnion Bool(bool); 80 static SkPDFUnion Bool(bool);
83 81
84 static SkPDFUnion Scalar(SkScalar); 82 static SkPDFUnion Scalar(SkScalar);
85 83
86 /** These two functions do NOT take ownership of ptr, and do NOT 84 /** These two functions do NOT take ownership of ptr, and do NOT
87 copy the string. Suitable for passing in static const 85 copy the string. Suitable for passing in static const
88 strings. For example: 86 strings. For example:
89 SkPDFUnion n = SkPDFUnion::Name("Length"); 87 SkPDFUnion n = SkPDFUnion::Name("Length");
90 SkPDFUnion u = SkPDFUnion::String("Identity"); */ 88 SkPDFUnion u = SkPDFUnion::String("Identity"); */
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 #endif // 0 179 #endif // 0
182 180
183 //////////////////////////////////////////////////////////////////////////////// 181 ////////////////////////////////////////////////////////////////////////////////
184 182
185 /** \class SkPDFArray 183 /** \class SkPDFArray
186 184
187 An array object in a PDF. 185 An array object in a PDF.
188 */ 186 */
189 class SkPDFArray : public SkPDFObject { 187 class SkPDFArray : public SkPDFObject {
190 public: 188 public:
191
192
193 static const int kMaxLen = 8191; 189 static const int kMaxLen = 8191;
194 190
195 /** Create a PDF array. Maximum length is 8191. 191 /** Create a PDF array. Maximum length is 8191.
196 */ 192 */
197 SkPDFArray(); 193 SkPDFArray();
198 virtual ~SkPDFArray(); 194 virtual ~SkPDFArray();
199 195
200 // The SkPDFObject interface. 196 // The SkPDFObject interface.
201 void emitObject(SkWStream* stream, 197 void emitObject(SkWStream* stream,
202 const SkPDFObjNumMap& objNumMap, 198 const SkPDFObjNumMap& objNumMap,
(...skipping 29 matching lines...) Expand all
232 void append(SkPDFUnion&& value); 228 void append(SkPDFUnion&& value);
233 typedef SkPDFObject INHERITED; 229 typedef SkPDFObject INHERITED;
234 }; 230 };
235 231
236 /** \class SkPDFDict 232 /** \class SkPDFDict
237 233
238 A dictionary object in a PDF. 234 A dictionary object in a PDF.
239 */ 235 */
240 class SkPDFDict : public SkPDFObject { 236 class SkPDFDict : public SkPDFObject {
241 public: 237 public:
242
243
244 /** Create a PDF dictionary. Maximum number of entries is 4095. 238 /** Create a PDF dictionary. Maximum number of entries is 4095.
245 */ 239 */
246 SkPDFDict(); 240 SkPDFDict();
247 241
248 /** Create a PDF dictionary with a Type entry. 242 /** Create a PDF dictionary with a Type entry.
249 * @param type The value of the Type entry. 243 * @param type The value of the Type entry.
250 */ 244 */
251 explicit SkPDFDict(const char type[]); 245 explicit SkPDFDict(const char type[]);
252 246
253 virtual ~SkPDFDict(); 247 virtual ~SkPDFDict();
(...skipping 29 matching lines...) Expand all
283 void insertScalar(const char key[], SkScalar value); 277 void insertScalar(const char key[], SkScalar value);
284 void insertName(const char key[], const char nameValue[]); 278 void insertName(const char key[], const char nameValue[]);
285 void insertName(const char key[], const SkString& nameValue); 279 void insertName(const char key[], const SkString& nameValue);
286 void insertString(const char key[], const char value[]); 280 void insertString(const char key[], const char value[]);
287 void insertString(const char key[], const SkString& value); 281 void insertString(const char key[], const SkString& value);
288 282
289 /** Remove all entries from the dictionary. 283 /** Remove all entries from the dictionary.
290 */ 284 */
291 void clear(); 285 void clear();
292 286
287 /** Emit the dictionary, without the "<<" and ">>".
288 */
289 void emitAll(SkWStream* stream,
290 const SkPDFObjNumMap& objNumMap,
291 const SkPDFSubstituteMap& substitutes) const;
292
293 private: 293 private:
294 struct Record { 294 struct Record {
295 SkPDFUnion fKey; 295 SkPDFUnion fKey;
296 SkPDFUnion fValue; 296 SkPDFUnion fValue;
297 }; 297 };
298 SkTDArray<Record> fRecords; 298 SkTDArray<Record> fRecords;
299 static const int kMaxLen = 4095; 299 static const int kMaxLen = 4095;
300 300
301 void set(SkPDFUnion&& name, SkPDFUnion&& value); 301 void set(SkPDFUnion&& name, SkPDFUnion&& value);
302 302
303 typedef SkPDFObject INHERITED; 303 typedef SkPDFObject INHERITED;
304 }; 304 };
305 305
306 /** \class SkPDFSharedStream
307
308 This class takes an asset and assumes that it is backed by
309 long-lived shared data (for example, an open file
310 descriptor). That is: no memory savings can be made by holding on
311 to a compressed version instead.
312 */
313 class SkPDFSharedStream : public SkPDFObject {
314 public:
315 // Takes ownership of asset.
316 SkPDFSharedStream(SkStreamAsset* data)
317 : fAsset(data), fDict(SkNEW(SkPDFDict)) {
318 SkASSERT(data);
319 }
320 SkPDFDict* dict() { return fDict; }
321 void emitObject(SkWStream*,
322 const SkPDFObjNumMap&,
323 const SkPDFSubstituteMap&) const override;
324 void addResources(SkPDFObjNumMap*,
325 const SkPDFSubstituteMap&) const override;
326
327 private:
328 SkAutoTDelete<SkStreamAsset> fAsset;
329 SkAutoTUnref<SkPDFDict> fDict;
330 typedef SkPDFObject INHERITED;
331 };
332
306 //////////////////////////////////////////////////////////////////////////////// 333 ////////////////////////////////////////////////////////////////////////////////
307 334
308 /** \class SkPDFObjNumMap 335 /** \class SkPDFObjNumMap
309 336
310 The PDF Object Number Map manages object numbers. It is used to 337 The PDF Object Number Map manages object numbers. It is used to
311 create the PDF cross reference table. 338 create the PDF cross reference table.
312 */ 339 */
313 class SkPDFObjNumMap : SkNoncopyable { 340 class SkPDFObjNumMap : SkNoncopyable {
314 public: 341 public:
315 /** Add the passed object to the catalog. 342 /** Add the passed object to the catalog.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 379
353 SkPDFObject* operator()(SkPDFObject* o) const { 380 SkPDFObject* operator()(SkPDFObject* o) const {
354 return this->getSubstitute(o); 381 return this->getSubstitute(o);
355 } 382 }
356 383
357 private: 384 private:
358 SkTHashMap<SkPDFObject*, SkPDFObject*> fSubstituteMap; 385 SkTHashMap<SkPDFObject*, SkPDFObject*> fSubstituteMap;
359 }; 386 };
360 387
361 #endif 388 #endif
OLDNEW
« no previous file with comments | « src/pdf/SkPDFStream.cpp ('k') | src/pdf/SkPDFTypes.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698