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 "SkReadBuffer.h" 14 #include "SkWriteBuffer.h" 15 #include "SkPath.h" 16 #include "SkPicture.h" 17 #include "SkReader32.h" 18 19 class SkBitmap; 20 21 class SkValidatingReadBuffer : public SkReadBuffer { 22 public: 23 SkValidatingReadBuffer(const void* data, size_t size); 24 virtual ~SkValidatingReadBuffer(); 25 26 virtual const void* skip(size_t size) SK_OVERRIDE; 27 28 // primitives 29 virtual bool readBool() SK_OVERRIDE; 30 virtual SkColor readColor() SK_OVERRIDE; 31 virtual SkFixed readFixed() SK_OVERRIDE; 32 virtual int32_t readInt() SK_OVERRIDE; 33 virtual SkScalar readScalar() SK_OVERRIDE; 34 virtual uint32_t readUInt() SK_OVERRIDE; 35 virtual int32_t read32() SK_OVERRIDE; 36 37 // strings -- the caller is responsible for freeing the string contents 38 virtual void readString(SkString* string) SK_OVERRIDE; 39 virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encoding) SK_OVERRIDE; 40 41 // common data structures 42 virtual SkFlattenable* readFlattenable(SkFlattenable::Type type) SK_OVERRIDE; 43 virtual void skipFlattenable() SK_OVERRIDE; 44 virtual void readPoint(SkPoint* point) SK_OVERRIDE; 45 virtual void readMatrix(SkMatrix* matrix) SK_OVERRIDE; 46 virtual void readIRect(SkIRect* rect) SK_OVERRIDE; 47 virtual void readRect(SkRect* rect) SK_OVERRIDE; 48 virtual void readRegion(SkRegion* region) SK_OVERRIDE; 49 virtual void readPath(SkPath* path) SK_OVERRIDE; 50 51 // binary data and arrays 52 virtual bool readByteArray(void* value, size_t size) SK_OVERRIDE; 53 virtual bool readColorArray(SkColor* colors, size_t size) SK_OVERRIDE; 54 virtual bool readIntArray(int32_t* values, size_t size) SK_OVERRIDE; 55 virtual bool readPointArray(SkPoint* points, size_t size) SK_OVERRIDE; 56 virtual bool readScalarArray(SkScalar* values, size_t size) SK_OVERRIDE; 57 58 // helpers to get info about arrays and binary data 59 virtual uint32_t getArrayCount() SK_OVERRIDE; 60 61 // TODO: Implement this (securely) when needed 62 virtual SkTypeface* readTypeface() SK_OVERRIDE; 63 64 virtual bool validate(bool isValid) SK_OVERRIDE; 65 virtual bool isValid() const SK_OVERRIDE; 66 67 virtual bool validateAvailable(size_t size) SK_OVERRIDE; 68 69 private: 70 bool readArray(void* value, size_t size, size_t elementSize); 71 72 void setMemory(const void* data, size_t size); 73 74 static bool IsPtrAlign4(const void* ptr) { 75 return SkIsAlign4((uintptr_t)ptr); 76 } 77 78 bool fError; 79 80 typedef SkReadBuffer INHERITED; 81 }; 82 83 #endif // SkValidatingReadBuffer_DEFINED 84