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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 bool isScalarFloat() const { return SkToBool(fFlags & kScalarIsFloat_Flag);
} | 94 bool isScalarFloat() const { return SkToBool(fFlags & kScalarIsFloat_Flag);
} |
95 bool isPtr64Bit() const { return SkToBool(fFlags & kPtrIs64Bit_Flag); } | 95 bool isPtr64Bit() const { return SkToBool(fFlags & kPtrIs64Bit_Flag); } |
96 bool isValidating() const { return SkToBool(fFlags & kValidation_Flag); } | 96 bool isValidating() const { return SkToBool(fFlags & kValidation_Flag); } |
97 | 97 |
98 SkReader32* getReader32() { return &fReader; } | 98 SkReader32* getReader32() { return &fReader; } |
99 | 99 |
100 size_t size() { return fReader.size(); } | 100 size_t size() { return fReader.size(); } |
101 size_t offset() { return fReader.offset(); } | 101 size_t offset() { return fReader.offset(); } |
102 bool eof() { return fReader.eof(); } | 102 bool eof() { return fReader.eof(); } |
103 virtual const void* skip(size_t size) { return fReader.skip(size); } | 103 virtual const void* skip(size_t size) { return fReader.skip(size); } |
| 104 |
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 |
114 // strings -- the caller is responsible for freeing the string contents | 115 // strings -- the caller is responsible for freeing the string contents |
115 virtual void readString(SkString* string); | 116 virtual void readString(SkString* string); |
116 virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encodi
ng); | 117 virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encodi
ng); |
117 | 118 |
118 // common data structures | 119 // common data structures |
119 virtual void readPoint(SkPoint* point); | 120 virtual void readPoint(SkPoint* point); |
120 SkPoint readPoint() { SkPoint p; this->readPoint(&p); return p; } | 121 SkPoint readPoint() { SkPoint p; this->readPoint(&p); return p; } |
121 virtual void readMatrix(SkMatrix* matrix); | 122 virtual void readMatrix(SkMatrix* matrix); |
122 virtual void readIRect(SkIRect* rect); | 123 virtual void readIRect(SkIRect* rect); |
123 virtual void readRect(SkRect* rect); | 124 virtual void readRect(SkRect* rect); |
| 125 virtual void readRRect(SkRRect* rrect); |
124 virtual void readRegion(SkRegion* region); | 126 virtual void readRegion(SkRegion* region); |
125 | 127 |
126 virtual void readPath(SkPath* path); | 128 virtual void readPath(SkPath* path); |
127 void readPaint(SkPaint* paint) { paint->unflatten(*this); } | 129 void readPaint(SkPaint* paint) { paint->unflatten(*this); } |
128 | 130 |
129 virtual SkFlattenable* readFlattenable(SkFlattenable::Type); | 131 virtual SkFlattenable* readFlattenable(SkFlattenable::Type); |
130 template <typename T> sk_sp<T> readFlattenable() { | 132 template <typename T> sk_sp<T> readFlattenable() { |
131 return sk_sp<T>((T*)this->readFlattenable(T::GetFlattenableType())); | 133 return sk_sp<T>((T*)this->readFlattenable(T::GetFlattenableType())); |
132 } | 134 } |
133 sk_sp<SkColorFilter> readColorFilter() { return this->readFlattenable<SkColo
rFilter>(); } | 135 sk_sp<SkColorFilter> readColorFilter() { return this->readFlattenable<SkColo
rFilter>(); } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 /** | 198 /** |
197 * Provide a function to decode an SkBitmap from encoded data. Only used if
the writer | 199 * 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 | 200 * encoded the SkBitmap. If the proper decoder cannot be used, a red bitmap
with the |
199 * appropriate size will be used. | 201 * appropriate size will be used. |
200 */ | 202 */ |
201 void setBitmapDecoder(SkPicture::InstallPixelRefProc bitmapDecoder) { | 203 void setBitmapDecoder(SkPicture::InstallPixelRefProc bitmapDecoder) { |
202 fBitmapDecoder = bitmapDecoder; | 204 fBitmapDecoder = bitmapDecoder; |
203 } | 205 } |
204 | 206 |
205 // Default impelementations don't check anything. | 207 // Default impelementations don't check anything. |
206 virtual bool validate(bool isValid) { return true; } | 208 virtual bool validate(bool isValid) { return isValid; } |
207 virtual bool isValid() const { return true; } | 209 virtual bool isValid() const { return true; } |
208 virtual bool validateAvailable(size_t size) { return true; } | 210 virtual bool validateAvailable(size_t size) { return true; } |
| 211 bool validateIndex(int index, int count) { |
| 212 return this->validate(index >= 0 && index < count); |
| 213 } |
209 | 214 |
210 protected: | 215 protected: |
211 SkReader32 fReader; | 216 SkReader32 fReader; |
212 | 217 |
213 private: | 218 private: |
214 bool readArray(void* value, size_t size, size_t elementSize); | 219 bool readArray(void* value, size_t size, size_t elementSize); |
215 | 220 |
216 uint32_t fFlags; | 221 uint32_t fFlags; |
217 int fVersion; | 222 int fVersion; |
218 | 223 |
219 void* fMemoryPtr; | 224 void* fMemoryPtr; |
220 | 225 |
221 SkBitmapHeapReader* fBitmapStorage; | 226 SkBitmapHeapReader* fBitmapStorage; |
222 SkTypeface** fTFArray; | 227 SkTypeface** fTFArray; |
223 int fTFCount; | 228 int fTFCount; |
224 | 229 |
225 SkFlattenable::Factory* fFactoryArray; | 230 SkFlattenable::Factory* fFactoryArray; |
226 int fFactoryCount; | 231 int fFactoryCount; |
227 | 232 |
228 SkPicture::InstallPixelRefProc fBitmapDecoder; | 233 SkPicture::InstallPixelRefProc fBitmapDecoder; |
229 | 234 |
230 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT | 235 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
231 // Debugging counter to keep track of how many bitmaps we | 236 // Debugging counter to keep track of how many bitmaps we |
232 // have decoded. | 237 // have decoded. |
233 int fDecodedBitmapIndex; | 238 int fDecodedBitmapIndex; |
234 #endif // DEBUG_NON_DETERMINISTIC_ASSERT | 239 #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
235 }; | 240 }; |
236 | 241 |
237 #endif // SkReadBuffer_DEFINED | 242 #endif // SkReadBuffer_DEFINED |
OLD | NEW |