blob: b593f1e843a3167a186cef7a84fc3193d9660829 [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
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080028#include <stdlib.h>
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080029#include <assert.h>
30#include <signal.h>
31#include <unistd.h>
Marek Chalupac8daf772015-03-30 06:37:55 -040032#include <string.h>
Bryce Harringtona7680262014-11-19 17:18:34 -080033
Jon Cruz4678bab2015-06-15 15:37:07 -070034#include "src/compositor.h"
Derek Foremanf6a65922015-02-24 09:32:14 -060035#include "weston-test-server-protocol.h"
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080036
Neil Roberts40c0c3f2013-10-29 20:13:45 +000037#ifdef ENABLE_EGL
38#include <EGL/egl.h>
39#include <EGL/eglext.h>
Jon Cruz4678bab2015-06-15 15:37:07 -070040#include "src/weston-egl-ext.h"
Neil Roberts40c0c3f2013-10-29 20:13:45 +000041#endif /* ENABLE_EGL */
42
Jon Cruz867d50e2015-06-15 15:37:10 -070043#include "shared/helpers.h"
44
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080045struct weston_test {
46 struct weston_compositor *compositor;
47 struct weston_layer layer;
48 struct weston_process process;
Marek Chalupac3c3fc42015-03-30 09:17:40 -040049 struct weston_seat seat;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080050};
51
52struct weston_test_surface {
53 struct weston_surface *surface;
Jason Ekstranda7af7042013-10-12 22:38:11 -050054 struct weston_view *view;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080055 int32_t x, y;
56 struct weston_test *test;
57};
58
59static void
60test_client_sigchld(struct weston_process *process, int status)
61{
62 struct weston_test *test =
63 container_of(process, struct weston_test, process);
64
Emilio Pozuelo Monfortdae8a4b2014-02-07 09:34:48 +010065 /* Chain up from weston-test-runner's exit code so that automake
66 * knows the exit status and can report e.g. skipped tests. */
67 if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
68 exit(WEXITSTATUS(status));
69
70 /* In case the child aborted or segfaulted... */
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080071 assert(status == 0);
72
73 wl_display_terminate(test->compositor->wl_display);
74}
75
76static struct weston_seat *
77get_seat(struct weston_test *test)
78{
Marek Chalupac3c3fc42015-03-30 09:17:40 -040079 return &test->seat;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080080}
81
82static void
83notify_pointer_position(struct weston_test *test, struct wl_resource *resource)
84{
85 struct weston_seat *seat = get_seat(test);
Derek Foreman1281a362015-07-31 16:55:32 -050086 struct weston_pointer *pointer = weston_seat_get_pointer(seat);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080087
Derek Foremanf6a65922015-02-24 09:32:14 -060088 weston_test_send_pointer_position(resource, pointer->x, pointer->y);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080089}
90
91static void
Jason Ekstrand918f2dd2013-12-02 21:01:53 -060092test_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy)
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080093{
Giulio Camuffo7fe01b12013-03-28 18:02:42 +010094 struct weston_test_surface *test_surface = surface->configure_private;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -080095 struct weston_test *test = test_surface->test;
96
Giulio Camuffo412e6a52014-07-09 22:12:56 +030097 if (wl_list_empty(&test_surface->view->layer_link.link))
98 weston_layer_entry_insert(&test->layer.view_list,
99 &test_surface->view->layer_link);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800100
Jason Ekstrand918f2dd2013-12-02 21:01:53 -0600101 weston_view_set_position(test_surface->view,
102 test_surface->x, test_surface->y);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800103
Kristian Høgsbergace0a392013-11-13 21:55:57 -0800104 weston_view_update_transform(test_surface->view);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800105}
106
107static void
108move_surface(struct wl_client *client, struct wl_resource *resource,
109 struct wl_resource *surface_resource,
110 int32_t x, int32_t y)
111{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400112 struct weston_surface *surface =
113 wl_resource_get_user_data(surface_resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800114 struct weston_test_surface *test_surface;
115
Giulio Camuffo7fe01b12013-03-28 18:02:42 +0100116 test_surface = surface->configure_private;
Jason Ekstranda7af7042013-10-12 22:38:11 -0500117 if (!test_surface) {
118 test_surface = malloc(sizeof *test_surface);
119 if (!test_surface) {
120 wl_resource_post_no_memory(resource);
121 return;
122 }
123
124 test_surface->view = weston_view_create(surface);
125 if (!test_surface->view) {
126 wl_resource_post_no_memory(resource);
127 free(test_surface);
128 return;
129 }
130
131 surface->configure_private = test_surface;
132 surface->configure = test_surface_configure;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800133 }
134
135 test_surface->surface = surface;
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400136 test_surface->test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800137 test_surface->x = x;
138 test_surface->y = y;
139}
140
141static void
142move_pointer(struct wl_client *client, struct wl_resource *resource,
143 int32_t x, int32_t y)
144{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400145 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800146 struct weston_seat *seat = get_seat(test);
Derek Foreman1281a362015-07-31 16:55:32 -0500147 struct weston_pointer *pointer = weston_seat_get_pointer(seat);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800148
Kristian Høgsberg068b61c2013-02-25 17:04:47 -0500149 notify_motion(seat, 100,
150 wl_fixed_from_int(x) - pointer->x,
151 wl_fixed_from_int(y) - pointer->y);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800152
153 notify_pointer_position(test, resource);
154}
155
156static void
157send_button(struct wl_client *client, struct wl_resource *resource,
158 int32_t button, uint32_t state)
159{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400160 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800161 struct weston_seat *seat = get_seat(test);
162
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800163 notify_button(seat, 100, button, state);
164}
165
166static void
167activate_surface(struct wl_client *client, struct wl_resource *resource,
168 struct wl_resource *surface_resource)
169{
170 struct weston_surface *surface = surface_resource ?
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400171 wl_resource_get_user_data(surface_resource) : NULL;
172 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800173 struct weston_seat *seat;
Derek Foreman1281a362015-07-31 16:55:32 -0500174 struct weston_keyboard *keyboard;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800175
176 seat = get_seat(test);
Derek Foreman1281a362015-07-31 16:55:32 -0500177 keyboard = weston_seat_get_keyboard(seat);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800178 if (surface) {
179 weston_surface_activate(surface, seat);
Derek Foreman1281a362015-07-31 16:55:32 -0500180 notify_keyboard_focus_in(seat, &keyboard->keys,
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800181 STATE_UPDATE_AUTOMATIC);
182 }
183 else {
184 notify_keyboard_focus_out(seat);
185 weston_surface_activate(surface, seat);
186 }
187}
188
189static void
190send_key(struct wl_client *client, struct wl_resource *resource,
191 uint32_t key, enum wl_keyboard_key_state state)
192{
Kristian Høgsberg8f7f4832013-06-25 16:18:35 -0400193 struct weston_test *test = wl_resource_get_user_data(resource);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800194 struct weston_seat *seat = get_seat(test);
195
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800196 notify_key(seat, 100, key, state, STATE_UPDATE_AUTOMATIC);
197}
198
Marek Chalupac8daf772015-03-30 06:37:55 -0400199static void
200device_release(struct wl_client *client,
201 struct wl_resource *resource, const char *device)
202{
203 struct weston_test *test = wl_resource_get_user_data(resource);
204 struct weston_seat *seat = get_seat(test);
205
206 if (strcmp(device, "pointer") == 0) {
207 weston_seat_release_pointer(seat);
208 } else if (strcmp(device, "keyboard") == 0) {
209 weston_seat_release_keyboard(seat);
210 } else if (strcmp(device, "touch") == 0) {
211 weston_seat_release_touch(seat);
212 } else if (strcmp(device, "seat") == 0) {
213 weston_seat_release(seat);
214 } else {
215 assert(0 && "Unsupported device");
216 }
217}
218
219static void
220device_add(struct wl_client *client,
221 struct wl_resource *resource, const char *device)
222{
223 struct weston_test *test = wl_resource_get_user_data(resource);
224 struct weston_seat *seat = get_seat(test);
225
226 if (strcmp(device, "pointer") == 0) {
227 weston_seat_init_pointer(seat);
228 } else if (strcmp(device, "keyboard") == 0) {
229 weston_seat_init_keyboard(seat, NULL);
230 } else if (strcmp(device, "touch") == 0) {
231 weston_seat_init_touch(seat);
232 } else {
233 assert(0 && "Unsupported device");
234 }
235}
236
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000237#ifdef ENABLE_EGL
238static int
239is_egl_buffer(struct wl_resource *resource)
240{
241 PFNEGLQUERYWAYLANDBUFFERWL query_buffer =
242 (void *) eglGetProcAddress("eglQueryWaylandBufferWL");
243 EGLint format;
244
245 if (query_buffer(eglGetCurrentDisplay(),
246 resource,
247 EGL_TEXTURE_FORMAT,
248 &format))
249 return 1;
250
251 return 0;
252}
253#endif /* ENABLE_EGL */
254
255static void
256get_n_buffers(struct wl_client *client, struct wl_resource *resource)
257{
258 int n_buffers = 0;
259
260#ifdef ENABLE_EGL
261 struct wl_resource *buffer_resource;
262 int i;
263
264 for (i = 0; i < 1000; i++) {
265 buffer_resource = wl_client_get_object(client, i);
266
267 if (buffer_resource == NULL)
268 continue;
269
270 if (is_egl_buffer(buffer_resource))
271 n_buffers++;
272 }
273#endif /* ENABLE_EGL */
274
Derek Foremanf6a65922015-02-24 09:32:14 -0600275 weston_test_send_n_egl_buffers(resource, n_buffers);
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000276}
277
Bryce Harringtonf280d112015-05-05 15:13:20 -0700278enum weston_test_screenshot_outcome {
279 WESTON_TEST_SCREENSHOT_SUCCESS,
280 WESTON_TEST_SCREENSHOT_NO_MEMORY,
281 WESTON_TEST_SCREENSHOT_BAD_BUFFER
282 };
283
284typedef void (*weston_test_screenshot_done_func_t)(void *data,
285 enum weston_test_screenshot_outcome outcome);
286
287struct test_screenshot {
288 struct weston_compositor *compositor;
289 struct wl_global *global;
290 struct wl_client *client;
291 struct weston_process process;
292 struct wl_listener destroy_listener;
293};
294
295struct test_screenshot_frame_listener {
296 struct wl_listener listener;
297 struct weston_buffer *buffer;
298 weston_test_screenshot_done_func_t done;
299 void *data;
300};
301
302static void
303copy_bgra_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
304{
305 uint8_t *end;
306
307 end = dst + height * stride;
308 while (dst < end) {
309 memcpy(dst, src, stride);
310 dst += stride;
311 src -= stride;
312 }
313}
314
315
316static void
317copy_bgra(uint8_t *dst, uint8_t *src, int height, int stride)
318{
319 /* TODO: optimize this out */
320 memcpy(dst, src, height * stride);
321}
322
323static void
324copy_row_swap_RB(void *vdst, void *vsrc, int bytes)
325{
326 uint32_t *dst = vdst;
327 uint32_t *src = vsrc;
328 uint32_t *end = dst + bytes / 4;
329
330 while (dst < end) {
331 uint32_t v = *src++;
332 /* A R G B */
333 uint32_t tmp = v & 0xff00ff00;
334 tmp |= (v >> 16) & 0x000000ff;
335 tmp |= (v << 16) & 0x00ff0000;
336 *dst++ = tmp;
337 }
338}
339
340static void
341copy_rgba_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
342{
343 uint8_t *end;
344
345 end = dst + height * stride;
346 while (dst < end) {
347 copy_row_swap_RB(dst, src, stride);
348 dst += stride;
349 src -= stride;
350 }
351}
352
353static void
354copy_rgba(uint8_t *dst, uint8_t *src, int height, int stride)
355{
356 uint8_t *end;
357
358 end = dst + height * stride;
359 while (dst < end) {
360 copy_row_swap_RB(dst, src, stride);
361 dst += stride;
362 src += stride;
363 }
364}
365
366static void
367test_screenshot_frame_notify(struct wl_listener *listener, void *data)
368{
369 struct test_screenshot_frame_listener *l =
370 container_of(listener,
371 struct test_screenshot_frame_listener, listener);
372 struct weston_output *output = data;
373 struct weston_compositor *compositor = output->compositor;
374 int32_t stride;
375 uint8_t *pixels, *d, *s;
376
377 output->disable_planes--;
378 wl_list_remove(&listener->link);
379 stride = l->buffer->width * (PIXMAN_FORMAT_BPP(compositor->read_format) / 8);
380 pixels = malloc(stride * l->buffer->height);
381
382 if (pixels == NULL) {
383 l->done(l->data, WESTON_TEST_SCREENSHOT_NO_MEMORY);
384 free(l);
385 return;
386 }
387
388 // FIXME: Needs to handle output transformations
389
390 compositor->renderer->read_pixels(output,
391 compositor->read_format,
392 pixels,
393 0, 0,
394 output->current_mode->width,
395 output->current_mode->height);
396
397 stride = wl_shm_buffer_get_stride(l->buffer->shm_buffer);
398
399 d = wl_shm_buffer_get_data(l->buffer->shm_buffer);
400 s = pixels + stride * (l->buffer->height - 1);
401
402 wl_shm_buffer_begin_access(l->buffer->shm_buffer);
403
404 /* XXX: It would be nice if we used Pixman to do all this rather
405 * than our own implementation
406 */
407 switch (compositor->read_format) {
408 case PIXMAN_a8r8g8b8:
409 case PIXMAN_x8r8g8b8:
410 if (compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP)
411 copy_bgra_yflip(d, s, output->current_mode->height, stride);
412 else
413 copy_bgra(d, pixels, output->current_mode->height, stride);
414 break;
415 case PIXMAN_x8b8g8r8:
416 case PIXMAN_a8b8g8r8:
417 if (compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP)
418 copy_rgba_yflip(d, s, output->current_mode->height, stride);
419 else
420 copy_rgba(d, pixels, output->current_mode->height, stride);
421 break;
422 default:
423 break;
424 }
425
426 wl_shm_buffer_end_access(l->buffer->shm_buffer);
427
428 l->done(l->data, WESTON_TEST_SCREENSHOT_SUCCESS);
429 free(pixels);
430 free(l);
431}
432
433static bool
434weston_test_screenshot_shoot(struct weston_output *output,
435 struct weston_buffer *buffer,
436 weston_test_screenshot_done_func_t done,
437 void *data)
438{
439 struct test_screenshot_frame_listener *l;
440
441 /* Get the shm buffer resource the client created */
442 if (!wl_shm_buffer_get(buffer->resource)) {
443 done(data, WESTON_TEST_SCREENSHOT_BAD_BUFFER);
444 return false;
445 }
446
447 buffer->shm_buffer = wl_shm_buffer_get(buffer->resource);
448 buffer->width = wl_shm_buffer_get_width(buffer->shm_buffer);
449 buffer->height = wl_shm_buffer_get_height(buffer->shm_buffer);
450
451 /* Verify buffer is big enough */
452 if (buffer->width < output->current_mode->width ||
453 buffer->height < output->current_mode->height) {
454 done(data, WESTON_TEST_SCREENSHOT_BAD_BUFFER);
455 return false;
456 }
457
458 /* allocate the frame listener */
459 l = malloc(sizeof *l);
460 if (l == NULL) {
461 done(data, WESTON_TEST_SCREENSHOT_NO_MEMORY);
462 return false;
463 }
464
465 /* Set up the listener */
466 l->buffer = buffer;
467 l->done = done;
468 l->data = data;
469 l->listener.notify = test_screenshot_frame_notify;
470 wl_signal_add(&output->frame_signal, &l->listener);
471
472 /* Fire off a repaint */
473 output->disable_planes++;
474 weston_output_schedule_repaint(output);
475
476 return true;
477}
478
479static void
480capture_screenshot_done(void *data, enum weston_test_screenshot_outcome outcome)
481{
482 struct wl_resource *resource = data;
483
484 switch (outcome) {
485 case WESTON_TEST_SCREENSHOT_SUCCESS:
486 weston_test_send_capture_screenshot_done(resource);
487 break;
488 case WESTON_TEST_SCREENSHOT_NO_MEMORY:
489 wl_resource_post_no_memory(resource);
490 break;
491 default:
492 break;
493 }
494}
495
496
497/**
498 * Grabs a snapshot of the screen.
499 */
500static void
501capture_screenshot(struct wl_client *client,
502 struct wl_resource *resource,
503 struct wl_resource *output_resource,
504 struct wl_resource *buffer_resource)
505{
506 struct weston_output *output =
507 wl_resource_get_user_data(output_resource);
508 struct weston_buffer *buffer =
509 weston_buffer_from_resource(buffer_resource);
510
511 if (buffer == NULL) {
512 wl_resource_post_no_memory(resource);
513 return;
514 }
515
516 weston_test_screenshot_shoot(output, buffer,
517 capture_screenshot_done, resource);
518}
519
Derek Foremanf6a65922015-02-24 09:32:14 -0600520static const struct weston_test_interface test_implementation = {
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800521 move_surface,
522 move_pointer,
523 send_button,
524 activate_surface,
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000525 send_key,
Marek Chalupac8daf772015-03-30 06:37:55 -0400526 device_release,
527 device_add,
Neil Roberts40c0c3f2013-10-29 20:13:45 +0000528 get_n_buffers,
Bryce Harringtonf280d112015-05-05 15:13:20 -0700529 capture_screenshot,
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800530};
531
532static void
533bind_test(struct wl_client *client, void *data, uint32_t version, uint32_t id)
534{
535 struct weston_test *test = data;
536 struct wl_resource *resource;
537
Derek Foremanf6a65922015-02-24 09:32:14 -0600538 resource = wl_resource_create(client, &weston_test_interface, 1, id);
Marek Chalupa42ebdda2014-07-11 12:33:02 +0200539 if (!resource) {
540 wl_client_post_no_memory(client);
541 return;
542 }
543
Kristian Høgsberg442a5fa2013-07-03 18:13:33 -0400544 wl_resource_set_implementation(resource,
545 &test_implementation, test, NULL);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800546
547 notify_pointer_position(test, resource);
548}
549
550static void
551idle_launch_client(void *data)
552{
553 struct weston_test *test = data;
554 pid_t pid;
555 sigset_t allsigs;
556 char *path;
557
558 path = getenv("WESTON_TEST_CLIENT_PATH");
559 if (path == NULL)
Pekka Paalanenf72e4792013-11-21 16:23:57 +0200560 return;
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800561 pid = fork();
562 if (pid == -1)
563 exit(EXIT_FAILURE);
564 if (pid == 0) {
565 sigfillset(&allsigs);
566 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
567 execl(path, path, NULL);
568 weston_log("compositor: executing '%s' failed: %m\n", path);
569 exit(EXIT_FAILURE);
570 }
571
572 test->process.pid = pid;
573 test->process.cleanup = test_client_sigchld;
574 weston_watch_process(&test->process);
575}
576
577WL_EXPORT int
Kristian Høgsbergcb4685b2013-02-20 15:37:49 -0500578module_init(struct weston_compositor *ec,
Ossama Othmana50e6e42013-05-14 09:48:26 -0700579 int *argc, char *argv[])
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800580{
581 struct weston_test *test;
582 struct wl_event_loop *loop;
583
Peter Huttererf3d62272013-08-08 11:57:05 +1000584 test = zalloc(sizeof *test);
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800585 if (test == NULL)
586 return -1;
587
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800588 test->compositor = ec;
589 weston_layer_init(&test->layer, &ec->cursor_layer.link);
590
Derek Foremanf6a65922015-02-24 09:32:14 -0600591 if (wl_global_create(ec->wl_display, &weston_test_interface, 1,
Kristian Høgsberg919cddb2013-07-08 19:03:57 -0400592 test, bind_test) == NULL)
U. Artie Eoff65e7e7a2012-12-07 13:50:29 -0800593 return -1;
594
Marek Chalupac3c3fc42015-03-30 09:17:40 -0400595 /* create our own seat */
596 weston_seat_init(&test->seat, ec, "test-seat");
597
598 /* add devices */
599 weston_seat_init_pointer(&test->seat);
600 weston_seat_init_keyboard(&test->seat, NULL);
601 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}