Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Test cases for the drm_plane_helper functions
4 */
5
6#define pr_fmt(fmt) "drm_plane_helper: " fmt
7
8#include <drm/drm_atomic_helper.h>
9#include <drm/drm_framebuffer.h>
10#include <drm/drm_plane_helper.h>
11#include <drm/drm_modes.h>
12
13#include "test-drm_modeset_common.h"
14
15static void set_src(struct drm_plane_state *plane_state,
16 unsigned src_x, unsigned src_y,
17 unsigned src_w, unsigned src_h)
18{
19 plane_state->src_x = src_x;
20 plane_state->src_y = src_y;
21 plane_state->src_w = src_w;
22 plane_state->src_h = src_h;
23}
24
25static bool check_src_eq(struct drm_plane_state *plane_state,
26 unsigned src_x, unsigned src_y,
27 unsigned src_w, unsigned src_h)
28{
29 if (plane_state->src.x1 < 0) {
30 pr_err("src x coordinate %x should never be below 0.\n", plane_state->src.x1);
31 drm_rect_debug_print("src: ", &plane_state->src, true);
32 return false;
33 }
34 if (plane_state->src.y1 < 0) {
35 pr_err("src y coordinate %x should never be below 0.\n", plane_state->src.y1);
36 drm_rect_debug_print("src: ", &plane_state->src, true);
37 return false;
38 }
39
40 if (plane_state->src.x1 != src_x ||
41 plane_state->src.y1 != src_y ||
42 drm_rect_width(&plane_state->src) != src_w ||
43 drm_rect_height(&plane_state->src) != src_h) {
44 drm_rect_debug_print("src: ", &plane_state->src, true);
45 return false;
46 }
47
48 return true;
49}
50
51static void set_crtc(struct drm_plane_state *plane_state,
52 int crtc_x, int crtc_y,
53 unsigned crtc_w, unsigned crtc_h)
54{
55 plane_state->crtc_x = crtc_x;
56 plane_state->crtc_y = crtc_y;
57 plane_state->crtc_w = crtc_w;
58 plane_state->crtc_h = crtc_h;
59}
60
61static bool check_crtc_eq(struct drm_plane_state *plane_state,
62 int crtc_x, int crtc_y,
63 unsigned crtc_w, unsigned crtc_h)
64{
65 if (plane_state->dst.x1 != crtc_x ||
66 plane_state->dst.y1 != crtc_y ||
67 drm_rect_width(&plane_state->dst) != crtc_w ||
68 drm_rect_height(&plane_state->dst) != crtc_h) {
69 drm_rect_debug_print("dst: ", &plane_state->dst, false);
70
71 return false;
72 }
73
74 return true;
75}
76
77int igt_check_plane_state(void *ignored)
78{
79 int ret;
80
81 static const struct drm_crtc_state crtc_state = {
82 .crtc = ZERO_SIZE_PTR,
83 .enable = true,
84 .active = true,
85 .mode = {
86 DRM_MODE("1024x768", 0, 65000, 1024, 1048,
87 1184, 1344, 0, 768, 771, 777, 806, 0,
88 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC)
89 },
90 };
91 static struct drm_plane plane = {
92 .dev = NULL
93 };
94 static struct drm_framebuffer fb = {
95 .width = 2048,
96 .height = 2048
97 };
98 static struct drm_plane_state plane_state = {
99 .plane = &plane,
100 .crtc = ZERO_SIZE_PTR,
101 .fb = &fb,
102 .rotation = DRM_MODE_ROTATE_0
103 };
104
105 /* Simple clipping, no scaling. */
106 set_src(&plane_state, 0, 0, fb.width << 16, fb.height << 16);
107 set_crtc(&plane_state, 0, 0, fb.width, fb.height);
108 ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
109 DRM_PLANE_HELPER_NO_SCALING,
110 DRM_PLANE_HELPER_NO_SCALING,
111 false, false);
112 FAIL(ret < 0, "Simple clipping check should pass\n");
113 FAIL_ON(!plane_state.visible);
114 FAIL_ON(!check_src_eq(&plane_state, 0, 0, 1024 << 16, 768 << 16));
115 FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1024, 768));
116
117 /* Rotated clipping + reflection, no scaling. */
118 plane_state.rotation = DRM_MODE_ROTATE_90 | DRM_MODE_REFLECT_X;
119 ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
120 DRM_PLANE_HELPER_NO_SCALING,
121 DRM_PLANE_HELPER_NO_SCALING,
122 false, false);
123 FAIL(ret < 0, "Rotated clipping check should pass\n");
124 FAIL_ON(!plane_state.visible);
125 FAIL_ON(!check_src_eq(&plane_state, 0, 0, 768 << 16, 1024 << 16));
126 FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1024, 768));
127 plane_state.rotation = DRM_MODE_ROTATE_0;
128
129 /* Check whether positioning works correctly. */
130 set_src(&plane_state, 0, 0, 1023 << 16, 767 << 16);
131 set_crtc(&plane_state, 0, 0, 1023, 767);
132 ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
133 DRM_PLANE_HELPER_NO_SCALING,
134 DRM_PLANE_HELPER_NO_SCALING,
135 false, false);
136 FAIL(!ret, "Should not be able to position on the crtc with can_position=false\n");
137
138 ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
139 DRM_PLANE_HELPER_NO_SCALING,
140 DRM_PLANE_HELPER_NO_SCALING,
141 true, false);
142 FAIL(ret < 0, "Simple positioning should work\n");
143 FAIL_ON(!plane_state.visible);
144 FAIL_ON(!check_src_eq(&plane_state, 0, 0, 1023 << 16, 767 << 16));
145 FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1023, 767));
146
147 /* Simple scaling tests. */
148 set_src(&plane_state, 0, 0, 512 << 16, 384 << 16);
149 set_crtc(&plane_state, 0, 0, 1024, 768);
150 ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
151 0x8001,
152 DRM_PLANE_HELPER_NO_SCALING,
153 false, false);
154 FAIL(!ret, "Upscaling out of range should fail.\n");
155 ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
156 0x8000,
157 DRM_PLANE_HELPER_NO_SCALING,
158 false, false);
159 FAIL(ret < 0, "Upscaling exactly 2x should work\n");
160 FAIL_ON(!plane_state.visible);
161 FAIL_ON(!check_src_eq(&plane_state, 0, 0, 512 << 16, 384 << 16));
162 FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1024, 768));
163
164 set_src(&plane_state, 0, 0, 2048 << 16, 1536 << 16);
165 ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
166 DRM_PLANE_HELPER_NO_SCALING,
167 0x1ffff, false, false);
168 FAIL(!ret, "Downscaling out of range should fail.\n");
169 ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
170 DRM_PLANE_HELPER_NO_SCALING,
171 0x20000, false, false);
172 FAIL(ret < 0, "Should succeed with exact scaling limit\n");
173 FAIL_ON(!plane_state.visible);
174 FAIL_ON(!check_src_eq(&plane_state, 0, 0, 2048 << 16, 1536 << 16));
175 FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1024, 768));
176
177 /* Testing rounding errors. */
178 set_src(&plane_state, 0, 0, 0x40001, 0x40001);
179 set_crtc(&plane_state, 1022, 766, 4, 4);
180 ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
181 DRM_PLANE_HELPER_NO_SCALING,
182 0x10001,
183 true, false);
184 FAIL(ret < 0, "Should succeed by clipping to exact multiple");
185 FAIL_ON(!plane_state.visible);
186 FAIL_ON(!check_src_eq(&plane_state, 0, 0, 2 << 16, 2 << 16));
187 FAIL_ON(!check_crtc_eq(&plane_state, 1022, 766, 2, 2));
188
189 set_src(&plane_state, 0x20001, 0x20001, 0x4040001, 0x3040001);
190 set_crtc(&plane_state, -2, -2, 1028, 772);
191 ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
192 DRM_PLANE_HELPER_NO_SCALING,
193 0x10001,
194 false, false);
195 FAIL(ret < 0, "Should succeed by clipping to exact multiple");
196 FAIL_ON(!plane_state.visible);
197 FAIL_ON(!check_src_eq(&plane_state, 0x40002, 0x40002, 1024 << 16, 768 << 16));
198 FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1024, 768));
199
200 set_src(&plane_state, 0, 0, 0x3ffff, 0x3ffff);
201 set_crtc(&plane_state, 1022, 766, 4, 4);
202 ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
203 0xffff,
204 DRM_PLANE_HELPER_NO_SCALING,
205 true, false);
206 FAIL(ret < 0, "Should succeed by clipping to exact multiple");
207 FAIL_ON(!plane_state.visible);
208 /* Should not be rounded to 0x20001, which would be upscaling. */
209 FAIL_ON(!check_src_eq(&plane_state, 0, 0, 2 << 16, 2 << 16));
210 FAIL_ON(!check_crtc_eq(&plane_state, 1022, 766, 2, 2));
211
212 set_src(&plane_state, 0x1ffff, 0x1ffff, 0x403ffff, 0x303ffff);
213 set_crtc(&plane_state, -2, -2, 1028, 772);
214 ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
215 0xffff,
216 DRM_PLANE_HELPER_NO_SCALING,
217 false, false);
218 FAIL(ret < 0, "Should succeed by clipping to exact multiple");
219 FAIL_ON(!plane_state.visible);
220 FAIL_ON(!check_src_eq(&plane_state, 0x3fffe, 0x3fffe, 1024 << 16, 768 << 16));
221 FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1024, 768));
222
223 return 0;
224}