blob: 7f33c162aac1448c9781adf89b1a735a02622ee7 [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.
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 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
46
vandebo@chromium.org421d6442011-07-20 17:39:01 +000047protected:
vandebo@chromium.org421d6442011-07-20 17:39:01 +000048 enum State {
49 kUnused_State, //!< The stream hasn't been requested yet.
50 kNoCompression_State, //!< The stream's been requested in an
51 // uncompressed form.
52 kCompressed_State, //!< The stream's already been compressed.
53 };
edisonn@google.comd9dfa182013-04-24 13:01:01 +000054
halcanary1f8ed022014-06-27 10:37:27 -070055 /** Create a PDF stream with the same content and dictionary entries
56 * as the passed one.
57 */
58 explicit SkPDFStream(const SkPDFStream& pdfStream);
59
edisonn@google.comd9dfa182013-04-24 13:01:01 +000060 /* Create a PDF stream with no data. The setData method must be called to
61 * set the data.
62 */
63 SkPDFStream();
64
65 // Populate the stream dictionary. This method returns false if
66 // fSubstitute should be used.
67 virtual bool populate(SkPDFCatalog* catalog);
68
69 void setSubstitute(SkPDFStream* stream) {
70 fSubstitute.reset(stream);
71 }
72
halcanary67ec1f82014-06-27 11:36:20 -070073 SkPDFStream* getSubstitute() const {
edisonn@google.comd9dfa182013-04-24 13:01:01 +000074 return fSubstitute.get();
75 }
76
commit-bot@chromium.orgd8d976e2013-07-08 23:17:57 +000077 void setData(SkData* data);
edisonn@google.comd9dfa182013-04-24 13:01:01 +000078 void setData(SkStream* stream);
79
halcanary67ec1f82014-06-27 11:36:20 -070080 size_t dataSize() const;
81
edisonn@google.comd9dfa182013-04-24 13:01:01 +000082 void setState(State state) {
83 fState = state;
84 }
85
halcanary67ec1f82014-06-27 11:36:20 -070086 State getState() const {
edisonn@google.comd9dfa182013-04-24 13:01:01 +000087 return fState;
88 }
89
90private:
vandebo@chromium.org421d6442011-07-20 17:39:01 +000091 // Indicates what form (or if) the stream has been requested.
92 State fState;
skia.committer@gmail.com83f0d302013-04-25 07:01:04 +000093
halcanarye3224822014-07-14 09:12:12 -070094 // Mutex guards fState, fDataStream, and fSubstitute in public interface.
halcanary67ec1f82014-06-27 11:36:20 -070095 SkMutex fMutex;
96
halcanarye3224822014-07-14 09:12:12 -070097 SkMemoryStream fMemoryStream; // Used by fDataStream when
98 // fDataStream needs to be backed
99 // by SkData.
100 SkAutoTUnref<SkStreamRewindable> fDataStream;
vandebo@chromium.orgd96d17b2013-01-04 19:31:24 +0000101 SkAutoTUnref<SkPDFStream> fSubstitute;
vandebo@chromium.orgd90c1412011-02-24 21:50:04 +0000102
103 typedef SkPDFDict INHERITED;
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +0000104};
105
106#endif