Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: src/core/SkValue.h

Issue 1604253002: SkValue: implementation, unit test (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-01-20 (Wednesday) 07:22:07 EST Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
14 class SkValue { 16 class SkValue {
15 public: 17 public:
16 enum Type : uint32_t { 18 enum Type : uint32_t {
17 // 0-255 are reserved for built-in SkValue types. 19 // 0-255 are reserved for built-in SkValue types.
18 Null, 20 Null,
19 Byte , S16 , U16 , S32 , U32 , S64 , U64 , F32 , F64 , 21 Byte , S16 , U16 , S32 , U32 , S64 , U64 , F32 , F64 ,
20 Bytes, S16s, U16s, S32s, U32s, S64s, U64s, F32s, F64s, 22 Bytes, S16s, U16s, S32s, U32s, S64s, U64s, F32s, F64s,
21 Array, 23 Array,
22 24
25 kMaxBuiltin = 0xFF,
23 // 256-2147483647 may be used by Skia for public Object types. 26 // 256-2147483647 may be used by Skia for public Object types.
24 27
28 Matrix,
25 29
26 // 2147483648+ won't be used by Skia. They're open for client-specific use, testing, etc. 30 kMaxPublicObject = 0x7FFFFFFF,
31 // 2147483648+ won't be used by Skia. They're open for
32 // client-specific use, testing, etc.
27 }; 33 };
28 34
29 enum Key : uint32_t { 35 // Each Object type may define its own namespace of Key values,
30 // Each Object type may define its own namespace of Key values, 36 // so there are no pre-defined Keys here.
31 // so there are no pre-defined Keys here. 37 //
32 // 38 // 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, 39 // 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) . 40 typedef uint32_t Key;
35 };
36 41
37 SkValue(); 42 SkValue();
38 SkValue(const SkValue&); 43 SkValue(const SkValue&);
39 SkValue(SkValue&&); 44 SkValue(SkValue&&);
40 45
41 SkValue& operator=(const SkValue&); 46 SkValue& operator=(const SkValue&);
42 SkValue& operator=(SkValue&&); 47 SkValue& operator=(SkValue&&);
43 48
44 ~SkValue(); 49 ~SkValue();
45 50
46 static SkValue FromS32(int32_t); 51 static SkValue FromS32(int32_t);
47 static SkValue FromU32(uint32_t); 52 static SkValue FromU32(uint32_t);
48 static SkValue FromF32(float); 53 static SkValue FromF32(float);
49 static SkValue FromBytes(const void*, size_t); // Copies. 54 static SkValue FromBytes(SkData*);
55 static SkValue FromU16s(SkData*);
56 static SkValue FromU32s(SkData*);
57 static SkValue FromF32s(SkData*);
58 static SkValue ValueArray();
50 static SkValue Object(Type); 59 static SkValue Object(Type);
51 60
52 Type type() const; 61 Type type() const { return fType; }
53 62
54 // These remaining methods may assert they're called on a value of the appro priate type. 63 // These remaining methods may assert they're called on a value of the appro priate type.
55 64
56 int32_t s32() const; 65 int32_t s32() const;
57 uint32_t u32() const; 66 uint32_t u32() const;
58 float f32() const; 67 float f32() const;
68 SkData* bytes() const;
69 bool isData() const {
mtklein 2016/01/20 14:20:59 private?
hal.canary 2016/01/20 15:14:35 done
70 return Bytes == fType || U16s == fType || U32s == fType || F32s == fType ;
71 }
72 const uint16_t* u16s(int* count) const;
73 const uint32_t* u32s(int* count) const;
74 const float* f32s(int* count) const;
59 75
60 const void* bytes() const; 76 // Object
61 size_t count() const; 77 bool isObject() const { return fType > kMaxBuiltin; }
mtklein 2016/01/20 14:20:59 private?
hal.canary 2016/01/20 15:14:35 done
62
63 void set(Key, SkValue); 78 void set(Key, SkValue);
64 const SkValue* get(Key) const;
65 void foreach(std::function<void(Key, const SkValue&)>) const; 79 void foreach(std::function<void(Key, const SkValue&)>) const;
66 80
81 // Array
82 size_t length() const;
83 const SkValue& at(size_t) const;
84 void append(SkValue);
85
86 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.
87 template <typename T> static bool Decode(const SkValue&, T*);
88
67 private: 89 private:
68 class Bytes; 90 class Obj;
69 class Object; 91 class Arr;
70 92
71 Type fType; 93 Type fType;
72 union { 94 union {
73 int32_t fS32; 95 int32_t fS32;
74 uint32_t fU32; 96 uint32_t fU32;
75 float fF32; 97 float fF32;
76 class Bytes* fBytes; 98 SkData* fBytes;
77 class Object* fObject; 99 Obj* fObject;
100 Arr* fArray;
78 }; 101 };
79 }; 102 };
80 103
81 #endif//SkValue_DEFINED 104 #endif // SkValue_DEFINED
OLDNEW
« no previous file with comments | « gyp/core.gypi ('k') | src/core/SkValue.cpp » ('j') | src/core/SkValue.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698