blob: 4f010950646c3aa470d819b00c24ad7e252b436e [file] [log] [blame]
Pekka Paalanen82d95a62016-04-19 17:20:42 +03001/*
2 * Copyright © 2014, 2016 Collabora, Ltd.
3 *
4 * 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:
11 *
12 * 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.
24 */
25
26#include "config.h"
27
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31#include <assert.h>
32#include <time.h>
33
34#include "shared/helpers.h"
35#include "shared/xalloc.h"
36#include "weston-test-client-helper.h"
Pekka Paalanen701676d2019-11-13 15:45:10 +020037#include "weston-test-fixture-compositor.h"
38
39static enum test_result_code
40fixture_setup(struct weston_test_harness *harness)
41{
42 struct compositor_setup setup;
43
44 compositor_setup_defaults(&setup);
45
46 return weston_test_harness_execute_as_client(harness, &setup);
47}
48DECLARE_FIXTURE_SETUP(fixture_setup);
Pekka Paalanen82d95a62016-04-19 17:20:42 +030049
Pekka Paalanen82d95a62016-04-19 17:20:42 +030050static void
51set_source(struct wp_viewport *vp, int x, int y, int w, int h)
52{
53 wp_viewport_set_source(vp, wl_fixed_from_int(x), wl_fixed_from_int(y),
54 wl_fixed_from_int(w), wl_fixed_from_int(h));
55}
56
57TEST(test_viewporter_double_create)
58{
59 struct wp_viewporter *viewporter;
Pekka Paalanenef4d5c42021-05-24 14:33:19 +030060 struct wp_viewport *vp[2];
Pekka Paalanen82d95a62016-04-19 17:20:42 +030061 struct client *client;
62
63 client = create_client_and_test_surface(100, 50, 123, 77);
64
Pekka Paalanen9c267e52020-03-11 17:11:03 +020065 viewporter = bind_to_singleton_global(client,
66 &wp_viewporter_interface, 1);
Pekka Paalanenef4d5c42021-05-24 14:33:19 +030067 vp[0] = wp_viewporter_get_viewport(viewporter, client->surface->wl_surface);
68 vp[1] = wp_viewporter_get_viewport(viewporter, client->surface->wl_surface);
Pekka Paalanen82d95a62016-04-19 17:20:42 +030069
70 expect_protocol_error(client, &wp_viewporter_interface,
71 WP_VIEWPORTER_ERROR_VIEWPORT_EXISTS);
Pekka Paalanenef4d5c42021-05-24 14:33:19 +030072
73 wp_viewport_destroy(vp[1]);
74 wp_viewport_destroy(vp[0]);
75 wp_viewporter_destroy(viewporter);
76 client_destroy(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +030077}
78
79struct bad_source_rect_args {
80 int x, y, w, h;
81};
82
83static const struct bad_source_rect_args bad_source_rect_args[] = {
84 { -5, 0, 20, 10 },
85 { 0, -5, 20, 10 },
86 { 5, 6, 0, 10 },
87 { 5, 6, 20, 0 },
88 { 5, 6, -20, 10 },
89 { 5, 6, 20, -10 },
90 { -1, -1, 20, 10 },
91 { 5, 6, -1, -1 },
92};
93
94TEST_P(test_viewporter_bad_source_rect, bad_source_rect_args)
95{
96 const struct bad_source_rect_args *args = data;
97 struct client *client;
98 struct wp_viewport *vp;
99
100 client = create_client_and_test_surface(100, 50, 123, 77);
101
Pekka Paalanen9c267e52020-03-11 17:11:03 +0200102 vp = client_create_viewport(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300103
Pekka Paalanen12a138d2019-11-06 15:59:33 +0200104 testlog("wp_viewport.set_source x=%d, y=%d, w=%d, h=%d\n",
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300105 args->x, args->y, args->w, args->h);
106 set_source(vp, args->x, args->y, args->w, args->h);
107
108 expect_protocol_error(client, &wp_viewport_interface,
109 WP_VIEWPORT_ERROR_BAD_VALUE);
Pekka Paalanenef4d5c42021-05-24 14:33:19 +0300110
111 wp_viewport_destroy(vp);
112 client_destroy(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300113}
114
115TEST(test_viewporter_unset_source_rect)
116{
117 struct client *client;
118 struct wp_viewport *vp;
119
120 client = create_client_and_test_surface(100, 50, 123, 77);
121
Pekka Paalanen9c267e52020-03-11 17:11:03 +0200122 vp = client_create_viewport(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300123 set_source(vp, -1, -1, -1, -1);
124 wl_surface_commit(client->surface->wl_surface);
125
126 client_roundtrip(client);
Pekka Paalanenef4d5c42021-05-24 14:33:19 +0300127
128 wp_viewport_destroy(vp);
129 client_destroy(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300130}
131
132struct bad_destination_args {
133 int w, h;
134};
135
136static const struct bad_destination_args bad_destination_args[] = {
137 { 0, 10 },
138 { 20, 0 },
139 { -20, 10 },
140 { -1, 10 },
141 { 20, -10 },
142 { 20, -1 },
143};
144
145TEST_P(test_viewporter_bad_destination_size, bad_destination_args)
146{
147 const struct bad_destination_args *args = data;
148 struct client *client;
149 struct wp_viewport *vp;
150
151 client = create_client_and_test_surface(100, 50, 123, 77);
152
Pekka Paalanen9c267e52020-03-11 17:11:03 +0200153 vp = client_create_viewport(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300154
Pekka Paalanen12a138d2019-11-06 15:59:33 +0200155 testlog("wp_viewport.set_destination w=%d, h=%d\n", args->w, args->h);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300156 wp_viewport_set_destination(vp, args->w, args->h);
157
158 expect_protocol_error(client, &wp_viewport_interface,
159 WP_VIEWPORT_ERROR_BAD_VALUE);
Pekka Paalanenef4d5c42021-05-24 14:33:19 +0300160
161 wp_viewport_destroy(vp);
162 client_destroy(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300163}
164
165TEST(test_viewporter_unset_destination_size)
166{
167 struct client *client;
168 struct wp_viewport *vp;
169
170 client = create_client_and_test_surface(100, 50, 123, 77);
171
Pekka Paalanen9c267e52020-03-11 17:11:03 +0200172 vp = client_create_viewport(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300173 wp_viewport_set_destination(vp, -1, -1);
174 wl_surface_commit(client->surface->wl_surface);
175
176 client_roundtrip(client);
Pekka Paalanenef4d5c42021-05-24 14:33:19 +0300177
178 wp_viewport_destroy(vp);
179 client_destroy(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300180}
181
182struct nonint_destination_args {
183 wl_fixed_t w, h;
184};
185
186static const struct nonint_destination_args nonint_destination_args[] = {
187#define F(i,f) ((i) * 256 + (f))
188 { F(20, 0), F(10, 1) },
189 { F(20, 0), F(10, -1) },
190 { F(20, 1), F(10, 0) },
191 { F(20, -1), F(10, 0) },
192 { F(20, 128), F(10, 128) },
193#undef F
194};
195
196TEST_P(test_viewporter_non_integer_destination_size, nonint_destination_args)
197{
198 const struct nonint_destination_args *args = data;
199 struct client *client;
200 struct wp_viewport *vp;
201
202 client = create_client_and_test_surface(100, 50, 123, 77);
203
Pekka Paalanen9c267e52020-03-11 17:11:03 +0200204 vp = client_create_viewport(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300205
Pekka Paalanen12a138d2019-11-06 15:59:33 +0200206 testlog("non-integer size w=%f, h=%f\n",
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300207 wl_fixed_to_double(args->w), wl_fixed_to_double(args->h));
208 wp_viewport_set_source(vp, 5, 6, args->w, args->h);
209 wp_viewport_set_destination(vp, -1, -1);
210 wl_surface_commit(client->surface->wl_surface);
211
212 expect_protocol_error(client, &wp_viewport_interface,
213 WP_VIEWPORT_ERROR_BAD_SIZE);
Pekka Paalanenef4d5c42021-05-24 14:33:19 +0300214
215 wp_viewport_destroy(vp);
216 client_destroy(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300217}
218
219struct source_buffer_args {
220 wl_fixed_t x, y;
221 wl_fixed_t w, h;
222 int buffer_scale;
223 enum wl_output_transform buffer_transform;
224};
225
226static int
227get_surface_width(struct surface *surface,
228 int buffer_scale,
229 enum wl_output_transform buffer_transform)
230{
231 switch (buffer_transform) {
232 case WL_OUTPUT_TRANSFORM_NORMAL:
233 case WL_OUTPUT_TRANSFORM_180:
234 case WL_OUTPUT_TRANSFORM_FLIPPED:
235 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
236 return surface->width / buffer_scale;
237 case WL_OUTPUT_TRANSFORM_90:
238 case WL_OUTPUT_TRANSFORM_270:
239 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
240 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
241 return surface->height / buffer_scale;
242 }
243
244 return -1;
245}
246
247static int
248get_surface_height(struct surface *surface,
249 int buffer_scale,
250 enum wl_output_transform buffer_transform)
251{
252 switch (buffer_transform) {
253 case WL_OUTPUT_TRANSFORM_NORMAL:
254 case WL_OUTPUT_TRANSFORM_180:
255 case WL_OUTPUT_TRANSFORM_FLIPPED:
256 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
257 return surface->height / buffer_scale;
258 case WL_OUTPUT_TRANSFORM_90:
259 case WL_OUTPUT_TRANSFORM_270:
260 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
261 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
262 return surface->width / buffer_scale;
263 }
264
265 return -1;
266}
267
Pekka Paalanenef4d5c42021-05-24 14:33:19 +0300268static struct wp_viewport *
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300269setup_source_vs_buffer(struct client *client,
270 const struct source_buffer_args *args)
271{
272 struct wl_surface *surf;
273 struct wp_viewport *vp;
274
275 surf = client->surface->wl_surface;
Pekka Paalanen9c267e52020-03-11 17:11:03 +0200276 vp = client_create_viewport(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300277
Pekka Paalanen12a138d2019-11-06 15:59:33 +0200278 testlog("surface %dx%d\n",
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300279 get_surface_width(client->surface,
280 args->buffer_scale, args->buffer_transform),
281 get_surface_height(client->surface,
282 args->buffer_scale, args->buffer_transform));
Pekka Paalanen12a138d2019-11-06 15:59:33 +0200283 testlog("source x=%f, y=%f, w=%f, h=%f; "
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300284 "buffer scale=%d, transform=%d\n",
285 wl_fixed_to_double(args->x), wl_fixed_to_double(args->y),
286 wl_fixed_to_double(args->w), wl_fixed_to_double(args->h),
287 args->buffer_scale, args->buffer_transform);
288
289 wl_surface_set_buffer_scale(surf, args->buffer_scale);
290 wl_surface_set_buffer_transform(surf, args->buffer_transform);
Pekka Paalanen924cd942016-05-20 17:25:38 +0300291 wl_surface_attach(surf, client->surface->buffer->proxy, 0, 0);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300292 wp_viewport_set_source(vp, args->x, args->y, args->w, args->h);
293 wp_viewport_set_destination(vp, 99, 99);
294 wl_surface_commit(surf);
Pekka Paalanenef4d5c42021-05-24 14:33:19 +0300295
296 return vp;
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300297}
298
299/* buffer dimensions */
300#define WIN_W 124
301#define WIN_H 78
302
303/* source rect base size */
304#define SRC_W 20
305#define SRC_H 10
306
307/* margin */
308#define MRG 10
309/* epsilon of wl_fixed_t */
310#define EPS 1
311
312TEST(test_viewporter_source_buffer_params)
313{
314 const int max_scale = 2;
315
316 /* buffer_scale requirement */
317 assert(WIN_W % max_scale == 0);
318 assert(WIN_H % max_scale == 0);
319
320 /* source rect must fit inside regardless of scale and transform */
321 assert(SRC_W < WIN_W / max_scale);
322 assert(SRC_H < WIN_H / max_scale);
323 assert(SRC_W < WIN_H / max_scale);
324 assert(SRC_H < WIN_W / max_scale);
325
326 /* If buffer scale was ignored, source rect should be inside instead */
327 assert(WIN_W / max_scale + SRC_W + MRG < WIN_W);
328 assert(WIN_H / max_scale + SRC_H + MRG < WIN_H);
329 assert(WIN_W / max_scale + SRC_H + MRG < WIN_W);
330 assert(WIN_H / max_scale + SRC_W + MRG < WIN_H);
331}
332
333static const struct source_buffer_args bad_source_buffer_args[] = {
334#define F(i) ((i) * 256)
335
336/* Flush right-top, but epsilon too far right. */
337 { F(WIN_W - SRC_W) + EPS, F(0), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_NORMAL },
338 { F(WIN_W - SRC_W), F(0), F(SRC_W) + EPS, F(SRC_H), 1, WL_OUTPUT_TRANSFORM_NORMAL },
339/* Flush left-bottom, but epsilon too far down. */
340 { F(0), F(WIN_H - SRC_H) + EPS, F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_NORMAL },
341 { F(0), F(WIN_H - SRC_H), F(SRC_W), F(SRC_H) + EPS, 1, WL_OUTPUT_TRANSFORM_NORMAL },
342/* Completely outside on the right. */
343 { F(WIN_W + MRG), F(0), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_NORMAL },
344/* Competely outside on the bottom. */
345 { F(0), F(WIN_H + MRG), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_NORMAL },
346
347/*
348 * buffer_scale=2, so the surface size will be halved.
349 * If buffer_scale was not taken into account, these would all be inside.
350 * These are the same as above, but adapted to buffer_scale=2.
351 */
352 { F(WIN_W / 2 - SRC_W) + EPS, F(0), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_NORMAL },
353 { F(WIN_W / 2 - SRC_W), F(0), F(SRC_W) + EPS, F(SRC_H), 2, WL_OUTPUT_TRANSFORM_NORMAL },
354
355 { F(0), F(WIN_H / 2 - SRC_H) + EPS, F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_NORMAL },
356 { F(0), F(WIN_H / 2 - SRC_H), F(SRC_W), F(SRC_H) + EPS, 2, WL_OUTPUT_TRANSFORM_NORMAL },
357
358 { F(WIN_W / 2 + MRG), F(0), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_NORMAL },
359
360 { F(0), F(WIN_H / 2 + MRG), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_NORMAL },
361
362/* Exceeding bottom-right corner by epsilon: */
363/* non-dimension-swapping transforms */
364 { F(WIN_W - SRC_W), F(WIN_H - SRC_H), F(SRC_W), F(SRC_H) + EPS, 1, WL_OUTPUT_TRANSFORM_FLIPPED_180 },
365 { F(WIN_W - SRC_W), F(WIN_H - SRC_H) + EPS, F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_FLIPPED },
366 { F(WIN_W - SRC_W), F(WIN_H - SRC_H), F(SRC_W) + EPS, F(SRC_H), 1, WL_OUTPUT_TRANSFORM_180 },
367
368/* dimension-swapping transforms */
369 { F(WIN_H - SRC_W) + EPS, F(WIN_W - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_90 },
370 { F(WIN_H - SRC_W), F(WIN_W - SRC_H) + EPS, F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_270 },
371 { F(WIN_H - SRC_W), F(WIN_W - SRC_H), F(SRC_W) + EPS, F(SRC_H), 1, WL_OUTPUT_TRANSFORM_FLIPPED_90 },
372 { F(WIN_H - SRC_W), F(WIN_W - SRC_H), F(SRC_W), F(SRC_H) + EPS, 1, WL_OUTPUT_TRANSFORM_FLIPPED_270 },
373
374/* non-dimension-swapping transforms, buffer_scale=2 */
375 { F(WIN_W / 2 - SRC_W), F(WIN_H / 2 - SRC_H) + EPS, F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_FLIPPED_180 },
376 { F(WIN_W / 2 - SRC_W), F(WIN_H / 2 - SRC_H), F(SRC_W) + EPS, F(SRC_H), 2, WL_OUTPUT_TRANSFORM_FLIPPED },
377 { F(WIN_W / 2 - SRC_W), F(WIN_H / 2 - SRC_H), F(SRC_W), F(SRC_H) + EPS, 2, WL_OUTPUT_TRANSFORM_180 },
378
379/* dimension-swapping transforms, buffer_scale=2 */
380 { F(WIN_H / 2 - SRC_W) + EPS, F(WIN_W / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_90 },
381 { F(WIN_H / 2 - SRC_W), F(WIN_W / 2 - SRC_H) + EPS, F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_270 },
382 { F(WIN_H / 2 - SRC_W), F(WIN_W / 2 - SRC_H), F(SRC_W) + EPS, F(SRC_H), 2, WL_OUTPUT_TRANSFORM_FLIPPED_90 },
383 { F(WIN_H / 2 - SRC_W), F(WIN_W / 2 - SRC_H), F(SRC_W), F(SRC_H) + EPS, 2, WL_OUTPUT_TRANSFORM_FLIPPED_270 },
384
385#undef F
386};
387
388TEST_P(test_viewporter_source_outside_buffer, bad_source_buffer_args)
389{
390 const struct source_buffer_args *args = data;
391 struct client *client;
Pekka Paalanenef4d5c42021-05-24 14:33:19 +0300392 struct wp_viewport *vp;
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300393
394 client = create_client_and_test_surface(100, 50, WIN_W, WIN_H);
Pekka Paalanenef4d5c42021-05-24 14:33:19 +0300395 vp = setup_source_vs_buffer(client, args);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300396
397 expect_protocol_error(client, &wp_viewport_interface,
398 WP_VIEWPORT_ERROR_OUT_OF_BUFFER);
Pekka Paalanenef4d5c42021-05-24 14:33:19 +0300399
400 wp_viewport_destroy(vp);
401 client_destroy(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300402}
403
404static const struct source_buffer_args good_source_buffer_args[] = {
405#define F(i) ((i) * 256)
406
407/* top-left, top-right, bottom-left, and bottom-right corner */
408 { F(0), F(0), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_NORMAL },
409 { F(WIN_W - SRC_W), F(0), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_NORMAL },
410 { F(0), F(WIN_H - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_NORMAL },
411 { F(WIN_W - SRC_W), F(WIN_H - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_NORMAL },
412
413/* buffer_scale=2, so the surface size will be halved */
414 { F(0), F(0), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_NORMAL },
415 { F(WIN_W / 2 - SRC_W), F(0), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_NORMAL },
416 { F(0), F(WIN_H / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_NORMAL },
417 { F(WIN_W / 2 - SRC_W), F(WIN_H / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_NORMAL },
418
419/* with half pixel offset */
420 { F(WIN_W / 2 - SRC_W) + 128, F(WIN_H / 2 - SRC_H) + 128, F(SRC_W) - 128, F(SRC_H) - 128, 2, WL_OUTPUT_TRANSFORM_NORMAL },
421
422/* Flushed to bottom-right corner: */
423/* non-dimension-swapping transforms */
424 { F(WIN_W - SRC_W), F(WIN_H - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_FLIPPED_180 },
425 { F(WIN_W - SRC_W), F(WIN_H - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_FLIPPED },
426 { F(WIN_W - SRC_W), F(WIN_H - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_180 },
427
428/* dimension-swapping transforms */
429 { F(WIN_H - SRC_W), F(WIN_W - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_90 },
430 { F(WIN_H - SRC_W), F(WIN_W - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_270 },
431 { F(WIN_H - SRC_W), F(WIN_W - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_FLIPPED_90 },
432 { F(WIN_H - SRC_W), F(WIN_W - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_FLIPPED_270 },
433
434/* non-dimension-swapping transforms, buffer_scale=2 */
435 { F(WIN_W / 2 - SRC_W), F(WIN_H / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_FLIPPED_180 },
436 { F(WIN_W / 2 - SRC_W), F(WIN_H / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_FLIPPED },
437 { F(WIN_W / 2 - SRC_W), F(WIN_H / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_180 },
438
439/* dimension-swapping transforms, buffer_scale=2 */
440 { F(WIN_H / 2 - SRC_W), F(WIN_W / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_90 },
441 { F(WIN_H / 2 - SRC_W), F(WIN_W / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_270 },
442 { F(WIN_H / 2 - SRC_W), F(WIN_W / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_FLIPPED_90 },
443 { F(WIN_H / 2 - SRC_W), F(WIN_W / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_FLIPPED_270 },
444
445#undef F
446};
447
448TEST_P(test_viewporter_source_inside_buffer, good_source_buffer_args)
449{
450 const struct source_buffer_args *args = data;
451 struct client *client;
Pekka Paalanenef4d5c42021-05-24 14:33:19 +0300452 struct wp_viewport *vp;
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300453
454 client = create_client_and_test_surface(100, 50, WIN_W, WIN_H);
Pekka Paalanenef4d5c42021-05-24 14:33:19 +0300455 vp = setup_source_vs_buffer(client, args);
456 wp_viewport_destroy(vp);
457 client_destroy(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300458}
459
460#undef WIN_W
461#undef WIN_H
462#undef SRC_W
463#undef SRC_H
464#undef MRG
465#undef EPS
466
467TEST(test_viewporter_outside_null_buffer)
468{
469 struct client *client;
470 struct wp_viewport *vp;
471 struct wl_surface *surf;
472
473 client = create_client_and_test_surface(100, 50, 123, 77);
474 surf = client->surface->wl_surface;
475
476 /* If buffer is NULL, does not matter what the source rect is. */
Pekka Paalanen9c267e52020-03-11 17:11:03 +0200477 vp = client_create_viewport(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300478 wl_surface_attach(surf, NULL, 0, 0);
479 set_source(vp, 1000, 1000, 20, 10);
480 wp_viewport_set_destination(vp, 99, 99);
481 wl_surface_commit(surf);
482 client_roundtrip(client);
483
484 /* Try again, with all old values. */
485 wl_surface_commit(surf);
486 client_roundtrip(client);
487
488 /* Try once more with old NULL buffer. */
489 set_source(vp, 1200, 1200, 20, 10);
490 wl_surface_commit(surf);
491 client_roundtrip(client);
492
493 /* When buffer comes back, source rect matters again. */
Pekka Paalanen924cd942016-05-20 17:25:38 +0300494 wl_surface_attach(surf, client->surface->buffer->proxy, 0, 0);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300495 wl_surface_commit(surf);
496 expect_protocol_error(client, &wp_viewport_interface,
497 WP_VIEWPORT_ERROR_OUT_OF_BUFFER);
Pekka Paalanenef4d5c42021-05-24 14:33:19 +0300498
499 wp_viewport_destroy(vp);
500 client_destroy(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300501}
502
503TEST(test_viewporter_no_surface_set_source)
504{
505 struct client *client;
506 struct wp_viewport *vp;
507
508 client = create_client_and_test_surface(100, 50, 123, 77);
Pekka Paalanen9c267e52020-03-11 17:11:03 +0200509 vp = client_create_viewport(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300510 wl_surface_destroy(client->surface->wl_surface);
511 client->surface->wl_surface = NULL;
512
513 /* But the wl_surface does not exist anymore. */
514 set_source(vp, 1000, 1000, 20, 10);
515
516 expect_protocol_error(client, &wp_viewport_interface,
517 WP_VIEWPORT_ERROR_NO_SURFACE);
Pekka Paalanenef4d5c42021-05-24 14:33:19 +0300518
519 wp_viewport_destroy(vp);
520 client_destroy(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300521}
522
523TEST(test_viewporter_no_surface_set_destination)
524{
525 struct client *client;
526 struct wp_viewport *vp;
527
528 client = create_client_and_test_surface(100, 50, 123, 77);
Pekka Paalanen9c267e52020-03-11 17:11:03 +0200529 vp = client_create_viewport(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300530 wl_surface_destroy(client->surface->wl_surface);
531 client->surface->wl_surface = NULL;
532
533 /* But the wl_surface does not exist anymore. */
534 wp_viewport_set_destination(vp, 99, 99);
535
536 expect_protocol_error(client, &wp_viewport_interface,
537 WP_VIEWPORT_ERROR_NO_SURFACE);
Pekka Paalanenef4d5c42021-05-24 14:33:19 +0300538
539 wp_viewport_destroy(vp);
540 client_destroy(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300541}
542
543TEST(test_viewporter_no_surface_destroy)
544{
545 struct client *client;
546 struct wp_viewport *vp;
547
548 client = create_client_and_test_surface(100, 50, 123, 77);
Pekka Paalanen9c267e52020-03-11 17:11:03 +0200549 vp = client_create_viewport(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300550 wl_surface_destroy(client->surface->wl_surface);
551 client->surface->wl_surface = NULL;
552
553 /* But the wl_surface does not exist anymore. */
554 wp_viewport_destroy(vp);
555
Pekka Paalanenef4d5c42021-05-24 14:33:19 +0300556 client_destroy(client);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300557}