Chromium Code Reviews| Index: src/core/SkValue.h |
| diff --git a/src/core/SkValue.h b/src/core/SkValue.h |
| index dd42b3a889042f5843d847225de4c66939975951..575a218b312fb4e70a9fa5d6d6ef04a0df4dcee5 100644 |
| --- a/src/core/SkValue.h |
| +++ b/src/core/SkValue.h |
| @@ -11,6 +11,8 @@ |
| #include "SkTypes.h" |
| #include <functional> |
| +class SkData; |
| + |
| class SkValue { |
| public: |
| enum Type : uint32_t { |
| @@ -20,19 +22,22 @@ public: |
| Bytes, S16s, U16s, S32s, U32s, S64s, U64s, F32s, F64s, |
| Array, |
| + kMaxBuiltin = 0xFF, |
| // 256-2147483647 may be used by Skia for public Object types. |
| + Matrix, |
| - // 2147483648+ won't be used by Skia. They're open for client-specific use, testing, etc. |
| + kMaxPublicObject = 0x7FFFFFFF, |
| + // 2147483648+ won't be used by Skia. They're open for |
| + // client-specific use, testing, etc. |
| }; |
| - enum Key : uint32_t { |
| - // Each Object type may define its own namespace of Key values, |
| - // so there are no pre-defined Keys here. |
| - // |
| - // This is just a reminder that they must fit in a uint32_t, |
| - // and that their namespace is distinct from other uint32_ts (e.g. Type). |
| - }; |
| + // Each Object type may define its own namespace of Key values, |
| + // so there are no pre-defined Keys here. |
| + // |
| + // This is just a reminder that they must fit in a uint32_t, |
| + // and that their namespace is distinct from other uint32_ts (e.g. Type). |
| + typedef uint32_t Key; |
| SkValue(); |
| SkValue(const SkValue&); |
| @@ -46,36 +51,54 @@ public: |
| static SkValue FromS32(int32_t); |
| static SkValue FromU32(uint32_t); |
| static SkValue FromF32(float); |
| - static SkValue FromBytes(const void*, size_t); // Copies. |
| + static SkValue FromBytes(SkData*); |
| + static SkValue FromU16s(SkData*); |
| + static SkValue FromU32s(SkData*); |
| + static SkValue FromF32s(SkData*); |
| + static SkValue ValueArray(); |
| static SkValue Object(Type); |
| - Type type() const; |
| + Type type() const { return fType; } |
| // These remaining methods may assert they're called on a value of the appropriate type. |
| int32_t s32() const; |
| uint32_t u32() const; |
| float f32() const; |
| - |
| - const void* bytes() const; |
| - size_t count() const; |
| - |
| + SkData* bytes() const; |
| + bool isData() const { |
|
mtklein
2016/01/20 14:20:59
private?
hal.canary
2016/01/20 15:14:35
done
|
| + return Bytes == fType || U16s == fType || U32s == fType || F32s == fType; |
| + } |
| + const uint16_t* u16s(int* count) const; |
| + const uint32_t* u32s(int* count) const; |
| + const float* f32s(int* count) const; |
| + |
| + // Object |
| + bool isObject() const { return fType > kMaxBuiltin; } |
|
mtklein
2016/01/20 14:20:59
private?
hal.canary
2016/01/20 15:14:35
done
|
| void set(Key, SkValue); |
| - const SkValue* get(Key) const; |
| void foreach(std::function<void(Key, const SkValue&)>) const; |
| + // Array |
| + size_t length() const; |
| + const SkValue& at(size_t) const; |
| + void append(SkValue); |
| + |
| + template <typename T> static SkValue Encode(const T&); |
|
mtklein
2016/01/20 14:20:59
Let's make these
template <typename T>
SkValue Sk
hal.canary
2016/01/20 15:14:35
done.
|
| + template <typename T> static bool Decode(const SkValue&, T*); |
| + |
| private: |
| - class Bytes; |
| - class Object; |
| + class Obj; |
| + class Arr; |
| Type fType; |
| union { |
| - int32_t fS32; |
| - uint32_t fU32; |
| - float fF32; |
| - class Bytes* fBytes; |
| - class Object* fObject; |
| + int32_t fS32; |
| + uint32_t fU32; |
| + float fF32; |
| + SkData* fBytes; |
| + Obj* fObject; |
| + Arr* fArray; |
| }; |
| }; |
| -#endif//SkValue_DEFINED |
| +#endif // SkValue_DEFINED |