OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkValue_DEFINED | 8 #ifndef SkValue_DEFINED |
9 #define SkValue_DEFINED | 9 #define SkValue_DEFINED |
10 | 10 |
11 #include "SkTypes.h" | 11 #include "SkTypes.h" |
12 #include <functional> | 12 #include <functional> |
13 | 13 |
14 class SkData; | |
15 | |
16 #define SK_VALUE_OBJECT_TYPES(M) \ | |
17 M(ArithmeticXfermode) \ | |
18 M(LerpXfermode) \ | |
19 M(OverdrawXfermode) \ | |
20 M(PixelXorXfermode) \ | |
21 M(ProcCoeffXfermode) | |
22 | |
14 class SkValue { | 23 class SkValue { |
15 public: | 24 public: |
16 enum Type : uint32_t { | 25 enum Type : uint32_t { |
17 // 0-255 are reserved for built-in SkValue types. | 26 // 0-255 are reserved for built-in SkValue types. |
18 Null, | 27 Null, |
19 Byte , S16 , U16 , S32 , U32 , S64 , U64 , F32 , F64 , | 28 Byte , S16 , U16 , S32 , U32 , S64 , U64 , F32 , F64 , |
20 Bytes, S16s, U16s, S32s, U32s, S64s, U64s, F32s, F64s, | 29 Bytes, S16s, U16s, S32s, U32s, S64s, U64s, F32s, F64s, |
21 Array, | 30 Array, |
22 | 31 |
32 kMaxBuiltin = 0xFF, | |
33 | |
23 // 256-2147483647 may be used by Skia for public Object types. | 34 // 256-2147483647 may be used by Skia for public Object types. |
24 | 35 #define FN(TYPE) TYPE, |
36 SK_VALUE_OBJECT_TYPES(FN) | |
37 #undef FN | |
25 | 38 |
26 // 2147483648+ won't be used by Skia. They're open for client-specific use, testing, etc. | 39 // 2147483648+ won't be used by Skia. They're open for client-specific use, testing, etc. |
27 }; | 40 }; |
28 | 41 |
29 enum Key : uint32_t { | 42 // Each Object type may define its own namespace of Key values, |
30 // Each Object type may define its own namespace of Key values, | 43 // so there are no pre-defined Keys here. |
31 // so there are no pre-defined Keys here. | 44 // |
32 // | 45 // This is just a reminder that they must fit in a uint32_t, |
33 // This is just a reminder that they must fit in a uint32_t, | 46 // and that their namespace is distinct from other uint32_ts (e.g. Type). |
34 // and that their namespace is distinct from other uint32_ts (e.g. Type) . | 47 typedef uint32_t Key; |
35 }; | |
36 | 48 |
37 SkValue(); | 49 SkValue(); |
38 SkValue(const SkValue&); | 50 SkValue(const SkValue&); |
39 SkValue(SkValue&&); | 51 SkValue(SkValue&&); |
40 | 52 |
41 SkValue& operator=(const SkValue&); | 53 SkValue& operator=(const SkValue&); |
42 SkValue& operator=(SkValue&&); | 54 SkValue& operator=(SkValue&&); |
43 | 55 |
44 ~SkValue(); | 56 ~SkValue(); |
45 | 57 |
46 static SkValue FromS32(int32_t); | 58 static SkValue FromS32(int32_t); |
47 static SkValue FromU32(uint32_t); | 59 static SkValue FromU32(uint32_t); |
48 static SkValue FromF32(float); | 60 static SkValue FromF32(float); |
49 static SkValue FromBytes(const void*, size_t); // Copies. | 61 static SkValue FromBytes(const void*, size_t); // Copies. |
50 static SkValue Object(Type); | 62 static SkValue Object(Type); |
51 | 63 |
52 Type type() const; | 64 Type type() const; |
53 | 65 |
54 // These remaining methods may assert they're called on a value of the appro priate type. | 66 // These remaining methods may assert they're called on a value of the appro priate type. |
55 | 67 |
56 int32_t s32() const; | 68 int32_t s32() const; |
57 uint32_t u32() const; | 69 uint32_t u32() const; |
58 float f32() const; | 70 float f32() const; |
59 | 71 |
60 const void* bytes() const; | 72 const void* bytes() const; |
61 size_t count() const; | 73 size_t count() const; |
62 | 74 |
63 void set(Key, SkValue); | 75 bool set(Key, SkValue); // returns true on success. |
64 const SkValue* get(Key) const; | 76 const SkValue* get(Key) const; |
65 void foreach(std::function<void(Key, const SkValue&)>) const; | 77 void foreach(std::function<void(Key, const SkValue&)>) const; |
66 | 78 |
67 private: | 79 private: |
68 class Bytes; | 80 class Obj; |
69 class Object; | |
70 | 81 |
71 Type fType; | 82 Type fType; |
72 union { | 83 union { |
73 int32_t fS32; | 84 int32_t fS32; |
74 uint32_t fU32; | 85 uint32_t fU32; |
75 float fF32; | 86 float fF32; |
76 class Bytes* fBytes; | 87 SkData* fBytes; |
77 class Object* fObject; | 88 Obj* fObject; |
78 }; | 89 }; |
90 | |
91 bool isObject() const { return fType > 0xFF; } | |
mtklein
2016/01/15 17:26:20
kMaxBuiltin?
hal.canary
2016/01/15 19:44:31
done
| |
79 }; | 92 }; |
80 | 93 |
81 #endif//SkValue_DEFINED | 94 #endif//SkValue_DEFINED |
OLD | NEW |