| Index: include/core/SkFlattenableBuffers.h
|
| diff --git a/include/core/SkFlattenableBuffers.h b/include/core/SkFlattenableBuffers.h
|
| index 03c03f3877e6f8e3f508d29e371d5c7ebd91624e..53d1c13023a2fa55001b50ad735cb6ad1a9ad9d8 100644
|
| --- a/include/core/SkFlattenableBuffers.h
|
| +++ b/include/core/SkFlattenableBuffers.h
|
| @@ -41,14 +41,20 @@ public:
|
| kCrossProcess_Flag = 1 << 0,
|
| kScalarIsFloat_Flag = 1 << 1,
|
| kPtrIs64Bit_Flag = 1 << 2,
|
| + /** The kValidation_Flag is used to force stream validations (by making
|
| + * sure that no operation reads past the end of the stream, for example)
|
| + * and error handling if any reading operation yields an invalid value.
|
| + */
|
| + kValidation_Flag = 1 << 3,
|
| };
|
|
|
| void setFlags(uint32_t flags) { fFlags = flags; }
|
| uint32_t getFlags() const { return fFlags; }
|
|
|
| - bool isCrossProcess() const { return SkToBool(fFlags & kCrossProcess_Flag); }
|
| + bool isCrossProcess() const { return SkToBool(fFlags & (kCrossProcess_Flag | kValidation_Flag)); }
|
| bool isScalarFloat() const { return SkToBool(fFlags & kScalarIsFloat_Flag); }
|
| bool isPtr64Bit() const { return SkToBool(fFlags & kPtrIs64Bit_Flag); }
|
| + bool isValidating() const { return SkToBool(fFlags & kValidation_Flag); }
|
|
|
| // primitives
|
| virtual bool readBool() = 0;
|
| @@ -64,7 +70,16 @@ public:
|
| virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encoding) = 0;
|
|
|
| // common data structures
|
| - virtual SkFlattenable* readFlattenable() = 0;
|
| + virtual SkFlattenable* readFlattenable(
|
| + /**
|
| + @param type This parameter is only used when using SkValidatingReadBuffer. It will verify
|
| + that the object about to be deserialized is of the given type or early return
|
| + NULL otherwise. The type provided here is either the same type or the type of
|
| + one of the base classes of the object to deserialize. This can effectively be
|
| + bypassed by providing the type SkFlattenable::GetTypeName() here, since
|
| + SkFlattenable is a base class to all other classes that can be deserialized.
|
| + */
|
| + const char* name = SkFlattenable::GetTypeName()) = 0;
|
| virtual void readPoint(SkPoint* point) = 0;
|
| virtual void readMatrix(SkMatrix* matrix) = 0;
|
| virtual void readIRect(SkIRect* rect) = 0;
|
| @@ -99,9 +114,11 @@ public:
|
| }
|
|
|
| template <typename T> T* readFlattenableT() {
|
| - return static_cast<T*>(this->readFlattenable());
|
| + return static_cast<T*>(this->readFlattenable(T::GetTypeName()));
|
| }
|
|
|
| + virtual void validate(bool isValid) SK_OVERRIDE {}
|
| +
|
| private:
|
| uint32_t fFlags;
|
| };
|
| @@ -154,13 +171,22 @@ public:
|
|
|
| enum Flags {
|
| kCrossProcess_Flag = 0x01,
|
| + /** The kValidation_Flag is used here to make sure the write operation
|
| + * is symmetric with the read operation using the equivalent flag
|
| + * SkFlattenableReadBuffer::kValidation_Flag.
|
| + */
|
| + kValidation_Flag = 0x02,
|
| };
|
|
|
| uint32_t getFlags() const { return fFlags; }
|
| void setFlags(uint32_t flags) { fFlags = flags; }
|
|
|
| bool isCrossProcess() const {
|
| - return SkToBool(fFlags & kCrossProcess_Flag);
|
| + return SkToBool(fFlags & (kCrossProcess_Flag | kValidation_Flag));
|
| + }
|
| +
|
| + bool isValidating() const {
|
| + return SkToBool(fFlags & kValidation_Flag);
|
| }
|
|
|
| bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; }
|
|
|