1 /*
2 * Copyright © 2013,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 */
24
25 #include "igt.h"
26 #include <math.h>
27 #include <sys/stat.h>
28
29 IGT_TEST_DESCRIPTION("Test display panel fitting");
30
31 typedef struct {
32 int drm_fd;
33 igt_display_t display;
34
35 struct igt_fb fb1;
36 struct igt_fb fb2;
37
38 igt_plane_t *plane1;
39 igt_plane_t *plane2;
40 } data_t;
41
cleanup_crtc(data_t * data)42 static void cleanup_crtc(data_t *data)
43 {
44 igt_display_reset(&data->display);
45 igt_remove_fb(data->drm_fd, &data->fb1);
46 igt_remove_fb(data->drm_fd, &data->fb2);
47 }
48
prepare_crtc(data_t * data,igt_output_t * output,enum pipe pipe,igt_plane_t * plane,drmModeModeInfo * mode,enum igt_commit_style s)49 static void prepare_crtc(data_t *data, igt_output_t *output, enum pipe pipe,
50 igt_plane_t *plane, drmModeModeInfo *mode, enum igt_commit_style s)
51 {
52 igt_display_t *display = &data->display;
53
54 igt_output_override_mode(output, mode);
55 igt_output_set_pipe(output, pipe);
56
57 /* before allocating, free if any older fb */
58 igt_remove_fb(data->drm_fd, &data->fb1);
59
60 /* allocate fb for plane 1 */
61 igt_create_pattern_fb(data->drm_fd,
62 mode->hdisplay, mode->vdisplay,
63 DRM_FORMAT_XRGB8888,
64 LOCAL_DRM_FORMAT_MOD_NONE,
65 &data->fb1);
66
67 /*
68 * We always set the primary plane to actually enable the pipe as
69 * there's no way (that works) to light up a pipe with only a sprite
70 * plane enabled at the moment.
71 */
72 if (plane->type != DRM_PLANE_TYPE_PRIMARY) {
73 igt_plane_t *primary;
74
75 primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
76 igt_plane_set_fb(primary, &data->fb1);
77 }
78
79 igt_plane_set_fb(plane, &data->fb1);
80 igt_display_commit2(display, s);
81 }
82
test_panel_fitting(data_t * d)83 static void test_panel_fitting(data_t *d)
84 {
85 igt_display_t *display = &d->display;
86 igt_output_t *output;
87 enum pipe pipe;
88 int valid_tests = 0;
89
90 for_each_pipe_with_valid_output(display, pipe, output) {
91 drmModeModeInfo *mode, native_mode;
92 uint32_t devid = intel_get_drm_devid(display->drm_fd);
93
94 /* Check that the "scaling mode" property has been set. */
95 if (!igt_output_has_prop(output, IGT_CONNECTOR_SCALING_MODE))
96 continue;
97
98 cleanup_crtc(d);
99 igt_output_set_pipe(output, pipe);
100
101 mode = igt_output_get_mode(output);
102 native_mode = *mode;
103
104 /* allocate fb2 with image */
105 igt_create_pattern_fb(d->drm_fd, mode->hdisplay / 2, mode->vdisplay / 2,
106 DRM_FORMAT_XRGB8888,
107 LOCAL_DRM_FORMAT_MOD_NONE, &d->fb2);
108
109 /* Set up display to enable panel fitting */
110 mode->hdisplay = 640;
111 mode->vdisplay = 480;
112 d->plane1 = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
113 prepare_crtc(d, output, pipe, d->plane1, mode, COMMIT_LEGACY);
114
115 /* disable panel fitting */
116 prepare_crtc(d, output, pipe, d->plane1, &native_mode, COMMIT_LEGACY);
117
118 /* enable panel fitting */
119 mode->hdisplay = 800;
120 mode->vdisplay = 600;
121 prepare_crtc(d, output, pipe, d->plane1, mode, COMMIT_LEGACY);
122
123 /* disable panel fitting */
124 prepare_crtc(d, output, pipe, d->plane1, &native_mode, COMMIT_LEGACY);
125
126 /* Set up fb2->plane2 mapping. */
127 d->plane2 = igt_output_get_plane_type(output, DRM_PLANE_TYPE_OVERLAY);
128 igt_plane_set_fb(d->plane2, &d->fb2);
129
130 /* enable sprite plane */
131 igt_fb_set_position(&d->fb2, d->plane2, 100, 100);
132 igt_fb_set_size(&d->fb2, d->plane2, d->fb2.width-200, d->fb2.height-200);
133 igt_plane_set_position(d->plane2, 100, 100);
134 igt_plane_set_size(d->plane2, mode->hdisplay-200, mode->vdisplay-200);
135 igt_display_commit2(display, COMMIT_UNIVERSAL);
136
137 /*
138 * most of gen7 and all of gen8 doesn't support scaling at all.
139 *
140 * gen9 pipe C has only 1 scaler shared with the crtc, which
141 * means pipe scaling can't work simultaneously with panel
142 * fitting.
143 *
144 * Since this is the legacy path, userspace has to know about
145 * the HW limitations, whereas atomic can ask.
146 */
147 if (IS_GEN8(devid) || (IS_GEN7(devid) && !IS_IVYBRIDGE(devid)) ||
148 (IS_GEN9(devid) && pipe == PIPE_C))
149 igt_plane_set_size(d->plane2, d->fb2.width-200, d->fb2.height-200);
150
151 /* enable panel fitting along with sprite scaling */
152 mode->hdisplay = 1024;
153 mode->vdisplay = 768;
154 prepare_crtc(d, output, pipe, d->plane1, mode, COMMIT_LEGACY);
155
156 valid_tests++;
157 }
158 igt_require_f(valid_tests, "no valid crtc/connector combinations found\n");
159 }
160
161 static void
test_panel_fitting_fastset(igt_display_t * display,const enum pipe pipe,igt_output_t * output)162 test_panel_fitting_fastset(igt_display_t *display, const enum pipe pipe, igt_output_t *output)
163 {
164 igt_plane_t *primary, *sprite;
165 drmModeModeInfo mode;
166 struct igt_fb red, green, blue;
167
168 mode = *igt_output_get_mode(output);
169
170 igt_output_set_pipe(output, pipe);
171
172 primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
173 sprite = igt_output_get_plane_type(output, DRM_PLANE_TYPE_OVERLAY);
174
175 igt_create_color_fb(display->drm_fd, mode.hdisplay, mode.vdisplay,
176 DRM_FORMAT_XRGB8888, LOCAL_DRM_FORMAT_MOD_NONE,
177 0.f, 0.f, 1.f, &blue);
178
179 igt_create_color_fb(display->drm_fd, 640, 480,
180 DRM_FORMAT_XRGB8888, LOCAL_DRM_FORMAT_MOD_NONE,
181 1.f, 0.f, 0.f, &red);
182
183 igt_create_color_fb(display->drm_fd, 800, 600,
184 DRM_FORMAT_XRGB8888, LOCAL_DRM_FORMAT_MOD_NONE,
185 0.f, 1.f, 0.f, &green);
186
187 igt_plane_set_fb(primary, &blue);
188 igt_plane_set_fb(sprite, &red);
189
190 igt_display_commit2(display, COMMIT_ATOMIC);
191
192 mode.hdisplay = 640;
193 mode.vdisplay = 480;
194 igt_output_override_mode(output, &mode);
195
196 igt_plane_set_fb(sprite, NULL);
197 igt_plane_set_fb(primary, &red);
198
199 /* Don't pass ALLOW_MODESET with overridden mode, force fastset. */
200 igt_display_commit_atomic(display, 0, NULL);
201
202 /* Test with different scaled mode */
203 mode.hdisplay = 800;
204 mode.vdisplay = 600;
205 igt_output_override_mode(output, &mode);
206 igt_plane_set_fb(primary, &green);
207 igt_display_commit_atomic(display, 0, NULL);
208 }
209
test_atomic_fastset(data_t * data)210 static void test_atomic_fastset(data_t *data)
211 {
212 igt_display_t *display = &data->display;
213 igt_output_t *output;
214 enum pipe pipe;
215 int valid_tests = 0;
216 struct stat sb;
217
218 /* Until this is force enabled, force modeset evasion. */
219 if (stat("/sys/module/i915/parameters/fastboot", &sb) == 0)
220 igt_set_module_param_int("fastboot", 1);
221
222 igt_require(display->is_atomic);
223 igt_require(intel_gen(intel_get_drm_devid(display->drm_fd)) >= 5);
224
225 for_each_pipe_with_valid_output(display, pipe, output) {
226 if (!igt_output_has_prop(output, IGT_CONNECTOR_SCALING_MODE))
227 continue;
228
229 cleanup_crtc(data);
230 test_panel_fitting_fastset(display, pipe, output);
231 valid_tests++;
232 }
233 igt_require_f(valid_tests, "no valid crtc/connector combinations found\n");
234 }
235
236 igt_main
237 {
238 data_t data = {};
239
240 igt_fixture {
241 igt_skip_on_simulation();
242
243 data.drm_fd = drm_open_driver(DRIVER_ANY);
244 igt_display_require(&data.display, data.drm_fd);
245 igt_display_require_output(&data.display);
246 }
247
248 igt_subtest("legacy")
249 test_panel_fitting(&data);
250
251 igt_subtest("atomic-fastset")
252 test_atomic_fastset(&data);
253
254 igt_fixture
255 igt_display_fini(&data.display);
256 }
257