summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--COPYING18
-rw-r--r--ChangeLog0
-rw-r--r--Makefile.am1
-rw-r--r--NEWS0
-rw-r--r--README0
-rw-r--r--autogen.sh12
-rw-r--r--configure.ac61
-rw-r--r--packaging/libtbm-emulator.spec43
-rw-r--r--src/Makefile.am12
-rw-r--r--src/tbm_bufmgr_emulator.c282
-rw-r--r--src/tbm_emulator_log.c79
-rw-r--r--src/tbm_emulator_log.h29
13 files changed, 538 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..523ec0b
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+Stanislav Vorobiov <s.vorobiov@samsung.com>
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..52fd458
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,18 @@
+Copyright (C) 2000 - 2012 Samsung Electronics co., Ltd. All Rights Reserved.
+
+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 fur-
+nished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice 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, FIT-
+NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
+NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/ChangeLog b/ChangeLog
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/ChangeLog
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..af437a6
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = src
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/NEWS
diff --git a/README b/README
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/README
diff --git a/autogen.sh b/autogen.sh
new file mode 100644
index 0000000..904cd67
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,12 @@
+#! /bin/sh
+
+srcdir=`dirname $0`
+test -z "$srcdir" && srcdir=.
+
+ORIGDIR=`pwd`
+cd $srcdir
+
+autoreconf -v --install || exit 1
+cd $ORIGDIR || exit $?
+
+$srcdir/configure --enable-maintainer-mode "$@"
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..b4683c2
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,61 @@
+#
+# 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
+# on the rights to use, copy, modify, merge, publish, distribute, sub
+# license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL
+# ADAM JACKSON 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.
+
+AC_PREREQ(2.60)
+AC_INIT(libtbm-emulator, 1.0.0)
+AC_USE_SYSTEM_EXTENSIONS
+AC_CONFIG_SRCDIR([Makefile.am])
+AM_INIT_AUTOMAKE([dist-bzip2])
+
+AM_CONFIG_HEADER([config.h])
+
+AC_DISABLE_STATIC
+AC_PROG_LIBTOOL
+AC_PROG_CC
+
+AC_HEADER_STDC
+AC_SYS_LARGEFILE
+AC_FUNC_ALLOCA
+
+# Enable quiet compiles on automake 1.11.
+m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
+
+PKG_CHECK_MODULES(LIBDRM, libdrm)
+PKG_CHECK_MODULES(LIBDRM_VIGS, libdrm_vigs)
+PKG_CHECK_MODULES(LIBTBM, libtbm)
+
+LIBTBM_EMULATOR_CFLAGS="$LIBDRM_CFLAGS $LIBDRM_VIGS_CFLAGS $LIBTBM_CFLAGS "
+LIBTBM_EMULATOR_LIBS="$LIBDRM_LIBS $LIBDRM_VIGS_LIBS $LIBTBM_LIBS "
+AC_SUBST(LIBTBM_EMULATOR_CFLAGS)
+AC_SUBST(LIBTBM_EMULATOR_LIBS)
+
+bufmgr_dir=${libdir#*/}
+AC_SUBST(bufmgr_dir)
+
+AC_OUTPUT([
+ Makefile
+ src/Makefile])
+
+echo ""
+echo "CFLAGS : $CFLAGS"
+echo "LDFLAGS : $LDFLAGS"
+echo "LIBTBM_EMULATOR_CFLAGS : $LIBTBM_EMULATOR_CFLAGS"
+echo "LIBTBM_EMULATOR_LIBS : $LIBTBM_EMULATOR_LIBS"
+echo "bufmgr_dir : $bufmgr_dir"
+echo ""
diff --git a/packaging/libtbm-emulator.spec b/packaging/libtbm-emulator.spec
new file mode 100644
index 0000000..5761aaf
--- /dev/null
+++ b/packaging/libtbm-emulator.spec
@@ -0,0 +1,43 @@
+Name: libtbm-emulator
+Version: 0.1.0
+Release: 1
+License: MIT
+Summary: Tizen Buffer Manager - emulator backend
+Group: System/Libraries
+Source0: %{name}-%{version}.tar.gz
+
+BuildRequires: pkgconfig(pthread-stubs)
+BuildRequires: pkgconfig(libdrm)
+BuildRequires: pkgconfig(libtbm)
+
+Requires: libtbm
+Requires: libdrm2
+
+%description
+description: ${summary}
+
+%prep
+%setup -q
+
+%build
+autoreconf -vfi
+./configure --prefix=%{_prefix} --libdir=%{_libdir}/bufmgr \
+ CFLAGS="${CFLAGS} -Wall -Werror" LDFLAGS="${LDFLAGS} -Wl,--hash-style=both -Wl,--as-needed"
+
+make %{?_smp_mflags}
+
+%install
+rm -rf %{buildroot}
+
+%make_install
+
+%post
+if [ -f %{_libdir}/bufmgr/libtbm_default.so ]; then
+ rm -rf %{_libdir}/bufmgr/libtbm_default.so
+fi
+ln -s libtbm_emulator.so %{_libdir}/bufmgr/libtbm_default.so
+
+%postun -p /sbin/ldconfig
+
+%files
+%{_libdir}/bufmgr/libtbm_*.so*
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..fd662af
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,12 @@
+AM_CFLAGS = \
+ @LIBTBM_EMULATOR_CFLAGS@ \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/src
+
+libtbm_emulator_la_LTLIBRARIES = libtbm_emulator.la
+libtbm_emulator_ladir = /${bufmgr_dir}
+libtbm_emulator_la_LIBADD = @LIBTBM_EMULATOR_LIBS@
+
+libtbm_emulator_la_SOURCES = \
+ tbm_bufmgr_emulator.c \
+ tbm_emulator_log.c
diff --git a/src/tbm_bufmgr_emulator.c b/src/tbm_bufmgr_emulator.c
new file mode 100644
index 0000000..7476e92
--- /dev/null
+++ b/src/tbm_bufmgr_emulator.c
@@ -0,0 +1,282 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <tbm_bufmgr.h>
+#include <tbm_bufmgr_backend.h>
+#include "vigs.h"
+#include "tbm_emulator_log.h"
+#include <string.h>
+#include <stdlib.h>
+
+static tbm_bo_handle get_tbm_bo_handle(struct vigs_drm_gem *gem,
+ int device)
+{
+ tbm_bo_handle bo_handle;
+ int ret;
+
+ memset(&bo_handle, 0, sizeof(bo_handle));
+
+ switch (device) {
+ case TBM_DEVICE_DEFAULT:
+ case TBM_DEVICE_2D:
+ bo_handle.u32 = gem->handle;
+ break;
+ case TBM_DEVICE_CPU:
+ ret = vigs_drm_gem_map(gem, 1);
+
+ if (ret == 0) {
+ bo_handle.ptr = gem->vaddr;
+ } else {
+ TBM_EMULATOR_LOG_ERROR("vigs_drm_gem_map failed: %s",
+ strerror(-ret));
+ }
+
+ break;
+ case TBM_DEVICE_3D:
+ TBM_EMULATOR_LOG_ERROR("TBM_DEVICE_3D not supported");
+ break;
+ case TBM_DEVICE_MM:
+ TBM_EMULATOR_LOG_ERROR("TBM_DEVICE_MM not supported");
+ break;
+ default:
+ TBM_EMULATOR_LOG_ERROR("%d not supported", device);
+ break;
+ }
+
+ return bo_handle;
+}
+
+static void tbm_bufmgr_emulator_deinit(void *priv)
+{
+ struct vigs_drm_device *drm_dev = priv;
+
+ TBM_EMULATOR_LOG_DEBUG("enter");
+
+ vigs_drm_device_destroy(drm_dev);
+}
+
+static int tbm_bufmgr_emulator_bo_size(tbm_bo bo)
+{
+ struct vigs_drm_surface *sfc;
+
+ TBM_EMULATOR_LOG_DEBUG("bo = %p", bo);
+
+ sfc = (struct vigs_drm_surface*)tbm_backend_get_bo_priv(bo);
+
+ return sfc->gem.size;
+}
+
+static void *tbm_bufmgr_emulator_bo_alloc(tbm_bo bo, int size, int flags)
+{
+ TBM_EMULATOR_LOG_ERROR("not supported");
+ return NULL;
+}
+
+static void tbm_bufmgr_emulator_bo_free(tbm_bo bo)
+{
+ struct vigs_drm_surface *sfc;
+
+ TBM_EMULATOR_LOG_DEBUG("bo = %p", bo);
+
+ sfc = (struct vigs_drm_surface*)tbm_backend_get_bo_priv(bo);
+
+ vigs_drm_gem_unref(&sfc->gem);
+}
+
+static void *tbm_bufmgr_emulator_bo_import(tbm_bo bo, unsigned int key)
+{
+ struct vigs_drm_device *drm_dev;
+ int ret;
+ struct vigs_drm_surface *sfc;
+
+ TBM_EMULATOR_LOG_DEBUG("bo = %p, key = %u", bo, key);
+
+ drm_dev = (struct vigs_drm_device*)tbm_backend_get_bufmgr_priv(bo);
+
+ ret = vigs_drm_surface_open(drm_dev, key, &sfc);
+
+ if (ret != 0) {
+ TBM_EMULATOR_LOG_ERROR("vigs_drm_surface_open failed for key %u: %s",
+ key,
+ strerror(-ret));
+ return NULL;
+ }
+
+ TBM_EMULATOR_LOG_DEBUG("handle = %u", sfc->gem.handle);
+
+ return sfc;
+}
+
+static unsigned int tbm_bufmgr_emulator_bo_export(tbm_bo bo)
+{
+ struct vigs_drm_surface *sfc;
+ int ret;
+
+ TBM_EMULATOR_LOG_DEBUG("bo = %p", bo);
+
+ sfc = (struct vigs_drm_surface*)tbm_backend_get_bo_priv(bo);
+
+ ret = vigs_drm_gem_get_name(&sfc->gem);
+
+ if (ret != 0) {
+ TBM_EMULATOR_LOG_ERROR("vigs_drm_gem_get_name failed: %s",
+ strerror(-ret));
+ return 0;
+ }
+
+ return sfc->gem.name;
+}
+
+static tbm_bo_handle tbm_bufmgr_emulator_bo_get_handle(tbm_bo bo, int device)
+{
+ struct vigs_drm_surface *sfc;
+
+ TBM_EMULATOR_LOG_DEBUG("bo = %p, device = %d", bo, device);
+
+ sfc = (struct vigs_drm_surface*)tbm_backend_get_bo_priv(bo);
+
+ return get_tbm_bo_handle(&sfc->gem, device);
+}
+
+static tbm_bo_handle tbm_bufmgr_emulator_bo_map(tbm_bo bo, int device, int opt)
+{
+ struct vigs_drm_surface *sfc;
+ tbm_bo_handle handle;
+ uint32_t saf = 0;
+
+ TBM_EMULATOR_LOG_DEBUG("bo = %p, device = %d, opt = %d", bo, device, opt);
+
+ sfc = (struct vigs_drm_surface*)tbm_backend_get_bo_priv(bo);
+
+ handle = get_tbm_bo_handle(&sfc->gem, device);
+
+ if (!handle.ptr) {
+ return handle;
+ }
+
+ if ((opt & TBM_OPTION_READ) != 0) {
+ saf |= VIGS_DRM_SAF_READ;
+ }
+
+ if ((opt & TBM_OPTION_WRITE) != 0) {
+ saf |= VIGS_DRM_SAF_WRITE;
+ }
+
+ vigs_drm_surface_start_access(sfc, saf);
+
+ return handle;
+}
+
+static int tbm_bufmgr_emulator_bo_unmap(tbm_bo bo)
+{
+ struct vigs_drm_surface *sfc;
+
+ TBM_EMULATOR_LOG_DEBUG("bo = %p", bo);
+
+ sfc = (struct vigs_drm_surface*)tbm_backend_get_bo_priv(bo);
+
+ vigs_drm_surface_end_access(sfc, 1);
+
+ return 1;
+}
+
+static int tbm_bufmgr_emulator_bo_cache_flush(tbm_bo bo, int flags)
+{
+ TBM_EMULATOR_LOG_DEBUG("bo = %p, flags = %d", bo, flags);
+ return 1;
+}
+
+static int tbm_bufmgr_emulator_bo_get_global_key(tbm_bo bo)
+{
+ struct vigs_drm_surface *sfc;
+ int ret;
+
+ TBM_EMULATOR_LOG_DEBUG("bo = %p", bo);
+
+ sfc = (struct vigs_drm_surface*)tbm_backend_get_bo_priv(bo);
+
+ ret = vigs_drm_gem_get_name(&sfc->gem);
+
+ if (ret != 0) {
+ TBM_EMULATOR_LOG_ERROR("vigs_drm_gem_get_name failed: %s",
+ strerror(-ret));
+ return 0;
+ }
+
+ return sfc->gem.name;
+}
+
+MODULEINITPPROTO(tbm_bufmgr_emulator_init);
+
+static TBMModuleVersionInfo EmulatorVersRec =
+{
+ "emulator",
+ "Samsung",
+ TBM_ABI_VERSION,
+};
+
+TBMModuleData tbmModuleData = { &EmulatorVersRec, tbm_bufmgr_emulator_init };
+
+int tbm_bufmgr_emulator_init(tbm_bufmgr bufmgr, int fd)
+{
+ int ret = 0;
+ struct vigs_drm_device *drm_dev = NULL;
+ tbm_bufmgr_backend backend = NULL;
+
+ TBM_EMULATOR_LOG_DEBUG("enter");
+
+ if (!bufmgr) {
+ return 0;
+ }
+
+ ret = vigs_drm_device_create(fd, &drm_dev);
+
+ if (ret != 0) {
+ TBM_EMULATOR_LOG_ERROR("vigs_drm_device_create failed: %s", strerror(-ret));
+ goto fail;
+ }
+
+ backend = tbm_backend_alloc();
+
+ if (!backend) {
+ TBM_EMULATOR_LOG_ERROR("tbm_backend_alloc failed");
+ goto fail;
+ }
+
+ backend->flags = 0;
+ backend->priv = (void*)drm_dev;
+ backend->bufmgr_deinit = tbm_bufmgr_emulator_deinit;
+ backend->bo_size = tbm_bufmgr_emulator_bo_size;
+ backend->bo_alloc = tbm_bufmgr_emulator_bo_alloc;
+ backend->bo_free = tbm_bufmgr_emulator_bo_free;
+ backend->bo_import = tbm_bufmgr_emulator_bo_import;
+ backend->bo_export = tbm_bufmgr_emulator_bo_export;
+ backend->bo_get_handle = tbm_bufmgr_emulator_bo_get_handle;
+ backend->bo_map = tbm_bufmgr_emulator_bo_map;
+ backend->bo_unmap = tbm_bufmgr_emulator_bo_unmap;
+ backend->bo_cache_flush = tbm_bufmgr_emulator_bo_cache_flush;
+ backend->bo_get_global_key = tbm_bufmgr_emulator_bo_get_global_key;
+ backend->bo_lock = NULL;
+ backend->bo_unlock = NULL;
+
+ if (!tbm_backend_init(bufmgr, backend)) {
+ TBM_EMULATOR_LOG_ERROR("tbm_backend_init failed");
+ goto fail;
+ }
+
+ TBM_EMULATOR_LOG_INFO("initialized");
+
+ return 1;
+
+fail:
+ if (backend) {
+ tbm_backend_free(backend);
+ }
+
+ if (drm_dev) {
+ vigs_drm_device_destroy(drm_dev);
+ }
+
+ return 0;
+}
diff --git a/src/tbm_emulator_log.c b/src/tbm_emulator_log.c
new file mode 100644
index 0000000..54442b5
--- /dev/null
+++ b/src/tbm_emulator_log.c
@@ -0,0 +1,79 @@
+#include "tbm_emulator_log.h"
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+static const char *g_log_level_to_str[] =
+{
+ "OFF",
+ "ERROR",
+ "INFO",
+ "DEBUG"
+};
+
+static pthread_once_t g_log_init = PTHREAD_ONCE_INIT;
+static int g_debug_enabled = 0;
+
+static void tbm_emulator_log_init_once(void)
+{
+ char *debug_enabled_str = getenv("TBM_EMULATOR_DEBUG");
+ g_debug_enabled = debug_enabled_str ? atoi(debug_enabled_str) : 0;
+}
+
+static void tbm_emulator_log_init(void)
+{
+ pthread_once(&g_log_init, tbm_emulator_log_init_once);
+}
+
+static void tbm_emulator_log_print_current_time(void)
+{
+ char buff[128];
+ struct tm tm;
+ struct timeval tv = { 0, 0 };
+ time_t ti;
+
+ gettimeofday(&tv, NULL);
+
+ ti = tv.tv_sec;
+
+ localtime_r(&ti, &tm);
+ strftime(buff, sizeof(buff),
+ "%H:%M:%S", &tm);
+ fprintf(stderr, "%s", buff);
+}
+
+void tbm_emulator_log_event(tbm_emulator_log_level log_level,
+ const char *func,
+ int line,
+ const char *format, ...)
+{
+ va_list args;
+
+ tbm_emulator_log_init();
+
+ tbm_emulator_log_print_current_time();
+ fprintf(stderr,
+ " %-5s [%u] %s:%d",
+ g_log_level_to_str[log_level],
+ getpid(),
+ func,
+ line);
+ if (format) {
+ va_start(args, format);
+ fprintf(stderr, " - ");
+ vfprintf(stderr, format, args);
+ va_end(args);
+ }
+ fprintf(stderr, "\n");
+}
+
+int tbm_emulator_log_is_debug_enabled()
+{
+ tbm_emulator_log_init();
+
+ return g_debug_enabled;
+}
diff --git a/src/tbm_emulator_log.h b/src/tbm_emulator_log.h
new file mode 100644
index 0000000..4403f1e
--- /dev/null
+++ b/src/tbm_emulator_log.h
@@ -0,0 +1,29 @@
+#ifndef _TBM_EMULATOR_LOG_H
+#define _TBM_EMULATOR_LOG_H
+
+typedef enum
+{
+ tbm_emulator_log_level_off = 0,
+ tbm_emulator_log_level_error = 1,
+ tbm_emulator_log_level_info = 2,
+ tbm_emulator_log_level_debug = 3,
+} tbm_emulator_log_level;
+
+void tbm_emulator_log_event(tbm_emulator_log_level log_level,
+ const char *func,
+ int line,
+ const char *format, ...);
+
+int tbm_emulator_log_is_debug_enabled();
+
+#define TBM_EMULATOR_LOG_DEBUG(format, ...) \
+ do { \
+ if (tbm_emulator_log_is_debug_enabled()) { \
+ tbm_emulator_log_event(tbm_emulator_log_level_debug, __FUNCTION__, __LINE__, format,##__VA_ARGS__); \
+ } \
+ } while(0)
+
+#define TBM_EMULATOR_LOG_INFO(format, ...) tbm_emulator_log_event(tbm_emulator_log_level_info, __FUNCTION__, __LINE__, format,##__VA_ARGS__)
+#define TBM_EMULATOR_LOG_ERROR(format, ...) tbm_emulator_log_event(tbm_emulator_log_level_error, __FUNCTION__, __LINE__, format,##__VA_ARGS__)
+
+#endif