chandra konduru | a26f9f9 | 2015-03-30 13:52:04 -0700 | [diff] [blame] | 1 | /* |
| 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 Wood | 804e11f | 2015-08-17 17:57:43 +0100 | [diff] [blame^] | 25 | #include "igt.h" |
chandra konduru | a26f9f9 | 2015-03-30 13:52:04 -0700 | [diff] [blame] | 26 | #include <math.h> |
| 27 | |
chandra konduru | a26f9f9 | 2015-03-30 13:52:04 -0700 | [diff] [blame] | 28 | |
| 29 | IGT_TEST_DESCRIPTION("Test display plane scaling"); |
| 30 | |
| 31 | typedef 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 | |
| 58 | static void |
| 59 | paint_color(data_t *d, struct igt_fb *fb, uint16_t w, uint16_t h) |
| 60 | { |
| 61 | cairo_t *cr; |
| 62 | |
| 63 | cr = igt_get_cairo_ctx(d->drm_fd, fb); |
| 64 | igt_paint_test_pattern(cr, w, h); |
| 65 | cairo_destroy(cr); |
| 66 | } |
| 67 | |
| 68 | static void |
| 69 | paint_image(data_t *d, struct igt_fb *fb, uint16_t w, uint16_t h) |
| 70 | { |
| 71 | cairo_t *cr; |
| 72 | |
| 73 | cr = igt_get_cairo_ctx(d->drm_fd, fb); |
| 74 | igt_paint_image(cr, FILE_NAME, 0, 0, w, h); |
| 75 | cairo_destroy(cr); |
| 76 | } |
| 77 | |
| 78 | static void prepare_crtc(data_t *data, igt_output_t *output, enum pipe pipe, |
| 79 | igt_plane_t *plane, drmModeModeInfo *mode, enum igt_commit_style s) |
| 80 | { |
| 81 | igt_display_t *display = &data->display; |
| 82 | |
| 83 | igt_output_set_pipe(output, pipe); |
| 84 | |
| 85 | /* create the pipe_crc object for this pipe */ |
| 86 | igt_pipe_crc_free(data->pipe_crc); |
| 87 | data->pipe_crc = igt_pipe_crc_new(pipe, INTEL_PIPE_CRC_SOURCE_AUTO); |
| 88 | |
| 89 | /* before allocating, free if any older fb */ |
| 90 | if (data->fb_id1) { |
| 91 | igt_remove_fb(data->drm_fd, &data->fb1); |
| 92 | data->fb_id1 = 0; |
| 93 | } |
| 94 | |
| 95 | /* allocate fb for plane 1 */ |
| 96 | data->fb_id1 = igt_create_fb(data->drm_fd, |
| 97 | mode->hdisplay, mode->vdisplay, |
| 98 | DRM_FORMAT_XRGB8888, |
| 99 | LOCAL_I915_FORMAT_MOD_X_TILED, /* tiled */ |
| 100 | &data->fb1); |
| 101 | igt_assert(data->fb_id1); |
| 102 | |
| 103 | paint_color(data, &data->fb1, mode->hdisplay, mode->vdisplay); |
| 104 | |
| 105 | /* |
| 106 | * We always set the primary plane to actually enable the pipe as |
| 107 | * there's no way (that works) to light up a pipe with only a sprite |
| 108 | * plane enabled at the moment. |
| 109 | */ |
| 110 | if (!plane->is_primary) { |
| 111 | igt_plane_t *primary; |
| 112 | |
| 113 | primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY); |
| 114 | igt_plane_set_fb(primary, &data->fb1); |
| 115 | } |
| 116 | |
| 117 | igt_plane_set_fb(plane, &data->fb1); |
| 118 | if (s == COMMIT_LEGACY) { |
| 119 | int ret; |
| 120 | ret = drmModeSetCrtc(data->drm_fd, |
| 121 | output->config.crtc->crtc_id, |
| 122 | data->fb_id1, |
| 123 | plane->pan_x, plane->pan_y, |
| 124 | &output->id, |
| 125 | 1, |
| 126 | mode); |
| 127 | igt_assert(ret == 0); |
| 128 | } else { |
| 129 | igt_display_commit2(display, s); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | static void cleanup_crtc(data_t *data, igt_output_t *output, igt_plane_t *plane) |
| 134 | { |
| 135 | igt_display_t *display = &data->display; |
| 136 | |
| 137 | igt_pipe_crc_free(data->pipe_crc); |
| 138 | data->pipe_crc = NULL; |
| 139 | |
| 140 | if (data->fb_id1) { |
| 141 | igt_remove_fb(data->drm_fd, &data->fb1); |
| 142 | data->fb_id1 = 0; |
| 143 | } |
| 144 | if (data->fb_id2) { |
| 145 | igt_remove_fb(data->drm_fd, &data->fb2); |
| 146 | data->fb_id2 = 0; |
| 147 | } |
| 148 | if (data->fb_id3) { |
| 149 | igt_remove_fb(data->drm_fd, &data->fb3); |
| 150 | data->fb_id3 = 0; |
| 151 | } |
| 152 | |
| 153 | if (!plane->is_primary) { |
| 154 | igt_plane_t *primary; |
| 155 | |
| 156 | primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY); |
| 157 | igt_plane_set_fb(primary, NULL); |
| 158 | } |
| 159 | |
| 160 | igt_plane_set_fb(plane, NULL); |
| 161 | igt_output_set_pipe(output, PIPE_ANY); |
| 162 | |
| 163 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
| 164 | } |
| 165 | |
| 166 | /* does iterative scaling on plane2 */ |
| 167 | static void iterate_plane_scaling(data_t *d, drmModeModeInfo *mode) |
| 168 | { |
| 169 | igt_display_t *display = &d->display; |
| 170 | |
| 171 | if (mode->hdisplay >= d->fb2.width) { |
| 172 | int w, h; |
| 173 | /* fixed fb */ |
| 174 | igt_fb_set_position(&d->fb2, d->plane2, 0, 0); |
| 175 | igt_fb_set_size(&d->fb2, d->plane2, d->fb2.width, d->fb2.height); |
| 176 | igt_plane_set_position(d->plane2, 0, 0); |
| 177 | |
| 178 | /* adjust plane size */ |
| 179 | for (w = d->fb2.width; w <= mode->hdisplay; w+=10) { |
| 180 | h = w * d->fb2.height / d->fb2.width; |
| 181 | igt_plane_set_size(d->plane2, w, h); |
| 182 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
| 183 | } |
| 184 | } else { |
| 185 | int w, h; |
| 186 | /* fixed plane */ |
| 187 | igt_plane_set_position(d->plane2, 0, 0); |
| 188 | igt_plane_set_size(d->plane2, mode->hdisplay, mode->vdisplay); |
| 189 | igt_fb_set_position(&d->fb2, d->plane2, 0, 0); |
| 190 | |
| 191 | /* adjust fb size */ |
| 192 | for (w = mode->hdisplay; w <= d->fb2.width; w+=10) { |
| 193 | h = w * mode->hdisplay / mode->vdisplay; |
| 194 | igt_fb_set_size(&d->fb2, d->plane2, w, h); |
| 195 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | static void test_plane_scaling(data_t *d) |
| 201 | { |
| 202 | igt_display_t *display = &d->display; |
| 203 | igt_output_t *output; |
| 204 | cairo_surface_t *image; |
| 205 | enum pipe pipe; |
| 206 | int valid_tests = 0; |
| 207 | int primary_plane_scaling = 0; /* For now */ |
| 208 | |
| 209 | igt_require(d->display.has_universal_planes); |
| 210 | igt_require(d->num_scalers); |
| 211 | |
| 212 | for_each_connected_output(display, output) { |
| 213 | drmModeModeInfo *mode; |
| 214 | |
| 215 | pipe = output->config.pipe; |
| 216 | igt_output_set_pipe(output, pipe); |
| 217 | |
| 218 | mode = igt_output_get_mode(output); |
| 219 | |
| 220 | /* allocate fb2 with image size */ |
| 221 | image = cairo_image_surface_create_from_png(FILE_NAME); |
| 222 | igt_assert(cairo_surface_status(image) == CAIRO_STATUS_SUCCESS); |
| 223 | d->image_w = cairo_image_surface_get_width(image); |
| 224 | d->image_h = cairo_image_surface_get_height(image); |
| 225 | cairo_surface_destroy(image); |
| 226 | |
| 227 | d->fb_id2 = igt_create_fb(d->drm_fd, |
| 228 | d->image_w, d->image_h, |
| 229 | DRM_FORMAT_XRGB8888, |
| 230 | LOCAL_I915_FORMAT_MOD_X_TILED, /* tiled */ |
| 231 | &d->fb2); |
| 232 | igt_assert(d->fb_id2); |
| 233 | paint_image(d, &d->fb2, d->fb2.width, d->fb2.height); |
| 234 | |
| 235 | d->fb_id3 = igt_create_fb(d->drm_fd, |
| 236 | mode->hdisplay, mode->vdisplay, |
| 237 | DRM_FORMAT_XRGB8888, |
| 238 | LOCAL_I915_FORMAT_MOD_X_TILED, /* tiled */ |
| 239 | &d->fb3); |
| 240 | igt_assert(d->fb_id3); |
| 241 | paint_color(d, &d->fb3, mode->hdisplay, mode->vdisplay); |
| 242 | |
| 243 | /* Set up display with plane 1 */ |
| 244 | d->plane1 = igt_output_get_plane(output, IGT_PLANE_PRIMARY); |
| 245 | prepare_crtc(d, output, pipe, d->plane1, mode, COMMIT_UNIVERSAL); |
| 246 | |
| 247 | if (primary_plane_scaling) { |
| 248 | /* Primary plane upscaling */ |
| 249 | igt_fb_set_position(&d->fb1, d->plane1, 100, 100); |
| 250 | igt_fb_set_size(&d->fb1, d->plane1, 500, 500); |
| 251 | igt_plane_set_position(d->plane1, 0, 0); |
| 252 | igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay); |
| 253 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
| 254 | |
| 255 | /* Primary plane 1:1 no scaling */ |
| 256 | igt_fb_set_position(&d->fb1, d->plane1, 0, 0); |
| 257 | igt_fb_set_size(&d->fb1, d->plane1, d->fb1.width, d->fb1.height); |
| 258 | igt_plane_set_position(d->plane1, 0, 0); |
| 259 | igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay); |
| 260 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
| 261 | } |
| 262 | |
| 263 | /* Set up fb2->plane2 mapping. */ |
| 264 | d->plane2 = igt_output_get_plane(output, IGT_PLANE_2); |
| 265 | igt_plane_set_fb(d->plane2, &d->fb2); |
| 266 | |
| 267 | /* 2nd plane windowed */ |
| 268 | igt_fb_set_position(&d->fb2, d->plane2, 100, 100); |
| 269 | igt_fb_set_size(&d->fb2, d->plane2, d->fb2.width-200, d->fb2.height-200); |
| 270 | igt_plane_set_position(d->plane2, 100, 100); |
| 271 | igt_plane_set_size(d->plane2, mode->hdisplay-200, mode->vdisplay-200); |
| 272 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
| 273 | |
| 274 | iterate_plane_scaling(d, mode); |
| 275 | |
| 276 | /* 2nd plane up scaling */ |
| 277 | igt_fb_set_position(&d->fb2, d->plane2, 100, 100); |
| 278 | igt_fb_set_size(&d->fb2, d->plane2, 500, 500); |
| 279 | igt_plane_set_position(d->plane2, 10, 10); |
| 280 | igt_plane_set_size(d->plane2, mode->hdisplay-20, mode->vdisplay-20); |
| 281 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
| 282 | |
| 283 | /* 2nd plane downscaling */ |
| 284 | igt_fb_set_position(&d->fb2, d->plane2, 0, 0); |
| 285 | igt_fb_set_size(&d->fb2, d->plane2, d->fb2.width, d->fb2.height); |
| 286 | igt_plane_set_position(d->plane2, 10, 10); |
| 287 | igt_plane_set_size(d->plane2, 500, 500 * d->fb2.height/d->fb2.width); |
| 288 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
| 289 | |
| 290 | if (primary_plane_scaling) { |
| 291 | /* Primary plane up scaling */ |
| 292 | igt_fb_set_position(&d->fb1, d->plane1, 100, 100); |
| 293 | igt_fb_set_size(&d->fb1, d->plane1, 500, 500); |
| 294 | igt_plane_set_position(d->plane1, 0, 0); |
| 295 | igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay); |
| 296 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
| 297 | } |
| 298 | |
| 299 | /* Set up fb3->plane3 mapping. */ |
| 300 | d->plane3 = igt_output_get_plane(output, IGT_PLANE_3); |
| 301 | igt_plane_set_fb(d->plane3, &d->fb3); |
| 302 | |
| 303 | /* 3rd plane windowed - no scaling */ |
| 304 | igt_fb_set_position(&d->fb3, d->plane3, 100, 100); |
| 305 | igt_fb_set_size(&d->fb3, d->plane3, d->fb3.width-300, d->fb3.height-300); |
| 306 | igt_plane_set_position(d->plane3, 100, 100); |
| 307 | igt_plane_set_size(d->plane3, mode->hdisplay-300, mode->vdisplay-300); |
| 308 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
| 309 | |
| 310 | /* Switch scaler from plane 2 to plane 3 */ |
| 311 | igt_fb_set_position(&d->fb2, d->plane2, 100, 100); |
| 312 | igt_fb_set_size(&d->fb2, d->plane2, d->fb2.width-200, d->fb2.height-200); |
| 313 | igt_plane_set_position(d->plane2, 100, 100); |
| 314 | igt_plane_set_size(d->plane2, d->fb2.width-200, d->fb2.height-200); |
| 315 | |
| 316 | igt_fb_set_position(&d->fb3, d->plane3, 100, 100); |
| 317 | igt_fb_set_size(&d->fb3, d->plane3, d->fb3.width-400, d->fb3.height-400); |
| 318 | igt_plane_set_position(d->plane3, 10, 10); |
| 319 | igt_plane_set_size(d->plane3, mode->hdisplay-300, mode->vdisplay-300); |
| 320 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
| 321 | |
| 322 | if (primary_plane_scaling) { |
| 323 | /* Switch scaler from plane 1 to plane 2 */ |
| 324 | igt_fb_set_position(&d->fb1, d->plane1, 0, 0); |
| 325 | igt_fb_set_size(&d->fb1, d->plane1, d->fb1.width, d->fb1.height); |
| 326 | igt_plane_set_position(d->plane1, 0, 0); |
| 327 | igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay); |
| 328 | |
| 329 | igt_fb_set_position(&d->fb2, d->plane2, 100, 100); |
| 330 | igt_fb_set_size(&d->fb2, d->plane2, d->fb2.width-500,d->fb2.height-500); |
| 331 | igt_plane_set_position(d->plane2, 100, 100); |
| 332 | igt_plane_set_size(d->plane2, mode->hdisplay-200, mode->vdisplay-200); |
| 333 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
| 334 | } |
| 335 | |
| 336 | /* back to single plane mode */ |
| 337 | igt_plane_set_fb(d->plane2, NULL); |
| 338 | igt_plane_set_fb(d->plane3, NULL); |
| 339 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
| 340 | |
| 341 | valid_tests++; |
| 342 | cleanup_crtc(d, output, d->plane1); |
| 343 | } |
| 344 | igt_require_f(valid_tests, "no valid crtc/connector combinations found\n"); |
| 345 | } |
| 346 | |
| 347 | igt_simple_main |
| 348 | { |
| 349 | data_t data = {}; |
| 350 | |
| 351 | igt_skip_on_simulation(); |
| 352 | |
| 353 | |
| 354 | data.drm_fd = drm_open_any(); |
| 355 | igt_require_pipe_crc(); |
| 356 | igt_display_init(&data.display, data.drm_fd); |
| 357 | data.devid = intel_get_drm_devid(data.drm_fd); |
| 358 | |
| 359 | data.num_scalers = intel_gen(data.devid) >= 9 ? 2 : 0; |
| 360 | |
| 361 | test_plane_scaling(&data); |
| 362 | |
| 363 | igt_display_fini(&data.display); |
| 364 | } |