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/format_macros.h" | 13 #include "base/format_macros.h" |
14 #include "base/hash.h" | 14 #include "base/hash.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 | 18 |
19 class SurfaceId { | 19 class SurfaceId { |
20 public: | 20 public: |
21 SurfaceId() : id_namespace_(0), local_id_(0), nonce_(0) {} | 21 SurfaceId() : client_id_(0), local_id_(0), nonce_(0) {} |
22 | 22 |
23 SurfaceId(const SurfaceId& other) | 23 SurfaceId(const SurfaceId& other) |
24 : id_namespace_(other.id_namespace_), | 24 : client_id_(other.client_id_), |
25 local_id_(other.local_id_), | 25 local_id_(other.local_id_), |
26 nonce_(other.nonce_) {} | 26 nonce_(other.nonce_) {} |
27 | 27 |
28 // A SurfaceId consists of three components: namespace, local Id, and nonce. | 28 // A SurfaceId consists of three components: namespace, local Id, and nonce. |
dcheng
2016/07/13 01:57:48
Nit: namespace -> client ID?
Fady Samuel
2016/07/13 02:22:31
Done.
| |
29 // An |id_namespace| is a display compositor service allocated ID that | 29 // An |client_id| is a display compositor service allocated ID that |
30 // uniquely identifies a client. | 30 // uniquely identifies a client. |
31 // A |local_id| is a sequentially allocated ID generated by the display | 31 // A |local_id| is a sequentially allocated ID generated by the display |
32 // compositor client. | 32 // compositor client. |
dcheng
2016/07/13 01:57:48
Maybe mention something that local_id is unique wi
Fady Samuel
2016/07/13 02:22:31
Done.
| |
33 // A |nonce| is a cryptographically secure random int that makes a SurfaceId | 33 // A |nonce| is a cryptographically secure random int that makes a SurfaceId |
34 // unguessable by other clients. | 34 // unguessable by other clients. |
35 SurfaceId(uint32_t id_namespace, uint32_t local_id, uint64_t nonce) | 35 SurfaceId(uint32_t client_id, uint32_t local_id, uint64_t nonce) |
36 : id_namespace_(id_namespace), local_id_(local_id), nonce_(nonce) {} | 36 : client_id_(client_id), local_id_(local_id), nonce_(nonce) {} |
37 | 37 |
38 bool is_null() const { | 38 bool is_null() const { |
39 return id_namespace_ == 0 && nonce_ == 0 && local_id_ == 0; | 39 return client_id_ == 0 && nonce_ == 0 && local_id_ == 0; |
40 } | 40 } |
41 | 41 |
42 size_t hash() const { | 42 size_t hash() const { |
43 size_t interim = base::HashInts(id_namespace_, local_id_); | 43 size_t interim = base::HashInts(client_id_, local_id_); |
44 return base::HashInts(static_cast<uint64_t>(interim), nonce_); | 44 return base::HashInts(static_cast<uint64_t>(interim), nonce_); |
45 } | 45 } |
46 | 46 |
47 uint32_t id_namespace() const { return id_namespace_; } | 47 uint32_t client_id() const { return client_id_; } |
48 | 48 |
49 uint32_t local_id() const { return local_id_; } | 49 uint32_t local_id() const { return local_id_; } |
50 | 50 |
51 uint64_t nonce() const { return nonce_; } | 51 uint64_t nonce() const { return nonce_; } |
52 | 52 |
53 std::string ToString() const { | 53 std::string ToString() const { |
54 return base::StringPrintf("%d:%d:%" PRIu64, id_namespace_, local_id_, | 54 return base::StringPrintf("%d:%d:%" PRIu64, client_id_, local_id_, nonce_); |
55 nonce_); | |
56 } | 55 } |
57 | 56 |
58 bool operator==(const SurfaceId& other) const { | 57 bool operator==(const SurfaceId& other) const { |
59 return id_namespace_ == other.id_namespace_ && | 58 return client_id_ == other.client_id_ && local_id_ == other.local_id_ && |
60 local_id_ == other.local_id_ && nonce_ == other.nonce_; | 59 nonce_ == other.nonce_; |
61 } | 60 } |
62 | 61 |
63 bool operator!=(const SurfaceId& other) const { return !(*this == other); } | 62 bool operator!=(const SurfaceId& other) const { return !(*this == other); } |
64 | 63 |
65 bool operator<(const SurfaceId& other) const { | 64 bool operator<(const SurfaceId& other) const { |
66 return std::tie(id_namespace_, local_id_, nonce_) < | 65 return std::tie(client_id_, local_id_, nonce_) < |
67 std::tie(other.id_namespace_, other.local_id_, other.nonce_); | 66 std::tie(other.client_id_, other.local_id_, other.nonce_); |
68 } | 67 } |
69 | 68 |
70 private: | 69 private: |
71 // See SurfaceIdAllocator::GenerateId. | 70 // See SurfaceIdAllocator::GenerateId. |
72 uint32_t id_namespace_; | 71 uint32_t client_id_; |
73 uint32_t local_id_; | 72 uint32_t local_id_; |
74 uint64_t nonce_; | 73 uint64_t nonce_; |
75 }; | 74 }; |
76 | 75 |
77 struct SurfaceIdHash { | 76 struct SurfaceIdHash { |
78 size_t operator()(const SurfaceId& key) const { return key.hash(); } | 77 size_t operator()(const SurfaceId& key) const { return key.hash(); } |
79 }; | 78 }; |
80 | 79 |
81 } // namespace cc | 80 } // namespace cc |
82 | 81 |
83 #endif // CC_SURFACES_SURFACE_ID_H_ | 82 #endif // CC_SURFACES_SURFACE_ID_H_ |
OLD | NEW |