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

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

Issue 1589953003: sketch SkValue API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: hal 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
« no previous file with comments | « no previous file | tests/ValueTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkValue_DEFINED
9 #define SkValue_DEFINED
10
11 #include "SkTypes.h"
12 #include <functional>
13
14 class SkValue {
15 public:
16 enum Type : uint32_t {
17 // 0-255 are reserved for built-in SkValue types.
18 Null,
19 Byte , S16 , U16 , S32 , U32 , S64 , U64 , F32 , F64 ,
20 Bytes, S16s, U16s, S32s, U32s, S64s, U64s, F32s, F64s,
21 Array,
22
23 // 256-2147483647 may be used by Skia for public Object types.
24
25
26 // 2147483648+ won't be used by Skia. They're open for client-specific use, testing, etc.
27 };
28
29 enum Key : uint32_t {
30 // Each Object type may define its own namespace of Key values,
31 // so there are no pre-defined Keys here.
32 //
33 // This is just a reminder that they must fit in a uint32_t,
34 // and that their namespace is distinct from other uint32_ts (e.g. Type) .
35 };
36
37 SkValue();
38 SkValue(const SkValue&);
39 SkValue(SkValue&&);
40
41 SkValue& operator=(const SkValue&);
42 SkValue& operator=(SkValue&&);
43
44 ~SkValue();
45
46 static SkValue FromS32(int32_t);
47 static SkValue FromU32(uint32_t);
48 static SkValue FromF32(float);
49 static SkValue FromBytes(const void*, size_t); // Copies.
50 static SkValue Object(Type);
51
52 Type type() const;
53
54 // These remaining methods may assert they're called on a value of the appro priate type.
55
56 int32_t s32() const;
57 uint32_t u32() const;
58 float f32() const;
59
60 const void* bytes() const;
61 size_t count() const;
62
63 void set(Key, SkValue);
64 const SkValue* get(Key) const;
65 void foreach(std::function<void(Key, const SkValue&)>) const;
66
67 private:
68 class Bytes;
69 class Object;
70
71 Type fType;
72 union {
73 int32_t fS32;
74 uint32_t fU32;
75 float fF32;
76 class Bytes* fBytes;
77 class Object* fObject;
78 };
79 };
80
81 #endif//SkValue_DEFINED
OLDNEW
« no previous file with comments | « no previous file | tests/ValueTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698