kms_plane_lowres.c 8.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
/*
 * Copyright © 2016 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 */

#include "igt.h"
#include "drmtest.h"
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <time.h>

IGT_TEST_DESCRIPTION("Test atomic mode setting with a plane by switching between high and low resolutions");

#define MAX_CRCS          1
#define SIZE            256
#define LOOP_FOREVER     -1

typedef struct {
	int drm_fd;
	igt_display_t display;
42
	struct igt_fb *fb;
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
} data_t;

static drmModeModeInfo
get_lowres_mode(int drmfd, drmModeModeInfo *mode_default)
{
	drmModeRes *mode_resources = drmModeGetResources(drmfd);
	drmModeModeInfo mode;
	drmModeModeInfo std_1024_mode = {
		.clock = 65000,
		.hdisplay = 1024,
		.hsync_start = 1048,
		.hsync_end = 1184,
		.htotal = 1344,
		.hskew = 0,
		.vdisplay = 768,
		.vsync_start = 771,
		.vsync_end = 777,
		.vtotal = 806,
		.vscan = 0,
		.vrefresh = 60,
		.flags = 0xA,
		.type = 0x40,
		.name = "Custom 1024x768",
	};
	bool found;
	int limit = mode_default->vdisplay-SIZE;
	int i, j;

	if (!mode_resources) {
		igt_warn("drmModeGetResources failed: %s\n", strerror(errno));
		return std_1024_mode;
	}

	found = false;
	for (i = 0; i < mode_resources->count_connectors; i++) {
		drmModeConnector *connector;

		connector = drmModeGetConnectorCurrent(drmfd,
						       mode_resources->connectors[i]);
		if (!connector) {
			igt_warn("could not get connector %i: %s\n",
				 mode_resources->connectors[i], strerror(errno));
			continue;
		}

		if (!connector->count_modes)
			continue;

		for (j = 0; j < connector->count_modes; j++) {
			mode = connector->modes[j];
			if (mode.vdisplay < limit) {
				found = true;
				break;
			}
		}

		drmModeFreeConnector(connector);
	}

	drmModeFreeResources(mode_resources);

	if (!found)
		return std_1024_mode;

	return mode;
}

static void
111
test_fini(data_t *data, igt_output_t *output, enum pipe pipe)
112
{
113
	igt_plane_t *plane;
114 115 116 117

	/* restore original mode */
	igt_output_override_mode(output, NULL);

118 119
	for_each_plane_on_pipe(&data->display, pipe, plane)
		igt_plane_set_fb(plane, NULL);
120 121 122 123

	/* reset the constraint on the pipe */
	igt_output_set_pipe(output, PIPE_ANY);

124 125
	free(data->fb);
	data->fb = NULL;
126 127 128 129 130 131 132 133 134 135 136
}

static void
check_mode(drmModeModeInfo *mode1, drmModeModeInfo *mode2)
{
	igt_assert_eq(mode1->hdisplay, mode2->hdisplay);
	igt_assert_eq(mode1->vdisplay, mode2->vdisplay);
	igt_assert_eq(mode1->vrefresh, mode2->vrefresh);
}

static drmModeModeInfo *
137
test_setup(data_t *data, enum pipe pipe, uint64_t modifier,
138 139 140 141
	   igt_output_t *output)
{
	drmModeModeInfo *mode;
	int size;
142 143
	int i = 1, x, y;
	igt_plane_t *plane;
144

145 146 147 148
	igt_skip_on(!igt_display_has_format_mod(&data->display,
						DRM_FORMAT_XRGB8888,
						modifier));

149 150 151 152
	igt_output_set_pipe(output, pipe);

	mode = igt_output_get_mode(output);

153 154 155 156
	data->fb = calloc(data->display.pipes[pipe].n_planes, sizeof(struct igt_fb));
	igt_assert_f(data->fb, "Failed to allocate memory for %d FBs\n",
	             data->display.pipes[pipe].n_planes);

157 158 159 160 161 162 163
	igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
			    DRM_FORMAT_XRGB8888,
			    modifier,
			    0.0, 0.0, 1.0,
			    &data->fb[0]);

	/* yellow sprite plane in lower left corner */
164
	for_each_plane_on_pipe(&data->display, pipe, plane) {
165 166 167
		uint64_t plane_modifier;
		uint32_t plane_format;

168 169
		if (plane->type == DRM_PLANE_TYPE_PRIMARY) {
			igt_plane_set_fb(plane, &data->fb[0]);
170
			continue;
171 172 173
		}

		if (plane->type == DRM_PLANE_TYPE_CURSOR)
174 175 176 177 178 179 180
			size = 64;
		else
			size = SIZE;

		x = 0;
		y = mode->vdisplay - size;

181 182 183 184 185 186 187 188 189
		plane_format = plane->type == DRM_PLANE_TYPE_CURSOR ?
			DRM_FORMAT_ARGB8888 : DRM_FORMAT_XRGB8888;

		plane_modifier = plane->type == DRM_PLANE_TYPE_CURSOR ?
			LOCAL_DRM_FORMAT_MOD_NONE : modifier;

		igt_skip_on(!igt_plane_has_format_mod(plane, plane_format,
						      plane_modifier));

190 191
		igt_create_color_fb(data->drm_fd,
				    size, size,
192 193
				    plane_format,
				    plane_modifier,
194 195 196
				    1.0, 1.0, 0.0,
				    &data->fb[i]);

197 198
		igt_plane_set_position(plane, x, y);
		igt_plane_set_fb(plane, &data->fb[i++]);
199 200 201 202 203 204 205 206 207
	}

	return mode;
}

