aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Clark2012-02-25 11:00:29 -0600
committerRob Clark2012-03-10 14:42:52 -0600
commit27386b03f0cf5baecceb768e7ca2474f8a712371 (patch)
treef536c6b42f4a42c243692b76515cb2a2c2e7c829
downloadexternal-libgbm-27386b03f0cf5baecceb768e7ca2474f8a712371.tar.gz
external-libgbm-27386b03f0cf5baecceb768e7ca2474f8a712371.tar.xz
external-libgbm-27386b03f0cf5baecceb768e7ca2474f8a712371.zip
initial commit
-rw-r--r--.gitignore29
-rw-r--r--Makefile.am23
-rw-r--r--README37
-rwxr-xr-xautogen.sh12
-rw-r--r--backend.c93
-rw-r--r--backend.h36
-rw-r--r--backend_example.c135
-rw-r--r--common.c88
-rw-r--r--common.h42
-rw-r--r--common_drm.h49
-rw-r--r--configure.ac42
-rw-r--r--gbm.c190
-rw-r--r--gbm.h109
-rw-r--r--gbm.pc.in10
-rw-r--r--gbmint.h82
15 files changed, 977 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..3b7bfb99
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,29 @@
1aclocal.m4
2autom4te.cache
3Makefile.in
4Makefile
5.deps
6.libs
7*.o
8*.lo
9*.la
10libtool
11*.pc
12config.log
13config.status
14config.guess
15config.h
16config.h.in
17config.sub
18config
19configure
20install-sh
21ltmain.sh
22missing
23stamp-h1
24depcomp
25.cproject
26.project
27.settings
28dri2test
29dri2videotest
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 00000000..740ea6eb
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,23 @@
1lib_LTLIBRARIES = libgbm.la
2
3libgbm_la_SOURCES = \
4 gbm.c \
5 backend.c \
6 common.c
7
8libgbm_la_LIBADD = \
9 @UDEV_LIBS@
10
11libgbm_la_CFLAGS = \
12 @UDEV_CFLAGS@ \
13 -D_OS_UNIX=1 \
14 -DMODULEDIR='"$(exec_prefix)/lib/gbm"'
15
16extdir = $(includedir)/gbm
17ext_HEADERS = \
18 gbm.h \
19 gbmint.h \
20 common_drm.h
21
22pkgconfigdir = $(libdir)/pkgconfig
23pkgconfig_DATA = gbm.pc
diff --git a/README b/README
new file mode 100644
index 00000000..6ba18ef2
--- /dev/null
+++ b/README
@@ -0,0 +1,37 @@
1This is the gbm frontend used by (for example) weston compositor to
2load the GLES stack, and retrieve the backing buffer objects behind
3an eglImage (created with EGL_WAYLAND_BUFFER_WL), etc.
4
5The frontend is really just a backend loader and shim. The backend
6library must be provided by the GLES implementation.
7
8To get wayland up and running on your GLES stack:
9 1) implement gbm backend
10 2) implement EGL_WL_bind_wayland_display extension (including
11 EGL_WAYLAND_BUFFER_WL eglCreateImageKHR target
12 for compositor-drm it looks like we also need
13 EGL_KHR_surfaceless_gles2 extension..
14----
15<robclark> hmm, I don't suppose there is any extension description for EGL_KHR_surfaceless_gles2 ?
16<pq> robclark, it should simply mean you can eglMakeCurrent with NULL surface, but a real context.
17----
18 3) implement wayland-egl (must provide wayland-egl.pc)
19 4) ???
20 5) PROFIT!!
21
22need this in your eglext.h:
23
24-------------------
25#ifndef EGL_WL_bind_wayland_display
26#define EGL_WL_bind_wayland_display 1
27
28#define EGL_WAYLAND_BUFFER_WL 0x31D5 /* eglCreateImageKHR target */
29struct wl_display;
30#ifdef EGL_EGLEXT_PROTOTYPES
31EGLAPI EGLBoolean EGLAPIENTRY eglBindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display);
32EGLAPI EGLBoolean EGLAPIENTRY eglUnbindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display);
33#endif
34typedef EGLBoolean (EGLAPIENTRYP PFNEGLBINDWAYLANDDISPLAYWL) (EGLDisplay dpy, struct wl_display *display);
35typedef EGLBoolean (EGLAPIENTRYP PFNEGLUNBINDWAYLANDDISPLAYWL) (EGLDisplay dpy, struct wl_display *display);
36#endif
37-------------------
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 00000000..904cd674
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,12 @@
1#! /bin/sh
2
3srcdir=`dirname $0`
4test -z "$srcdir" && srcdir=.
5
6ORIGDIR=`pwd`
7cd $srcdir
8
9autoreconf -v --install || exit 1
10cd $ORIGDIR || exit $?
11
12$srcdir/configure --enable-maintainer-mode "$@"
diff --git a/backend.c b/backend.c
new file mode 100644
index 00000000..29d31517
--- /dev/null
+++ b/backend.c
@@ -0,0 +1,93 @@
1/*
2 * Copyright © 2011 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,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Benjamin Franzke <benjaminfranzke@googlemail.com>
26 */
27
28#include <stdio.h>
29#include <stddef.h>
30#include <stdlib.h>
31#include <string.h>
32#include <limits.h>
33#include <dlfcn.h>
34
35#include "backend.h"
36
37#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
38
39/* a more clever scheme would be to discover backends in a certain
40 * directory..
41 */
42static const char *backends[] = {
43 "gbm_dri.so",
44 "gbm_gallium_drm.so",
45 "gbm_pvr.so",
46};
47
48static const void *
49load_backend(const char *name)
50{
51 char path[PATH_MAX];
52 void *module;
53 const char *entrypoint = "gbm_backend";
54
55 if (name[0] != '/')
56 snprintf(path, sizeof path, MODULEDIR "/%s", name);
57 else
58 snprintf(path, sizeof path, "%s", name);
59
60 module = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
61 if (!module) {
62 fprintf(stderr, "failed to load module: %s\n", dlerror());
63 return NULL;
64 }
65
66 return dlsym(module, entrypoint);
67}
68
69struct gbm_device *
70_gbm_create_device(int fd)
71{
72 const struct gbm_backend *backend = NULL;
73 struct gbm_device *dev = NULL;
74 int i;
75 const char *b;
76
77 b = getenv("GBM_BACKEND");
78 if (b)
79 backend = load_backend(b);
80
81 if (backend)
82 dev = backend->create_device(fd);
83
84 for (i = 0; i < ARRAY_SIZE(backends) && dev == NULL; ++i) {
85 backend = load_backend(backends[i]);
86 if (backend == NULL)
87 continue;
88 fprintf(stderr, "loaded module: %s\n", backends[i]);
89 dev = backend->create_device(fd);
90 }
91
92 return dev;
93}
diff --git a/backend.h b/backend.h
new file mode 100644
index 00000000..4a643750
--- /dev/null
+++ b/backend.h
@@ -0,0 +1,36 @@
1/*
2 * Copyright © 2011 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,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Benjamin Franzke <benjaminfranzke@googlemail.com>
26 */
27
28#ifndef MODULE_H_
29#define MODULE_H_
30
31#include "gbmint.h"
32
33struct gbm_device *
34_gbm_create_device(int fd);
35
36#endif
diff --git a/backend_example.c b/backend_example.c
new file mode 100644
index 00000000..3854d6eb
--- /dev/null
+++ b/backend_example.c
@@ -0,0 +1,135 @@
1/*
2 * Copyright (C) 2012 Texas Instruments
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,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Rob Clark <rob.clark@linaro.org>
26 */
27
28/* This is an example/skeletal backend implementation.. this file isn't
29 * actually built as part of libgbm, but just intended to be a template
30 * to help in creating a new gbm backend
31 */
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <stddef.h>
36#include <stdint.h>
37#include <string.h>
38#include <limits.h>
39
40#include <sys/types.h>
41#include <unistd.h>
42#include <dlfcn.h>
43
44#include "gbmint.h"
45#include "common_drm.h"
46
47struct gbm_example_device {
48 struct gbm_drm_device base;
49 /* add whatever you need here */
50};
51
52struct gbm_example_bo {
53 struct gbm_drm_bo base;
54 /* add whatever you need here */
55};
56
57
58static int
59gles_init(struct gbm_example_device *dev)
60{
61 /* this should open/initialize the GLES stack.. for a DRM driver
62 * at least, dev->base.base.fd will have the already opened device
63 */
64 return 0;
65}
66
67static int
68gbm_example_is_format_supported(struct gbm_device *gbm,
69 enum gbm_bo_format format, uint32_t usage)
70{
71 return 0;
72}
73
74static void
75gbm_example_bo_destroy(struct gbm_bo *_bo)
76{
77}
78
79static struct gbm_bo *
80gbm_example_bo_create_from_egl_image(struct gbm_device *gbm, void *egl_dpy,
81 void *egl_img, uint32_t width, uint32_t height, uint32_t usage)
82{
83 /* eglimg is created w/ (see weston_buffer_attach()):
84 *
85 * struct wl_buffer *buffer = ...;
86 * eglCreateImageKHR(display, NULL, EGL_WAYLAND_BUFFER_WL, buffer, NULL);
87 */
88
89 return NULL;
90}
91
92static struct gbm_bo *
93gbm_example_bo_create(struct gbm_device *gbm, uint32_t width, uint32_t height,
94 enum gbm_bo_format format, uint32_t usage)
95{
96 return NULL;
97}
98
99static void
100gbm_example_destroy(struct gbm_device *gbm)
101{
102}
103
104static struct gbm_device *
105example_device_create(int fd)
106{
107 struct gbm_example_device *dev;
108 int ret;
109
110 dev = calloc(1, sizeof *dev);
111
112 dev->base.base.fd = fd;
113 dev->base.base.bo_create = gbm_example_bo_create;
114 dev->base.base.bo_create_from_egl_image = gbm_example_bo_create_from_egl_image;
115 dev->base.base.is_format_supported = gbm_example_is_format_supported;
116 dev->base.base.bo_destroy = gbm_example_bo_destroy;
117 dev->base.base.destroy = gbm_example_destroy;
118
119 dev->base.type = GBM_DRM_DRIVER_TYPE_CUSTOM;
120 dev->base.base.name = "example";
121
122 ret = gles_init(dev);
123 if (ret) {
124 free(dev);
125 return NULL;
126 }
127
128 return &dev->base.base;
129}
130
131/* backend loader looks for symbol "gbm_backend" */
132struct gbm_backend gbm_backend = {
133 .backend_name = "example",
134 .create_device = example_device_create,
135};
diff --git a/common.c b/common.c
new file mode 100644
index 00000000..f02162df
--- /dev/null
+++ b/common.c
@@ -0,0 +1,88 @@
1/*
2 * Copyright © 2011 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,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Benjamin Franzke <benjaminfranzke@googlemail.com>
26 */
27
28#include <stdio.h>
29#include <string.h>
30
31#include <libudev.h>
32#include <sys/types.h>
33#include <sys/stat.h>
34#include <unistd.h>
35
36#include "common.h"
37#include "gbmint.h"
38
39GBM_EXPORT struct udev_device *
40_gbm_udev_device_new_from_fd(struct udev *udev, int fd)
41{
42 struct udev_device *device;
43 struct stat buf;
44
45 if (fstat(fd, &buf) < 0) {
46 fprintf(stderr, "gbm: failed to stat fd %d", fd);
47 return NULL;
48 }
49
50 device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev);
51 if (device == NULL) {
52 fprintf(stderr,
53 "gbm: could not create udev device for fd %d", fd);
54 return NULL;
55 }
56
57 return device;
58}
59
60GBM_EXPORT char *
61_gbm_fd_get_device_name(int fd)
62{
63 struct udev *udev;
64 struct udev_device *device;
65 const char *const_device_name;
66 char *device_name = NULL;
67
68 udev = udev_new();
69 device = _gbm_udev_device_new_from_fd(udev, fd);
70 if (device == NULL)
71 return NULL;
72
73 const_device_name = udev_device_get_devnode(device);
74 if (!const_device_name)
75 goto out;
76 device_name = strdup(const_device_name);
77
78out:
79 udev_device_unref(device);
80 udev_unref(udev);
81
82 return device_name;
83}
84
85GBM_EXPORT void
86_gbm_log(const char *fmt_str, ...)
87{
88}
diff --git a/common.h b/common.h
new file mode 100644
index 00000000..1fcdfcac
--- /dev/null
+++ b/common.h
@@ -0,0 +1,42 @@
1/*
2 * Copyright © 2011 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,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Benjamin Franzke <benjaminfranzke@googlemail.com>
26 */
27
28#ifndef _COMMON_H_
29#define _COMMON_H_
30
31#include <libudev.h>
32
33struct udev_device *
34_gbm_udev_device_new_from_fd(struct udev *udev, int fd);
35
36char *
37_gbm_fd_get_device_name(int fd);
38
39void
40_gbm_log(const char *fmt_str, ...);
41
42#endif
diff --git a/common_drm.h b/common_drm.h
new file mode 100644
index 00000000..6b2f74d0
--- /dev/null
+++ b/common_drm.h
@@ -0,0 +1,49 @@
1/*
2 * Copyright © 2011 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,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Benjamin Franzke <benjaminfranzke@googlemail.com>
26 */
27
28#ifndef _COMMON_DRM_H_
29#define _COMMON_DRM_H_
30
31#include "gbmint.h"
32
33enum gbm_drm_driver_type {
34 GBM_DRM_DRIVER_TYPE_DRI,
35 GBM_DRM_DRIVER_TYPE_GALLIUM,
36 GBM_DRM_DRIVER_TYPE_CUSTOM, /* catch-all for non-mesa drivers */
37};
38
39struct gbm_drm_device {
40 struct gbm_device base;
41 enum gbm_drm_driver_type type;
42 char *driver_name;
43};
44
45struct gbm_drm_bo {
46 struct gbm_bo base;
47};
48
49#endif
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 00000000..27390922
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,42 @@
1#
2# Copyright 2005 Red Hat, Inc.
3#
4# Permission to use, copy, modify, distribute, and sell this software and its
5# documentation for any purpose is hereby granted without fee, provided that
6# the above copyright notice appear in all copies and that both that
7# copyright notice and this permission notice appear in supporting
8# documentation, and that the name of Red Hat not be used in
9# advertising or publicity pertaining to distribution of the software without
10# specific, written prior permission. Red Hat makes no
11# representations about the suitability of this software for any purpose. It
12# is provided "as is" without express or implied warranty.
13#
14# RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16# EVENT SHALL RED HAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20# PERFORMANCE OF THIS SOFTWARE.
21#
22
23# Initialize Autoconf
24AC_PREREQ([2.60])
25AC_INIT([libgbm], [1.0.0],
26 [https://bugs.freedesktop.org/enter_bug.cgi?product=wayland], [libgbm])
27AC_CONFIG_SRCDIR([Makefile.am])
28AC_CONFIG_HEADERS([config.h])
29
30# Initialize Automake
31AM_INIT_AUTOMAKE([foreign dist-bzip2])
32AM_MAINTAINER_MODE
33
34# Initialize libtool
35AC_PROG_LIBTOOL
36
37# Obtain compiler/linker options for dependencies
38PKG_CHECK_MODULES(UDEV, udev)
39PKG_CHECK_MODULES(DRM, libdrm)
40
41AC_CONFIG_FILES([Makefile gbm.pc])
42AC_OUTPUT
diff --git a/gbm.c b/gbm.c
new file mode 100644
index 00000000..8440b2c6
--- /dev/null
+++ b/gbm.c
@@ -0,0 +1,190 @@
1/*
2 * Copyright © 2011 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,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Benjamin Franzke <benjaminfranzke@googlemail.com>
26 */
27
28#define _BSD_SOURCE
29
30#include <stddef.h>
31#include <stdio.h>
32#include <stdlib.h>
33#include <string.h>
34#include <stdint.h>
35
36#include <sys/types.h>
37#include <sys/stat.h>
38#include <unistd.h>
39
40#include "gbm.h"
41#include "gbmint.h"
42#include "common.h"
43#include "backend.h"
44
45#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
46
47struct gbm_device *devices[16];
48
49static int device_num = 0;
50
51GBM_EXPORT int
52gbm_device_get_fd(struct gbm_device *gbm)
53{
54 return gbm->fd;
55}
56
57/* FIXME: maybe superfluous, use udev subclass from the fd? */
58GBM_EXPORT const char *
59gbm_device_get_backend_name(struct gbm_device *gbm)
60{
61 return gbm->name;
62}
63
64int
65gbm_device_is_format_supported(struct gbm_device *gbm,
66 enum gbm_bo_format format,
67 uint32_t usage)
68{
69 return gbm->is_format_supported(gbm, format, usage);
70}
71
72GBM_EXPORT void
73gbm_device_destroy(struct gbm_device *gbm)
74{
75 gbm->refcount--;
76 if (gbm->refcount == 0)
77 gbm->destroy(gbm);
78}
79
80GBM_EXPORT struct gbm_device *
81_gbm_mesa_get_device(int fd)
82{
83 struct gbm_device *gbm = NULL;
84 struct stat buf;
85 dev_t dev;
86 int i;
87
88 if (fd < 0 || fstat(fd, &buf) < 0 || !S_ISCHR(buf.st_mode)) {
89 fprintf(stderr, "_gbm_mesa_get_device: invalid fd: %d\n", fd);
90 return NULL;
91 }
92
93 for (i = 0; i < device_num; ++i) {
94 dev = devices[i]->stat.st_rdev;
95 if (major(dev) == major(buf.st_rdev) &&
96 minor(dev) == minor(buf.st_rdev)) {
97 gbm = devices[i];
98 gbm->refcount++;
99 break;
100 }
101 }
102
103 return gbm;
104}
105
106GBM_EXPORT struct gbm_device *
107gbm_create_device(int fd)
108{
109 struct gbm_device *gbm = NULL;
110 struct stat buf;
111
112 if (fd < 0 || fstat(fd, &buf) < 0 || !S_ISCHR(buf.st_mode)) {
113 fprintf(stderr, "gbm_create_device: invalid fd: %d\n", fd);
114 return NULL;
115 }
116
117 if (device_num == 0)
118 memset(devices, 0, sizeof devices);
119
120 gbm = _gbm_create_device(fd);
121 if (gbm == NULL)
122 return NULL;
123
124 gbm->dummy = gbm_create_device;
125 gbm->stat = buf;
126 gbm->refcount = 1;
127
128 if (device_num < ARRAY_SIZE(devices)-1)
129 devices[device_num++] = gbm;
130
131 return gbm;
132}
133
134GBM_EXPORT unsigned int
135gbm_bo_get_width(struct gbm_bo *bo)
136{
137 return bo->width;
138}
139
140GBM_EXPORT unsigned int
141gbm_bo_get_height(struct gbm_bo *bo)
142{
143 return bo->height;
144}
145
146GBM_EXPORT uint32_t
147gbm_bo_get_pitch(struct gbm_bo *bo)
148{
149 return bo->pitch;
150}
151
152GBM_EXPORT union gbm_bo_handle
153gbm_bo_get_handle(struct gbm_bo *bo)
154{
155 return bo->handle;
156}
157
158GBM_EXPORT void
159gbm_bo_destroy(struct gbm_bo *bo)
160{
161 bo->gbm->bo_destroy(bo);
162}
163
164GBM_EXPORT struct gbm_bo *
165gbm_bo_create(struct gbm_device *gbm,
166 uint32_t width, uint32_t height,
167 enum gbm_bo_format format, uint32_t usage)
168{
169 if (width == 0 || height == 0)
170 return NULL;
171
172 if (usage & GBM_BO_USE_CURSOR_64X64 &&
173 (width != 64 || height != 64))
174 return NULL;
175
176 return gbm->bo_create(gbm, width, height, format, usage);
177}
178
179GBM_EXPORT struct gbm_bo *
180gbm_bo_create_from_egl_image(struct gbm_device *gbm,
181 void *egl_dpy, void *egl_image,
182 uint32_t width, uint32_t height,
183 uint32_t usage)
184{
185 if (width == 0 || height == 0)
186 return NULL;
187
188 return gbm->bo_create_from_egl_image(gbm, egl_dpy, egl_image,
189 width, height, usage);
190}
diff --git a/gbm.h b/gbm.h
new file mode 100644
index 00000000..05d2292d
--- /dev/null
+++ b/gbm.h
@@ -0,0 +1,109 @@
1/*
2 * Copyright © 2011 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,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Benjamin Franzke <benjaminfranzke@googlemail.com>
26 */
27
28#ifndef _GBM_H_
29#define _GBM_H_
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35
36#define __GBM__ 1
37
38#include <stdint.h>
39
40struct gbm_device;
41struct gbm_bo;
42
43union gbm_bo_handle {
44 void *ptr;
45 int32_t s32;
46 uint32_t u32;
47 int64_t s64;
48 uint64_t u64;
49};
50
51enum gbm_bo_format {
52 GBM_BO_FORMAT_XRGB8888,
53 GBM_BO_FORMAT_ARGB8888,
54};
55
56enum gbm_bo_flags {
57 GBM_BO_USE_SCANOUT = (1 << 0),
58 GBM_BO_USE_CURSOR_64X64 = (1 << 1),
59 GBM_BO_USE_RENDERING = (1 << 2),
60};
61
62int
63gbm_device_get_fd(struct gbm_device *gbm);
64
65const char *
66gbm_device_get_backend_name(struct gbm_device *gbm);
67
68int
69gbm_device_is_format_supported(struct gbm_device *gbm,
70 enum gbm_bo_format format,
71 uint32_t usage);
72
73void
74gbm_device_destroy(struct gbm_device *gbm);
75
76struct gbm_device *
77gbm_create_device(int fd);
78
79struct gbm_bo *
80gbm_bo_create(struct gbm_device *gbm,
81 uint32_t width, uint32_t height,
82 enum gbm_bo_format format, uint32_t flags);
83
84struct gbm_bo *
85gbm_bo_create_from_egl_image(struct gbm_device *gbm,
86 void *egl_dpy, void *egl_img,
87 uint32_t width, uint32_t height,
88 uint32_t usage);
89
90uint32_t
91gbm_bo_get_width(struct gbm_bo *bo);
92
93uint32_t
94gbm_bo_get_height(struct gbm_bo *bo);
95
96uint32_t
97gbm_bo_get_pitch(struct gbm_bo *bo);
98
99union gbm_bo_handle
100gbm_bo_get_handle(struct gbm_bo *bo);
101
102void
103gbm_bo_destroy(struct gbm_bo *bo);
104
105#ifdef __cplusplus
106}
107#endif
108
109#endif
diff --git a/gbm.pc.in b/gbm.pc.in
new file mode 100644
index 00000000..12348412
--- /dev/null
+++ b/gbm.pc.in
@@ -0,0 +1,10 @@
1prefix=@prefix@
2exec_prefix=@exec_prefix@
3libdir=@libdir@
4includedir=@includedir@
5
6Name: gbm
7Description: gbm library
8Version: @PACKAGE_VERSION@
9Libs: -L${libdir} -lgbm
10Cflags: -I${includedir}/gbm
diff --git a/gbmint.h b/gbmint.h
new file mode 100644
index 00000000..fb8db804
--- /dev/null
+++ b/gbmint.h
@@ -0,0 +1,82 @@
1/*
2 * Copyright © 2011 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,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Benjamin Franzke <benjaminfranzke@googlemail.com>
26 */
27
28#ifndef INTERNAL_H_
29#define INTERNAL_H_
30
31#include "gbm.h"
32#include <sys/stat.h>
33
34/* GCC visibility */
35#if defined(__GNUC__) && __GNUC__ >= 4
36#define GBM_EXPORT __attribute__ ((visibility("default")))
37#else
38#define GBM_EXPORT
39#endif
40
41struct gbm_device {
42 /* Hack to make a gbm_device detectable by its first element. */
43 struct gbm_device *(*dummy)(int);
44
45 int fd;
46 const char *name;
47 unsigned int refcount;
48 struct stat stat;
49
50 void (*destroy)(struct gbm_device *gbm);
51 int (*is_format_supported)(struct gbm_device *gbm,
52 enum gbm_bo_format format,
53 uint32_t usage);
54
55 struct gbm_bo *(*bo_create)(struct gbm_device *gbm,
56 uint32_t width, uint32_t height,
57 enum gbm_bo_format format,
58 uint32_t usage);
59 struct gbm_bo *(*bo_create_from_egl_image)(struct gbm_device *gbm,
60 void *egl_dpy, void *egl_img,
61 uint32_t width, uint32_t height,
62 uint32_t usage);
63 void (*bo_destroy)(struct gbm_bo *bo);
64};
65
66struct gbm_bo {
67 struct gbm_device *gbm;
68 uint32_t width;
69 uint32_t height;
70 uint32_t pitch;
71 union gbm_bo_handle handle;
72};
73
74struct gbm_backend {
75 const char *backend_name;
76 struct gbm_device *(*create_device)(int fd);
77};
78
79GBM_EXPORT struct gbm_device *
80_gbm_mesa_get_device(int fd);
81
82#endif