2 * Copyright © 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
24 * Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
33 #include "igt_debugfs.h"
35 #include "ioctl_wrappers.h"
39 igt_display_t display;
43 * Test that a page flip from a tiled buffer to a linear one works
44 * correctly. First, it sets the crtc with the linear buffer and generate
45 * a reference crc for the pipe. Then, the crtc is set with the tiled one
46 * and page flip to the linear one issued. A new crc is generated and
47 * compared to the rerence one.
51 fill_linear_fb(struct igt_fb *fb, data_t *data, drmModeModeInfo *mode)
55 cr = igt_get_cairo_ctx(data->drm_fd, fb);
56 igt_paint_test_pattern(cr, mode->hdisplay, mode->vdisplay);
61 test_flip_changes_tiling(data_t *data, igt_output_t *output)
63 struct igt_fb linear, tiled;
64 drmModeModeInfo *mode;
66 igt_pipe_crc_t *pipe_crc;
67 igt_crc_t reference_crc, crc;
68 int fb_id, pipe, ret, width;
71 pipe_crc = igt_pipe_crc_new(pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
72 igt_output_set_pipe(output, 0);
74 mode = igt_output_get_mode(output);
75 primary = igt_output_get_plane(output, 0);
77 /* Allocate a linear buffer. Since a page flip to a buffer with
78 * different stride doesn't work, choose width so that the stride of
79 * both buffers is the same. */
81 while (width < mode->hdisplay)
83 fb_id = igt_create_fb(data->drm_fd, width, mode->vdisplay,
84 DRM_FORMAT_XRGB8888, false, &linear);
86 /* fill it with a pattern that will look wrong if tiling is wrong */
87 fill_linear_fb(&linear, data, mode);
89 /* set the crtc and generate a reference crc */
90 igt_plane_set_fb(primary, &linear);
91 igt_display_commit(&data->display);
92 igt_pipe_crc_collect_crc(pipe_crc, &reference_crc);
94 /* allocate a tiled buffer and set the crtc with it */
95 igt_create_color_fb(data->drm_fd, width, mode->vdisplay,
96 DRM_FORMAT_XRGB8888, true, 0.0, 0.0, 0.0, &tiled);
97 igt_plane_set_fb(primary, &tiled);
98 igt_display_commit(&data->display);
100 /* flip to the linear buffer */
101 ret = drmModePageFlip(data->drm_fd, output->config.crtc->crtc_id,
103 igt_assert(ret == 0);
105 igt_wait_for_vblank(data->drm_fd, pipe);
107 /* get a crc and compare with the reference */
108 igt_pipe_crc_collect_crc(pipe_crc, &crc);
109 igt_assert(igt_crc_equal(&reference_crc, &crc));
112 igt_plane_set_fb(primary, NULL);
113 igt_pipe_crc_free(pipe_crc);
114 igt_output_set_pipe(output, PIPE_ANY);
115 igt_display_commit(&data->display);
117 igt_remove_fb(data->drm_fd, &tiled);
118 igt_remove_fb(data->drm_fd, &linear);
122 igt_output_t *output;
126 igt_skip_on_simulation();
129 data.drm_fd = drm_open_any();
131 igt_set_vt_graphics_mode();
133 igt_require_pipe_crc();
134 igt_display_init(&data.display, data.drm_fd);
137 igt_subtest_f("flip-changes-tiling") {
138 for_each_connected_output(&data.display, output)
139 test_flip_changes_tiling(&data, output);
143 igt_display_fini(&data.display);