Blame tests/kms/libkms-test-screen.c

Packit Service 103f6b
/*
Packit Service 103f6b
 * Copyright © 2014 NVIDIA Corporation
Packit Service 103f6b
 *
Packit Service 103f6b
 * Permission is hereby granted, free of charge, to any person obtaining a
Packit Service 103f6b
 * copy of this software and associated documentation files (the "Software"),
Packit Service 103f6b
 * to deal in the Software without restriction, including without limitation
Packit Service 103f6b
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Packit Service 103f6b
 * and/or sell copies of the Software, and to permit persons to whom the
Packit Service 103f6b
 * Software is furnished to do so, subject to the following conditions:
Packit Service 103f6b
 *
Packit Service 103f6b
 * The above copyright notice and this permission notice (including the next
Packit Service 103f6b
 * paragraph) shall be included in all copies or substantial portions of the
Packit Service 103f6b
 * Software.
Packit Service 103f6b
 *
Packit Service 103f6b
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit Service 103f6b
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit Service 103f6b
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
Packit Service 103f6b
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Packit Service 103f6b
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
Packit Service 103f6b
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
Packit Service 103f6b
 * IN THE SOFTWARE.
Packit Service 103f6b
 */
Packit Service 103f6b
Packit Service 103f6b
#include <errno.h>
Packit Service 103f6b
#include <string.h>
Packit Service 103f6b
Packit Service 103f6b
#include "libkms-test.h"
Packit Service 103f6b
Packit Service 103f6b
static void kms_screen_probe(struct kms_screen *screen)
Packit Service 103f6b
{
Packit Service 103f6b
	struct kms_device *device = screen->device;
Packit Service 103f6b
	drmModeConnector *con;
Packit Service 103f6b
Packit Service 103f6b
	con = drmModeGetConnector(device->fd, screen->id);
Packit Service 103f6b
	if (!con)
Packit Service 103f6b
		return;
Packit Service 103f6b
Packit Service 103f6b
	screen->type = con->connector_type;
Packit Service 103f6b
Packit Service 103f6b
	if (con->connection == DRM_MODE_CONNECTED)
Packit Service 103f6b
		screen->connected = true;
Packit Service 103f6b
	else
Packit Service 103f6b
		screen->connected = false;
Packit Service 103f6b
Packit Service 103f6b
	if (con->modes)
Packit Service 103f6b
		memcpy(&screen->mode, &con->modes[0], sizeof(drmModeModeInfo));
Packit Service 103f6b
Packit Service 103f6b
	screen->width = screen->mode.hdisplay;
Packit Service 103f6b
	screen->height = screen->mode.vdisplay;
Packit Service 103f6b
Packit Service 103f6b
	drmModeFreeConnector(con);
Packit Service 103f6b
}
Packit Service 103f6b
Packit Service 103f6b
struct kms_screen *kms_screen_create(struct kms_device *device, uint32_t id)
Packit Service 103f6b
{
Packit Service 103f6b
	struct kms_screen *screen;
Packit Service 103f6b
Packit Service 103f6b
	screen = calloc(1, sizeof(*screen));
Packit Service 103f6b
	if (!screen)
Packit Service 103f6b
		return NULL;
Packit Service 103f6b
Packit Service 103f6b
	screen->device = device;
Packit Service 103f6b
	screen->id = id;
Packit Service 103f6b
Packit Service 103f6b
	kms_screen_probe(screen);
Packit Service 103f6b
Packit Service 103f6b
	return screen;
Packit Service 103f6b
}
Packit Service 103f6b
Packit Service 103f6b
void kms_screen_free(struct kms_screen *screen)
Packit Service 103f6b
{
Packit Service 103f6b
	if (screen)
Packit Service 103f6b
		free(screen->name);
Packit Service 103f6b
Packit Service 103f6b
	free(screen);
Packit Service 103f6b
}
Packit Service 103f6b
Packit Service 103f6b
int kms_screen_set(struct kms_screen *screen, struct kms_crtc *crtc,
Packit Service 103f6b
		   struct kms_framebuffer *fb)
Packit Service 103f6b
{
Packit Service 103f6b
	struct kms_device *device = screen->device;
Packit Service 103f6b
	int err;
Packit Service 103f6b
Packit Service 103f6b
	err = drmModeSetCrtc(device->fd, crtc->id, fb->id, 0, 0, &screen->id,
Packit Service 103f6b
			     1, &screen->mode);
Packit Service 103f6b
	if (err < 0)
Packit Service 103f6b
		return -errno;
Packit Service 103f6b
Packit Service 103f6b
	return 0;
Packit Service 103f6b
}