Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2013 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 | |
| 25 | #include <errno.h> |
Ville Syrjälä | fee27cf | 2014-01-13 17:05:19 +0200 | [diff] [blame] | 26 | #include <limits.h> |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 27 | #include <stdbool.h> |
| 28 | #include <stdio.h> |
| 29 | #include <string.h> |
| 30 | |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 31 | #include "drmtest.h" |
| 32 | #include "igt_debugfs.h" |
Oscar Mateo | 37f26d1 | 2013-11-12 11:50:38 +0000 | [diff] [blame] | 33 | #include "igt_kms.h" |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 34 | |
Sagar Kamble | ba3a1a8 | 2014-03-18 15:59:43 +0530 | [diff] [blame] | 35 | #ifndef DRM_CAP_CURSOR_WIDTH |
| 36 | #define DRM_CAP_CURSOR_WIDTH 0x8 |
| 37 | #endif |
| 38 | #ifndef DRM_CAP_CURSOR_HEIGHT |
| 39 | #define DRM_CAP_CURSOR_HEIGHT 0x9 |
| 40 | #endif |
| 41 | |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 42 | typedef struct { |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 43 | int drm_fd; |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 44 | igt_display_t display; |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 45 | struct igt_fb primary_fb; |
Antti Koskipaa | a593d61 | 2014-04-10 15:08:05 +0300 | [diff] [blame] | 46 | struct igt_fb fb; |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 47 | igt_pipe_crc_t **pipe_crc; |
| 48 | } data_t; |
| 49 | |
| 50 | typedef struct { |
| 51 | data_t *data; |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 52 | igt_output_t *output; |
| 53 | enum pipe pipe; |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 54 | igt_crc_t ref_crc; |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 55 | int left, right, top, bottom; |
Antti Koskipaa | 795eddc | 2014-04-10 15:08:09 +0300 | [diff] [blame] | 56 | int screenw, screenh; |
Antti Koskipaa | fe8041b | 2014-04-10 15:08:07 +0300 | [diff] [blame] | 57 | int curw, curh; /* cursor size */ |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 58 | } test_data_t; |
| 59 | |
Antti Koskipaa | a593d61 | 2014-04-10 15:08:05 +0300 | [diff] [blame] | 60 | static void draw_cursor(cairo_t *cr, int x, int y, int w) |
| 61 | { |
| 62 | w /= 2; |
Antti Koskipaa | 795eddc | 2014-04-10 15:08:09 +0300 | [diff] [blame] | 63 | /* Cairo doesn't like to be fed numbers that are too wild */ |
| 64 | if ((x < SHRT_MIN) || (x > SHRT_MAX) || (y < SHRT_MIN) || (y > SHRT_MAX)) |
| 65 | return; |
Antti Koskipaa | a593d61 | 2014-04-10 15:08:05 +0300 | [diff] [blame] | 66 | cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); |
| 67 | /* 4 color rectangles in the corners, RGBY */ |
| 68 | igt_paint_color_alpha(cr, x, y, w, w, 1.0, 0.0, 0.0, 1.0); |
| 69 | igt_paint_color_alpha(cr, x + w, y, w, w, 0.0, 1.0, 0.0, 1.0); |
| 70 | igt_paint_color_alpha(cr, x, y + w, w, w, 0.0, 0.0, 1.0, 1.0); |
| 71 | igt_paint_color_alpha(cr, x + w, y + w, w, w, 0.5, 0.5, 0.5, 1.0); |
| 72 | } |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 73 | |
Antti Koskipaa | a593d61 | 2014-04-10 15:08:05 +0300 | [diff] [blame] | 74 | static void cursor_enable(test_data_t *test_data) |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 75 | { |
| 76 | data_t *data = test_data->data; |
| 77 | igt_display_t *display = &data->display; |
| 78 | igt_output_t *output = test_data->output; |
| 79 | igt_plane_t *cursor; |
| 80 | |
Damien Lespiau | 2043e6b | 2014-02-11 17:45:48 +0000 | [diff] [blame] | 81 | cursor = igt_output_get_plane(output, IGT_PLANE_CURSOR); |
Antti Koskipaa | a593d61 | 2014-04-10 15:08:05 +0300 | [diff] [blame] | 82 | igt_plane_set_fb(cursor, &data->fb); |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 83 | igt_display_commit(display); |
| 84 | } |
| 85 | |
| 86 | static void cursor_disable(test_data_t *test_data) |
| 87 | { |
| 88 | data_t *data = test_data->data; |
| 89 | igt_display_t *display = &data->display; |
| 90 | igt_output_t *output = test_data->output; |
| 91 | igt_plane_t *cursor; |
| 92 | |
Damien Lespiau | 2043e6b | 2014-02-11 17:45:48 +0000 | [diff] [blame] | 93 | cursor = igt_output_get_plane(output, IGT_PLANE_CURSOR); |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 94 | igt_plane_set_fb(cursor, NULL); |
| 95 | igt_display_commit(display); |
| 96 | } |
| 97 | |
Antti Koskipaa | 7ec631c | 2014-04-10 15:08:06 +0300 | [diff] [blame] | 98 | static igt_pipe_crc_t *create_crc(data_t *data, enum pipe pipe) |
| 99 | { |
| 100 | igt_pipe_crc_t *crc; |
| 101 | |
| 102 | crc = igt_pipe_crc_new(pipe, INTEL_PIPE_CRC_SOURCE_AUTO); |
| 103 | return crc; |
| 104 | } |
| 105 | |
| 106 | static void do_single_test(test_data_t *test_data, int x, int y) |
| 107 | { |
| 108 | data_t *data = test_data->data; |
| 109 | igt_display_t *display = &data->display; |
| 110 | igt_pipe_crc_t *pipe_crc = data->pipe_crc[test_data->pipe]; |
Antti Koskipaa | 795eddc | 2014-04-10 15:08:09 +0300 | [diff] [blame] | 111 | igt_crc_t crc, ref_crc; |
Antti Koskipaa | 7ec631c | 2014-04-10 15:08:06 +0300 | [diff] [blame] | 112 | igt_plane_t *cursor; |
Antti Koskipaa | 795eddc | 2014-04-10 15:08:09 +0300 | [diff] [blame] | 113 | cairo_t *cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb); |
Antti Koskipaa | 7ec631c | 2014-04-10 15:08:06 +0300 | [diff] [blame] | 114 | |
| 115 | printf("."); fflush(stdout); |
| 116 | |
Antti Koskipaa | 795eddc | 2014-04-10 15:08:09 +0300 | [diff] [blame] | 117 | /* Hardware test */ |
Antti Koskipaa | 7ec631c | 2014-04-10 15:08:06 +0300 | [diff] [blame] | 118 | cursor_enable(test_data); |
| 119 | cursor = igt_output_get_plane(test_data->output, IGT_PLANE_CURSOR); |
| 120 | igt_plane_set_position(cursor, x, y); |
| 121 | igt_display_commit(display); |
| 122 | igt_wait_for_vblank(data->drm_fd, test_data->pipe); |
| 123 | igt_pipe_crc_collect_crc(pipe_crc, &crc); |
| 124 | cursor_disable(test_data); |
| 125 | |
Antti Koskipaa | 795eddc | 2014-04-10 15:08:09 +0300 | [diff] [blame] | 126 | /* Now render the same in software and collect crc */ |
| 127 | draw_cursor(cr, x, y, test_data->curw); |
| 128 | igt_display_commit(display); |
| 129 | igt_wait_for_vblank(data->drm_fd, test_data->pipe); |
| 130 | igt_pipe_crc_collect_crc(pipe_crc, &ref_crc); |
| 131 | /* Clear screen afterwards */ |
| 132 | igt_paint_color(cr, 0, 0, test_data->screenw, test_data->screenh, |
| 133 | 0.0, 0.0, 0.0); |
| 134 | |
| 135 | igt_assert(igt_crc_equal(&crc, &ref_crc)); |
Antti Koskipaa | 7ec631c | 2014-04-10 15:08:06 +0300 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static void do_test(test_data_t *test_data, |
| 139 | int left, int right, int top, int bottom) |
| 140 | { |
| 141 | do_single_test(test_data, left, top); |
| 142 | do_single_test(test_data, right, top); |
| 143 | do_single_test(test_data, right, bottom); |
| 144 | do_single_test(test_data, left, bottom); |
| 145 | } |
| 146 | |
Antti Koskipaa | ead0173 | 2014-04-10 15:08:08 +0300 | [diff] [blame] | 147 | static void test_crc_onscreen(test_data_t *test_data) |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 148 | { |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 149 | int left = test_data->left; |
| 150 | int right = test_data->right; |
| 151 | int top = test_data->top; |
| 152 | int bottom = test_data->bottom; |
Antti Koskipaa | fe8041b | 2014-04-10 15:08:07 +0300 | [diff] [blame] | 153 | int cursor_w = test_data->curw; |
| 154 | int cursor_h = test_data->curh; |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 155 | |
Antti Koskipaa | ead0173 | 2014-04-10 15:08:08 +0300 | [diff] [blame] | 156 | /* fully inside */ |
| 157 | do_test(test_data, left, right, top, bottom); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 158 | |
Antti Koskipaa | ead0173 | 2014-04-10 15:08:08 +0300 | [diff] [blame] | 159 | /* 2 pixels inside */ |
| 160 | do_test(test_data, left - (cursor_w-2), right + (cursor_w-2), top , bottom ); |
| 161 | do_test(test_data, left , right , top - (cursor_h-2), bottom + (cursor_h-2)); |
| 162 | do_test(test_data, left - (cursor_w-2), right + (cursor_w-2), top - (cursor_h-2), bottom + (cursor_h-2)); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 163 | |
Antti Koskipaa | ead0173 | 2014-04-10 15:08:08 +0300 | [diff] [blame] | 164 | /* 1 pixel inside */ |
| 165 | do_test(test_data, left - (cursor_w-1), right + (cursor_w-1), top , bottom ); |
| 166 | do_test(test_data, left , right , top - (cursor_h-1), bottom + (cursor_h-1)); |
| 167 | do_test(test_data, left - (cursor_w-1), right + (cursor_w-1), top - (cursor_h-1), bottom + (cursor_h-1)); |
| 168 | } |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 169 | |
Antti Koskipaa | ead0173 | 2014-04-10 15:08:08 +0300 | [diff] [blame] | 170 | static void test_crc_offscreen(test_data_t *test_data) |
| 171 | { |
| 172 | int left = test_data->left; |
| 173 | int right = test_data->right; |
| 174 | int top = test_data->top; |
| 175 | int bottom = test_data->bottom; |
| 176 | int cursor_w = test_data->curw; |
| 177 | int cursor_h = test_data->curh; |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 178 | |
Antti Koskipaa | ead0173 | 2014-04-10 15:08:08 +0300 | [diff] [blame] | 179 | /* fully outside */ |
| 180 | do_test(test_data, left - (cursor_w), right + (cursor_w), top , bottom ); |
| 181 | do_test(test_data, left , right , top - (cursor_h), bottom + (cursor_h)); |
| 182 | do_test(test_data, left - (cursor_w), right + (cursor_w), top - (cursor_h), bottom + (cursor_h)); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 183 | |
Antti Koskipaa | ead0173 | 2014-04-10 15:08:08 +0300 | [diff] [blame] | 184 | /* fully outside by 1 extra pixels */ |
| 185 | do_test(test_data, left - (cursor_w+1), right + (cursor_w+1), top , bottom ); |
| 186 | do_test(test_data, left , right , top - (cursor_h+1), bottom + (cursor_h+1)); |
| 187 | do_test(test_data, left - (cursor_w+1), right + (cursor_w+1), top - (cursor_h+1), bottom + (cursor_h+1)); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 188 | |
Antti Koskipaa | ead0173 | 2014-04-10 15:08:08 +0300 | [diff] [blame] | 189 | /* fully outside by 2 extra pixels */ |
| 190 | do_test(test_data, left - (cursor_w+2), right + (cursor_w+2), top , bottom ); |
| 191 | do_test(test_data, left , right , top - (cursor_h+2), bottom + (cursor_h+2)); |
| 192 | do_test(test_data, left - (cursor_w+2), right + (cursor_w+2), top - (cursor_h+2), bottom + (cursor_h+2)); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 193 | |
Antti Koskipaa | ead0173 | 2014-04-10 15:08:08 +0300 | [diff] [blame] | 194 | /* fully outside by a lot of extra pixels */ |
| 195 | do_test(test_data, left - (cursor_w+512), right + (cursor_w+512), top , bottom ); |
| 196 | do_test(test_data, left , right , top - (cursor_h+512), bottom + (cursor_h+512)); |
| 197 | do_test(test_data, left - (cursor_w+512), right + (cursor_w+512), top - (cursor_h+512), bottom + (cursor_h+512)); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 198 | |
Antti Koskipaa | ead0173 | 2014-04-10 15:08:08 +0300 | [diff] [blame] | 199 | /* go nuts */ |
| 200 | do_test(test_data, INT_MIN, INT_MAX, INT_MIN, INT_MAX); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 201 | } |
| 202 | |
Antti Koskipaa | 470e5ce | 2014-04-10 15:08:10 +0300 | [diff] [blame^] | 203 | static void test_crc_sliding(test_data_t *test_data) |
| 204 | { |
| 205 | int i; |
| 206 | |
| 207 | /* Make sure cursor moves smoothly and pixel-by-pixel, and that there are |
| 208 | * no alignment issues. Horizontal, vertical and diagonal test. |
| 209 | */ |
| 210 | for (i = 0; i < 16; i++) { |
| 211 | do_single_test(test_data, i, 0); |
| 212 | do_single_test(test_data, 0, i); |
| 213 | do_single_test(test_data, i, i); |
| 214 | } |
| 215 | } |
| 216 | |
Sagar Kamble | ba3a1a8 | 2014-03-18 15:59:43 +0530 | [diff] [blame] | 217 | static bool prepare_crtc(test_data_t *test_data, igt_output_t *output, |
| 218 | int cursor_w, int cursor_h) |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 219 | { |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 220 | drmModeModeInfo *mode; |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 221 | data_t *data = test_data->data; |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 222 | igt_display_t *display = &data->display; |
Daniel Vetter | 43def94 | 2013-10-31 16:06:40 +0100 | [diff] [blame] | 223 | igt_pipe_crc_t *pipe_crc; |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 224 | igt_plane_t *primary; |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 225 | |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 226 | /* select the pipe we want to use */ |
| 227 | igt_output_set_pipe(output, test_data->pipe); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 228 | |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 229 | /* create and set the primary plane fb */ |
| 230 | mode = igt_output_get_mode(output); |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 231 | igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay, |
Damien Lespiau | 0631940 | 2014-02-06 19:04:58 +0000 | [diff] [blame] | 232 | DRM_FORMAT_XRGB8888, |
| 233 | false, /* tiled */ |
| 234 | 0.0, 0.0, 0.0, |
| 235 | &data->primary_fb); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 236 | |
Damien Lespiau | 2043e6b | 2014-02-11 17:45:48 +0000 | [diff] [blame] | 237 | primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY); |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 238 | igt_plane_set_fb(primary, &data->primary_fb); |
Ville Syrjälä | 3d371a7 | 2013-11-22 23:46:32 +0200 | [diff] [blame] | 239 | |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 240 | igt_display_commit(display); |
| 241 | |
| 242 | /* create the pipe_crc object for this pipe */ |
| 243 | igt_pipe_crc_free(data->pipe_crc[test_data->pipe]); |
| 244 | data->pipe_crc[test_data->pipe] = NULL; |
| 245 | |
| 246 | pipe_crc = create_crc(data, test_data->pipe); |
Daniel Vetter | 43def94 | 2013-10-31 16:06:40 +0100 | [diff] [blame] | 247 | if (!pipe_crc) { |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 248 | printf("auto crc not supported on this connector with pipe %i\n", |
| 249 | test_data->pipe); |
Daniel Vetter | 43def94 | 2013-10-31 16:06:40 +0100 | [diff] [blame] | 250 | return false; |
| 251 | } |
| 252 | |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 253 | data->pipe_crc[test_data->pipe] = pipe_crc; |
Daniel Vetter | 43def94 | 2013-10-31 16:06:40 +0100 | [diff] [blame] | 254 | |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 255 | /* x/y position where the cursor is still fully visible */ |
| 256 | test_data->left = 0; |
Sagar Kamble | ba3a1a8 | 2014-03-18 15:59:43 +0530 | [diff] [blame] | 257 | test_data->right = mode->hdisplay - cursor_w; |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 258 | test_data->top = 0; |
Sagar Kamble | ba3a1a8 | 2014-03-18 15:59:43 +0530 | [diff] [blame] | 259 | test_data->bottom = mode->vdisplay - cursor_h; |
Antti Koskipaa | 795eddc | 2014-04-10 15:08:09 +0300 | [diff] [blame] | 260 | test_data->screenw = mode->hdisplay; |
| 261 | test_data->screenh = mode->vdisplay; |
Antti Koskipaa | fe8041b | 2014-04-10 15:08:07 +0300 | [diff] [blame] | 262 | test_data->curw = cursor_w; |
| 263 | test_data->curh = cursor_h; |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 264 | |
| 265 | /* make sure cursor is disabled */ |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 266 | cursor_disable(test_data); |
| 267 | igt_wait_for_vblank(data->drm_fd, test_data->pipe); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 268 | |
| 269 | /* get reference crc w/o cursor */ |
Damien Lespiau | 1c608a2 | 2014-02-06 16:26:31 +0000 | [diff] [blame] | 270 | igt_pipe_crc_collect_crc(pipe_crc, &test_data->ref_crc); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 271 | |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 272 | return true; |
| 273 | } |
| 274 | |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 275 | static void cleanup_crtc(test_data_t *test_data, igt_output_t *output) |
| 276 | { |
| 277 | data_t *data = test_data->data; |
| 278 | igt_plane_t *primary; |
| 279 | |
| 280 | igt_pipe_crc_free(data->pipe_crc[test_data->pipe]); |
| 281 | data->pipe_crc[test_data->pipe] = NULL; |
| 282 | |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 283 | igt_remove_fb(data->drm_fd, &data->primary_fb); |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 284 | |
Damien Lespiau | 2043e6b | 2014-02-11 17:45:48 +0000 | [diff] [blame] | 285 | primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY); |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 286 | igt_plane_set_fb(primary, NULL); |
| 287 | |
| 288 | igt_output_set_pipe(output, PIPE_ANY); |
| 289 | } |
| 290 | |
Antti Koskipaa | ead0173 | 2014-04-10 15:08:08 +0300 | [diff] [blame] | 291 | static void run_test(data_t *data, void (*testfunc)(test_data_t *), int cursor_w, int cursor_h) |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 292 | { |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 293 | igt_display_t *display = &data->display; |
| 294 | igt_output_t *output; |
| 295 | enum pipe p; |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 296 | test_data_t test_data = { |
| 297 | .data = data, |
| 298 | }; |
Daniel Vetter | 43def94 | 2013-10-31 16:06:40 +0100 | [diff] [blame] | 299 | int valid_tests = 0; |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 300 | |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 301 | for_each_connected_output(display, output) { |
| 302 | test_data.output = output; |
| 303 | for (p = 0; p < igt_display_get_n_pipes(display); p++) { |
| 304 | test_data.pipe = p; |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 305 | |
Sagar Kamble | ba3a1a8 | 2014-03-18 15:59:43 +0530 | [diff] [blame] | 306 | if (!prepare_crtc(&test_data, output, cursor_w, cursor_h)) |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 307 | continue; |
| 308 | |
Daniel Vetter | 43def94 | 2013-10-31 16:06:40 +0100 | [diff] [blame] | 309 | valid_tests++; |
| 310 | |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 311 | fprintf(stdout, "Beginning %s on pipe %c, connector %s\n", |
| 312 | igt_subtest_name(), pipe_name(test_data.pipe), |
| 313 | igt_output_name(output)); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 314 | |
Antti Koskipaa | ead0173 | 2014-04-10 15:08:08 +0300 | [diff] [blame] | 315 | testfunc(&test_data); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 316 | |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 317 | fprintf(stdout, "\n%s on pipe %c, connector %s: PASSED\n\n", |
| 318 | igt_subtest_name(), pipe_name(test_data.pipe), |
| 319 | igt_output_name(output)); |
Daniel Vetter | 43def94 | 2013-10-31 16:06:40 +0100 | [diff] [blame] | 320 | |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 321 | /* cleanup what prepare_crtc() has done */ |
| 322 | cleanup_crtc(&test_data, output); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 323 | } |
| 324 | } |
Daniel Vetter | 43def94 | 2013-10-31 16:06:40 +0100 | [diff] [blame] | 325 | |
| 326 | igt_require_f(valid_tests, "no valid crtc/connector combinations found\n"); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 327 | } |
| 328 | |
Antti Koskipaa | a593d61 | 2014-04-10 15:08:05 +0300 | [diff] [blame] | 329 | static void create_cursor_fb(data_t *data, int cur_w, int cur_h) |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 330 | { |
| 331 | cairo_t *cr; |
Antti Koskipaa | a593d61 | 2014-04-10 15:08:05 +0300 | [diff] [blame] | 332 | uint32_t fb_id; |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 333 | |
Antti Koskipaa | a593d61 | 2014-04-10 15:08:05 +0300 | [diff] [blame] | 334 | fb_id = igt_create_fb(data->drm_fd, cur_w, cur_h, |
| 335 | DRM_FORMAT_ARGB8888, false, |
| 336 | &data->fb); |
| 337 | igt_assert(fb_id); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 338 | |
Antti Koskipaa | a593d61 | 2014-04-10 15:08:05 +0300 | [diff] [blame] | 339 | cr = igt_get_cairo_ctx(data->drm_fd, &data->fb); |
| 340 | draw_cursor(cr, 0, 0, cur_w); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 341 | igt_assert(cairo_status(cr) == 0); |
| 342 | } |
| 343 | |
Sagar Kamble | ba3a1a8 | 2014-03-18 15:59:43 +0530 | [diff] [blame] | 344 | static void run_test_generic(data_t *data, int cursor_max_size) |
| 345 | { |
| 346 | int cursor_size; |
| 347 | char c_size[5]; |
| 348 | for (cursor_size = 64; cursor_size <= cursor_max_size; cursor_size *= 2) |
| 349 | { |
| 350 | igt_require(cursor_max_size >= cursor_size); |
| 351 | sprintf(c_size, "%d", cursor_size); |
| 352 | |
Antti Koskipaa | a593d61 | 2014-04-10 15:08:05 +0300 | [diff] [blame] | 353 | create_cursor_fb(data, cursor_size, cursor_size); |
Sagar Kamble | ba3a1a8 | 2014-03-18 15:59:43 +0530 | [diff] [blame] | 354 | |
| 355 | /* Using created cursor FBs to test cursor support */ |
Antti Koskipaa | a593d61 | 2014-04-10 15:08:05 +0300 | [diff] [blame] | 356 | igt_subtest_f("cursor-%s-onscreen", c_size) |
Antti Koskipaa | ead0173 | 2014-04-10 15:08:08 +0300 | [diff] [blame] | 357 | run_test(data, test_crc_onscreen, cursor_size, cursor_size); |
Antti Koskipaa | a593d61 | 2014-04-10 15:08:05 +0300 | [diff] [blame] | 358 | igt_subtest_f("cursor-%s-offscreen", c_size) |
Antti Koskipaa | ead0173 | 2014-04-10 15:08:08 +0300 | [diff] [blame] | 359 | run_test(data, test_crc_offscreen, cursor_size, cursor_size); |
Antti Koskipaa | 470e5ce | 2014-04-10 15:08:10 +0300 | [diff] [blame^] | 360 | igt_subtest_f("cursor-%s-sliding", c_size) |
| 361 | run_test(data, test_crc_sliding, cursor_size, cursor_size); |
Sagar Kamble | ba3a1a8 | 2014-03-18 15:59:43 +0530 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | } |
| 365 | |
Daniel Vetter | 52edf3a | 2014-03-22 14:45:54 +0100 | [diff] [blame] | 366 | uint64_t cursor_width, cursor_height; |
| 367 | |
Daniel Vetter | 071e9ca | 2013-10-31 16:23:26 +0100 | [diff] [blame] | 368 | igt_main |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 369 | { |
| 370 | data_t data = {}; |
Daniel Vetter | 52edf3a | 2014-03-22 14:45:54 +0100 | [diff] [blame] | 371 | int ret; |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 372 | |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 373 | igt_skip_on_simulation(); |
| 374 | |
| 375 | igt_fixture { |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 376 | data.drm_fd = drm_open_any(); |
Daniel Vetter | 1f0cf2d | 2013-10-31 17:02:41 +0100 | [diff] [blame] | 377 | |
Sagar Kamble | ba3a1a8 | 2014-03-18 15:59:43 +0530 | [diff] [blame] | 378 | ret = drmGetCap(data.drm_fd, DRM_CAP_CURSOR_WIDTH, &cursor_width); |
| 379 | igt_assert(ret == 0); |
| 380 | /* Not making use of cursor_height since it is same as width, still reading */ |
| 381 | ret = drmGetCap(data.drm_fd, DRM_CAP_CURSOR_HEIGHT, &cursor_height); |
| 382 | igt_assert(ret == 0); |
| 383 | |
Sagar Kamble | ba3a1a8 | 2014-03-18 15:59:43 +0530 | [diff] [blame] | 384 | /* We assume width and height are same so max is assigned width */ |
Daniel Vetter | 701a755 | 2014-03-20 17:31:16 +0100 | [diff] [blame] | 385 | igt_assert_cmpint(cursor_width, ==, cursor_height); |
Sagar Kamble | ba3a1a8 | 2014-03-18 15:59:43 +0530 | [diff] [blame] | 386 | |
Daniel Vetter | 1f0cf2d | 2013-10-31 17:02:41 +0100 | [diff] [blame] | 387 | igt_set_vt_graphics_mode(); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 388 | |
Daniel Vetter | f2e5dc0 | 2014-03-16 15:09:22 +0100 | [diff] [blame] | 389 | igt_require_pipe_crc(); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 390 | |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 391 | igt_display_init(&data.display, data.drm_fd); |
| 392 | data.pipe_crc = calloc(igt_display_get_n_pipes(&data.display), |
| 393 | sizeof(data.pipe_crc[0])); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 394 | |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 395 | } |
| 396 | |
Daniel Vetter | 52edf3a | 2014-03-22 14:45:54 +0100 | [diff] [blame] | 397 | run_test_generic(&data, cursor_width); |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 398 | |
Damien Lespiau | d435829 | 2014-02-05 17:14:12 +0000 | [diff] [blame] | 399 | igt_fixture { |
| 400 | free(data.pipe_crc); |
| 401 | igt_display_fini(&data.display); |
| 402 | } |
Ville Syrjälä | 08c27e3 | 2013-10-18 17:44:42 +0300 | [diff] [blame] | 403 | } |