Pekka Paalanen | 147e67c | 2020-02-27 17:04:45 +0200 | [diff] [blame] | 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 |
Pekka Paalanen | ef81388 | 2021-02-15 13:46:42 +0200 | [diff] [blame^] | 36 | #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 Paalanen | 147e67c | 2020-02-27 17:04:45 +0200 | [diff] [blame] | 51 | |
| 52 | struct setup_args { |
Pekka Paalanen | ef81388 | 2021-02-15 13:46:42 +0200 | [diff] [blame^] | 53 | struct fixture_metadata meta; |
Pekka Paalanen | 147e67c | 2020-02-27 17:04:45 +0200 | [diff] [blame] | 54 | enum renderer_type renderer; |
| 55 | int scale; |
| 56 | enum wl_output_transform transform; |
| 57 | const char *transform_name; |
| 58 | }; |
| 59 | |
| 60 | static const struct setup_args my_setup_args[] = { |
| 61 | RENDERERS(1, NORMAL), |
| 62 | RENDERERS(2, 90), |
| 63 | }; |
| 64 | |
| 65 | static enum test_result_code |
| 66 | fixture_setup(struct weston_test_harness *harness, const struct setup_args *arg) |
| 67 | { |
| 68 | struct compositor_setup setup; |
| 69 | |
| 70 | /* The width and height are chosen to produce 324x240 framebuffer, to |
| 71 | * emulate keeping the video mode constant. |
| 72 | * This resolution is divisible by 2 and 3. |
| 73 | * Headless multiplies the given size by scale. |
| 74 | */ |
| 75 | |
| 76 | compositor_setup_defaults(&setup); |
| 77 | setup.renderer = arg->renderer; |
| 78 | setup.width = 324 / arg->scale; |
| 79 | setup.height = 240 / arg->scale; |
| 80 | setup.scale = arg->scale; |
| 81 | setup.transform = arg->transform; |
| 82 | setup.shell = SHELL_TEST_DESKTOP; |
| 83 | |
| 84 | return weston_test_harness_execute_as_client(harness, &setup); |
| 85 | } |
Pekka Paalanen | ef81388 | 2021-02-15 13:46:42 +0200 | [diff] [blame^] | 86 | DECLARE_FIXTURE_SETUP_WITH_ARG(fixture_setup, my_setup_args, meta); |
Pekka Paalanen | 147e67c | 2020-02-27 17:04:45 +0200 | [diff] [blame] | 87 | |
| 88 | struct buffer_args { |
| 89 | int scale; |
| 90 | enum wl_output_transform transform; |
| 91 | const char *transform_name; |
| 92 | }; |
| 93 | |
| 94 | static const struct buffer_args my_buffer_args[] = { |
| 95 | /* { 1, TRANSFORM(NORMAL) }, done in output-transforms-test.c */ |
| 96 | { 1, TRANSFORM(90) }, |
| 97 | { 1, TRANSFORM(180) }, |
| 98 | { 1, TRANSFORM(270) }, |
| 99 | { 1, TRANSFORM(FLIPPED) }, |
| 100 | { 1, TRANSFORM(FLIPPED_90) }, |
| 101 | { 1, TRANSFORM(FLIPPED_180) }, |
| 102 | { 1, TRANSFORM(FLIPPED_270) }, |
| 103 | { 2, TRANSFORM(NORMAL) }, |
| 104 | /* { 2, TRANSFORM(90) }, done in output-transforms-test.c */ |
| 105 | { 2, TRANSFORM(180) }, |
| 106 | { 2, TRANSFORM(FLIPPED) }, |
| 107 | { 3, TRANSFORM(NORMAL) }, |
| 108 | { 3, TRANSFORM(FLIPPED_90) }, |
| 109 | }; |
| 110 | |
| 111 | TEST_P(buffer_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); |
| 150 | } |