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 SkReadBuffer_DEFINED | 8 #ifndef SkReadBuffer_DEFINED |
9 #define SkReadBuffer_DEFINED | 9 #define SkReadBuffer_DEFINED |
10 | 10 |
11 #include "SkBitmapHeap.h" | 11 #include "SkBitmapHeap.h" |
12 #include "SkColorFilter.h" | 12 #include "SkColorFilter.h" |
13 #include "SkData.h" | 13 #include "SkData.h" |
14 #include "SkDrawLooper.h" | 14 #include "SkDrawLooper.h" |
15 #include "SkImageFilter.h" | 15 #include "SkImageFilter.h" |
16 #include "SkMaskFilter.h" | 16 #include "SkMaskFilter.h" |
17 #include "SkPath.h" | 17 #include "SkPath.h" |
18 #include "SkPathEffect.h" | 18 #include "SkPathEffect.h" |
19 #include "SkPicture.h" | 19 #include "SkPicture.h" |
20 #include "SkRasterizer.h" | 20 #include "SkRasterizer.h" |
21 #include "SkReadBuffer.h" | 21 #include "SkReadBuffer.h" |
22 #include "SkReader32.h" | 22 #include "SkReader32.h" |
23 #include "SkRefCnt.h" | 23 #include "SkRefCnt.h" |
24 #include "SkShader.h" | 24 #include "SkShader.h" |
| 25 #include "SkTHash.h" |
25 #include "SkWriteBuffer.h" | 26 #include "SkWriteBuffer.h" |
26 #include "SkXfermode.h" | 27 #include "SkXfermode.h" |
27 | 28 |
28 class SkBitmap; | 29 class SkBitmap; |
29 class SkImage; | 30 class SkImage; |
30 | 31 |
31 #if defined(SK_DEBUG) && defined(SK_BUILD_FOR_MAC) | 32 #if defined(SK_DEBUG) && defined(SK_BUILD_FOR_MAC) |
32 #define DEBUG_NON_DETERMINISTIC_ASSERT | 33 #define DEBUG_NON_DETERMINISTIC_ASSERT |
33 #endif | 34 #endif |
34 | 35 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 /** | 196 /** |
196 * Call this with a pre-loaded array of Factories, in the same order as | 197 * Call this with a pre-loaded array of Factories, in the same order as |
197 * were created/written by the writer. SkPicture uses this. | 198 * were created/written by the writer. SkPicture uses this. |
198 */ | 199 */ |
199 void setFactoryPlayback(SkFlattenable::Factory array[], int count) { | 200 void setFactoryPlayback(SkFlattenable::Factory array[], int count) { |
200 fFactoryArray = array; | 201 fFactoryArray = array; |
201 fFactoryCount = count; | 202 fFactoryCount = count; |
202 } | 203 } |
203 | 204 |
204 /** | 205 /** |
| 206 * For an input flattenable (specified by name), set custom factory proc |
| 207 * to use when unflattening. |
| 208 */ |
| 209 void setCustomFactory(const char* name, SkFlattenable::Factory factory) { |
| 210 SkFlattenable::Factory defaultFactory = SkFlattenable::NameToFactory(nam
e); |
| 211 fCustomFactory->set(defaultFactory, factory); |
| 212 } |
| 213 |
| 214 /** |
205 * Provide a function to decode an SkBitmap from encoded data. Only used if
the writer | 215 * Provide a function to decode an SkBitmap from encoded data. Only used if
the writer |
206 * encoded the SkBitmap. If the proper decoder cannot be used, a red bitmap
with the | 216 * encoded the SkBitmap. If the proper decoder cannot be used, a red bitmap
with the |
207 * appropriate size will be used. | 217 * appropriate size will be used. |
208 */ | 218 */ |
209 void setBitmapDecoder(SkPicture::InstallPixelRefProc bitmapDecoder) { | 219 void setBitmapDecoder(SkPicture::InstallPixelRefProc bitmapDecoder) { |
210 fBitmapDecoder = bitmapDecoder; | 220 fBitmapDecoder = bitmapDecoder; |
211 } | 221 } |
212 | 222 |
213 // Default impelementations don't check anything. | 223 // Default impelementations don't check anything. |
214 virtual bool validate(bool isValid) { return true; } | 224 virtual bool validate(bool isValid) { return true; } |
215 virtual bool isValid() const { return true; } | 225 virtual bool isValid() const { return true; } |
216 virtual bool validateAvailable(size_t size) { return true; } | 226 virtual bool validateAvailable(size_t size) { return true; } |
217 | 227 |
218 protected: | 228 protected: |
219 SkReader32 fReader; | 229 SkReader32 fReader; |
220 | 230 |
| 231 /** |
| 232 * Checks if a custom factory has been set for a given flattenable. |
| 233 * Returns the custom factory if it exists, or nullptr otherwise. |
| 234 */ |
| 235 SkFlattenable::Factory* getCustomFactory(SkFlattenable::Factory factory) { |
| 236 return fCustomFactory->find(factory); |
| 237 } |
| 238 |
221 private: | 239 private: |
222 bool readArray(void* value, size_t size, size_t elementSize); | 240 bool readArray(void* value, size_t size, size_t elementSize); |
223 | 241 |
224 uint32_t fFlags; | 242 uint32_t fFlags; |
225 int fVersion; | 243 int fVersion; |
226 | 244 |
227 void* fMemoryPtr; | 245 void* fMemoryPtr; |
228 | 246 |
229 SkBitmapHeapReader* fBitmapStorage; | 247 SkBitmapHeapReader* fBitmapStorage; |
230 SkTypeface** fTFArray; | 248 SkTypeface** fTFArray; |
231 int fTFCount; | 249 int fTFCount; |
232 | 250 |
233 SkFlattenable::Factory* fFactoryArray; | 251 SkFlattenable::Factory* fFactoryArray; |
234 int fFactoryCount; | 252 int fFactoryCount; |
235 | 253 |
| 254 // Maps the default Factory to any custom Factory that was specified for |
| 255 // this SkReadBuffer. |
| 256 SkAutoTDelete<SkTHashMap<SkFlattenable::Factory, SkFlattenable::Factory>> fC
ustomFactory; |
| 257 |
236 SkPicture::InstallPixelRefProc fBitmapDecoder; | 258 SkPicture::InstallPixelRefProc fBitmapDecoder; |
237 | 259 |
238 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT | 260 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
239 // Debugging counter to keep track of how many bitmaps we | 261 // Debugging counter to keep track of how many bitmaps we |
240 // have decoded. | 262 // have decoded. |
241 int fDecodedBitmapIndex; | 263 int fDecodedBitmapIndex; |
242 #endif // DEBUG_NON_DETERMINISTIC_ASSERT | 264 #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
243 }; | 265 }; |
244 | 266 |
245 #endif // SkReadBuffer_DEFINED | 267 #endif // SkReadBuffer_DEFINED |
OLD | NEW |