• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2012 Intel Corporation
3  * Copyright © 2013 Collabora, Ltd.
4  *
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:
12  *
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.
16  *
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
24  * SOFTWARE.
25  */
26 
27 #include "config.h"
28 
29 #include "weston-test-client-helper.h"
30 #include "weston-test-fixture-compositor.h"
31 
32 static enum test_result_code
fixture_setup(struct weston_test_harness * harness)33 fixture_setup(struct weston_test_harness *harness)
34 {
35 	struct compositor_setup setup;
36 
37 	compositor_setup_defaults(&setup);
38 
39 	return weston_test_harness_execute_as_client(harness, &setup);
40 }
41 DECLARE_FIXTURE_SETUP(fixture_setup);
42 
43 static int
output_contains_client(struct client * client)44 output_contains_client(struct client *client)
45 {
46 	struct output *output = client->output;
47 	struct surface *surface = client->surface;
48 
49 	return !(output->x >= surface->x + surface->width
50 		|| output->x + output->width <= surface->x
51 		|| output->y >= surface->y + surface->height
52 		|| output->y + output->height <= surface->y);
53 }
54 
55 static void
check_client_move(struct client * client,int x,int y)56 check_client_move(struct client *client, int x, int y)
57 {
58 	move_client(client, x, y);
59 
60 	if (output_contains_client(client)) {
61 		assert(client->surface->output == client->output);
62 	} else {
63 		assert(client->surface->output == NULL);
64 	}
65 }
66 
TEST(test_surface_output)67 TEST(test_surface_output)
68 {
69 	struct client *client;
70 	int x, y;
71 
72 	client = create_client_and_test_surface(100, 100, 100, 100);
73 	assert(client);
74 
75 	assert(output_contains_client(client));
76 
77 	/* not visible */
78 	x = 0;
79 	y = -client->surface->height;
80 	check_client_move(client, x, y);
81 
82 	/* visible */
83 	check_client_move(client, x, ++y);
84 
85 	/* not visible */
86 	x = -client->surface->width;
87 	y = 0;
88 	check_client_move(client, x, y);
89 
90 	/* visible */
91 	check_client_move(client, ++x, y);
92 
93 	/* not visible */
94 	x = client->output->width;
95 	y = 0;
96 	check_client_move(client, x, y);
97 
98 	/* visible */
99 	check_client_move(client, --x, y);
100 	assert(output_contains_client(client));
101 
102 	/* not visible */
103 	x = 0;
104 	y = client->output->height;
105 	check_client_move(client, x, y);
106 	assert(!output_contains_client(client));
107 
108 	/* visible */
109 	check_client_move(client, x, --y);
110 	assert(output_contains_client(client));
111 }
112 
113 static void
buffer_release_handler(void * data,struct wl_buffer * buffer)114 buffer_release_handler(void *data, struct wl_buffer *buffer)
115 {
116 	int *released = data;
117 
118 	*released = 1;
119 }
120 
121 static struct wl_buffer_listener buffer_listener = {
122 	buffer_release_handler
123 };
124 
TEST(buffer_release)125 TEST(buffer_release)
126 {
127 	struct client *client;
128 	struct wl_surface *surface;
129 	struct buffer *buf1;
130 	struct buffer *buf2;
131 	struct buffer *buf3;
132 	int buf1_released = 0;
133 	int buf2_released = 0;
134 	int buf3_released = 0;
135 	int frame;
136 
137 	client = create_client_and_test_surface(100, 100, 100, 100);
138 	assert(client);
139 	surface = client->surface->wl_surface;
140 
141 	buf1 = create_shm_buffer_a8r8g8b8(client, 100, 100);
142 	wl_buffer_add_listener(buf1->proxy, &buffer_listener, &buf1_released);
143 
144 	buf2 = create_shm_buffer_a8r8g8b8(client, 100, 100);
145 	wl_buffer_add_listener(buf2->proxy, &buffer_listener, &buf2_released);
146 
147 	buf3 = create_shm_buffer_a8r8g8b8(client, 100, 100);
148 	wl_buffer_add_listener(buf3->proxy, &buffer_listener, &buf3_released);
149 
150 	/*
151 	 * buf1 must never be released, since it is replaced before
152 	 * it is committed, therefore it never becomes busy.
153 	 */
154 
155 	wl_surface_attach(surface, buf1->proxy, 0, 0);
156 	wl_surface_attach(surface, buf2->proxy, 0, 0);
157 	frame_callback_set(surface, &frame);
158 	wl_surface_commit(surface);
159 	frame_callback_wait(client, &frame);
160 	assert(buf1_released == 0);
161 	/* buf2 may or may not be released */
162 	assert(buf3_released == 0);
163 
164 	wl_surface_attach(surface, buf3->proxy, 0, 0);
165 	frame_callback_set(surface, &frame);
166 	wl_surface_commit(surface);
167 	frame_callback_wait(client, &frame);
168 	assert(buf1_released == 0);
169 	assert(buf2_released == 1);
170 	/* buf3 may or may not be released */
171 
172 	wl_surface_attach(surface, client->surface->buffer->proxy, 0, 0);
173 	frame_callback_set(surface, &frame);
174 	wl_surface_commit(surface);
175 	frame_callback_wait(client, &frame);
176 	assert(buf1_released == 0);
177 	assert(buf2_released == 1);
178 	assert(buf3_released == 1);
179 }
180