• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2014 NVIDIA 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 #include <errno.h>
25 #include <string.h>
26 
27 #include "libkms-test.h"
28 
kms_screen_probe(struct kms_screen * screen)29 static void kms_screen_probe(struct kms_screen *screen)
30 {
31 	struct kms_device *device = screen->device;
32 	drmModeConnector *con;
33 
34 	con = drmModeGetConnector(device->fd, screen->id);
35 	if (!con)
36 		return;
37 
38 	screen->type = con->connector_type;
39 
40 	if (con->connection == DRM_MODE_CONNECTED)
41 		screen->connected = true;
42 	else
43 		screen->connected = false;
44 
45 	memcpy(&screen->mode, &con->modes[0], sizeof(drmModeModeInfo));
46 	screen->width = screen->mode.hdisplay;
47 	screen->height = screen->mode.vdisplay;
48 
49 	drmModeFreeConnector(con);
50 }
51 
kms_screen_create(struct kms_device * device,uint32_t id)52 struct kms_screen *kms_screen_create(struct kms_device *device, uint32_t id)
53 {
54 	struct kms_screen *screen;
55 
56 	screen = calloc(1, sizeof(*screen));
57 	if (!screen)
58 		return NULL;
59 
60 	screen->device = device;
61 	screen->id = id;
62 
63 	kms_screen_probe(screen);
64 
65 	return screen;
66 }
67 
kms_screen_free(struct kms_screen * screen)68 void kms_screen_free(struct kms_screen *screen)
69 {
70 	if (screen)
71 		free(screen->name);
72 
73 	free(screen);
74 }
75 
kms_screen_set(struct kms_screen * screen,struct kms_crtc * crtc,struct kms_framebuffer * fb)76 int kms_screen_set(struct kms_screen *screen, struct kms_crtc *crtc,
77 		   struct kms_framebuffer *fb)
78 {
79 	struct kms_device *device = screen->device;
80 	int err;
81 
82 	err = drmModeSetCrtc(device->fd, crtc->id, fb->id, 0, 0, &screen->id,
83 			     1, &screen->mode);
84 	if (err < 0)
85 		return -errno;
86 
87 	return 0;
88 }
89