Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: cc/surfaces/surface_id.h

Issue 2136413002: Update Surface ID Terminology (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix webkit_unit_tests Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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() : gpu_id_(0), client_id_(0), local_id_(0), nonce_(0) {}
22 22
23 SurfaceId(const SurfaceId& other) 23 SurfaceId(const SurfaceId& other) = default;
24 : id_namespace_(other.id_namespace_),
25 local_id_(other.local_id_),
26 nonce_(other.nonce_) {}
27 24
28 // A SurfaceId consists of three components: namespace, local Id, and nonce. 25 // A SurfaceId consists of three components: namespace, local Id, and nonce.
29 // An |id_namespace| is a display compositor service allocated ID that 26 // An |client_id| is a display compositor service allocated ID that
30 // uniquely identifies a client. 27 // uniquely identifies a client.
31 // A |local_id| is a sequentially allocated ID generated by the display 28 // A |local_id| is a sequentially allocated ID generated by the display
32 // compositor client. 29 // compositor client.
33 // A |nonce| is a cryptographically secure random int that makes a SurfaceId 30 // A |nonce| is a cryptographically secure random int that makes a SurfaceId
34 // unguessable by other clients. 31 // unguessable by other clients.
35 SurfaceId(uint32_t id_namespace, uint32_t local_id, uint64_t nonce) 32 SurfaceId(uint32_t gpu_id,
36 : id_namespace_(id_namespace), local_id_(local_id), nonce_(nonce) {} 33 uint32_t client_id,
34 uint32_t local_id,
35 uint64_t nonce)
36 : gpu_id_(gpu_id),
37 client_id_(client_id),
38 local_id_(local_id),
39 nonce_(nonce) {}
37 40
38 bool is_null() const { 41 bool is_null() const {
39 return id_namespace_ == 0 && nonce_ == 0 && local_id_ == 0; 42 return gpu_id_ == 0 && client_id_ == 0 && nonce_ == 0 && local_id_ == 0;
40 } 43 }
41 44
42 size_t hash() const { 45 size_t hash() const {
43 size_t interim = base::HashInts(id_namespace_, local_id_); 46 size_t first = base::HashInts(gpu_id_, client_id_);
44 return base::HashInts(static_cast<uint64_t>(interim), nonce_); 47 size_t second = base::HashInts(static_cast<uint64_t>(local_id_), nonce_);
48 return base::HashInts(first, second);
45 } 49 }
46 50
47 uint32_t id_namespace() const { return id_namespace_; } 51 uint32_t gpu_id() const { return gpu_id_; }
52
53 uint32_t client_id() const { return client_id_; }
48 54
49 uint32_t local_id() const { return local_id_; } 55 uint32_t local_id() const { return local_id_; }
50 56
51 uint64_t nonce() const { return nonce_; } 57 uint64_t nonce() const { return nonce_; }
52 58
53 std::string ToString() const { 59 std::string ToString() const {
54 return base::StringPrintf("%d:%d:%" PRIu64, id_namespace_, local_id_, 60 return base::StringPrintf("%d:%d:%d:%" PRIu64, gpu_id_, client_id_,
55 nonce_); 61 local_id_, nonce_);
56 } 62 }
57 63
58 bool operator==(const SurfaceId& other) const { 64 bool operator==(const SurfaceId& other) const {
59 return id_namespace_ == other.id_namespace_ && 65 return gpu_id_ == other.gpu_id_ && client_id_ == other.client_id_ &&
60 local_id_ == other.local_id_ && nonce_ == other.nonce_; 66 local_id_ == other.local_id_ && nonce_ == other.nonce_;
61 } 67 }
62 68
63 bool operator!=(const SurfaceId& other) const { return !(*this == other); } 69 bool operator!=(const SurfaceId& other) const { return !(*this == other); }
64 70
65 bool operator<(const SurfaceId& other) const { 71 bool operator<(const SurfaceId& other) const {
66 return std::tie(id_namespace_, local_id_, nonce_) < 72 return std::tie(gpu_id_, client_id_, local_id_, nonce_) <
67 std::tie(other.id_namespace_, other.local_id_, other.nonce_); 73 std::tie(other.gpu_id_, other.client_id_, other.local_id_,
74 other.nonce_);
68 } 75 }
69 76
70 private: 77 private:
71 // See SurfaceIdAllocator::GenerateId. 78 // See SurfaceIdAllocator::GenerateId.
72 uint32_t id_namespace_; 79 uint32_t gpu_id_;
80 uint32_t client_id_;
73 uint32_t local_id_; 81 uint32_t local_id_;
74 uint64_t nonce_; 82 uint64_t nonce_;
piman 2016/07/12 20:57:19 nit: can we order the fields so that it's more com
Fady Samuel 2016/07/12 22:45:34 tsepez@ preferred nonce at the end for readability
piman 2016/07/12 22:47:50 ok - it doesn't matter any more.
75 }; 83 };
76 84
77 struct SurfaceIdHash { 85 struct SurfaceIdHash {
78 size_t operator()(const SurfaceId& key) const { return key.hash(); } 86 size_t operator()(const SurfaceId& key) const { return key.hash(); }
79 }; 87 };
80 88
81 } // namespace cc 89 } // namespace cc
82 90
83 #endif // CC_SURFACES_SURFACE_ID_H_ 91 #endif // CC_SURFACES_SURFACE_ID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698