Skip to content

Commit

Permalink
Wl region support (#522)
Browse files Browse the repository at this point in the history
The TestRegion class is introduced, and the mock surface now handles region-related methods.
  • Loading branch information
alex-voodoo authored Jan 31, 2019
1 parent 1637f68 commit a011df3
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 14 deletions.
3 changes: 3 additions & 0 deletions ui/ozone/platform/wayland/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ source_set("test_support") {
"test/test_pointer.h",
"test/test_positioner.cc",
"test/test_positioner.h",
"test/test_region.cc",
"test/test_region.h",
"test/test_seat.cc",
"test/test_seat.h",
"test/test_touch.cc",
Expand All @@ -203,6 +205,7 @@ source_set("test_support") {

deps = [
"//base:base",
"//skia",
"//testing/gmock",
"//third_party/wayland:wayland_server",
"//third_party/wayland-protocols:linux_dmabuf_protocol",
Expand Down
34 changes: 23 additions & 11 deletions ui/ozone/platform/wayland/test/mock_surface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ void Attach(wl_client* client,
GetUserDataAs<MockSurface>(resource)->Attach(buffer_resource, x, y);
}

void SetOpaqueRegion(wl_client* client,
wl_resource* resource,
wl_resource* region) {
GetUserDataAs<MockSurface>(resource)->SetOpaqueRegion(region);
}

void SetInputRegion(wl_client* client,
wl_resource* resource,
wl_resource* region) {
GetUserDataAs<MockSurface>(resource)->SetInputRegion(region);
}

void Damage(wl_client* client,
wl_resource* resource,
int32_t x,
Expand All @@ -32,16 +44,16 @@ void Commit(wl_client* client, wl_resource* resource) {
} // namespace

const struct wl_surface_interface kMockSurfaceImpl = {
&DestroyResource, // destroy
&Attach, // attach
&Damage, // damage
nullptr, // frame
nullptr, // set_opaque_region
nullptr, // set_input_region
&Commit, // commit
nullptr, // set_buffer_transform
nullptr, // set_buffer_scale
nullptr, // damage_buffer
DestroyResource, // destroy
Attach, // attach
Damage, // damage
nullptr, // frame
SetOpaqueRegion, // set_opaque_region
SetInputRegion, // set_input_region
Commit, // commit
nullptr, // set_buffer_transform
nullptr, // set_buffer_scale
nullptr, // damage_buffer
};

MockSurface::MockSurface(wl_resource* resource) : ServerObject(resource) {}
Expand All @@ -53,7 +65,7 @@ MockSurface::~MockSurface() {

MockSurface* MockSurface::FromResource(wl_resource* resource) {
if (!ResourceHasImplementation(resource, &wl_surface_interface,
&kMockSurfaceImpl))
&kMockSurfaceImpl))
return nullptr;
return GetUserDataAs<MockSurface>(resource);
}
Expand Down
2 changes: 2 additions & 0 deletions ui/ozone/platform/wayland/test/mock_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class MockSurface : public ServerObject {
static MockSurface* FromResource(wl_resource* resource);

MOCK_METHOD3(Attach, void(wl_resource* buffer, int32_t x, int32_t y));
MOCK_METHOD1(SetOpaqueRegion, void(wl_resource* region));
MOCK_METHOD1(SetInputRegion, void(wl_resource* region));
MOCK_METHOD4(Damage,
void(int32_t x, int32_t y, int32_t width, int32_t height));
MOCK_METHOD0(Commit, void());
Expand Down
16 changes: 13 additions & 3 deletions ui/ozone/platform/wayland/test/test_compositor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

#include <wayland-server-core.h>

#include "base/logging.h"
#include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/ozone/platform/wayland/test/server_object.h"
#include "ui/ozone/platform/wayland/test/test_region.h"

namespace wl {

Expand All @@ -16,7 +18,6 @@ namespace {
constexpr uint32_t kCompositorVersion = 4;

void CreateSurface(wl_client* client, wl_resource* resource, uint32_t id) {
auto* compositor = GetUserDataAs<TestCompositor>(resource);
wl_resource* surface_resource = wl_resource_create(
client, &wl_surface_interface, wl_resource_get_version(resource), id);
if (!surface_resource) {
Expand All @@ -25,14 +26,23 @@ void CreateSurface(wl_client* client, wl_resource* resource, uint32_t id) {
}
SetImplementation(surface_resource, &kMockSurfaceImpl,
std::make_unique<MockSurface>(surface_resource));

auto* compositor = GetUserDataAs<TestCompositor>(resource);
compositor->AddSurface(GetUserDataAs<MockSurface>(surface_resource));
}

void CreateRegion(wl_client* client, wl_resource* resource, uint32_t id) {
wl_resource* region_resource =
wl_resource_create(client, &wl_region_interface, 1, id);
SetImplementation(region_resource, &kTestWlRegionImpl,
std::make_unique<TestRegion>());
}

} // namespace

const struct wl_compositor_interface kTestCompositorImpl = {
&CreateSurface, // create_surface
nullptr, // create_region
CreateSurface, // create_surface
CreateRegion, // create_region
};

TestCompositor::TestCompositor()
Expand Down
43 changes: 43 additions & 0 deletions ui/ozone/platform/wayland/test/test_region.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2019 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 "ui/ozone/platform/wayland/test/test_region.h"

#include <wayland-server-core.h>

#include "ui/ozone/platform/wayland/test/server_object.h"

namespace wl {

namespace {

void Destroy(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}

void Add(wl_client* client,
wl_resource* resource,
int32_t x,
int32_t y,
int32_t width,
int32_t height) {
GetUserDataAs<SkRegion>(resource)->op(SkIRect::MakeXYWH(x, y, width, height),
SkRegion::kUnion_Op);
}

static void Subtract(wl_client* client,
wl_resource* resource,
int32_t x,
int32_t y,
int32_t width,
int32_t height) {
GetUserDataAs<SkRegion>(resource)->op(SkIRect::MakeXYWH(x, y, width, height),
SkRegion::kDifference_Op);
}

} // namespace

const struct wl_region_interface kTestWlRegionImpl = {Destroy, Add, Subtract};

} // namespace wl
20 changes: 20 additions & 0 deletions ui/ozone/platform/wayland/test/test_region.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2019 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 UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_REGION_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_REGION_H_

#include <wayland-server-protocol-core.h>

#include "third_party/skia/include/core/SkRegion.h"

namespace wl {

extern const struct wl_region_interface kTestWlRegionImpl;

using TestRegion = SkRegion;

} // namespace wl

#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_REGION_H_

0 comments on commit a011df3

Please sign in to comment.