blob: 368da09f4c5318fb6b24dbddc5f4b1dcd22a5b17 [file] [log] [blame]
chandra kondurua26f9f92015-03-30 13:52:04 -07001/*
2 * Copyright © 2013,2014 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 */
24
Thomas Wood804e11f2015-08-17 17:57:43 +010025#include "igt.h"
chandra kondurua26f9f92015-03-30 13:52:04 -070026#include <math.h>
27
chandra kondurua26f9f92015-03-30 13:52:04 -070028
29IGT_TEST_DESCRIPTION("Test display plane scaling");
30
31typedef struct {
32 uint32_t devid;
33 int drm_fd;
34 igt_display_t display;
35 igt_crc_t ref_crc;
36 igt_pipe_crc_t *pipe_crc;
37
38 int image_w;
39 int image_h;
40
41 int num_scalers;
42
43 struct igt_fb fb1;
44 struct igt_fb fb2;
45 struct igt_fb fb3;
46 int fb_id1;
47 int fb_id2;
48 int fb_id3;
49
50 igt_plane_t *plane1;
51 igt_plane_t *plane2;
52 igt_plane_t *plane3;
53 igt_plane_t *plane4;
54} data_t;
55
56#define FILE_NAME "1080p-left.png"
57
chandra kondurua26f9f92015-03-30 13:52:04 -070058static void prepare_crtc(data_t *data, igt_output_t *output, enum pipe pipe,
59 igt_plane_t *plane, drmModeModeInfo *mode, enum igt_commit_style s)
60{
61 igt_display_t *display = &data->display;
62
63 igt_output_set_pipe(output, pipe);
64
65 /* create the pipe_crc object for this pipe */
66 igt_pipe_crc_free(data->pipe_crc);
67 data->pipe_crc = igt_pipe_crc_new(pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
68
69 /* before allocating, free if any older fb */
70 if (data->fb_id1) {
71 igt_remove_fb(data->drm_fd, &data->fb1);
72 data->fb_id1 = 0;
73 }
74
75 /* allocate fb for plane 1 */
Ville Syrjälä5b113d32015-12-17 01:39:31 +020076 data->fb_id1 = igt_create_pattern_fb(data->drm_fd,
77 mode->hdisplay, mode->vdisplay,
78 DRM_FORMAT_XRGB8888,
79 LOCAL_I915_FORMAT_MOD_X_TILED, /* tiled */
80 &data->fb1);
chandra kondurua26f9f92015-03-30 13:52:04 -070081 igt_assert(data->fb_id1);
82
chandra kondurua26f9f92015-03-30 13:52:04 -070083 /*
84 * We always set the primary plane to actually enable the pipe as
85 * there's no way (that works) to light up a pipe with only a sprite
86 * plane enabled at the moment.
87 */
88 if (!plane->is_primary) {
89 igt_plane_t *primary;
90
91 primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
92 igt_plane_set_fb(primary, &data->fb1);
93 }
94
95 igt_plane_set_fb(plane, &data->fb1);
96 if (s == COMMIT_LEGACY) {
97 int ret;
98 ret = drmModeSetCrtc(data->drm_fd,
Maarten Lankhorst5af520a2016-07-05 12:53:05 +020099 plane->pipe->crtc_id,
chandra kondurua26f9f92015-03-30 13:52:04 -0700100 data->fb_id1,
Maarten Lankhorst0e29ce32016-06-30 11:32:10 +0200101 plane->src_x, plane->src_y,
chandra kondurua26f9f92015-03-30 13:52:04 -0700102 &output->id,
103 1,
104 mode);
Daniel Stonede7ccdd2015-10-01 14:16:48 +0100105 igt_assert_eq(ret, 0);
chandra kondurua26f9f92015-03-30 13:52:04 -0700106 } else {
107 igt_display_commit2(display, s);
108 }
109}
110
111static void cleanup_crtc(data_t *data, igt_output_t *output, igt_plane_t *plane)
112{
113 igt_display_t *display = &data->display;
114
115 igt_pipe_crc_free(data->pipe_crc);
116 data->pipe_crc = NULL;
117
118 if (data->fb_id1) {
119 igt_remove_fb(data->drm_fd, &data->fb1);
120 data->fb_id1 = 0;
121 }
122 if (data->fb_id2) {
123 igt_remove_fb(data->drm_fd, &data->fb2);
124 data->fb_id2 = 0;
125 }
126 if (data->fb_id3) {
127 igt_remove_fb(data->drm_fd, &data->fb3);
128 data->fb_id3 = 0;
129 }
130
131 if (!plane->is_primary) {
132 igt_plane_t *primary;
133
134 primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
135 igt_plane_set_fb(primary, NULL);
136 }
137
138 igt_plane_set_fb(plane, NULL);
139 igt_output_set_pipe(output, PIPE_ANY);
140
141 igt_display_commit2(display, COMMIT_UNIVERSAL);
142}
143
144/* does iterative scaling on plane2 */
145static void iterate_plane_scaling(data_t *d, drmModeModeInfo *mode)
146{
147 igt_display_t *display = &d->display;
148
149 if (mode->hdisplay >= d->fb2.width) {
150 int w, h;
151 /* fixed fb */
152 igt_fb_set_position(&d->fb2, d->plane2, 0, 0);
153 igt_fb_set_size(&d->fb2, d->plane2, d->fb2.width, d->fb2.height);
154 igt_plane_set_position(d->plane2, 0, 0);
155
156 /* adjust plane size */
157 for (w = d->fb2.width; w <= mode->hdisplay; w+=10) {
158 h = w * d->fb2.height / d->fb2.width;
159 igt_plane_set_size(d->plane2, w, h);
160 igt_display_commit2(display, COMMIT_UNIVERSAL);
161 }
162 } else {
163 int w, h;
164 /* fixed plane */
165 igt_plane_set_position(d->plane2, 0, 0);
166 igt_plane_set_size(d->plane2, mode->hdisplay, mode->vdisplay);
167 igt_fb_set_position(&d->fb2, d->plane2, 0, 0);
168
169 /* adjust fb size */
170 for (w = mode->hdisplay; w <= d->fb2.width; w+=10) {
171 h = w * mode->hdisplay / mode->vdisplay;
172 igt_fb_set_size(&d->fb2, d->plane2, w, h);
173 igt_display_commit2(display, COMMIT_UNIVERSAL);
174 }
175 }
176}
177
178static void test_plane_scaling(data_t *d)
179{
180 igt_display_t *display = &d->display;
181 igt_output_t *output;
chandra kondurua26f9f92015-03-30 13:52:04 -0700182 enum pipe pipe;
183 int valid_tests = 0;
184 int primary_plane_scaling = 0; /* For now */
185
chandra kondurua26f9f92015-03-30 13:52:04 -0700186 igt_require(d->num_scalers);
187
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200188 for_each_pipe_with_valid_output(display, pipe, output) {
chandra kondurua26f9f92015-03-30 13:52:04 -0700189 drmModeModeInfo *mode;
190
chandra kondurua26f9f92015-03-30 13:52:04 -0700191 igt_output_set_pipe(output, pipe);
192
193 mode = igt_output_get_mode(output);
194
195 /* allocate fb2 with image size */
Ville Syrjälä5b113d32015-12-17 01:39:31 +0200196 d->fb_id2 = igt_create_image_fb(d->drm_fd, 0, 0,
197 DRM_FORMAT_XRGB8888,
198 LOCAL_I915_FORMAT_MOD_X_TILED, /* tiled */
199 FILE_NAME, &d->fb2);
chandra kondurua26f9f92015-03-30 13:52:04 -0700200 igt_assert(d->fb_id2);
chandra kondurua26f9f92015-03-30 13:52:04 -0700201
Ville Syrjälä5b113d32015-12-17 01:39:31 +0200202 d->fb_id3 = igt_create_pattern_fb(d->drm_fd,
203 mode->hdisplay, mode->vdisplay,
204 DRM_FORMAT_XRGB8888,
205 LOCAL_I915_FORMAT_MOD_X_TILED, /* tiled */
206 &d->fb3);
chandra kondurua26f9f92015-03-30 13:52:04 -0700207 igt_assert(d->fb_id3);
chandra kondurua26f9f92015-03-30 13:52:04 -0700208
209 /* Set up display with plane 1 */
210 d->plane1 = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
211 prepare_crtc(d, output, pipe, d->plane1, mode, COMMIT_UNIVERSAL);
212
213 if (primary_plane_scaling) {
214 /* Primary plane upscaling */
215 igt_fb_set_position(&d->fb1, d->plane1, 100, 100);
216 igt_fb_set_size(&d->fb1, d->plane1, 500, 500);
217 igt_plane_set_position(d->plane1, 0, 0);
218 igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
219 igt_display_commit2(display, COMMIT_UNIVERSAL);
220
221 /* Primary plane 1:1 no scaling */
222 igt_fb_set_position(&d->fb1, d->plane1, 0, 0);
223 igt_fb_set_size(&d->fb1, d->plane1, d->fb1.width, d->fb1.height);
224 igt_plane_set_position(d->plane1, 0, 0);
225 igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
226 igt_display_commit2(display, COMMIT_UNIVERSAL);
227 }
228
229 /* Set up fb2->plane2 mapping. */
230 d->plane2 = igt_output_get_plane(output, IGT_PLANE_2);
231 igt_plane_set_fb(d->plane2, &d->fb2);
232
233 /* 2nd plane windowed */
234 igt_fb_set_position(&d->fb2, d->plane2, 100, 100);
235 igt_fb_set_size(&d->fb2, d->plane2, d->fb2.width-200, d->fb2.height-200);
236 igt_plane_set_position(d->plane2, 100, 100);
237 igt_plane_set_size(d->plane2, mode->hdisplay-200, mode->vdisplay-200);
238 igt_display_commit2(display, COMMIT_UNIVERSAL);
239
240 iterate_plane_scaling(d, mode);
241
242 /* 2nd plane up scaling */
243 igt_fb_set_position(&d->fb2, d->plane2, 100, 100);
244 igt_fb_set_size(&d->fb2, d->plane2, 500, 500);
245 igt_plane_set_position(d->plane2, 10, 10);
246 igt_plane_set_size(d->plane2, mode->hdisplay-20, mode->vdisplay-20);
247 igt_display_commit2(display, COMMIT_UNIVERSAL);
248
249 /* 2nd plane downscaling */
250 igt_fb_set_position(&d->fb2, d->plane2, 0, 0);
251 igt_fb_set_size(&d->fb2, d->plane2, d->fb2.width, d->fb2.height);
252 igt_plane_set_position(d->plane2, 10, 10);
253 igt_plane_set_size(d->plane2, 500, 500 * d->fb2.height/d->fb2.width);
254 igt_display_commit2(display, COMMIT_UNIVERSAL);
255
256 if (primary_plane_scaling) {
257 /* Primary plane up scaling */
258 igt_fb_set_position(&d->fb1, d->plane1, 100, 100);
259 igt_fb_set_size(&d->fb1, d->plane1, 500, 500);
260 igt_plane_set_position(d->plane1, 0, 0);
261 igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
262 igt_display_commit2(display, COMMIT_UNIVERSAL);
263 }
264
265 /* Set up fb3->plane3 mapping. */
266 d->plane3 = igt_output_get_plane(output, IGT_PLANE_3);
267 igt_plane_set_fb(d->plane3, &d->fb3);
268
269 /* 3rd plane windowed - no scaling */
270 igt_fb_set_position(&d->fb3, d->plane3, 100, 100);
271 igt_fb_set_size(&d->fb3, d->plane3, d->fb3.width-300, d->fb3.height-300);
272 igt_plane_set_position(d->plane3, 100, 100);
273 igt_plane_set_size(d->plane3, mode->hdisplay-300, mode->vdisplay-300);
274 igt_display_commit2(display, COMMIT_UNIVERSAL);
275
276 /* Switch scaler from plane 2 to plane 3 */
277 igt_fb_set_position(&d->fb2, d->plane2, 100, 100);
278 igt_fb_set_size(&d->fb2, d->plane2, d->fb2.width-200, d->fb2.height-200);
279 igt_plane_set_position(d->plane2, 100, 100);
280 igt_plane_set_size(d->plane2, d->fb2.width-200, d->fb2.height-200);
281
282 igt_fb_set_position(&d->fb3, d->plane3, 100, 100);
283 igt_fb_set_size(&d->fb3, d->plane3, d->fb3.width-400, d->fb3.height-400);
284 igt_plane_set_position(d->plane3, 10, 10);
285 igt_plane_set_size(d->plane3, mode->hdisplay-300, mode->vdisplay-300);
286 igt_display_commit2(display, COMMIT_UNIVERSAL);
287
288 if (primary_plane_scaling) {
289 /* Switch scaler from plane 1 to plane 2 */
290 igt_fb_set_position(&d->fb1, d->plane1, 0, 0);
291 igt_fb_set_size(&d->fb1, d->plane1, d->fb1.width, d->fb1.height);
292 igt_plane_set_position(d->plane1, 0, 0);
293 igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
294
295 igt_fb_set_position(&d->fb2, d->plane2, 100, 100);
296 igt_fb_set_size(&d->fb2, d->plane2, d->fb2.width-500,d->fb2.height-500);
297 igt_plane_set_position(d->plane2, 100, 100);
298 igt_plane_set_size(d->plane2, mode->hdisplay-200, mode->vdisplay-200);
299 igt_display_commit2(display, COMMIT_UNIVERSAL);
300 }
301
302 /* back to single plane mode */
303 igt_plane_set_fb(d->plane2, NULL);
304 igt_plane_set_fb(d->plane3, NULL);
305 igt_display_commit2(display, COMMIT_UNIVERSAL);
306
307 valid_tests++;
308 cleanup_crtc(d, output, d->plane1);
309 }
310 igt_require_f(valid_tests, "no valid crtc/connector combinations found\n");
311}
312
313igt_simple_main
314{
315 data_t data = {};
316
317 igt_skip_on_simulation();
318
319
Micah Fedkec81d2932015-07-22 21:54:02 +0000320 data.drm_fd = drm_open_driver(DRIVER_INTEL);
chandra kondurua26f9f92015-03-30 13:52:04 -0700321 igt_require_pipe_crc();
322 igt_display_init(&data.display, data.drm_fd);
323 data.devid = intel_get_drm_devid(data.drm_fd);
324
325 data.num_scalers = intel_gen(data.devid) >= 9 ? 2 : 0;
326
327 test_plane_scaling(&data);
328
329 igt_display_fini(&data.display);
330}