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

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

Issue 2382873002: Replace usage of SurfaceId's client_id with FrameSinkId (Closed)
Patch Set: Fixed windows + android + mac issues Created 4 years, 2 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 #include "cc/surfaces/frame_sink_id.h"
16 17
17 namespace cc { 18 namespace cc {
18 19
19 class SurfaceId { 20 class SurfaceId {
20 public: 21 public:
21 SurfaceId() : client_id_(0), local_id_(0), nonce_(0) {} 22 SurfaceId() : local_id_(0), nonce_(0) {}
22 23
23 SurfaceId(const SurfaceId& other) 24 SurfaceId(const SurfaceId& other)
24 : client_id_(other.client_id_), 25 : frame_sink_id_(other.frame_sink_id_),
25 local_id_(other.local_id_), 26 local_id_(other.local_id_),
26 nonce_(other.nonce_) {} 27 nonce_(other.nonce_) {}
27 28
28 // A SurfaceId consists of three components: client Id, local Id, and nonce. 29 // A SurfaceId consists of three components: client Id, local Id, and nonce.
29 // A |client_id| is a display compositor service allocated ID that 30 // A |client_id| is a display compositor service allocated ID that
30 // uniquely identifies a client. 31 // uniquely identifies a client.
31 // A |local_id| is a sequentially allocated ID generated by the display 32 // A |local_id| is a sequentially allocated ID generated by the display
32 // compositor client that uniquely identifies a surface. 33 // compositor client that uniquely identifies a surface.
33 // A |nonce| is a cryptographically secure random int that makes a SurfaceId 34 // A |nonce| is a cryptographically secure random int that makes a SurfaceId
34 // unguessable by other clients. 35 // unguessable by other clients.
35 SurfaceId(uint32_t client_id, uint32_t local_id, uint64_t nonce) 36 SurfaceId(const FrameSinkId& frame_sink_id, uint32_t local_id, uint64_t nonce)
36 : client_id_(client_id), local_id_(local_id), nonce_(nonce) {} 37 : frame_sink_id_(frame_sink_id), local_id_(local_id), nonce_(nonce) {}
37 38
38 bool is_null() const { 39 bool is_null() const {
39 return client_id_ == 0 && nonce_ == 0 && local_id_ == 0; 40 return frame_sink_id_.is_null() && nonce_ == 0 && local_id_ == 0;
40 } 41 }
41 42
42 size_t hash() const { 43 size_t hash() const {
43 size_t interim = base::HashInts(client_id_, local_id_); 44 size_t interim = base::HashInts(local_id_, nonce_);
44 return base::HashInts(static_cast<uint64_t>(interim), nonce_); 45 return base::HashInts(frame_sink_id_.hash(),
46 static_cast<uint64_t>(interim));
45 } 47 }
46 48
47 uint32_t client_id() const { return client_id_; } 49 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; }
48 50
49 uint32_t local_id() const { return local_id_; } 51 uint32_t local_id() const { return local_id_; }
50 52
51 uint64_t nonce() const { return nonce_; } 53 uint64_t nonce() const { return nonce_; }
52 54
53 std::string ToString() const { 55 std::string ToString() const {
54 return base::StringPrintf("%d:%d:%" PRIu64, client_id_, local_id_, nonce_); 56 return base::StringPrintf("%s:LocalId(%d, %" PRIu64 ")",
57 frame_sink_id_.ToString().c_str(), local_id_,
58 nonce_);
55 } 59 }
56 60
57 bool operator==(const SurfaceId& other) const { 61 bool operator==(const SurfaceId& other) const {
58 return client_id_ == other.client_id_ && local_id_ == other.local_id_ && 62 return frame_sink_id_ == other.frame_sink_id_ &&
59 nonce_ == other.nonce_; 63 local_id_ == other.local_id_ && nonce_ == other.nonce_;
60 } 64 }
61 65
62 bool operator!=(const SurfaceId& other) const { return !(*this == other); } 66 bool operator!=(const SurfaceId& other) const { return !(*this == other); }
63 67
64 bool operator<(const SurfaceId& other) const { 68 bool operator<(const SurfaceId& other) const {
65 return std::tie(client_id_, local_id_, nonce_) < 69 return std::tie(frame_sink_id_, local_id_, nonce_) <
66 std::tie(other.client_id_, other.local_id_, other.nonce_); 70 std::tie(frame_sink_id_, other.local_id_, other.nonce_);
67 } 71 }
68 72
69 private: 73 private:
70 // See SurfaceIdAllocator::GenerateId. 74 // See SurfaceIdAllocator::GenerateId.
71 uint32_t client_id_; 75 FrameSinkId frame_sink_id_;
72 uint32_t local_id_; 76 uint32_t local_id_;
73 uint64_t nonce_; 77 uint64_t nonce_;
74 }; 78 };
75 79
76 struct SurfaceIdHash { 80 struct SurfaceIdHash {
77 size_t operator()(const SurfaceId& key) const { return key.hash(); } 81 size_t operator()(const SurfaceId& key) const { return key.hash(); }
78 }; 82 };
79 83
80 } // namespace cc 84 } // namespace cc
81 85
82 #endif // CC_SURFACES_SURFACE_ID_H_ 86 #endif // CC_SURFACES_SURFACE_ID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698