lib/igt_kms: s/kmstest_create_fb2/kmstest_create_fb/
[platform/upstream/intel-gpu-tools.git] / tests / kms_plane.c
1 /*
2  * Copyright © 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  * Authors:
24  *   Damien Lespiau <damien.lespiau@intel.com>
25  */
26
27 #include <errno.h>
28 #include <stdbool.h>
29 #include <stdio.h>
30 #include <string.h>
31
32 #include "drmtest.h"
33 #include "igt_debugfs.h"
34 #include "igt_kms.h"
35
36 typedef struct {
37         int drm_fd;
38         igt_display_t display;
39 } data_t;
40
41 /*
42  * Plane position test.
43  *   - We start by grabbing a reference CRC of a full green fb being scanned
44  *     out on the primary plane
45  *   - Then we scannout 2 planes:
46  *      - the primary plane uses a green fb with a black rectangle
47  *      - a plane, on top of the primary plane, with a green fb that is set-up
48  *        to cover the black rectangle of the primary plane fb
49  *     The resulting CRC should be identical to the reference CRC
50  */
51
52 typedef struct {
53         data_t *data;
54         igt_pipe_crc_t *pipe_crc;
55         igt_crc_t reference_crc;
56 } test_position_t;
57
58 /*
59  * create a green fb with a black rectangle at (rect_x,rect_y) and of size
60  * (rect_w,rect_h)
61  */
62 static void
63 create_fb_for_mode__position(data_t *data, drmModeModeInfo *mode,
64                              double rect_x, double rect_y,
65                              double rect_w, double rect_h,
66                              struct kmstest_fb *fb /* out */)
67 {
68         unsigned int fb_id;
69         cairo_t *cr;
70
71         fb_id = kmstest_create_fb(data->drm_fd,
72                                   mode->hdisplay, mode->vdisplay,
73                                   DRM_FORMAT_XRGB8888,
74                                   false /* tiling */,
75                                   fb);
76         igt_assert(fb_id);
77
78         cr = kmstest_get_cairo_ctx(data->drm_fd, fb);
79         kmstest_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
80                             0.0, 1.0, 0.0);
81         kmstest_paint_color(cr, rect_x, rect_y, rect_w, rect_h, 0.0, 0.0, 0.0);
82         igt_assert(cairo_status(cr) == 0);
83         cairo_destroy(cr);
84 }
85
86 static void
87 test_position_init(test_position_t *test, igt_output_t *output, enum pipe pipe)
88 {
89         data_t *data = test->data;
90         struct kmstest_fb green_fb;
91         drmModeModeInfo *mode;
92         igt_plane_t *primary;
93
94         test->pipe_crc = igt_pipe_crc_new(pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
95
96         igt_output_set_pipe(output, pipe);
97         primary = igt_output_get_plane(output, 0);
98
99         mode = igt_output_get_mode(output);
100         kmstest_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
101                                 DRM_FORMAT_XRGB8888,
102                                 false, /* tiled */
103                                 0.0, 1.0, 0.0,
104                                 &green_fb);
105         igt_plane_set_fb(primary, &green_fb);
106
107         igt_display_commit(&data->display);
108
109         igt_pipe_crc_collect_crc(test->pipe_crc, &test->reference_crc);
110
111         igt_plane_set_fb(primary, NULL);
112         igt_display_commit(&data->display);
113
114         kmstest_remove_fb(data->drm_fd, &green_fb);
115 }
116
117 static void
118 test_position_fini(test_position_t *test, igt_output_t *output)
119 {
120         igt_pipe_crc_free(test->pipe_crc);
121
122         igt_output_set_pipe(output, PIPE_ANY);
123         igt_display_commit(&test->data->display);
124 }
125
126 enum {
127         TEST_POSITION_FULLY_COVERED = 1 << 0,
128 };
129
130 static void
131 test_plane_position_with_output(data_t *data,
132                                 enum pipe pipe,
133                                 enum igt_plane plane,
134                                 igt_output_t *output,
135                                 unsigned int flags)
136 {
137         test_position_t test = { .data = data };
138         igt_plane_t *primary, *sprite;
139         struct kmstest_fb primary_fb, sprite_fb;
140         drmModeModeInfo *mode;
141         igt_crc_t crc;
142
143         fprintf(stdout, "Testing connector %s using pipe %c plane %d\n",
144                 igt_output_name(output), pipe_name(pipe), plane);
145
146         test_position_init(&test, output, pipe);
147
148         mode = igt_output_get_mode(output);
149         primary = igt_output_get_plane(output, 0);
150         sprite = igt_output_get_plane(output, plane);
151
152         create_fb_for_mode__position(data, mode, 100, 100, 64, 64,
153                                      &primary_fb);
154         igt_plane_set_fb(primary, &primary_fb);
155
156         kmstest_create_color_fb(data->drm_fd,
157                                 64, 64, /* width, height */
158                                 DRM_FORMAT_XRGB8888,
159                                 false, /* tiled */
160                                 0.0, 1.0, 0.0,
161                                 &sprite_fb);
162         igt_plane_set_fb(sprite, &sprite_fb);
163
164         if (flags & TEST_POSITION_FULLY_COVERED)
165                 igt_plane_set_position(sprite, 100, 100);
166         else
167                 igt_plane_set_position(sprite, 132, 132);
168
169         igt_display_commit(&data->display);
170
171         igt_pipe_crc_collect_crc(test.pipe_crc, &crc);
172
173         if (flags & TEST_POSITION_FULLY_COVERED)
174                 igt_assert(igt_crc_equal(&test.reference_crc, &crc));
175         else
176                 igt_assert(!igt_crc_equal(&test.reference_crc, &crc));
177
178         igt_plane_set_fb(primary, NULL);
179         igt_plane_set_fb(sprite, NULL);
180
181         test_position_fini(&test, output);
182 }
183
184 static void
185 test_plane_position(data_t *data, enum pipe pipe, enum igt_plane plane,
186                     unsigned int flags)
187 {
188         igt_output_t *output;
189
190         igt_skip_on(pipe >= data->display.n_pipes);
191         igt_skip_on(plane >= data->display.pipes[pipe].n_planes);
192
193         for_each_connected_output(&data->display, output)
194                 test_plane_position_with_output(data, pipe, plane, output,
195                                                 flags);
196 }
197
198 static void
199 run_tests_for_pipe_plane(data_t *data, enum pipe pipe, enum igt_plane plane)
200 {
201         igt_subtest_f("plane-position-covered-pipe-%c-plane-%d",
202                       pipe_name(pipe), plane)
203                 test_plane_position(data, pipe, plane,
204                                     TEST_POSITION_FULLY_COVERED);
205
206         igt_subtest_f("plane-position-hole-pipe-%c-plane-%d",
207                       pipe_name(pipe), plane)
208                 test_plane_position(data, pipe, plane, 0);
209 }
210
211 static void
212 run_tests_for_pipe(data_t *data, enum pipe pipe)
213 {
214         int plane;
215
216         for (plane = 1; plane < IGT_MAX_PLANES; plane++)
217                 run_tests_for_pipe_plane(data, pipe, plane);
218 }
219
220 static data_t data;
221
222 igt_main
223 {
224
225         igt_skip_on_simulation();
226
227         igt_fixture {
228                 data.drm_fd = drm_open_any();
229
230                 igt_set_vt_graphics_mode();
231
232                 igt_require_pipe_crc();
233                 igt_display_init(&data.display, data.drm_fd);
234         }
235
236         for (int pipe = 0; pipe < 3; pipe++)
237                 run_tests_for_pipe(&data, pipe);
238
239         igt_fixture {
240                 igt_display_fini(&data.display);
241         }
242 }