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