blob: d21fc998417feb2ac2696e873ca69419ef96df62 [file] [log] [blame]
Ville Syrjälä08c27e32013-10-18 17:44:42 +03001/*
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äfee27cf2014-01-13 17:05:19 +020026#include <limits.h>
Ville Syrjälä08c27e32013-10-18 17:44:42 +030027#include <stdbool.h>
28#include <stdio.h>
29#include <string.h>
30
Ville Syrjälä08c27e32013-10-18 17:44:42 +030031#include "drmtest.h"
32#include "igt_debugfs.h"
Oscar Mateo37f26d12013-11-12 11:50:38 +000033#include "igt_kms.h"
Ville Syrjälä08c27e32013-10-18 17:44:42 +030034
Sagar Kambleba3a1a82014-03-18 15:59:43 +053035#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ä08c27e32013-10-18 17:44:42 +030042typedef struct {
Ville Syrjälä08c27e32013-10-18 17:44:42 +030043 int drm_fd;
Damien Lespiaud4358292014-02-05 17:14:12 +000044 igt_display_t display;
Daniel Vetter9aea7ae2014-03-26 09:18:11 +010045 struct igt_fb primary_fb;
Antti Koskipaaa593d612014-04-10 15:08:05 +030046 struct igt_fb fb;
Damien Lespiaud4358292014-02-05 17:14:12 +000047 igt_output_t *output;
48 enum pipe pipe;
Ville Syrjälä08c27e32013-10-18 17:44:42 +030049 igt_crc_t ref_crc;
Ville Syrjälä08c27e32013-10-18 17:44:42 +030050 int left, right, top, bottom;
Antti Koskipaa795eddc2014-04-10 15:08:09 +030051 int screenw, screenh;
Antti Koskipaafe8041b2014-04-10 15:08:07 +030052 int curw, curh; /* cursor size */
Antti Koskipaa21fb1182014-06-02 13:43:18 +030053 int cursor_max_size;
Ville Syrjäläf6e86972014-04-24 19:07:18 +030054 igt_pipe_crc_t *pipe_crc;
Matt Roper07087ad2014-06-30 16:44:29 -070055} data_t;
Ville Syrjälä08c27e32013-10-18 17:44:42 +030056
Antti Koskipaaa593d612014-04-10 15:08:05 +030057static void draw_cursor(cairo_t *cr, int x, int y, int w)
58{
59 w /= 2;
Antti Koskipaa795eddc2014-04-10 15:08:09 +030060 /* Cairo doesn't like to be fed numbers that are too wild */
61 if ((x < SHRT_MIN) || (x > SHRT_MAX) || (y < SHRT_MIN) || (y > SHRT_MAX))
62 return;
Antti Koskipaaa593d612014-04-10 15:08:05 +030063 cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
64 /* 4 color rectangles in the corners, RGBY */
65 igt_paint_color_alpha(cr, x, y, w, w, 1.0, 0.0, 0.0, 1.0);
66 igt_paint_color_alpha(cr, x + w, y, w, w, 0.0, 1.0, 0.0, 1.0);
67 igt_paint_color_alpha(cr, x, y + w, w, w, 0.0, 0.0, 1.0, 1.0);
68 igt_paint_color_alpha(cr, x + w, y + w, w, w, 0.5, 0.5, 0.5, 1.0);
69}
Ville Syrjälä08c27e32013-10-18 17:44:42 +030070
Matt Roper07087ad2014-06-30 16:44:29 -070071static void cursor_enable(data_t *data)
Damien Lespiaud4358292014-02-05 17:14:12 +000072{
Damien Lespiaud4358292014-02-05 17:14:12 +000073 igt_display_t *display = &data->display;
Matt Roper07087ad2014-06-30 16:44:29 -070074 igt_output_t *output = data->output;
Damien Lespiaud4358292014-02-05 17:14:12 +000075 igt_plane_t *cursor;
76
Damien Lespiau2043e6b2014-02-11 17:45:48 +000077 cursor = igt_output_get_plane(output, IGT_PLANE_CURSOR);
Antti Koskipaaa593d612014-04-10 15:08:05 +030078 igt_plane_set_fb(cursor, &data->fb);
Damien Lespiaud4358292014-02-05 17:14:12 +000079 igt_display_commit(display);
80}
81
Matt Roper07087ad2014-06-30 16:44:29 -070082static void cursor_disable(data_t *data)
Damien Lespiaud4358292014-02-05 17:14:12 +000083{
Damien Lespiaud4358292014-02-05 17:14:12 +000084 igt_display_t *display = &data->display;
Matt Roper07087ad2014-06-30 16:44:29 -070085 igt_output_t *output = data->output;
Damien Lespiaud4358292014-02-05 17:14:12 +000086 igt_plane_t *cursor;
87
Damien Lespiau2043e6b2014-02-11 17:45:48 +000088 cursor = igt_output_get_plane(output, IGT_PLANE_CURSOR);
Damien Lespiaud4358292014-02-05 17:14:12 +000089 igt_plane_set_fb(cursor, NULL);
90 igt_display_commit(display);
91}
92
Antti Koskipaa7ec631c2014-04-10 15:08:06 +030093
Matt Roper07087ad2014-06-30 16:44:29 -070094static void do_single_test(data_t *data, int x, int y)
Antti Koskipaa7ec631c2014-04-10 15:08:06 +030095{
Antti Koskipaa7ec631c2014-04-10 15:08:06 +030096 igt_display_t *display = &data->display;
Matt Roper07087ad2014-06-30 16:44:29 -070097 igt_pipe_crc_t *pipe_crc = data->pipe_crc;
Antti Koskipaa795eddc2014-04-10 15:08:09 +030098 igt_crc_t crc, ref_crc;
Antti Koskipaa7ec631c2014-04-10 15:08:06 +030099 igt_plane_t *cursor;
Antti Koskipaa795eddc2014-04-10 15:08:09 +0300100 cairo_t *cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300101
Daniel Vettere624fa82014-05-14 00:36:04 +0200102 igt_info("."); fflush(stdout);
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300103
Antti Koskipaa795eddc2014-04-10 15:08:09 +0300104 /* Hardware test */
Matt Roper07087ad2014-06-30 16:44:29 -0700105 igt_paint_test_pattern(cr, data->screenw, data->screenh);
106 cursor_enable(data);
107 cursor = igt_output_get_plane(data->output, IGT_PLANE_CURSOR);
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300108 igt_plane_set_position(cursor, x, y);
109 igt_display_commit(display);
Matt Roper07087ad2014-06-30 16:44:29 -0700110 igt_wait_for_vblank(data->drm_fd, data->pipe);
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300111 igt_pipe_crc_collect_crc(pipe_crc, &crc);
Matt Roper07087ad2014-06-30 16:44:29 -0700112 cursor_disable(data);
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300113
Antti Koskipaa795eddc2014-04-10 15:08:09 +0300114 /* Now render the same in software and collect crc */
Matt Roper07087ad2014-06-30 16:44:29 -0700115 draw_cursor(cr, x, y, data->curw);
Antti Koskipaa795eddc2014-04-10 15:08:09 +0300116 igt_display_commit(display);
Matt Roper07087ad2014-06-30 16:44:29 -0700117 igt_wait_for_vblank(data->drm_fd, data->pipe);
Antti Koskipaa795eddc2014-04-10 15:08:09 +0300118 igt_pipe_crc_collect_crc(pipe_crc, &ref_crc);
119 /* Clear screen afterwards */
Matt Roper07087ad2014-06-30 16:44:29 -0700120 igt_paint_color(cr, 0, 0, data->screenw, data->screenh,
121 0.0, 0.0, 0.0);
Antti Koskipaa795eddc2014-04-10 15:08:09 +0300122
123 igt_assert(igt_crc_equal(&crc, &ref_crc));
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300124}
125
Matt Roper07087ad2014-06-30 16:44:29 -0700126static void do_test(data_t *data,
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300127 int left, int right, int top, int bottom)
128{
Matt Roper07087ad2014-06-30 16:44:29 -0700129 do_single_test(data, left, top);
130 do_single_test(data, right, top);
131 do_single_test(data, right, bottom);
132 do_single_test(data, left, bottom);
Antti Koskipaa7ec631c2014-04-10 15:08:06 +0300133}
134
Matt Roper07087ad2014-06-30 16:44:29 -0700135static void test_crc_onscreen(data_t *data)
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300136{
Matt Roper07087ad2014-06-30 16:44:29 -0700137 int left = data->left;
138 int right = data->right;
139 int top = data->top;
140 int bottom = data->bottom;
141 int cursor_w = data->curw;
142 int cursor_h = data->curh;
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300143
Antti Koskipaaead01732014-04-10 15:08:08 +0300144 /* fully inside */
Matt Roper07087ad2014-06-30 16:44:29 -0700145 do_test(data, left, right, top, bottom);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300146
Antti Koskipaaead01732014-04-10 15:08:08 +0300147 /* 2 pixels inside */
Matt Roper07087ad2014-06-30 16:44:29 -0700148 do_test(data, left - (cursor_w-2), right + (cursor_w-2), top , bottom );
149 do_test(data, left , right , top - (cursor_h-2), bottom + (cursor_h-2));
150 do_test(data, left - (cursor_w-2), right + (cursor_w-2), top - (cursor_h-2), bottom + (cursor_h-2));
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300151
Antti Koskipaaead01732014-04-10 15:08:08 +0300152 /* 1 pixel inside */
Matt Roper07087ad2014-06-30 16:44:29 -0700153 do_test(data, left - (cursor_w-1), right + (cursor_w-1), top , bottom );
154 do_test(data, left , right , top - (cursor_h-1), bottom + (cursor_h-1));
155 do_test(data, left - (cursor_w-1), right + (cursor_w-1), top - (cursor_h-1), bottom + (cursor_h-1));
Antti Koskipaaead01732014-04-10 15:08:08 +0300156}
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300157
Matt Roper07087ad2014-06-30 16:44:29 -0700158static void test_crc_offscreen(data_t *data)
Antti Koskipaaead01732014-04-10 15:08:08 +0300159{
Matt Roper07087ad2014-06-30 16:44:29 -0700160 int left = data->left;
161 int right = data->right;
162 int top = data->top;
163 int bottom = data->bottom;
164 int cursor_w = data->curw;
165 int cursor_h = data->curh;
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300166
Antti Koskipaaead01732014-04-10 15:08:08 +0300167 /* fully outside */
Matt Roper07087ad2014-06-30 16:44:29 -0700168 do_test(data, left - (cursor_w), right + (cursor_w), top , bottom );
169 do_test(data, left , right , top - (cursor_h), bottom + (cursor_h));
170 do_test(data, left - (cursor_w), right + (cursor_w), top - (cursor_h), bottom + (cursor_h));
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300171
Antti Koskipaaead01732014-04-10 15:08:08 +0300172 /* fully outside by 1 extra pixels */
Matt Roper07087ad2014-06-30 16:44:29 -0700173 do_test(data, left - (cursor_w+1), right + (cursor_w+1), top , bottom );
174 do_test(data, left , right , top - (cursor_h+1), bottom + (cursor_h+1));
175 do_test(data, left - (cursor_w+1), right + (cursor_w+1), top - (cursor_h+1), bottom + (cursor_h+1));
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300176
Antti Koskipaaead01732014-04-10 15:08:08 +0300177 /* fully outside by 2 extra pixels */
Matt Roper07087ad2014-06-30 16:44:29 -0700178 do_test(data, left - (cursor_w+2), right + (cursor_w+2), top , bottom );
179 do_test(data, left , right , top - (cursor_h+2), bottom + (cursor_h+2));
180 do_test(data, left - (cursor_w+2), right + (cursor_w+2), top - (cursor_h+2), bottom + (cursor_h+2));
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300181
Antti Koskipaaead01732014-04-10 15:08:08 +0300182 /* fully outside by a lot of extra pixels */
Matt Roper07087ad2014-06-30 16:44:29 -0700183 do_test(data, left - (cursor_w+512), right + (cursor_w+512), top , bottom );
184 do_test(data, left , right , top - (cursor_h+512), bottom + (cursor_h+512));
185 do_test(data, left - (cursor_w+512), right + (cursor_w+512), top - (cursor_h+512), bottom + (cursor_h+512));
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300186
Antti Koskipaaead01732014-04-10 15:08:08 +0300187 /* go nuts */
Matt Roper07087ad2014-06-30 16:44:29 -0700188 do_test(data, INT_MIN, INT_MAX, INT_MIN, INT_MAX);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300189}
190
Matt Roper07087ad2014-06-30 16:44:29 -0700191static void test_crc_sliding(data_t *data)
Antti Koskipaa470e5ce2014-04-10 15:08:10 +0300192{
193 int i;
194
195 /* Make sure cursor moves smoothly and pixel-by-pixel, and that there are
196 * no alignment issues. Horizontal, vertical and diagonal test.
197 */
198 for (i = 0; i < 16; i++) {
Matt Roper07087ad2014-06-30 16:44:29 -0700199 do_single_test(data, i, 0);
200 do_single_test(data, 0, i);
201 do_single_test(data, i, i);
Antti Koskipaa470e5ce2014-04-10 15:08:10 +0300202 }
203}
204
Matt Roper07087ad2014-06-30 16:44:29 -0700205static void test_crc_random(data_t *data)
Antti Koskipaafafcff92014-04-10 15:08:11 +0300206{
207 int i;
208
209 /* Random cursor placement */
210 for (i = 0; i < 50; i++) {
Matt Roper07087ad2014-06-30 16:44:29 -0700211 int x = rand() % (data->screenw + data->curw * 2) - data->curw;
212 int y = rand() % (data->screenh + data->curh * 2) - data->curh;
213 do_single_test(data, x, y);
Antti Koskipaafafcff92014-04-10 15:08:11 +0300214 }
215}
216
Matt Roper07087ad2014-06-30 16:44:29 -0700217static bool prepare_crtc(data_t *data, igt_output_t *output,
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530218 int cursor_w, int cursor_h)
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300219{
Damien Lespiaud4358292014-02-05 17:14:12 +0000220 drmModeModeInfo *mode;
Damien Lespiaud4358292014-02-05 17:14:12 +0000221 igt_display_t *display = &data->display;
Damien Lespiaud4358292014-02-05 17:14:12 +0000222 igt_plane_t *primary;
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300223
Damien Lespiaud4358292014-02-05 17:14:12 +0000224 /* select the pipe we want to use */
Matt Roper07087ad2014-06-30 16:44:29 -0700225 igt_output_set_pipe(output, data->pipe);
Ville Syrjäläa4615152014-04-25 15:27:57 +0300226 igt_display_commit(display);
227
228 if (!output->valid) {
229 igt_output_set_pipe(output, PIPE_ANY);
230 igt_display_commit(display);
231 return false;
232 }
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300233
Damien Lespiaud4358292014-02-05 17:14:12 +0000234 /* create and set the primary plane fb */
235 mode = igt_output_get_mode(output);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100236 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
Matt Roper07087ad2014-06-30 16:44:29 -0700237 DRM_FORMAT_XRGB8888,
238 false, /* tiled */
239 0.0, 0.0, 0.0,
240 &data->primary_fb);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300241
Damien Lespiau2043e6b2014-02-11 17:45:48 +0000242 primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
Damien Lespiaud4358292014-02-05 17:14:12 +0000243 igt_plane_set_fb(primary, &data->primary_fb);
Ville Syrjälä3d371a72013-11-22 23:46:32 +0200244
Damien Lespiaud4358292014-02-05 17:14:12 +0000245 igt_display_commit(display);
246
247 /* create the pipe_crc object for this pipe */
Matt Roper07087ad2014-06-30 16:44:29 -0700248 if (data->pipe_crc)
249 igt_pipe_crc_free(data->pipe_crc);
Damien Lespiaud4358292014-02-05 17:14:12 +0000250
Matt Roper07087ad2014-06-30 16:44:29 -0700251 data->pipe_crc = igt_pipe_crc_new(data->pipe,
252 INTEL_PIPE_CRC_SOURCE_AUTO);
253 if (!data->pipe_crc) {
Daniel Vettere624fa82014-05-14 00:36:04 +0200254 igt_info("auto crc not supported on this connector with pipe %i\n",
Matt Roper07087ad2014-06-30 16:44:29 -0700255 data->pipe);
Daniel Vetter43def942013-10-31 16:06:40 +0100256 return false;
257 }
258
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300259 /* x/y position where the cursor is still fully visible */
Matt Roper07087ad2014-06-30 16:44:29 -0700260 data->left = 0;
261 data->right = mode->hdisplay - cursor_w;
262 data->top = 0;
263 data->bottom = mode->vdisplay - cursor_h;
264 data->screenw = mode->hdisplay;
265 data->screenh = mode->vdisplay;
266 data->curw = cursor_w;
267 data->curh = cursor_h;
268 data->cursor_max_size = cursor_w;
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300269
270 /* make sure cursor is disabled */
Matt Roper07087ad2014-06-30 16:44:29 -0700271 cursor_disable(data);
272 igt_wait_for_vblank(data->drm_fd, data->pipe);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300273
274 /* get reference crc w/o cursor */
Matt Roper07087ad2014-06-30 16:44:29 -0700275 igt_pipe_crc_collect_crc(data->pipe_crc, &data->ref_crc);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300276
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300277 return true;
278}
279
Matt Roper07087ad2014-06-30 16:44:29 -0700280static void cleanup_crtc(data_t *data, igt_output_t *output)
Damien Lespiaud4358292014-02-05 17:14:12 +0000281{
Ville Syrjäläa4615152014-04-25 15:27:57 +0300282 igt_display_t *display = &data->display;
Damien Lespiaud4358292014-02-05 17:14:12 +0000283 igt_plane_t *primary;
284
Matt Roper07087ad2014-06-30 16:44:29 -0700285 igt_pipe_crc_free(data->pipe_crc);
286 data->pipe_crc = NULL;
Damien Lespiaud4358292014-02-05 17:14:12 +0000287
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100288 igt_remove_fb(data->drm_fd, &data->primary_fb);
Damien Lespiaud4358292014-02-05 17:14:12 +0000289
Damien Lespiau2043e6b2014-02-11 17:45:48 +0000290 primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
Damien Lespiaud4358292014-02-05 17:14:12 +0000291 igt_plane_set_fb(primary, NULL);
292
293 igt_output_set_pipe(output, PIPE_ANY);
Ville Syrjäläa4615152014-04-25 15:27:57 +0300294 igt_display_commit(display);
Damien Lespiaud4358292014-02-05 17:14:12 +0000295}
296
Matt Roper07087ad2014-06-30 16:44:29 -0700297static void run_test(data_t *data, void (*testfunc)(data_t *), int cursor_w, int cursor_h)
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300298{
Damien Lespiaud4358292014-02-05 17:14:12 +0000299 igt_display_t *display = &data->display;
300 igt_output_t *output;
301 enum pipe p;
Daniel Vetter43def942013-10-31 16:06:40 +0100302 int valid_tests = 0;
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300303
Damien Lespiaud4358292014-02-05 17:14:12 +0000304 for_each_connected_output(display, output) {
Matt Roper07087ad2014-06-30 16:44:29 -0700305 data->output = output;
Damien Lespiaud4358292014-02-05 17:14:12 +0000306 for (p = 0; p < igt_display_get_n_pipes(display); p++) {
Matt Roper07087ad2014-06-30 16:44:29 -0700307 data->pipe = p;
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300308
Matt Roper07087ad2014-06-30 16:44:29 -0700309 if (!prepare_crtc(data, output, cursor_w, cursor_h))
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300310 continue;
311
Daniel Vetter43def942013-10-31 16:06:40 +0100312 valid_tests++;
313
Daniel Vettere624fa82014-05-14 00:36:04 +0200314 igt_info("Beginning %s on pipe %c, connector %s\n",
Matt Roper07087ad2014-06-30 16:44:29 -0700315 igt_subtest_name(), pipe_name(data->pipe),
Daniel Vettere624fa82014-05-14 00:36:04 +0200316 igt_output_name(output));
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300317
Matt Roper07087ad2014-06-30 16:44:29 -0700318 testfunc(data);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300319
Daniel Vettere624fa82014-05-14 00:36:04 +0200320 igt_info("\n%s on pipe %c, connector %s: PASSED\n\n",
Matt Roper07087ad2014-06-30 16:44:29 -0700321 igt_subtest_name(), pipe_name(data->pipe),
Daniel Vettere624fa82014-05-14 00:36:04 +0200322 igt_output_name(output));
Daniel Vetter43def942013-10-31 16:06:40 +0100323
Damien Lespiaud4358292014-02-05 17:14:12 +0000324 /* cleanup what prepare_crtc() has done */
Matt Roper07087ad2014-06-30 16:44:29 -0700325 cleanup_crtc(data, output);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300326 }
327 }
Daniel Vetter43def942013-10-31 16:06:40 +0100328
329 igt_require_f(valid_tests, "no valid crtc/connector combinations found\n");
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300330}
331
Antti Koskipaaa593d612014-04-10 15:08:05 +0300332static void create_cursor_fb(data_t *data, int cur_w, int cur_h)
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300333{
334 cairo_t *cr;
Antti Koskipaaa593d612014-04-10 15:08:05 +0300335 uint32_t fb_id;
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300336
Antti Koskipaaa593d612014-04-10 15:08:05 +0300337 fb_id = igt_create_fb(data->drm_fd, cur_w, cur_h,
338 DRM_FORMAT_ARGB8888, false,
339 &data->fb);
340 igt_assert(fb_id);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300341
Antti Koskipaaa593d612014-04-10 15:08:05 +0300342 cr = igt_get_cairo_ctx(data->drm_fd, &data->fb);
343 draw_cursor(cr, 0, 0, cur_w);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300344 igt_assert(cairo_status(cr) == 0);
345}
346
Matt Roper07087ad2014-06-30 16:44:29 -0700347static void test_cursor_size(data_t *data)
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300348{
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300349 igt_display_t *display = &data->display;
Matt Roper07087ad2014-06-30 16:44:29 -0700350 igt_pipe_crc_t *pipe_crc = data->pipe_crc;
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300351 igt_crc_t crc[10], ref_crc;
352 igt_plane_t *cursor;
353 cairo_t *cr;
354 uint32_t fb_id;
Matt Roper07087ad2014-06-30 16:44:29 -0700355 int i, size, cursor_max_size = data->cursor_max_size;
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300356
357 /* Create a maximum size cursor, then change the size in flight to
358 * smaller ones to see that the size is applied correctly
359 */
360 fb_id = igt_create_fb(data->drm_fd, cursor_max_size, cursor_max_size,
361 DRM_FORMAT_ARGB8888, false, &data->fb);
362 igt_assert(fb_id);
363
364 /* Use a solid white rectangle as the cursor */
365 cr = igt_get_cairo_ctx(data->drm_fd, &data->fb);
366 igt_paint_color_alpha(cr, 0, 0, cursor_max_size, cursor_max_size, 1.0, 1.0, 1.0, 1.0);
367
368 /* Hardware test loop */
Matt Roper07087ad2014-06-30 16:44:29 -0700369 cursor_enable(data);
370 cursor = igt_output_get_plane(data->output, IGT_PLANE_CURSOR);
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300371 igt_plane_set_position(cursor, 0, 0);
372 for (i = 0, size = cursor_max_size; size >= 64; size /= 2, i++) {
373 /* Change size in flight: */
Matt Roper07087ad2014-06-30 16:44:29 -0700374 int ret = drmModeSetCursor(data->drm_fd, data->output->config.crtc->crtc_id,
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300375 data->fb.gem_handle, size, size);
376 igt_assert(ret == 0);
Matt Roper07087ad2014-06-30 16:44:29 -0700377 igt_wait_for_vblank(data->drm_fd, data->pipe);
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300378 igt_pipe_crc_collect_crc(pipe_crc, &crc[i]);
379 }
Matt Roper07087ad2014-06-30 16:44:29 -0700380 cursor_disable(data);
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300381 /* Software test loop */
382 cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
383 for (i = 0, size = cursor_max_size; size >= 64; size /= 2, i++) {
384 /* Now render the same in software and collect crc */
385 igt_paint_color_alpha(cr, 0, 0, size, size, 1.0, 1.0, 1.0, 1.0);
386 igt_display_commit(display);
Matt Roper07087ad2014-06-30 16:44:29 -0700387 igt_wait_for_vblank(data->drm_fd, data->pipe);
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300388 igt_pipe_crc_collect_crc(pipe_crc, &ref_crc);
389 /* Clear screen afterwards */
Matt Roper07087ad2014-06-30 16:44:29 -0700390 igt_paint_color(cr, 0, 0, data->screenw, data->screenh,
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300391 0.0, 0.0, 0.0);
392 igt_assert(igt_crc_equal(&crc[i], &ref_crc));
393 }
394}
395
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530396static void run_test_generic(data_t *data, int cursor_max_size)
397{
398 int cursor_size;
Ville Syrjäläfb2ccb12014-04-25 13:50:59 +0300399 for (cursor_size = 64; cursor_size <= 256; cursor_size *= 2)
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530400 {
Ville Syrjälä5b908332014-04-25 13:37:09 +0300401 igt_fixture
402 igt_require(cursor_max_size >= cursor_size);
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530403
Ville Syrjäläf8e5a3f2014-04-25 13:49:11 +0300404 igt_fixture
405 create_cursor_fb(data, cursor_size, cursor_size);
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530406
407 /* Using created cursor FBs to test cursor support */
Ville Syrjäläf688a562014-04-25 13:38:31 +0300408 igt_subtest_f("cursor-%d-onscreen", cursor_size)
Antti Koskipaaead01732014-04-10 15:08:08 +0300409 run_test(data, test_crc_onscreen, cursor_size, cursor_size);
Ville Syrjäläf688a562014-04-25 13:38:31 +0300410 igt_subtest_f("cursor-%d-offscreen", cursor_size)
Antti Koskipaaead01732014-04-10 15:08:08 +0300411 run_test(data, test_crc_offscreen, cursor_size, cursor_size);
Ville Syrjäläf688a562014-04-25 13:38:31 +0300412 igt_subtest_f("cursor-%d-sliding", cursor_size)
Antti Koskipaa470e5ce2014-04-10 15:08:10 +0300413 run_test(data, test_crc_sliding, cursor_size, cursor_size);
Ville Syrjäläf688a562014-04-25 13:38:31 +0300414 igt_subtest_f("cursor-%d-random", cursor_size)
Antti Koskipaafafcff92014-04-10 15:08:11 +0300415 run_test(data, test_crc_random, cursor_size, cursor_size);
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530416
Ville Syrjäläf8e5a3f2014-04-25 13:49:11 +0300417 igt_fixture
418 igt_remove_fb(data->drm_fd, &data->fb);
419 }
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530420}
421
Daniel Vetter071e9ca2013-10-31 16:23:26 +0100422igt_main
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300423{
Ville Syrjäläfb2ccb12014-04-25 13:50:59 +0300424 uint64_t cursor_width = 64, cursor_height = 64;
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300425 data_t data = {};
Daniel Vetter52edf3a2014-03-22 14:45:54 +0100426 int ret;
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300427
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300428 igt_skip_on_simulation();
429
430 igt_fixture {
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300431 data.drm_fd = drm_open_any();
Daniel Vetter1f0cf2d2013-10-31 17:02:41 +0100432
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530433 ret = drmGetCap(data.drm_fd, DRM_CAP_CURSOR_WIDTH, &cursor_width);
Ville Syrjäläfb2ccb12014-04-25 13:50:59 +0300434 igt_assert(ret == 0 || errno == EINVAL);
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530435 /* Not making use of cursor_height since it is same as width, still reading */
436 ret = drmGetCap(data.drm_fd, DRM_CAP_CURSOR_HEIGHT, &cursor_height);
Ville Syrjäläfb2ccb12014-04-25 13:50:59 +0300437 igt_assert(ret == 0 || errno == EINVAL);
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530438
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530439 /* We assume width and height are same so max is assigned width */
Daniel Vetter701a7552014-03-20 17:31:16 +0100440 igt_assert_cmpint(cursor_width, ==, cursor_height);
Sagar Kambleba3a1a82014-03-18 15:59:43 +0530441
Daniel Vetter1f0cf2d2013-10-31 17:02:41 +0100442 igt_set_vt_graphics_mode();
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300443
Daniel Vetterf2e5dc02014-03-16 15:09:22 +0100444 igt_require_pipe_crc();
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300445
Damien Lespiaud4358292014-02-05 17:14:12 +0000446 igt_display_init(&data.display, data.drm_fd);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300447 }
448
Antti Koskipaa21fb1182014-06-02 13:43:18 +0300449 igt_subtest_f("cursor-size-change")
450 run_test(&data, test_cursor_size, cursor_width, cursor_height);
451
Daniel Vetter52edf3a2014-03-22 14:45:54 +0100452 run_test_generic(&data, cursor_width);
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300453
Damien Lespiaud4358292014-02-05 17:14:12 +0000454 igt_fixture {
Damien Lespiaud4358292014-02-05 17:14:12 +0000455 igt_display_fini(&data.display);
456 }
Ville Syrjälä08c27e32013-10-18 17:44:42 +0300457}