commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 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" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 12 | #include "SkReadBuffer.h" |
| 13 | #include "SkWriteBuffer.h" |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 14 | #include "SkPath.h" |
| 15 | #include "SkPicture.h" |
| 16 | #include "SkReader32.h" |
| 17 | |
| 18 | class SkBitmap; |
| 19 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 20 | class SkValidatingReadBuffer : public SkReadBuffer { |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 21 | public: |
| 22 | SkValidatingReadBuffer(const void* data, size_t size); |
robertphillips | 99e2089 | 2016-04-22 11:40:42 -0700 | [diff] [blame] | 23 | ~SkValidatingReadBuffer() override; |
| 24 | |
| 25 | SkReadBuffer* clone(const void* data, size_t size) const override { |
| 26 | return new SkValidatingReadBuffer(data, size); |
| 27 | } |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 28 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 29 | const void* skip(size_t size) override; |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 30 | |
| 31 | // primitives |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 32 | bool readBool() override; |
| 33 | SkColor readColor() override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 34 | int32_t readInt() override; |
| 35 | SkScalar readScalar() override; |
| 36 | uint32_t readUInt() override; |
| 37 | int32_t read32() override; |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 38 | |
msarett | a3b3b23 | 2016-04-22 12:43:07 -0700 | [diff] [blame] | 39 | // peek |
| 40 | uint8_t peekByte() override; |
| 41 | |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 42 | // strings -- the caller is responsible for freeing the string contents |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 43 | void readString(SkString* string) override; |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 44 | |
| 45 | // common data structures |
mtklein | 3b37545 | 2016-04-04 14:57:19 -0700 | [diff] [blame] | 46 | SkFlattenable* readFlattenable(SkFlattenable::Type type) override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 47 | void readPoint(SkPoint* point) override; |
| 48 | void readMatrix(SkMatrix* matrix) override; |
| 49 | void readIRect(SkIRect* rect) override; |
| 50 | void readRect(SkRect* rect) override; |
robertphillips | 9ca06c4 | 2016-04-20 11:43:33 -0700 | [diff] [blame] | 51 | void readRRect(SkRRect* rrect) override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 52 | void readRegion(SkRegion* region) override; |
| 53 | void readPath(SkPath* path) override; |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 54 | |
| 55 | // binary data and arrays |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 56 | bool readByteArray(void* value, size_t size) override; |
| 57 | bool readColorArray(SkColor* colors, size_t size) override; |
| 58 | bool readIntArray(int32_t* values, size_t size) override; |
| 59 | bool readPointArray(SkPoint* points, size_t size) override; |
| 60 | bool readScalarArray(SkScalar* values, size_t size) override; |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 61 | |
| 62 | // helpers to get info about arrays and binary data |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 63 | uint32_t getArrayCount() override; |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 64 | |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 65 | // TODO: Implement this (securely) when needed |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 66 | SkTypeface* readTypeface() override; |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 67 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 68 | bool validate(bool isValid) override; |
| 69 | bool isValid() const override; |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 70 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 71 | bool validateAvailable(size_t size) override; |
commit-bot@chromium.org | ef74fa1 | 2013-12-17 20:49:46 +0000 | [diff] [blame] | 72 | |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 73 | private: |
commit-bot@chromium.org | 0251288 | 2013-10-31 18:37:50 +0000 | [diff] [blame] | 74 | bool readArray(void* value, size_t size, size_t elementSize); |
| 75 | |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 76 | void setMemory(const void* data, size_t size); |
| 77 | |
| 78 | static bool IsPtrAlign4(const void* ptr) { |
| 79 | return SkIsAlign4((uintptr_t)ptr); |
| 80 | } |
| 81 | |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 82 | bool fError; |
| 83 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 84 | typedef SkReadBuffer INHERITED; |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | #endif // SkValidatingReadBuffer_DEFINED |