1 /*
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
40 struct setup_args {
41 enum renderer_type renderer;
42 int scale;
43 enum wl_output_transform transform;
44 const char *transform_name;
45 };
46
47 static const struct setup_args my_setup_args[] = {
48 RENDERERS(1, NORMAL),
49 RENDERERS(1, 90),
50 RENDERERS(1, 180),
51 RENDERERS(1, 270),
52 RENDERERS(1, FLIPPED),
53 RENDERERS(1, FLIPPED_90),
54 RENDERERS(1, FLIPPED_180),
55 RENDERERS(1, FLIPPED_270),
56 RENDERERS(2, NORMAL),
57 RENDERERS(3, NORMAL),
58 RENDERERS(2, 90),
59 RENDERERS(2, 180),
60 RENDERERS(2, FLIPPED),
61 RENDERERS(3, FLIPPED_270),
62 };
63
64 static enum test_result_code
fixture_setup(struct weston_test_harness * harness,const struct setup_args * arg)65 fixture_setup(struct weston_test_harness *harness, const struct setup_args *arg)
66 {
67 struct compositor_setup setup;
68
69 /* The width and height are chosen to produce 324x240 framebuffer, to
70 * emulate keeping the video mode constant.
71 * This resolution is divisible by 2 and 3.
72 * Headless multiplies the given size by scale.
73 */
74
75 compositor_setup_defaults(&setup);
76 setup.renderer = arg->renderer;
77 setup.width = 324 / arg->scale;
78 setup.height = 240 / arg->scale;
79 setup.scale = arg->scale;
80 setup.transform = arg->transform;
81 setup.shell = SHELL_TEST_DESKTOP;
82
83 return weston_test_harness_execute_as_client(harness, &setup);
84 }
85 DECLARE_FIXTURE_SETUP_WITH_ARG(fixture_setup, my_setup_args);
86
87 struct buffer_args {
88 int scale;
89 enum wl_output_transform transform;
90 const char *transform_name;
91 };
92
93 static const struct buffer_args my_buffer_args[] = {
94 { 1, TRANSFORM(NORMAL) },
95 { 2, TRANSFORM(90) },
96 };
97
TEST_P(output_transform,my_buffer_args)98 TEST_P(output_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 }
138