blob: 392484d72973d6c09e4569e5145cfebbe40e184b [file] [log] [blame]
Pekka Paalanen97359ba2020-01-21 12:00:28 +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
Pekka Paalanenef813882021-02-15 13:46:42 +020036#define RENDERERS(s, t) \
37 { \
38 .renderer = RENDERER_PIXMAN, \
39 .scale = s, \
40 .transform = WL_OUTPUT_TRANSFORM_ ## t, \
41 .transform_name = #t, \
42 .meta.name = "pixman " #s " " #t, \
43 }, \
44 { \
45 .renderer = RENDERER_GL, \
46 .scale = s, \
47 .transform = WL_OUTPUT_TRANSFORM_ ## t, \
48 .transform_name = #t, \
49 .meta.name = "GL " #s " " #t, \
50 }
Pekka Paalanen97359ba2020-01-21 12:00:28 +020051
52struct setup_args {
Pekka Paalanenef813882021-02-15 13:46:42 +020053 struct fixture_metadata meta;
Pekka Paalanen97359ba2020-01-21 12:00:28 +020054 enum renderer_type renderer;
55 int scale;
56 enum wl_output_transform transform;
57 const char *transform_name;
58};
59
60static const struct setup_args my_setup_args[] = {
61 RENDERERS(1, NORMAL),
62 RENDERERS(1, 90),
63 RENDERERS(1, 180),
64 RENDERERS(1, 270),
65 RENDERERS(1, FLIPPED),
66 RENDERERS(1, FLIPPED_90),
67 RENDERERS(1, FLIPPED_180),
68 RENDERERS(1, FLIPPED_270),
69 RENDERERS(2, NORMAL),
70 RENDERERS(3, NORMAL),
71 RENDERERS(2, 90),
72 RENDERERS(2, 180),
73 RENDERERS(2, FLIPPED),
74 RENDERERS(3, FLIPPED_270),
75};
76
77static enum test_result_code
78fixture_setup(struct weston_test_harness *harness, const struct setup_args *arg)
79{
80 struct compositor_setup setup;
81
82 /* The width and height are chosen to produce 324x240 framebuffer, to
83 * emulate keeping the video mode constant.
84 * This resolution is divisible by 2 and 3.
85 * Headless multiplies the given size by scale.
86 */
87
88 compositor_setup_defaults(&setup);
89 setup.renderer = arg->renderer;
90 setup.width = 324 / arg->scale;
91 setup.height = 240 / arg->scale;
92 setup.scale = arg->scale;
93 setup.transform = arg->transform;
94 setup.shell = SHELL_TEST_DESKTOP;
95
96 return weston_test_harness_execute_as_client(harness, &setup);
97}
Pekka Paalanenef813882021-02-15 13:46:42 +020098DECLARE_FIXTURE_SETUP_WITH_ARG(fixture_setup, my_setup_args, meta);
Pekka Paalanen97359ba2020-01-21 12:00:28 +020099
100struct buffer_args {
101 int scale;
102 enum wl_output_transform transform;
103 const char *transform_name;
104};
105
106static const struct buffer_args my_buffer_args[] = {
107 { 1, TRANSFORM(NORMAL) },
108 { 2, TRANSFORM(90) },
109};
110
111TEST_P(output_transform, my_buffer_args)
112{
113 const struct buffer_args *bargs = data;
114 const struct setup_args *oargs;
115 struct client *client;
116 bool match;
117 char *refname;
118 int ret;
119
120 oargs = &my_setup_args[get_test_fixture_index()];
121
122 ret = asprintf(&refname, "output_%d-%s_buffer_%d-%s",
123 oargs->scale, oargs->transform_name,
124 bargs->scale, bargs->transform_name);
125 assert(ret);
126
127 testlog("%s: %s\n", get_test_name(), refname);
128
129 /*
130 * NOTE! The transform set below is a lie.
131 * Take that into account when analyzing screenshots.
132 */
133
134 client = create_client();
135 client->surface = create_test_surface(client);
136 client->surface->width = 10000; /* used only for damage */
137 client->surface->height = 10000;
138 client->surface->buffer = client_buffer_from_image_file(client,
139 "basic-test-card",
140 bargs->scale);
141 wl_surface_set_buffer_scale(client->surface->wl_surface, bargs->scale);
142 wl_surface_set_buffer_transform(client->surface->wl_surface,
143 bargs->transform);
144 move_client(client, 19, 19);
145
146 match = verify_screen_content(client, refname, 0, NULL, 0);
147 assert(match);
148
149 client_destroy(client);
Pekka Paalanenb0eb0592021-06-11 16:40:34 +0300150 free(refname);
Pekka Paalanen97359ba2020-01-21 12:00:28 +0200151}