OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2013 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #ifndef SkValidatingReadBuffer_DEFINED |
| 9 #define SkValidatingReadBuffer_DEFINED |
| 10 |
| 11 #include "SkRefCnt.h" |
| 12 #include "SkBitmapHeap.h" |
| 13 #include "SkFlattenableBuffers.h" |
| 14 #include "SkPath.h" |
| 15 #include "SkPicture.h" |
| 16 #include "SkReader32.h" |
| 17 |
| 18 class SkBitmap; |
| 19 |
| 20 class SkValidatingReadBuffer : public SkFlattenableReadBuffer { |
| 21 public: |
| 22 SkValidatingReadBuffer(const void* data, size_t size); |
| 23 virtual ~SkValidatingReadBuffer(); |
| 24 |
| 25 const void* skip(size_t size); |
| 26 |
| 27 // primitives |
| 28 virtual bool readBool() SK_OVERRIDE; |
| 29 virtual SkColor readColor() SK_OVERRIDE; |
| 30 virtual SkFixed readFixed() SK_OVERRIDE; |
| 31 virtual int32_t readInt() SK_OVERRIDE; |
| 32 virtual SkScalar readScalar() SK_OVERRIDE; |
| 33 virtual uint32_t readUInt() SK_OVERRIDE; |
| 34 virtual int32_t read32() SK_OVERRIDE; |
| 35 |
| 36 // strings -- the caller is responsible for freeing the string contents |
| 37 virtual void readString(SkString* string) SK_OVERRIDE; |
| 38 virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encodi
ng) SK_OVERRIDE; |
| 39 |
| 40 // common data structures |
| 41 virtual SkFlattenable* readFlattenable( |
| 42 const char* name = SkFlattenable::GetTypeName()) SK_OVERRIDE; |
| 43 virtual void readPoint(SkPoint* point) SK_OVERRIDE; |
| 44 virtual void readMatrix(SkMatrix* matrix) SK_OVERRIDE; |
| 45 virtual void readIRect(SkIRect* rect) SK_OVERRIDE; |
| 46 virtual void readRect(SkRect* rect) SK_OVERRIDE; |
| 47 virtual void readRegion(SkRegion* region) SK_OVERRIDE; |
| 48 virtual void readPath(SkPath* path) SK_OVERRIDE; |
| 49 |
| 50 // binary data and arrays |
| 51 virtual uint32_t readByteArray(void* value) SK_OVERRIDE; |
| 52 virtual uint32_t readColorArray(SkColor* colors) SK_OVERRIDE; |
| 53 virtual uint32_t readIntArray(int32_t* values) SK_OVERRIDE; |
| 54 virtual uint32_t readPointArray(SkPoint* points) SK_OVERRIDE; |
| 55 virtual uint32_t readScalarArray(SkScalar* values) SK_OVERRIDE; |
| 56 |
| 57 // helpers to get info about arrays and binary data |
| 58 virtual uint32_t getArrayCount() SK_OVERRIDE; |
| 59 |
| 60 virtual void readBitmap(SkBitmap* bitmap) SK_OVERRIDE; |
| 61 // TODO: Implement this (securely) when needed |
| 62 virtual SkTypeface* readTypeface() SK_OVERRIDE { return NULL; } |
| 63 |
| 64 virtual void validate(bool isValid) SK_OVERRIDE { |
| 65 fError = fError || !isValid; |
| 66 } |
| 67 |
| 68 private: |
| 69 void setMemory(const void* data, size_t size); |
| 70 |
| 71 static bool IsPtrAlign4(const void* ptr) { |
| 72 return SkIsAlign4((uintptr_t)ptr); |
| 73 } |
| 74 |
| 75 SkReader32 fReader; |
| 76 bool fError; |
| 77 |
| 78 typedef SkFlattenableReadBuffer INHERITED; |
| 79 }; |
| 80 |
| 81 #endif // SkValidatingReadBuffer_DEFINED |
OLD | NEW |