2 * Copyright © 2013,2014 Intel Corporation
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:
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
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
28 #include "igt_debugfs.h"
34 igt_display_t display;
37 igt_pipe_crc_t *pipe_crc;
41 paint_squares(data_t *data, struct igt_fb *fb, drmModeModeInfo *mode,
42 igt_rotation_t rotation)
50 cr = igt_get_cairo_ctx(data->gfx_fd, &data->fb);
52 if (rotation == IGT_ROTATION_180) {
53 cairo_translate(cr, w, h);
54 cairo_rotate(cr, M_PI);
57 /* Paint with 4 squares of Red, Green, White, Blue Clockwise */
58 igt_paint_color(cr, 0, 0, w / 2, h / 2, 1.0, 0.0, 0.0);
59 igt_paint_color(cr, w / 2, 0, w / 2, h / 2, 0.0, 1.0, 0.0);
60 igt_paint_color(cr, 0, h / 2, w / 2, h / 2, 0.0, 0.0, 1.0);
61 igt_paint_color(cr, w / 2, h / 2, w / 2, h / 2, 1.0, 1.0, 1.0);
66 static bool prepare_crtc(data_t *data, igt_output_t *output, enum pipe pipe,
69 drmModeModeInfo *mode;
70 igt_display_t *display = &data->display;
73 igt_output_set_pipe(output, pipe);
76 /* create the pipe_crc object for this pipe */
77 igt_pipe_crc_free(data->pipe_crc);
78 data->pipe_crc = igt_pipe_crc_new(pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
79 if (!data->pipe_crc) {
80 igt_info("auto crc not supported on this connector with pipe %i\n",
85 mode = igt_output_get_mode(output);
87 fb_id = igt_create_fb(data->gfx_fd,
88 mode->hdisplay, mode->vdisplay,
94 /* Step 1: create a reference CRC for a software-rotated fb */
96 paint_squares(data, &data->fb, mode, IGT_ROTATION_180);
99 * XXX: We always set the primary plane to actually enable the pipe as
100 * there's no way (that works) to light up a pipe with only a sprite
101 * plane enabled at the moment.
103 if (!plane->is_primary) {
104 igt_plane_t *primary;
106 primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
107 igt_plane_set_fb(primary, &data->fb);
110 igt_plane_set_fb(plane, &data->fb);
111 igt_display_commit(display);
113 igt_pipe_crc_collect_crc(data->pipe_crc, &data->ref_crc);
116 * Step 2: prepare the plane with an non-rotated fb let the hw
119 paint_squares(data, &data->fb, mode, IGT_ROTATION_0);
121 igt_plane_set_fb(plane, &data->fb);
122 igt_display_commit(display);
127 static void cleanup_crtc(data_t *data, igt_output_t *output, igt_plane_t *plane)
129 igt_display_t *display = &data->display;
131 igt_pipe_crc_free(data->pipe_crc);
132 data->pipe_crc = NULL;
134 igt_remove_fb(data->gfx_fd, &data->fb);
136 /* XXX: see the note in prepare_crtc() */
137 if (!plane->is_primary) {
138 igt_plane_t *primary;
140 primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
141 igt_plane_set_fb(primary, NULL);
144 igt_plane_set_fb(plane, NULL);
145 igt_output_set_pipe(output, PIPE_ANY);
147 igt_display_commit(display);
150 static void test_plane_rotation(data_t *data, enum igt_plane plane_type)
152 igt_display_t *display = &data->display;
153 igt_output_t *output;
156 igt_crc_t crc_output;
157 enum igt_commit_style commit = COMMIT_LEGACY;
159 if (plane_type == IGT_PLANE_PRIMARY) {
160 igt_require(data->display.has_universal_planes);
161 commit = COMMIT_UNIVERSAL;
164 for_each_connected_output(display, output) {
165 for_each_pipe(display, pipe) {
168 igt_output_set_pipe(output, pipe);
170 plane = igt_output_get_plane(output, plane_type);
171 igt_require(igt_plane_supports_rotation(plane));
173 if (!prepare_crtc(data, output, pipe, plane))
176 igt_plane_set_rotation(plane, IGT_ROTATION_180);
177 igt_display_commit2(display, commit);
179 igt_pipe_crc_collect_crc(data->pipe_crc, &crc_output);
180 igt_assert(igt_crc_equal(&data->ref_crc, &crc_output));
183 cleanup_crtc(data, output, plane);
186 igt_require_f(valid_tests, "no valid crtc/connector combinations found\n");
193 igt_skip_on_simulation();
196 data.gfx_fd = drm_open_any();
198 igt_set_vt_graphics_mode();
200 igt_require_pipe_crc();
202 igt_display_init(&data.display, data.gfx_fd);
205 igt_subtest_f("primary-rotation")
206 test_plane_rotation(&data, IGT_PLANE_PRIMARY);
208 igt_subtest_f("sprite-rotation")
209 test_plane_rotation(&data, IGT_PLANE_2);
212 igt_display_fini(&data.display);