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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 void* readFunctionPtr() { return fReader.readPtr(); } | 105 void* readFunctionPtr() { return fReader.readPtr(); } |
105 | 106 |
106 // primitives | 107 // primitives |
107 virtual bool readBool(); | 108 virtual bool readBool(); |
108 virtual SkColor readColor(); | 109 virtual SkColor readColor(); |
109 virtual int32_t readInt(); | 110 virtual int32_t readInt(); |
110 virtual SkScalar readScalar(); | 111 virtual SkScalar readScalar(); |
111 virtual uint32_t readUInt(); | 112 virtual uint32_t readUInt(); |
112 virtual int32_t read32(); | 113 virtual int32_t read32(); |
113 | 114 |
| 115 // peek |
| 116 virtual uint8_t peekByte(); |
| 117 |
114 // strings -- the caller is responsible for freeing the string contents | 118 // strings -- the caller is responsible for freeing the string contents |
115 virtual void readString(SkString* string); | 119 virtual void readString(SkString* string); |
116 virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encodi
ng); | 120 virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encodi
ng); |
117 | 121 |
118 // common data structures | 122 // common data structures |
119 virtual void readPoint(SkPoint* point); | 123 virtual void readPoint(SkPoint* point); |
120 SkPoint readPoint() { SkPoint p; this->readPoint(&p); return p; } | 124 SkPoint readPoint() { SkPoint p; this->readPoint(&p); return p; } |
121 virtual void readMatrix(SkMatrix* matrix); | 125 virtual void readMatrix(SkMatrix* matrix); |
122 virtual void readIRect(SkIRect* rect); | 126 virtual void readIRect(SkIRect* rect); |
123 virtual void readRect(SkRect* rect); | 127 virtual void readRect(SkRect* rect); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 /** | 191 /** |
188 * Call this with a pre-loaded array of Factories, in the same order as | 192 * Call this with a pre-loaded array of Factories, in the same order as |
189 * were created/written by the writer. SkPicture uses this. | 193 * were created/written by the writer. SkPicture uses this. |
190 */ | 194 */ |
191 void setFactoryPlayback(SkFlattenable::Factory array[], int count) { | 195 void setFactoryPlayback(SkFlattenable::Factory array[], int count) { |
192 fFactoryArray = array; | 196 fFactoryArray = array; |
193 fFactoryCount = count; | 197 fFactoryCount = count; |
194 } | 198 } |
195 | 199 |
196 /** | 200 /** |
| 201 * For an input flattenable (specified by name), set a custom factory proc |
| 202 * to use when unflattening. Will make a copy of |name|. |
| 203 * |
| 204 * If the global registry already has a default factory for the flattenable
, |
| 205 * this will override that factory. If a custom factory has already been |
| 206 * set for the flattenable, this will override that factory. |
| 207 * |
| 208 * Custom factories can be removed by calling setCustomFactory("...", nullp
tr). |
| 209 */ |
| 210 void setCustomFactory(const SkString& name, SkFlattenable::Factory factory)
{ |
| 211 fCustomFactory.set(name, factory); |
| 212 } |
| 213 |
| 214 /** |
197 * 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 |
198 * 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 |
199 * appropriate size will be used. | 217 * appropriate size will be used. |
200 */ | 218 */ |
201 void setBitmapDecoder(SkPicture::InstallPixelRefProc bitmapDecoder) { | 219 void setBitmapDecoder(SkPicture::InstallPixelRefProc bitmapDecoder) { |
202 fBitmapDecoder = bitmapDecoder; | 220 fBitmapDecoder = bitmapDecoder; |
203 } | 221 } |
204 | 222 |
205 // Default impelementations don't check anything. | 223 // Default impelementations don't check anything. |
206 virtual bool validate(bool isValid) { return true; } | 224 virtual bool validate(bool isValid) { return true; } |
207 virtual bool isValid() const { return true; } | 225 virtual bool isValid() const { return true; } |
208 virtual bool validateAvailable(size_t size) { return true; } | 226 virtual bool validateAvailable(size_t size) { return true; } |
209 | 227 |
210 protected: | 228 protected: |
| 229 /** |
| 230 * Allows subclass to check if we are using factories for expansion |
| 231 * of flattenables. |
| 232 */ |
| 233 int factoryCount() { return fFactoryCount; } |
| 234 |
| 235 |
| 236 /** |
| 237 * Checks if a custom factory has been set for a given flattenable. |
| 238 * Returns the custom factory if it exists, or nullptr otherwise. |
| 239 */ |
| 240 SkFlattenable::Factory getCustomFactory(const SkString& name) { |
| 241 SkFlattenable::Factory* factoryPtr = fCustomFactory.find(name); |
| 242 return factoryPtr ? *factoryPtr : nullptr; |
| 243 } |
| 244 |
211 SkReader32 fReader; | 245 SkReader32 fReader; |
212 | 246 |
| 247 // Only used if we do not have an fFactoryArray. |
| 248 SkTHashMap<uint32_t, SkString> fFlattenableDict; |
| 249 |
213 private: | 250 private: |
214 bool readArray(void* value, size_t size, size_t elementSize); | 251 bool readArray(void* value, size_t size, size_t elementSize); |
215 | 252 |
216 uint32_t fFlags; | 253 uint32_t fFlags; |
217 int fVersion; | 254 int fVersion; |
218 | 255 |
219 void* fMemoryPtr; | 256 void* fMemoryPtr; |
220 | 257 |
221 SkBitmapHeapReader* fBitmapStorage; | 258 SkBitmapHeapReader* fBitmapStorage; |
222 SkTypeface** fTFArray; | 259 SkTypeface** fTFArray; |
223 int fTFCount; | 260 int fTFCount; |
224 | 261 |
225 SkFlattenable::Factory* fFactoryArray; | 262 SkFlattenable::Factory* fFactoryArray; |
226 int fFactoryCount; | 263 int fFactoryCount; |
227 | 264 |
| 265 // Only used if we do not have an fFactoryArray. |
| 266 SkTHashMap<SkString, SkFlattenable::Factory> fCustomFactory; |
| 267 |
228 SkPicture::InstallPixelRefProc fBitmapDecoder; | 268 SkPicture::InstallPixelRefProc fBitmapDecoder; |
229 | 269 |
230 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT | 270 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
231 // Debugging counter to keep track of how many bitmaps we | 271 // Debugging counter to keep track of how many bitmaps we |
232 // have decoded. | 272 // have decoded. |
233 int fDecodedBitmapIndex; | 273 int fDecodedBitmapIndex; |
234 #endif // DEBUG_NON_DETERMINISTIC_ASSERT | 274 #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
235 }; | 275 }; |
236 | 276 |
237 #endif // SkReadBuffer_DEFINED | 277 #endif // SkReadBuffer_DEFINED |
OLD | NEW |