aboutsummaryrefslogtreecommitdiffstats
path: root/tests/kms
diff options
context:
space:
mode:
authorThierry Reding2015-12-09 11:37:42 -0600
committerEmil Velikov2015-12-18 11:44:05 -0600
commitc13c504ed2778fe5410d4883a7025abd75d0a6a1 (patch)
treef82520d45a23ff14a3f72b44225c5d71d3587e71 /tests/kms
parentca6c5f8c81e762b25c7b999fa5fd9d17fd67e4dc (diff)
downloadexternal-libgbm-c13c504ed2778fe5410d4883a7025abd75d0a6a1.tar.gz
external-libgbm-c13c504ed2778fe5410d4883a7025abd75d0a6a1.tar.xz
external-libgbm-c13c504ed2778fe5410d4883a7025abd75d0a6a1.zip
tests: Add libkms-test library
This library contains abstractions for KMS that help remove the need for a lot of boilerplate in KMS test programs. Signed-off-by: Thierry Reding <treding@nvidia.com> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Diffstat (limited to 'tests/kms')
-rw-r--r--tests/kms/Makefile.am20
-rw-r--r--tests/kms/libkms-test-crtc.c47
-rw-r--r--tests/kms/libkms-test-device.c218
-rw-r--r--tests/kms/libkms-test-framebuffer.c157
-rw-r--r--tests/kms/libkms-test-plane.c139
-rw-r--r--tests/kms/libkms-test-screen.c92
-rw-r--r--tests/kms/libkms-test.h120
7 files changed, 793 insertions, 0 deletions
diff --git a/tests/kms/Makefile.am b/tests/kms/Makefile.am
new file mode 100644
index 00000000..da464218
--- /dev/null
+++ b/tests/kms/Makefile.am
@@ -0,0 +1,20 @@
1AM_CPPFLAGS = \
2 -I$(top_srcdir)/include/drm \
3 -I$(top_srcdir)/tests \
4 -I$(top_srcdir)
5
6AM_CFLAGS = \
7 $(WARN_CFLAGS)
8
9noinst_LTLIBRARIES = libkms-test.la
10
11libkms_test_la_SOURCES = \
12 libkms-test.h \
13 libkms-test-crtc.c \
14 libkms-test-device.c \
15 libkms-test-framebuffer.c \
16 libkms-test-plane.c \
17 libkms-test-screen.c
18
19libkms_test_la_LIBADD = \
20 $(top_builddir)/libdrm.la
diff --git a/tests/kms/libkms-test-crtc.c b/tests/kms/libkms-test-crtc.c
new file mode 100644
index 00000000..3adb4903
--- /dev/null
+++ b/tests/kms/libkms-test-crtc.c
@@ -0,0 +1,47 @@
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#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28#include "libkms-test.h"
29
30struct kms_crtc *kms_crtc_create(struct kms_device *device, uint32_t id)
31{
32 struct kms_crtc *crtc;
33
34 crtc = calloc(1, sizeof(*crtc));
35 if (!crtc)
36 return NULL;
37
38 crtc->device = device;
39 crtc->id = id;
40
41 return crtc;
42}
43
44void kms_crtc_free(struct kms_crtc *crtc)
45{
46 free(crtc);
47}
diff --git a/tests/kms/libkms-test-device.c b/tests/kms/libkms-test-device.c
new file mode 100644
index 00000000..53c7349b
--- /dev/null
+++ b/tests/kms/libkms-test-device.c
@@ -0,0 +1,218 @@
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#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28#include <stdio.h>
29#include <string.h>
30#include <unistd.h>
31
32#include "util/common.h"
33#include "libkms-test.h"
34
35static const char *const connector_names[] = {
36 "Unknown",
37 "VGA",
38 "DVI-I",
39 "DVI-D",
40 "DVI-A",
41 "Composite",
42 "SVIDEO",
43 "LVDS",
44 "Component",
45 "9PinDIN",
46 "DisplayPort",
47 "HDMI-A",
48 "HDMI-B",
49 "TV",
50 "eDP",
51 "Virtual",
52 "DSI",
53};
54
55static void kms_device_probe_screens(struct kms_device *device)
56{
57 unsigned int counts[ARRAY_SIZE(connector_names)];
58 struct kms_screen *screen;
59 drmModeRes *res;
60 int i;
61
62 memset(counts, 0, sizeof(counts));
63
64 res = drmModeGetResources(device->fd);
65 if (!res)
66 return;
67
68 device->screens = calloc(res->count_connectors, sizeof(screen));
69 if (!device->screens)
70 return;
71
72 for (i = 0; i < res->count_connectors; i++) {
73 unsigned int *count;
74 const char *type;
75 int len;
76
77 screen = kms_screen_create(device, res->connectors[i]);
78 if (!screen)
79 continue;
80
81 /* assign a unique name to this screen */
82 type = connector_names[screen->type];
83 count = &counts[screen->type];
84
85 len = snprintf(NULL, 0, "%s-%u", type, *count);
86
87 screen->name = malloc(len + 1);
88 if (!screen->name) {
89 free(screen);
90 continue;
91 }
92
93 snprintf(screen->name, len + 1, "%s-%u", type, *count);
94 (*count)++;
95
96 device->screens[i] = screen;
97 device->num_screens++;
98 }
99
100 drmModeFreeResources(res);
101}
102
103static void kms_device_probe_crtcs(struct kms_device *device)
104{
105 struct kms_crtc *crtc;
106 drmModeRes *res;
107 int i;
108
109 res = drmModeGetResources(device->fd);
110 if (!res)
111 return;
112
113 device->crtcs = calloc(res->count_crtcs, sizeof(crtc));
114 if (!device->crtcs)
115 return;
116
117 for (i = 0; i < res->count_crtcs; i++) {
118 crtc = kms_crtc_create(device, res->crtcs[i]);
119 if (!crtc)
120 continue;
121
122 device->crtcs[i] = crtc;
123 device->num_crtcs++;
124 }
125
126 drmModeFreeResources(res);
127}
128
129static void kms_device_probe_planes(struct kms_device *device)
130{
131 struct kms_plane *plane;
132 drmModePlaneRes *res;
133 unsigned int i;
134
135 res = drmModeGetPlaneResources(device->fd);
136 if (!res)
137 return;
138
139 device->planes = calloc(res->count_planes, sizeof(plane));
140 if (!device->planes)
141 return;
142
143 for (i = 0; i < res->count_planes; i++) {
144 plane = kms_plane_create(device, res->planes[i]);
145 if (!plane)
146 continue;
147
148 device->planes[i] = plane;
149 device->num_planes++;
150 }
151
152 drmModeFreePlaneResources(res);
153}
154
155static void kms_device_probe(struct kms_device *device)
156{
157 kms_device_probe_screens(device);
158 kms_device_probe_crtcs(device);
159 kms_device_probe_planes(device);
160}
161
162struct kms_device *kms_device_open(int fd)
163{
164 struct kms_device *device;
165
166 device = calloc(1, sizeof(*device));
167 if (!device)
168 return NULL;
169
170 device->fd = fd;
171
172 kms_device_probe(device);
173
174 return device;
175}
176
177void kms_device_close(struct kms_device *device)
178{
179 unsigned int i;
180
181 for (i = 0; i < device->num_planes; i++)
182 kms_plane_free(device->planes[i]);
183
184 free(device->planes);
185
186 for (i = 0; i < device->num_crtcs; i++)
187 kms_crtc_free(device->crtcs[i]);
188
189 free(device->crtcs);
190
191 for (i = 0; i < device->num_screens; i++)
192 kms_screen_free(device->screens[i]);
193
194 free(device->screens);
195
196 if (device->fd >= 0)
197 close(device->fd);
198
199 free(device);
200}
201
202struct kms_plane *kms_device_find_plane_by_type(struct kms_device *device,
203 uint32_t type,
204 unsigned int index)
205{
206 unsigned int i;
207
208 for (i = 0; i < device->num_planes; i++) {
209 if (device->planes[i]->type == type) {
210 if (index == 0)
211 return device->planes[i];
212
213 index--;
214 }
215 }
216
217 return NULL;
218}
diff --git a/tests/kms/libkms-test-framebuffer.c b/tests/kms/libkms-test-framebuffer.c
new file mode 100644
index 00000000..c9e5ad3c
--- /dev/null
+++ b/tests/kms/libkms-test-framebuffer.c
@@ -0,0 +1,157 @@
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#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28#include <errno.h>
29#include <string.h>
30
31#include <sys/mman.h>
32
33#include <drm_fourcc.h>
34
35#include "xf86drm.h"
36
37#include "libkms-test.h"
38
39struct kms_framebuffer *kms_framebuffer_create(struct kms_device *device,
40 unsigned int width,
41 unsigned int height,
42 uint32_t format)
43{
44 uint32_t handles[4], pitches[4], offsets[4];
45 struct drm_mode_create_dumb args;
46 struct kms_framebuffer *fb;
47 int err;
48
49 fb = calloc(1, sizeof(*fb));
50 if (!fb)
51 return NULL;
52
53 fb->device = device;
54 fb->width = width;
55 fb->height = height;
56 fb->format = format;
57
58 memset(&args, 0, sizeof(args));
59 args.width = width;
60 args.height = height;
61
62 switch (format) {
63 case DRM_FORMAT_XRGB8888:
64 case DRM_FORMAT_XBGR8888:
65 case DRM_FORMAT_RGBA8888:
66 args.bpp = 32;
67 break;
68
69 default:
70 free(fb);
71 return NULL;
72 }
73
74 err = drmIoctl(device->fd, DRM_IOCTL_MODE_CREATE_DUMB, &args);
75 if (err < 0) {
76 free(fb);
77 return NULL;
78 }
79
80 fb->handle = args.handle;
81 fb->pitch = args.pitch;
82 fb->size = args.size;
83
84 handles[0] = fb->handle;
85 pitches[0] = fb->pitch;
86 offsets[0] = 0;
87
88 err = drmModeAddFB2(device->fd, width, height, format, handles,
89 pitches, offsets, &fb->id, 0);
90 if (err < 0) {
91 kms_framebuffer_free(fb);
92 return NULL;
93 }
94
95 return fb;
96}
97
98void kms_framebuffer_free(struct kms_framebuffer *fb)
99{
100 struct kms_device *device = fb->device;
101 struct drm_mode_destroy_dumb args;
102 int err;
103
104 if (fb->id) {
105 err = drmModeRmFB(device->fd, fb->id);
106 if (err < 0) {
107 /* not much we can do now */
108 }
109 }
110
111 memset(&args, 0, sizeof(args));
112 args.handle = fb->handle;
113
114 err = drmIoctl(device->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &args);
115 if (err < 0) {
116 /* not much we can do now */
117 }
118
119 free(fb);
120}
121
122int kms_framebuffer_map(struct kms_framebuffer *fb, void **ptrp)
123{
124 struct kms_device *device = fb->device;
125 struct drm_mode_map_dumb args;
126 void *ptr;
127 int err;
128
129 if (fb->ptr) {
130 *ptrp = fb->ptr;
131 return 0;
132 }
133
134 memset(&args, 0, sizeof(args));
135 args.handle = fb->handle;
136
137 err = drmIoctl(device->fd, DRM_IOCTL_MODE_MAP_DUMB, &args);
138 if (err < 0)
139 return -errno;
140
141 ptr = mmap(0, fb->size, PROT_READ | PROT_WRITE, MAP_SHARED,
142 device->fd, args.offset);
143 if (ptr == MAP_FAILED)
144 return -errno;
145
146 *ptrp = fb->ptr = ptr;
147
148 return 0;
149}
150
151void kms_framebuffer_unmap(struct kms_framebuffer *fb)
152{
153 if (fb->ptr) {
154 munmap(fb->ptr, fb->size);
155 fb->ptr = NULL;
156 }
157}
diff --git a/tests/kms/libkms-test-plane.c b/tests/kms/libkms-test-plane.c
new file mode 100644
index 00000000..8eb78af1
--- /dev/null
+++ b/tests/kms/libkms-test-plane.c
@@ -0,0 +1,139 @@
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#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28#include <errno.h>
29#include <string.h>
30
31#include "libkms-test.h"
32
33static int kms_plane_probe(struct kms_plane *plane)
34{
35 struct kms_device *device = plane->device;
36 drmModeObjectPropertiesPtr props;
37 drmModePlane *p;
38 unsigned int i;
39
40 p = drmModeGetPlane(device->fd, plane->id);
41 if (!p)
42 return -ENODEV;
43
44 /* TODO: allow dynamic assignment to CRTCs */
45 if (p->crtc_id == 0) {
46 for (i = 0; i < device->num_crtcs; i++) {
47 if (p->possible_crtcs & (1 << i)) {
48 p->crtc_id = device->crtcs[i]->id;
49 break;
50 }
51 }
52 }
53
54 for (i = 0; i < device->num_crtcs; i++) {
55 if (device->crtcs[i]->id == p->crtc_id) {
56 plane->crtc = device->crtcs[i];
57 break;
58 }
59 }
60
61 plane->formats = calloc(p->count_formats, sizeof(uint32_t));
62 if (!plane->formats)
63 return -ENOMEM;
64
65 for (i = 0; i < p->count_formats; i++)
66 plane->formats[i] = p->formats[i];
67
68 plane->num_formats = p->count_formats;
69
70 drmModeFreePlane(p);
71
72 props = drmModeObjectGetProperties(device->fd, plane->id,
73 DRM_MODE_OBJECT_PLANE);
74 if (!props)
75 return -ENODEV;
76
77 for (i = 0; i < props->count_props; i++) {
78 drmModePropertyPtr prop;
79
80 prop = drmModeGetProperty(device->fd, props->props[i]);
81 if (prop) {
82 if (strcmp(prop->name, "type") == 0)
83 plane->type = props->prop_values[i];
84
85 drmModeFreeProperty(prop);
86 }
87 }
88
89 drmModeFreeObjectProperties(props);
90
91 return 0;
92}
93
94struct kms_plane *kms_plane_create(struct kms_device *device, uint32_t id)
95{
96 struct kms_plane *plane;
97
98 plane = calloc(1, sizeof(*plane));
99 if (!plane)
100 return NULL;
101
102 plane->device = device;
103 plane->id = id;
104
105 kms_plane_probe(plane);
106
107 return plane;
108}
109
110void kms_plane_free(struct kms_plane *plane)
111{
112 free(plane);
113}
114
115int kms_plane_set(struct kms_plane *plane, struct kms_framebuffer *fb,
116 unsigned int x, unsigned int y)
117{
118 struct kms_device *device = plane->device;
119 int err;
120
121 err = drmModeSetPlane(device->fd, plane->id, plane->crtc->id, fb->id,
122 0, x, y, fb->width, fb->height, 0 << 16,
123 0 << 16, fb->width << 16, fb->height << 16);
124 if (err < 0)
125 return -errno;
126
127 return 0;
128}
129
130bool kms_plane_supports_format(struct kms_plane *plane, uint32_t format)
131{
132 unsigned int i;
133
134 for (i = 0; i < plane->num_formats; i++)
135 if (plane->formats[i] == format)
136 return true;
137
138 return false;
139}
diff --git a/tests/kms/libkms-test-screen.c b/tests/kms/libkms-test-screen.c
new file mode 100644
index 00000000..33690222
--- /dev/null
+++ b/tests/kms/libkms-test-screen.c
@@ -0,0 +1,92 @@
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#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28#include <errno.h>
29#include <string.h>
30
31#include "libkms-test.h"
32
33static void kms_screen_probe(struct kms_screen *screen)
34{
35 struct kms_device *device = screen->device;
36 drmModeConnector *con;
37
38 con = drmModeGetConnector(device->fd, screen->id);
39 if (!con)
40 return;
41
42 screen->type = con->connector_type;
43
44 if (con->connection == DRM_MODE_CONNECTED)
45 screen->connected = true;
46 else
47 screen->connected = false;
48
49 memcpy(&screen->mode, &con->modes[0], sizeof(drmModeModeInfo));
50 screen->width = screen->mode.hdisplay;
51 screen->height = screen->mode.vdisplay;
52
53 drmModeFreeConnector(con);
54}
55
56struct kms_screen *kms_screen_create(struct kms_device *device, uint32_t id)
57{
58 struct kms_screen *screen;
59
60 screen = calloc(1, sizeof(*screen));
61 if (!screen)
62 return NULL;
63
64 screen->device = device;
65 screen->id = id;
66
67 kms_screen_probe(screen);
68
69 return screen;
70}
71
72void kms_screen_free(struct kms_screen *screen)
73{
74 if (screen)
75 free(screen->name);
76
77 free(screen);
78}
79
80int kms_screen_set(struct kms_screen *screen, struct kms_crtc *crtc,
81 struct kms_framebuffer *fb)
82{
83 struct kms_device *device = screen->device;
84 int err;
85
86 err = drmModeSetCrtc(device->fd, crtc->id, fb->id, 0, 0, &screen->id,
87 1, &screen->mode);
88 if (err < 0)
89 return -errno;
90
91 return 0;
92}
diff --git a/tests/kms/libkms-test.h b/tests/kms/libkms-test.h
new file mode 100644
index 00000000..7b1d02e9
--- /dev/null
+++ b/tests/kms/libkms-test.h
@@ -0,0 +1,120 @@
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#ifndef LIBKMS_TEST_H
25#define LIBKMS_TEST_H
26
27#include <stdbool.h>
28#include <stdint.h>
29#include <stdlib.h>
30
31#include <xf86drmMode.h>
32
33struct kms_device {
34 int fd;
35
36 struct kms_screen **screens;
37 unsigned int num_screens;
38
39 struct kms_crtc **crtcs;
40 unsigned int num_crtcs;
41
42 struct kms_plane **planes;
43 unsigned int num_planes;
44};
45
46struct kms_device *kms_device_open(int fd);
47void kms_device_close(struct kms_device *device);
48
49struct kms_plane *kms_device_find_plane_by_type(struct kms_device *device,
50 uint32_t type,
51 unsigned int index);
52
53struct kms_crtc {
54 struct kms_device *device;
55 uint32_t id;
56};
57
58struct kms_crtc *kms_crtc_create(struct kms_device *device, uint32_t id);
59void kms_crtc_free(struct kms_crtc *crtc);
60
61struct kms_framebuffer {
62 struct kms_device *device;
63
64 unsigned int width;
65 unsigned int height;
66 unsigned int pitch;
67 uint32_t format;
68 size_t size;
69
70 uint32_t handle;
71 uint32_t id;
72
73 void *ptr;
74};
75
76struct kms_framebuffer *kms_framebuffer_create(struct kms_device *device,
77 unsigned int width,
78 unsigned int height,
79 uint32_t format);
80void kms_framebuffer_free(struct kms_framebuffer *fb);
81int kms_framebuffer_map(struct kms_framebuffer *fb, void **ptrp);
82void kms_framebuffer_unmap(struct kms_framebuffer *fb);
83
84struct kms_screen {
85 struct kms_device *device;
86 bool connected;
87 uint32_t type;
88 uint32_t id;
89
90 unsigned int width;
91 unsigned int height;
92 char *name;
93
94 drmModeModeInfo mode;
95};
96
97struct kms_screen *kms_screen_create(struct kms_device *device, uint32_t id);
98void kms_screen_free(struct kms_screen *screen);
99
100int kms_screen_set(struct kms_screen *screen, struct kms_crtc *crtc,
101 struct kms_framebuffer *fb);
102
103struct kms_plane {
104 struct kms_device *device;
105 struct kms_crtc *crtc;
106 unsigned int type;
107 uint32_t id;
108
109 uint32_t *formats;
110 unsigned int num_formats;
111};
112
113struct kms_plane *kms_plane_create(struct kms_device *device, uint32_t id);
114void kms_plane_free(struct kms_plane *plane);
115
116int kms_plane_set(struct kms_plane *plane, struct kms_framebuffer *fb,
117 unsigned int x, unsigned int y);
118bool kms_plane_supports_format(struct kms_plane *plane, uint32_t format);
119
120#endif