| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 } | 160 } |
| 161 void* buffer = sk_malloc_throw(len); | 161 void* buffer = sk_malloc_throw(len); |
| 162 this->readByteArray(buffer, len); | 162 this->readByteArray(buffer, len); |
| 163 return SkData::MakeFromMalloc(buffer, len); | 163 return SkData::MakeFromMalloc(buffer, len); |
| 164 } | 164 } |
| 165 | 165 |
| 166 // helpers to get info about arrays and binary data | 166 // helpers to get info about arrays and binary data |
| 167 virtual uint32_t getArrayCount(); | 167 virtual uint32_t getArrayCount(); |
| 168 | 168 |
| 169 /** | 169 /** |
| 170 * Returns false if the bitmap could not be completely read. In that case,
it will be set | 170 * Returns false if the image could not be completely read. In that case, i
t will be set |
| 171 * to have width/height, but no pixels. | 171 * to have width/height, but no pixels. |
| 172 */ | 172 */ |
| 173 bool readBitmap(SkBitmap* bitmap); | 173 sk_sp<SkImage> readBitmapAsImage(); |
| 174 | 174 sk_sp<SkImage> readImage(); |
| 175 SkImage* readImage(); | |
| 176 | 175 |
| 177 virtual SkTypeface* readTypeface(); | 176 virtual SkTypeface* readTypeface(); |
| 178 | 177 |
| 179 void setTypefaceArray(SkTypeface* array[], int count) { | 178 void setTypefaceArray(SkTypeface* array[], int count) { |
| 180 fTFArray = array; | 179 fTFArray = array; |
| 181 fTFCount = count; | 180 fTFCount = count; |
| 182 } | 181 } |
| 183 | 182 |
| 184 /** | 183 /** |
| 185 * Call this with a pre-loaded array of Factories, in the same order as | 184 * Call this with a pre-loaded array of Factories, in the same order as |
| (...skipping 11 matching lines...) Expand all Loading... |
| 197 * If the global registry already has a default factory for the flattenable
, | 196 * If the global registry already has a default factory for the flattenable
, |
| 198 * this will override that factory. If a custom factory has already been | 197 * this will override that factory. If a custom factory has already been |
| 199 * set for the flattenable, this will override that factory. | 198 * set for the flattenable, this will override that factory. |
| 200 * | 199 * |
| 201 * Custom factories can be removed by calling setCustomFactory("...", nullp
tr). | 200 * Custom factories can be removed by calling setCustomFactory("...", nullp
tr). |
| 202 */ | 201 */ |
| 203 void setCustomFactory(const SkString& name, SkFlattenable::Factory factory)
{ | 202 void setCustomFactory(const SkString& name, SkFlattenable::Factory factory)
{ |
| 204 fCustomFactory.set(name, factory); | 203 fCustomFactory.set(name, factory); |
| 205 } | 204 } |
| 206 | 205 |
| 207 /** | 206 // If nullptr is passed, then the default deserializer will be used |
| 208 * Provide a function to decode an SkBitmap from encoded data. Only used if
the writer | 207 // which calls SkImage::MakeFromEncoded() |
| 209 * encoded the SkBitmap. If the proper decoder cannot be used, a red bitmap
with the | 208 void setImageDeserializer(SkImageDeserializer* factory); |
| 210 * appropriate size will be used. | |
| 211 */ | |
| 212 void setBitmapDecoder(SkPicture::InstallPixelRefProc bitmapDecoder) { | |
| 213 fBitmapDecoder = bitmapDecoder; | |
| 214 } | |
| 215 | 209 |
| 216 // Default impelementations don't check anything. | 210 // Default impelementations don't check anything. |
| 217 virtual bool validate(bool isValid) { return isValid; } | 211 virtual bool validate(bool isValid) { return isValid; } |
| 218 virtual bool isValid() const { return true; } | 212 virtual bool isValid() const { return true; } |
| 219 virtual bool validateAvailable(size_t size) { return true; } | 213 virtual bool validateAvailable(size_t size) { return true; } |
| 220 bool validateIndex(int index, int count) { | 214 bool validateIndex(int index, int count) { |
| 221 return this->validate(index >= 0 && index < count); | 215 return this->validate(index >= 0 && index < count); |
| 222 } | 216 } |
| 223 | 217 |
| 224 protected: | 218 protected: |
| 225 /** | 219 /** |
| 226 * Allows subclass to check if we are using factories for expansion | 220 * Allows subclass to check if we are using factories for expansion |
| 227 * of flattenables. | 221 * of flattenables. |
| 228 */ | 222 */ |
| 229 int factoryCount() { return fFactoryCount; } | 223 int factoryCount() { return fFactoryCount; } |
| 230 | 224 |
| 231 | |
| 232 /** | 225 /** |
| 233 * Checks if a custom factory has been set for a given flattenable. | 226 * Checks if a custom factory has been set for a given flattenable. |
| 234 * Returns the custom factory if it exists, or nullptr otherwise. | 227 * Returns the custom factory if it exists, or nullptr otherwise. |
| 235 */ | 228 */ |
| 236 SkFlattenable::Factory getCustomFactory(const SkString& name) { | 229 SkFlattenable::Factory getCustomFactory(const SkString& name) { |
| 237 SkFlattenable::Factory* factoryPtr = fCustomFactory.find(name); | 230 SkFlattenable::Factory* factoryPtr = fCustomFactory.find(name); |
| 238 return factoryPtr ? *factoryPtr : nullptr; | 231 return factoryPtr ? *factoryPtr : nullptr; |
| 239 } | 232 } |
| 240 | 233 |
| 241 SkReader32 fReader; | 234 SkReader32 fReader; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 253 | 246 |
| 254 SkTypeface** fTFArray; | 247 SkTypeface** fTFArray; |
| 255 int fTFCount; | 248 int fTFCount; |
| 256 | 249 |
| 257 SkFlattenable::Factory* fFactoryArray; | 250 SkFlattenable::Factory* fFactoryArray; |
| 258 int fFactoryCount; | 251 int fFactoryCount; |
| 259 | 252 |
| 260 // Only used if we do not have an fFactoryArray. | 253 // Only used if we do not have an fFactoryArray. |
| 261 SkTHashMap<SkString, SkFlattenable::Factory> fCustomFactory; | 254 SkTHashMap<SkString, SkFlattenable::Factory> fCustomFactory; |
| 262 | 255 |
| 263 SkPicture::InstallPixelRefProc fBitmapDecoder; | 256 // We do not own this ptr, we just use it (guaranteed to never be null) |
| 257 SkImageDeserializer* fImageDeserializer; |
| 264 | 258 |
| 265 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT | 259 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
| 266 // Debugging counter to keep track of how many bitmaps we | 260 // Debugging counter to keep track of how many bitmaps we |
| 267 // have decoded. | 261 // have decoded. |
| 268 int fDecodedBitmapIndex; | 262 int fDecodedBitmapIndex; |
| 269 #endif // DEBUG_NON_DETERMINISTIC_ASSERT | 263 #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
| 270 }; | 264 }; |
| 271 | 265 |
| 272 #endif // SkReadBuffer_DEFINED | 266 #endif // SkReadBuffer_DEFINED |
| OLD | NEW |