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 | |
105 void setOffset(size_t offset) { fReader.setOffset(offset); } | |
reed1
2016/04/20 13:26:37
who needs this, why?
robertphillips
2016/04/20 17:09:40
SkPicturePlayback::handleOp uses it as an optimiza
| |
106 | |
104 void* readFunctionPtr() { return fReader.readPtr(); } | 107 void* readFunctionPtr() { return fReader.readPtr(); } |
105 | 108 |
106 // primitives | 109 // primitives |
107 virtual bool readBool(); | 110 virtual bool readBool(); |
108 virtual SkColor readColor(); | 111 virtual SkColor readColor(); |
109 virtual int32_t readInt(); | 112 virtual int32_t readInt(); |
110 virtual SkScalar readScalar(); | 113 virtual SkScalar readScalar(); |
111 virtual uint32_t readUInt(); | 114 virtual uint32_t readUInt(); |
112 virtual int32_t read32(); | 115 virtual int32_t read32(); |
113 | 116 |
114 // strings -- the caller is responsible for freeing the string contents | 117 // strings -- the caller is responsible for freeing the string contents |
115 virtual void readString(SkString* string); | 118 virtual void readString(SkString* string); |
116 virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encodi ng); | 119 virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encodi ng); |
117 | 120 |
118 // common data structures | 121 // common data structures |
119 virtual void readPoint(SkPoint* point); | 122 virtual void readPoint(SkPoint* point); |
120 SkPoint readPoint() { SkPoint p; this->readPoint(&p); return p; } | 123 SkPoint readPoint() { SkPoint p; this->readPoint(&p); return p; } |
121 virtual void readMatrix(SkMatrix* matrix); | 124 virtual void readMatrix(SkMatrix* matrix); |
122 virtual void readIRect(SkIRect* rect); | 125 virtual void readIRect(SkIRect* rect); |
123 virtual void readRect(SkRect* rect); | 126 virtual void readRect(SkRect* rect); |
127 virtual void readRRect(SkRRect* rrect); | |
124 virtual void readRegion(SkRegion* region); | 128 virtual void readRegion(SkRegion* region); |
125 | 129 |
126 virtual void readPath(SkPath* path); | 130 virtual void readPath(SkPath* path); |
127 void readPaint(SkPaint* paint) { paint->unflatten(*this); } | 131 void readPaint(SkPaint* paint) { paint->unflatten(*this); } |
128 | 132 |
129 virtual SkFlattenable* readFlattenable(SkFlattenable::Type); | 133 virtual SkFlattenable* readFlattenable(SkFlattenable::Type); |
130 template <typename T> sk_sp<T> readFlattenable() { | 134 template <typename T> sk_sp<T> readFlattenable() { |
131 return sk_sp<T>((T*)this->readFlattenable(T::GetFlattenableType())); | 135 return sk_sp<T>((T*)this->readFlattenable(T::GetFlattenableType())); |
132 } | 136 } |
133 sk_sp<SkColorFilter> readColorFilter() { return this->readFlattenable<SkColo rFilter>(); } | 137 sk_sp<SkColorFilter> readColorFilter() { return this->readFlattenable<SkColo rFilter>(); } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 /** | 200 /** |
197 * Provide a function to decode an SkBitmap from encoded data. Only used if the writer | 201 * 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 | 202 * encoded the SkBitmap. If the proper decoder cannot be used, a red bitmap with the |
199 * appropriate size will be used. | 203 * appropriate size will be used. |
200 */ | 204 */ |
201 void setBitmapDecoder(SkPicture::InstallPixelRefProc bitmapDecoder) { | 205 void setBitmapDecoder(SkPicture::InstallPixelRefProc bitmapDecoder) { |
202 fBitmapDecoder = bitmapDecoder; | 206 fBitmapDecoder = bitmapDecoder; |
203 } | 207 } |
204 | 208 |
205 // Default impelementations don't check anything. | 209 // Default impelementations don't check anything. |
206 virtual bool validate(bool isValid) { return true; } | 210 virtual bool validate(bool isValid) { return isValid; } |
207 virtual bool isValid() const { return true; } | 211 virtual bool isValid() const { return true; } |
208 virtual bool validateAvailable(size_t size) { return true; } | 212 virtual bool validateAvailable(size_t size) { return true; } |
213 bool validateIndex(int index, int count) { | |
214 return this->validate(index >= 0 && index < count); | |
215 } | |
209 | 216 |
210 protected: | 217 protected: |
211 SkReader32 fReader; | 218 SkReader32 fReader; |
212 | 219 |
213 private: | 220 private: |
214 bool readArray(void* value, size_t size, size_t elementSize); | 221 bool readArray(void* value, size_t size, size_t elementSize); |
215 | 222 |
216 uint32_t fFlags; | 223 uint32_t fFlags; |
217 int fVersion; | 224 int fVersion; |
218 | 225 |
219 void* fMemoryPtr; | 226 void* fMemoryPtr; |
220 | 227 |
221 SkBitmapHeapReader* fBitmapStorage; | 228 SkBitmapHeapReader* fBitmapStorage; |
222 SkTypeface** fTFArray; | 229 SkTypeface** fTFArray; |
223 int fTFCount; | 230 int fTFCount; |
224 | 231 |
225 SkFlattenable::Factory* fFactoryArray; | 232 SkFlattenable::Factory* fFactoryArray; |
226 int fFactoryCount; | 233 int fFactoryCount; |
227 | 234 |
228 SkPicture::InstallPixelRefProc fBitmapDecoder; | 235 SkPicture::InstallPixelRefProc fBitmapDecoder; |
229 | 236 |
230 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT | 237 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
231 // Debugging counter to keep track of how many bitmaps we | 238 // Debugging counter to keep track of how many bitmaps we |
232 // have decoded. | 239 // have decoded. |
233 int fDecodedBitmapIndex; | 240 int fDecodedBitmapIndex; |
234 #endif // DEBUG_NON_DETERMINISTIC_ASSERT | 241 #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
235 }; | 242 }; |
236 | 243 |
237 #endif // SkReadBuffer_DEFINED | 244 #endif // SkReadBuffer_DEFINED |
OLD | NEW |