From 50ea632e3b2e6b318036bae1e35e86d44566f0a4 Mon Sep 17 00:00:00 2001 From: Sangwon Ha Date: Thu, 14 Aug 2014 01:20:23 +0900 Subject: [PATCH 01/11] Initial commit Change-Id: Ib6efd78bb1dd4ec8d9a29e1c37ed209d6f36f068 --- README | 1 + 1 file changed, 1 insertion(+) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..04d79a7 --- /dev/null +++ b/README @@ -0,0 +1 @@ +Empty master branch -- 2.7.4 From c17298af6319b0a16618c8cb277ebed32727b704 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Fri, 29 Aug 2014 18:54:13 +0900 Subject: [PATCH 03/11] Upload initial Wayland-only code Change-Id: I7daa608c3547c4facf919fb89ce182483b5185d6 --- Makefile | 68 +++++++ README | 1 - libgbm.manifest | 5 + packaging/libgbm.spec | 59 ++++++ pkgconfig/libgbm.pc | 12 ++ src/backend.c | 127 +++++++++++++ src/backend.h | 36 ++++ src/backends/Makefile | 23 +++ src/common.c | 88 +++++++++ src/common.h | 42 +++++ src/common_drm.h | 48 +++++ src/gbm.c | 489 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/gbm.h | 304 +++++++++++++++++++++++++++++++ src/gbmint.h | 117 ++++++++++++ 14 files changed, 1418 insertions(+), 1 deletion(-) create mode 100644 Makefile delete mode 100644 README create mode 100644 libgbm.manifest create mode 100644 packaging/libgbm.spec create mode 100644 pkgconfig/libgbm.pc create mode 100644 src/backend.c create mode 100644 src/backend.h create mode 100644 src/backends/Makefile create mode 100644 src/common.c create mode 100644 src/common.h create mode 100644 src/common_drm.h create mode 100644 src/gbm.c create mode 100644 src/gbm.h create mode 100644 src/gbmint.h diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a6d6d38 --- /dev/null +++ b/Makefile @@ -0,0 +1,68 @@ +prefix ?= /usr/local + +GBM_SO_VER ?= no_ver +SRC_DIR = ./src + +#CROSS_COMPILE ?= arm-none-linux-gnueabi- +TARGET_CC ?= $(CROSS_COMPILE)gcc +TARGET_AR ?= $(CROSS_COMPILE)ar +CFLAGS += -Wall -ludev -fPIC + +#gbm backend sources +GBM_BACKENDS_DIR = $(SRC_DIR)/backends + +#gbm backend module location +CFLAGS += -DMODULEDIR='"/usr/lib/gbm"' + +#gbm main source +GBM_SRCS += \ + $(SRC_DIR)/gbm.c \ + $(SRC_DIR)/common.c \ + $(SRC_DIR)/backend.c + +%.o: %.c + $(TARGET_CC) -c -o $@ $< $(CFLAGS) + +GBM_OBJS := $(GBM_SRCS:.c=.o) + +libgbm.so.$(GBM_SO_VER): $(GBM_OBJS) + $(TARGET_CC) -shared -o $@ $(GBM_OBJS) $(CFLAGS) +backend: + @for dir in $(GBM_BACKENDS_DIR) ; do \ + $(MAKE) -C $$dir ; \ + done + +.DEFAULT_GOAL = all +all: libgbm.so.$(GBM_SO_VER) backend + +clean: + -rm -f $(GBM_OBJS) libgbm.so.$(GBM_SO_VER) + @for dir in $(GBM_BACKENDS_DIR) ; do \ + $(MAKE) $@ -C $$dir ; \ + done + +install: all + cp $(SRC_DIR)/gbm.h $(prefix)/include/ + -mkdir $(prefix)/include/gbm +# cp $(SRC_DIR)/gbm.h $(prefix)/include/gbm/ + cp $(SRC_DIR)/backend.h $(prefix)/include/gbm/ + cp $(SRC_DIR)/common_drm.h $(prefix)/include/gbm/ + cp $(SRC_DIR)/common.h $(prefix)/include/gbm/ + cp $(SRC_DIR)/gbmint.h $(prefix)/include/gbm/ + cp pkgconfig/libgbm.pc $(prefix)/lib/pkgconfig/ + cp libgbm.so.$(GBM_SO_VER) $(prefix)/lib/ + @for dir in $(GBM_BACKENDS_DIR) ; do \ + $(MAKE) $@ -C $$dir ; \ + done + +uninstall: + -rm -f $(prefix)/include/gbm.h + -rm -f $(prefix)/include/gbm/backend.h + -rm -f $(prefix)/include/gbm/common_drm.h + -rm -f $(prefix)/include/gbm/common.h + -rm -f $(prefix)/include/gbm/gbmint.h + -rm -f $(prefix)/lib/pkgconfig/libgbm.pc + -rm -f $(prefix)/lib/libgbm.so.$(GBM_SO_VER) + @for dir in $(GBM_BACKENDS_DIR) ; do \ + $(MAKE) $@ -C $$dir ; \ + done diff --git a/README b/README deleted file mode 100644 index 04d79a7..0000000 --- a/README +++ /dev/null @@ -1 +0,0 @@ -Empty master branch diff --git a/libgbm.manifest b/libgbm.manifest new file mode 100644 index 0000000..97e8c31 --- /dev/null +++ b/libgbm.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/libgbm.spec b/packaging/libgbm.spec new file mode 100644 index 0000000..e2f4fe2 --- /dev/null +++ b/packaging/libgbm.spec @@ -0,0 +1,59 @@ +Summary: Wayland Generic Buffer Management for TIZEN +Name: libgbm +Version: 1.0.0s +Release: 1 +Group: System/X Hardware Support +License: Unknown + +Source0: %{name}.tar.gz + +Provides: libgbm.so.1.0.0s +Provides: libgbm.so.1 +Provides: libgbm.so + +# Requirements +BuildRequires: autoconf +BuildRequires: libtool +BuildRequires: systemd-devel +BuildRequires: pkgconfig(libudev) +BuildRequires: libdrm-devel + +%description +Wayland Generic Buffer Management for TIZEN + +%package devel +Summary: Development header files for use with GBM +Group: Development/Libraries +Requires: %{name} + +%description devel +Development header files for use with gbm + +%prep +%setup -q -n %{name} + +%build +export GBM_SO_VER=1.0.0s +make + +%install +mkdir -p %{buildroot}%{_includedir} +mkdir -p %{buildroot}%{_libdir}/pkgconfig +ln -sf libgbm.so.1.0.0s %{buildroot}%{_libdir}/libgbm.so +ln -sf libgbm.so.1.0.0s %{buildroot}%{_libdir}/libgbm.so.1 + +export GBM_SO_VER=1.0.0s +%makeinstall + +%files +%manifest libgbm.manifest +%defattr(-,root,root,-) +%{_libdir}/libgbm.so.1.0.0s +%{_libdir}/libgbm.so.1 + +%files devel +%defattr(-,root,root,-) +%{_includedir}/gbm.h +%{_includedir}/gbm/* +%{_libdir}/pkgconfig/libgbm.pc +%{_libdir}/libgbm.so diff --git a/pkgconfig/libgbm.pc b/pkgconfig/libgbm.pc new file mode 100644 index 0000000..271ceed --- /dev/null +++ b/pkgconfig/libgbm.pc @@ -0,0 +1,12 @@ +prefix=/usr/local +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: libgbm +Description: Mesa GBM library +Requires.private: libudev >= 151 +Version: 10.2.0-devel +Libs: -L${libdir} -lgbm +Libs.private: -ldl +Cflags: -I${includedir} diff --git a/src/backend.c b/src/backend.c new file mode 100644 index 0000000..6da2abb --- /dev/null +++ b/src/backend.c @@ -0,0 +1,127 @@ +/* + * 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 + */ + +#include +#include +#include +#include +#include +#include + +#include "backend.h" + +#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) + +struct backend_desc { + const char *name; + const struct gbm_backend *builtin; +}; + +static const struct backend_desc backends[] = { + { "gbm_dri.so", NULL }, + { "gbm_gallium_drm.so", NULL }, + { "gbm_tbm.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/backend.h b/src/backend.h new file mode 100644 index 0000000..4a64375 --- /dev/null +++ b/src/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 + */ + +#ifndef MODULE_H_ +#define MODULE_H_ + +#include "gbmint.h" + +struct gbm_device * +_gbm_create_device(int fd); + +#endif diff --git a/src/backends/Makefile b/src/backends/Makefile new file mode 100644 index 0000000..115b394 --- /dev/null +++ b/src/backends/Makefile @@ -0,0 +1,23 @@ +#SUBDIRS = + +default: subdirs + +subdirs: + @for dir in $(SUBDIRS) ; do \ + $(MAKE) -C $$dir ; \ + done + +clean: + @for dir in $(SUBDIRS) ; do \ + $(MAKE) $@ -C $$dir ; \ + done + +install: subdirs + @for dir in $(SUBDIRS) ; do \ + $(MAKE) $@ -C $$dir ; \ + done + +uninstall: + @for dir in $(SUBDIRS) ; do \ + $(MAKE) $@ -C $$dir ; \ + done diff --git a/src/common.c b/src/common.c new file mode 100644 index 0000000..f02162d --- /dev/null +++ b/src/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 + */ + +#include +#include + +#include +#include +#include +#include + +#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/common.h b/src/common.h new file mode 100644 index 0000000..1fcdfca --- /dev/null +++ b/src/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 + */ + +#ifndef _COMMON_H_ +#define _COMMON_H_ + +#include + +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/common_drm.h b/src/common_drm.h new file mode 100644 index 0000000..d28c3f0 --- /dev/null +++ b/src/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 + */ + +#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.c b/src/gbm.c new file mode 100644 index 0000000..6179e5b --- /dev/null +++ b/src/gbm.c @@ -0,0 +1,489 @@ +/* + * 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 + */ + +#define _BSD_SOURCE + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "gbm.h" +#include "gbmint.h" +#include "backend.h" + +#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) + +static struct gbm_device *devices[16]; + +static int device_num = 0; + +/** Returns the file description for the gbm device + * + * \return The fd that the struct gbm_device was created with + */ +GBM_EXPORT int +gbm_device_get_fd(struct gbm_device *gbm) +{ + return gbm->fd; +} + +/* FIXME: maybe superfluous, use udev subclass from the fd? */ +/** Get the backend name for the given gbm device + * + * \return The backend name string - this belongs to the device and must not + * be freed + */ +GBM_EXPORT const char * +gbm_device_get_backend_name(struct gbm_device *gbm) +{ + return gbm->name; +} + +/** Test if a format is supported for a given set of usage flags. + * + * \param gbm The created buffer manager + * \param format The format to test + * \param usage A bitmask of the usages to test the format against + * \return 1 if the format is supported otherwise 0 + * + * \sa enum gbm_bo_flags for the list of flags that the format can be + * tested against + * + * \sa enum gbm_bo_format for the list of formats + */ +GBM_EXPORT int +gbm_device_is_format_supported(struct gbm_device *gbm, + uint32_t format, uint32_t usage) +{ + return gbm->is_format_supported(gbm, format, usage); +} + +/** Destroy the gbm device and free all resources associated with it. + * + * \param gbm The device created using gbm_create_device() + */ +GBM_EXPORT void +gbm_device_destroy(struct gbm_device *gbm) +{ + gbm->refcount--; + if (gbm->refcount == 0) + gbm->destroy(gbm); +} + +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; +} + +/** Create a gbm device for allocating buffers + * + * The file descriptor passed in is used by the backend to communicate with + * platform for allocating the memory. For allocations using DRI this would be + * the file descriptor returned when opening a device such as \c + * /dev/dri/card0 + * + * \param fd The file descriptor for an backend specific device + * \return The newly created struct gbm_device. The resources associated with + * the device should be freed with gbm_device_destroy() when it is no longer + * needed. If the creation of the device failed NULL will be returned. + */ +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; +} + +/** Get the width of the buffer object + * + * \param bo The buffer object + * \return The width of the allocated buffer object + * + */ +GBM_EXPORT unsigned int +gbm_bo_get_width(struct gbm_bo *bo) +{ + return bo->width; +} + +/** Get the height of the buffer object + * + * \param bo The buffer object + * \return The height of the allocated buffer object + */ +GBM_EXPORT unsigned int +gbm_bo_get_height(struct gbm_bo *bo) +{ + return bo->height; +} + +/** Get the stride of the buffer object + * + * This is calculated by the backend when it does the allocation in + * gbm_bo_create() + * + * \param bo The buffer object + * \return The stride of the allocated buffer object in bytes + */ +GBM_EXPORT uint32_t +gbm_bo_get_stride(struct gbm_bo *bo) +{ + return bo->stride; +} + +/** Get the format of the buffer object + * + * The format of the pixels in the buffer. + * + * \param bo The buffer object + * \return The format of buffer object, on of the GBM_FORMAT_* codes + */ +GBM_EXPORT uint32_t +gbm_bo_get_format(struct gbm_bo *bo) +{ + return bo->format; +} + +/** Get the handle of the buffer object + * + * This is stored in the platform generic union gbm_bo_handle type. However + * the format of this handle is platform specific. + * + * \param bo The buffer object + * \return Returns the handle of the allocated buffer object + */ +GBM_EXPORT union gbm_bo_handle +gbm_bo_get_handle(struct gbm_bo *bo) +{ + return bo->handle; +} + +/** Get a DMA-BUF file descriptor for the buffer object + * + * This function creates a DMA-BUF (also known as PRIME) file descriptor + * handle for the buffer object. Eeach call to gbm_bo_get_fd() returns a new + * file descriptor and the caller is responsible for closing the file + * descriptor. + + * \param bo The buffer object + * \return Returns a file descriptor referring to the underlying buffer + */ +GBM_EXPORT int +gbm_bo_get_fd(struct gbm_bo *bo) +{ + return bo->gbm->bo_get_fd(bo); +} + + +/** Write data into the buffer object + * + * If the buffer object was created with the GBM_BO_USE_WRITE flag, + * this function can used to write data into the buffer object. The + * data is copied directly into the object and it's the responsiblity + * of the caller to make sure the data represents valid pixel data, + * according to the width, height, stride and format of the buffer object. + * + * \param bo The buffer object + * \param buf The data to write + * \param count The number of bytes to write + * \return Returns -1 on error, 0 otherwise + */ +GBM_EXPORT int +gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count) +{ + return bo->gbm->bo_write(bo, buf, count); +} + +/** Get the gbm device used to create the buffer object + * + * \param bo The buffer object + * \return Returns the gbm device with which the buffer object was created + */ +GBM_EXPORT struct gbm_device * +gbm_bo_get_device(struct gbm_bo *bo) +{ + return bo->gbm; +} + +/** Set the user data associated with a buffer object + * + * \param bo The buffer object + * \param data The data to associate to the buffer object + * \param destroy_user_data A callback (which may be %NULL) that will be + * called prior to the buffer destruction + */ +GBM_EXPORT void +gbm_bo_set_user_data(struct gbm_bo *bo, void *data, + void (*destroy_user_data)(struct gbm_bo *, void *)) +{ + bo->user_data = data; + bo->destroy_user_data = destroy_user_data; +} + +/** Get the user data associated with a buffer object + * + * \param bo The buffer object + * \return Returns the user data associated with the buffer object or %NULL + * if no data was associated with it + * + * \sa gbm_bo_set_user_data() + */ +GBM_EXPORT void * +gbm_bo_get_user_data(struct gbm_bo *bo) +{ + return bo->user_data; +} + +/** + * Destroys the given buffer object and frees all resources associated with + * it. + * + * \param bo The buffer object + */ +GBM_EXPORT void +gbm_bo_destroy(struct gbm_bo *bo) +{ + if (bo->destroy_user_data) + bo->destroy_user_data(bo, bo->user_data); + + bo->gbm->bo_destroy(bo); +} + +/** + * Allocate a buffer object for the given dimensions + * + * \param gbm The gbm device returned from gbm_create_device() + * \param width The width for the buffer + * \param height The height for the buffer + * \param format The format to use for the buffer + * \param usage The union of the usage flags for this buffer + * + * \return A newly allocated buffer that should be freed with gbm_bo_destroy() + * when no longer needed. If an error occurs during allocation %NULL will be + * returned. + * + * \sa enum gbm_bo_format for the list of formats + * \sa enum gbm_bo_flags for the list of usage flags + */ +GBM_EXPORT struct gbm_bo * +gbm_bo_create(struct gbm_device *gbm, + uint32_t width, uint32_t height, + uint32_t 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); +} + +/** + * Create a gbm buffer object from an foreign object + * + * This function imports a foreign object and creates a new gbm bo for it. + * This enabled using the foreign object with a display API such as KMS. + * Currently two types of foreign objects are supported, indicated by the type + * argument: + * + * GBM_BO_IMPORT_WL_BUFFER + * GBM_BO_IMPORT_EGL_IMAGE + * GBM_BO_IMPORT_FD + * + * The the gbm bo shares the underlying pixels but its life-time is + * independent of the foreign object. + * + * \param gbm The gbm device returned from gbm_create_device() + * \param gbm The type of object we're importing + * \param gbm Pointer to the external object + * \param usage The union of the usage flags for this buffer + * + * \return A newly allocated buffer object that should be freed with + * gbm_bo_destroy() when no longer needed. + * + * \sa enum gbm_bo_flags for the list of usage flags + */ +GBM_EXPORT struct gbm_bo * +gbm_bo_import(struct gbm_device *gbm, + uint32_t type, void *buffer, uint32_t usage) +{ + return gbm->bo_import(gbm, type, buffer, usage); +} + +/** + * Allocate a surface object + * + * \param gbm The gbm device returned from gbm_create_device() + * \param width The width for the surface + * \param height The height for the surface + * \param format The format to use for the surface + * + * \return A newly allocated surface that should be freed with + * gbm_surface_destroy() when no longer needed. If an error occurs + * during allocation %NULL will be returned. + * + * \sa enum gbm_bo_format for the list of formats + */ +GBM_EXPORT struct gbm_surface * +gbm_surface_create(struct gbm_device *gbm, + uint32_t width, uint32_t height, + uint32_t format, uint32_t flags) +{ + return gbm->surface_create(gbm, width, height, format, flags); +} + +/** + * Destroys the given surface and frees all resources associated with + * it. + * + * All buffers locked with gbm_surface_lock_front_buffer() should be + * released prior to calling this function. + * + * \param surf The surface + */ +GBM_EXPORT void +gbm_surface_destroy(struct gbm_surface *surf) +{ + surf->gbm->surface_destroy(surf); +} + +/** + * Lock the surface's current front buffer + * + * Lock rendering to the surface's current front buffer until it is + * released with gbm_surface_release_buffer(). + * + * This function must be called exactly once after calling + * eglSwapBuffers. Calling it before any eglSwapBuffer has happened + * on the surface or two or more times after eglSwapBuffers is an + * error. A new bo representing the new front buffer is returned. On + * multiple invocations, all the returned bos must be released in + * order to release the actual surface buffer. + * + * \param surf The surface + * + * \return A buffer object that should be released with + * gbm_surface_release_buffer() when no longer needed. The implementation + * is free to reuse buffers released with gbm_surface_release_buffer() so + * this bo should not be destroyed using gbm_bo_destroy(). If an error + * occurs this function returns %NULL. + */ +GBM_EXPORT struct gbm_bo * +gbm_surface_lock_front_buffer(struct gbm_surface *surf) +{ + return surf->gbm->surface_lock_front_buffer(surf); +} + +/** + * Release a locked buffer obtained with gbm_surface_lock_front_buffer() + * + * Returns the underlying buffer to the gbm surface. Releasing a bo + * will typically make gbm_surface_has_free_buffer() return 1 and thus + * allow rendering the next frame, but not always. The implementation + * may choose to destroy the bo immediately or reuse it, in which case + * the user data associated with it is unchanged. + * + * \param surf The surface + * \param bo The buffer object + */ +GBM_EXPORT void +gbm_surface_release_buffer(struct gbm_surface *surf, struct gbm_bo *bo) +{ + surf->gbm->surface_release_buffer(surf, bo); +} + +/** + * Return whether or not a surface has free (non-locked) buffers + * + * Before starting a new frame, the surface must have a buffer + * available for rendering. Initially, a gbm surface will have a free + * buffer, but after one of more buffers have been locked (\sa + * gbm_surface_lock_front_buffer()), the application must check for a + * free buffer before rendering. + * + * If a surface doesn't have a free buffer, the application must + * return a buffer to the surface using gbm_surface_release_buffer() + * and after that, the application can query for free buffers again. + * + * \param surf The surface + * \return 1 if the surface has free buffers, 0 otherwise + */ +GBM_EXPORT int +gbm_surface_has_free_buffers(struct gbm_surface *surf) +{ + return surf->gbm->surface_has_free_buffers(surf); +} diff --git a/src/gbm.h b/src/gbm.h new file mode 100644 index 0000000..92d472a --- /dev/null +++ b/src/gbm.h @@ -0,0 +1,304 @@ +/* + * 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 + */ + +#ifndef _GBM_H_ +#define _GBM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + + +#define __GBM__ 1 + +#include + +/** + * \file gbm.h + * \brief Generic Buffer Manager + */ + +struct gbm_device; +struct gbm_bo; +struct gbm_surface; + +/** + * \mainpage The Generic Buffer Manager + * + * This module provides an abstraction that the caller can use to request a + * buffer from the underlying memory management system for the platform. + * + * This allows the creation of portable code whilst still allowing access to + * the underlying memory manager. + */ + +/** + * Abstraction representing the handle to a buffer allocated by the + * manager + */ +union gbm_bo_handle { + void *ptr; + int32_t s32; + uint32_t u32; + int64_t s64; + uint64_t u64; +}; + +/** Format of the allocated buffer */ +enum gbm_bo_format { + /** RGB with 8 bits per channel in a 32 bit value */ + GBM_BO_FORMAT_XRGB8888, + /** ARGB with 8 bits per channel in a 32 bit value */ + GBM_BO_FORMAT_ARGB8888 +}; + +#define __gbm_fourcc_code(a,b,c,d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \ + ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24)) + +#define GBM_FORMAT_BIG_ENDIAN (1<<31) /* format is big endian instead of little endian */ + +/* color index */ +#define GBM_FORMAT_C8 __gbm_fourcc_code('C', '8', ' ', ' ') /* [7:0] C */ + +/* 8 bpp RGB */ +#define GBM_FORMAT_RGB332 __gbm_fourcc_code('R', 'G', 'B', '8') /* [7:0] R:G:B 3:3:2 */ +#define GBM_FORMAT_BGR233 __gbm_fourcc_code('B', 'G', 'R', '8') /* [7:0] B:G:R 2:3:3 */ + +/* 16 bpp RGB */ +#define GBM_FORMAT_XRGB4444 __gbm_fourcc_code('X', 'R', '1', '2') /* [15:0] x:R:G:B 4:4:4:4 little endian */ +#define GBM_FORMAT_XBGR4444 __gbm_fourcc_code('X', 'B', '1', '2') /* [15:0] x:B:G:R 4:4:4:4 little endian */ +#define GBM_FORMAT_RGBX4444 __gbm_fourcc_code('R', 'X', '1', '2') /* [15:0] R:G:B:x 4:4:4:4 little endian */ +#define GBM_FORMAT_BGRX4444 __gbm_fourcc_code('B', 'X', '1', '2') /* [15:0] B:G:R:x 4:4:4:4 little endian */ + +#define GBM_FORMAT_ARGB4444 __gbm_fourcc_code('A', 'R', '1', '2') /* [15:0] A:R:G:B 4:4:4:4 little endian */ +#define GBM_FORMAT_ABGR4444 __gbm_fourcc_code('A', 'B', '1', '2') /* [15:0] A:B:G:R 4:4:4:4 little endian */ +#define GBM_FORMAT_RGBA4444 __gbm_fourcc_code('R', 'A', '1', '2') /* [15:0] R:G:B:A 4:4:4:4 little endian */ +#define GBM_FORMAT_BGRA4444 __gbm_fourcc_code('B', 'A', '1', '2') /* [15:0] B:G:R:A 4:4:4:4 little endian */ + +#define GBM_FORMAT_XRGB1555 __gbm_fourcc_code('X', 'R', '1', '5') /* [15:0] x:R:G:B 1:5:5:5 little endian */ +#define GBM_FORMAT_XBGR1555 __gbm_fourcc_code('X', 'B', '1', '5') /* [15:0] x:B:G:R 1:5:5:5 little endian */ +#define GBM_FORMAT_RGBX5551 __gbm_fourcc_code('R', 'X', '1', '5') /* [15:0] R:G:B:x 5:5:5:1 little endian */ +#define GBM_FORMAT_BGRX5551 __gbm_fourcc_code('B', 'X', '1', '5') /* [15:0] B:G:R:x 5:5:5:1 little endian */ + +#define GBM_FORMAT_ARGB1555 __gbm_fourcc_code('A', 'R', '1', '5') /* [15:0] A:R:G:B 1:5:5:5 little endian */ +#define GBM_FORMAT_ABGR1555 __gbm_fourcc_code('A', 'B', '1', '5') /* [15:0] A:B:G:R 1:5:5:5 little endian */ +#define GBM_FORMAT_RGBA5551 __gbm_fourcc_code('R', 'A', '1', '5') /* [15:0] R:G:B:A 5:5:5:1 little endian */ +#define GBM_FORMAT_BGRA5551 __gbm_fourcc_code('B', 'A', '1', '5') /* [15:0] B:G:R:A 5:5:5:1 little endian */ + +#define GBM_FORMAT_RGB565 __gbm_fourcc_code('R', 'G', '1', '6') /* [15:0] R:G:B 5:6:5 little endian */ +#define GBM_FORMAT_BGR565 __gbm_fourcc_code('B', 'G', '1', '6') /* [15:0] B:G:R 5:6:5 little endian */ + +/* 24 bpp RGB */ +#define GBM_FORMAT_RGB888 __gbm_fourcc_code('R', 'G', '2', '4') /* [23:0] R:G:B little endian */ +#define GBM_FORMAT_BGR888 __gbm_fourcc_code('B', 'G', '2', '4') /* [23:0] B:G:R little endian */ + +/* 32 bpp RGB */ +#define GBM_FORMAT_XRGB8888 __gbm_fourcc_code('X', 'R', '2', '4') /* [31:0] x:R:G:B 8:8:8:8 little endian */ +#define GBM_FORMAT_XBGR8888 __gbm_fourcc_code('X', 'B', '2', '4') /* [31:0] x:B:G:R 8:8:8:8 little endian */ +#define GBM_FORMAT_RGBX8888 __gbm_fourcc_code('R', 'X', '2', '4') /* [31:0] R:G:B:x 8:8:8:8 little endian */ +#define GBM_FORMAT_BGRX8888 __gbm_fourcc_code('B', 'X', '2', '4') /* [31:0] B:G:R:x 8:8:8:8 little endian */ + +#define GBM_FORMAT_ARGB8888 __gbm_fourcc_code('A', 'R', '2', '4') /* [31:0] A:R:G:B 8:8:8:8 little endian */ +#define GBM_FORMAT_ABGR8888 __gbm_fourcc_code('A', 'B', '2', '4') /* [31:0] A:B:G:R 8:8:8:8 little endian */ +#define GBM_FORMAT_RGBA8888 __gbm_fourcc_code('R', 'A', '2', '4') /* [31:0] R:G:B:A 8:8:8:8 little endian */ +#define GBM_FORMAT_BGRA8888 __gbm_fourcc_code('B', 'A', '2', '4') /* [31:0] B:G:R:A 8:8:8:8 little endian */ + +#define GBM_FORMAT_XRGB2101010 __gbm_fourcc_code('X', 'R', '3', '0') /* [31:0] x:R:G:B 2:10:10:10 little endian */ +#define GBM_FORMAT_XBGR2101010 __gbm_fourcc_code('X', 'B', '3', '0') /* [31:0] x:B:G:R 2:10:10:10 little endian */ +#define GBM_FORMAT_RGBX1010102 __gbm_fourcc_code('R', 'X', '3', '0') /* [31:0] R:G:B:x 10:10:10:2 little endian */ +#define GBM_FORMAT_BGRX1010102 __gbm_fourcc_code('B', 'X', '3', '0') /* [31:0] B:G:R:x 10:10:10:2 little endian */ + +#define GBM_FORMAT_ARGB2101010 __gbm_fourcc_code('A', 'R', '3', '0') /* [31:0] A:R:G:B 2:10:10:10 little endian */ +#define GBM_FORMAT_ABGR2101010 __gbm_fourcc_code('A', 'B', '3', '0') /* [31:0] A:B:G:R 2:10:10:10 little endian */ +#define GBM_FORMAT_RGBA1010102 __gbm_fourcc_code('R', 'A', '3', '0') /* [31:0] R:G:B:A 10:10:10:2 little endian */ +#define GBM_FORMAT_BGRA1010102 __gbm_fourcc_code('B', 'A', '3', '0') /* [31:0] B:G:R:A 10:10:10:2 little endian */ + +/* packed YCbCr */ +#define GBM_FORMAT_YUYV __gbm_fourcc_code('Y', 'U', 'Y', 'V') /* [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian */ +#define GBM_FORMAT_YVYU __gbm_fourcc_code('Y', 'V', 'Y', 'U') /* [31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian */ +#define GBM_FORMAT_UYVY __gbm_fourcc_code('U', 'Y', 'V', 'Y') /* [31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian */ +#define GBM_FORMAT_VYUY __gbm_fourcc_code('V', 'Y', 'U', 'Y') /* [31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian */ + +#define GBM_FORMAT_AYUV __gbm_fourcc_code('A', 'Y', 'U', 'V') /* [31:0] A:Y:Cb:Cr 8:8:8:8 little endian */ + +/* + * 2 plane YCbCr + * index 0 = Y plane, [7:0] Y + * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian + * or + * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian + */ +#define GBM_FORMAT_NV12 __gbm_fourcc_code('N', 'V', '1', '2') /* 2x2 subsampled Cr:Cb plane */ +#define GBM_FORMAT_NV21 __gbm_fourcc_code('N', 'V', '2', '1') /* 2x2 subsampled Cb:Cr plane */ +#define GBM_FORMAT_NV16 __gbm_fourcc_code('N', 'V', '1', '6') /* 2x1 subsampled Cr:Cb plane */ +#define GBM_FORMAT_NV61 __gbm_fourcc_code('N', 'V', '6', '1') /* 2x1 subsampled Cb:Cr plane */ + +/* + * 3 plane YCbCr + * index 0: Y plane, [7:0] Y + * index 1: Cb plane, [7:0] Cb + * index 2: Cr plane, [7:0] Cr + * or + * index 1: Cr plane, [7:0] Cr + * index 2: Cb plane, [7:0] Cb + */ +#define GBM_FORMAT_YUV410 __gbm_fourcc_code('Y', 'U', 'V', '9') /* 4x4 subsampled Cb (1) and Cr (2) planes */ +#define GBM_FORMAT_YVU410 __gbm_fourcc_code('Y', 'V', 'U', '9') /* 4x4 subsampled Cr (1) and Cb (2) planes */ +#define GBM_FORMAT_YUV411 __gbm_fourcc_code('Y', 'U', '1', '1') /* 4x1 subsampled Cb (1) and Cr (2) planes */ +#define GBM_FORMAT_YVU411 __gbm_fourcc_code('Y', 'V', '1', '1') /* 4x1 subsampled Cr (1) and Cb (2) planes */ +#define GBM_FORMAT_YUV420 __gbm_fourcc_code('Y', 'U', '1', '2') /* 2x2 subsampled Cb (1) and Cr (2) planes */ +#define GBM_FORMAT_YVU420 __gbm_fourcc_code('Y', 'V', '1', '2') /* 2x2 subsampled Cr (1) and Cb (2) planes */ +#define GBM_FORMAT_YUV422 __gbm_fourcc_code('Y', 'U', '1', '6') /* 2x1 subsampled Cb (1) and Cr (2) planes */ +#define GBM_FORMAT_YVU422 __gbm_fourcc_code('Y', 'V', '1', '6') /* 2x1 subsampled Cr (1) and Cb (2) planes */ +#define GBM_FORMAT_YUV444 __gbm_fourcc_code('Y', 'U', '2', '4') /* non-subsampled Cb (1) and Cr (2) planes */ +#define GBM_FORMAT_YVU444 __gbm_fourcc_code('Y', 'V', '2', '4') /* non-subsampled Cr (1) and Cb (2) planes */ + + +/** + * Flags to indicate the intended use for the buffer - these are passed into + * gbm_bo_create(). The caller must set the union of all the flags that are + * appropriate + * + * \sa Use gbm_device_is_format_supported() to check if the combination of format + * and use flags are supported + */ +enum gbm_bo_flags { + /** + * Buffer is going to be presented to the screen using an API such as KMS + */ + GBM_BO_USE_SCANOUT = (1 << 0), + /** + * Buffer is going to be used as cursor - the dimensions for the buffer + * must be 64x64 if this flag is passed. + */ + GBM_BO_USE_CURSOR_64X64 = (1 << 1), + /** + * Buffer is to be used for rendering - for example it is going to be used + * as the storage for a color buffer + */ + GBM_BO_USE_RENDERING = (1 << 2), + /** + * Buffer can be used for gbm_bo_write. This is guaranteed to work + * with GBM_BO_USE_CURSOR_64X64. but may not work for other + * combinations. + */ + GBM_BO_USE_WRITE = (1 << 3), +}; + +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, + uint32_t 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, + uint32_t format, uint32_t flags); + +#define GBM_BO_IMPORT_WL_BUFFER 0x5501 +#define GBM_BO_IMPORT_EGL_IMAGE 0x5502 +#define GBM_BO_IMPORT_FD 0x5503 + +struct gbm_import_fd_data { + int fd; + uint32_t width; + uint32_t height; + uint32_t stride; + uint32_t format; +}; + +struct gbm_bo * +gbm_bo_import(struct gbm_device *gbm, uint32_t type, + void *buffer, 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_stride(struct gbm_bo *bo); + +uint32_t +gbm_bo_get_format(struct gbm_bo *bo); + +struct gbm_device * +gbm_bo_get_device(struct gbm_bo *bo); + +union gbm_bo_handle +gbm_bo_get_handle(struct gbm_bo *bo); + +int +gbm_bo_get_fd(struct gbm_bo *bo); + +int +gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count); + +void +gbm_bo_set_user_data(struct gbm_bo *bo, void *data, + void (*destroy_user_data)(struct gbm_bo *, void *)); + +void * +gbm_bo_get_user_data(struct gbm_bo *bo); + +void +gbm_bo_destroy(struct gbm_bo *bo); + +struct gbm_surface * +gbm_surface_create(struct gbm_device *gbm, + uint32_t width, uint32_t height, + uint32_t format, uint32_t flags); + +struct gbm_bo * +gbm_surface_lock_front_buffer(struct gbm_surface *surface); + +void +gbm_surface_release_buffer(struct gbm_surface *surface, struct gbm_bo *bo); + +int +gbm_surface_has_free_buffers(struct gbm_surface *surface); + +void +gbm_surface_destroy(struct gbm_surface *surface); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gbmint.h b/src/gbmint.h new file mode 100644 index 0000000..31345e6 --- /dev/null +++ b/src/gbmint.h @@ -0,0 +1,117 @@ +/* + * 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 + */ + +#ifndef INTERNAL_H_ +#define INTERNAL_H_ + +#include "gbm.h" +#include + +/* GCC visibility */ +#if defined(__GNUC__) && __GNUC__ >= 4 +#define GBM_EXPORT __attribute__ ((visibility("default"))) +#else +#define GBM_EXPORT +#endif + +/** + * \file gbmint.h + * \brief Internal implementation details of gbm + */ + +/** + * The device used for the memory allocation. + * + * The members of this structure should be not accessed directly + */ +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, + uint32_t format, + uint32_t usage); + + struct gbm_bo *(*bo_create)(struct gbm_device *gbm, + uint32_t width, uint32_t height, + uint32_t format, + uint32_t usage); + struct gbm_bo *(*bo_import)(struct gbm_device *gbm, uint32_t type, + void *buffer, uint32_t usage); + int (*bo_write)(struct gbm_bo *bo, const void *buf, size_t data); + int (*bo_get_fd)(struct gbm_bo *bo); + void (*bo_destroy)(struct gbm_bo *bo); + + struct gbm_surface *(*surface_create)(struct gbm_device *gbm, + uint32_t width, uint32_t height, + uint32_t format, uint32_t flags); + struct gbm_bo *(*surface_lock_front_buffer)(struct gbm_surface *surface); + void (*surface_release_buffer)(struct gbm_surface *surface, + struct gbm_bo *bo); + int (*surface_has_free_buffers)(struct gbm_surface *surface); + void (*surface_destroy)(struct gbm_surface *surface); +}; + +/** + * The allocated buffer object. + * + * The members in this structure should not be accessed directly. + */ +struct gbm_bo { + struct gbm_device *gbm; + uint32_t width; + uint32_t height; + uint32_t stride; + uint32_t format; + union gbm_bo_handle handle; + void *user_data; + void (*destroy_user_data)(struct gbm_bo *, void *); +}; + +struct gbm_surface { + struct gbm_device *gbm; + uint32_t width; + uint32_t height; + uint32_t format; + uint32_t flags; +}; + +struct gbm_backend { + const char *backend_name; + struct gbm_device *(*create_device)(int fd); +}; + +struct gbm_device * +_gbm_mesa_get_device(int fd); + +#endif -- 2.7.4 From 1e18876757478c27727401342e8ea49e24a37a74 Mon Sep 17 00:00:00 2001 From: Sangwon Ha Date: Mon, 10 Nov 2014 16:05:47 +0900 Subject: [PATCH 04/11] Cleanup packaging and pkg-config files - Move .so file to release pkg - Fix incorrect path in pkg-config file TODO: - Provides: libgbm.so should be removed by finding out which pkg requires the .so file directly Change-Id: I66cbaa1efc5265c37c3a95e6d903cd9554d58ad5 --- Makefile | 6 ++--- libgbm.manifest => packaging/libgbm.manifest | 0 packaging/libgbm.spec | 35 ++++++++++++++++------------ pkgconfig/{libgbm.pc => gbm.pc} | 8 +++---- src/backend.c | 4 ++-- 5 files changed, 28 insertions(+), 25 deletions(-) rename libgbm.manifest => packaging/libgbm.manifest (100%) rename pkgconfig/{libgbm.pc => gbm.pc} (62%) diff --git a/Makefile b/Makefile index a6d6d38..c58d1d5 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,3 @@ -prefix ?= /usr/local - GBM_SO_VER ?= no_ver SRC_DIR = ./src @@ -49,7 +47,7 @@ install: all cp $(SRC_DIR)/common_drm.h $(prefix)/include/gbm/ cp $(SRC_DIR)/common.h $(prefix)/include/gbm/ cp $(SRC_DIR)/gbmint.h $(prefix)/include/gbm/ - cp pkgconfig/libgbm.pc $(prefix)/lib/pkgconfig/ + cp pkgconfig/gbm.pc $(prefix)/lib/pkgconfig/ cp libgbm.so.$(GBM_SO_VER) $(prefix)/lib/ @for dir in $(GBM_BACKENDS_DIR) ; do \ $(MAKE) $@ -C $$dir ; \ @@ -61,7 +59,7 @@ uninstall: -rm -f $(prefix)/include/gbm/common_drm.h -rm -f $(prefix)/include/gbm/common.h -rm -f $(prefix)/include/gbm/gbmint.h - -rm -f $(prefix)/lib/pkgconfig/libgbm.pc + -rm -f $(prefix)/lib/pkgconfig/gbm.pc -rm -f $(prefix)/lib/libgbm.so.$(GBM_SO_VER) @for dir in $(GBM_BACKENDS_DIR) ; do \ $(MAKE) $@ -C $$dir ; \ diff --git a/libgbm.manifest b/packaging/libgbm.manifest similarity index 100% rename from libgbm.manifest rename to packaging/libgbm.manifest diff --git a/packaging/libgbm.spec b/packaging/libgbm.spec index e2f4fe2..628a849 100644 --- a/packaging/libgbm.spec +++ b/packaging/libgbm.spec @@ -1,14 +1,12 @@ -Summary: Wayland Generic Buffer Management for TIZEN +Summary: Wayland GBM for TIZEN Name: libgbm Version: 1.0.0s Release: 1 -Group: System/X Hardware Support -License: Unknown +Group: System/Libraries +License: MIT Source0: %{name}.tar.gz -Provides: libgbm.so.1.0.0s -Provides: libgbm.so.1 Provides: libgbm.so # Requirements @@ -23,37 +21,44 @@ Wayland Generic Buffer Management for TIZEN %package devel Summary: Development header files for use with GBM -Group: Development/Libraries +Group: System/Libraries Requires: %{name} %description devel -Development header files for use with gbm +Development header files for use with Wayland GBM %prep %setup -q -n %{name} %build -export GBM_SO_VER=1.0.0s +export GBM_SO_VER=%{version} +make clean make %install mkdir -p %{buildroot}%{_includedir} mkdir -p %{buildroot}%{_libdir}/pkgconfig -ln -sf libgbm.so.1.0.0s %{buildroot}%{_libdir}/libgbm.so -ln -sf libgbm.so.1.0.0s %{buildroot}%{_libdir}/libgbm.so.1 +ln -sf libgbm.so.%{version} %{buildroot}%{_libdir}/libgbm.so +ln -sf libgbm.so.%{version} %{buildroot}%{_libdir}/libgbm.so.1 +ln -sf libgbm.so.%{version} %{buildroot}%{_libdir}/libgbm.so.1.0 -export GBM_SO_VER=1.0.0s +export GBM_SO_VER=%{version} %makeinstall +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + %files -%manifest libgbm.manifest +%manifest packaging/libgbm.manifest %defattr(-,root,root,-) -%{_libdir}/libgbm.so.1.0.0s +%{_libdir}/libgbm.so %{_libdir}/libgbm.so.1 +%{_libdir}/libgbm.so.1.0 +%{_libdir}/libgbm.so.%{version} %files devel %defattr(-,root,root,-) %{_includedir}/gbm.h %{_includedir}/gbm/* -%{_libdir}/pkgconfig/libgbm.pc -%{_libdir}/libgbm.so +%{_libdir}/pkgconfig/gbm.pc diff --git a/pkgconfig/libgbm.pc b/pkgconfig/gbm.pc similarity index 62% rename from pkgconfig/libgbm.pc rename to pkgconfig/gbm.pc index 271ceed..9493742 100644 --- a/pkgconfig/libgbm.pc +++ b/pkgconfig/gbm.pc @@ -1,12 +1,12 @@ -prefix=/usr/local +prefix=/usr exec_prefix=${prefix} libdir=${exec_prefix}/lib includedir=${prefix}/include -Name: libgbm -Description: Mesa GBM library +Name: gbm +Description: Wayland Generic Buffer Management for TIZEN (from Mesa) +Version: 10.2.0 Requires.private: libudev >= 151 -Version: 10.2.0-devel Libs: -L${libdir} -lgbm Libs.private: -ldl Cflags: -I${includedir} diff --git a/src/backend.c b/src/backend.c index 6da2abb..a38b71f 100644 --- a/src/backend.c +++ b/src/backend.c @@ -63,7 +63,7 @@ load_backend(const struct backend_desc *backend) if (backend->builtin) { init = backend->builtin; - } else { + } else { if (name[0] != '/') snprintf(path, sizeof path, MODULEDIR "/%s", name); else @@ -122,6 +122,6 @@ _gbm_create_device(int fd) dev = backend->create_device(fd); } - + return dev; } -- 2.7.4 From 1b69fdf10c5e7a7e5b2e49e35da945f2cc791412 Mon Sep 17 00:00:00 2001 From: Sangwon Ha Date: Wed, 31 Dec 2014 18:44:36 +0900 Subject: [PATCH 05/11] Sync with codes from Mesa3D in Tizen Public - mesa commit id: f3880bb35eb8d0dbe4ba7d4a5744a135b340c821 Change-Id: I14bad6afe39963fc22adbe1e1f7c1b8c34c1a820 --- src/backend.c | 4 +++- src/gbm.c | 16 ++++++++++------ src/gbm.h | 15 ++++++++++----- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/backend.c b/src/backend.c index a38b71f..bf3f06b 100644 --- a/src/backend.c +++ b/src/backend.c @@ -36,13 +36,15 @@ #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", NULL }, + { "gbm_dri.so", &gbm_dri_backend }, { "gbm_gallium_drm.so", NULL }, { "gbm_tbm.so", NULL }, }; diff --git a/src/gbm.c b/src/gbm.c index 6179e5b..cb24e92 100644 --- a/src/gbm.c +++ b/src/gbm.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "gbm.h" #include "gbmint.h" @@ -109,7 +110,7 @@ _gbm_mesa_get_device(int fd) 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); + errno = EINVAL; return NULL; } @@ -145,7 +146,7 @@ gbm_create_device(int fd) 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); + errno = EINVAL; return NULL; } @@ -258,7 +259,7 @@ gbm_bo_get_fd(struct gbm_bo *bo) * \param bo The buffer object * \param buf The data to write * \param count The number of bytes to write - * \return Returns -1 on error, 0 otherwise + * \return Returns 0 on success, otherwise -1 is returned an errno set */ GBM_EXPORT int gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count) @@ -332,7 +333,7 @@ gbm_bo_destroy(struct gbm_bo *bo) * * \return A newly allocated buffer that should be freed with gbm_bo_destroy() * when no longer needed. If an error occurs during allocation %NULL will be - * returned. + * returned and errno set. * * \sa enum gbm_bo_format for the list of formats * \sa enum gbm_bo_flags for the list of usage flags @@ -342,8 +343,10 @@ gbm_bo_create(struct gbm_device *gbm, uint32_t width, uint32_t height, uint32_t format, uint32_t usage) { - if (width == 0 || height == 0) + if (width == 0 || height == 0) { + errno = EINVAL; return NULL; + } if (usage & GBM_BO_USE_CURSOR_64X64 && (width != 64 || height != 64)) @@ -373,7 +376,8 @@ gbm_bo_create(struct gbm_device *gbm, * \param usage The union of the usage flags for this buffer * * \return A newly allocated buffer object that should be freed with - * gbm_bo_destroy() when no longer needed. + * gbm_bo_destroy() when no longer needed. On error, %NULL is returned + * and errno is set. * * \sa enum gbm_bo_flags for the list of usage flags */ diff --git a/src/gbm.h b/src/gbm.h index 92d472a..7b23c26 100644 --- a/src/gbm.h +++ b/src/gbm.h @@ -192,10 +192,13 @@ enum gbm_bo_flags { */ GBM_BO_USE_SCANOUT = (1 << 0), /** - * Buffer is going to be used as cursor - the dimensions for the buffer - * must be 64x64 if this flag is passed. + * Buffer is going to be used as cursor */ - GBM_BO_USE_CURSOR_64X64 = (1 << 1), + GBM_BO_USE_CURSOR = (1 << 1), + /** + * Deprecated + */ + GBM_BO_USE_CURSOR_64X64 = GBM_BO_USE_CURSOR, /** * Buffer is to be used for rendering - for example it is going to be used * as the storage for a color buffer @@ -203,8 +206,7 @@ enum gbm_bo_flags { GBM_BO_USE_RENDERING = (1 << 2), /** * Buffer can be used for gbm_bo_write. This is guaranteed to work - * with GBM_BO_USE_CURSOR_64X64. but may not work for other - * combinations. + * with GBM_BO_USE_CURSOR. but may not work for other combinations. */ GBM_BO_USE_WRITE = (1 << 3), }; @@ -285,6 +287,9 @@ gbm_surface_create(struct gbm_device *gbm, uint32_t width, uint32_t height, uint32_t format, uint32_t flags); +int +gbm_surface_needs_lock_front_buffer(struct gbm_surface *surface); + struct gbm_bo * gbm_surface_lock_front_buffer(struct gbm_surface *surface); -- 2.7.4 From c08e91f7b31ea20a20177617ac5ccf19670c6b78 Mon Sep 17 00:00:00 2001 From: Sangwon Ha Date: Wed, 29 Apr 2015 14:24:38 +0900 Subject: [PATCH 06/11] Revert "Sync with codes from Mesa3D in Tizen Public" This reverts commit 0f65da9449c436b067ec8106acea36363c6612ef. Change-Id: I848c92fa62fc81002dabcac9e1d8f6e25f4c042a --- src/backend.c | 4 +--- src/gbm.c | 16 ++++++---------- src/gbm.h | 15 +++++---------- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/backend.c b/src/backend.c index bf3f06b..a38b71f 100644 --- a/src/backend.c +++ b/src/backend.c @@ -36,15 +36,13 @@ #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_dri.so", NULL }, { "gbm_gallium_drm.so", NULL }, { "gbm_tbm.so", NULL }, }; diff --git a/src/gbm.c b/src/gbm.c index cb24e92..6179e5b 100644 --- a/src/gbm.c +++ b/src/gbm.c @@ -36,7 +36,6 @@ #include #include #include -#include #include "gbm.h" #include "gbmint.h" @@ -110,7 +109,7 @@ _gbm_mesa_get_device(int fd) int i; if (fd < 0 || fstat(fd, &buf) < 0 || !S_ISCHR(buf.st_mode)) { - errno = EINVAL; + fprintf(stderr, "_gbm_mesa_get_device: invalid fd: %d\n", fd); return NULL; } @@ -146,7 +145,7 @@ gbm_create_device(int fd) struct stat buf; if (fd < 0 || fstat(fd, &buf) < 0 || !S_ISCHR(buf.st_mode)) { - errno = EINVAL; + fprintf(stderr, "gbm_create_device: invalid fd: %d\n", fd); return NULL; } @@ -259,7 +258,7 @@ gbm_bo_get_fd(struct gbm_bo *bo) * \param bo The buffer object * \param buf The data to write * \param count The number of bytes to write - * \return Returns 0 on success, otherwise -1 is returned an errno set + * \return Returns -1 on error, 0 otherwise */ GBM_EXPORT int gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count) @@ -333,7 +332,7 @@ gbm_bo_destroy(struct gbm_bo *bo) * * \return A newly allocated buffer that should be freed with gbm_bo_destroy() * when no longer needed. If an error occurs during allocation %NULL will be - * returned and errno set. + * returned. * * \sa enum gbm_bo_format for the list of formats * \sa enum gbm_bo_flags for the list of usage flags @@ -343,10 +342,8 @@ gbm_bo_create(struct gbm_device *gbm, uint32_t width, uint32_t height, uint32_t format, uint32_t usage) { - if (width == 0 || height == 0) { - errno = EINVAL; + if (width == 0 || height == 0) return NULL; - } if (usage & GBM_BO_USE_CURSOR_64X64 && (width != 64 || height != 64)) @@ -376,8 +373,7 @@ gbm_bo_create(struct gbm_device *gbm, * \param usage The union of the usage flags for this buffer * * \return A newly allocated buffer object that should be freed with - * gbm_bo_destroy() when no longer needed. On error, %NULL is returned - * and errno is set. + * gbm_bo_destroy() when no longer needed. * * \sa enum gbm_bo_flags for the list of usage flags */ diff --git a/src/gbm.h b/src/gbm.h index 7b23c26..92d472a 100644 --- a/src/gbm.h +++ b/src/gbm.h @@ -192,13 +192,10 @@ enum gbm_bo_flags { */ GBM_BO_USE_SCANOUT = (1 << 0), /** - * Buffer is going to be used as cursor + * Buffer is going to be used as cursor - the dimensions for the buffer + * must be 64x64 if this flag is passed. */ - GBM_BO_USE_CURSOR = (1 << 1), - /** - * Deprecated - */ - GBM_BO_USE_CURSOR_64X64 = GBM_BO_USE_CURSOR, + GBM_BO_USE_CURSOR_64X64 = (1 << 1), /** * Buffer is to be used for rendering - for example it is going to be used * as the storage for a color buffer @@ -206,7 +203,8 @@ enum gbm_bo_flags { GBM_BO_USE_RENDERING = (1 << 2), /** * Buffer can be used for gbm_bo_write. This is guaranteed to work - * with GBM_BO_USE_CURSOR. but may not work for other combinations. + * with GBM_BO_USE_CURSOR_64X64. but may not work for other + * combinations. */ GBM_BO_USE_WRITE = (1 << 3), }; @@ -287,9 +285,6 @@ gbm_surface_create(struct gbm_device *gbm, uint32_t width, uint32_t height, uint32_t format, uint32_t flags); -int -gbm_surface_needs_lock_front_buffer(struct gbm_surface *surface); - struct gbm_bo * gbm_surface_lock_front_buffer(struct gbm_surface *surface); -- 2.7.4 From a25867ebf3d51d4ebd1490478645f591bc65fe98 Mon Sep 17 00:00:00 2001 From: Sangwon Ha Date: Tue, 12 May 2015 19:05:50 +0900 Subject: [PATCH 07/11] Remove hard-coded path names to build for both 32- and 64-bit Change-Id: If4ff667728e586fdcecb1cccf22ba3c89a53e9ec --- Makefile | 31 +++++++++++++++---------------- packaging/libgbm.spec | 3 --- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index c58d1d5..7c07759 100644 --- a/Makefile +++ b/Makefile @@ -40,27 +40,26 @@ clean: done install: all - cp $(SRC_DIR)/gbm.h $(prefix)/include/ - -mkdir $(prefix)/include/gbm -# cp $(SRC_DIR)/gbm.h $(prefix)/include/gbm/ - cp $(SRC_DIR)/backend.h $(prefix)/include/gbm/ - cp $(SRC_DIR)/common_drm.h $(prefix)/include/gbm/ - cp $(SRC_DIR)/common.h $(prefix)/include/gbm/ - cp $(SRC_DIR)/gbmint.h $(prefix)/include/gbm/ - cp pkgconfig/gbm.pc $(prefix)/lib/pkgconfig/ - cp libgbm.so.$(GBM_SO_VER) $(prefix)/lib/ + cp $(SRC_DIR)/gbm.h $(includedir)/ + -mkdir $(includedir)/gbm/ + cp $(SRC_DIR)/backend.h $(includedir)/gbm/ + cp $(SRC_DIR)/common_drm.h $(includedir)/gbm/ + cp $(SRC_DIR)/common.h $(includedir)/gbm/ + cp $(SRC_DIR)/gbmint.h $(includedir)/gbm/ + cp pkgconfig/gbm.pc $(libdir)/pkgconfig/ + cp libgbm.so.$(GBM_SO_VER) $(libdir)/ @for dir in $(GBM_BACKENDS_DIR) ; do \ $(MAKE) $@ -C $$dir ; \ done uninstall: - -rm -f $(prefix)/include/gbm.h - -rm -f $(prefix)/include/gbm/backend.h - -rm -f $(prefix)/include/gbm/common_drm.h - -rm -f $(prefix)/include/gbm/common.h - -rm -f $(prefix)/include/gbm/gbmint.h - -rm -f $(prefix)/lib/pkgconfig/gbm.pc - -rm -f $(prefix)/lib/libgbm.so.$(GBM_SO_VER) + -rm -f $(includedir)/gbm.h + -rm -f $(includedir)/gbm/backend.h + -rm -f $(includedir)/gbm/common_drm.h + -rm -f $(includedir)/gbm/common.h + -rm -f $(includedir)/gbm/gbmint.h + -rm -f $(libdir)/pkgconfig/gbm.pc + -rm -f $(libdir)/libgbm.so.$(GBM_SO_VER) @for dir in $(GBM_BACKENDS_DIR) ; do \ $(MAKE) $@ -C $$dir ; \ done diff --git a/packaging/libgbm.spec b/packaging/libgbm.spec index 628a849..2a5c7f2 100644 --- a/packaging/libgbm.spec +++ b/packaging/libgbm.spec @@ -7,8 +7,6 @@ License: MIT Source0: %{name}.tar.gz -Provides: libgbm.so - # Requirements BuildRequires: autoconf BuildRequires: libtool @@ -32,7 +30,6 @@ Development header files for use with Wayland GBM %build export GBM_SO_VER=%{version} -make clean make %install -- 2.7.4 From 8b514e8d15ef3e1126162274c6cdca852c275d6c Mon Sep 17 00:00:00 2001 From: Sangwon Ha Date: Mon, 8 Jun 2015 15:46:44 +0900 Subject: [PATCH 08/11] Change gbm backend lookup directory to support 64-bit Change-Id: I33208f6254147b37b33c463b11c4fc1b7ae4b31a --- Makefile | 2 +- packaging/libgbm.spec | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7c07759..7caa560 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ CFLAGS += -Wall -ludev -fPIC GBM_BACKENDS_DIR = $(SRC_DIR)/backends #gbm backend module location -CFLAGS += -DMODULEDIR='"/usr/lib/gbm"' +CFLAGS += -DMODULEDIR='"$(libdir)/gbm"' #gbm main source GBM_SRCS += \ diff --git a/packaging/libgbm.spec b/packaging/libgbm.spec index 2a5c7f2..e125232 100644 --- a/packaging/libgbm.spec +++ b/packaging/libgbm.spec @@ -30,7 +30,8 @@ Development header files for use with Wayland GBM %build export GBM_SO_VER=%{version} -make +make clean +make libdir=%{_libdir} %install mkdir -p %{buildroot}%{_includedir} -- 2.7.4 From e272abc2db49f44ca25bce22d2d85294f3a4a4a1 Mon Sep 17 00:00:00 2001 From: Keeho Song Date: Tue, 21 Jul 2015 14:34:00 +0900 Subject: [PATCH 09/11] Add changes for libtpl-egl Change-Id: I70ddc3768984290acb2120e586b037cf55826f86 --- packaging/libgbm.spec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packaging/libgbm.spec b/packaging/libgbm.spec index e125232..767e3fa 100644 --- a/packaging/libgbm.spec +++ b/packaging/libgbm.spec @@ -14,6 +14,8 @@ BuildRequires: systemd-devel BuildRequires: pkgconfig(libudev) BuildRequires: libdrm-devel +Provides: libgbm.so + %description Wayland Generic Buffer Management for TIZEN -- 2.7.4 From 459733dfb5fc4a24351598e405ec624c9a061c67 Mon Sep 17 00:00:00 2001 From: Sangwon Ha Date: Tue, 21 Jul 2015 23:38:07 +0900 Subject: [PATCH 10/11] Fix build failure in dependent packages - Before, package supplied incorrect Provides field - Change .so filename to reflect un-versioned .so Change-Id: I590b2019b85dcae3f514010d5f58700e302a2b02 --- Makefile | 11 +++++------ packaging/libgbm.spec | 10 ---------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 7caa560..f5ec405 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,3 @@ -GBM_SO_VER ?= no_ver SRC_DIR = ./src #CROSS_COMPILE ?= arm-none-linux-gnueabi- @@ -23,7 +22,7 @@ GBM_SRCS += \ GBM_OBJS := $(GBM_SRCS:.c=.o) -libgbm.so.$(GBM_SO_VER): $(GBM_OBJS) +libgbm.so: $(GBM_OBJS) $(TARGET_CC) -shared -o $@ $(GBM_OBJS) $(CFLAGS) backend: @for dir in $(GBM_BACKENDS_DIR) ; do \ @@ -31,10 +30,10 @@ backend: done .DEFAULT_GOAL = all -all: libgbm.so.$(GBM_SO_VER) backend +all: libgbm.so backend clean: - -rm -f $(GBM_OBJS) libgbm.so.$(GBM_SO_VER) + -rm -f $(GBM_OBJS) libgbm.so @for dir in $(GBM_BACKENDS_DIR) ; do \ $(MAKE) $@ -C $$dir ; \ done @@ -47,7 +46,7 @@ install: all cp $(SRC_DIR)/common.h $(includedir)/gbm/ cp $(SRC_DIR)/gbmint.h $(includedir)/gbm/ cp pkgconfig/gbm.pc $(libdir)/pkgconfig/ - cp libgbm.so.$(GBM_SO_VER) $(libdir)/ + cp libgbm.so $(libdir)/ @for dir in $(GBM_BACKENDS_DIR) ; do \ $(MAKE) $@ -C $$dir ; \ done @@ -59,7 +58,7 @@ uninstall: -rm -f $(includedir)/gbm/common.h -rm -f $(includedir)/gbm/gbmint.h -rm -f $(libdir)/pkgconfig/gbm.pc - -rm -f $(libdir)/libgbm.so.$(GBM_SO_VER) + -rm -f $(libdir)/libgbm.so @for dir in $(GBM_BACKENDS_DIR) ; do \ $(MAKE) $@ -C $$dir ; \ done diff --git a/packaging/libgbm.spec b/packaging/libgbm.spec index 767e3fa..7d285cf 100644 --- a/packaging/libgbm.spec +++ b/packaging/libgbm.spec @@ -14,8 +14,6 @@ BuildRequires: systemd-devel BuildRequires: pkgconfig(libudev) BuildRequires: libdrm-devel -Provides: libgbm.so - %description Wayland Generic Buffer Management for TIZEN @@ -31,18 +29,13 @@ Development header files for use with Wayland GBM %setup -q -n %{name} %build -export GBM_SO_VER=%{version} make clean make libdir=%{_libdir} %install mkdir -p %{buildroot}%{_includedir} mkdir -p %{buildroot}%{_libdir}/pkgconfig -ln -sf libgbm.so.%{version} %{buildroot}%{_libdir}/libgbm.so -ln -sf libgbm.so.%{version} %{buildroot}%{_libdir}/libgbm.so.1 -ln -sf libgbm.so.%{version} %{buildroot}%{_libdir}/libgbm.so.1.0 -export GBM_SO_VER=%{version} %makeinstall %post -p /sbin/ldconfig @@ -53,9 +46,6 @@ export GBM_SO_VER=%{version} %manifest packaging/libgbm.manifest %defattr(-,root,root,-) %{_libdir}/libgbm.so -%{_libdir}/libgbm.so.1 -%{_libdir}/libgbm.so.1.0 -%{_libdir}/libgbm.so.%{version} %files devel %defattr(-,root,root,-) -- 2.7.4 From 2dfaa2598640473c195ea6181cb81ea124a22b07 Mon Sep 17 00:00:00 2001 From: Sangwon Ha Date: Wed, 22 Jul 2015 17:48:07 +0900 Subject: [PATCH 11/11] Match ABI with Mesa3D Change-Id: I83bc7ffa481df75bbf192359dbb212d52ab1532a --- Makefile | 14 ++++++++------ packaging/libgbm.spec | 40 +++++++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index f5ec405..a7ffe70 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ SRC_DIR = ./src +SO_NAME = libgbm.so.$(major_ver) +BIN_NAME = $(SO_NAME).$(minor_ver) #CROSS_COMPILE ?= arm-none-linux-gnueabi- TARGET_CC ?= $(CROSS_COMPILE)gcc @@ -22,18 +24,18 @@ GBM_SRCS += \ GBM_OBJS := $(GBM_SRCS:.c=.o) -libgbm.so: $(GBM_OBJS) - $(TARGET_CC) -shared -o $@ $(GBM_OBJS) $(CFLAGS) +$(BIN_NAME): $(GBM_OBJS) + $(TARGET_CC) -shared -Wl,-soname,$(SO_NAME) -o $@ $(GBM_OBJS) $(CFLAGS) backend: @for dir in $(GBM_BACKENDS_DIR) ; do \ $(MAKE) -C $$dir ; \ done .DEFAULT_GOAL = all -all: libgbm.so backend +all: $(BIN_NAME) backend clean: - -rm -f $(GBM_OBJS) libgbm.so + -rm -f $(GBM_OBJS) $(BIN_NAME) @for dir in $(GBM_BACKENDS_DIR) ; do \ $(MAKE) $@ -C $$dir ; \ done @@ -46,7 +48,7 @@ install: all cp $(SRC_DIR)/common.h $(includedir)/gbm/ cp $(SRC_DIR)/gbmint.h $(includedir)/gbm/ cp pkgconfig/gbm.pc $(libdir)/pkgconfig/ - cp libgbm.so $(libdir)/ + cp $(BIN_NAME) $(libdir)/ @for dir in $(GBM_BACKENDS_DIR) ; do \ $(MAKE) $@ -C $$dir ; \ done @@ -58,7 +60,7 @@ uninstall: -rm -f $(includedir)/gbm/common.h -rm -f $(includedir)/gbm/gbmint.h -rm -f $(libdir)/pkgconfig/gbm.pc - -rm -f $(libdir)/libgbm.so + -rm -f $(libdir)/$(BIN_NAME) @for dir in $(GBM_BACKENDS_DIR) ; do \ $(MAKE) $@ -C $$dir ; \ done diff --git a/packaging/libgbm.spec b/packaging/libgbm.spec index 7d285cf..edc2727 100644 --- a/packaging/libgbm.spec +++ b/packaging/libgbm.spec @@ -1,18 +1,19 @@ -Summary: Wayland GBM for TIZEN -Name: libgbm -Version: 1.0.0s -Release: 1 -Group: System/Libraries -License: MIT - -Source0: %{name}.tar.gz - -# Requirements -BuildRequires: autoconf -BuildRequires: libtool -BuildRequires: systemd-devel -BuildRequires: pkgconfig(libudev) -BuildRequires: libdrm-devel +%define MAJOR_VER 1 +%define MINOR_VER 0s + +Summary: Wayland GBM for TIZEN +Name: libgbm +Version: %{MAJOR_VER}.%{MINOR_VER} +Release: 1 +Group: System/Libraries +License: MIT +Source: %{name}-%{version}.tar.gz + +BuildRequires: autoconf +BuildRequires: libtool +BuildRequires: systemd-devel +BuildRequires: pkgconfig(libudev) +BuildRequires: libdrm-devel %description Wayland Generic Buffer Management for TIZEN @@ -30,13 +31,16 @@ Development header files for use with Wayland GBM %build make clean -make libdir=%{_libdir} +make libdir=%{_libdir} major_ver=%{MAJOR_VER} minor_ver=%{MINOR_VER} %install mkdir -p %{buildroot}%{_includedir} mkdir -p %{buildroot}%{_libdir}/pkgconfig -%makeinstall +%makeinstall major_ver=%{MAJOR_VER} minor_ver=%{MINOR_VER} + +ln -sf libgbm.so.%{MAJOR_VER}.%{MINOR_VER} %{buildroot}%{_libdir}/libgbm.so.%{MAJOR_VER} +ln -sf libgbm.so.%{MAJOR_VER} %{buildroot}%{_libdir}/libgbm.so %post -p /sbin/ldconfig @@ -46,6 +50,8 @@ mkdir -p %{buildroot}%{_libdir}/pkgconfig %manifest packaging/libgbm.manifest %defattr(-,root,root,-) %{_libdir}/libgbm.so +%{_libdir}/libgbm.so.%{MAJOR_VER} +%{_libdir}/libgbm.so.%{MAJOR_VER}.%{MINOR_VER} %files devel %defattr(-,root,root,-) -- 2.7.4