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

Unified Diff: cc/surfaces/surface_reference.h

Issue 2537343004: Add SurfaceReference class. (Closed)
Patch Set: Fixes. Created 4 years 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_id.h ('k') | cc/surfaces/surface_reference.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/surfaces/surface_reference.h
diff --git a/cc/surfaces/surface_reference.h b/cc/surfaces/surface_reference.h
new file mode 100644
index 0000000000000000000000000000000000000000..ac3bb773d10e80d9c3159bf36e1672ea44ed6438
--- /dev/null
+++ b/cc/surfaces/surface_reference.h
@@ -0,0 +1,65 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_SURFACES_SURFACE_REFERENCE_H_
+#define CC_SURFACES_SURFACE_REFERENCE_H_
+
+#include <string>
+
+#include "base/hash.h"
+#include "cc/surfaces/surface_id.h"
+#include "mojo/public/cpp/bindings/struct_traits.h"
+
+namespace cc {
+namespace mojom {
+class SurfaceReferenceDataView;
+}
+
+// Hold a reference from an embedding (parent) to embedded (child) surface.
+class SurfaceReference {
+ public:
+ SurfaceReference();
+ SurfaceReference(const SurfaceId& parent_id, const SurfaceId& child_id);
+ SurfaceReference(const SurfaceReference& other);
+
+ ~SurfaceReference();
+
+ const SurfaceId& parent_id() const { return parent_id_; }
+ const SurfaceId& child_id() const { return child_id_; }
+
+ size_t hash() const {
+ return base::HashInts(static_cast<uint64_t>(parent_id_.hash()),
+ static_cast<uint64_t>(child_id_.hash()));
+ }
+
+ bool operator==(const SurfaceReference& other) const {
+ return parent_id_ == other.parent_id_ && child_id_ == other.child_id_;
+ }
+
+ bool operator!=(const SurfaceReference& other) const {
+ return !(*this == other);
+ }
+
+ bool operator<(const SurfaceReference& other) const {
+ return std::tie(parent_id_, child_id_) <
+ std::tie(other.parent_id_, other.child_id_);
+ }
+
+ std::string ToString() const;
+
+ private:
+ friend struct mojo::StructTraits<mojom::SurfaceReferenceDataView,
+ SurfaceReference>;
+
+ SurfaceId parent_id_;
+ SurfaceId child_id_;
+};
+
+struct SurfaceReferenceHash {
+ size_t operator()(const SurfaceReference& ref) const { return ref.hash(); }
+};
+
+} // namespace cc
+
+#endif // CC_SURFACES_SURFACE_REFERENCE_H_
« no previous file with comments | « cc/surfaces/surface_id.h ('k') | cc/surfaces/surface_reference.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698