blob: 39bb5e1134117fbc5bed4c4052be59b60e09edd6 [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,
101 plane->pan_x, plane->pan_y,
102 &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
186 igt_require(d->display.has_universal_planes);
187 igt_require(d->num_scalers);
188
Maarten Lankhorst5af520a2016-07-05 12:53:05 +0200189 for_each_pipe_with_valid_output(display, pipe, output) {
chandra kondurua26f9f92015-03-30 13:52:04 -0700190 drmModeModeInfo *mode;
191
chandra kondurua26f9f92015-03-30 13:52:04 -0700192 igt_output_set_pipe(output, pipe);
193
194 mode = igt_output_get_mode(output);
195
196 /* allocate fb2 with image size */
Ville Syrjälä5b113d32015-12-17 01:39:31 +0200197 d->fb_id2 = igt_create_image_fb(d->drm_fd, 0, 0,
198 DRM_FORMAT_XRGB8888,
199 LOCAL_I915_FORMAT_MOD_X_TILED, /* tiled */
200 FILE_NAME, &d->fb2);
chandra kondurua26f9f92015-03-30 13:52:04 -0700201 igt_assert(d->fb_id2);
chandra kondurua26f9f92015-03-30 13:52:04 -0700202
Ville Syrjälä5b113d32015-12-17 01:39:31 +0200203 d->fb_id3 = igt_create_pattern_fb(d->drm_fd,
204 mode->hdisplay, mode->vdisplay,
205 DRM_FORMAT_XRGB8888,
206 LOCAL_I915_FORMAT_MOD_X_TILED, /* tiled */
207 &d->fb3);
chandra kondurua26f9f92015-03-30 13:52:04 -0700208 igt_assert(d->fb_id3);
chandra kondurua26f9f92015-03-30 13:52:04 -0700209
210 /* Set up display with plane 1 */
211 d->plane1 = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
212 prepare_crtc(d, output, pipe, d->plane1, mode, COMMIT_UNIVERSAL);
213
214 if (primary_plane_scaling) {
215 /* Primary plane upscaling */
216 igt_fb_set_position(&d->fb1, d->plane1, 100, 100);
217 igt_fb_set_size(&d->fb1, d->plane1, 500, 500);
218 igt_plane_set_position(d->plane1, 0, 0);
219 igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
220 igt_display_commit2(display, COMMIT_UNIVERSAL);
221
222 /* Primary plane 1:1 no scaling */
223 igt_fb_set_position(&d->fb1, d->plane1, 0, 0);
224 igt_fb_set_size(&d->fb1, d->plane1, d->fb1.width, d->fb1.height);
225 igt_plane_set_position(d->plane1, 0, 0);
226 igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
227 igt_display_commit2(display, COMMIT_UNIVERSAL);
228 }
229
230 /* Set up fb2->plane2 mapping. */
231 d->plane2 = igt_output_get_plane(output, IGT_PLANE_2);
232 igt_plane_set_fb(d->plane2, &d->fb2);
233
234 /* 2nd plane windowed */
235 igt_fb_set_position(&d->fb2, d->plane2, 100, 100);
236 igt_fb_set_size(&d->fb2, d->plane2, d->fb2.width-200, d->fb2.height-200);
237 igt_plane_set_position(d->plane2, 100, 100);
238 igt_plane_set_size(d->plane2, mode->hdisplay-200, mode->vdisplay-200);
239 igt_display_commit2(display, COMMIT_UNIVERSAL);
240
241 iterate_plane_scaling(d, mode);
242
243 /* 2nd plane up scaling */
244 igt_fb_set_position(&d->fb2, d->plane2, 100, 100);
245 igt_fb_set_size(&d->fb2, d->plane2, 500, 500);
246 igt_plane_set_position(d->plane2, 10, 10);
247 igt_plane_set_size(d->plane2, mode->hdisplay-20, mode->vdisplay-20);
248 igt_display_commit2(display, COMMIT_UNIVERSAL);
249
250 /* 2nd plane downscaling */
251 igt_fb_set_position(&d->fb2, d->plane2, 0, 0);
252 igt_fb_set_size(&d->fb2, d->plane2, d->fb2.width, d->fb2.height);
253 igt_plane_set_position(d->plane2, 10, 10);
254 igt_plane_set_size(d->plane2, 500, 500 * d->fb2.height/d->fb2.width);
255 igt_display_commit2(display, COMMIT_UNIVERSAL);
256
257 if (primary_plane_scaling) {
258 /* Primary plane up scaling */
259 igt_fb_set_position(&d->fb1, d->plane1, 100, 100);
260 igt_fb_set_size(&d->fb1, d->plane1, 500, 500);
261 igt_plane_set_position(d->plane1, 0, 0);
262 igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
263 igt_display_commit2(display, COMMIT_UNIVERSAL);
264 }
265
266 /* Set up fb3->plane3 mapping. */
267 d->plane3 = igt_output_get_plane(output, IGT_PLANE_3);
268 igt_plane_set_fb(d->plane3, &d->fb3);
269
270 /* 3rd plane windowed - no scaling */
271 igt_fb_set_position(&d->fb3, d->plane3, 100, 100);
272 igt_fb_set_size(&d->fb3, d->plane3, d->fb3.width-300, d->fb3.height-300);
273 igt_plane_set_position(d->plane3, 100, 100);
274 igt_plane_set_size(d->plane3, mode->hdisplay-300, mode->vdisplay-300);
275 igt_display_commit2(display, COMMIT_UNIVERSAL);
276
277 /* Switch scaler from plane 2 to plane 3 */
278 igt_fb_set_position(&d->fb2, d->plane2, 100, 100);
279 igt_fb_set_size(&d->fb2, d->plane2, d->fb2.width-200, d->fb2.height-200);
280 igt_plane_set_position(d->plane2, 100, 100);
281 igt_plane_set_size(d->plane2, d->fb2.width-200, d->fb2.height-200);
282
283 igt_fb_set_position(&d->fb3, d->plane3, 100, 100);
284 igt_fb_set_size(&d->fb3, d->plane3, d->fb3.width-400, d->fb3.height-400);
285 igt_plane_set_position(d->plane3, 10, 10);
286 igt_plane_set_size(d->plane3, mode->hdisplay-300, mode->vdisplay-300);
287 igt_display_commit2(display, COMMIT_UNIVERSAL);
288
289 if (primary_plane_scaling) {
290 /* Switch scaler from plane 1 to plane 2 */
291 igt_fb_set_position(&d->fb1, d->plane1, 0, 0);
292 igt_fb_set_size(&d->fb1, d->plane1, d->fb1.width, d->fb1.height);
293 igt_plane_set_position(d->plane1, 0, 0);
294 igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
295
296 igt_fb_set_position(&d->fb2, d->plane2, 100, 100);
297 igt_fb_set_size(&d->fb2, d->plane2, d->fb2.width-500,d->fb2.height-500);
298 igt_plane_set_position(d->plane2, 100, 100);
299 igt_plane_set_size(d->plane2, mode->hdisplay-200, mode->vdisplay-200);
300 igt_display_commit2(display, COMMIT_UNIVERSAL);
301 }
302
303 /* back to single plane mode */
304 igt_plane_set_fb(d->plane2, NULL);
305 igt_plane_set_fb(d->plane3, NULL);
306 igt_display_commit2(display, COMMIT_UNIVERSAL);
307
308 valid_tests++;
309 cleanup_crtc(d, output, d->plane1);
310 }
311 igt_require_f(valid_tests, "no valid crtc/connector combinations found\n");
312}
313
314igt_simple_main
315{
316 data_t data = {};
317
318 igt_skip_on_simulation();
319
320
Micah Fedkec81d2932015-07-22 21:54:02 +0000321 data.drm_fd = drm_open_driver(DRIVER_INTEL);
chandra kondurua26f9f92015-03-30 13:52:04 -0700322 igt_require_pipe_crc();
323 igt_display_init(&data.display, data.drm_fd);
324 data.devid = intel_get_drm_devid(data.drm_fd);
325
326 data.num_scalers = intel_gen(data.devid) >= 9 ? 2 : 0;
327
328 test_plane_scaling(&data);
329
330 igt_display_fini(&data.display);
331}