gfx/skia/trunk/src/core/SkValidatingReadBuffer.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial