summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanislav Vorobiov <s.vorobiov@samsung.com>2013-05-31 18:24:31 +0400
committerStanislav Vorobiov <s.vorobiov@samsung.com>2013-05-31 18:24:31 +0400
commiteaeaedaa3e4235385914dba0ce9fcb0925fa8c9b (patch)
treeb4f747e451464a22d09b229fe61068f9334de271
parent1f7132bd31593eecca790aa943ae151453b41626 (diff)
downloadlibtbm-vigs-eaeaedaa3e4235385914dba0ce9fcb0925fa8c9b.tar.gz
libtbm-vigs-eaeaedaa3e4235385914dba0ce9fcb0925fa8c9b.tar.bz2
libtbm-vigs-eaeaedaa3e4235385914dba0ce9fcb0925fa8c9b.zip
Dummy driver implemented
Change-Id: I0d8695f55fb160c1ddcb094d64e7ea3fd96360eb
-rw-r--r--configure.ac5
-rw-r--r--src/Makefile.am3
-rw-r--r--src/tbm_bufmgr_emulator.c151
-rw-r--r--src/tbm_emulator_log.c79
-rw-r--r--src/tbm_emulator_log.h29
5 files changed, 264 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index 603227f..b4683c2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,10 +37,11 @@ AC_FUNC_ALLOCA
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 $LIBTBM_CFLAGS "
-LIBTBM_EMULATOR_LIBS="$LIBDRM_LIBS $LIBTBM_LIBS "
+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)
diff --git a/src/Makefile.am b/src/Makefile.am
index 9e7f1e6..fd662af 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,4 +8,5 @@ libtbm_emulator_ladir = /${bufmgr_dir}
libtbm_emulator_la_LIBADD = @LIBTBM_EMULATOR_LIBS@
libtbm_emulator_la_SOURCES = \
- tbm_bufmgr_emulator.c
+ tbm_bufmgr_emulator.c \
+ tbm_emulator_log.c
diff --git a/src/tbm_bufmgr_emulator.c b/src/tbm_bufmgr_emulator.c
index e69de29..5ec6444 100644
--- a/src/tbm_bufmgr_emulator.c
+++ b/src/tbm_bufmgr_emulator.c
@@ -0,0 +1,151 @@
+#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>
+
+static void tbm_bufmgr_emulator_deinit(void *priv)
+{
+ TBM_EMULATOR_LOG_DEBUG("enter");
+}
+
+static int tbm_bufmgr_emulator_bo_size(tbm_bo bo)
+{
+ TBM_EMULATOR_LOG_DEBUG("enter");
+ return 0;
+}
+
+static void *tbm_bufmgr_emulator_bo_alloc(tbm_bo bo, int size, int flags)
+{
+ TBM_EMULATOR_LOG_DEBUG("enter");
+ return NULL;
+}
+
+static void tbm_bufmgr_emulator_bo_free(tbm_bo bo)
+{
+ TBM_EMULATOR_LOG_DEBUG("enter");
+}
+
+static void *tbm_bufmgr_emulator_bo_import(tbm_bo bo, unsigned int key)
+{
+ TBM_EMULATOR_LOG_DEBUG("enter");
+ return NULL;
+}
+
+static unsigned int tbm_bufmgr_emulator_bo_export(tbm_bo bo)
+{
+ TBM_EMULATOR_LOG_DEBUG("enter");
+ return 0;
+}
+
+static tbm_bo_handle tbm_bufmgr_emulator_bo_get_handle(tbm_bo bo, int device)
+{
+ tbm_bo_handle handle;
+ handle.ptr = NULL;
+ TBM_EMULATOR_LOG_DEBUG("enter");
+ return handle;
+}
+
+static tbm_bo_handle tbm_bufmgr_emulator_bo_map(tbm_bo bo, int device, int opt)
+{
+ tbm_bo_handle handle;
+ handle.ptr = NULL;
+ TBM_EMULATOR_LOG_DEBUG("enter");
+ return handle;
+}
+
+static int tbm_bufmgr_emulator_bo_unmap(tbm_bo bo)
+{
+ TBM_EMULATOR_LOG_DEBUG("enter");
+ return 0;
+}
+
+static int tbm_bufmgr_emulator_bo_cache_flush(tbm_bo bo, int flags)
+{
+ TBM_EMULATOR_LOG_DEBUG("enter");
+ return 0;
+}
+
+static int tbm_bufmgr_emulator_bo_get_global_key(tbm_bo bo)
+{
+ TBM_EMULATOR_LOG_DEBUG("enter");
+ return 0;
+}
+
+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