blob: cf9316ff1446d7af0288e844a6452fe68c90d3d5 [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
halcanaryf361b712015-01-13 07:12:57 -080042 // The SkPDFObject interface. This two method uses a mutex to
halcanary67ec1f82014-06-27 11:36:20 -070043 // allow multiple threads to call at the same time.
halcanary4fc48af2015-01-12 10:07:50 -080044 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRIDE;
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000045
vandebo@chromium.org421d6442011-07-20 17:39:01 +000046protected:
vandebo@chromium.org421d6442011-07-20 17:39:01 +000047 enum State {
48 kUnused_State, //!< The stream hasn't been requested yet.
49 kNoCompression_State, //!< The stream's been requested in an
50 // uncompressed form.
51 kCompressed_State, //!< The stream's already been compressed.
52 };
edisonn@google.comd9dfa182013-04-24 13:01:01 +000053
halcanary1f8ed022014-06-27 10:37:27 -070054 /** Create a PDF stream with the same content and dictionary entries
55 * as the passed one.
56 */
57 explicit SkPDFStream(const SkPDFStream& pdfStream);
58
edisonn@google.comd9dfa182013-04-24 13:01:01 +000059 /* Create a PDF stream with no data. The setData method must be called to
60 * set the data.
61 */
62 SkPDFStream();
63
64 // Populate the stream dictionary. This method returns false if
65 // fSubstitute should be used.
66 virtual bool populate(SkPDFCatalog* catalog);
67
68 void setSubstitute(SkPDFStream* stream) {
69 fSubstitute.reset(stream);
70 }
71
halcanary67ec1f82014-06-27 11:36:20 -070072 SkPDFStream* getSubstitute() const {
edisonn@google.comd9dfa182013-04-24 13:01:01 +000073 return fSubstitute.get();
74 }
75
commit-bot@chromium.orgd8d976e2013-07-08 23:17:57 +000076 void setData(SkData* data);
edisonn@google.comd9dfa182013-04-24 13:01:01 +000077 void setData(SkStream* stream);
78
halcanary67ec1f82014-06-27 11:36:20 -070079 size_t dataSize() const;
80
edisonn@google.comd9dfa182013-04-24 13:01:01 +000081 void setState(State state) {
82 fState = state;
83 }
84
halcanary67ec1f82014-06-27 11:36:20 -070085 State getState() const {
edisonn@google.comd9dfa182013-04-24 13:01:01 +000086 return fState;
87 }
88
89private:
vandebo@chromium.org421d6442011-07-20 17:39:01 +000090 // Indicates what form (or if) the stream has been requested.
91 State fState;
skia.committer@gmail.com83f0d302013-04-25 07:01:04 +000092
halcanarye3224822014-07-14 09:12:12 -070093 // Mutex guards fState, fDataStream, and fSubstitute in public interface.
halcanary67ec1f82014-06-27 11:36:20 -070094 SkMutex fMutex;
95
scroggoa1193e42015-01-21 12:09:53 -080096 SkAutoTDelete<SkStreamRewindable> fDataStream;
vandebo@chromium.orgd96d17b2013-01-04 19:31:24 +000097 SkAutoTUnref<SkPDFStream> fSubstitute;
vandebo@chromium.orgd90c1412011-02-24 21:50:04 +000098
99 typedef SkPDFDict INHERITED;
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +0000100};
101
102#endif