OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
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 #ifndef SkPictureData_DEFINED | 8 #ifndef SkPictureData_DEFINED |
9 #define SkPictureData_DEFINED | 9 #define SkPictureData_DEFINED |
10 | 10 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 // Always write this guy last (with no length field afterwards) | 58 // Always write this guy last (with no length field afterwards) |
59 #define SK_PICT_EOF_TAG SkSetFourByteTag('e', 'o', 'f', ' ') | 59 #define SK_PICT_EOF_TAG SkSetFourByteTag('e', 'o', 'f', ' ') |
60 | 60 |
61 class SkPictureData { | 61 class SkPictureData { |
62 public: | 62 public: |
63 SkPictureData(const SkPictureRecord& record, const SkPictInfo&); | 63 SkPictureData(const SkPictureRecord& record, const SkPictInfo&); |
64 // Does not affect ownership of SkStream. | 64 // Does not affect ownership of SkStream. |
65 static SkPictureData* CreateFromStream(SkStream*, | 65 static SkPictureData* CreateFromStream(SkStream*, |
66 const SkPictInfo&, | 66 const SkPictInfo&, |
67 SkPicture::InstallPixelRefProc, | 67 SkImageDeserializer*, |
68 SkTypefacePlayback*); | 68 SkTypefacePlayback*); |
69 static SkPictureData* CreateFromBuffer(SkReadBuffer&, const SkPictInfo&); | 69 static SkPictureData* CreateFromBuffer(SkReadBuffer&, const SkPictInfo&); |
70 | 70 |
71 virtual ~SkPictureData(); | 71 virtual ~SkPictureData(); |
72 | 72 |
73 void serialize(SkWStream*, SkPixelSerializer*, SkRefCntSet*) const; | 73 void serialize(SkWStream*, SkPixelSerializer*, SkRefCntSet*) const; |
74 void flatten(SkWriteBuffer&) const; | 74 void flatten(SkWriteBuffer&) const; |
75 | 75 |
76 bool containsBitmaps() const; | 76 bool containsBitmaps() const; |
77 | 77 |
78 bool hasText() const { return fContentInfo.hasText(); } | 78 bool hasText() const { return fContentInfo.hasText(); } |
79 | 79 |
80 int opCount() const { return fContentInfo.numOperations(); } | 80 int opCount() const { return fContentInfo.numOperations(); } |
81 | 81 |
82 const sk_sp<SkData>& opData() const { return fOpData; } | 82 const sk_sp<SkData>& opData() const { return fOpData; } |
83 | 83 |
84 protected: | 84 protected: |
85 explicit SkPictureData(const SkPictInfo& info); | 85 explicit SkPictureData(const SkPictInfo& info); |
86 | 86 |
87 // Does not affect ownership of SkStream. | 87 // Does not affect ownership of SkStream. |
88 bool parseStream(SkStream*, SkPicture::InstallPixelRefProc, SkTypefacePlayba
ck*); | 88 bool parseStream(SkStream*, SkImageDeserializer*, SkTypefacePlayback*); |
89 bool parseBuffer(SkReadBuffer& buffer); | 89 bool parseBuffer(SkReadBuffer& buffer); |
90 | 90 |
91 public: | 91 public: |
92 const SkBitmap& getBitmap(SkReadBuffer* reader) const { | 92 const SkImage* getBitmapAsImage(SkReadBuffer* reader) const { |
93 const int index = reader->readInt(); | 93 const int index = reader->readInt(); |
94 return reader->validateIndex(index, fBitmaps.count()) ? fBitmaps[index]
: fEmptyBitmap; | 94 return reader->validateIndex(index, fBitmapImageCount) ? fBitmapImageRef
s[index] : nullptr; |
95 } | 95 } |
96 | 96 |
97 const SkImage* getImage(SkReadBuffer* reader) const { | 97 const SkImage* getImage(SkReadBuffer* reader) const { |
98 const int index = reader->readInt(); | 98 const int index = reader->readInt(); |
99 return reader->validateIndex(index, fImageCount) ? fImageRefs[index] : n
ullptr; | 99 return reader->validateIndex(index, fImageCount) ? fImageRefs[index] : n
ullptr; |
100 } | 100 } |
101 | 101 |
102 const SkPath& getPath(SkReadBuffer* reader) const { | 102 const SkPath& getPath(SkReadBuffer* reader) const { |
103 const int index = reader->readInt() - 1; | 103 const int index = reader->readInt() - 1; |
104 return reader->validateIndex(index, fPaths.count()) ? fPaths[index] : fE
mptyPath; | 104 return reader->validateIndex(index, fPaths.count()) ? fPaths[index] : fE
mptyPath; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 142 |
143 bool suitableForLayerOptimization() const; | 143 bool suitableForLayerOptimization() const; |
144 #endif | 144 #endif |
145 | 145 |
146 private: | 146 private: |
147 void init(); | 147 void init(); |
148 | 148 |
149 // these help us with reading/writing | 149 // these help us with reading/writing |
150 // Does not affect ownership of SkStream. | 150 // Does not affect ownership of SkStream. |
151 bool parseStreamTag(SkStream*, uint32_t tag, uint32_t size, | 151 bool parseStreamTag(SkStream*, uint32_t tag, uint32_t size, |
152 SkPicture::InstallPixelRefProc, SkTypefacePlayback*); | 152 SkImageDeserializer*, SkTypefacePlayback*); |
153 bool parseBufferTag(SkReadBuffer&, uint32_t tag, uint32_t size); | 153 bool parseBufferTag(SkReadBuffer&, uint32_t tag, uint32_t size); |
154 void flattenToBuffer(SkWriteBuffer&) const; | 154 void flattenToBuffer(SkWriteBuffer&) const; |
155 | 155 |
156 SkTArray<SkBitmap> fBitmaps; | |
157 SkTArray<SkPaint> fPaints; | 156 SkTArray<SkPaint> fPaints; |
158 SkTArray<SkPath> fPaths; | 157 SkTArray<SkPath> fPaths; |
159 | 158 |
160 sk_sp<SkData> fOpData; // opcodes and parameters | 159 sk_sp<SkData> fOpData; // opcodes and parameters |
161 | 160 |
162 const SkPath fEmptyPath; | 161 const SkPath fEmptyPath; |
163 const SkBitmap fEmptyBitmap; | 162 const SkBitmap fEmptyBitmap; |
164 | 163 |
165 const SkPicture** fPictureRefs; | 164 const SkPicture** fPictureRefs; |
166 int fPictureCount; | 165 int fPictureCount; |
167 SkDrawable** fDrawableRefs; | 166 SkDrawable** fDrawableRefs; |
168 int fDrawableCount; | 167 int fDrawableCount; |
169 const SkTextBlob** fTextBlobRefs; | 168 const SkTextBlob** fTextBlobRefs; |
170 int fTextBlobCount; | 169 int fTextBlobCount; |
171 const SkImage** fImageRefs; | 170 const SkImage** fImageRefs; |
172 int fImageCount; | 171 int fImageCount; |
| 172 const SkImage** fBitmapImageRefs; |
| 173 int fBitmapImageCount; |
173 | 174 |
174 SkPictureContentInfo fContentInfo; | 175 SkPictureContentInfo fContentInfo; |
175 | 176 |
176 SkTypefacePlayback fTFPlayback; | 177 SkTypefacePlayback fTFPlayback; |
177 SkFactoryPlayback* fFactoryPlayback; | 178 SkFactoryPlayback* fFactoryPlayback; |
178 | 179 |
179 const SkPictInfo fInfo; | 180 const SkPictInfo fInfo; |
180 | 181 |
181 static void WriteFactories(SkWStream* stream, const SkFactorySet& rec); | 182 static void WriteFactories(SkWStream* stream, const SkFactorySet& rec); |
182 static void WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec); | 183 static void WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec); |
183 | 184 |
184 void initForPlayback() const; | 185 void initForPlayback() const; |
185 }; | 186 }; |
186 | 187 |
187 #endif | 188 #endif |
OLD | NEW |