blob: 491e429f4570c13b99cf3f14746680653233343c [file] [log] [blame]
chandra konduru8b3082a2015-03-30 13:53:00 -07001/*
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
Thomas Wood804e11f2015-08-17 17:57:43 +010025#include "igt.h"
chandra konduru8b3082a2015-03-30 13:53:00 -070026#include <math.h>
Maarten Lankhorst38170522016-07-05 14:55:52 +020027#include <sys/stat.h>
chandra konduru8b3082a2015-03-30 13:53:00 -070028
29IGT_TEST_DESCRIPTION("Test display panel fitting");
30
31typedef struct {
chandra konduru8b3082a2015-03-30 13:53:00 -070032 int drm_fd;
33 igt_display_t display;
chandra konduru8b3082a2015-03-30 13:53:00 -070034
chandra konduru8b3082a2015-03-30 13:53:00 -070035 struct igt_fb fb1;
36 struct igt_fb fb2;
chandra konduru8b3082a2015-03-30 13:53:00 -070037
38 igt_plane_t *plane1;
39 igt_plane_t *plane2;
chandra konduru8b3082a2015-03-30 13:53:00 -070040} data_t;
41
Maarten Lankhorst3df9f712018-02-22 13:37:10 +010042static 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}
chandra konduru8b3082a2015-03-30 13:53:00 -070048
chandra konduru8b3082a2015-03-30 13:53:00 -070049static 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
Maarten Lankhorst3df9f712018-02-22 13:37:10 +010054 igt_output_override_mode(output, mode);
chandra konduru8b3082a2015-03-30 13:53:00 -070055 igt_output_set_pipe(output, pipe);
56
chandra konduru8b3082a2015-03-30 13:53:00 -070057 /* before allocating, free if any older fb */
Maarten Lankhorstaa5068c2018-02-02 11:00:50 +010058 igt_remove_fb(data->drm_fd, &data->fb1);
chandra konduru8b3082a2015-03-30 13:53:00 -070059
60 /* allocate fb for plane 1 */
Maarten Lankhorst2646ae12018-01-18 12:54:07 +010061 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);
chandra konduru8b3082a2015-03-30 13:53:00 -070066
chandra konduru8b3082a2015-03-30 13:53:00 -070067 /*
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 */
Robert Foss303937a2017-01-10 20:04:55 -050072 if (plane->type != DRM_PLANE_TYPE_PRIMARY) {
chandra konduru8b3082a2015-03-30 13:53:00 -070073 igt_plane_t *primary;
74
Robert Foss303937a2017-01-10 20:04:55 -050075 primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
chandra konduru8b3082a2015-03-30 13:53:00 -070076 igt_plane_set_fb(primary, &data->fb1);
77 }
78
79 igt_plane_set_fb(plane, &data->fb1);
Maarten Lankhorst7df7e3b2017-09-21 12:53:27 +020080 igt_display_commit2(display, s);
chandra konduru8b3082a2015-03-30 13:53:00 -070081}
82
chandra konduru8b3082a2015-03-30 13:53:00 -070083static void test_panel_fitting(data_t *d)
84{
85 igt_display_t *display = &d->display;
86 igt_output_t *output;
chandra konduru8b3082a2015-03-30 13:53:00 -070087 enum pipe pipe;
88 int valid_tests = 0;
89
Maarten Lankhorst5af520a2016-07-05 12:53:05 +020090 for_each_pipe_with_valid_output(display, pipe, output) {
chandra konduru8b3082a2015-03-30 13:53:00 -070091 drmModeModeInfo *mode, native_mode;
Maarten Lankhorst24c5e072018-05-24 09:00:47 +020092 uint32_t devid = intel_get_drm_devid(display->drm_fd);
Robert Fossec83ef92016-05-03 10:40:22 -040093
94 /* Check that the "scaling mode" property has been set. */
Maarten Lankhorst3df9f712018-02-22 13:37:10 +010095 if (!igt_output_has_prop(output, IGT_CONNECTOR_SCALING_MODE))
Robert Foss26afcfc2016-05-03 10:40:16 -040096 continue;
chandra konduru8b3082a2015-03-30 13:53:00 -070097
Maarten Lankhorst3df9f712018-02-22 13:37:10 +010098 cleanup_crtc(d);
chandra konduru8b3082a2015-03-30 13:53:00 -070099 igt_output_set_pipe(output, pipe);
100
101 mode = igt_output_get_mode(output);
102 native_mode = *mode;
103
Maarten Lankhorst2646ae12018-01-18 12:54:07 +0100104 /* allocate fb2 with image */
Maarten Lankhorst3df9f712018-02-22 13:37:10 +0100105 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);
chandra konduru8b3082a2015-03-30 13:53:00 -0700108
109 /* Set up display to enable panel fitting */
110 mode->hdisplay = 640;
111 mode->vdisplay = 480;
Robert Foss303937a2017-01-10 20:04:55 -0500112 d->plane1 = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
chandra konduru8b3082a2015-03-30 13:53:00 -0700113 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. */
Robert Foss303937a2017-01-10 20:04:55 -0500127 d->plane2 = igt_output_get_plane_type(output, DRM_PLANE_TYPE_OVERLAY);
chandra konduru8b3082a2015-03-30 13:53:00 -0700128 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
Maarten Lankhorst8a26e0e2018-03-14 11:47:30 +0100137 /*
Maarten Lankhorst24c5e072018-05-24 09:00:47 +0200138 * most of gen7 and all of gen8 doesn't support scaling at all.
139 *
Maarten Lankhorst8a26e0e2018-03-14 11:47:30 +0100140 * 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 */
Maarten Lankhorst24c5e072018-05-24 09:00:47 +0200147 if (IS_GEN8(devid) || (IS_GEN7(devid) && !IS_IVYBRIDGE(devid)) ||
148 (IS_GEN9(devid) && pipe == PIPE_C))
Maarten Lankhorst8a26e0e2018-03-14 11:47:30 +0100149 igt_plane_set_size(d->plane2, d->fb2.width-200, d->fb2.height-200);
150
chandra konduru8b3082a2015-03-30 13:53:00 -0700151 /* 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
chandra konduru8b3082a2015-03-30 13:53:00 -0700156 valid_tests++;
chandra konduru8b3082a2015-03-30 13:53:00 -0700157 }
158 igt_require_f(valid_tests, "no valid crtc/connector combinations found\n");
159}
160
Maarten Lankhorst38170522016-07-05 14:55:52 +0200161static void
162test_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;
Maarten Lankhorst56f1bd62016-11-28 12:36:02 +0100166 struct igt_fb red, green, blue;
Maarten Lankhorst38170522016-07-05 14:55:52 +0200167
Maarten Lankhorst3df9f712018-02-22 13:37:10 +0100168 mode = *igt_output_get_mode(output);
Maarten Lankhorst38170522016-07-05 14:55:52 +0200169
Maarten Lankhorst38170522016-07-05 14:55:52 +0200170 igt_output_set_pipe(output, pipe);
171
Robert Foss303937a2017-01-10 20:04:55 -0500172 primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
173 sprite = igt_output_get_plane_type(output, DRM_PLANE_TYPE_OVERLAY);
Maarten Lankhorst38170522016-07-05 14:55:52 +0200174
175 igt_create_color_fb(display->drm_fd, mode.hdisplay, mode.vdisplay,
176 DRM_FORMAT_XRGB8888, LOCAL_DRM_FORMAT_MOD_NONE,
Maarten Lankhorst56f1bd62016-11-28 12:36:02 +0100177 0.f, 0.f, 1.f, &blue);
Maarten Lankhorst38170522016-07-05 14:55:52 +0200178
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
Maarten Lankhorst56f1bd62016-11-28 12:36:02 +0100183 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);
Maarten Lankhorst38170522016-07-05 14:55:52 +0200188 igt_plane_set_fb(sprite, &red);
189
190 igt_display_commit2(display, COMMIT_ATOMIC);
191
Maarten Lankhorst38170522016-07-05 14:55:52 +0200192 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
Maarten Lankhorst56f1bd62016-11-28 12:36:02 +0100202 /* 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);
Maarten Lankhorst38170522016-07-05 14:55:52 +0200208}
209
Maarten Lankhorst3df9f712018-02-22 13:37:10 +0100210static void test_atomic_fastset(data_t *data)
Maarten Lankhorst38170522016-07-05 14:55:52 +0200211{
Maarten Lankhorst3df9f712018-02-22 13:37:10 +0100212 igt_display_t *display = &data->display;
Maarten Lankhorst38170522016-07-05 14:55:52 +0200213 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
Maarten Lankhorst38170522016-07-05 14:55:52 +0200222 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) {
Maarten Lankhorst3df9f712018-02-22 13:37:10 +0100226 if (!igt_output_has_prop(output, IGT_CONNECTOR_SCALING_MODE))
Maarten Lankhorst38170522016-07-05 14:55:52 +0200227 continue;
228
Maarten Lankhorst3df9f712018-02-22 13:37:10 +0100229 cleanup_crtc(data);
Maarten Lankhorst38170522016-07-05 14:55:52 +0200230 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
236igt_main
chandra konduru8b3082a2015-03-30 13:53:00 -0700237{
238 data_t data = {};
239
Maarten Lankhorst38170522016-07-05 14:55:52 +0200240 igt_fixture {
241 igt_skip_on_simulation();
chandra konduru8b3082a2015-03-30 13:53:00 -0700242
Maarten Lankhorst38170522016-07-05 14:55:52 +0200243 data.drm_fd = drm_open_driver(DRIVER_ANY);
Chris Wilson7f41adf2018-09-14 21:10:05 +0100244 igt_display_require(&data.display, data.drm_fd);
Maarten Lankhorst3df9f712018-02-22 13:37:10 +0100245 igt_display_require_output(&data.display);
Maarten Lankhorst38170522016-07-05 14:55:52 +0200246 }
chandra konduru8b3082a2015-03-30 13:53:00 -0700247
Maarten Lankhorst38170522016-07-05 14:55:52 +0200248 igt_subtest("legacy")
249 test_panel_fitting(&data);
chandra konduru8b3082a2015-03-30 13:53:00 -0700250
Maarten Lankhorst38170522016-07-05 14:55:52 +0200251 igt_subtest("atomic-fastset")
Maarten Lankhorst3df9f712018-02-22 13:37:10 +0100252 test_atomic_fastset(&data);
Maarten Lankhorst38170522016-07-05 14:55:52 +0200253
254 igt_fixture
255 igt_display_fini(&data.display);
chandra konduru8b3082a2015-03-30 13:53:00 -0700256}