Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CC_SURFACES_SURFACE_ID_H_ | 5 #ifndef CC_SURFACES_SURFACE_ID_H_ |
| 6 #define CC_SURFACES_SURFACE_ID_H_ | 6 #define CC_SURFACES_SURFACE_ID_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <functional> | 11 #include <functional> |
| 12 | 12 |
| 13 namespace cc { | 13 namespace cc { |
| 14 | 14 |
| 15 struct SurfaceId { | 15 struct SurfaceId { |
| 16 SurfaceId() : id(0) {} | 16 SurfaceId() : id_namespace(0), id(0) {} |
| 17 explicit SurfaceId(uint64_t id) : id(id) {} | 17 SurfaceId(uint32_t id_namespace, uint64_t id) |
| 18 : id_namespace(id_namespace), id(id) {} | |
| 18 | 19 |
| 19 bool is_null() const { return id == 0; } | 20 bool is_null() const { return id_namespace == 0 && id == 0; } |
| 20 | 21 |
| 21 // See SurfaceIdAllocator::GenerateId. | 22 // See SurfaceIdAllocator::GenerateId. |
| 22 uint32_t id_namespace() const { return id >> 32; } | 23 uint32_t id_namespace; |
| 23 | |
| 24 uint64_t id; | 24 uint64_t id; |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 inline bool operator==(const SurfaceId& a, const SurfaceId& b) { | 27 inline bool operator==(const SurfaceId& a, const SurfaceId& b) { |
| 28 return a.id == b.id; | 28 return (a.id_namespace == a.id_namespace) && (a.id == b.id); |
| 29 } | 29 } |
| 30 | 30 |
| 31 inline bool operator!=(const SurfaceId& a, const SurfaceId& b) { | 31 inline bool operator!=(const SurfaceId& a, const SurfaceId& b) { |
| 32 return !(a == b); | 32 return !(a == b); |
| 33 } | 33 } |
| 34 | 34 |
| 35 inline bool operator<(const SurfaceId& a, const SurfaceId& b) { | 35 inline bool operator<(const SurfaceId& a, const SurfaceId& b) { |
| 36 return a.id < b.id; | 36 return (a.id_namespace < b.id_namespace) || |
| 37 (a.id_namespace == b.id_namespace && a.id < b.id); | |
| 37 } | 38 } |
| 38 | 39 |
| 39 struct SurfaceIdHash { | 40 struct SurfaceIdHash { |
| 40 size_t operator()(const SurfaceId& key) const { | 41 size_t operator()(const SurfaceId& key) const { |
| 41 return std::hash<uint64_t>()(key.id); | 42 return std::hash<uint64_t>()((key.id_namespace) | (key.id << 32)); |
|
jbauman
2016/05/20 00:29:00
Probably better to use base::HashInts64.
Fady Samuel
2016/05/20 00:40:31
Done.
| |
| 42 } | 43 } |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 } // namespace cc | 46 } // namespace cc |
| 46 | 47 |
| 47 #endif // CC_SURFACES_SURFACE_ID_H_ | 48 #endif // CC_SURFACES_SURFACE_ID_H_ |
| OLD | NEW |