2012-12-08 01:50:29 +04:00
|
|
|
/*
|
|
|
|
* Copyright © 2012 Intel Corporation
|
|
|
|
*
|
2015-06-12 01:39:40 +03:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
2012-12-08 01:50:29 +04:00
|
|
|
*
|
2015-06-12 01:39:40 +03:00
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2012-12-08 01:50:29 +04:00
|
|
|
*/
|
|
|
|
|
2013-10-30 00:13:45 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
2016-07-19 14:16:27 +03:00
|
|
|
#include <stdint.h>
|
2012-12-08 01:50:29 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
2015-03-30 13:37:55 +03:00
|
|
|
#include <string.h>
|
2019-04-27 00:57:31 +03:00
|
|
|
#include <errno.h>
|
2014-11-20 04:18:34 +03:00
|
|
|
|
2019-03-28 17:28:47 +03:00
|
|
|
#include <libweston/libweston.h>
|
2019-07-16 23:44:21 +03:00
|
|
|
#include "backend.h"
|
2019-07-10 17:32:42 +03:00
|
|
|
#include "libweston-internal.h"
|
2016-06-03 16:45:21 +03:00
|
|
|
#include "compositor/weston.h"
|
2015-02-24 18:32:14 +03:00
|
|
|
#include "weston-test-server-protocol.h"
|
2012-12-08 01:50:29 +04:00
|
|
|
|
2015-06-16 01:37:10 +03:00
|
|
|
#include "shared/helpers.h"
|
2017-11-24 19:01:46 +03:00
|
|
|
#include "shared/timespec-util.h"
|
2015-06-16 01:37:10 +03:00
|
|
|
|
2017-11-29 04:42:47 +03:00
|
|
|
#define MAX_TOUCH_DEVICES 32
|
|
|
|
|
2012-12-08 01:50:29 +04:00
|
|
|
struct weston_test {
|
|
|
|
struct weston_compositor *compositor;
|
2019-11-06 13:59:32 +03:00
|
|
|
/* XXX: missing compositor destroy listener
|
|
|
|
* https://gitlab.freedesktop.org/wayland/weston/issues/300
|
|
|
|
*/
|
2012-12-08 01:50:29 +04:00
|
|
|
struct weston_layer layer;
|
|
|
|
struct weston_process process;
|
2015-03-30 16:17:40 +03:00
|
|
|
struct weston_seat seat;
|
2017-11-29 04:42:47 +03:00
|
|
|
struct weston_touch_device *touch_device[MAX_TOUCH_DEVICES];
|
|
|
|
int nr_touch_devices;
|
2018-01-26 19:48:00 +03:00
|
|
|
bool is_seat_initialized;
|
2012-12-08 01:50:29 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct weston_test_surface {
|
|
|
|
struct weston_surface *surface;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
struct weston_view *view;
|
2012-12-08 01:50:29 +04:00
|
|
|
int32_t x, y;
|
|
|
|
struct weston_test *test;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_client_sigchld(struct weston_process *process, int status)
|
|
|
|
{
|
|
|
|
struct weston_test *test =
|
|
|
|
container_of(process, struct weston_test, process);
|
|
|
|
|
2019-03-14 17:56:27 +03:00
|
|
|
/* Chain up from weston-test-runner's exit code so that ninja
|
2014-02-07 12:34:48 +04:00
|
|
|
* knows the exit status and can report e.g. skipped tests. */
|
|
|
|
if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
|
|
|
|
exit(WEXITSTATUS(status));
|
|
|
|
|
|
|
|
/* In case the child aborted or segfaulted... */
|
2012-12-08 01:50:29 +04:00
|
|
|
assert(status == 0);
|
|
|
|
|
2019-02-06 11:53:35 +03:00
|
|
|
weston_compositor_exit(test->compositor);
|
2012-12-08 01:50:29 +04:00
|
|
|
}
|
|
|
|
|
2017-11-29 04:42:47 +03:00
|
|
|
static void
|
|
|
|
touch_device_add(struct weston_test *test)
|
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
int i = test->nr_touch_devices;
|
|
|
|
|
|
|
|
assert(i < MAX_TOUCH_DEVICES);
|
|
|
|
assert(!test->touch_device[i]);
|
|
|
|
|
|
|
|
snprintf(buf, sizeof buf, "test-touch-device-%d", i);
|
|
|
|
|
|
|
|
test->touch_device[i] = weston_touch_create_touch_device(
|
|
|
|
test->seat.touch_state, buf, NULL, NULL);
|
|
|
|
test->nr_touch_devices++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
touch_device_remove(struct weston_test *test)
|
|
|
|
{
|
|
|
|
int i = test->nr_touch_devices - 1;
|
|
|
|
|
|
|
|
assert(i >= 0);
|
|
|
|
assert(test->touch_device[i]);
|
|
|
|
weston_touch_device_destroy(test->touch_device[i]);
|
|
|
|
test->touch_device[i] = NULL;
|
|
|
|
--test->nr_touch_devices;
|
|
|
|
}
|
|
|
|
|
2018-01-26 19:48:00 +03:00
|
|
|
static int
|
|
|
|
test_seat_init(struct weston_test *test)
|
|
|
|
{
|
2018-02-26 15:14:14 +03:00
|
|
|
assert(!test->is_seat_initialized &&
|
|
|
|
"Trying to add already added test seat");
|
|
|
|
|
2018-01-26 19:48:00 +03:00
|
|
|
/* create our own seat */
|
|
|
|
weston_seat_init(&test->seat, test->compositor, "test-seat");
|
|
|
|
test->is_seat_initialized = true;
|
|
|
|
|
|
|
|
/* add devices */
|
|
|
|
weston_seat_init_pointer(&test->seat);
|
|
|
|
if (weston_seat_init_keyboard(&test->seat, NULL) < 0)
|
|
|
|
return -1;
|
|
|
|
weston_seat_init_touch(&test->seat);
|
2017-11-29 04:42:47 +03:00
|
|
|
touch_device_add(test);
|
2018-01-26 19:48:00 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-26 15:14:14 +03:00
|
|
|
static void
|
|
|
|
test_seat_release(struct weston_test *test)
|
|
|
|
{
|
2017-11-29 04:42:47 +03:00
|
|
|
while (test->nr_touch_devices > 0)
|
|
|
|
touch_device_remove(test);
|
|
|
|
|
2018-02-26 15:14:14 +03:00
|
|
|
assert(test->is_seat_initialized &&
|
|
|
|
"Trying to release already released test seat");
|
|
|
|
test->is_seat_initialized = false;
|
|
|
|
weston_seat_release(&test->seat);
|
|
|
|
memset(&test->seat, 0, sizeof test->seat);
|
|
|
|
}
|
|
|
|
|
2012-12-08 01:50:29 +04:00
|
|
|
static struct weston_seat *
|
|
|
|
get_seat(struct weston_test *test)
|
|
|
|
{
|
2015-03-30 16:17:40 +03:00
|
|
|
return &test->seat;
|
2012-12-08 01:50:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
notify_pointer_position(struct weston_test *test, struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
struct weston_seat *seat = get_seat(test);
|
2015-08-01 00:55:32 +03:00
|
|
|
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
|
2012-12-08 01:50:29 +04:00
|
|
|
|
2015-02-24 18:32:14 +03:00
|
|
|
weston_test_send_pointer_position(resource, pointer->x, pointer->y);
|
2012-12-08 01:50:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-08-12 11:41:33 +03:00
|
|
|
test_surface_committed(struct weston_surface *surface, int32_t sx, int32_t sy)
|
2012-12-08 01:50:29 +04:00
|
|
|
{
|
2016-08-12 11:41:33 +03:00
|
|
|
struct weston_test_surface *test_surface = surface->committed_private;
|
2012-12-08 01:50:29 +04:00
|
|
|
struct weston_test *test = test_surface->test;
|
|
|
|
|
2014-07-09 23:12:56 +04:00
|
|
|
if (wl_list_empty(&test_surface->view->layer_link.link))
|
|
|
|
weston_layer_entry_insert(&test->layer.view_list,
|
|
|
|
&test_surface->view->layer_link);
|
2012-12-08 01:50:29 +04:00
|
|
|
|
2013-12-03 07:01:53 +04:00
|
|
|
weston_view_set_position(test_surface->view,
|
|
|
|
test_surface->x, test_surface->y);
|
2012-12-08 01:50:29 +04:00
|
|
|
|
2013-11-14 09:55:57 +04:00
|
|
|
weston_view_update_transform(test_surface->view);
|
2016-06-30 07:04:32 +03:00
|
|
|
|
|
|
|
test_surface->surface->is_mapped = true;
|
|
|
|
test_surface->view->is_mapped = true;
|
2012-12-08 01:50:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
move_surface(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
struct wl_resource *surface_resource,
|
|
|
|
int32_t x, int32_t y)
|
|
|
|
{
|
2013-06-26 00:18:35 +04:00
|
|
|
struct weston_surface *surface =
|
|
|
|
wl_resource_get_user_data(surface_resource);
|
2012-12-08 01:50:29 +04:00
|
|
|
struct weston_test_surface *test_surface;
|
|
|
|
|
2016-08-12 11:41:33 +03:00
|
|
|
test_surface = surface->committed_private;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
if (!test_surface) {
|
|
|
|
test_surface = malloc(sizeof *test_surface);
|
|
|
|
if (!test_surface) {
|
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
test_surface->view = weston_view_create(surface);
|
|
|
|
if (!test_surface->view) {
|
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
free(test_surface);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-12 11:41:33 +03:00
|
|
|
surface->committed_private = test_surface;
|
|
|
|
surface->committed = test_surface_committed;
|
2012-12-08 01:50:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
test_surface->surface = surface;
|
2013-06-26 00:18:35 +04:00
|
|
|
test_surface->test = wl_resource_get_user_data(resource);
|
2012-12-08 01:50:29 +04:00
|
|
|
test_surface->x = x;
|
|
|
|
test_surface->y = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
move_pointer(struct wl_client *client, struct wl_resource *resource,
|
2017-12-13 14:27:55 +03:00
|
|
|
uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec,
|
2012-12-08 01:50:29 +04:00
|
|
|
int32_t x, int32_t y)
|
|
|
|
{
|
2013-06-26 00:18:35 +04:00
|
|
|
struct weston_test *test = wl_resource_get_user_data(resource);
|
2012-12-08 01:50:29 +04:00
|
|
|
struct weston_seat *seat = get_seat(test);
|
2015-08-01 00:55:32 +03:00
|
|
|
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
|
2014-10-05 23:39:14 +04:00
|
|
|
struct weston_pointer_motion_event event = { 0 };
|
2017-11-24 19:01:46 +03:00
|
|
|
struct timespec time;
|
2012-12-08 01:50:29 +04:00
|
|
|
|
2014-10-05 23:39:14 +04:00
|
|
|
event = (struct weston_pointer_motion_event) {
|
|
|
|
.mask = WESTON_POINTER_MOTION_REL,
|
|
|
|
.dx = wl_fixed_to_double(wl_fixed_from_int(x) - pointer->x),
|
|
|
|
.dy = wl_fixed_to_double(wl_fixed_from_int(y) - pointer->y),
|
|
|
|
};
|
|
|
|
|
2017-12-13 14:27:55 +03:00
|
|
|
timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec);
|
2017-11-24 19:01:46 +03:00
|
|
|
|
|
|
|
notify_motion(seat, &time, &event);
|
2012-12-08 01:50:29 +04:00
|
|
|
|
|
|
|
notify_pointer_position(test, resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
send_button(struct wl_client *client, struct wl_resource *resource,
|
2017-12-13 14:27:55 +03:00
|
|
|
uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec,
|
2012-12-08 01:50:29 +04:00
|
|
|
int32_t button, uint32_t state)
|
|
|
|
{
|
2017-11-16 19:20:55 +03:00
|
|
|
struct timespec time;
|
|
|
|
|
2013-06-26 00:18:35 +04:00
|
|
|
struct weston_test *test = wl_resource_get_user_data(resource);
|
2012-12-08 01:50:29 +04:00
|
|
|
struct weston_seat *seat = get_seat(test);
|
|
|
|
|
2017-12-13 14:27:55 +03:00
|
|
|
timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec);
|
2017-11-16 19:20:55 +03:00
|
|
|
|
|
|
|
notify_button(seat, &time, button, state);
|
2012-12-08 01:50:29 +04:00
|
|
|
}
|
|
|
|
|
2017-12-18 13:16:55 +03:00
|
|
|
static void
|
|
|
|
send_axis(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec,
|
|
|
|
uint32_t axis, wl_fixed_t value)
|
|
|
|
{
|
|
|
|
struct weston_test *test = wl_resource_get_user_data(resource);
|
|
|
|
struct weston_seat *seat = get_seat(test);
|
|
|
|
struct timespec time;
|
|
|
|
struct weston_pointer_axis_event axis_event;
|
|
|
|
|
|
|
|
timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec);
|
|
|
|
axis_event.axis = axis;
|
|
|
|
axis_event.value = wl_fixed_to_double(value);
|
|
|
|
axis_event.has_discrete = false;
|
|
|
|
axis_event.discrete = 0;
|
|
|
|
|
|
|
|
notify_axis(seat, &time, &axis_event);
|
|
|
|
}
|
|
|
|
|
2012-12-08 01:50:29 +04:00
|
|
|
static void
|
|
|
|
activate_surface(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
struct wl_resource *surface_resource)
|
|
|
|
{
|
|
|
|
struct weston_surface *surface = surface_resource ?
|
2013-06-26 00:18:35 +04:00
|
|
|
wl_resource_get_user_data(surface_resource) : NULL;
|
|
|
|
struct weston_test *test = wl_resource_get_user_data(resource);
|
2012-12-08 01:50:29 +04:00
|
|
|
struct weston_seat *seat;
|
2015-08-01 00:55:32 +03:00
|
|
|
struct weston_keyboard *keyboard;
|
2012-12-08 01:50:29 +04:00
|
|
|
|
|
|
|
seat = get_seat(test);
|
2015-08-01 00:55:32 +03:00
|
|
|
keyboard = weston_seat_get_keyboard(seat);
|
2012-12-08 01:50:29 +04:00
|
|
|
if (surface) {
|
2016-06-30 05:04:06 +03:00
|
|
|
weston_seat_set_keyboard_focus(seat, surface);
|
2015-08-01 00:55:32 +03:00
|
|
|
notify_keyboard_focus_in(seat, &keyboard->keys,
|
2012-12-08 01:50:29 +04:00
|
|
|
STATE_UPDATE_AUTOMATIC);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
notify_keyboard_focus_out(seat);
|
2016-06-30 05:04:06 +03:00
|
|
|
weston_seat_set_keyboard_focus(seat, surface);
|
2012-12-08 01:50:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
send_key(struct wl_client *client, struct wl_resource *resource,
|
2017-12-13 14:27:57 +03:00
|
|
|
uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec,
|
2012-12-08 01:50:29 +04:00
|
|
|
uint32_t key, enum wl_keyboard_key_state state)
|
|
|
|
{
|
2013-06-26 00:18:35 +04:00
|
|
|
struct weston_test *test = wl_resource_get_user_data(resource);
|
2012-12-08 01:50:29 +04:00
|
|
|
struct weston_seat *seat = get_seat(test);
|
2017-11-16 19:20:57 +03:00
|
|
|
struct timespec time;
|
|
|
|
|
2017-12-13 14:27:57 +03:00
|
|
|
timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec);
|
2012-12-08 01:50:29 +04:00
|
|
|
|
2017-11-16 19:20:57 +03:00
|
|
|
notify_key(seat, &time, key, state, STATE_UPDATE_AUTOMATIC);
|
2012-12-08 01:50:29 +04:00
|
|
|
}
|
|
|
|
|
2015-03-30 13:37:55 +03:00
|
|
|
static void
|
|
|
|
device_release(struct wl_client *client,
|
|
|
|
struct wl_resource *resource, const char *device)
|
|
|
|
{
|
|
|
|
struct weston_test *test = wl_resource_get_user_data(resource);
|
|
|
|
struct weston_seat *seat = get_seat(test);
|
|
|
|
|
|
|
|
if (strcmp(device, "pointer") == 0) {
|
|
|
|
weston_seat_release_pointer(seat);
|
|
|
|
} else if (strcmp(device, "keyboard") == 0) {
|
|
|
|
weston_seat_release_keyboard(seat);
|
|
|
|
} else if (strcmp(device, "touch") == 0) {
|
2017-11-29 04:42:47 +03:00
|
|
|
touch_device_remove(test);
|
2015-03-30 13:37:55 +03:00
|
|
|
weston_seat_release_touch(seat);
|
|
|
|
} else if (strcmp(device, "seat") == 0) {
|
2018-02-26 15:14:14 +03:00
|
|
|
test_seat_release(test);
|
2015-03-30 13:37:55 +03:00
|
|
|
} else {
|
|
|
|
assert(0 && "Unsupported device");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
device_add(struct wl_client *client,
|
|
|
|
struct wl_resource *resource, const char *device)
|
|
|
|
{
|
|
|
|
struct weston_test *test = wl_resource_get_user_data(resource);
|
|
|
|
struct weston_seat *seat = get_seat(test);
|
|
|
|
|
|
|
|
if (strcmp(device, "pointer") == 0) {
|
|
|
|
weston_seat_init_pointer(seat);
|
|
|
|
} else if (strcmp(device, "keyboard") == 0) {
|
|
|
|
weston_seat_init_keyboard(seat, NULL);
|
|
|
|
} else if (strcmp(device, "touch") == 0) {
|
|
|
|
weston_seat_init_touch(seat);
|
2017-11-29 04:42:47 +03:00
|
|
|
touch_device_add(test);
|
2018-01-26 19:48:00 +03:00
|
|
|
} else if (strcmp(device, "seat") == 0) {
|
|
|
|
test_seat_init(test);
|
2015-03-30 13:37:55 +03:00
|
|
|
} else {
|
|
|
|
assert(0 && "Unsupported device");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-06 01:13:20 +03:00
|
|
|
enum weston_test_screenshot_outcome {
|
|
|
|
WESTON_TEST_SCREENSHOT_SUCCESS,
|
|
|
|
WESTON_TEST_SCREENSHOT_NO_MEMORY,
|
|
|
|
WESTON_TEST_SCREENSHOT_BAD_BUFFER
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (*weston_test_screenshot_done_func_t)(void *data,
|
|
|
|
enum weston_test_screenshot_outcome outcome);
|
|
|
|
|
|
|
|
struct test_screenshot {
|
|
|
|
struct weston_compositor *compositor;
|
|
|
|
struct wl_global *global;
|
|
|
|
struct wl_client *client;
|
|
|
|
struct weston_process process;
|
|
|
|
struct wl_listener destroy_listener;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct test_screenshot_frame_listener {
|
|
|
|
struct wl_listener listener;
|
|
|
|
struct weston_buffer *buffer;
|
|
|
|
weston_test_screenshot_done_func_t done;
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
copy_bgra_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
|
|
|
|
{
|
|
|
|
uint8_t *end;
|
|
|
|
|
|
|
|
end = dst + height * stride;
|
|
|
|
while (dst < end) {
|
|
|
|
memcpy(dst, src, stride);
|
|
|
|
dst += stride;
|
|
|
|
src -= stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
copy_bgra(uint8_t *dst, uint8_t *src, int height, int stride)
|
|
|
|
{
|
|
|
|
/* TODO: optimize this out */
|
|
|
|
memcpy(dst, src, height * stride);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
copy_row_swap_RB(void *vdst, void *vsrc, int bytes)
|
|
|
|
{
|
|
|
|
uint32_t *dst = vdst;
|
|
|
|
uint32_t *src = vsrc;
|
|
|
|
uint32_t *end = dst + bytes / 4;
|
|
|
|
|
|
|
|
while (dst < end) {
|
|
|
|
uint32_t v = *src++;
|
|
|
|
/* A R G B */
|
|
|
|
uint32_t tmp = v & 0xff00ff00;
|
|
|
|
tmp |= (v >> 16) & 0x000000ff;
|
|
|
|
tmp |= (v << 16) & 0x00ff0000;
|
|
|
|
*dst++ = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
copy_rgba_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
|
|
|
|
{
|
|
|
|
uint8_t *end;
|
|
|
|
|
|
|
|
end = dst + height * stride;
|
|
|
|
while (dst < end) {
|
|
|
|
copy_row_swap_RB(dst, src, stride);
|
|
|
|
dst += stride;
|
|
|
|
src -= stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
copy_rgba(uint8_t *dst, uint8_t *src, int height, int stride)
|
|
|
|
{
|
|
|
|
uint8_t *end;
|
|
|
|
|
|
|
|
end = dst + height * stride;
|
|
|
|
while (dst < end) {
|
|
|
|
copy_row_swap_RB(dst, src, stride);
|
|
|
|
dst += stride;
|
|
|
|
src += stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_screenshot_frame_notify(struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
struct test_screenshot_frame_listener *l =
|
|
|
|
container_of(listener,
|
|
|
|
struct test_screenshot_frame_listener, listener);
|
|
|
|
struct weston_output *output = data;
|
|
|
|
struct weston_compositor *compositor = output->compositor;
|
|
|
|
int32_t stride;
|
|
|
|
uint8_t *pixels, *d, *s;
|
|
|
|
|
2019-07-08 09:16:42 +03:00
|
|
|
weston_output_disable_planes_decr(output);
|
2015-05-06 01:13:20 +03:00
|
|
|
wl_list_remove(&listener->link);
|
|
|
|
stride = l->buffer->width * (PIXMAN_FORMAT_BPP(compositor->read_format) / 8);
|
|
|
|
pixels = malloc(stride * l->buffer->height);
|
|
|
|
|
|
|
|
if (pixels == NULL) {
|
|
|
|
l->done(l->data, WESTON_TEST_SCREENSHOT_NO_MEMORY);
|
|
|
|
free(l);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-03 20:23:12 +03:00
|
|
|
/* FIXME: Needs to handle output transformations */
|
2015-05-06 01:13:20 +03:00
|
|
|
|
|
|
|
compositor->renderer->read_pixels(output,
|
|
|
|
compositor->read_format,
|
|
|
|
pixels,
|
|
|
|
0, 0,
|
|
|
|
output->current_mode->width,
|
|
|
|
output->current_mode->height);
|
|
|
|
|
|
|
|
stride = wl_shm_buffer_get_stride(l->buffer->shm_buffer);
|
|
|
|
|
|
|
|
d = wl_shm_buffer_get_data(l->buffer->shm_buffer);
|
|
|
|
s = pixels + stride * (l->buffer->height - 1);
|
|
|
|
|
|
|
|
wl_shm_buffer_begin_access(l->buffer->shm_buffer);
|
|
|
|
|
|
|
|
/* XXX: It would be nice if we used Pixman to do all this rather
|
|
|
|
* than our own implementation
|
|
|
|
*/
|
|
|
|
switch (compositor->read_format) {
|
|
|
|
case PIXMAN_a8r8g8b8:
|
|
|
|
case PIXMAN_x8r8g8b8:
|
|
|
|
if (compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP)
|
|
|
|
copy_bgra_yflip(d, s, output->current_mode->height, stride);
|
|
|
|
else
|
|
|
|
copy_bgra(d, pixels, output->current_mode->height, stride);
|
|
|
|
break;
|
|
|
|
case PIXMAN_x8b8g8r8:
|
|
|
|
case PIXMAN_a8b8g8r8:
|
|
|
|
if (compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP)
|
|
|
|
copy_rgba_yflip(d, s, output->current_mode->height, stride);
|
|
|
|
else
|
|
|
|
copy_rgba(d, pixels, output->current_mode->height, stride);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_shm_buffer_end_access(l->buffer->shm_buffer);
|
|
|
|
|
|
|
|
l->done(l->data, WESTON_TEST_SCREENSHOT_SUCCESS);
|
|
|
|
free(pixels);
|
|
|
|
free(l);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
weston_test_screenshot_shoot(struct weston_output *output,
|
|
|
|
struct weston_buffer *buffer,
|
|
|
|
weston_test_screenshot_done_func_t done,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
struct test_screenshot_frame_listener *l;
|
|
|
|
|
|
|
|
/* Get the shm buffer resource the client created */
|
|
|
|
if (!wl_shm_buffer_get(buffer->resource)) {
|
|
|
|
done(data, WESTON_TEST_SCREENSHOT_BAD_BUFFER);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer->shm_buffer = wl_shm_buffer_get(buffer->resource);
|
|
|
|
buffer->width = wl_shm_buffer_get_width(buffer->shm_buffer);
|
|
|
|
buffer->height = wl_shm_buffer_get_height(buffer->shm_buffer);
|
|
|
|
|
|
|
|
/* Verify buffer is big enough */
|
|
|
|
if (buffer->width < output->current_mode->width ||
|
|
|
|
buffer->height < output->current_mode->height) {
|
|
|
|
done(data, WESTON_TEST_SCREENSHOT_BAD_BUFFER);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate the frame listener */
|
|
|
|
l = malloc(sizeof *l);
|
|
|
|
if (l == NULL) {
|
|
|
|
done(data, WESTON_TEST_SCREENSHOT_NO_MEMORY);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up the listener */
|
|
|
|
l->buffer = buffer;
|
|
|
|
l->done = done;
|
|
|
|
l->data = data;
|
|
|
|
l->listener.notify = test_screenshot_frame_notify;
|
|
|
|
wl_signal_add(&output->frame_signal, &l->listener);
|
|
|
|
|
|
|
|
/* Fire off a repaint */
|
2019-07-08 09:16:42 +03:00
|
|
|
weston_output_disable_planes_incr(output);
|
2015-05-06 01:13:20 +03:00
|
|
|
weston_output_schedule_repaint(output);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
capture_screenshot_done(void *data, enum weston_test_screenshot_outcome outcome)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource = data;
|
|
|
|
|
|
|
|
switch (outcome) {
|
|
|
|
case WESTON_TEST_SCREENSHOT_SUCCESS:
|
|
|
|
weston_test_send_capture_screenshot_done(resource);
|
|
|
|
break;
|
|
|
|
case WESTON_TEST_SCREENSHOT_NO_MEMORY:
|
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Grabs a snapshot of the screen.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
capture_screenshot(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *output_resource,
|
|
|
|
struct wl_resource *buffer_resource)
|
|
|
|
{
|
|
|
|
struct weston_output *output =
|
2017-03-27 16:31:25 +03:00
|
|
|
weston_head_from_resource(output_resource)->output;
|
2015-05-06 01:13:20 +03:00
|
|
|
struct weston_buffer *buffer =
|
|
|
|
weston_buffer_from_resource(buffer_resource);
|
|
|
|
|
|
|
|
if (buffer == NULL) {
|
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
weston_test_screenshot_shoot(output, buffer,
|
|
|
|
capture_screenshot_done, resource);
|
|
|
|
}
|
|
|
|
|
2017-12-13 14:27:58 +03:00
|
|
|
static void
|
|
|
|
send_touch(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec,
|
|
|
|
int32_t touch_id, wl_fixed_t x, wl_fixed_t y, uint32_t touch_type)
|
|
|
|
{
|
|
|
|
struct weston_test *test = wl_resource_get_user_data(resource);
|
2018-02-26 15:43:00 +03:00
|
|
|
struct weston_touch_device *device = test->touch_device[0];
|
2017-12-13 14:27:58 +03:00
|
|
|
struct timespec time;
|
|
|
|
|
2018-02-26 15:43:00 +03:00
|
|
|
assert(device);
|
|
|
|
|
2017-12-13 14:27:58 +03:00
|
|
|
timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec);
|
|
|
|
|
2018-02-26 15:43:00 +03:00
|
|
|
notify_touch(device, &time, touch_id, wl_fixed_to_double(x),
|
2017-12-13 14:27:58 +03:00
|
|
|
wl_fixed_to_double(y), touch_type);
|
|
|
|
}
|
|
|
|
|
2015-02-24 18:32:14 +03:00
|
|
|
static const struct weston_test_interface test_implementation = {
|
2012-12-08 01:50:29 +04:00
|
|
|
move_surface,
|
|
|
|
move_pointer,
|
|
|
|
send_button,
|
2017-12-18 13:16:55 +03:00
|
|
|
send_axis,
|
2012-12-08 01:50:29 +04:00
|
|
|
activate_surface,
|
2013-10-30 00:13:45 +04:00
|
|
|
send_key,
|
2015-03-30 13:37:55 +03:00
|
|
|
device_release,
|
|
|
|
device_add,
|
2015-05-06 01:13:20 +03:00
|
|
|
capture_screenshot,
|
2017-12-13 14:27:58 +03:00
|
|
|
send_touch,
|
2012-12-08 01:50:29 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_test(struct wl_client *client, void *data, uint32_t version, uint32_t id)
|
|
|
|
{
|
|
|
|
struct weston_test *test = data;
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
2015-02-24 18:32:14 +03:00
|
|
|
resource = wl_resource_create(client, &weston_test_interface, 1, id);
|
2014-07-11 14:33:02 +04:00
|
|
|
if (!resource) {
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-04 02:13:33 +04:00
|
|
|
wl_resource_set_implementation(resource,
|
|
|
|
&test_implementation, test, NULL);
|
2012-12-08 01:50:29 +04:00
|
|
|
|
|
|
|
notify_pointer_position(test, resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
idle_launch_client(void *data)
|
|
|
|
{
|
|
|
|
struct weston_test *test = data;
|
|
|
|
pid_t pid;
|
|
|
|
sigset_t allsigs;
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
path = getenv("WESTON_TEST_CLIENT_PATH");
|
|
|
|
if (path == NULL)
|
2013-11-21 18:23:57 +04:00
|
|
|
return;
|
2012-12-08 01:50:29 +04:00
|
|
|
pid = fork();
|
|
|
|
if (pid == -1)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
if (pid == 0) {
|
|
|
|
sigfillset(&allsigs);
|
|
|
|
sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
|
|
|
|
execl(path, path, NULL);
|
2019-04-27 00:57:31 +03:00
|
|
|
weston_log("compositor: executing '%s' failed: %s\n", path,
|
|
|
|
strerror(errno));
|
2012-12-08 01:50:29 +04:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
test->process.pid = pid;
|
|
|
|
test->process.cleanup = test_client_sigchld;
|
|
|
|
weston_watch_process(&test->process);
|
|
|
|
}
|
|
|
|
|
|
|
|
WL_EXPORT int
|
2016-12-02 16:21:46 +03:00
|
|
|
wet_module_init(struct weston_compositor *ec,
|
|
|
|
int *argc, char *argv[])
|
2012-12-08 01:50:29 +04:00
|
|
|
{
|
|
|
|
struct weston_test *test;
|
|
|
|
struct wl_event_loop *loop;
|
|
|
|
|
2013-08-08 05:57:05 +04:00
|
|
|
test = zalloc(sizeof *test);
|
2012-12-08 01:50:29 +04:00
|
|
|
if (test == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
test->compositor = ec;
|
2016-12-17 15:40:51 +03:00
|
|
|
weston_layer_init(&test->layer, ec);
|
|
|
|
weston_layer_set_position(&test->layer, WESTON_LAYER_POSITION_CURSOR - 1);
|
2012-12-08 01:50:29 +04:00
|
|
|
|
2015-02-24 18:32:14 +03:00
|
|
|
if (wl_global_create(ec->wl_display, &weston_test_interface, 1,
|
2013-07-09 03:03:57 +04:00
|
|
|
test, bind_test) == NULL)
|
2012-12-08 01:50:29 +04:00
|
|
|
return -1;
|
|
|
|
|
2018-01-26 19:48:00 +03:00
|
|
|
if (test_seat_init(test) == -1)
|
2016-06-16 12:04:53 +03:00
|
|
|
return -1;
|
2015-03-30 16:17:40 +03:00
|
|
|
|
2012-12-08 01:50:29 +04:00
|
|
|
loop = wl_display_get_event_loop(ec->wl_display);
|
|
|
|
wl_event_loop_add_idle(loop, idle_launch_client, test);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|