OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 SkRemote_protocol_DEFINED | 8 #ifndef SkRemote_protocol_DEFINED |
9 #define SkRemote_protocol_DEFINED | 9 #define SkRemote_protocol_DEFINED |
10 | 10 |
11 // ATTENTION! Changes to this file can break protocol compatibility. Tread car
efully. | 11 // ATTENTION! Changes to this file can break protocol compatibility. Tread car
efully. |
12 | 12 |
13 namespace SkRemote { | 13 namespace SkRemote { |
14 | 14 |
15 // It is safe to append to this enum without breaking protocol compatibility
. | 15 // It is safe to append to this enum without breaking protocol compatibility
. |
16 // Resorting, deleting, or inserting anywhere but the end will break compati
bility. | 16 // Resorting, deleting, or inserting anywhere but the end will break compati
bility. |
17 enum class Type : uint8_t { | 17 enum class Type : uint8_t { |
18 kNone, | |
19 | |
20 kMatrix, | 18 kMatrix, |
21 kMisc, | 19 kMisc, |
22 kPath, | 20 kPath, |
23 kStroke, | 21 kStroke, |
24 kShader, | 22 kShader, |
25 kXfermode, | 23 kXfermode, |
26 }; | 24 }; |
27 | 25 |
28 class ID { | |
29 public: | |
30 explicit ID(Type type = Type::kNone) : fVal((uint64_t)type << 56) {} | |
31 ID(Type type, uint64_t val) { | |
32 fVal = (uint64_t)type << 56 | val; | |
33 SkASSERT(this->type() == type && this->val() == val); | |
34 } | |
35 | |
36 Type type() const { return (Type)(fVal >> 56); } | |
37 uint64_t val() const { return fVal & ~((uint64_t)0xFF << 56); } | |
38 | |
39 bool operator==(ID o) const { return fVal == o.fVal; } | |
40 ID operator++() { | |
41 ++fVal; | |
42 SkASSERT(this->val() != 0); // Overflow is particularly bad as it'd
change our Type. | |
43 return *this; | |
44 } | |
45 | |
46 private: | |
47 // High 8 bits hold a Type. Low 56 bits are unique within that Type. | |
48 // Any change to this format will break protocol compatibility. | |
49 uint64_t fVal; | |
50 }; | |
51 | |
52 } // namespace SkRemote | 26 } // namespace SkRemote |
53 | 27 |
54 #endif//SkRemote_protocol_DEFINED | 28 #endif//SkRemote_protocol_DEFINED |
OLD | NEW |