1c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org/*
2c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org * Copyright 2013 Google Inc.
3c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org *
4c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be
5c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org * found in the LICENSE file.
6c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org */
7c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org
8c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#ifndef SkValidatingReadBuffer_DEFINED
9c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#define SkValidatingReadBuffer_DEFINED
10c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org
11c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#include "SkRefCnt.h"
12c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#include "SkBitmapHeap.h"
138b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org#include "SkReadBuffer.h"
148b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org#include "SkWriteBuffer.h"
15c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#include "SkPath.h"
16c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#include "SkPicture.h"
17c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#include "SkReader32.h"
18c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org
19c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.orgclass SkBitmap;
20c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org
218b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.orgclass SkValidatingReadBuffer : public SkReadBuffer {
22c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.orgpublic:
23c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    SkValidatingReadBuffer(const void* data, size_t size);
24c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    virtual ~SkValidatingReadBuffer();
25c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org
260951fe12984944406e0f1bb105b9fa4c54fcdcddsugoi    virtual const void* skip(size_t size) SK_OVERRIDE;
27c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org
28c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    // primitives
29c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    virtual bool readBool() SK_OVERRIDE;
30c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    virtual SkColor readColor() SK_OVERRIDE;
31c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    virtual SkFixed readFixed() SK_OVERRIDE;
32c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    virtual int32_t readInt() SK_OVERRIDE;
33c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    virtual SkScalar readScalar() SK_OVERRIDE;
34c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    virtual uint32_t readUInt() SK_OVERRIDE;
35c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    virtual int32_t read32() SK_OVERRIDE;
36c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org
37c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    // strings -- the caller is responsible for freeing the string contents
38c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    virtual void readString(SkString* string) SK_OVERRIDE;
39c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encoding) SK_OVERRIDE;
40c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org
41c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    // common data structures
42c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    virtual SkFlattenable* readFlattenable(SkFlattenable::Type type) SK_OVERRIDE;
4383f23d87f1d67e6e73873e1ef7cda621c43703a0commit-bot@chromium.org    virtual void skipFlattenable() SK_OVERRIDE;
44c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    virtual void readPoint(SkPoint* point) SK_OVERRIDE;
45c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    virtual void readMatrix(SkMatrix* matrix) SK_OVERRIDE;
46c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    virtual void readIRect(SkIRect* rect) SK_OVERRIDE;
47c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    virtual void readRect(SkRect* rect) SK_OVERRIDE;
48c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    virtual void readRegion(SkRegion* region) SK_OVERRIDE;
49c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    virtual void readPath(SkPath* path) SK_OVERRIDE;
50c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org
51c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    // binary data and arrays
52025128811219dc45fd99b6c4d1d14f833cf7a26ecommit-bot@chromium.org    virtual bool readByteArray(void* value, size_t size) SK_OVERRIDE;
53025128811219dc45fd99b6c4d1d14f833cf7a26ecommit-bot@chromium.org    virtual bool readColorArray(SkColor* colors, size_t size) SK_OVERRIDE;
54025128811219dc45fd99b6c4d1d14f833cf7a26ecommit-bot@chromium.org    virtual bool readIntArray(int32_t* values, size_t size) SK_OVERRIDE;
55025128811219dc45fd99b6c4d1d14f833cf7a26ecommit-bot@chromium.org    virtual bool readPointArray(SkPoint* points, size_t size) SK_OVERRIDE;
56025128811219dc45fd99b6c4d1d14f833cf7a26ecommit-bot@chromium.org    virtual bool readScalarArray(SkScalar* values, size_t size) SK_OVERRIDE;
57c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org
58c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    // helpers to get info about arrays and binary data
59c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    virtual uint32_t getArrayCount() SK_OVERRIDE;
60c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org
61c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    // TODO: Implement this (securely) when needed
62025128811219dc45fd99b6c4d1d14f833cf7a26ecommit-bot@chromium.org    virtual SkTypeface* readTypeface() SK_OVERRIDE;
63c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org
648f457e3230f1a4ce737f512ffbb5c919b8d02407commit-bot@chromium.org    virtual bool validate(bool isValid) SK_OVERRIDE;
65c2e9db30d393862bd3485cfe57b4ac06433f2f32commit-bot@chromium.org    virtual bool isValid() const SK_OVERRIDE;
66c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org
67ef74fa189b738e13295d6a96f86a6e10223505a8commit-bot@chromium.org    virtual bool validateAvailable(size_t size) SK_OVERRIDE;
68ef74fa189b738e13295d6a96f86a6e10223505a8commit-bot@chromium.org
69c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.orgprivate:
70025128811219dc45fd99b6c4d1d14f833cf7a26ecommit-bot@chromium.org    bool readArray(void* value, size_t size, size_t elementSize);
71025128811219dc45fd99b6c4d1d14f833cf7a26ecommit-bot@chromium.org
72c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    void setMemory(const void* data, size_t size);
73c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org
74c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    static bool IsPtrAlign4(const void* ptr) {
75c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org        return SkIsAlign4((uintptr_t)ptr);
76c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    }
77c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org
78c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org    bool fError;
79c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org
808b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org    typedef SkReadBuffer INHERITED;
81c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org};
82c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org
83c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#endif // SkValidatingReadBuffer_DEFINED
84