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 #include "base/hash.h" | |
| 14 | |
| 13 namespace cc { | 15 namespace cc { |
| 14 | 16 |
| 15 struct SurfaceId { | 17 struct SurfaceId { |
| 16 SurfaceId() : id(0) {} | 18 SurfaceId() : id_namespace(0), local_id(0) {} |
| 17 explicit SurfaceId(uint64_t id) : id(id) {} | 19 SurfaceId(const SurfaceId& other) |
| 20 : id_namespace(other.id_namespace), local_id(other.local_id) {} | |
| 21 SurfaceId(uint32_t id_namespace, uint64_t local_id) | |
| 22 : id_namespace(id_namespace), local_id(local_id) {} | |
| 18 | 23 |
| 19 bool is_null() const { return id == 0; } | 24 bool is_null() const { return id_namespace == 0 && local_id == 0; } |
| 20 | 25 |
| 21 // See SurfaceIdAllocator::GenerateId. | 26 // See SurfaceIdAllocator::GenerateId. |
| 22 uint32_t id_namespace() const { return id >> 32; } | 27 uint32_t id_namespace; |
| 23 | 28 uint64_t local_id; |
| 24 uint64_t id; | |
| 25 }; | 29 }; |
| 26 | 30 |
| 27 inline bool operator==(const SurfaceId& a, const SurfaceId& b) { | 31 inline bool operator==(const SurfaceId& a, const SurfaceId& b) { |
| 28 return a.id == b.id; | 32 return (a.id_namespace == b.id_namespace) && (a.local_id == b.local_id); |
|
Tom Sepez
2016/05/20 20:22:02
nit: overparenthesized, also line 40
Fady Samuel
2016/05/24 20:33:07
Done. I've switched to if statements for readabili
| |
| 29 } | 33 } |
| 30 | 34 |
| 31 inline bool operator!=(const SurfaceId& a, const SurfaceId& b) { | 35 inline bool operator!=(const SurfaceId& a, const SurfaceId& b) { |
| 32 return !(a == b); | 36 return !(a == b); |
| 33 } | 37 } |
| 34 | 38 |
| 35 inline bool operator<(const SurfaceId& a, const SurfaceId& b) { | 39 inline bool operator<(const SurfaceId& a, const SurfaceId& b) { |
| 36 return a.id < b.id; | 40 return (a.id_namespace < b.id_namespace) || |
| 41 ((a.id_namespace == b.id_namespace) && (a.local_id < b.local_id)); | |
| 37 } | 42 } |
| 38 | 43 |
| 39 struct SurfaceIdHash { | 44 struct SurfaceIdHash { |
| 40 size_t operator()(const SurfaceId& key) const { | 45 size_t operator()(const SurfaceId& key) const { |
| 41 return std::hash<uint64_t>()(key.id); | 46 return base::HashInts64(key.id_namespace, key.local_id); |
|
danakj
2016/05/20 21:01:36
Just use HashInts() it picks the right function.
Fady Samuel
2016/05/24 20:33:07
Done.
| |
| 42 } | 47 } |
| 43 }; | 48 }; |
| 44 | 49 |
| 45 } // namespace cc | 50 } // namespace cc |
| 46 | 51 |
| 47 #endif // CC_SURFACES_SURFACE_ID_H_ | 52 #endif // CC_SURFACES_SURFACE_ID_H_ |
| OLD | NEW |