| 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: 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(), interim); |
| 45 } | 46 } |
| 46 | 47 |
| 47 uint32_t client_id() const { return client_id_; } | 48 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; } |
| 48 | 49 |
| 49 uint32_t local_id() const { return local_id_; } | 50 uint32_t local_id() const { return local_id_; } |
| 50 | 51 |
| 51 uint64_t nonce() const { return nonce_; } | 52 uint64_t nonce() const { return nonce_; } |
| 52 | 53 |
| 53 std::string ToString() const { | 54 std::string ToString() const { |
| 54 return base::StringPrintf("%d:%d:%" PRIu64, client_id_, local_id_, nonce_); | 55 return base::StringPrintf("%s:LocalId(%d, %" PRIu64 ")", |
| 56 frame_sink_id_.ToString().c_str(), local_id_, |
| 57 nonce_); |
| 55 } | 58 } |
| 56 | 59 |
| 57 bool operator==(const SurfaceId& other) const { | 60 bool operator==(const SurfaceId& other) const { |
| 58 return client_id_ == other.client_id_ && local_id_ == other.local_id_ && | 61 return frame_sink_id_ == other.frame_sink_id_ && |
| 59 nonce_ == other.nonce_; | 62 local_id_ == other.local_id_ && nonce_ == other.nonce_; |
| 60 } | 63 } |
| 61 | 64 |
| 62 bool operator!=(const SurfaceId& other) const { return !(*this == other); } | 65 bool operator!=(const SurfaceId& other) const { return !(*this == other); } |
| 63 | 66 |
| 64 bool operator<(const SurfaceId& other) const { | 67 bool operator<(const SurfaceId& other) const { |
| 65 return std::tie(client_id_, local_id_, nonce_) < | 68 return std::tie(frame_sink_id_, local_id_, nonce_) < |
| 66 std::tie(other.client_id_, other.local_id_, other.nonce_); | 69 std::tie(frame_sink_id_, other.local_id_, other.nonce_); |
| 67 } | 70 } |
| 68 | 71 |
| 69 private: | 72 private: |
| 70 // See SurfaceIdAllocator::GenerateId. | 73 // See SurfaceIdAllocator::GenerateId. |
| 71 uint32_t client_id_; | 74 FrameSinkId frame_sink_id_; |
| 72 uint32_t local_id_; | 75 uint32_t local_id_; |
| 73 uint64_t nonce_; | 76 uint64_t nonce_; |
| 74 }; | 77 }; |
| 75 | 78 |
| 76 struct SurfaceIdHash { | 79 struct SurfaceIdHash { |
| 77 size_t operator()(const SurfaceId& key) const { return key.hash(); } | 80 size_t operator()(const SurfaceId& key) const { return key.hash(); } |
| 78 }; | 81 }; |
| 79 | 82 |
| 80 } // namespace cc | 83 } // namespace cc |
| 81 | 84 |
| 82 #endif // CC_SURFACES_SURFACE_ID_H_ | 85 #endif // CC_SURFACES_SURFACE_ID_H_ |
| OLD | NEW |