blob: 14030f4ce2f6fe8c33ab2055e2c3fc10ab323cba [file] [log] [blame]
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -08001/*
2 * Copyright © 2012 Intel Corporation
3 *
Bryce Harrington2cc92972015-06-11 15:39:40 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080011 *
Bryce Harrington2cc92972015-06-11 15:39:40 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080024 */
25
Neil Roberts40c0c3f2013-10-29 20:13:45 +000026#include "config.h"
27
Jussi Kukkonen649bbce2016-07-19 14:16:27 +030028#include <stdint.h>
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080029#include <stdlib.h>
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080030#include <assert.h>
31#include <signal.h>
32#include <unistd.h>
Marek Chalupac8daf772015-03-30 06:37:55 -040033#include <string.h>
Bryce Harringtona7680262014-11-19 17:18:34 -080034
Pekka Paalanenb5e3ea22016-06-03 17:12:10 +030035#include "compositor.h"
Pekka Paalanen58f98c92016-06-03 16:45:21 +030036#include "compositor/weston.h"
Derek Foremanf6a65922015-02-24 09:32:14 -060037#include "weston-test-server-protocol.h"
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080038
Neil Roberts40c0c3f2013-10-29 20:13:45 +000039#ifdef ENABLE_EGL
40#include <EGL/egl.h>
41#include <EGL/eglext.h>
Pekka Paalanenb5e3ea22016-06-03 17:12:10 +030042#include "weston-egl-ext.h"
Neil Roberts40c0c3f2013-10-29 20:13:45 +000043#endif /* ENABLE_EGL */
44
Jon Cruz867d50e2015-06-15 15:37:10 -070045#include "shared/helpers.h"
Alexandros Frantzis84b31f82017-11-24 18:01:46 +020046#include "shared/timespec-util.h"
Jon Cruz867d50e2015-06-15 15:37:10 -070047
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080048struct weston_test {
49 struct weston_compositor *compositor;
50 struct weston_layer layer;
51 struct weston_process process;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040052 struct weston_seat seat;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080053};
54
55struct weston_test_surface {
56 struct weston_surface *surface;
Jason Ekstranda7af7042013-10-12 22:38:11 -050057 struct weston_view *view;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080058 int32_t x, y;
59 struct weston_test *test;
60};
61
62static void
63test_client_sigchld(struct weston_process *process, int status)
64{
65 struct weston_test *test =
66 container_of(process, struct weston_test, process);
67
Emilio Pozuelo Monfortdae8a4b2014-02-07 09:34:48 +010068 /* Chain up from weston-test-runner's exit code so that automake
69 * knows the exit status and can report e.g. skipped tests. */
70 if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
71 exit(WEXITSTATUS(status));
72
73 /* In case the child aborted or segfaulted... */
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080074 assert(status == 0);
75
76 wl_display_terminate(test->compositor->wl_display);
77}
78
79static struct weston_seat *
80get_seat(struct weston_test *test)
81{
Marek Chalupac3c3fc42015-03-30 09:17:40 -040082 return &test->seat;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080083}
84
85static void
86notify_pointer_position(struct weston_test *test, struct wl_resource *resource)
87{
88 struct weston_seat *seat = get_seat(test);
Derek Foreman1281a362015-07-31 16:55:32 -050089 struct weston_pointer *pointer = weston_seat_get_pointer(seat);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080090
Derek Foremanf6a65922015-02-24 09:32:14 -060091 weston_test_send_pointer_position(resource, pointer->x, pointer->y);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080092}
93
94static void
Quentin Glidic2edc3d52016-08-12 10:41:33 +020095test_surface_committed(struct weston_surface *surface, int32_t sx, int32_t sy)
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080096{
Quentin Glidic2edc3d52016-08-12 10:41:33 +020097 struct weston_test_surface *test_surface = surface->committed_private;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080098 struct weston_test *test = test_surface->test;
99
Giulio Camuffo412e6a52014-07-09 22:12:56 +0300100 if (wl_list_empty(&test_surface->view->layer_link.link))
101 weston_layer_entry_insert(&test->layer.view_list,
102 &test_surface->view->layer_link);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800103
Jason Ekstrand918f2dd2013-12-02 21:01:53 -0600104 weston_view_set_position(test_surface->view,
105 test_surface->x, test_surface->y);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800106
Kristian Høgsbergace0a392013-11-13 21:55:57 -0800107 weston_view_update_transform(test_surface->view);
Armin Krezovićd0cf4412016-06-30 06:04:32 +0200108
109 test_surface->surface->is_mapped = true;
110 test_surface->view->is_mapped = true;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800111}
112
113static void
114move_surface(struct wl_client *client, struct wl_resource *resource,
115 struct wl_resource *surface_resource,
116 int32_t x, int32_t y)
117{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400118 struct weston_surface *surface =
119 wl_resource_get_user_data(surface_resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800120 struct weston_test_surface *test_surface;
121
Quentin Glidic2edc3d52016-08-12 10:41:33 +0200122 test_surface = surface->committed_private;
Jason Ekstranda7af7042013-10-12 22:38:11 -0500123 if (!test_surface) {
124 test_surface = malloc(sizeof *test_surface);
125 if (!test_surface) {
126 wl_resource_post_no_memory(resource);
127 return;
128 }
129
130 test_surface->view = weston_view_create(surface);
131 if (!test_surface->view) {
132 wl_resource_post_no_memory(resource);
133 free(test_surface);
134 return;
135 }
136
Quentin Glidic2edc3d52016-08-12 10:41:33 +0200137 surface->committed_private = test_surface;
138 surface->committed = test_surface_committed;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800139 }
140
141 test_surface->surface = surface;
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400142 test_surface->test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800143 test_surface->x = x;
144 test_surface->y = y;
145}
146
147static void
148move_pointer(struct wl_client *client, struct wl_resource *resource,
Alexandros Frantzis21808582017-12-13 13:27:55 +0200149 uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec,
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800150 int32_t x, int32_t y)
151{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400152 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800153 struct weston_seat *seat = get_seat(test);
Derek Foreman1281a362015-07-31 16:55:32 -0500154 struct weston_pointer *pointer = weston_seat_get_pointer(seat);
Jonas Ådahld2510102014-10-05 21:39:14 +0200155 struct weston_pointer_motion_event event = { 0 };
Alexandros Frantzis84b31f82017-11-24 18:01:46 +0200156 struct timespec time;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800157
Jonas Ådahld2510102014-10-05 21:39:14 +0200158 event = (struct weston_pointer_motion_event) {
159 .mask = WESTON_POINTER_MOTION_REL,
160 .dx = wl_fixed_to_double(wl_fixed_from_int(x) - pointer->x),
161 .dy = wl_fixed_to_double(wl_fixed_from_int(y) - pointer->y),
162 };
163
Alexandros Frantzis21808582017-12-13 13:27:55 +0200164 timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec);
Alexandros Frantzis84b31f82017-11-24 18:01:46 +0200165
166 notify_motion(seat, &time, &event);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800167
168 notify_pointer_position(test, resource);
169}
170
171static void
172send_button(struct wl_client *client, struct wl_resource *resource,
Alexandros Frantzis21808582017-12-13 13:27:55 +0200173 uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec,
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800174 int32_t button, uint32_t state)
175{
Alexandros Frantzis215bedc2017-11-16 18:20:55 +0200176 struct timespec time;
177
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400178 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800179 struct weston_seat *seat = get_seat(test);
180
Alexandros Frantzis21808582017-12-13 13:27:55 +0200181 timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec);
Alexandros Frantzis215bedc2017-11-16 18:20:55 +0200182
183 notify_button(seat, &time, button, state);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800184}
185
186static void
187activate_surface(struct wl_client *client, struct wl_resource *resource,
188 struct wl_resource *surface_resource)
189{
190 struct weston_surface *surface = surface_resource ?
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400191 wl_resource_get_user_data(surface_resource) : NULL;
192 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800193 struct weston_seat *seat;
Derek Foreman1281a362015-07-31 16:55:32 -0500194 struct weston_keyboard *keyboard;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800195
196 seat = get_seat(test);
Derek Foreman1281a362015-07-31 16:55:32 -0500197 keyboard = weston_seat_get_keyboard(seat);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800198 if (surface) {
Bryce Harrington260c2ff2016-06-29 19:04:06 -0700199 weston_seat_set_keyboard_focus(seat, surface);
Derek Foreman1281a362015-07-31 16:55:32 -0500200 notify_keyboard_focus_in(seat, &keyboard->keys,
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800201 STATE_UPDATE_AUTOMATIC);
202 }
203 else {
204 notify_keyboard_focus_out(seat);
Bryce Harrington260c2ff2016-06-29 19:04:06 -0700205 weston_seat_set_keyboard_focus(seat, surface);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800206 }
207}
208
209static void
210send_key(struct wl_client *client, struct wl_resource *resource,
Alexandros Frantzisdae224c2017-12-13 13:27:57 +0200211 uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec,
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800212 uint32_t key, enum wl_keyboard_key_state state)
213{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400214 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800215 struct weston_seat *seat = get_seat(test);
Alexandros Frantzis47e79c82017-11-16 18:20:57 +0200216 struct timespec time;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800217
Alexandros Frantzisdae224c2017-12-13 13:27:57 +0200218 timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec);
Alexandros Frantzis47e79c82017-11-16 18:20:57 +0200219
220 notify_key(seat, &time, key, state, STATE_UPDATE_AUTOMATIC);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800221}
222
Marek Chalupac8daf772015-03-30 06:37:55 -0400223static void
224device_release(struct wl_client *client,
225 struct wl_resource *resource, const char *device)
226{
227 struct weston_test *test = wl_resource_get_user_data(resource);
228 struct weston_seat *seat = get_seat(test);
229
230 if (strcmp(device, "pointer") == 0) {
231 weston_seat_release_pointer(seat);
232 } else if (strcmp(device, "keyboard") == 0) {
233 weston_seat_release_keyboard(seat);
234 } else if (strcmp(device, "touch") == 0) {
235 weston_seat_release_touch(seat);
236 } else if (strcmp(device, "seat") == 0) {
237 weston_seat_release(seat);
238 } else {
239 assert(0 && "Unsupported device");
240 }
241}
242
243static void
244device_add(struct wl_client *client,
245 struct wl_resource *resource, const char *device)
246{
247 struct weston_test *test = wl_resource_get_user_data(resource);
248 struct weston_seat *seat = get_seat(test);
249
250 if (strcmp(device, "pointer") == 0) {
251 weston_seat_init_pointer(seat);
252 } else if (strcmp(device, "keyboard") == 0) {
253 weston_seat_init_keyboard(seat, NULL);
254 } else if (strcmp(device, "touch") == 0) {
255 weston_seat_init_touch(seat);
256 } else {
257 assert(0 && "Unsupported device");
258 }
259}
260
Bryce Harringtonf280d112015-05-05 15:13:20 -0700261enum weston_test_screenshot_outcome {
262 WESTON_TEST_SCREENSHOT_SUCCESS,
263 WESTON_TEST_SCREENSHOT_NO_MEMORY,
264 WESTON_TEST_SCREENSHOT_BAD_BUFFER
265 };
266
267typedef void (*weston_test_screenshot_done_func_t)(void *data,
268 enum weston_test_screenshot_outcome outcome);
269
270struct test_screenshot {
271 struct weston_compositor *compositor;
272 struct wl_global *global;
273 struct wl_client *client;
274 struct weston_process process;
275 struct wl_listener destroy_listener;
276};
277
278struct test_screenshot_frame_listener {
279 struct wl_listener listener;
280 struct weston_buffer *buffer;
281 weston_test_screenshot_done_func_t done;
282 void *data;
283};
284
285static void
286copy_bgra_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
287{
288 uint8_t *end;
289
290 end = dst + height * stride;
291 while (dst < end) {
292 memcpy(dst, src, stride);
293 dst += stride;
294 src -= stride;
295 }
296}
297
298
299static void
300copy_bgra(uint8_t *dst, uint8_t *src, int height, int stride)
301{
302 /* TODO: optimize this out */
303 memcpy(dst, src, height * stride);
304}
305
306static void
307copy_row_swap_RB(void *vdst, void *vsrc, int bytes)
308{
309 uint32_t *dst = vdst;
310 uint32_t *src = vsrc;
311 uint32_t *end = dst + bytes / 4;
312
313 while (dst < end) {
314 uint32_t v = *src++;
315 /* A R G B */
316 uint32_t tmp = v & 0xff00ff00;
317 tmp |= (v >> 16) & 0x000000ff;
318 tmp |= (v << 16) & 0x00ff0000;
319 *dst++ = tmp;
320 }
321}
322
323static void
324copy_rgba_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
325{
326 uint8_t *end;
327
328 end = dst + height * stride;
329 while (dst < end) {
330 copy_row_swap_RB(dst, src, stride);
331 dst += stride;
332 src -= stride;
333 }
334}
335
336static void
337copy_rgba(uint8_t *dst, uint8_t *src, int height, int stride)
338{
339 uint8_t *end;
340
341 end = dst + height * stride;
342 while (dst < end) {
343 copy_row_swap_RB(dst, src, stride);
344 dst += stride;
345 src += stride;
346 }
347}
348
349static void
350test_screenshot_frame_notify(struct wl_listener *listener, void *data)
351{
352 struct test_screenshot_frame_listener *l =
353 container_of(listener,
354 struct test_screenshot_frame_listener, listener);
355 struct weston_output *output = data;
356 struct weston_compositor *compositor = output->compositor;
357 int32_t stride;
358 uint8_t *pixels, *d, *s;
359
360 output->disable_planes--;
361 wl_list_remove(&listener->link);
362 stride = l->buffer->width * (PIXMAN_FORMAT_BPP(compositor->read_format) / 8);
363 pixels = malloc(stride * l->buffer->height);
364
365 if (pixels == NULL) {
366 l->done(l->data, WESTON_TEST_SCREENSHOT_NO_MEMORY);
367 free(l);
368 return;
369 }
370
Chris Michael2ec5f2a2015-12-03 12:23:12 -0500371 /* FIXME: Needs to handle output transformations */
Bryce Harringtonf280d112015-05-05 15:13:20 -0700372
373 compositor->renderer->read_pixels(output,
374 compositor->read_format,
375 pixels,
376 0, 0,
377 output->current_mode->width,
378 output->current_mode->height);
379
380 stride = wl_shm_buffer_get_stride(l->buffer->shm_buffer);
381
382 d = wl_shm_buffer_get_data(l->buffer->shm_buffer);
383 s = pixels + stride * (l->buffer->height - 1);
384
385 wl_shm_buffer_begin_access(l->buffer->shm_buffer);
386
387 /* XXX: It would be nice if we used Pixman to do all this rather
388 * than our own implementation
389 */
390 switch (compositor->read_format) {
391 case PIXMAN_a8r8g8b8:
392 case PIXMAN_x8r8g8b8:
393 if (compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP)
394 copy_bgra_yflip(d, s, output->current_mode->height, stride);
395 else
396 copy_bgra(d, pixels, output->current_mode->height, stride);
397 break;
398 case PIXMAN_x8b8g8r8:
399 case PIXMAN_a8b8g8r8:
400 if (compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP)
401 copy_rgba_yflip(d, s, output->current_mode->height, stride);
402 else
403 copy_rgba(d, pixels, output->current_mode->height, stride);
404 break;
405 default:
406 break;
407 }
408
409 wl_shm_buffer_end_access(l->buffer->shm_buffer);
410
411 l->done(l->data, WESTON_TEST_SCREENSHOT_SUCCESS);
412 free(pixels);
413 free(l);
414}
415
416static bool
417weston_test_screenshot_shoot(struct weston_output *output,
418 struct weston_buffer *buffer,
419 weston_test_screenshot_done_func_t done,
420 void *data)
421{
422 struct test_screenshot_frame_listener *l;
423
424 /* Get the shm buffer resource the client created */
425 if (!wl_shm_buffer_get(buffer->resource)) {
426 done(data, WESTON_TEST_SCREENSHOT_BAD_BUFFER);
427 return false;
428 }
429
430 buffer->shm_buffer = wl_shm_buffer_get(buffer->resource);
431 buffer->width = wl_shm_buffer_get_width(buffer->shm_buffer);
432 buffer->height = wl_shm_buffer_get_height(buffer->shm_buffer);
433
434 /* Verify buffer is big enough */
435 if (buffer->width < output->current_mode->width ||
436 buffer->height < output->current_mode->height) {
437 done(data, WESTON_TEST_SCREENSHOT_BAD_BUFFER);
438 return false;
439 }
440
441 /* allocate the frame listener */
442 l = malloc(sizeof *l);
443 if (l == NULL) {
444 done(data, WESTON_TEST_SCREENSHOT_NO_MEMORY);
445 return false;
446 }
447
448 /* Set up the listener */
449 l->buffer = buffer;
450 l->done = done;
451 l->data = data;
452 l->listener.notify = test_screenshot_frame_notify;
453 wl_signal_add(&output->frame_signal, &l->listener);
454
455 /* Fire off a repaint */
456 output->disable_planes++;
457 weston_output_schedule_repaint(output);
458
459 return true;
460}
461
462static void
463capture_screenshot_done(void *data, enum weston_test_screenshot_outcome outcome)
464{
465 struct wl_resource *resource = data;
466
467 switch (outcome) {
468 case WESTON_TEST_SCREENSHOT_SUCCESS:
469 weston_test_send_capture_screenshot_done(resource);
470 break;
471 case WESTON_TEST_SCREENSHOT_NO_MEMORY:
472 wl_resource_post_no_memory(resource);
473 break;
474 default:
475 break;
476 }
477}
478
479
480/**
481 * Grabs a snapshot of the screen.
482 */
483static void
484capture_screenshot(struct wl_client *client,
485 struct wl_resource *resource,
486 struct wl_resource *output_resource,
487 struct wl_resource *buffer_resource)
488{
489 struct weston_output *output =
Pekka Paalanen9ffb2502017-03-27 15:14:32 +0300490 weston_output_from_resource(output_resource);
Bryce Harringtonf280d112015-05-05 15:13:20 -0700491 struct weston_buffer *buffer =
492 weston_buffer_from_resource(buffer_resource);
493
494 if (buffer == NULL) {
495 wl_resource_post_no_memory(resource);
496 return;
497 }
498
499 weston_test_screenshot_shoot(output, buffer,
500 capture_screenshot_done, resource);
501}
502
Alexandros Frantzisc20b5802017-12-13 13:27:58 +0200503static void
504send_touch(struct wl_client *client, struct wl_resource *resource,
505 uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec,
506 int32_t touch_id, wl_fixed_t x, wl_fixed_t y, uint32_t touch_type)
507{
508 struct weston_test *test = wl_resource_get_user_data(resource);
509 struct weston_seat *seat = get_seat(test);
510 struct timespec time;
511
512 timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec);
513
514 notify_touch(seat, &time, touch_id, wl_fixed_to_double(x),
515 wl_fixed_to_double(y), touch_type);
516}
517
Derek Foremanf6a65922015-02-24 09:32:14 -0600518static const struct weston_test_interface test_implementation = {
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800519 move_surface,
520 move_pointer,
521 send_button,
522 activate_surface,
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000523 send_key,
Marek Chalupac8daf772015-03-30 06:37:55 -0400524 device_release,
525 device_add,
Bryce Harringtonf280d112015-05-05 15:13:20 -0700526 capture_screenshot,
Alexandros Frantzisc20b5802017-12-13 13:27:58 +0200527 send_touch,
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800528};
529
530static void
531bind_test(struct wl_client *client, void *data, uint32_t version, uint32_t id)
532{
533 struct weston_test *test = data;
534 struct wl_resource *resource;
535
Derek Foremanf6a65922015-02-24 09:32:14 -0600536 resource = wl_resource_create(client, &weston_test_interface, 1, id);
Marek Chalupa42ebdda2014-07-11 12:33:02 +0200537 if (!resource) {
538 wl_client_post_no_memory(client);
539 return;
540 }
541
Kristian Høgsberg442a5fa2013-07-03 18:13:33 -0400542 wl_resource_set_implementation(resource,
543 &test_implementation, test, NULL);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800544
545 notify_pointer_position(test, resource);
546}
547
548static void
549idle_launch_client(void *data)
550{
551 struct weston_test *test = data;
552 pid_t pid;
553 sigset_t allsigs;
554 char *path;
555
556 path = getenv("WESTON_TEST_CLIENT_PATH");
557 if (path == NULL)
Pekka Paalanenf72e4792013-11-21 16:23:57 +0200558 return;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800559 pid = fork();
560 if (pid == -1)
561 exit(EXIT_FAILURE);
562 if (pid == 0) {
563 sigfillset(&allsigs);
564 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
565 execl(path, path, NULL);
566 weston_log("compositor: executing '%s' failed: %m\n", path);
567 exit(EXIT_FAILURE);
568 }
569
570 test->process.pid = pid;
571 test->process.cleanup = test_client_sigchld;
572 weston_watch_process(&test->process);
573}
574
575WL_EXPORT int
Quentin Glidic8af2bec2016-12-02 14:21:46 +0100576wet_module_init(struct weston_compositor *ec,
577 int *argc, char *argv[])
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800578{
579 struct weston_test *test;
580 struct wl_event_loop *loop;
581
Peter Huttererf3d62272013-08-08 11:57:05 +1000582 test = zalloc(sizeof *test);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800583 if (test == NULL)
584 return -1;
585
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800586 test->compositor = ec;
Quentin Glidic82681572016-12-17 13:40:51 +0100587 weston_layer_init(&test->layer, ec);
588 weston_layer_set_position(&test->layer, WESTON_LAYER_POSITION_CURSOR - 1);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800589
Derek Foremanf6a65922015-02-24 09:32:14 -0600590 if (wl_global_create(ec->wl_display, &weston_test_interface, 1,
Kristian Høgsberg919cddb2013-07-08 19:03:57 -0400591 test, bind_test) == NULL)
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800592 return -1;
593
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400594 /* create our own seat */
595 weston_seat_init(&test->seat, ec, "test-seat");
596
597 /* add devices */
598 weston_seat_init_pointer(&test->seat);
Pekka Paalanen315bf8c2016-06-16 12:04:53 +0300599 if (weston_seat_init_keyboard(&test->seat, NULL) < 0)
600 return -1;
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400601 weston_seat_init_touch(&test->seat);
602
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800603 loop = wl_display_get_event_loop(ec->wl_display);
604 wl_event_loop_add_idle(loop, idle_launch_client, test);
605
606 return 0;
607}