Commit e85e6608 authored by Alexander Dunaev's avatar Alexander Dunaev Committed by Commit Bot

[ozone/wayland] Test support for wl_region is added.

The TestRegion class is introduced, and the mock surface now handles
region-related methods.

Bug: 847740
Change-Id: I38151f729548033043786e6828c8c97e1f56b67f
Reviewed-on: https://chromium-review.googlesource.com/c/1447871
Commit-Queue: Alexander Dunaev <adunaev@igalia.com>
Reviewed-by: default avatarMaksim Sisov <msisov@igalia.com>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Cr-Commit-Position: refs/heads/master@{#628208}
parent b52dc658
......@@ -192,6 +192,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",
......@@ -202,6 +204,7 @@ source_set("test_support") {
deps = [
"//base:base",
"//skia",
"//testing/gmock",
"//third_party/wayland:wayland_server",
"//third_party/wayland-protocols:linux_dmabuf_protocol",
......
......@@ -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,
......@@ -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) {}
......
......@@ -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());
......
......@@ -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 {
......@@ -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) {
......@@ -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()
......
// 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
// 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_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment