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

Unified Diff: cc/surfaces/surface_id.h

Issue 1996783002: Make cc::SurfaceId unguessable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Tom's comments Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/surfaces/surface_hittest_unittest.cc ('k') | cc/surfaces/surface_id_allocator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/surfaces/surface_id.h
diff --git a/cc/surfaces/surface_id.h b/cc/surfaces/surface_id.h
index bbc485f9009f90eaf577205f31dd7d2533310b6e..03c88097534941135a8bbd68d21407dac7cec9da 100644
--- a/cc/surfaces/surface_id.h
+++ b/cc/surfaces/surface_id.h
@@ -10,36 +10,79 @@
#include <functional>
+#include "base/format_macros.h"
+#include "base/hash.h"
+#include "base/strings/stringprintf.h"
+
namespace cc {
-struct SurfaceId {
- SurfaceId() : id(0) {}
- explicit SurfaceId(uint64_t id) : id(id) {}
+class SurfaceId {
+ public:
+ SurfaceId() : id_namespace_(0), local_id_(0), nonce_(0) {}
- bool is_null() const { return id == 0; }
+ SurfaceId(const SurfaceId& other)
+ : id_namespace_(other.id_namespace_),
+ local_id_(other.local_id_),
+ nonce_(other.nonce_) {}
- // See SurfaceIdAllocator::GenerateId.
- uint32_t id_namespace() const { return id >> 32; }
+ SurfaceId(uint32_t id_namespace, uint32_t local_id, uint64_t nonce)
+ : id_namespace_(id_namespace),
+ local_id_(local_id),
+ nonce_(nonce)
- uint64_t id;
-};
+ {}
-inline bool operator==(const SurfaceId& a, const SurfaceId& b) {
- return a.id == b.id;
-}
+ bool is_null() const {
+ return id_namespace_ == 0 && nonce_ == 0 && local_id_ == 0;
+ }
-inline bool operator!=(const SurfaceId& a, const SurfaceId& b) {
- return !(a == b);
-}
+ size_t hash() const {
+ size_t interim = base::HashInts(id_namespace_, local_id_);
+ return base::HashInts(interim, nonce_);
+ }
-inline bool operator<(const SurfaceId& a, const SurfaceId& b) {
- return a.id < b.id;
-}
+ uint32_t id_namespace() const { return id_namespace_; }
-struct SurfaceIdHash {
- size_t operator()(const SurfaceId& key) const {
- return std::hash<uint64_t>()(key.id);
+ uint32_t local_id() const { return local_id_; }
+
+ uint64_t nonce() const { return nonce_; }
+
+ std::string ToString() const {
+ return base::StringPrintf("%d:%" PRIuS ":%d", id_namespace_, nonce_,
+ local_id_);
}
+
+ bool operator==(const SurfaceId& other) const {
+ return (id_namespace_ == other.id_namespace_) &&
Tom Sepez 2016/05/25 00:09:53 nit: overparenthesized.
Fady Samuel 2016/05/25 00:57:45 Done.
+ (local_id_ == other.local_id_) && (nonce_ == other.nonce_);
+ }
+
+ bool operator!=(const SurfaceId& other) const { return !(*this == other); }
+
+ bool operator<(const SurfaceId& other) const {
+ if (id_namespace_ < other.id_namespace_)
Tom Sepez 2016/05/25 00:09:53 nit: this is fine, but still reads a little weird.
Fady Samuel 2016/05/25 00:57:45 Nice! Much nicer! Done.
danakj 2016/05/25 00:58:55 The "modern" way to do that is with std::tie(), an
Fady Samuel 2016/05/25 01:07:41 I totally forgot about std::tie. Thanks! Let's go
+ return true;
+
+ if (local_id_ < other.local_id_)
+ return id_namespace_ == other.id_namespace_;
+
+ if (nonce_ < other.nonce_) {
+ return id_namespace_ == other.id_namespace_ &&
+ local_id_ == other.local_id_;
+ }
+
+ return false;
+ }
+
+ private:
+ // See SurfaceIdAllocator::GenerateId.
+ uint32_t id_namespace_;
+ uint32_t local_id_;
+ uint64_t nonce_;
+};
+
+struct SurfaceIdHash {
+ size_t operator()(const SurfaceId& key) const { return key.hash(); }
};
} // namespace cc
« no previous file with comments | « cc/surfaces/surface_hittest_unittest.cc ('k') | cc/surfaces/surface_id_allocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698