blob: fdc86bbade652f0eeba66cfdf323eb1bfda7b1ba [file] [log] [blame]
Pekka Paalanen147e67c2020-02-27 17:04:45 +02001/*
2 * Copyright © 2020 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 <string.h>
30#include <sys/mman.h>
31
32#include "weston-test-client-helper.h"
33#include "weston-test-fixture-compositor.h"
34
35#define TRANSFORM(x) WL_OUTPUT_TRANSFORM_ ## x, #x
36#define RENDERERS(s, t) \
37 { RENDERER_PIXMAN, s, TRANSFORM(t) }, \
38 { RENDERER_GL, s, TRANSFORM(t) }
39
40struct setup_args {
41 enum renderer_type renderer;
42 int scale;
43 enum wl_output_transform transform;
44 const char *transform_name;
45};
46
47static const struct setup_args my_setup_args[] = {
48 RENDERERS(1, NORMAL),
49 RENDERERS(2, 90),
50};
51
52static enum test_result_code
53fixture_setup(struct weston_test_harness *harness, const struct setup_args *arg)
54{
55 struct compositor_setup setup;
56
57 /* The width and height are chosen to produce 324x240 framebuffer, to
58 * emulate keeping the video mode constant.
59 * This resolution is divisible by 2 and 3.
60 * Headless multiplies the given size by scale.
61 */
62
63 compositor_setup_defaults(&setup);
64 setup.renderer = arg->renderer;
65 setup.width = 324 / arg->scale;
66 setup.height = 240 / arg->scale;
67 setup.scale = arg->scale;
68 setup.transform = arg->transform;
69 setup.shell = SHELL_TEST_DESKTOP;
70
71 return weston_test_harness_execute_as_client(harness, &setup);
72}
73DECLARE_FIXTURE_SETUP_WITH_ARG(fixture_setup, my_setup_args);
74
75struct buffer_args {
76 int scale;
77 enum wl_output_transform transform;
78 const char *transform_name;
79};
80
81static const struct buffer_args my_buffer_args[] = {
82 /* { 1, TRANSFORM(NORMAL) }, done in output-transforms-test.c */
83 { 1, TRANSFORM(90) },
84 { 1, TRANSFORM(180) },
85 { 1, TRANSFORM(270) },
86 { 1, TRANSFORM(FLIPPED) },
87 { 1, TRANSFORM(FLIPPED_90) },
88 { 1, TRANSFORM(FLIPPED_180) },
89 { 1, TRANSFORM(FLIPPED_270) },
90 { 2, TRANSFORM(NORMAL) },
91 /* { 2, TRANSFORM(90) }, done in output-transforms-test.c */
92 { 2, TRANSFORM(180) },
93 { 2, TRANSFORM(FLIPPED) },
94 { 3, TRANSFORM(NORMAL) },
95 { 3, TRANSFORM(FLIPPED_90) },
96};
97
98TEST_P(buffer_transform, my_buffer_args)
99{
100 const struct buffer_args *bargs = data;
101 const struct setup_args *oargs;
102 struct client *client;
103 bool match;
104 char *refname;
105 int ret;
106
107 oargs = &my_setup_args[get_test_fixture_index()];
108
109 ret = asprintf(&refname, "output_%d-%s_buffer_%d-%s",
110 oargs->scale, oargs->transform_name,
111 bargs->scale, bargs->transform_name);
112 assert(ret);
113
114 testlog("%s: %s\n", get_test_name(), refname);
115
116 /*
117 * NOTE! The transform set below is a lie.
118 * Take that into account when analyzing screenshots.
119 */
120
121 client = create_client();
122 client->surface = create_test_surface(client);
123 client->surface->width = 10000; /* used only for damage */
124 client->surface->height = 10000;
125 client->surface->buffer = client_buffer_from_image_file(client,
126 "basic-test-card",
127 bargs->scale);
128 wl_surface_set_buffer_scale(client->surface->wl_surface, bargs->scale);
129 wl_surface_set_buffer_transform(client->surface->wl_surface,
130 bargs->transform);
131 move_client(client, 19, 19);
132
133 match = verify_screen_content(client, refname, 0, NULL, 0);
134 assert(match);
135
136 client_destroy(client);
137}