blob: f908fbf2f3200dbf1ecb0d3b5d9d65fd72f2db49 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2010 Google Inc.
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000010#ifndef SkPDFStream_DEFINED
11#define SkPDFStream_DEFINED
12
13#include "SkPDFTypes.h"
14#include "SkRefCnt.h"
vandebo@chromium.orga09ef972010-12-01 22:17:20 +000015#include "SkStream.h"
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000016#include "SkTemplates.h"
17
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000018class SkPDFCatalog;
19
20/** \class SkPDFStream
21
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000022 A stream object in a PDF. Note, all streams must be indirect objects (via
23 SkObjRef).
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000024*/
vandebo@chromium.orgd90c1412011-02-24 21:50:04 +000025class SkPDFStream : public SkPDFDict {
commit-bot@chromium.orgab1c1382013-12-05 12:08:12 +000026 SK_DECLARE_INST_COUNT(SkPDFStream)
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000027public:
28 /** Create a PDF stream. A Length entry is automatically added to the
halcanarye3224822014-07-14 09:12:12 -070029 * stream dictionary.
30 * @param data The data part of the stream. Will be ref()ed.
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000031 */
vandebo@chromium.org421d6442011-07-20 17:39:01 +000032 explicit SkPDFStream(SkData* data);
halcanarye3224822014-07-14 09:12:12 -070033
34 /** Create a PDF stream. A Length entry is automatically added to the
35 * stream dictionary.
36 * @param stream The data part of the stream. Will be duplicate()d.
37 */
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000038 explicit SkPDFStream(SkStream* stream);
halcanary1f8ed022014-06-27 10:37:27 -070039
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000040 virtual ~SkPDFStream();
41
halcanary67ec1f82014-06-27 11:36:20 -070042 // The SkPDFObject interface. These two methods use a mutex to
43 // allow multiple threads to call at the same time.
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000044 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
45 bool indirect);
46 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
47
vandebo@chromium.org421d6442011-07-20 17:39:01 +000048protected:
vandebo@chromium.org421d6442011-07-20 17:39:01 +000049 enum State {
50 kUnused_State, //!< The stream hasn't been requested yet.
51 kNoCompression_State, //!< The stream's been requested in an
52 // uncompressed form.
53 kCompressed_State, //!< The stream's already been compressed.
54 };
edisonn@google.comd9dfa182013-04-24 13:01:01 +000055
halcanary1f8ed022014-06-27 10:37:27 -070056 /** Create a PDF stream with the same content and dictionary entries
57 * as the passed one.
58 */
59 explicit SkPDFStream(const SkPDFStream& pdfStream);
60
edisonn@google.comd9dfa182013-04-24 13:01:01 +000061 /* Create a PDF stream with no data. The setData method must be called to
62 * set the data.
63 */
64 SkPDFStream();
65
66 // Populate the stream dictionary. This method returns false if
67 // fSubstitute should be used.
68 virtual bool populate(SkPDFCatalog* catalog);
69
70 void setSubstitute(SkPDFStream* stream) {
71 fSubstitute.reset(stream);
72 }
73
halcanary67ec1f82014-06-27 11:36:20 -070074 SkPDFStream* getSubstitute() const {
edisonn@google.comd9dfa182013-04-24 13:01:01 +000075 return fSubstitute.get();
76 }
77
commit-bot@chromium.orgd8d976e2013-07-08 23:17:57 +000078 void setData(SkData* data);
edisonn@google.comd9dfa182013-04-24 13:01:01 +000079 void setData(SkStream* stream);
80
halcanary67ec1f82014-06-27 11:36:20 -070081 size_t dataSize() const;
82
edisonn@google.comd9dfa182013-04-24 13:01:01 +000083 void setState(State state) {
84 fState = state;
85 }
86
halcanary67ec1f82014-06-27 11:36:20 -070087 State getState() const {
edisonn@google.comd9dfa182013-04-24 13:01:01 +000088 return fState;
89 }
90
91private:
vandebo@chromium.org421d6442011-07-20 17:39:01 +000092 // Indicates what form (or if) the stream has been requested.
93 State fState;
skia.committer@gmail.com83f0d302013-04-25 07:01:04 +000094
halcanarye3224822014-07-14 09:12:12 -070095 // Mutex guards fState, fDataStream, and fSubstitute in public interface.
halcanary67ec1f82014-06-27 11:36:20 -070096 SkMutex fMutex;
97
halcanarye3224822014-07-14 09:12:12 -070098 SkMemoryStream fMemoryStream; // Used by fDataStream when
99 // fDataStream needs to be backed
100 // by SkData.
101 SkAutoTUnref<SkStreamRewindable> fDataStream;
vandebo@chromium.orgd96d17b2013-01-04 19:31:24 +0000102 SkAutoTUnref<SkPDFStream> fSubstitute;
vandebo@chromium.orgd90c1412011-02-24 21:50:04 +0000103
104 typedef SkPDFDict INHERITED;
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +0000105};
106
107#endif