static void
test_plane_position_with_output(data_t *data, enum pipe pipe,
				igt_output_t *output, uint64_t modifier)
{
208 209
	igt_crc_t crc_hires1, crc_hires2;
	igt_crc_t crc_lowres;
210 211
	drmModeModeInfo mode_lowres;
	drmModeModeInfo *mode1, *mode2, *mode3;
212
	int ret;
213
	igt_pipe_crc_t *pipe_crc;
214 215 216 217

	igt_info("Testing connector %s using pipe %s\n",
		 igt_output_name(output), kmstest_pipe_name(pipe));

218
	mode1 = test_setup(data, pipe, modifier, output);
219 220 221 222 223 224

	mode_lowres = get_lowres_mode(data->drm_fd, mode1);

	ret = igt_display_try_commit2(&data->display, COMMIT_ATOMIC);
	igt_skip_on(ret != 0);

225
	pipe_crc = igt_pipe_crc_new(data->drm_fd, pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
226 227
	igt_pipe_crc_start(pipe_crc);
	igt_pipe_crc_get_single(pipe_crc, &crc_hires1);
228

229
	igt_assert_plane_visible(data->drm_fd, pipe, true);
230 231 232 233 234 235 236 237 238

	/* switch to lower resolution */
	igt_output_override_mode(output, &mode_lowres);
	igt_output_set_pipe(output, pipe);

	mode2 = igt_output_get_mode(output);

	check_mode(&mode_lowres, mode2);

239
	igt_display_commit2(&data->display, COMMIT_ATOMIC);
240
	igt_pipe_crc_get_current(data->display.drm_fd, pipe_crc, &crc_lowres);
241

242
	igt_assert_plane_visible(data->drm_fd, pipe, false);
243 244 245 246 247 248 249 250 251

	/* switch back to higher resolution */
	igt_output_override_mode(output, NULL);
	igt_output_set_pipe(output, pipe);

	mode3 = igt_output_get_mode(output);

	check_mode(mode1, mode3);

252 253
	igt_display_commit2(&data->display, COMMIT_ATOMIC);

254
	igt_pipe_crc_get_current(data->display.drm_fd, pipe_crc, &crc_hires2);
255

256
	igt_assert_plane_visible(data->drm_fd, pipe, true);
257

258 259
	igt_assert_crc_equal(&crc_hires1, &crc_hires2);

260 261
	igt_pipe_crc_stop(pipe_crc);
	igt_pipe_crc_free(pipe_crc);
262

263
	test_fini(data, output, pipe);
264 265 266 267 268 269 270
}

static void
test_plane_position(data_t *data, enum pipe pipe, uint64_t modifier)
{
	igt_output_t *output;

271
	for_each_valid_output_on_pipe(&data->display, pipe, output)
272 273 274 275 276 277
		test_plane_position_with_output(data, pipe, output, modifier);
}

static void
run_tests_for_pipe(data_t *data, enum pipe pipe)
{
278 279 280 281 282 283
	igt_fixture {
		igt_skip_on(pipe >= data->display.n_pipes);

		igt_display_require_output_on_pipe(&data->display, pipe);
	}

284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
	igt_subtest_f("pipe-%s-tiling-none",
		      kmstest_pipe_name(pipe))
		test_plane_position(data, pipe, LOCAL_DRM_FORMAT_MOD_NONE);

	igt_subtest_f("pipe-%s-tiling-x",
		      kmstest_pipe_name(pipe))
		test_plane_position(data, pipe, LOCAL_I915_FORMAT_MOD_X_TILED);

	igt_subtest_f("pipe-%s-tiling-y",
		      kmstest_pipe_name(pipe))
		test_plane_position(data, pipe, LOCAL_I915_FORMAT_MOD_Y_TILED);

	igt_subtest_f("pipe-%s-tiling-yf",
		      kmstest_pipe_name(pipe))
		test_plane_position(data, pipe, LOCAL_I915_FORMAT_MOD_Yf_TILED);
}

static data_t data;

igt_main
{
305 306
	enum pipe pipe;

307 308 309 310 311 312 313
	igt_skip_on_simulation();

	igt_fixture {
		data.drm_fd = drm_open_driver_master(DRIVER_ANY);

		kmstest_set_vt_graphics_mode();

314
		igt_require_pipe_crc(data.drm_fd);
315
		igt_display_require(&data.display, data.drm_fd);
316
		igt_require(data.display.is_atomic);
317 318
	}

319
	for_each_pipe_static(pipe)
320 321
		igt_subtest_group
			run_tests_for_pipe(&data, pipe);
322 323 324 325 326 327 328

	igt_fixture {
		igt_display_fini(&data.display);
	}

	igt_exit();
}