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

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

Issue 2388753003: Introduce cc::LocalFrameId and use in SurfaceFactory (Closed)
Patch Set: Fix exo_unittests 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 #include "cc/surfaces/frame_sink_id.h"
17 #include "cc/surfaces/local_frame_id.h"
17 18
18 namespace cc { 19 namespace cc {
19 20
20 class SurfaceId { 21 class SurfaceId {
21 public: 22 public:
22 SurfaceId() : local_id_(0), nonce_(0) {} 23 SurfaceId() = default;
23 24
24 SurfaceId(const SurfaceId& other) 25 SurfaceId(const SurfaceId& other)
25 : frame_sink_id_(other.frame_sink_id_), 26 : frame_sink_id_(other.frame_sink_id_),
26 local_id_(other.local_id_), 27 local_frame_id_(other.local_frame_id_) {}
27 nonce_(other.nonce_) {}
28 28
29 // A SurfaceId consists of three components: FrameSinkId, local Id, and nonce. 29 // A SurfaceId consists of three components: FrameSinkId, local Id, and nonce.
30 // A |frame_sink_id| consists of two components; one is allocated by the 30 // A |frame_sink_id| consists of two components; one is allocated by the
31 // display compositor service and one is allocated by the client. The 31 // display compositor service and one is allocated by the client. The
32 // |frame_sink_id| uniquely identifies a FrameSink (and frame source). 32 // |frame_sink_id| uniquely identifies a FrameSink (and frame source).
33 // A |local_id| is a sequentially allocated ID generated by the frame source 33 // A |local_id| is a sequentially allocated ID generated by the frame source
34 // that uniquely identifies a sequential set of frames of the same size and 34 // that uniquely identifies a sequential set of frames of the same size and
35 // device scale factor. 35 // device scale factor.
36 // A |nonce| is a cryptographically secure unguessable token that makes it 36 // A |nonce| is a cryptographically secure unguessable token that makes it
37 // impossible for an unprivileged frame source to embed another frame source 37 // impossible for an unprivileged frame source to embed another frame source
38 // without being explicitly given the surface ID of that frame source from a 38 // without being explicitly given the surface ID of that frame source from a
39 // privileged process. 39 // privileged process.
40 SurfaceId(const FrameSinkId& frame_sink_id, uint32_t local_id, uint64_t nonce) 40 SurfaceId(const FrameSinkId& frame_sink_id,
41 : frame_sink_id_(frame_sink_id), local_id_(local_id), nonce_(nonce) {} 41 const LocalFrameId& local_frame_id)
42 : frame_sink_id_(frame_sink_id), local_frame_id_(local_frame_id) {}
42 43
43 bool is_null() const { 44 bool is_null() const {
44 return frame_sink_id_.is_null() && nonce_ == 0 && local_id_ == 0; 45 return frame_sink_id_.is_null() && local_frame_id_.is_null();
45 } 46 }
46 47
47 size_t hash() const { 48 size_t hash() const {
48 size_t interim = base::HashInts(local_id_, nonce_);
49 return base::HashInts(static_cast<uint64_t>(frame_sink_id_.hash()), 49 return base::HashInts(static_cast<uint64_t>(frame_sink_id_.hash()),
50 static_cast<uint64_t>(interim)); 50 static_cast<uint64_t>(local_frame_id_.hash()));
51 } 51 }
52 52
53 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; } 53 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; }
54 54
55 uint32_t local_id() const { return local_id_; } 55 const LocalFrameId& local_frame_id() const { return local_frame_id_; }
56
57 uint64_t nonce() const { return nonce_; }
58 56
59 std::string ToString() const { 57 std::string ToString() const {
60 return base::StringPrintf("%s:LocalId(%d, %" PRIu64 ")", 58 return base::StringPrintf("SurfaceId(%s, %s)",
61 frame_sink_id_.ToString().c_str(), local_id_, 59 frame_sink_id_.ToString().c_str(),
62 nonce_); 60 local_frame_id_.ToString().c_str());
63 } 61 }
64 62
65 bool operator==(const SurfaceId& other) const { 63 bool operator==(const SurfaceId& other) const {
66 return frame_sink_id_ == other.frame_sink_id_ && 64 return frame_sink_id_ == other.frame_sink_id_ &&
67 local_id_ == other.local_id_ && nonce_ == other.nonce_; 65 local_frame_id_ == other.local_frame_id_;
68 } 66 }
69 67
70 bool operator!=(const SurfaceId& other) const { return !(*this == other); } 68 bool operator!=(const SurfaceId& other) const { return !(*this == other); }
71 69
72 bool operator<(const SurfaceId& other) const { 70 bool operator<(const SurfaceId& other) const {
73 return std::tie(frame_sink_id_, local_id_, nonce_) < 71 return std::tie(frame_sink_id_, local_frame_id_) <
74 std::tie(frame_sink_id_, other.local_id_, other.nonce_); 72 std::tie(other.frame_sink_id_, other.local_frame_id_);
75 } 73 }
76 74
77 private: 75 private:
78 // See SurfaceIdAllocator::GenerateId. 76 // See SurfaceIdAllocator::GenerateId.
79 FrameSinkId frame_sink_id_; 77 FrameSinkId frame_sink_id_;
80 uint32_t local_id_; 78 LocalFrameId local_frame_id_;
81 uint64_t nonce_;
82 }; 79 };
83 80
84 struct SurfaceIdHash { 81 struct SurfaceIdHash {
85 size_t operator()(const SurfaceId& key) const { return key.hash(); } 82 size_t operator()(const SurfaceId& key) const { return key.hash(); }
86 }; 83 };
87 84
88 } // namespace cc 85 } // namespace cc
89 86
90 #endif // CC_SURFACES_SURFACE_ID_H_ 87 #endif // CC_SURFACES_SURFACE_ID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698