OLD | NEW |
---|---|
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 "SkTHash.h" | 14 #include "SkTHash.h" |
15 #include "SkTypes.h" | 15 #include "SkTypes.h" |
16 | 16 |
17 class SkData; | |
17 class SkPDFObjNumMap; | 18 class SkPDFObjNumMap; |
18 class SkPDFObject; | 19 class SkPDFObject; |
19 class SkPDFSubstituteMap; | 20 class SkPDFSubstituteMap; |
20 class SkStreamAsset; | 21 class SkStreamAsset; |
21 class SkString; | 22 class SkString; |
22 class SkWStream; | 23 class SkWStream; |
23 | 24 |
24 #ifdef SK_PDF_IMAGE_STATS | 25 #ifdef SK_PDF_IMAGE_STATS |
25 #include "SkAtomics.h" | 26 #include "SkAtomics.h" |
26 #endif | 27 #endif |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 | 301 |
301 /** \class SkPDFSharedStream | 302 /** \class SkPDFSharedStream |
302 | 303 |
303 This class takes an asset and assumes that it is backed by | 304 This class takes an asset and assumes that it is backed by |
304 long-lived shared data (for example, an open file | 305 long-lived shared data (for example, an open file |
305 descriptor). That is: no memory savings can be made by holding on | 306 descriptor). That is: no memory savings can be made by holding on |
306 to a compressed version instead. | 307 to a compressed version instead. |
307 */ | 308 */ |
308 class SkPDFSharedStream final : public SkPDFObject { | 309 class SkPDFSharedStream final : public SkPDFObject { |
309 public: | 310 public: |
310 // Takes ownership of asset. | 311 SkPDFSharedStream(std::unique_ptr<SkStreamAsset> data); |
311 SkPDFSharedStream(SkStreamAsset* data); | |
312 ~SkPDFSharedStream(); | 312 ~SkPDFSharedStream(); |
313 SkPDFDict* dict() { return fDict.get(); } | 313 SkPDFDict* dict() { return &fDict; } |
314 void emitObject(SkWStream*, | 314 void emitObject(SkWStream*, |
315 const SkPDFObjNumMap&, | 315 const SkPDFObjNumMap&, |
316 const SkPDFSubstituteMap&) const override; | 316 const SkPDFSubstituteMap&) const override; |
317 void addResources(SkPDFObjNumMap*, | 317 void addResources(SkPDFObjNumMap*, |
318 const SkPDFSubstituteMap&) const override; | 318 const SkPDFSubstituteMap&) const override; |
319 void drop() override; | 319 void drop() override; |
320 | 320 |
321 private: | 321 private: |
322 std::unique_ptr<SkStreamAsset> fAsset; | 322 std::unique_ptr<SkStreamAsset> fAsset; |
323 sk_sp<SkPDFDict> fDict; | 323 SkPDFDict fDict; |
324 SkDEBUGCODE(bool fDumped;) | |
325 typedef SkPDFObject INHERITED; | 324 typedef SkPDFObject INHERITED; |
326 }; | 325 }; |
327 | 326 |
327 /** \class SkPDFSharedStream | |
tomhudson
2016/07/29 16:06:05
name in comment doesn't match name of class?
hal.canary
2016/07/29 16:31:29
Done.
| |
328 | |
329 This class takes an asset and assumes that it is the only owner of | |
330 the asset's data. It immediately compresses the asset to save | |
331 memory. | |
332 */ | |
333 | |
334 class SkPDFStream : public SkPDFObject { | |
335 | |
336 public: | |
337 /** Create a PDF stream. A Length entry is automatically added to the | |
338 * stream dictionary. | |
339 * @param data The data part of the stream. | |
340 * @param stream The data part of the stream. */ | |
341 explicit SkPDFStream(sk_sp<SkData> data); | |
342 explicit SkPDFStream(std::unique_ptr<SkStreamAsset> stream); | |
343 virtual ~SkPDFStream(); | |
344 | |
345 SkPDFDict* dict() { return &fDict; } | |
346 | |
347 // The SkPDFObject interface. | |
348 void emitObject(SkWStream* stream, | |
349 const SkPDFObjNumMap& objNumMap, | |
350 const SkPDFSubstituteMap& substitutes) const override; | |
351 void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const final; | |
352 void drop() override; | |
353 | |
354 protected: | |
355 /* Create a PDF stream with no data. The setData method must be called to | |
356 * set the data. */ | |
357 SkPDFStream(); | |
358 | |
359 /** Only call this function once. */ | |
360 void setData(std::unique_ptr<SkStreamAsset> stream); | |
361 | |
362 private: | |
363 std::unique_ptr<SkStreamAsset> fCompressedData; | |
364 SkPDFDict fDict; | |
365 | |
366 typedef SkPDFDict INHERITED; | |
367 }; | |
368 | |
328 //////////////////////////////////////////////////////////////////////////////// | 369 //////////////////////////////////////////////////////////////////////////////// |
329 | 370 |
330 /** \class SkPDFObjNumMap | 371 /** \class SkPDFObjNumMap |
331 | 372 |
332 The PDF Object Number Map manages object numbers. It is used to | 373 The PDF Object Number Map manages object numbers. It is used to |
333 create the PDF cross reference table. | 374 create the PDF cross reference table. |
334 */ | 375 */ |
335 class SkPDFObjNumMap : SkNoncopyable { | 376 class SkPDFObjNumMap : SkNoncopyable { |
336 public: | 377 public: |
337 /** Add the passed object to the catalog. | 378 /** Add the passed object to the catalog. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 }; | 428 }; |
388 | 429 |
389 #ifdef SK_PDF_IMAGE_STATS | 430 #ifdef SK_PDF_IMAGE_STATS |
390 extern SkAtomic<int> gDrawImageCalls; | 431 extern SkAtomic<int> gDrawImageCalls; |
391 extern SkAtomic<int> gJpegImageObjects; | 432 extern SkAtomic<int> gJpegImageObjects; |
392 extern SkAtomic<int> gRegularImageObjects; | 433 extern SkAtomic<int> gRegularImageObjects; |
393 extern void SkPDFImageDumpStats(); | 434 extern void SkPDFImageDumpStats(); |
394 #endif // SK_PDF_IMAGE_STATS | 435 #endif // SK_PDF_IMAGE_STATS |
395 | 436 |
396 #endif | 437 #endif |
OLD | NEW |