Skip to content

Commit

Permalink
Add mojom, struct_traits and typemap for AggregatedHitTestRegion.
Browse files Browse the repository at this point in the history
Used in
https://chromium-review.googlesource.com/c/chromium/src/+/1044887.

Bug: 803548
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel
Change-Id: If6adbd59ee035b392ea87f3df286bfea569d6950
Reviewed-on: https://chromium-review.googlesource.com/1044783
Reviewed-by: kylechar <kylechar@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Ken Buchanan <kenrb@chromium.org>
Commit-Queue: Ria Jiang <riajiang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556535}
  • Loading branch information
riaj authored and Commit Bot committed May 7, 2018
1 parent 43b70f7 commit 2c8b3a8
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 4 deletions.
3 changes: 3 additions & 0 deletions components/viz/common/hit_test/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+mojo/public/cpp/bindings",
]
18 changes: 14 additions & 4 deletions components/viz/common/hit_test/aggregated_hit_test_region.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@

#include <stdint.h>

#include "components/viz/common/surfaces/surface_id.h"
#include "components/viz/common/surfaces/frame_sink_id.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/transform.h"

namespace viz {

namespace mojom {
class AggregatedHitTestRegionDataView;
}

// A AggregatedHitTestRegion element with child_count of kEndOfList indicates
// the last element and end of the list.
constexpr int32_t kEndOfList = -1;
Expand All @@ -24,10 +29,12 @@ constexpr int32_t kEndOfList = -1;
// write the hit_test data, and the viz host can read without
// process hops.
struct AggregatedHitTestRegion {
AggregatedHitTestRegion(FrameSinkId frame_sink_id,
AggregatedHitTestRegion() = default;

AggregatedHitTestRegion(const FrameSinkId& frame_sink_id,
uint32_t flags,
gfx::Rect rect,
gfx::Transform transform,
const gfx::Rect& rect,
const gfx::Transform& transform,
int32_t child_count)
: frame_sink_id(frame_sink_id),
flags(flags),
Expand Down Expand Up @@ -68,6 +75,9 @@ struct AggregatedHitTestRegion {
}

private:
friend struct mojo::StructTraits<mojom::AggregatedHitTestRegionDataView,
AggregatedHitTestRegion>;

// The transform applied to the rect in parent region's coordinate space.
gfx::Transform transform_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ _typemap_imports = [
"//services/viz/privileged/cpp/typemaps.gni",
"//services/viz/privileged/interfaces/compositing/typemaps.gni",
"//services/viz/public/cpp/compositing/typemaps.gni",
"//services/viz/public/cpp/hit_test/typemaps.gni",
"//skia/public/interfaces/typemaps.gni",
"//third_party/blink/common/typemaps.gni",
"//third_party/blink/public/public_typemaps.gni",
Expand Down
1 change: 1 addition & 0 deletions services/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ service_test("services_unittests") {
"//services/viz",
"//services/viz/privileged/interfaces:unit_tests",
"//services/viz/public/cpp/compositing:tests",
"//services/viz/public/cpp/hit_test:tests",
]
}

Expand Down
21 changes: 21 additions & 0 deletions services/viz/public/cpp/hit_test/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2018 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.

source_set("tests") {
testonly = true

sources = [
"struct_traits_unittest.cc",
]

deps = [
"//base/test:test_support",
"//components/viz/common:common",
"//components/viz/test:test_support",
"//services/viz/public/interfaces",
"//testing/gtest",
"//ui/gfx:test_support",
"//ui/gfx/geometry/mojo:struct_traits",
]
}
3 changes: 3 additions & 0 deletions services/viz/public/cpp/hit_test/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+ui/gfx",
]
4 changes: 4 additions & 0 deletions services/viz/public/cpp/hit_test/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
per-file *_struct_traits*.*=set noparent
per-file *_struct_traits*.*=file://ipc/SECURITY_OWNERS
per-file *.typemap=set noparent
per-file *.typemap=file://ipc/SECURITY_OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2018 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 =
"//services/viz/public/interfaces/hit_test/aggregated_hit_test_region.mojom"
public_headers =
[ "//components/viz/common/hit_test/aggregated_hit_test_region.h" ]
deps = [
"//components/viz/common",
]
traits_headers = [ "//services/viz/public/cpp/hit_test/aggregated_hit_test_region_struct_traits.h" ]
type_mappings =
[ "viz.mojom.AggregatedHitTestRegion=viz::AggregatedHitTestRegion" ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2018 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 SERVICES_VIZ_PUBLIC_CPP_HIT_TEST_AGGREGATED_HIT_TEST_REGION_STRUCT_TRAITS_H_
#define SERVICES_VIZ_PUBLIC_CPP_HIT_TEST_AGGREGATED_HIT_TEST_REGION_STRUCT_TRAITS_H_

#include "services/viz/public/cpp/compositing/frame_sink_id_struct_traits.h"
#include "services/viz/public/interfaces/hit_test/aggregated_hit_test_region.mojom-shared.h"
#include "ui/gfx/geometry/mojo/geometry_struct_traits.h"
#include "ui/gfx/mojo/transform_struct_traits.h"

namespace mojo {

template <>
struct StructTraits<viz::mojom::AggregatedHitTestRegionDataView,
viz::AggregatedHitTestRegion> {
static const viz::FrameSinkId& frame_sink_id(
const viz::AggregatedHitTestRegion& region) {
return region.frame_sink_id;
}

static uint32_t flags(const viz::AggregatedHitTestRegion& region) {
return region.flags;
}

static const gfx::Rect& rect(const viz::AggregatedHitTestRegion& region) {
return region.rect;
}

static uint32_t child_count(const viz::AggregatedHitTestRegion& region) {
return region.child_count;
}

static gfx::Transform transform(const viz::AggregatedHitTestRegion& region) {
return region.transform();
}

static bool Read(viz::mojom::AggregatedHitTestRegionDataView data,
viz::AggregatedHitTestRegion* out) {
if (!data.ReadFrameSinkId(&out->frame_sink_id) ||
!data.ReadRect(&out->rect) || !data.ReadTransform(&out->transform_)) {
return false;
}
out->flags = data.flags();
out->child_count = data.child_count();
return true;
}
};

} // namespace mojo

#endif // SERVICES_VIZ_PUBLIC_CPP_HIT_TEST_AGGREGATED_HIT_TEST_REGION_STRUCT_TRAITS_H_
48 changes: 48 additions & 0 deletions services/viz/public/cpp/hit_test/struct_traits_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2018 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 "components/viz/common/hit_test/aggregated_hit_test_region.h"
#include "services/viz/public/cpp/hit_test/aggregated_hit_test_region_struct_traits.h"
#include "services/viz/public/interfaces/hit_test/aggregated_hit_test_region.mojom.h"
#include "services/viz/public/interfaces/hit_test/hit_test_region_list.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/mojo/geometry_struct_traits.h"
#include "ui/gfx/mojo/transform_struct_traits.h"

namespace viz {

namespace {

using StructTraitsTest = testing::Test;

// Test StructTrait serialization and deserialization for copyable type. |input|
// will be serialized and then deserialized into |output|.
template <class MojomType, class Type>
void SerializeAndDeserialize(const Type& input, Type* output) {
MojomType::DeserializeFromMessage(
mojo::Message(MojomType::SerializeAsMessage(&input).TakeMojoMessage()),
output);
}

} // namespace

TEST_F(StructTraitsTest, AggregatedHitTestRegion) {
constexpr FrameSinkId frame_sink_id(1337, 1234);
constexpr uint32_t flags = mojom::kHitTestAsk;
constexpr gfx::Rect rect(1024, 768);
gfx::Transform transform;
transform.Scale(.5f, .7f);
constexpr int32_t child_count = 5;
AggregatedHitTestRegion input(frame_sink_id, flags, rect, transform,
child_count);
AggregatedHitTestRegion output;
SerializeAndDeserialize<mojom::AggregatedHitTestRegion>(input, &output);
EXPECT_EQ(input.frame_sink_id, output.frame_sink_id);
EXPECT_EQ(input.flags, output.flags);
EXPECT_EQ(input.rect, output.rect);
EXPECT_EQ(input.transform(), output.transform());
EXPECT_EQ(input.child_count, output.child_count);
}

} // namespace viz
6 changes: 6 additions & 0 deletions services/viz/public/cpp/hit_test/typemaps.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright 2018 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.

typemaps =
[ "//services/viz/public/cpp/hit_test/aggregated_hit_test_region.typemap" ]
1 change: 1 addition & 0 deletions services/viz/public/interfaces/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ mojom("interfaces") {
"compositing/transferable_resource.mojom",
"compositing/video_detector_observer.mojom",
"constants.mojom",
"hit_test/aggregated_hit_test_region.mojom",
"hit_test/hit_test_region_list.mojom",
"hit_test/input_target_client.mojom",
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2018 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 viz.mojom;

import "services/viz/public/interfaces/compositing/frame_sink_id.mojom";
import "ui/gfx/geometry/mojo/geometry.mojom";
import "ui/gfx/mojo/transform.mojom";

// Corresponds to viz::AggregatedHitTestRegion.
struct AggregatedHitTestRegion {
FrameSinkId frame_sink_id;

uint32 flags;

gfx.mojom.Rect rect;

uint32 child_count;

gfx.mojom.Transform transform;
};

0 comments on commit 2c8b3a8

Please sign in to comment.