forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple class SurfaceReference that holds a parent and child SurfaceId. Also add Mojo struct and StructTraits for use over IPC. Update SurfaceId and LocalFrameId struct traits slightly to avoid unnecessary copies. This requires a friend declaration but it seems reasonable and is done elsewhere. BUG=659227 CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel Review-Url: https://codereview.chromium.org/2537343004 Cr-Commit-Position: refs/heads/master@{#436423}
- Loading branch information
kylechar
authored and
Commit bot
committed
Dec 5, 2016
1 parent
e9559d0
commit c142d1d
Showing
15 changed files
with
201 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// 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. | ||
|
||
module cc.mojom; | ||
|
||
import "cc/ipc/surface_id.mojom"; | ||
|
||
struct SurfaceReference { | ||
SurfaceId parent_id; | ||
SurfaceId child_id; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# 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. | ||
|
||
mojom = "//cc/ipc/surface_reference.mojom" | ||
public_headers = [ "//cc/surfaces/surface_reference.h" ] | ||
traits_headers = [ "//cc/ipc/surface_reference_struct_traits.h" ] | ||
deps = [ | ||
"//cc/ipc:struct_traits", | ||
] | ||
type_mappings = [ "cc.mojom.SurfaceReference=cc::SurfaceReference" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// 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_IPC_SURFACE_REFERENCE_STRUCT_TRAITS_H_ | ||
#define CC_IPC_SURFACE_REFERENCE_STRUCT_TRAITS_H_ | ||
|
||
#include "cc/ipc/surface_id_struct_traits.h" | ||
#include "cc/ipc/surface_reference.mojom-shared.h" | ||
#include "cc/surfaces/surface_id.h" | ||
#include "cc/surfaces/surface_reference.h" | ||
|
||
namespace mojo { | ||
|
||
template <> | ||
struct StructTraits<cc::mojom::SurfaceReferenceDataView, cc::SurfaceReference> { | ||
static const cc::SurfaceId& parent_id(const cc::SurfaceReference& ref) { | ||
return ref.parent_id(); | ||
} | ||
|
||
static const cc::SurfaceId& child_id(const cc::SurfaceReference& ref) { | ||
return ref.child_id(); | ||
} | ||
|
||
static bool Read(cc::mojom::SurfaceReferenceDataView data, | ||
cc::SurfaceReference* out) { | ||
return data.ReadParentId(&out->parent_id_) && | ||
data.ReadChildId(&out->child_id_); | ||
} | ||
}; | ||
|
||
} // namespace mojo | ||
|
||
#endif // CC_IPC_SURFACE_REFERENCE_STRUCT_TRAITS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include_rules = [ | ||
"+mojo/public/cpp/bindings/struct_traits.h", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// 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. | ||
|
||
#include "cc/surfaces/surface_reference.h" | ||
|
||
#include "base/strings/stringprintf.h" | ||
|
||
namespace cc { | ||
|
||
SurfaceReference::SurfaceReference() = default; | ||
|
||
SurfaceReference::SurfaceReference(const SurfaceId& parent_id, | ||
const SurfaceId& child_id) | ||
: parent_id_(parent_id), child_id_(child_id) {} | ||
|
||
SurfaceReference::SurfaceReference(const SurfaceReference& other) = default; | ||
|
||
SurfaceReference::~SurfaceReference() = default; | ||
|
||
std::string SurfaceReference::ToString() const { | ||
return base::StringPrintf("parent=%s, child=%s", | ||
parent_id_.ToString().c_str(), | ||
child_id_.ToString().c_str()); | ||
} | ||
|
||
} // namespace cc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ |