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