| 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 #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: FrameSinkId, local Id, and nonce. |
| 29 // A |client_id| is a display compositor service allocated ID that | 30 // A |frame_sink_id| consists of two components; one is allocated by the |
| 30 // uniquely identifies a client. | 31 // display compositor service and one is allocated by the client. The |
| 31 // A |local_id| is a sequentially allocated ID generated by the display | 32 // |frame_sink_id| uniquely identifies a FrameSink (and frame source). |
| 32 // compositor client that uniquely identifies a surface. | 33 // A |local_id| is a sequentially allocated ID generated by the frame source |
| 33 // A |nonce| is a cryptographically secure random int that makes a SurfaceId | 34 // that uniquely identifies a sequential set of frames of the same size and |
| 34 // unguessable by other clients. | 35 // device scale factor. |
| 35 SurfaceId(uint32_t client_id, uint32_t local_id, uint64_t nonce) | 36 // A |nonce| is a cryptographically secure unguessable token that makes it |
| 36 : client_id_(client_id), local_id_(local_id), nonce_(nonce) {} | 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 |
| 39 // privileged process. |
| 40 SurfaceId(const FrameSinkId& frame_sink_id, uint32_t local_id, uint64_t nonce) |
| 41 : frame_sink_id_(frame_sink_id), local_id_(local_id), nonce_(nonce) {} |
| 37 | 42 |
| 38 bool is_null() const { | 43 bool is_null() const { |
| 39 return client_id_ == 0 && nonce_ == 0 && local_id_ == 0; | 44 return frame_sink_id_.is_null() && nonce_ == 0 && local_id_ == 0; |
| 40 } | 45 } |
| 41 | 46 |
| 42 size_t hash() const { | 47 size_t hash() const { |
| 43 size_t interim = base::HashInts(client_id_, local_id_); | 48 size_t interim = base::HashInts(local_id_, nonce_); |
| 44 return base::HashInts(static_cast<uint64_t>(interim), nonce_); | 49 return base::HashInts(static_cast<uint64_t>(frame_sink_id_.hash()), |
| 50 static_cast<uint64_t>(interim)); |
| 45 } | 51 } |
| 46 | 52 |
| 47 uint32_t client_id() const { return client_id_; } | 53 const FrameSinkId& frame_sink_id() const { return frame_sink_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, client_id_, local_id_, nonce_); | 60 return base::StringPrintf("%s:LocalId(%d, %" PRIu64 ")", |
| 61 frame_sink_id_.ToString().c_str(), local_id_, |
| 62 nonce_); |
| 55 } | 63 } |
| 56 | 64 |
| 57 bool operator==(const SurfaceId& other) const { | 65 bool operator==(const SurfaceId& other) const { |
| 58 return client_id_ == other.client_id_ && local_id_ == other.local_id_ && | 66 return frame_sink_id_ == other.frame_sink_id_ && |
| 59 nonce_ == other.nonce_; | 67 local_id_ == other.local_id_ && nonce_ == other.nonce_; |
| 60 } | 68 } |
| 61 | 69 |
| 62 bool operator!=(const SurfaceId& other) const { return !(*this == other); } | 70 bool operator!=(const SurfaceId& other) const { return !(*this == other); } |
| 63 | 71 |
| 64 bool operator<(const SurfaceId& other) const { | 72 bool operator<(const SurfaceId& other) const { |
| 65 return std::tie(client_id_, local_id_, nonce_) < | 73 return std::tie(frame_sink_id_, local_id_, nonce_) < |
| 66 std::tie(other.client_id_, other.local_id_, other.nonce_); | 74 std::tie(frame_sink_id_, other.local_id_, other.nonce_); |
| 67 } | 75 } |
| 68 | 76 |
| 69 private: | 77 private: |
| 70 // See SurfaceIdAllocator::GenerateId. | 78 // See SurfaceIdAllocator::GenerateId. |
| 71 uint32_t client_id_; | 79 FrameSinkId frame_sink_id_; |
| 72 uint32_t local_id_; | 80 uint32_t local_id_; |
| 73 uint64_t nonce_; | 81 uint64_t nonce_; |
| 74 }; | 82 }; |
| 75 | 83 |
| 76 struct SurfaceIdHash { | 84 struct SurfaceIdHash { |
| 77 size_t operator()(const SurfaceId& key) const { return key.hash(); } | 85 size_t operator()(const SurfaceId& key) const { return key.hash(); } |
| 78 }; | 86 }; |
| 79 | 87 |
| 80 } // namespace cc | 88 } // namespace cc |
| 81 | 89 |
| 82 #endif // CC_SURFACES_SURFACE_ID_H_ | 90 #endif // CC_SURFACES_SURFACE_ID_H_ |
| OLD | NEW |