2 * Copyright © 2012 Intel Corporation
3 * Copyright © 2013 Collabora, Ltd.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include "weston-test-client-helper.h"
32 output_contains_client(struct client *client)
34 struct output *output = client->output;
35 struct surface *surface = client->surface;
37 return !(output->x >= surface->x + surface->width
38 || output->x + output->width <= surface->x
39 || output->y >= surface->y + surface->height
40 || output->y + output->height <= surface->y);
44 check_client_move(struct client *client, int x, int y)
46 move_client(client, x, y);
48 if (output_contains_client(client)) {
49 assert(client->surface->output == client->output);
51 assert(client->surface->output == NULL);
55 TEST(test_surface_output)
57 struct client *client;
60 client = create_client_and_test_surface(100, 100, 100, 100);
63 assert(output_contains_client(client));
67 y = -client->surface->height;
68 check_client_move(client, x, y);
71 check_client_move(client, x, ++y);
74 x = -client->surface->width;
76 check_client_move(client, x, y);
79 check_client_move(client, ++x, y);
82 x = client->output->width;
84 check_client_move(client, x, y);
87 check_client_move(client, --x, y);
88 assert(output_contains_client(client));
92 y = client->output->height;
93 check_client_move(client, x, y);
94 assert(!output_contains_client(client));
97 check_client_move(client, x, --y);
98 assert(output_contains_client(client));
102 buffer_release_handler(void *data, struct wl_buffer *buffer)
104 int *released = data;
109 static struct wl_buffer_listener buffer_listener = {
110 buffer_release_handler
115 struct client *client;
116 struct wl_surface *surface;
120 int buf1_released = 0;
121 int buf2_released = 0;
122 int buf3_released = 0;
125 client = create_client_and_test_surface(100, 100, 100, 100);
127 surface = client->surface->wl_surface;
129 buf1 = create_shm_buffer_a8r8g8b8(client, 100, 100);
130 wl_buffer_add_listener(buf1->proxy, &buffer_listener, &buf1_released);
132 buf2 = create_shm_buffer_a8r8g8b8(client, 100, 100);
133 wl_buffer_add_listener(buf2->proxy, &buffer_listener, &buf2_released);
135 buf3 = create_shm_buffer_a8r8g8b8(client, 100, 100);
136 wl_buffer_add_listener(buf3->proxy, &buffer_listener, &buf3_released);
139 * buf1 must never be released, since it is replaced before
140 * it is committed, therefore it never becomes busy.
143 wl_surface_attach(surface, buf1->proxy, 0, 0);
144 wl_surface_attach(surface, buf2->proxy, 0, 0);
145 frame_callback_set(surface, &frame);
146 wl_surface_commit(surface);
147 frame_callback_wait(client, &frame);
148 assert(buf1_released == 0);
149 /* buf2 may or may not be released */
150 assert(buf3_released == 0);
152 wl_surface_attach(surface, buf3->proxy, 0, 0);
153 frame_callback_set(surface, &frame);
154 wl_surface_commit(surface);
155 frame_callback_wait(client, &frame);
156 assert(buf1_released == 0);
157 assert(buf2_released == 1);
158 /* buf3 may or may not be released */
160 wl_surface_attach(surface, client->surface->buffer->proxy, 0, 0);
161 frame_callback_set(surface, &frame);
162 wl_surface_commit(surface);
163 frame_callback_wait(client, &frame);
164 assert(buf1_released == 0);
165 assert(buf2_released == 1);
166 assert(buf3_released == 1);