diff options
Diffstat (limited to 'src/gbm/main')
-rw-r--r-- | src/gbm/main/Makefile | 90 | ||||
-rw-r--r-- | src/gbm/main/backend.c | 128 | ||||
-rw-r--r-- | src/gbm/main/backend.h | 36 | ||||
-rw-r--r-- | src/gbm/main/common.c | 88 | ||||
-rw-r--r-- | src/gbm/main/common.h | 42 | ||||
-rw-r--r-- | src/gbm/main/common_drm.h | 48 | ||||
-rw-r--r-- | src/gbm/main/gbm.c | 190 | ||||
-rw-r--r-- | src/gbm/main/gbm.h | 109 | ||||
-rw-r--r-- | src/gbm/main/gbm.pc.in | 12 | ||||
-rw-r--r-- | src/gbm/main/gbmint.h | 82 |
10 files changed, 825 insertions, 0 deletions
diff --git a/src/gbm/main/Makefile b/src/gbm/main/Makefile new file mode 100644 index 00000000000..5130b9b5df2 --- /dev/null +++ b/src/gbm/main/Makefile @@ -0,0 +1,90 @@ +# src/gbm/main/Makefile + +TOP = ../../.. +include $(TOP)/configs/current + +INCLUDE_DIRS = -I$(TOP)/include + +HEADERS = \ + common.h \ + backend.h \ + gbmint.h \ + gbm.h + +SOURCES = \ + gbm.c \ + backend.c \ + common.c + +OBJECTS = $(SOURCES:.c=.o) + +# use dl*() to load drivers +LOCAL_CFLAGS = $(LIBUDEV_CFLAGS) $(DLOPEN_CFLAGS) \ + -D_OS_UNIX=1 -DMODULEDIR='"$(GBM_BACKEND_INSTALL_DIR)"' +LOCAL_LIBS = + +# Builtin backends +ifeq ($(filter dri, $(GBM_BACKEND_DIRS)),dri) +LOCAL_LIBS += $(TOP)/src/gbm/backends/dri/libgbm_dri.a +endif + +.c.o: + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $(LOCAL_CFLAGS) $< -o $@ + + +default: depend library + + +library: $(TOP)/$(LIB_DIR)/libgbm.so + +$(TOP)/$(LIB_DIR)/libgbm.so: $(OBJECTS) $(LOCAL_LIBS) + $(MKLIB) -o gbm -linker '$(CC)' -ldflags '$(LDFLAGS)' \ + -major 1 -minor 0 \ + -install $(TOP)/$(LIB_DIR) $(MKLIB_OPTIONS) \ + -L$(TOP)/$(LIB_DIR) $(GBM_LIB_DEPS) \ + $(OBJECTS) $(LOCAL_LIBS) + +install-headers: + $(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/ + $(INSTALL) -m 644 $(TOP)/src/gbm/main/gbm.h \ + $(DESTDIR)$(INSTALL_INC_DIR) + + +PKG_CONFIG_DIR = $(INSTALL_LIB_DIR)/pkgconfig + +gbm_pcedit = sed \ + -e 's,@INSTALL_DIR@,$(INSTALL_DIR),' \ + -e 's,@INSTALL_LIB_DIR@,$(INSTALL_LIB_DIR),' \ + -e 's,@INSTALL_INC_DIR@,$(INSTALL_INC_DIR),' \ + -e 's,@VERSION@,0.0.0,' \ + -e 's,@GBM_PC_REQ_PRIV@,$(GBM_PC_REQ_PRIV),' \ + -e 's,@GBM_PC_LIB_PRIV@,$(GBM_PC_LIB_PRIV),' \ + -e 's,@GBM_PC_CFLAGS@,$(GBM_PC_CFLAGS),' \ + -e 's,@GBM_LIB@,$(GBM_LIB),' + +gbm.pc: gbm.pc.in + $(gbm_pcedit) $< > $@ + +install: default install-headers gbm.pc + $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR) + $(MINSTALL) $(TOP)/$(LIB_DIR)/libgbm.so* \ + $(DESTDIR)$(INSTALL_LIB_DIR) + $(INSTALL) -d $(DESTDIR)$(PKG_CONFIG_DIR) + $(INSTALL) -m 644 gbm.pc $(DESTDIR)$(PKG_CONFIG_DIR) + +clean: + -rm -f *.o + -rm -f depend depend.bak + -rm -f gbm.pc + + +depend: $(SOURCES) $(HEADERS) + @ echo "running $(MKDEP)" + @ rm -f depend + @ touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(DEFINES) $(INCLUDE_DIRS) \ + $(SOURCES) $(HEADERS) > /dev/null 2>/dev/null + + +-include depend +# DO NOT DELETE diff --git a/src/gbm/main/backend.c b/src/gbm/main/backend.c new file mode 100644 index 00000000000..aceb6621f96 --- /dev/null +++ b/src/gbm/main/backend.c @@ -0,0 +1,128 @@ +/* + * Copyright © 2011 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. + * + * Authors: + * Benjamin Franzke <[email protected]> + */ + +#include <stdio.h> +#include <stddef.h> +#include <stdlib.h> +#include <string.h> +#include <limits.h> +#include <dlfcn.h> + +#include "backend.h" + +#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) + +extern const struct gbm_backend gbm_dri_backend; + +struct backend_desc { + const char *name; + const struct gbm_backend *builtin; +}; + +static const struct backend_desc backends[] = { + { "gbm_dri.so", &gbm_dri_backend }, + { "gbm_gallium_drm.so", NULL }, +}; + +static const void * +load_backend(const struct backend_desc *backend) +{ + char path[PATH_MAX]; + const void *init = NULL; + void *module; + const char *name; + const char *entrypoint = "gbm_backend"; + + if (backend == NULL) + return NULL; + + name = backend->name; + + if (backend->builtin) { + init = backend->builtin; + } else { + if (name[0] != '/') + snprintf(path, sizeof path, MODULEDIR "/%s", name); + else + snprintf(path, sizeof path, "%s", name); + + module = dlopen(path, RTLD_NOW | RTLD_GLOBAL); + if (!module) { + fprintf(stderr, + "failed to load module: %s\n", dlerror()); + return NULL; + } + + init = dlsym(module, entrypoint); + if (!init) + return NULL; + } + + return init; +} + +static const struct backend_desc * +find_backend(const char *name) +{ + const struct backend_desc *backend = NULL; + int i; + + for (i = 0; i < ARRAY_SIZE(backends); ++i) { + if (strcmp(backends[i].name, name) == 0) { + backend = &backends[i]; + break; + } + } + + return backend; +} + +struct gbm_device * +_gbm_create_device(int fd) +{ + const struct gbm_backend *backend = NULL; + struct gbm_device *dev = NULL; + int i; + const char *b; + + b = getenv("GBM_BACKEND"); + if (b) + backend = load_backend(find_backend(b)); + + if (backend) + dev = backend->create_device(fd); + + for (i = 0; i < ARRAY_SIZE(backends) && dev == NULL; ++i) { + backend = load_backend(&backends[i]); + if (backend == NULL) + continue; + + dev = backend->create_device(fd); + } + + return dev; +} diff --git a/src/gbm/main/backend.h b/src/gbm/main/backend.h new file mode 100644 index 00000000000..4a643750333 --- /dev/null +++ b/src/gbm/main/backend.h @@ -0,0 +1,36 @@ +/* + * Copyright © 2011 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. + * + * Authors: + * Benjamin Franzke <[email protected]> + */ + +#ifndef MODULE_H_ +#define MODULE_H_ + +#include "gbmint.h" + +struct gbm_device * +_gbm_create_device(int fd); + +#endif diff --git a/src/gbm/main/common.c b/src/gbm/main/common.c new file mode 100644 index 00000000000..f02162df292 --- /dev/null +++ b/src/gbm/main/common.c @@ -0,0 +1,88 @@ +/* + * Copyright © 2011 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. + * + * Authors: + * Benjamin Franzke <[email protected]> + */ + +#include <stdio.h> +#include <string.h> + +#include <libudev.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> + +#include "common.h" +#include "gbmint.h" + +GBM_EXPORT struct udev_device * +_gbm_udev_device_new_from_fd(struct udev *udev, int fd) +{ + struct udev_device *device; + struct stat buf; + + if (fstat(fd, &buf) < 0) { + fprintf(stderr, "gbm: failed to stat fd %d", fd); + return NULL; + } + + device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev); + if (device == NULL) { + fprintf(stderr, + "gbm: could not create udev device for fd %d", fd); + return NULL; + } + + return device; +} + +GBM_EXPORT char * +_gbm_fd_get_device_name(int fd) +{ + struct udev *udev; + struct udev_device *device; + const char *const_device_name; + char *device_name = NULL; + + udev = udev_new(); + device = _gbm_udev_device_new_from_fd(udev, fd); + if (device == NULL) + return NULL; + + const_device_name = udev_device_get_devnode(device); + if (!const_device_name) + goto out; + device_name = strdup(const_device_name); + +out: + udev_device_unref(device); + udev_unref(udev); + + return device_name; +} + +GBM_EXPORT void +_gbm_log(const char *fmt_str, ...) +{ +} diff --git a/src/gbm/main/common.h b/src/gbm/main/common.h new file mode 100644 index 00000000000..1fcdfcac30d --- /dev/null +++ b/src/gbm/main/common.h @@ -0,0 +1,42 @@ +/* + * Copyright © 2011 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. + * + * Authors: + * Benjamin Franzke <[email protected]> + */ + +#ifndef _COMMON_H_ +#define _COMMON_H_ + +#include <libudev.h> + +struct udev_device * +_gbm_udev_device_new_from_fd(struct udev *udev, int fd); + +char * +_gbm_fd_get_device_name(int fd); + +void +_gbm_log(const char *fmt_str, ...); + +#endif diff --git a/src/gbm/main/common_drm.h b/src/gbm/main/common_drm.h new file mode 100644 index 00000000000..d28c3f01f48 --- /dev/null +++ b/src/gbm/main/common_drm.h @@ -0,0 +1,48 @@ +/* + * Copyright © 2011 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. + * + * Authors: + * Benjamin Franzke <[email protected]> + */ + +#ifndef _COMMON_DRM_H_ +#define _COMMON_DRM_H_ + +#include "gbmint.h" + +enum gbm_drm_driver_type { + GBM_DRM_DRIVER_TYPE_DRI, + GBM_DRM_DRIVER_TYPE_GALLIUM, +}; + +struct gbm_drm_device { + struct gbm_device base; + enum gbm_drm_driver_type type; + char *driver_name; +}; + +struct gbm_drm_bo { + struct gbm_bo base; +}; + +#endif diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c new file mode 100644 index 00000000000..8440b2c6ae3 --- /dev/null +++ b/src/gbm/main/gbm.c @@ -0,0 +1,190 @@ +/* + * Copyright © 2011 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. + * + * Authors: + * Benjamin Franzke <[email protected]> + */ + +#define _BSD_SOURCE + +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdint.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> + +#include "gbm.h" +#include "gbmint.h" +#include "common.h" +#include "backend.h" + +#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) + +struct gbm_device *devices[16]; + +static int device_num = 0; + +GBM_EXPORT int +gbm_device_get_fd(struct gbm_device *gbm) +{ + return gbm->fd; +} + +/* FIXME: maybe superfluous, use udev subclass from the fd? */ +GBM_EXPORT const char * +gbm_device_get_backend_name(struct gbm_device *gbm) +{ + return gbm->name; +} + +int +gbm_device_is_format_supported(struct gbm_device *gbm, + enum gbm_bo_format format, + uint32_t usage) +{ + return gbm->is_format_supported(gbm, format, usage); +} + +GBM_EXPORT void +gbm_device_destroy(struct gbm_device *gbm) +{ + gbm->refcount--; + if (gbm->refcount == 0) + gbm->destroy(gbm); +} + +GBM_EXPORT struct gbm_device * +_gbm_mesa_get_device(int fd) +{ + struct gbm_device *gbm = NULL; + struct stat buf; + dev_t dev; + int i; + + if (fd < 0 || fstat(fd, &buf) < 0 || !S_ISCHR(buf.st_mode)) { + fprintf(stderr, "_gbm_mesa_get_device: invalid fd: %d\n", fd); + return NULL; + } + + for (i = 0; i < device_num; ++i) { + dev = devices[i]->stat.st_rdev; + if (major(dev) == major(buf.st_rdev) && + minor(dev) == minor(buf.st_rdev)) { + gbm = devices[i]; + gbm->refcount++; + break; + } + } + + return gbm; +} + +GBM_EXPORT struct gbm_device * +gbm_create_device(int fd) +{ + struct gbm_device *gbm = NULL; + struct stat buf; + + if (fd < 0 || fstat(fd, &buf) < 0 || !S_ISCHR(buf.st_mode)) { + fprintf(stderr, "gbm_create_device: invalid fd: %d\n", fd); + return NULL; + } + + if (device_num == 0) + memset(devices, 0, sizeof devices); + + gbm = _gbm_create_device(fd); + if (gbm == NULL) + return NULL; + + gbm->dummy = gbm_create_device; + gbm->stat = buf; + gbm->refcount = 1; + + if (device_num < ARRAY_SIZE(devices)-1) + devices[device_num++] = gbm; + + return gbm; +} + +GBM_EXPORT unsigned int +gbm_bo_get_width(struct gbm_bo *bo) +{ + return bo->width; +} + +GBM_EXPORT unsigned int +gbm_bo_get_height(struct gbm_bo *bo) +{ + return bo->height; +} + +GBM_EXPORT uint32_t +gbm_bo_get_pitch(struct gbm_bo *bo) +{ + return bo->pitch; +} + +GBM_EXPORT union gbm_bo_handle +gbm_bo_get_handle(struct gbm_bo *bo) +{ + return bo->handle; +} + +GBM_EXPORT void +gbm_bo_destroy(struct gbm_bo *bo) +{ + bo->gbm->bo_destroy(bo); +} + +GBM_EXPORT struct gbm_bo * +gbm_bo_create(struct gbm_device *gbm, + uint32_t width, uint32_t height, + enum gbm_bo_format format, uint32_t usage) +{ + if (width == 0 || height == 0) + return NULL; + + if (usage & GBM_BO_USE_CURSOR_64X64 && + (width != 64 || height != 64)) + return NULL; + + return gbm->bo_create(gbm, width, height, format, usage); +} + +GBM_EXPORT struct gbm_bo * +gbm_bo_create_from_egl_image(struct gbm_device *gbm, + void *egl_dpy, void *egl_image, + uint32_t width, uint32_t height, + uint32_t usage) +{ + if (width == 0 || height == 0) + return NULL; + + return gbm->bo_create_from_egl_image(gbm, egl_dpy, egl_image, + width, height, usage); +} diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h new file mode 100644 index 00000000000..05d2292dc75 --- /dev/null +++ b/src/gbm/main/gbm.h @@ -0,0 +1,109 @@ +/* + * Copyright © 2011 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. + * + * Authors: + * Benjamin Franzke <[email protected]> + */ + +#ifndef _GBM_H_ +#define _GBM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + + +#define __GBM__ 1 + +#include <stdint.h> + +struct gbm_device; +struct gbm_bo; + +union gbm_bo_handle { + void *ptr; + int32_t s32; + uint32_t u32; + int64_t s64; + uint64_t u64; +}; + +enum gbm_bo_format { + GBM_BO_FORMAT_XRGB8888, + GBM_BO_FORMAT_ARGB8888, +}; + +enum gbm_bo_flags { + GBM_BO_USE_SCANOUT = (1 << 0), + GBM_BO_USE_CURSOR_64X64 = (1 << 1), + GBM_BO_USE_RENDERING = (1 << 2), +}; + +int +gbm_device_get_fd(struct gbm_device *gbm); + +const char * +gbm_device_get_backend_name(struct gbm_device *gbm); + +int +gbm_device_is_format_supported(struct gbm_device *gbm, + enum gbm_bo_format format, + uint32_t usage); + +void +gbm_device_destroy(struct gbm_device *gbm); + +struct gbm_device * +gbm_create_device(int fd); + +struct gbm_bo * +gbm_bo_create(struct gbm_device *gbm, + uint32_t width, uint32_t height, + enum gbm_bo_format format, uint32_t flags); + +struct gbm_bo * +gbm_bo_create_from_egl_image(struct gbm_device *gbm, + void *egl_dpy, void *egl_img, + uint32_t width, uint32_t height, + uint32_t usage); + +uint32_t +gbm_bo_get_width(struct gbm_bo *bo); + +uint32_t +gbm_bo_get_height(struct gbm_bo *bo); + +uint32_t +gbm_bo_get_pitch(struct gbm_bo *bo); + +union gbm_bo_handle +gbm_bo_get_handle(struct gbm_bo *bo); + +void +gbm_bo_destroy(struct gbm_bo *bo); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gbm/main/gbm.pc.in b/src/gbm/main/gbm.pc.in new file mode 100644 index 00000000000..76299e77f83 --- /dev/null +++ b/src/gbm/main/gbm.pc.in @@ -0,0 +1,12 @@ +prefix=@INSTALL_DIR@ +exec_prefix=${prefix} +libdir=@INSTALL_LIB_DIR@ +includedir=@INSTALL_INC_DIR@ + +Name: gbm +Description: Mesa gbm library +Requires.private: @GBM_PC_REQ_PRIV@ +Version: @VERSION@ +Libs: -L${libdir} -l@GBM_LIB@ +Libs.private: @GBM_PC_LIB_PRIV@ +Cflags: -I${includedir} @GBM_PC_CFLAGS@ diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h new file mode 100644 index 00000000000..fb8db804c1b --- /dev/null +++ b/src/gbm/main/gbmint.h @@ -0,0 +1,82 @@ +/* + * Copyright © 2011 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. + * + * Authors: + * Benjamin Franzke <[email protected]> + */ + +#ifndef INTERNAL_H_ +#define INTERNAL_H_ + +#include "gbm.h" +#include <sys/stat.h> + +/* GCC visibility */ +#if defined(__GNUC__) && __GNUC__ >= 4 +#define GBM_EXPORT __attribute__ ((visibility("default"))) +#else +#define GBM_EXPORT +#endif + +struct gbm_device { + /* Hack to make a gbm_device detectable by its first element. */ + struct gbm_device *(*dummy)(int); + + int fd; + const char *name; + unsigned int refcount; + struct stat stat; + + void (*destroy)(struct gbm_device *gbm); + int (*is_format_supported)(struct gbm_device *gbm, + enum gbm_bo_format format, + uint32_t usage); + + struct gbm_bo *(*bo_create)(struct gbm_device *gbm, + uint32_t width, uint32_t height, + enum gbm_bo_format format, + uint32_t usage); + struct gbm_bo *(*bo_create_from_egl_image)(struct gbm_device *gbm, + void *egl_dpy, void *egl_img, + uint32_t width, uint32_t height, + uint32_t usage); + void (*bo_destroy)(struct gbm_bo *bo); +}; + +struct gbm_bo { + struct gbm_device *gbm; + uint32_t width; + uint32_t height; + uint32_t pitch; + union gbm_bo_handle handle; +}; + +struct gbm_backend { + const char *backend_name; + struct gbm_device *(*create_device)(int fd); +}; + +GBM_EXPORT struct gbm_device * +_gbm_mesa_get_device(int fd); + +#endif |