1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
|
/*
* Copyright 2019 Advanced Micro Devices, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "igt.h"
/**
* TEST: kms plane cursor
* Category: Display
* Description: Tests cursor interactions with primary and overlay planes.
*
* SUBTEST: overlay
* Description: Tests atomic cursor positioning on primary plane and overlay plane
* Driver requirement: i915, xe
* Functionality: cursor, plane
* Mega feature: General Display Features
* Test category: functionality test
*
* SUBTEST: primary
* Description: Tests atomic cursor positioning on primary plane
* Driver requirement: i915, xe
* Functionality: cursor, plane
* Mega feature: General Display Features
* Test category: functionality test
*
* SUBTEST: viewport
* Description: Tests atomic cursor positioning on primary plane and overlay plane
* with buffer larger than viewport used for display
* Driver requirement: i915, xe
* Functionality: cursor, plane
* Mega feature: General Display Features
* Test category: functionality test
*/
/*
* This file tests cursor interactions with primary and overlay planes.
*
* Some assumptions made:
* - Cursor planes can be placed on top of overlay planes
* - DRM index indicates z-ordering, higher index = higher z-order
*/
enum {
TEST_PRIMARY = 0,
TEST_OVERLAY = 1 << 0,
TEST_VIEWPORT = 1 << 1,
};
typedef struct {
int x;
int y;
} pos_t;
typedef struct {
int x;
int y;
int w;
int h;
} rect_t;
/* Common test data. */
typedef struct data {
igt_display_t display;
igt_plane_t *primary;
igt_plane_t *overlay;
igt_plane_t *cursor;
igt_output_t *output;
igt_pipe_t *pipe;
igt_pipe_crc_t *pipe_crc;
drmModeModeInfo *mode;
igt_fb_t pfb;
igt_fb_t ofb;
igt_fb_t cfb;
enum pipe pipe_id;
int drm_fd;
rect_t or;
uint64_t max_curw;
uint64_t max_curh;
} data_t;
/* Common test setup. */
static void test_init(data_t *data, enum pipe pipe_id, igt_output_t *output)
{
data->pipe_id = pipe_id;
data->pipe = &data->display.pipes[data->pipe_id];
data->output = output;
data->mode = igt_output_get_mode(data->output);
data->primary = igt_pipe_get_plane_type(data->pipe, DRM_PLANE_TYPE_PRIMARY);
data->overlay = igt_pipe_get_plane_type(data->pipe, DRM_PLANE_TYPE_OVERLAY);
data->cursor = igt_pipe_get_plane_type(data->pipe, DRM_PLANE_TYPE_CURSOR);
igt_info("Using (pipe %s + %s) to run the subtest.\n",
kmstest_pipe_name(data->pipe_id), igt_output_name(data->output));
igt_require_pipe_crc(data->drm_fd);
data->pipe_crc = igt_pipe_crc_new(data->drm_fd, data->pipe_id,
IGT_PIPE_CRC_SOURCE_AUTO);
/* Overlay rectangle for a rect in the center of the screen */
data->or.x = data->mode->hdisplay / 4;
data->or.y = data->mode->vdisplay / 4;
data->or.w = data->mode->hdisplay / 2;
data->or.h = data->mode->vdisplay / 2;
}
/* Common test cleanup. */
static void test_fini(data_t *data)
{
igt_pipe_crc_free(data->pipe_crc);
igt_display_reset(&data->display);
igt_plane_set_fb(data->primary, NULL);
igt_plane_set_fb(data->overlay, NULL);
igt_plane_set_fb(data->cursor, NULL);
igt_display_commit2(&data->display, COMMIT_ATOMIC);
}
/* Fills a FB with the solid color given. */
static void draw_color(igt_fb_t *fb, double r, double g, double b)
{
cairo_t *cr = igt_get_cairo_ctx(fb->fd, fb);
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
igt_paint_color(cr, 0, 0, fb->width, fb->height, r, g, b);
igt_put_cairo_ctx(cr);
}
/*
* Draws white and gray (if overlay FB is given) on the primary FB.
* Draws a magenta square where the cursor should be over top both planes.
* Takes this as the reference CRC.
*
* Draws white on the primary FB and gray on the overlay FB if given.
* Places the cursor where the magenta square should be with a magenta FB.
* Takes this as the test CRC and compares it to the reference.
*/
static void test_cursor_pos(data_t *data, int x, int y, unsigned int flags)
{
igt_crc_t ref_crc, test_crc;
cairo_t *cr;
igt_fb_t *pfb = &data->pfb;
igt_fb_t *ofb = &data->ofb;
igt_fb_t *cfb = &data->cfb;
int cw = cfb->width;
int ch = cfb->height;
const rect_t *or = &data->or;
cr = igt_get_cairo_ctx(pfb->fd, pfb);
igt_paint_color(cr, 0, 0, pfb->width, pfb->height, 1.0, 1.0, 1.0);
if (flags & TEST_OVERLAY)
igt_paint_color(cr, or->x, or->y, or->w, or->h, 0.5, 0.5, 0.5);
igt_paint_color(cr, x, y, cw, ch, 1.0, 0.0, 1.0);
igt_put_cairo_ctx(cr);
igt_plane_set_fb(data->overlay, NULL);
igt_plane_set_fb(data->cursor, NULL);
igt_display_commit_atomic(&data->display, 0, NULL);
igt_pipe_crc_start(data->pipe_crc);
igt_pipe_crc_get_current(data->drm_fd, data->pipe_crc, &ref_crc);
draw_color(pfb, 1.0, 1.0, 1.0);
if (flags & TEST_OVERLAY) {
igt_plane_set_fb(data->overlay, ofb);
igt_plane_set_position(data->overlay, or->x, or->y);
igt_plane_set_size(data->overlay, or->w, or->h);
igt_fb_set_size(ofb, data->overlay, or->w, or->h);
igt_fb_set_position(ofb, data->overlay,
(ofb->width - or->w) / 2,
(ofb->height - or->h) / 2);
}
igt_plane_set_fb(data->cursor, cfb);
igt_plane_set_position(data->cursor, x, y);
igt_display_commit_atomic(&data->display, 0, NULL);
/* Wait for one more vblank since cursor updates are not
* synchronized to the same frame on AMD hw */
if(is_amdgpu_device(data->drm_fd))
igt_wait_for_vblank_count(data->drm_fd, data->display.pipes[data->pipe_id].crtc_offset, 1);
igt_pipe_crc_get_current(data->drm_fd, data->pipe_crc, &test_crc);
igt_pipe_crc_stop(data->pipe_crc);
igt_assert_crc_equal(&ref_crc, &test_crc);
}
/*
* Tests the cursor on a variety of positions on the screen.
* Specific edge cases that should be captured here are the negative edges
* of each plane and the centers.
*/
static void test_cursor_spots(data_t *data, int size, unsigned int flags)
{
int sw = data->mode->hdisplay;
int sh = data->mode->vdisplay;
const rect_t *or = &data->or;
int i;
const pos_t pos[] = {
/* Test diagonally from top left to bottom right. */
{ -size / 3, -size / 3 },
{ 0, 0 },
{ or->x - size, or->y - size },
{ or->x - size / 3, or->y - size / 3 },
{ or->x, or->y },
{ or->x + size, or->y + size },
{ sw / 2, sh / 2 },
{ or->x + or->w - size, or->y + or->h - size },
{ or->x + or->w - size / 3, or->y + or->h - size / 3 },
{ or->x + or->w + size, or->y + or->h + size },
{ sw - size, sh - size },
{ sw - size / 3, sh - size / 3 },
/* Test remaining corners. */
{ sw - size, 0 },
{ 0, sh - size },
{ or->x + or->w - size, or->y },
{ or->x, or->y + or->h - size }
};
for (i = 0; i < ARRAY_SIZE(pos); ++i) {
test_cursor_pos(data, pos[i].x, pos[i].y, flags);
}
}
static void test_cleanup(data_t *data)
{
igt_remove_fb(data->drm_fd, &data->cfb);
igt_remove_fb(data->drm_fd, &data->ofb);
igt_remove_fb(data->drm_fd, &data->pfb);
}
static void test_cursor(data_t *data, int size, unsigned int flags)
{
int sw, sh;
int pad = 128;
igt_skip_on(size > data->max_curw || size > data->max_curh);
sw = data->mode->hdisplay;
sh = data->mode->vdisplay;
test_cleanup(data);
igt_create_color_fb(data->drm_fd, sw, sh, DRM_FORMAT_XRGB8888,
DRM_FORMAT_MOD_LINEAR, 1.0, 1.0, 1.0, &data->pfb);
if (flags & TEST_OVERLAY) {
int width = (flags & TEST_VIEWPORT) ? data->or.w + pad : data->or.w;
int height = (flags & TEST_VIEWPORT) ? data->or.h + pad : data->or.h;
igt_create_color_fb(data->drm_fd, width, height, DRM_FORMAT_XRGB8888,
DRM_FORMAT_MOD_LINEAR, 0.5, 0.5, 0.5, &data->ofb);
}
igt_create_color_fb(data->drm_fd, size, size, DRM_FORMAT_ARGB8888,
DRM_FORMAT_MOD_LINEAR, 1.0, 0.0, 1.0, &data->cfb);
igt_plane_set_fb(data->primary, &data->pfb);
igt_output_set_pipe(data->output, data->pipe_id);
igt_display_commit2(&data->display, COMMIT_ATOMIC);
test_cursor_spots(data, size, flags);
}
igt_main
{
static const int cursor_sizes[] = { 64, 128, 256 };
data_t data = { .max_curw = 64, .max_curh = 64 };
enum pipe pipe;
igt_output_t *output;
igt_display_t *display;
int i, j;
struct {
const char *name;
unsigned int flags;
const char *desc;
} tests[] = {
{ "primary", TEST_PRIMARY,
"Tests atomic cursor positioning on primary plane" },
{ "overlay", TEST_PRIMARY | TEST_OVERLAY,
"Tests atomic cursor positioning on primary plane and overlay plane" },
{ "viewport", TEST_PRIMARY | TEST_OVERLAY | TEST_VIEWPORT,
"Tests atomic cursor positioning on primary plane and overlay plane "
"with buffer larger than viewport used for display" },
};
igt_fixture {
int ret;
data.drm_fd = drm_open_driver_master(DRIVER_ANY);
ret = drmGetCap(data.drm_fd, DRM_CAP_CURSOR_WIDTH, &data.max_curw);
igt_assert(ret == 0 || errno == EINVAL);
ret = drmGetCap(data.drm_fd, DRM_CAP_CURSOR_HEIGHT, &data.max_curh);
igt_assert(ret == 0 || errno == EINVAL);
kmstest_set_vt_graphics_mode();
igt_display_require(&data.display, data.drm_fd);
igt_require(data.display.is_atomic);
igt_display_require_output(&data.display);
display = &data.display;
}
for (i = 0; i < ARRAY_SIZE(tests); i++) {
igt_describe_f("%s", tests[i].desc);
igt_subtest_with_dynamic_f("%s", tests[i].name) {
for_each_pipe_with_single_output(&data.display, pipe, output) {
if ((tests[i].flags & TEST_OVERLAY) &&
!igt_pipe_get_plane_type(&data.display.pipes[pipe],
DRM_PLANE_TYPE_OVERLAY))
continue;
igt_display_reset(display);
igt_output_set_pipe(output, pipe);
if (!i915_pipe_output_combo_valid(display))
continue;
test_init(&data, pipe, output);
for (j = 0; j < ARRAY_SIZE(cursor_sizes); j++) {
int size = cursor_sizes[j];
igt_dynamic_f("pipe-%s-%s-size-%d",
kmstest_pipe_name(pipe),
igt_output_name(output),
size)
test_cursor(&data, size, tests[i].flags);
test_cleanup(&data);
}
test_fini(&data);
}
}
}
igt_fixture {
igt_display_fini(&data.display);
drm_close_driver(data.drm_fd);
}
}
|