blob: 2dd6be4c8ee8f8daa9fd776ad5addc3c901f0884 [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"
37#include "viewporter-client-protocol.h"
38
39static struct wp_viewporter *
40get_viewporter(struct client *client)
41{
42 struct global *g;
43 struct global *global_wpr = NULL;
Pekka Paalanen40588282019-11-05 15:40:25 +020044 struct wp_viewporter *wpr;
Pekka Paalanen82d95a62016-04-19 17:20:42 +030045
46 wl_list_for_each(g, &client->global_list, link) {
47 if (strcmp(g->interface, wp_viewporter_interface.name))
48 continue;
49
50 if (global_wpr)
51 assert(0 && "multiple wp_viewporter objects");
52
53 global_wpr = g;
54 }
55
56 assert(global_wpr && "no wp_viewporter found");
57
58 assert(global_wpr->version == 1);
59
60 wpr = wl_registry_bind(client->wl_registry, global_wpr->name,
61 &wp_viewporter_interface, 1);
62 assert(wpr);
63
64 return wpr;
65}
66
67static struct wp_viewport *
68create_viewport(struct client *client)
69{
70 struct wp_viewporter *viewporter;
71 struct wp_viewport *viewport;
72
73 viewporter = get_viewporter(client);
74 viewport = wp_viewporter_get_viewport(viewporter,
75 client->surface->wl_surface);
76 assert(viewport);
77
78 return viewport;
79}
80
81static void
82set_source(struct wp_viewport *vp, int x, int y, int w, int h)
83{
84 wp_viewport_set_source(vp, wl_fixed_from_int(x), wl_fixed_from_int(y),
85 wl_fixed_from_int(w), wl_fixed_from_int(h));
86}
87
88TEST(test_viewporter_double_create)
89{
90 struct wp_viewporter *viewporter;
91 struct client *client;
92
93 client = create_client_and_test_surface(100, 50, 123, 77);
94
95 viewporter = get_viewporter(client);
96 wp_viewporter_get_viewport(viewporter, client->surface->wl_surface);
97 wp_viewporter_get_viewport(viewporter, client->surface->wl_surface);
98
99 expect_protocol_error(client, &wp_viewporter_interface,
100 WP_VIEWPORTER_ERROR_VIEWPORT_EXISTS);
101}
102
103struct bad_source_rect_args {
104 int x, y, w, h;
105};
106
107static const struct bad_source_rect_args bad_source_rect_args[] = {
108 { -5, 0, 20, 10 },
109 { 0, -5, 20, 10 },
110 { 5, 6, 0, 10 },
111 { 5, 6, 20, 0 },
112 { 5, 6, -20, 10 },
113 { 5, 6, 20, -10 },
114 { -1, -1, 20, 10 },
115 { 5, 6, -1, -1 },
116};
117
118TEST_P(test_viewporter_bad_source_rect, bad_source_rect_args)
119{
120 const struct bad_source_rect_args *args = data;
121 struct client *client;
122 struct wp_viewport *vp;
123
124 client = create_client_and_test_surface(100, 50, 123, 77);
125
126 vp = create_viewport(client);
127
Pekka Paalanen12a138d2019-11-06 15:59:33 +0200128 testlog("wp_viewport.set_source x=%d, y=%d, w=%d, h=%d\n",
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300129 args->x, args->y, args->w, args->h);
130 set_source(vp, args->x, args->y, args->w, args->h);
131
132 expect_protocol_error(client, &wp_viewport_interface,
133 WP_VIEWPORT_ERROR_BAD_VALUE);
134}
135
136TEST(test_viewporter_unset_source_rect)
137{
138 struct client *client;
139 struct wp_viewport *vp;
140
141 client = create_client_and_test_surface(100, 50, 123, 77);
142
143 vp = create_viewport(client);
144 set_source(vp, -1, -1, -1, -1);
145 wl_surface_commit(client->surface->wl_surface);
146
147 client_roundtrip(client);
148}
149
150struct bad_destination_args {
151 int w, h;
152};
153
154static const struct bad_destination_args bad_destination_args[] = {
155 { 0, 10 },
156 { 20, 0 },
157 { -20, 10 },
158 { -1, 10 },
159 { 20, -10 },
160 { 20, -1 },
161};
162
163TEST_P(test_viewporter_bad_destination_size, bad_destination_args)
164{
165 const struct bad_destination_args *args = data;
166 struct client *client;
167 struct wp_viewport *vp;
168
169 client = create_client_and_test_surface(100, 50, 123, 77);
170
171 vp = create_viewport(client);
172
Pekka Paalanen12a138d2019-11-06 15:59:33 +0200173 testlog("wp_viewport.set_destination w=%d, h=%d\n", args->w, args->h);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300174 wp_viewport_set_destination(vp, args->w, args->h);
175
176 expect_protocol_error(client, &wp_viewport_interface,
177 WP_VIEWPORT_ERROR_BAD_VALUE);
178}
179
180TEST(test_viewporter_unset_destination_size)
181{
182 struct client *client;
183 struct wp_viewport *vp;
184
185 client = create_client_and_test_surface(100, 50, 123, 77);
186
187 vp = create_viewport(client);
188 wp_viewport_set_destination(vp, -1, -1);
189 wl_surface_commit(client->surface->wl_surface);
190
191 client_roundtrip(client);
192}
193
194struct nonint_destination_args {
195 wl_fixed_t w, h;
196};
197
198static const struct nonint_destination_args nonint_destination_args[] = {
199#define F(i,f) ((i) * 256 + (f))
200 { F(20, 0), F(10, 1) },
201 { F(20, 0), F(10, -1) },
202 { F(20, 1), F(10, 0) },
203 { F(20, -1), F(10, 0) },
204 { F(20, 128), F(10, 128) },
205#undef F
206};
207
208TEST_P(test_viewporter_non_integer_destination_size, nonint_destination_args)
209{
210 const struct nonint_destination_args *args = data;
211 struct client *client;
212 struct wp_viewport *vp;
213
214 client = create_client_and_test_surface(100, 50, 123, 77);
215
216 vp = create_viewport(client);
217
Pekka Paalanen12a138d2019-11-06 15:59:33 +0200218 testlog("non-integer size w=%f, h=%f\n",
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300219 wl_fixed_to_double(args->w), wl_fixed_to_double(args->h));
220 wp_viewport_set_source(vp, 5, 6, args->w, args->h);
221 wp_viewport_set_destination(vp, -1, -1);
222 wl_surface_commit(client->surface->wl_surface);
223
224 expect_protocol_error(client, &wp_viewport_interface,
225 WP_VIEWPORT_ERROR_BAD_SIZE);
226}
227
228struct source_buffer_args {
229 wl_fixed_t x, y;
230 wl_fixed_t w, h;
231 int buffer_scale;
232 enum wl_output_transform buffer_transform;
233};
234
235static int
236get_surface_width(struct surface *surface,
237 int buffer_scale,
238 enum wl_output_transform buffer_transform)
239{
240 switch (buffer_transform) {
241 case WL_OUTPUT_TRANSFORM_NORMAL:
242 case WL_OUTPUT_TRANSFORM_180:
243 case WL_OUTPUT_TRANSFORM_FLIPPED:
244 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
245 return surface->width / buffer_scale;
246 case WL_OUTPUT_TRANSFORM_90:
247 case WL_OUTPUT_TRANSFORM_270:
248 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
249 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
250 return surface->height / buffer_scale;
251 }
252
253 return -1;
254}
255
256static int
257get_surface_height(struct surface *surface,
258 int buffer_scale,
259 enum wl_output_transform buffer_transform)
260{
261 switch (buffer_transform) {
262 case WL_OUTPUT_TRANSFORM_NORMAL:
263 case WL_OUTPUT_TRANSFORM_180:
264 case WL_OUTPUT_TRANSFORM_FLIPPED:
265 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
266 return surface->height / buffer_scale;
267 case WL_OUTPUT_TRANSFORM_90:
268 case WL_OUTPUT_TRANSFORM_270:
269 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
270 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
271 return surface->width / buffer_scale;
272 }
273
274 return -1;
275}
276
277static void
278setup_source_vs_buffer(struct client *client,
279 const struct source_buffer_args *args)
280{
281 struct wl_surface *surf;
282 struct wp_viewport *vp;
283
284 surf = client->surface->wl_surface;
285 vp = create_viewport(client);
286
Pekka Paalanen12a138d2019-11-06 15:59:33 +0200287 testlog("surface %dx%d\n",
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300288 get_surface_width(client->surface,
289 args->buffer_scale, args->buffer_transform),
290 get_surface_height(client->surface,
291 args->buffer_scale, args->buffer_transform));
Pekka Paalanen12a138d2019-11-06 15:59:33 +0200292 testlog("source x=%f, y=%f, w=%f, h=%f; "
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300293 "buffer scale=%d, transform=%d\n",
294 wl_fixed_to_double(args->x), wl_fixed_to_double(args->y),
295 wl_fixed_to_double(args->w), wl_fixed_to_double(args->h),
296 args->buffer_scale, args->buffer_transform);
297
298 wl_surface_set_buffer_scale(surf, args->buffer_scale);
299 wl_surface_set_buffer_transform(surf, args->buffer_transform);
Pekka Paalanen924cd942016-05-20 17:25:38 +0300300 wl_surface_attach(surf, client->surface->buffer->proxy, 0, 0);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300301 wp_viewport_set_source(vp, args->x, args->y, args->w, args->h);
302 wp_viewport_set_destination(vp, 99, 99);
303 wl_surface_commit(surf);
304}
305
306/* buffer dimensions */
307#define WIN_W 124
308#define WIN_H 78
309
310/* source rect base size */
311#define SRC_W 20
312#define SRC_H 10
313
314/* margin */
315#define MRG 10
316/* epsilon of wl_fixed_t */
317#define EPS 1
318
319TEST(test_viewporter_source_buffer_params)
320{
321 const int max_scale = 2;
322
323 /* buffer_scale requirement */
324 assert(WIN_W % max_scale == 0);
325 assert(WIN_H % max_scale == 0);
326
327 /* source rect must fit inside regardless of scale and transform */
328 assert(SRC_W < WIN_W / max_scale);
329 assert(SRC_H < WIN_H / max_scale);
330 assert(SRC_W < WIN_H / max_scale);
331 assert(SRC_H < WIN_W / max_scale);
332
333 /* If buffer scale was ignored, source rect should be inside instead */
334 assert(WIN_W / max_scale + SRC_W + MRG < WIN_W);
335 assert(WIN_H / max_scale + SRC_H + MRG < WIN_H);
336 assert(WIN_W / max_scale + SRC_H + MRG < WIN_W);
337 assert(WIN_H / max_scale + SRC_W + MRG < WIN_H);
338}
339
340static const struct source_buffer_args bad_source_buffer_args[] = {
341#define F(i) ((i) * 256)
342
343/* Flush right-top, but epsilon too far right. */
344 { F(WIN_W - SRC_W) + EPS, F(0), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_NORMAL },
345 { F(WIN_W - SRC_W), F(0), F(SRC_W) + EPS, F(SRC_H), 1, WL_OUTPUT_TRANSFORM_NORMAL },
346/* Flush left-bottom, but epsilon too far down. */
347 { F(0), F(WIN_H - SRC_H) + EPS, F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_NORMAL },
348 { F(0), F(WIN_H - SRC_H), F(SRC_W), F(SRC_H) + EPS, 1, WL_OUTPUT_TRANSFORM_NORMAL },
349/* Completely outside on the right. */
350 { F(WIN_W + MRG), F(0), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_NORMAL },
351/* Competely outside on the bottom. */
352 { F(0), F(WIN_H + MRG), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_NORMAL },
353
354/*
355 * buffer_scale=2, so the surface size will be halved.
356 * If buffer_scale was not taken into account, these would all be inside.
357 * These are the same as above, but adapted to buffer_scale=2.
358 */
359 { F(WIN_W / 2 - SRC_W) + EPS, F(0), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_NORMAL },
360 { F(WIN_W / 2 - SRC_W), F(0), F(SRC_W) + EPS, F(SRC_H), 2, WL_OUTPUT_TRANSFORM_NORMAL },
361
362 { F(0), F(WIN_H / 2 - SRC_H) + EPS, F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_NORMAL },
363 { F(0), F(WIN_H / 2 - SRC_H), F(SRC_W), F(SRC_H) + EPS, 2, WL_OUTPUT_TRANSFORM_NORMAL },
364
365 { F(WIN_W / 2 + MRG), F(0), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_NORMAL },
366
367 { F(0), F(WIN_H / 2 + MRG), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_NORMAL },
368
369/* Exceeding bottom-right corner by epsilon: */
370/* non-dimension-swapping transforms */
371 { F(WIN_W - SRC_W), F(WIN_H - SRC_H), F(SRC_W), F(SRC_H) + EPS, 1, WL_OUTPUT_TRANSFORM_FLIPPED_180 },
372 { F(WIN_W - SRC_W), F(WIN_H - SRC_H) + EPS, F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_FLIPPED },
373 { F(WIN_W - SRC_W), F(WIN_H - SRC_H), F(SRC_W) + EPS, F(SRC_H), 1, WL_OUTPUT_TRANSFORM_180 },
374
375/* dimension-swapping transforms */
376 { F(WIN_H - SRC_W) + EPS, F(WIN_W - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_90 },
377 { F(WIN_H - SRC_W), F(WIN_W - SRC_H) + EPS, F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_270 },
378 { F(WIN_H - SRC_W), F(WIN_W - SRC_H), F(SRC_W) + EPS, F(SRC_H), 1, WL_OUTPUT_TRANSFORM_FLIPPED_90 },
379 { F(WIN_H - SRC_W), F(WIN_W - SRC_H), F(SRC_W), F(SRC_H) + EPS, 1, WL_OUTPUT_TRANSFORM_FLIPPED_270 },
380
381/* non-dimension-swapping transforms, buffer_scale=2 */
382 { 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 },
383 { F(WIN_W / 2 - SRC_W), F(WIN_H / 2 - SRC_H), F(SRC_W) + EPS, F(SRC_H), 2, WL_OUTPUT_TRANSFORM_FLIPPED },
384 { F(WIN_W / 2 - SRC_W), F(WIN_H / 2 - SRC_H), F(SRC_W), F(SRC_H) + EPS, 2, WL_OUTPUT_TRANSFORM_180 },
385
386/* dimension-swapping transforms, buffer_scale=2 */
387 { F(WIN_H / 2 - SRC_W) + EPS, F(WIN_W / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_90 },
388 { F(WIN_H / 2 - SRC_W), F(WIN_W / 2 - SRC_H) + EPS, F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_270 },
389 { 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 },
390 { 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 },
391
392#undef F
393};
394
395TEST_P(test_viewporter_source_outside_buffer, bad_source_buffer_args)
396{
397 const struct source_buffer_args *args = data;
398 struct client *client;
399
400 client = create_client_and_test_surface(100, 50, WIN_W, WIN_H);
401 setup_source_vs_buffer(client, args);
402
403 expect_protocol_error(client, &wp_viewport_interface,
404 WP_VIEWPORT_ERROR_OUT_OF_BUFFER);
405}
406
407static const struct source_buffer_args good_source_buffer_args[] = {
408#define F(i) ((i) * 256)
409
410/* top-left, top-right, bottom-left, and bottom-right corner */
411 { F(0), F(0), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_NORMAL },
412 { F(WIN_W - SRC_W), F(0), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_NORMAL },
413 { F(0), F(WIN_H - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_NORMAL },
414 { F(WIN_W - SRC_W), F(WIN_H - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_NORMAL },
415
416/* buffer_scale=2, so the surface size will be halved */
417 { F(0), F(0), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_NORMAL },
418 { F(WIN_W / 2 - SRC_W), F(0), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_NORMAL },
419 { F(0), F(WIN_H / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_NORMAL },
420 { F(WIN_W / 2 - SRC_W), F(WIN_H / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_NORMAL },
421
422/* with half pixel offset */
423 { 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 },
424
425/* Flushed to bottom-right corner: */
426/* non-dimension-swapping transforms */
427 { F(WIN_W - SRC_W), F(WIN_H - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_FLIPPED_180 },
428 { F(WIN_W - SRC_W), F(WIN_H - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_FLIPPED },
429 { F(WIN_W - SRC_W), F(WIN_H - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_180 },
430
431/* dimension-swapping transforms */
432 { F(WIN_H - SRC_W), F(WIN_W - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_90 },
433 { F(WIN_H - SRC_W), F(WIN_W - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_270 },
434 { F(WIN_H - SRC_W), F(WIN_W - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_FLIPPED_90 },
435 { F(WIN_H - SRC_W), F(WIN_W - SRC_H), F(SRC_W), F(SRC_H), 1, WL_OUTPUT_TRANSFORM_FLIPPED_270 },
436
437/* non-dimension-swapping transforms, buffer_scale=2 */
438 { F(WIN_W / 2 - SRC_W), F(WIN_H / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_FLIPPED_180 },
439 { F(WIN_W / 2 - SRC_W), F(WIN_H / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_FLIPPED },
440 { F(WIN_W / 2 - SRC_W), F(WIN_H / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_180 },
441
442/* dimension-swapping transforms, buffer_scale=2 */
443 { F(WIN_H / 2 - SRC_W), F(WIN_W / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_90 },
444 { F(WIN_H / 2 - SRC_W), F(WIN_W / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_270 },
445 { F(WIN_H / 2 - SRC_W), F(WIN_W / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_FLIPPED_90 },
446 { F(WIN_H / 2 - SRC_W), F(WIN_W / 2 - SRC_H), F(SRC_W), F(SRC_H), 2, WL_OUTPUT_TRANSFORM_FLIPPED_270 },
447
448#undef F
449};
450
451TEST_P(test_viewporter_source_inside_buffer, good_source_buffer_args)
452{
453 const struct source_buffer_args *args = data;
454 struct client *client;
455
456 client = create_client_and_test_surface(100, 50, WIN_W, WIN_H);
457 setup_source_vs_buffer(client, args);
458 client_roundtrip(client);
459}
460
461#undef WIN_W
462#undef WIN_H
463#undef SRC_W
464#undef SRC_H
465#undef MRG
466#undef EPS
467
468TEST(test_viewporter_outside_null_buffer)
469{
470 struct client *client;
471 struct wp_viewport *vp;
472 struct wl_surface *surf;
473
474 client = create_client_and_test_surface(100, 50, 123, 77);
475 surf = client->surface->wl_surface;
476
477 /* If buffer is NULL, does not matter what the source rect is. */
478 vp = create_viewport(client);
479 wl_surface_attach(surf, NULL, 0, 0);
480 set_source(vp, 1000, 1000, 20, 10);
481 wp_viewport_set_destination(vp, 99, 99);
482 wl_surface_commit(surf);
483 client_roundtrip(client);
484
485 /* Try again, with all old values. */
486 wl_surface_commit(surf);
487 client_roundtrip(client);
488
489 /* Try once more with old NULL buffer. */
490 set_source(vp, 1200, 1200, 20, 10);
491 wl_surface_commit(surf);
492 client_roundtrip(client);
493
494 /* When buffer comes back, source rect matters again. */
Pekka Paalanen924cd942016-05-20 17:25:38 +0300495 wl_surface_attach(surf, client->surface->buffer->proxy, 0, 0);
Pekka Paalanen82d95a62016-04-19 17:20:42 +0300496 wl_surface_commit(surf);
497 expect_protocol_error(client, &wp_viewport_interface,
498 WP_VIEWPORT_ERROR_OUT_OF_BUFFER);
499}
500
501TEST(test_viewporter_no_surface_set_source)
502{
503 struct client *client;
504 struct wp_viewport *vp;
505
506 client = create_client_and_test_surface(100, 50, 123, 77);
507 vp = create_viewport(client);
508 wl_surface_destroy(client->surface->wl_surface);
509 client->surface->wl_surface = NULL;
510
511 /* But the wl_surface does not exist anymore. */
512 set_source(vp, 1000, 1000, 20, 10);
513
514 expect_protocol_error(client, &wp_viewport_interface,
515 WP_VIEWPORT_ERROR_NO_SURFACE);
516}
517
518TEST(test_viewporter_no_surface_set_destination)
519{
520 struct client *client;
521 struct wp_viewport *vp;
522
523 client = create_client_and_test_surface(100, 50, 123, 77);
524 vp = create_viewport(client);
525 wl_surface_destroy(client->surface->wl_surface);
526 client->surface->wl_surface = NULL;
527
528 /* But the wl_surface does not exist anymore. */
529 wp_viewport_set_destination(vp, 99, 99);
530
531 expect_protocol_error(client, &wp_viewport_interface,
532 WP_VIEWPORT_ERROR_NO_SURFACE);
533}
534
535TEST(test_viewporter_no_surface_destroy)
536{
537 struct client *client;
538 struct wp_viewport *vp;
539
540 client = create_client_and_test_surface(100, 50, 123, 77);
541 vp = create_viewport(client);
542 wl_surface_destroy(client->surface->wl_surface);
543 client->surface->wl_surface = NULL;
544
545 /* But the wl_surface does not exist anymore. */
546 wp_viewport_destroy(vp);
547
548 client_roundtrip(client);
549}