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 "SkColorFilter.h" | 11 #include "SkColorFilter.h" |
12 #include "SkData.h" | 12 #include "SkData.h" |
13 #include "SkDrawLooper.h" | 13 #include "SkDrawLooper.h" |
14 #include "SkImageFilter.h" | 14 #include "SkImageFilter.h" |
15 #include "SkMaskFilter.h" | 15 #include "SkMaskFilter.h" |
16 #include "SkPath.h" | 16 #include "SkPath.h" |
17 #include "SkPathEffect.h" | 17 #include "SkPathEffect.h" |
18 #include "SkPicture.h" | 18 #include "SkPicture.h" |
19 #include "SkRasterizer.h" | 19 #include "SkRasterizer.h" |
20 #include "SkReadBuffer.h" | 20 #include "SkReadBuffer.h" |
21 #include "SkReader32.h" | 21 #include "SkReader32.h" |
22 #include "SkRefCnt.h" | 22 #include "SkRefCnt.h" |
23 #include "SkShader.h" | 23 #include "SkShader.h" |
24 #include "SkTHash.h" | 24 #include "SkTHash.h" |
25 #include "SkWriteBuffer.h" | 25 #include "SkWriteBuffer.h" |
26 #include "SkXfermode.h" | 26 #include "SkXfermode.h" |
27 | 27 |
28 class SkBitmap; | 28 class SkBitmap; |
29 class SkImage; | 29 class SkImage; |
| 30 class SkInflator; |
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 |
35 class SkReadBuffer { | 36 class SkReadBuffer { |
36 public: | 37 public: |
37 SkReadBuffer(); | 38 SkReadBuffer(); |
38 SkReadBuffer(const void* data, size_t size); | 39 SkReadBuffer(const void* data, size_t size); |
39 SkReadBuffer(SkStream* stream); | 40 SkReadBuffer(SkStream* stream); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 // common data structures | 125 // common data structures |
125 virtual void readPoint(SkPoint* point); | 126 virtual void readPoint(SkPoint* point); |
126 SkPoint readPoint() { SkPoint p; this->readPoint(&p); return p; } | 127 SkPoint readPoint() { SkPoint p; this->readPoint(&p); return p; } |
127 virtual void readMatrix(SkMatrix* matrix); | 128 virtual void readMatrix(SkMatrix* matrix); |
128 virtual void readIRect(SkIRect* rect); | 129 virtual void readIRect(SkIRect* rect); |
129 virtual void readRect(SkRect* rect); | 130 virtual void readRect(SkRect* rect); |
130 virtual void readRRect(SkRRect* rrect); | 131 virtual void readRRect(SkRRect* rrect); |
131 virtual void readRegion(SkRegion* region); | 132 virtual void readRegion(SkRegion* region); |
132 | 133 |
133 virtual void readPath(SkPath* path); | 134 virtual void readPath(SkPath* path); |
134 void readPaint(SkPaint* paint) { paint->unflatten(*this); } | 135 virtual void readPaint(SkPaint* paint) { paint->unflatten(*this); } |
135 | 136 |
136 virtual SkFlattenable* readFlattenable(SkFlattenable::Type); | 137 virtual SkFlattenable* readFlattenable(SkFlattenable::Type); |
137 template <typename T> sk_sp<T> readFlattenable() { | 138 template <typename T> sk_sp<T> readFlattenable() { |
138 return sk_sp<T>((T*)this->readFlattenable(T::GetFlattenableType())); | 139 return sk_sp<T>((T*)this->readFlattenable(T::GetFlattenableType())); |
139 } | 140 } |
140 sk_sp<SkColorFilter> readColorFilter() { return this->readFlattenable<SkColo
rFilter>(); } | 141 sk_sp<SkColorFilter> readColorFilter() { return this->readFlattenable<SkColo
rFilter>(); } |
141 sk_sp<SkDrawLooper> readDrawLooper() { return this->readFlattenable<SkDrawLo
oper>(); } | 142 sk_sp<SkDrawLooper> readDrawLooper() { return this->readFlattenable<SkDrawLo
oper>(); } |
142 sk_sp<SkImageFilter> readImageFilter() { return this->readFlattenable<SkImag
eFilter>(); } | 143 sk_sp<SkImageFilter> readImageFilter() { return this->readFlattenable<SkImag
eFilter>(); } |
143 sk_sp<SkMaskFilter> readMaskFilter() { return this->readFlattenable<SkMaskFi
lter>(); } | 144 sk_sp<SkMaskFilter> readMaskFilter() { return this->readFlattenable<SkMaskFi
lter>(); } |
144 sk_sp<SkPathEffect> readPathEffect() { return this->readFlattenable<SkPathEf
fect>(); } | 145 sk_sp<SkPathEffect> readPathEffect() { return this->readFlattenable<SkPathEf
fect>(); } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 void setImageDeserializer(SkImageDeserializer* factory); | 204 void setImageDeserializer(SkImageDeserializer* factory); |
204 | 205 |
205 // Default impelementations don't check anything. | 206 // Default impelementations don't check anything. |
206 virtual bool validate(bool isValid) { return isValid; } | 207 virtual bool validate(bool isValid) { return isValid; } |
207 virtual bool isValid() const { return true; } | 208 virtual bool isValid() const { return true; } |
208 virtual bool validateAvailable(size_t size) { return true; } | 209 virtual bool validateAvailable(size_t size) { return true; } |
209 bool validateIndex(int index, int count) { | 210 bool validateIndex(int index, int count) { |
210 return this->validate(index >= 0 && index < count); | 211 return this->validate(index >= 0 && index < count); |
211 } | 212 } |
212 | 213 |
| 214 SkInflator* getInflator() const { return fInflator; } |
| 215 void setInflator(SkInflator* inf) { fInflator = inf; } |
| 216 |
| 217 // sk_sp<SkImage> inflateImage(); |
| 218 |
213 protected: | 219 protected: |
214 /** | 220 /** |
215 * Allows subclass to check if we are using factories for expansion | 221 * Allows subclass to check if we are using factories for expansion |
216 * of flattenables. | 222 * of flattenables. |
217 */ | 223 */ |
218 int factoryCount() { return fFactoryCount; } | 224 int factoryCount() { return fFactoryCount; } |
219 | 225 |
220 /** | 226 /** |
221 * Checks if a custom factory has been set for a given flattenable. | 227 * Checks if a custom factory has been set for a given flattenable. |
222 * Returns the custom factory if it exists, or nullptr otherwise. | 228 * Returns the custom factory if it exists, or nullptr otherwise. |
(...skipping 26 matching lines...) Expand all Loading... |
249 SkTHashMap<SkString, SkFlattenable::Factory> fCustomFactory; | 255 SkTHashMap<SkString, SkFlattenable::Factory> fCustomFactory; |
250 | 256 |
251 // We do not own this ptr, we just use it (guaranteed to never be null) | 257 // We do not own this ptr, we just use it (guaranteed to never be null) |
252 SkImageDeserializer* fImageDeserializer; | 258 SkImageDeserializer* fImageDeserializer; |
253 | 259 |
254 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT | 260 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
255 // Debugging counter to keep track of how many bitmaps we | 261 // Debugging counter to keep track of how many bitmaps we |
256 // have decoded. | 262 // have decoded. |
257 int fDecodedBitmapIndex; | 263 int fDecodedBitmapIndex; |
258 #endif // DEBUG_NON_DETERMINISTIC_ASSERT | 264 #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
| 265 |
| 266 SkInflator* fInflator = nullptr; |
259 }; | 267 }; |
260 | 268 |
261 #endif // SkReadBuffer_DEFINED | 269 #endif // SkReadBuffer_DEFINED |
OLD | NEW |