Chromium Code Reviews| 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 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 /** | 187 /** |
| 188 * Call this with a pre-loaded array of Factories, in the same order as | 188 * Call this with a pre-loaded array of Factories, in the same order as |
| 189 * were created/written by the writer. SkPicture uses this. | 189 * were created/written by the writer. SkPicture uses this. |
| 190 */ | 190 */ |
| 191 void setFactoryPlayback(SkFlattenable::Factory array[], int count) { | 191 void setFactoryPlayback(SkFlattenable::Factory array[], int count) { |
| 192 fFactoryArray = array; | 192 fFactoryArray = array; |
| 193 fFactoryCount = count; | 193 fFactoryCount = count; |
| 194 } | 194 } |
| 195 | 195 |
| 196 /** | 196 /** |
| 197 * For an input flattenable (specified by name), set a custom factory proc | |
|
reed1
2016/04/11 15:07:48
Dox comments:
1. Does the name get copied, or mus
msarett
2016/04/19 18:03:50
Done.
| |
| 198 * to use when unflattening. | |
| 199 */ | |
| 200 void setCustomFactory(const char* name, SkFlattenable::Factory factory) { | |
| 201 NameFactoryEntry entry; | |
| 202 entry.fName = name; | |
| 203 entry.fFactory = factory; | |
| 204 fCustomFactory.push_back(entry); | |
| 205 } | |
| 206 | |
| 207 /** | |
| 197 * Provide a function to decode an SkBitmap from encoded data. Only used if the writer | 208 * 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 | 209 * encoded the SkBitmap. If the proper decoder cannot be used, a red bitmap with the |
| 199 * appropriate size will be used. | 210 * appropriate size will be used. |
| 200 */ | 211 */ |
| 201 void setBitmapDecoder(SkPicture::InstallPixelRefProc bitmapDecoder) { | 212 void setBitmapDecoder(SkPicture::InstallPixelRefProc bitmapDecoder) { |
| 202 fBitmapDecoder = bitmapDecoder; | 213 fBitmapDecoder = bitmapDecoder; |
| 203 } | 214 } |
| 204 | 215 |
| 205 // Default impelementations don't check anything. | 216 // Default impelementations don't check anything. |
| 206 virtual bool validate(bool isValid) { return true; } | 217 virtual bool validate(bool isValid) { return true; } |
| 207 virtual bool isValid() const { return true; } | 218 virtual bool isValid() const { return true; } |
| 208 virtual bool validateAvailable(size_t size) { return true; } | 219 virtual bool validateAvailable(size_t size) { return true; } |
| 209 | 220 |
| 210 protected: | 221 protected: |
| 211 SkReader32 fReader; | 222 SkReader32 fReader; |
| 212 | 223 |
| 224 /** | |
| 225 * Checks if a custom factory has been set for a given flattenable. | |
| 226 * Returns the custom factory if it exists, or nullptr otherwise. | |
| 227 */ | |
| 228 SkFlattenable::Factory getCustomFactory(const char* name) { | |
| 229 for (int i = 0; i < fCustomFactory.count(); i++) { | |
| 230 if (!strcmp(fCustomFactory[i].fName, name)) { | |
| 231 return fCustomFactory[i].fFactory; | |
| 232 } | |
| 233 } | |
| 234 | |
| 235 return nullptr; | |
| 236 } | |
| 237 | |
| 213 private: | 238 private: |
| 214 bool readArray(void* value, size_t size, size_t elementSize); | 239 bool readArray(void* value, size_t size, size_t elementSize); |
| 215 | 240 |
| 216 uint32_t fFlags; | 241 uint32_t fFlags; |
| 217 int fVersion; | 242 int fVersion; |
| 218 | 243 |
| 219 void* fMemoryPtr; | 244 void* fMemoryPtr; |
| 220 | 245 |
| 221 SkBitmapHeapReader* fBitmapStorage; | 246 SkBitmapHeapReader* fBitmapStorage; |
| 222 SkTypeface** fTFArray; | 247 SkTypeface** fTFArray; |
| 223 int fTFCount; | 248 int fTFCount; |
| 224 | 249 |
| 225 SkFlattenable::Factory* fFactoryArray; | 250 SkFlattenable::Factory* fFactoryArray; |
| 226 int fFactoryCount; | 251 int fFactoryCount; |
| 227 | 252 |
| 253 // Maps the flattenable name to a custom factory that should be used to | |
| 254 // create the flattenable. | |
| 255 struct NameFactoryEntry { | |
| 256 const char* fName; | |
| 257 SkFlattenable::Factory fFactory; | |
| 258 }; | |
| 259 SkTArray<NameFactoryEntry> fCustomFactory; | |
| 260 | |
| 228 SkPicture::InstallPixelRefProc fBitmapDecoder; | 261 SkPicture::InstallPixelRefProc fBitmapDecoder; |
| 229 | 262 |
| 230 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT | 263 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
| 231 // Debugging counter to keep track of how many bitmaps we | 264 // Debugging counter to keep track of how many bitmaps we |
| 232 // have decoded. | 265 // have decoded. |
| 233 int fDecodedBitmapIndex; | 266 int fDecodedBitmapIndex; |
| 234 #endif // DEBUG_NON_DETERMINISTIC_ASSERT | 267 #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
| 235 }; | 268 }; |
| 236 | 269 |
| 237 #endif // SkReadBuffer_DEFINED | 270 #endif // SkReadBuffer_DEFINED |
| OLD | NEW |