2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkValidatingReadBuffer_DEFINED
9 #define SkValidatingReadBuffer_DEFINED
12 #include "SkBitmapHeap.h"
13 #include "SkReadBuffer.h"
14 #include "SkWriteBuffer.h"
16 #include "SkPicture.h"
17 #include "SkReader32.h"
21 class SkValidatingReadBuffer : public SkReadBuffer {
23 SkValidatingReadBuffer(const void* data, size_t size);
24 virtual ~SkValidatingReadBuffer();
26 const void* skip(size_t size) SK_OVERRIDE;
29 bool readBool() SK_OVERRIDE;
30 SkColor readColor() SK_OVERRIDE;
31 SkFixed readFixed() SK_OVERRIDE;
32 int32_t readInt() SK_OVERRIDE;
33 SkScalar readScalar() SK_OVERRIDE;
34 uint32_t readUInt() SK_OVERRIDE;
35 int32_t read32() SK_OVERRIDE;
37 // strings -- the caller is responsible for freeing the string contents
38 void readString(SkString* string) SK_OVERRIDE;
39 void* readEncodedString(size_t* length, SkPaint::TextEncoding encoding) SK_OVERRIDE;
41 // common data structures
42 SkFlattenable* readFlattenable(SkFlattenable::Type type) SK_OVERRIDE;
43 void skipFlattenable() SK_OVERRIDE;
44 void readPoint(SkPoint* point) SK_OVERRIDE;
45 void readMatrix(SkMatrix* matrix) SK_OVERRIDE;
46 void readIRect(SkIRect* rect) SK_OVERRIDE;
47 void readRect(SkRect* rect) SK_OVERRIDE;
48 void readRegion(SkRegion* region) SK_OVERRIDE;
49 void readPath(SkPath* path) SK_OVERRIDE;
51 // binary data and arrays
52 bool readByteArray(void* value, size_t size) SK_OVERRIDE;
53 bool readColorArray(SkColor* colors, size_t size) SK_OVERRIDE;
54 bool readIntArray(int32_t* values, size_t size) SK_OVERRIDE;
55 bool readPointArray(SkPoint* points, size_t size) SK_OVERRIDE;
56 bool readScalarArray(SkScalar* values, size_t size) SK_OVERRIDE;
58 // helpers to get info about arrays and binary data
59 uint32_t getArrayCount() SK_OVERRIDE;
61 // TODO: Implement this (securely) when needed
62 SkTypeface* readTypeface() SK_OVERRIDE;
64 bool validate(bool isValid) SK_OVERRIDE;
65 bool isValid() const SK_OVERRIDE;
67 bool validateAvailable(size_t size) SK_OVERRIDE;
70 bool readArray(void* value, size_t size, size_t elementSize);
72 void setMemory(const void* data, size_t size);
74 static bool IsPtrAlign4(const void* ptr) {
75 return SkIsAlign4((uintptr_t)ptr);
80 typedef SkReadBuffer INHERITED;
83 #endif // SkValidatingReadBuffer_DEFINED