| 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: |
| 211 SkReader32 fReader; | 229 SkReader32 fReader; |
| 212 | 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(const SkString& name) { |
| 236 SkFlattenable::Factory* factoryPtr = fCustomFactory.find(name); |
| 237 return factoryPtr ? *factoryPtr : nullptr; |
| 238 } |
| 239 |
| 213 private: | 240 private: |
| 214 bool readArray(void* value, size_t size, size_t elementSize); | 241 bool readArray(void* value, size_t size, size_t elementSize); |
| 215 | 242 |
| 216 uint32_t fFlags; | 243 uint32_t fFlags; |
| 217 int fVersion; | 244 int fVersion; |
| 218 | 245 |
| 219 void* fMemoryPtr; | 246 void* fMemoryPtr; |
| 220 | 247 |
| 221 SkBitmapHeapReader* fBitmapStorage; | 248 SkBitmapHeapReader* fBitmapStorage; |
| 222 SkTypeface** fTFArray; | 249 SkTypeface** fTFArray; |
| 223 int fTFCount; | 250 int fTFCount; |
| 224 | 251 |
| 225 SkFlattenable::Factory* fFactoryArray; | 252 SkFlattenable::Factory* fFactoryArray; |
| 226 int fFactoryCount; | 253 int fFactoryCount; |
| 227 | 254 |
| 255 // Only used if we do not have an fFactoryArray. |
| 256 SkTHashMap<SkString, SkFlattenable::Factory> fCustomFactory; |
| 257 SkTHashMap<uint32_t, SkString> fFlattenableDict; |
| 258 |
| 228 SkPicture::InstallPixelRefProc fBitmapDecoder; | 259 SkPicture::InstallPixelRefProc fBitmapDecoder; |
| 229 | 260 |
| 230 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT | 261 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
| 231 // Debugging counter to keep track of how many bitmaps we | 262 // Debugging counter to keep track of how many bitmaps we |
| 232 // have decoded. | 263 // have decoded. |
| 233 int fDecodedBitmapIndex; | 264 int fDecodedBitmapIndex; |
| 234 #endif // DEBUG_NON_DETERMINISTIC_ASSERT | 265 #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
| 235 }; | 266 }; |
| 236 | 267 |
| 237 #endif // SkReadBuffer_DEFINED | 268 #endif // SkReadBuffer_DEFINED |
| OLD | NEW |