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, | 18 kNone, |
19 | 19 |
20 kMatrix, | 20 kMatrix, |
21 kMisc, | 21 kMisc, |
22 kPath, | 22 kPath, |
23 kStroke, | 23 kStroke, |
| 24 kXfermode, |
24 }; | 25 }; |
25 | 26 |
26 class ID { | 27 class ID { |
27 public: | 28 public: |
28 explicit ID(Type type = Type::kNone) : fVal((uint64_t)type << 56) {} | 29 explicit ID(Type type = Type::kNone) : fVal((uint64_t)type << 56) {} |
29 ID(Type type, uint64_t val) { | 30 ID(Type type, uint64_t val) { |
30 fVal = (uint64_t)type << 56 | val; | 31 fVal = (uint64_t)type << 56 | val; |
31 SkASSERT(this->type() == type && this->val() == val); | 32 SkASSERT(this->type() == type && this->val() == val); |
32 } | 33 } |
33 | 34 |
34 Type type() const { return (Type)(fVal >> 56); } | 35 Type type() const { return (Type)(fVal >> 56); } |
35 uint64_t val() const { return fVal & ~((uint64_t)0xFF << 56); } | 36 uint64_t val() const { return fVal & ~((uint64_t)0xFF << 56); } |
36 | 37 |
37 bool operator==(ID o) const { return fVal == o.fVal; } | 38 bool operator==(ID o) const { return fVal == o.fVal; } |
38 ID operator++(int) { | 39 ID operator++() { |
39 ID prev = *this; | 40 ++fVal; |
40 fVal++; | |
41 SkASSERT(this->val() != 0); // Overflow is particularly bad as it'd
change our Type. | 41 SkASSERT(this->val() != 0); // Overflow is particularly bad as it'd
change our Type. |
42 return prev; | 42 return *this; |
43 } | 43 } |
44 | 44 |
45 private: | 45 private: |
46 // High 8 bits hold a Type. Low 56 bits are unique within that Type. | 46 // High 8 bits hold a Type. Low 56 bits are unique within that Type. |
47 // Any change to this format will break protocol compatibility. | 47 // Any change to this format will break protocol compatibility. |
48 uint64_t fVal; | 48 uint64_t fVal; |
49 }; | 49 }; |
50 | 50 |
51 } // namespace SkRemote | 51 } // namespace SkRemote |
52 | 52 |
53 #endif//SkRemote_protocol_DEFINED | 53 #endif//SkRemote_protocol_DEFINED |
OLD | NEW |