From: SooChan Lim Date: Mon, 26 Mar 2018 06:14:39 +0000 (+0900) Subject: make the new backend inteface with tbm_backend.h X-Git-Tag: submit/tizen/20180416.022856~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=05f21d03b83f13a8821cf199a0955875ff0418d9;p=platform%2Fadaptation%2Femulator%2Flibtbm-vigs.git make the new backend inteface with tbm_backend.h Change-Id: Ic0a93ec13db5661c318deb6941576f4c14ee3459 --- diff --git a/src/Makefile.am b/src/Makefile.am index 9609c5d..7db9357 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,8 +8,7 @@ libtbm_vigs_ladir = /${bufmgr_dir} libtbm_vigs_la_LIBADD = @LIBTBM_VIGS_LIBS@ libtbm_vigs_la_SOURCES = \ - tbm_bufmgr_vigs.c \ - tbm_vigs_log.c + tbm_bufmgr_vigs.c libtbm_vigs_includedir=$(includedir)/tbm-vigs -libtbm_vigs_include_HEADERS = tbm_vigs.h \ No newline at end of file +libtbm_vigs_include_HEADERS = tbm_vigs.h diff --git a/src/tbm_bufmgr_vigs.c b/src/tbm_bufmgr_vigs.c old mode 100644 new mode 100755 index 96c796d..9ea9449 --- a/src/tbm_bufmgr_vigs.c +++ b/src/tbm_bufmgr_vigs.c @@ -36,23 +36,24 @@ #include "config.h" #endif -#include -#include -#include -#include #include "vigs.h" -#include "tbm_vigs_log.h" #include #include #include #include +#include #include -#include "tbm_vigs.h" +#include +#include +#include -static struct vigs_drm_device *g_drm_dev = NULL; +#define STRERR_BUFSIZE 128 #define VIGS_DRM_NAME "vigs" +/* global singleton drm_dev. this is shared with yagl. */ +struct vigs_drm_device *g_drm_dev = NULL; + static uint32_t tbm_bufmgr_vigs_color_format_list[] = { TBM_FORMAT_RGB888, TBM_FORMAT_ARGB8888, @@ -63,13 +64,33 @@ static uint32_t tbm_bufmgr_vigs_color_format_list[] = { TBM_FORMAT_YUV420, }; +typedef struct _tbm_bufmgr_vigs *tbm_bufmgr_vigs; +typedef struct _tbm_bo_vigs *tbm_bo_vigs; + +/* tbm buffor object for vigs */ +struct _tbm_bo_vigs { + struct vigs_drm_surface *sfc; + + tbm_bufmgr_vigs bufmgr_vigs; +}; + +/* tbm bufmgr private for vigs */ +struct _tbm_bufmgr_vigs { + struct vigs_drm_device *drm_dev; + + tbm_backend_bufmgr_func *bufmgr_func; + tbm_backend_bo_func *bo_func; + + tbm_bufmgr bufmgr; +}; + static int _tbm_vigs_open_drm(void) { int fd = -1; fd = drmOpen(VIGS_DRM_NAME, NULL); if (fd < 0) { - TBM_VIGS_LOG_ERROR("open vigs drm device failed"); + TBM_ERR("open vigs drm device failed"); return -1; } @@ -81,6 +102,7 @@ static tbm_bo_handle get_tbm_bo_handle(struct vigs_drm_surface *sfc, int device) tbm_bo_handle bo_handle; int ret; struct vigs_drm_gem *gem = &sfc->gem; + char buf[STRERR_BUFSIZE]; memset(&bo_handle, 0, sizeof(bo_handle)); @@ -95,195 +117,510 @@ static tbm_bo_handle get_tbm_bo_handle(struct vigs_drm_surface *sfc, int device) if (ret == 0) bo_handle.ptr = gem->vaddr; else - TBM_VIGS_LOG_ERROR("vigs_drm_gem_map failed: %s", strerror(-ret)); + TBM_ERR("vigs_drm_gem_map failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE)); break; case TBM_DEVICE_3D: bo_handle.ptr = (void *)sfc; break; case TBM_DEVICE_MM: - TBM_VIGS_LOG_ERROR("TBM_DEVICE_MM not supported"); + TBM_ERR("TBM_DEVICE_MM not supported"); break; default: - TBM_VIGS_LOG_ERROR("%d not supported", device); + TBM_ERR("%d not supported", device); break; } return bo_handle; } -static void tbm_bufmgr_vigs_deinit(void *priv) +static tbm_bufmgr_capability +tbm_vigs_bufmgr_get_capabilities(tbm_backend_bufmgr_data *bufmgr_data, tbm_error_e *error) { - struct vigs_drm_device *drm_dev = priv; + tbm_bufmgr_capability capabilities = TBM_BUFMGR_CAPABILITY_NONE; - TBM_VIGS_LOG_DEBUG("enter"); + capabilities = TBM_BUFMGR_CAPABILITY_SHARE_KEY|TBM_BUFMGR_CAPABILITY_SHARE_FD; - if (tbm_backend_is_display_server()) { - tbm_drm_helper_wl_auth_server_deinit(); - tbm_drm_helper_unset_tbm_master_fd(); + if (error) + *error = TBM_ERROR_NONE; + + return capabilities; +} + +static tbm_error_e +tbm_vigs_bufmgr_bind_native_display(tbm_backend_bufmgr_data *bufmgr_data, tbm_native_display *native_display) +{ + tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data; + struct vigs_drm_device *drm_dev; + char *device_name; + int ret = 0; + + if (bufmgr_vigs == NULL || bufmgr_vigs->drm_dev == NULL) { + TBM_ERR("bufmgr_data is null\n"); + return TBM_ERROR_INVALID_PARAMETER; } - close(drm_dev->fd); + drm_dev = bufmgr_vigs->drm_dev; - vigs_drm_device_destroy(drm_dev); + device_name = drmGetDeviceNameFromFd(drm_dev->fd); + if (!device_name) { + TBM_ERR("drmGetDeviceNameFromFd failed"); + return TBM_ERROR_INVALID_OPERATION; + } - g_drm_dev = NULL; + ret = tbm_drm_helper_wl_auth_server_init(native_display, drm_dev->fd, device_name, 0); + if (!ret) { + TBM_ERR("tbm_drm_helper_wl_auth_server_init failed"); + free(device_name); + return TBM_ERROR_INVALID_OPERATION; + } + + free(device_name); + + return TBM_ERROR_NONE; } -static int tbm_bufmgr_vigs_bo_size(tbm_bo bo) +static tbm_error_e +tbm_vigs_bufmgr_get_supported_formats(tbm_backend_bufmgr_data *bufmgr_data, + uint32_t **formats, uint32_t *num) { - struct vigs_drm_surface *sfc; + tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data; + uint32_t *color_formats; + + if (!bufmgr_vigs) + return TBM_ERROR_INVALID_PARAMETER; - TBM_VIGS_LOG_DEBUG("bo = %p", bo); + color_formats = (uint32_t *) calloc(1, sizeof(tbm_bufmgr_vigs_color_format_list)); + if (!color_formats) + return TBM_ERROR_OUT_OF_MEMORY; - sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo); + memcpy(color_formats, tbm_bufmgr_vigs_color_format_list, sizeof(tbm_bufmgr_vigs_color_format_list)); - return sfc->gem.size; + *formats = color_formats; + *num = sizeof(tbm_bufmgr_vigs_color_format_list) / sizeof(tbm_bufmgr_vigs_color_format_list[0]); + + return TBM_ERROR_NONE; } -static void *tbm_bufmgr_vigs_bo_alloc(tbm_bo bo, int size, int flags) +static tbm_error_e +tbm_vigs_bufmgr_get_plane_data(tbm_backend_bufmgr_data *bufmgr_data, + tbm_format format, int plane_idx, int width, + int height, uint32_t * size, uint32_t * offset, + uint32_t * pitch, int *bo_idx) { + tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data; + + *size = 0; + *offset = 0; + *pitch = 0; + *bo_idx = 0; + + if (!bufmgr_vigs) + return TBM_ERROR_INVALID_PARAMETER; + + switch (format) { + case TBM_FORMAT_RGB888: + *size = width * height * 3; + *offset = 0; + *pitch = width * 3; + *bo_idx = 0; + return TBM_ERROR_NONE; + case TBM_FORMAT_XRGB8888: + case TBM_FORMAT_ARGB8888: + case TBM_FORMAT_RGBA8888: + *size = width * height * 4; + *offset = 0; + *pitch = width * 4; + *bo_idx = 0; + return TBM_ERROR_NONE; + case TBM_FORMAT_NV21: + if (plane_idx == 0) { + *size = width * height; + *offset = 0; + *pitch = width; + *bo_idx = 0; + } else if (plane_idx == 1) { + *size = width * (height >> 1); + *offset = width * height; + *pitch = width; + *bo_idx = 0; + } else { + return TBM_ERROR_INVALID_PARAMETER; + } + return TBM_ERROR_NONE; + case TBM_FORMAT_NV61: + if (plane_idx == 0) { + *size = width * height; + *offset = 0; + *pitch = width; + *bo_idx = 0; + } else if (plane_idx == 1) { + *size = width * height; + *offset = width * height; + *pitch = width; + *bo_idx = 0; + } else { + return TBM_ERROR_INVALID_PARAMETER; + } + return TBM_ERROR_NONE; + case TBM_FORMAT_YUV420: + if (plane_idx == 0) { + *size = width * height; + *offset = 0; + *pitch = width; + *bo_idx = 0; + } else if (plane_idx == 1) { + *size = (width * height) >> 2; + *offset = width * height; + *pitch = width >> 1; + *bo_idx = 0; + } else if (plane_idx == 2) { + *size = (width * height) >> 2; + *offset = (width * height) + (width * height >> 2); + *pitch = width >> 1; + *bo_idx = 0; + } else { + return TBM_ERROR_INVALID_PARAMETER; + } + return TBM_ERROR_NONE; + default: + return TBM_ERROR_INVALID_PARAMETER; + } +} + +static tbm_backend_bo_data * +tbm_vigs_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, unsigned int size, + tbm_bo_memory_type flags, tbm_error_e *error) +{ + tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data; + tbm_bo_vigs bo_vigs; struct vigs_drm_device *drm_dev; struct vigs_drm_surface *sfc; uint32_t width = 2048, height; int ret; + char buf[STRERR_BUFSIZE]; - TBM_VIGS_LOG_DEBUG("size = %d, flags = 0x%X", size, flags); + if (bufmgr_vigs == NULL || bufmgr_vigs->drm_dev == NULL) { + TBM_ERR("bufmgr_data is null\n"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return NULL; + } - drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo); + drm_dev = bufmgr_vigs->drm_dev; height = ((uint32_t) size + (width * 4) - 1) / (width * 4); ret = vigs_drm_surface_create(drm_dev, width, height, width * 4, vigs_drm_surface_bgra8888, 0, &sfc); - if (ret != 0) { - TBM_VIGS_LOG_ERROR("vigs_drm_suface_create failed: %s", strerror(-ret)); + TBM_ERR("vigs_drm_suface_create failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE)); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; return NULL; } - return sfc; -} - -static void tbm_bufmgr_vigs_bo_free(tbm_bo bo) -{ - struct vigs_drm_surface *sfc; + bo_vigs = calloc(1, sizeof(struct _tbm_bo_vigs)); + if (!bo_vigs) { + TBM_ERR("fail to allocate the bo_vigs private\n"); + vigs_drm_gem_unref(&sfc->gem); + if (error) + *error = TBM_ERROR_OUT_OF_MEMORY; + return NULL; + } + bo_vigs->bufmgr_vigs = bufmgr_vigs; + bo_vigs->sfc = sfc; - TBM_VIGS_LOG_DEBUG("bo = %p", bo); + TBM_DBG("size = %d, flags = 0x%X", size, flags); - sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo); + if (error) + *error = TBM_ERROR_NONE; - vigs_drm_gem_unref(&sfc->gem); + return (tbm_backend_bo_data *)bo_vigs; } -static void *tbm_bufmgr_vigs_bo_import(tbm_bo bo, unsigned int key) +static tbm_backend_bo_data * +tbm_bufmgr_vigs_alloc_bo_with_format(tbm_backend_bufmgr_data *bufmgr_data, int format, int bo_idx, + int width, int height, tbm_bo_memory_type flags, tbm_error_e *error) { + tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data; + tbm_bo_vigs bo_vigs; struct vigs_drm_device *drm_dev; - int ret; struct vigs_drm_surface *sfc; + int ret; + char buf[STRERR_BUFSIZE]; - TBM_VIGS_LOG_DEBUG("bo = %p, key = %u", bo, key); + if (bufmgr_vigs == NULL || bufmgr_vigs->drm_dev == NULL) { + TBM_ERR("bufmgr_data is null\n"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return NULL; + } - drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo); + if (bo_idx != 0) { + TBM_ERR("Not supported bo idx"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return NULL; + } - ret = vigs_drm_surface_open(drm_dev, key, &sfc); + drm_dev = bufmgr_vigs->drm_dev; + + switch (format) { + case TBM_FORMAT_RGB888: + ret = vigs_drm_surface_create(drm_dev, width, height, width * 3, vigs_drm_surface_bgra8888, 0, &sfc); + break; + case TBM_FORMAT_XRGB8888: + ret = vigs_drm_surface_create(drm_dev, width, height, width * 4, vigs_drm_surface_bgra8888, 0, &sfc); + break; + case TBM_FORMAT_ARGB8888: + case TBM_FORMAT_RGBA8888: + ret = vigs_drm_surface_create(drm_dev, width, height, width * 4, vigs_drm_surface_bgra8888, 0, &sfc); + break; + case TBM_FORMAT_NV21: + ret = vigs_drm_surface_create(drm_dev, width, height * 3 >> 1, width, vigs_drm_surface_bgra8888, 0, &sfc); + break; + case TBM_FORMAT_NV61: + ret = vigs_drm_surface_create(drm_dev, width, height * 2, width, vigs_drm_surface_bgra8888, 0, &sfc); + break; + case TBM_FORMAT_YUV420: + ret = vigs_drm_surface_create(drm_dev, width, height * 3 >> 1, width, vigs_drm_surface_bgra8888, 0, &sfc); + break; + default: + TBM_ERR("Not supported format"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return NULL; + } if (ret != 0) { - TBM_VIGS_LOG_ERROR("vigs_drm_surface_open failed for key %u: %s", key, strerror(-ret)); + TBM_ERR("vigs_drm_suface_create failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE)); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return NULL; + } + + bo_vigs = calloc(1, sizeof(struct _tbm_bo_vigs)); + if (!bo_vigs) { + TBM_ERR("fail to allocate the bo_vigs private\n"); + vigs_drm_gem_unref(&sfc->gem); + if (error) + *error = TBM_ERROR_OUT_OF_MEMORY; return NULL; } + bo_vigs->bufmgr_vigs = bufmgr_vigs; + bo_vigs->sfc = sfc; + + TBM_DBG("width = %d, height = %d, format = %x, flags = 0x%X bo_idx = %d", + width, height, format, flags, bo_idx); - TBM_VIGS_LOG_DEBUG("handle = %u", sfc->gem.handle); + if (error) + *error = TBM_ERROR_NONE; - return sfc; + return (tbm_backend_bo_data *)bo_vigs; } -static void *tbm_bufmgr_vigs_bo_import_fd(tbm_bo bo, tbm_fd key) +static tbm_backend_bo_data * +tbm_vigs_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_error_e *error) { + tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data; + tbm_bo_vigs bo_vigs; struct vigs_drm_device *drm_dev; struct vigs_drm_surface *sfc; int ret; + char buf[STRERR_BUFSIZE]; - TBM_VIGS_LOG_DEBUG("bo = %p, key = %d", bo, key); + if (bufmgr_vigs == NULL || bufmgr_vigs->drm_dev == NULL) { + TBM_ERR("bufmgr_data is null\n"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return NULL; + } - drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo); + drm_dev = bufmgr_vigs->drm_dev; ret = vigs_drm_prime_import_fd(drm_dev, key, &sfc); - if (ret != 0) { - TBM_VIGS_LOG_ERROR("vigs_drm_prime_import_fd failed for key %d: %s", key, strerror(-ret)); + TBM_ERR("vigs_drm_prime_import_fd failed for key %d: %s", + key, strerror_r(errno, buf, STRERR_BUFSIZE)); + if (error) + *error = TBM_ERROR_INVALID_OPERATION; + return NULL; + } + + bo_vigs = calloc(1, sizeof(struct _tbm_bo_vigs)); + if (!bo_vigs) { + TBM_ERR("fail to allocate the bo_vigs private\n"); + vigs_drm_gem_unref(&sfc->gem); + if (error) + *error = TBM_ERROR_OUT_OF_MEMORY; return NULL; } + bo_vigs->bufmgr_vigs = bufmgr_vigs; + bo_vigs->sfc = sfc; + + TBM_DBG("bo_vigs = %p, key = %u handle = %u", bo_vigs, key, sfc->gem.handle); - TBM_VIGS_LOG_DEBUG("handle = %u", sfc->gem.handle); + if (error) + *error = TBM_ERROR_NONE; - return sfc; + return (tbm_backend_bo_data *)bo_vigs; } -static unsigned int tbm_bufmgr_vigs_bo_export(tbm_bo bo) +static tbm_backend_bo_data * +tbm_vigs_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tbm_error_e *error) { - struct vigs_drm_surface *sfc; + tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data; + tbm_bo_vigs bo_vigs; + struct vigs_drm_device *drm_dev; int ret; + struct vigs_drm_surface *sfc; + char buf[STRERR_BUFSIZE]; - TBM_VIGS_LOG_DEBUG("bo = %p", bo); - - sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo); + if (bufmgr_vigs == NULL || bufmgr_vigs->drm_dev == NULL) { + TBM_ERR("bufmgr_data is null\n"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return NULL; + } - ret = vigs_drm_gem_get_name(&sfc->gem); + drm_dev = bufmgr_vigs->drm_dev; + ret = vigs_drm_surface_open(drm_dev, key, &sfc); if (ret != 0) { - TBM_VIGS_LOG_ERROR("vigs_drm_gem_get_name failed: %s", strerror(-ret)); - return 0; + TBM_ERR("vigs_drm_surface_open failed for key %u: %s", + key, strerror_r(errno, buf, STRERR_BUFSIZE)); + if (error) + *error = TBM_ERROR_INVALID_OPERATION; + return NULL; + } + + bo_vigs = calloc(1, sizeof(struct _tbm_bo_vigs)); + if (!bo_vigs) { + TBM_ERR("fail to allocate the bo_vigs private\n"); + vigs_drm_gem_unref(&sfc->gem); + if (error) + *error = TBM_ERROR_OUT_OF_MEMORY; + return NULL; } + bo_vigs->bufmgr_vigs = bufmgr_vigs; + bo_vigs->sfc = sfc; + + TBM_DBG("bo_vigs = %p, key = %u handle = %u", bo_vigs, key, sfc->gem.handle); + + if (error) + *error = TBM_ERROR_NONE; - return sfc->gem.name; + return (tbm_backend_bo_data *)bo_vigs; } -tbm_fd tbm_bufmgr_vigs_bo_export_fd(tbm_bo bo) +static void +tbm_vigs_bo_free(tbm_backend_bo_data *bo_data) { - struct vigs_drm_device *drm_dev; + tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data; struct vigs_drm_surface *sfc; - int ret, fd = 0; - TBM_VIGS_LOG_DEBUG("bo = %p", bo); + if (!bo_data) + return; - drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo); - sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo);; + TBM_DBG("bo_vigs = %p", bo_vigs); - ret = vigs_drm_prime_export_fd(drm_dev, sfc, &fd); + sfc = bo_vigs->sfc; - if (ret != 0) { - TBM_VIGS_LOG_ERROR("vigs_drm_prime_export_fd failed: %s", strerror(-ret)); + vigs_drm_gem_unref(&sfc->gem); +} + +static int +tbm_vigs_bo_get_size(tbm_backend_bo_data *bo_data, tbm_error_e *error) +{ + tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data; + struct vigs_drm_surface *sfc; + + if (!bo_vigs || !bo_vigs->sfc) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; return 0; } - return fd; + TBM_DBG("bo_vigs = %p", bo_vigs); + + if (error) + *error = TBM_ERROR_NONE; + + return sfc->gem.size; } -static tbm_bo_handle tbm_bufmgr_vigs_bo_get_handle(tbm_bo bo, int device) +static tbm_bo_memory_type +tbm_vigs_bo_get_memory_type(tbm_backend_bo_data *bo_data, tbm_error_e *error) { + tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data; + + if (!bo_vigs || !bo_vigs->sfc) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return TBM_BO_DEFAULT; + } + + if (error) + *error = TBM_ERROR_NONE; + + return TBM_BO_DEFAULT; +} + +static tbm_bo_handle +tbm_vigs_bo_get_handle(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, tbm_error_e *error) +{ + tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data; struct vigs_drm_surface *sfc; + tbm_bo_handle handle; - TBM_VIGS_LOG_DEBUG("bo = %p, device = %d", bo, device); + if (!bo_vigs || !bo_vigs->sfc) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return (tbm_bo_handle) NULL; + } + + sfc = bo_vigs->sfc; - sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo); + TBM_DBG("bo_vigs = %p, device = %d", bo_vigs, device); - return get_tbm_bo_handle(sfc, device); + handle = get_tbm_bo_handle(sfc, device); + if (!handle.ptr) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return handle; + } + + if (error) + *error = TBM_ERROR_NONE; + + return handle; } -static tbm_bo_handle tbm_bufmgr_vigs_bo_map(tbm_bo bo, int device, int opt) +static tbm_bo_handle +tbm_vigs_bo_map(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, + tbm_bo_access_option opt, tbm_error_e *error) { + tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data; struct vigs_drm_surface *sfc; tbm_bo_handle handle; uint32_t saf = 0; - TBM_VIGS_LOG_DEBUG("bo = %p, device = %d, opt = %d", bo, device, opt); + if (!bo_vigs || !bo_vigs->sfc) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return (tbm_bo_handle) NULL; + } + + sfc = bo_vigs->sfc; - sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo); + TBM_DBG("bo_vigs = %p, device = %d, opt = %d", bo_vigs, device, opt); handle = get_tbm_bo_handle(sfc, device); - - if (!handle.ptr) + if (!handle.ptr) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; return handle; + } if ((opt & TBM_OPTION_READ) != 0) saf |= VIGS_DRM_SAF_READ; @@ -293,314 +630,314 @@ static tbm_bo_handle tbm_bufmgr_vigs_bo_map(tbm_bo bo, int device, int opt) vigs_drm_surface_start_access(sfc, saf); + if (error) + *error = TBM_ERROR_NONE; + return handle; } -static int tbm_bufmgr_vigs_bo_unmap(tbm_bo bo) +static tbm_error_e +tbm_vigs_bo_unmap(tbm_backend_bo_data *bo_data) { + tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data; struct vigs_drm_surface *sfc; - TBM_VIGS_LOG_DEBUG("bo = %p", bo); + if (!bo_vigs || !bo_vigs->sfc) + return TBM_ERROR_INVALID_PARAMETER; + + sfc = bo_vigs->sfc; - sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo); + TBM_DBG("bo_vigs = %p", bo_vigs); vigs_drm_surface_end_access(sfc, 1); - return 1; + return TBM_ERROR_NONE; } -static int tbm_bufmgr_vigs_bo_lock(tbm_bo bo, int device, int opt) +static tbm_error_e +tbm_vigs_bo_lock(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, + tbm_bo_access_option opt) { - TBM_VIGS_LOG_DEBUG("bo = %p", bo); - return 1; -} + tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data; -static int tbm_bufmgr_vigs_bo_unlock(tbm_bo bo) -{ - TBM_VIGS_LOG_DEBUG("bo = %p", bo); - return 1; -} + if (!bo_vigs || !bo_vigs->sfc) + return TBM_ERROR_INVALID_PARAMETER; -static int tbm_bufmgr_vigs_surface_get_plane_data(int width, int height, tbm_format format, int plane_idx, uint32_t * size, uint32_t * offset, uint32_t * pitch, int *bo_idx) -{ - *size = 0; - *offset = 0; - *pitch = 0; - *bo_idx = 0; + TBM_DBG("bo_vigs = %p", bo_vigs); - switch (format) { - case TBM_FORMAT_RGB888: - *size = width * height * 3; - *offset = 0; - *pitch = width * 3; - *bo_idx = 0; - return 1; - case TBM_FORMAT_XRGB8888: - case TBM_FORMAT_ARGB8888: - case TBM_FORMAT_RGBA8888: - *size = width * height * 4; - *offset = 0; - *pitch = width * 4; - *bo_idx = 0; - return 1; - case TBM_FORMAT_NV21: - if (plane_idx == 0) { - *size = width * height; - *offset = 0; - *pitch = width; - *bo_idx = 0; - } else if (plane_idx == 1) { - *size = width * (height >> 1); - *offset = width * height; - *pitch = width; - *bo_idx = 0; - } else { - return 0; - } - return 1; - case TBM_FORMAT_NV61: - if (plane_idx == 0) { - *size = width * height; - *offset = 0; - *pitch = width; - *bo_idx = 0; - } else if (plane_idx == 1) { - *size = width * height; - *offset = width * height; - *pitch = width; - *bo_idx = 0; - } else { - return 0; - } - return 1; - case TBM_FORMAT_YUV420: - if (plane_idx == 0) { - *size = width * height; - *offset = 0; - *pitch = width; - *bo_idx = 0; - } else if (plane_idx == 1) { - *size = (width * height) >> 2; - *offset = width * height; - *pitch = width >> 1; - *bo_idx = 0; - } else if (plane_idx == 2) { - *size = (width * height) >> 2; - *offset = (width * height) + (width * height >> 2); - *pitch = width >> 1; - *bo_idx = 0; - } else { - return 0; - } - return 1; - default: - return 0; - } + return TBM_ERROR_NONE; } -static int tbm_bufmgr_vigs_surface_supported_format(uint32_t ** formats, uint32_t * num) +static tbm_error_e +tbm_vigs_bo_unlock(tbm_backend_bo_data *bo_data) { - uint32_t *color_formats; - - color_formats = (uint32_t *) calloc(1, sizeof(tbm_bufmgr_vigs_color_format_list)); - - if (!color_formats) - return 0; + tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data; - memcpy(color_formats, tbm_bufmgr_vigs_color_format_list, sizeof(tbm_bufmgr_vigs_color_format_list)); + if (!bo_vigs || !bo_vigs->sfc) + return TBM_ERROR_INVALID_PARAMETER; - *formats = color_formats; - *num = sizeof(tbm_bufmgr_vigs_color_format_list) / sizeof(tbm_bufmgr_vigs_color_format_list[0]); + TBM_DBG("bo_vigs = %p", bo_data); - return 1; + return TBM_ERROR_NONE; } -static int tbm_bufmgr_vigs_bind_native_display(tbm_bufmgr bufmgr, void *native_display) +tbm_fd +tbm_vigs_bo_export_fd(tbm_backend_bo_data *bo_data, tbm_error_e *error) { + tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data; + tbm_bufmgr_vigs bufmgr_vigs; + struct vigs_drm_surface *sfc; struct vigs_drm_device *drm_dev; - char *device_name; - int ret = 0; - - drm_dev = (struct vigs_drm_device *)tbm_backend_get_priv_from_bufmgr(bufmgr); + int ret, fd = 0; + char buf[STRERR_BUFSIZE]; - device_name = drmGetDeviceNameFromFd(drm_dev->fd); + if (!bo_vigs || !bo_vigs->sfc) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return -1; + } - if (!device_name) { - TBM_VIGS_LOG_ERROR("drmGetDeviceNameFromFd failed"); - return 0; + bufmgr_vigs = bo_vigs->bufmgr_vigs; + if (!bufmgr_vigs || !bufmgr_vigs->drm_dev) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return -1; } - ret = tbm_drm_helper_wl_auth_server_init(native_display, drm_dev->fd, device_name, 0); + drm_dev = bufmgr_vigs->drm_dev; + sfc = bo_vigs->sfc; - if (!ret) { - TBM_VIGS_LOG_ERROR("tbm_drm_helper_wl_auth_server_init failed"); - free(device_name); - return 0; + ret = vigs_drm_prime_export_fd(drm_dev, sfc, &fd); + if (ret != 0) { + TBM_ERR("vigs_drm_prime_export_fd failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE)); + if (error) + *error = TBM_ERROR_INVALID_OPERATION; + return -1; } - free(device_name); + TBM_DBG(" bo_vigs:%p, gem:%d(%d)\n", bo_vigs, sfc->gem); + + if (error) + *error = TBM_ERROR_NONE; - return 1; + return (tbm_fd)fd; } -static void *tbm_bufmgr_vigs_surface_bo_alloc(tbm_bo bo, int width, int height, int format, int flags, int bo_idx) +static tbm_key +tbm_vigs_bo_export_key(tbm_backend_bo_data *bo_data, tbm_error_e *error) { - struct vigs_drm_device *drm_dev; + tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data; struct vigs_drm_surface *sfc; int ret; + char buf[STRERR_BUFSIZE]; - TBM_VIGS_LOG_DEBUG("width = %d, height = %d, format = %x, flags = 0x%X bo_idx = %d", width, height, format, flags, bo_idx); + if (!bo_vigs || !bo_vigs->sfc) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return 0; + } - drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo); + sfc = bo_vigs->sfc; - if (bo_idx != 0) { - TBM_VIGS_LOG_ERROR("Not supported bo idx"); - return NULL; + ret = vigs_drm_gem_get_name(&sfc->gem); + if (ret != 0) { + TBM_ERR("vigs_drm_gem_get_name failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE)); + if (error) + *error = TBM_ERROR_INVALID_OPERATION; + return 0; } - switch (format) { - case TBM_FORMAT_RGB888: - ret = vigs_drm_surface_create(drm_dev, width, height, width * 3, vigs_drm_surface_bgra8888, 0, &sfc); - break; + TBM_DBG(" bo_vigs:%p, gem:%d(%d)\n", bo_vigs, sfc->gem); - case TBM_FORMAT_XRGB8888: - ret = vigs_drm_surface_create(drm_dev, width, height, width * 4, vigs_drm_surface_bgra8888, 0, &sfc); - break; + if (error) + *error = TBM_ERROR_NONE; - case TBM_FORMAT_ARGB8888: - case TBM_FORMAT_RGBA8888: - ret = vigs_drm_surface_create(drm_dev, width, height, width * 4, vigs_drm_surface_bgra8888, 0, &sfc); - break; + return (tbm_key)sfc->gem.name; +} - case TBM_FORMAT_NV21: - ret = vigs_drm_surface_create(drm_dev, width, height * 3 >> 1, width, vigs_drm_surface_bgra8888, 0, &sfc); - break; +static void +tbm_vigs_deinit(tbm_backend_bufmgr_data *bufmgr_data) +{ + tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data; + struct vigs_drm_device *drm_dev; + tbm_error_e error; + tbm_bufmgr bufmgr; - case TBM_FORMAT_NV61: - ret = vigs_drm_surface_create(drm_dev, width, height * 2, width, vigs_drm_surface_bgra8888, 0, &sfc); - break; + TBM_DBG("enter"); - case TBM_FORMAT_YUV420: - ret = vigs_drm_surface_create(drm_dev, width, height * 3 >> 1, width, vigs_drm_surface_bgra8888, 0, &sfc); - break; + if (!bufmgr_vigs) + return; - default: - TBM_VIGS_LOG_ERROR("Not supported format"); - return NULL; - } + drm_dev = bufmgr_vigs->drm_dev; + if (!drm_dev) + return; - if (ret != 0) { - TBM_VIGS_LOG_ERROR("vigs_drm_suface_create failed: %s", strerror(-ret)); - return NULL; - } + bufmgr = bufmgr_vigs->bufmgr; + if (!bufmgr) + return; - return sfc; -} + if (tbm_backend_bufmgr_query_display_server(bufmgr, &error)) { + tbm_drm_helper_wl_auth_server_deinit(); + tbm_drm_helper_unset_tbm_master_fd(); + } -MODULEINITPPROTO(tbm_bufmgr_vigs_init); + close(drm_dev->fd); -static TBMModuleVersionInfo EmulatorVersRec = { - "vigs", - "Samsung", - TBM_ABI_VERSION, -}; + vigs_drm_device_destroy(drm_dev); -TBMModuleData tbmModuleData = { &EmulatorVersRec, tbm_bufmgr_vigs_init }; + g_drm_dev = NULL; +} -int tbm_bufmgr_vigs_init(tbm_bufmgr bufmgr, int fd) +static tbm_backend_bufmgr_data * +tbm_vigs_init(tbm_bufmgr bufmgr, tbm_error_e *error) { + tbm_bufmgr_vigs bufmgr_vigs = NULL; + tbm_backend_bufmgr_func *bufmgr_func = NULL; + tbm_backend_bo_func *bo_func = NULL; int ret = 0; struct vigs_drm_device *drm_dev = NULL; - tbm_bufmgr_backend backend = NULL; int drm_fd = -1; + tbm_error_e err; + char buf[STRERR_BUFSIZE]; - TBM_VIGS_LOG_DEBUG("enter"); + TBM_DBG("enter"); - if (!bufmgr) - return 0; + if (!bufmgr) { + TBM_ERR("bufmgr is null.\n"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return NULL; + } - if (tbm_backend_is_display_server()) { - drm_fd = tbm_drm_helper_get_master_fd(); + bufmgr_vigs = calloc(1, sizeof(struct _tbm_bufmgr_vigs)); + if (!bufmgr_vigs) { + TBM_ERR("fail to alloc bufmgr_vigs!\n"); + if (error) + *error = TBM_ERROR_OUT_OF_MEMORY; + return NULL; + } + if (tbm_backend_bufmgr_query_display_server(bufmgr, &err)) { + drm_fd = tbm_drm_helper_get_master_fd(); if (drm_fd < 0) drm_fd = _tbm_vigs_open_drm(); if (drm_fd < 0) { - TBM_VIGS_LOG_ERROR("vigs drm device failed"); - goto fail; + TBM_ERR("vigs drm device failed"); + if (error) + *error = TBM_ERROR_INVALID_OPERATION; + goto fail_open_drm; } tbm_drm_helper_set_tbm_master_fd(drm_fd); } else { if (!tbm_drm_helper_get_auth_info(&drm_fd, NULL, NULL)) { - TBM_VIGS_LOG_ERROR("tbm_drm_helper_get_auth_info failed"); - goto fail; + TBM_ERR("tbm_drm_helper_get_auth_info failed"); + if (error) + *error = TBM_ERROR_INVALID_OPERATION; + goto fail_get_auth_info; } } ret = vigs_drm_device_create(drm_fd, &drm_dev); - if (ret != 0) { - TBM_VIGS_LOG_ERROR("vigs_drm_device_create failed: %s", strerror(-ret)); - goto fail; + TBM_ERR("vigs_drm_device_create failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE)); + if (error) + *error = TBM_ERROR_INVALID_OPERATION; + goto fail_create_vigs_drm_device; } + bufmgr_vigs->drm_dev = drm_dev; g_drm_dev = drm_dev; - backend = tbm_backend_alloc(); - - if (!backend) { - TBM_VIGS_LOG_ERROR("tbm_backend_alloc failed"); - goto fail; + /* alloc and register bufmgr_funcs */ + bufmgr_func = tbm_backend_bufmgr_alloc_bufmgr_func(bufmgr, &err); + if (!bufmgr_func) { + TBM_ERR("fail to alloc bufmgr_func! err(%d)\n", err); + if (error) + *error = TBM_ERROR_OUT_OF_MEMORY; + goto fail_alloc_bufmgr_func; } - backend->priv = (void *)drm_dev; - backend->bufmgr_deinit = tbm_bufmgr_vigs_deinit; - backend->bo_size = tbm_bufmgr_vigs_bo_size; - backend->bo_alloc = tbm_bufmgr_vigs_bo_alloc; - backend->bo_free = tbm_bufmgr_vigs_bo_free; - backend->bo_import = tbm_bufmgr_vigs_bo_import; - backend->bo_import_fd = tbm_bufmgr_vigs_bo_import_fd; - backend->bo_export = tbm_bufmgr_vigs_bo_export; - backend->bo_export_fd = tbm_bufmgr_vigs_bo_export_fd; - backend->bo_get_handle = tbm_bufmgr_vigs_bo_get_handle; - backend->bo_map = tbm_bufmgr_vigs_bo_map; - backend->bo_unmap = tbm_bufmgr_vigs_bo_unmap; - backend->bo_lock = tbm_bufmgr_vigs_bo_lock; - backend->bo_unlock = tbm_bufmgr_vigs_bo_unlock; - backend->surface_get_plane_data = tbm_bufmgr_vigs_surface_get_plane_data; - backend->surface_supported_format = tbm_bufmgr_vigs_surface_supported_format; - backend->bufmgr_bind_native_display = tbm_bufmgr_vigs_bind_native_display; - backend->surface_bo_alloc = tbm_bufmgr_vigs_surface_bo_alloc; - - if (!tbm_backend_init(bufmgr, backend)) { - TBM_VIGS_LOG_ERROR("tbm_backend_init failed"); - goto fail; + bufmgr_func->bufmgr_get_capabilities = tbm_vigs_bufmgr_get_capabilities; + bufmgr_func->bufmgr_bind_native_display = tbm_vigs_bufmgr_bind_native_display; + bufmgr_func->bufmgr_get_supported_formats = tbm_vigs_bufmgr_get_supported_formats; + bufmgr_func->bufmgr_get_plane_data = tbm_vigs_bufmgr_get_plane_data; + bufmgr_func->bufmgr_alloc_bo = tbm_vigs_bufmgr_alloc_bo; + bufmgr_func->bufmgr_alloc_bo_with_format = tbm_bufmgr_vigs_alloc_bo_with_format; + bufmgr_func->bufmgr_import_fd = tbm_vigs_bufmgr_import_fd; + bufmgr_func->bufmgr_import_key = tbm_vigs_bufmgr_import_key; + + err = tbm_backend_bufmgr_register_bufmgr_func(bufmgr, bufmgr_func); + if (err != TBM_ERROR_NONE) { + TBM_ERR("fail to register bufmgr_func! err(%d)\n", err); + if (error) + *error = TBM_ERROR_INVALID_OPERATION; + goto fail_register_bufmgr_func; + } + bufmgr_vigs->bufmgr_func = bufmgr_func; + + /* alloc and register bo_funcs */ + bo_func = tbm_backend_bufmgr_alloc_bo_func(bufmgr, &err); + if (!bo_func) { + TBM_ERR("fail to alloc bo_func! err(%d)\n", err); + if (error) + *error = TBM_ERROR_OUT_OF_MEMORY; + goto fail_alloc_bo_func; } - TBM_VIGS_LOG_INFO("initialized"); - - return 1; - - fail: - if (backend) - tbm_backend_free(backend); + bo_func->bo_free = tbm_vigs_bo_free; + bo_func->bo_get_size = tbm_vigs_bo_get_size; + bo_func->bo_get_memory_types = tbm_vigs_bo_get_memory_type; + bo_func->bo_get_handle = tbm_vigs_bo_get_handle; + bo_func->bo_map = tbm_vigs_bo_map; + bo_func->bo_unmap = tbm_vigs_bo_unmap; + bo_func->bo_lock = tbm_vigs_bo_lock; + bo_func->bo_unlock = tbm_vigs_bo_unlock; + bo_func->bo_export_fd = tbm_vigs_bo_export_fd; + bo_func->bo_export_key = tbm_vigs_bo_export_key; + + err = tbm_backend_bufmgr_register_bo_func(bufmgr, bo_func); + if (err != TBM_ERROR_NONE) { + TBM_ERR("fail to register bo_func! err(%d)\n", err); + if (error) + *error = TBM_ERROR_INVALID_OPERATION; + goto fail_register_bo_func; + } + bufmgr_vigs->bo_func = bo_func; - if (drm_dev) - vigs_drm_device_destroy(drm_dev); + TBM_INFO("initialized"); - if (drm_fd >= 0) { - if (tbm_backend_is_display_server()) - tbm_drm_helper_unset_tbm_master_fd(); + return (tbm_backend_bufmgr_data *)bufmgr_vigs; +fail_register_bo_func: + tbm_backend_bufmgr_free_bo_func(bufmgr, bo_func); +fail_alloc_bo_func: +fail_register_bufmgr_func: + tbm_backend_bufmgr_free_bufmgr_func(bufmgr, bufmgr_func); +fail_alloc_bufmgr_func: + vigs_drm_device_destroy(drm_dev); +fail_create_vigs_drm_device: + if (tbm_backend_bufmgr_query_display_server(bufmgr, &err)) + tbm_drm_helper_unset_tbm_master_fd(); + if (drm_fd >= 0) close(drm_fd); - } - +fail_get_auth_info: +fail_open_drm: + if (bufmgr_vigs) + free(bufmgr_vigs); g_drm_dev = NULL; - - return 0; + return NULL; } +tbm_backend_module tbm_backend_module_data = { + "vigs", + "Samsung", + TBM_BACKEND_ABI_VERSION_2_0, + tbm_vigs_init, + tbm_vigs_deinit +}; + struct vigs_drm_device * tbm_vigs_get_drm_dev(void) { diff --git a/src/tbm_vigs_log.c b/src/tbm_vigs_log.c deleted file mode 100644 index d45097d..0000000 --- a/src/tbm_vigs_log.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * libtbm-vigs log - * - * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact : - * Stanislav Vorobiov - * Jinhyung Jo - * Sangho Park - * YeongKyoon Lee - * - * 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 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. - * - * Contributors: - * - S-Core Co., Ltd - * - */ - -#include "tbm_vigs_log.h" -#include -#include -#include -#include -#include -#include -#include - -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_vigs_log_init_once(void) -{ - char *debug_enabled_str = getenv("TBM_VIGS_DEBUG"); - g_debug_enabled = debug_enabled_str ? atoi(debug_enabled_str) : 0; -} - -static void tbm_vigs_log_init(void) -{ - pthread_once(&g_log_init, tbm_vigs_log_init_once); -} - -static void tbm_vigs_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_vigs_log_event(tbm_vigs_log_level log_level, const char *func, int line, const char *format, ...) -{ - va_list args; - - tbm_vigs_log_init(); - - tbm_vigs_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_vigs_log_is_debug_enabled() -{ - tbm_vigs_log_init(); - - return g_debug_enabled; -} diff --git a/src/tbm_vigs_log.h b/src/tbm_vigs_log.h deleted file mode 100644 index a97f57e..0000000 --- a/src/tbm_vigs_log.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * libtbm-vigs log header - * - * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact : - * Stanislav Vorobiov - * Jinhyung Jo - * Sangho Park - * YeongKyoon Lee - * - * 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 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. - * - * Contributors: - * - S-Core Co., Ltd - * - */ - -#ifndef _TBM_VIGS_LOG_H -#define _TBM_VIGS_LOG_H - -typedef enum { - tbm_vigs_log_level_off = 0, - tbm_vigs_log_level_error = 1, - tbm_vigs_log_level_info = 2, - tbm_vigs_log_level_debug = 3, -} tbm_vigs_log_level; - -void tbm_vigs_log_event(tbm_vigs_log_level log_level, const char *func, int line, const char *format, ...); - -int tbm_vigs_log_is_debug_enabled(); - -#define TBM_VIGS_LOG_DEBUG(format, ...) \ - do { \ - if (tbm_vigs_log_is_debug_enabled()) { \ - tbm_vigs_log_event(tbm_vigs_log_level_debug, __FUNCTION__, __LINE__, format, ##__VA_ARGS__); \ - } \ - } while (0) - -#define TBM_VIGS_LOG_INFO(format, ...) tbm_vigs_log_event(tbm_vigs_log_level_info, __FUNCTION__, __LINE__, format, ##__VA_ARGS__) -#define TBM_VIGS_LOG_ERROR(format, ...) tbm_vigs_log_event(tbm_vigs_log_level_error, __FUNCTION__, __LINE__, format, ##__VA_ARGS__) - -#endif