diff options
author | Changyeon Lee <cyeon.lee@samsung.com> | 2016-08-22 15:40:34 +0900 |
---|---|---|
committer | Changyeon Lee <cyeon.lee@samsung.com> | 2016-08-22 15:40:34 +0900 |
commit | d56e53199939ce3292151fde9201baecb9a396f0 (patch) | |
tree | 7fc1600ed1d374abb5d5449bfe39658dd608bd05 | |
parent | 9dcca676edd1ce9d5eccd9943861a2bfa20eae12 (diff) | |
download | libtbm-vigs-d56e53199939ce3292151fde9201baecb9a396f0.tar.gz libtbm-vigs-d56e53199939ce3292151fde9201baecb9a396f0.tar.bz2 libtbm-vigs-d56e53199939ce3292151fde9201baecb9a396f0.zip |
Apply tizen coding rulesubmit/tizen_unified/20170308.100403submit/tizen_3.0_wearable/20161015.000004submit/tizen_3.0_tv/20161015.000003submit/tizen_3.0_mobile/20161015.000004submit/tizen_3.0_ivi/20161010.000004submit/tizen_3.0_common/20161104.104000submit/tizen_3.0.m2/20170104.093748submit/tizen/20160823.022539accepted/tizen/wearable/20160824.055101accepted/tizen/unified/20170309.031135accepted/tizen/tv/20160824.055033accepted/tizen/mobile/20160824.054938accepted/tizen/ivi/20160824.055128accepted/tizen/common/20160824.154206accepted/tizen/3.0/wearable/20161015.083606accepted/tizen/3.0/tv/20161016.004939accepted/tizen/3.0/mobile/20161015.033705accepted/tizen/3.0/ivi/20161011.050540accepted/tizen/3.0/common/20161114.105036accepted/tizen/3.0.m2/wearable/20170104.100959accepted/tizen/3.0.m2/tv/20170104.100414accepted/tizen/3.0.m2/mobile/20170104.100228tizen_3.0_tvtizen_3.0.m2accepted/tizen_3.0.m2_wearableaccepted/tizen_3.0.m2_tvaccepted/tizen_3.0.m2_mobile
Change-Id: I9d3a70d5fc2b976db8b96bdf33ca3b82ba9bfccf
-rwxr-xr-x | src/tbm_bufmgr_emulator.c | 836 | ||||
-rw-r--r-- | src/tbm_emulator_log.c | 72 | ||||
-rw-r--r-- | src/tbm_emulator_log.h | 30 |
3 files changed, 435 insertions, 503 deletions
diff --git a/src/tbm_bufmgr_emulator.c b/src/tbm_bufmgr_emulator.c index 20283b0..5af6783 100755 --- a/src/tbm_bufmgr_emulator.c +++ b/src/tbm_bufmgr_emulator.c @@ -50,598 +50,544 @@ #define VIGS_DRM_NAME "vigs" -static uint32_t tbm_bufmgr_emulator_color_format_list[] = -{ - TBM_FORMAT_RGB888, - TBM_FORMAT_ARGB8888, - TBM_FORMAT_RGBA8888, - TBM_FORMAT_XRGB8888, - TBM_FORMAT_NV21, - TBM_FORMAT_NV61, - TBM_FORMAT_YUV420, +static uint32_t tbm_bufmgr_emulator_color_format_list[] = { + TBM_FORMAT_RGB888, + TBM_FORMAT_ARGB8888, + TBM_FORMAT_RGBA8888, + TBM_FORMAT_XRGB8888, + TBM_FORMAT_NV21, + TBM_FORMAT_NV61, + TBM_FORMAT_YUV420, }; static int _tbm_vigs_open_drm(void) { - int fd = -1; + int fd = -1; - fd = drmOpen(VIGS_DRM_NAME, NULL); - if (fd < 0) { - TBM_EMULATOR_LOG_ERROR ("open vigs drm device failed"); - return -1; - } + fd = drmOpen(VIGS_DRM_NAME, NULL); + if (fd < 0) { + TBM_EMULATOR_LOG_ERROR("open vigs drm device failed"); + return -1; + } - return fd; + return fd; } -static tbm_bo_handle get_tbm_bo_handle(struct vigs_drm_gem *gem, - int device) +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; + 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; + struct vigs_drm_device *drm_dev = priv; - TBM_EMULATOR_LOG_DEBUG("enter"); + TBM_EMULATOR_LOG_DEBUG("enter"); - if (tbm_backend_is_display_server()) { - tbm_drm_helper_wl_auth_server_deinit(); - tbm_drm_helper_unset_tbm_master_fd(); - } + if (tbm_backend_is_display_server()) { + tbm_drm_helper_wl_auth_server_deinit(); + tbm_drm_helper_unset_tbm_master_fd(); + } - close(drm_dev->fd); + close(drm_dev->fd); - vigs_drm_device_destroy(drm_dev); + vigs_drm_device_destroy(drm_dev); } static int tbm_bufmgr_emulator_bo_size(tbm_bo bo) { - struct vigs_drm_surface *sfc; + struct vigs_drm_surface *sfc; - TBM_EMULATOR_LOG_DEBUG("bo = %p", bo); + TBM_EMULATOR_LOG_DEBUG("bo = %p", bo); - sfc = (struct vigs_drm_surface*)tbm_backend_get_bo_priv(bo); + sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo); - return sfc->gem.size; + return sfc->gem.size; } static void *tbm_bufmgr_emulator_bo_alloc(tbm_bo bo, int size, int flags) { - struct vigs_drm_device *drm_dev; - struct vigs_drm_surface *sfc; - uint32_t width = 2048, height; - int ret; + struct vigs_drm_device *drm_dev; + struct vigs_drm_surface *sfc; + uint32_t width = 2048, height; + int ret; - TBM_EMULATOR_LOG_DEBUG("size = %d, flags = 0x%X", size, flags); + TBM_EMULATOR_LOG_DEBUG("size = %d, flags = 0x%X", size, flags); - drm_dev = (struct vigs_drm_device*)tbm_backend_get_bufmgr_priv(bo); + drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo); - height = ((uint32_t)size + (width * 4) - 1) / (width * 4); + 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); + ret = vigs_drm_surface_create(drm_dev, width, height, width * 4, vigs_drm_surface_bgra8888, 0, &sfc); - if (ret != 0) { - TBM_EMULATOR_LOG_ERROR("vigs_drm_suface_create failed: %s", - strerror(-ret)); - return NULL; - } + if (ret != 0) { + TBM_EMULATOR_LOG_ERROR("vigs_drm_suface_create failed: %s", strerror(-ret)); + return NULL; + } - return sfc; + return sfc; } static void tbm_bufmgr_emulator_bo_free(tbm_bo bo) { - struct vigs_drm_surface *sfc; + struct vigs_drm_surface *sfc; - TBM_EMULATOR_LOG_DEBUG("bo = %p", bo); + TBM_EMULATOR_LOG_DEBUG("bo = %p", bo); - sfc = (struct vigs_drm_surface*)tbm_backend_get_bo_priv(bo); + sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo); - vigs_drm_gem_unref(&sfc->gem); + 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; + struct vigs_drm_device *drm_dev; + int ret; + struct vigs_drm_surface *sfc; - TBM_EMULATOR_LOG_DEBUG("bo = %p, key = %u", bo, key); + TBM_EMULATOR_LOG_DEBUG("bo = %p, key = %u", bo, key); - drm_dev = (struct vigs_drm_device*)tbm_backend_get_bufmgr_priv(bo); + drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo); - ret = vigs_drm_surface_open(drm_dev, key, &sfc); + 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; - } + 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); + TBM_EMULATOR_LOG_DEBUG("handle = %u", sfc->gem.handle); - return sfc; + return sfc; } static void *tbm_bufmgr_emulator_bo_import_fd(tbm_bo bo, tbm_fd key) { - struct vigs_drm_device *drm_dev; - struct vigs_drm_surface *sfc; - int ret; + struct vigs_drm_device *drm_dev; + struct vigs_drm_surface *sfc; + int ret; - TBM_EMULATOR_LOG_DEBUG("bo = %p, key = %d", bo, key); + TBM_EMULATOR_LOG_DEBUG("bo = %p, key = %d", bo, key); - drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo); + drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo); - ret = vigs_drm_prime_import_fd(drm_dev, key, &sfc); + ret = vigs_drm_prime_import_fd(drm_dev, key, &sfc); - if (ret != 0) { - TBM_EMULATOR_LOG_ERROR("vigs_drm_prime_import_fd failed for key %d: %s", - key, - strerror(-ret)); - return NULL; - } + if (ret != 0) { + TBM_EMULATOR_LOG_ERROR("vigs_drm_prime_import_fd failed for key %d: %s", key, strerror(-ret)); + return NULL; + } - TBM_EMULATOR_LOG_DEBUG("handle = %u", sfc->gem.handle); + TBM_EMULATOR_LOG_DEBUG("handle = %u", sfc->gem.handle); - return sfc; + return sfc; } - static unsigned int tbm_bufmgr_emulator_bo_export(tbm_bo bo) { - struct vigs_drm_surface *sfc; - int ret; + struct vigs_drm_surface *sfc; + int ret; - TBM_EMULATOR_LOG_DEBUG("bo = %p", bo); + TBM_EMULATOR_LOG_DEBUG("bo = %p", bo); - sfc = (struct vigs_drm_surface*)tbm_backend_get_bo_priv(bo); + sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo); - ret = vigs_drm_gem_get_name(&sfc->gem); + 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; - } + if (ret != 0) { + TBM_EMULATOR_LOG_ERROR("vigs_drm_gem_get_name failed: %s", strerror(-ret)); + return 0; + } - return sfc->gem.name; + return sfc->gem.name; } tbm_fd tbm_bufmgr_emulator_bo_export_fd(tbm_bo bo) { - struct vigs_drm_device *drm_dev; - struct vigs_drm_surface *sfc; - int ret, fd = 0; + struct vigs_drm_device *drm_dev; + struct vigs_drm_surface *sfc; + int ret, fd = 0; - TBM_EMULATOR_LOG_DEBUG("bo = %p", bo); + TBM_EMULATOR_LOG_DEBUG("bo = %p", bo); - drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo); - sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo);; + drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo); + sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo);; - ret = vigs_drm_prime_export_fd(drm_dev, sfc, &fd); + ret = vigs_drm_prime_export_fd(drm_dev, sfc, &fd); - if (ret != 0) { - TBM_EMULATOR_LOG_ERROR("vigs_drm_prime_export_fd failed: %s", - strerror(-ret)); - return 0; - } + if (ret != 0) { + TBM_EMULATOR_LOG_ERROR("vigs_drm_prime_export_fd failed: %s", strerror(-ret)); + return 0; + } - return fd; + return fd; } static tbm_bo_handle tbm_bufmgr_emulator_bo_get_handle(tbm_bo bo, int device) { - struct vigs_drm_surface *sfc; + struct vigs_drm_surface *sfc; - TBM_EMULATOR_LOG_DEBUG("bo = %p, device = %d", bo, device); + TBM_EMULATOR_LOG_DEBUG("bo = %p, device = %d", bo, device); - sfc = (struct vigs_drm_surface*)tbm_backend_get_bo_priv(bo); + sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo); - return get_tbm_bo_handle(&sfc->gem, device); + 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; + 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); + TBM_EMULATOR_LOG_DEBUG("bo = %p, device = %d, opt = %d", bo, device, opt); - sfc = (struct vigs_drm_surface*)tbm_backend_get_bo_priv(bo); + sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo); - handle = get_tbm_bo_handle(&sfc->gem, device); + handle = get_tbm_bo_handle(&sfc->gem, device); - if (!handle.ptr) { - return handle; - } + if (!handle.ptr) + return handle; - if ((opt & TBM_OPTION_READ) != 0) { - saf |= VIGS_DRM_SAF_READ; - } + if ((opt & TBM_OPTION_READ) != 0) + saf |= VIGS_DRM_SAF_READ; - if ((opt & TBM_OPTION_WRITE) != 0) { - saf |= VIGS_DRM_SAF_WRITE; - } + if ((opt & TBM_OPTION_WRITE) != 0) + saf |= VIGS_DRM_SAF_WRITE; - vigs_drm_surface_start_access(sfc, saf); + vigs_drm_surface_start_access(sfc, saf); - return handle; + return handle; } static int tbm_bufmgr_emulator_bo_unmap(tbm_bo bo) { - struct vigs_drm_surface *sfc; + struct vigs_drm_surface *sfc; - TBM_EMULATOR_LOG_DEBUG("bo = %p", bo); + TBM_EMULATOR_LOG_DEBUG("bo = %p", bo); - sfc = (struct vigs_drm_surface*)tbm_backend_get_bo_priv(bo); + sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo); - vigs_drm_surface_end_access(sfc, 1); + vigs_drm_surface_end_access(sfc, 1); - return 1; + return 1; } static int tbm_bufmgr_emulator_bo_lock(tbm_bo bo, int device, int opt) { - TBM_EMULATOR_LOG_DEBUG("bo = %p", bo); - return 1; + TBM_EMULATOR_LOG_DEBUG("bo = %p", bo); + return 1; } static int tbm_bufmgr_emulator_bo_unlock(tbm_bo bo) { - TBM_EMULATOR_LOG_DEBUG("bo = %p", bo); - return 1; + TBM_EMULATOR_LOG_DEBUG("bo = %p", bo); + return 1; } -static int tbm_bufmgr_emulator_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) +static int tbm_bufmgr_emulator_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; - - 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; - } + *size = 0; + *offset = 0; + *pitch = 0; + *bo_idx = 0; + + 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; + } } -static int tbm_bufmgr_emulator_surface_supported_format(uint32_t **formats, uint32_t *num) +static int tbm_bufmgr_emulator_surface_supported_format(uint32_t ** formats, uint32_t * num) { - uint32_t *color_formats; + uint32_t *color_formats; - color_formats = (uint32_t*)calloc(1, sizeof(tbm_bufmgr_emulator_color_format_list)); + color_formats = (uint32_t *) calloc(1, sizeof(tbm_bufmgr_emulator_color_format_list)); - if (!color_formats) { - return 0; - } + if (!color_formats) + return 0; - memcpy(color_formats, - tbm_bufmgr_emulator_color_format_list, - sizeof(tbm_bufmgr_emulator_color_format_list)); + memcpy(color_formats, tbm_bufmgr_emulator_color_format_list, sizeof(tbm_bufmgr_emulator_color_format_list)); - *formats = color_formats; - *num = sizeof(tbm_bufmgr_emulator_color_format_list)/sizeof(tbm_bufmgr_emulator_color_format_list[0]); + *formats = color_formats; + *num = sizeof(tbm_bufmgr_emulator_color_format_list) / sizeof(tbm_bufmgr_emulator_color_format_list[0]); - return 1; + return 1; } -static int -tbm_bufmgr_emulator_bind_native_display (tbm_bufmgr bufmgr, void *native_display) +static int tbm_bufmgr_emulator_bind_native_display(tbm_bufmgr bufmgr, void *native_display) { - struct vigs_drm_device *drm_dev; - char *device_name; - int ret = 0; + 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); + drm_dev = (struct vigs_drm_device *)tbm_backend_get_priv_from_bufmgr(bufmgr); - device_name = drmGetDeviceNameFromFd(drm_dev->fd); + device_name = drmGetDeviceNameFromFd(drm_dev->fd); - if (!device_name) { - TBM_EMULATOR_LOG_ERROR("drmGetDeviceNameFromFd failed"); - return 0; - } + if (!device_name) { + TBM_EMULATOR_LOG_ERROR("drmGetDeviceNameFromFd failed"); + return 0; + } - ret = tbm_drm_helper_wl_auth_server_init(native_display, drm_dev->fd, device_name, 0); + ret = tbm_drm_helper_wl_auth_server_init(native_display, drm_dev->fd, device_name, 0); - if (!ret) { - TBM_EMULATOR_LOG_ERROR("tbm_drm_helper_wl_auth_server_init failed"); - free(device_name); - return 0; - } + if (!ret) { + TBM_EMULATOR_LOG_ERROR("tbm_drm_helper_wl_auth_server_init failed"); + free(device_name); + return 0; + } - free(device_name); + free(device_name); - return 1; + return 1; } static void *tbm_bufmgr_emulator_surface_bo_alloc(tbm_bo bo, int width, int height, int format, int flags, int bo_idx) { - struct vigs_drm_device *drm_dev; - struct vigs_drm_surface *sfc; - int ret; - - TBM_EMULATOR_LOG_DEBUG("width = %d, height = %d, format = %x, flags = 0x%X bo_idx = %d", width, height, format, flags, bo_idx); - - drm_dev = (struct vigs_drm_device*)tbm_backend_get_bufmgr_priv(bo); - - if (bo_idx != 0) { - TBM_EMULATOR_LOG_ERROR ("Not supported bo idx"); - return NULL; - } - - 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_EMULATOR_LOG_ERROR ("Not supported format"); - return NULL; - } - - if (ret != 0) { - TBM_EMULATOR_LOG_ERROR("vigs_drm_suface_create failed: %s", - strerror(-ret)); - return NULL; - } - - return sfc; + struct vigs_drm_device *drm_dev; + struct vigs_drm_surface *sfc; + int ret; + + TBM_EMULATOR_LOG_DEBUG("width = %d, height = %d, format = %x, flags = 0x%X bo_idx = %d", width, height, format, flags, bo_idx); + + drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo); + + if (bo_idx != 0) { + TBM_EMULATOR_LOG_ERROR("Not supported bo idx"); + return NULL; + } + + 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_EMULATOR_LOG_ERROR("Not supported format"); + return NULL; + } + + if (ret != 0) { + TBM_EMULATOR_LOG_ERROR("vigs_drm_suface_create failed: %s", strerror(-ret)); + return NULL; + } + + return sfc; } MODULEINITPPROTO(tbm_bufmgr_emulator_init); -static TBMModuleVersionInfo EmulatorVersRec = -{ - "emulator", - "Samsung", - TBM_ABI_VERSION, +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; - int drm_fd = -1; - - TBM_EMULATOR_LOG_DEBUG("enter"); - - if (!bufmgr) { - return 0; - } - - if (tbm_backend_is_display_server()) { - drm_fd = tbm_drm_helper_get_master_fd(); - - if (drm_fd < 0) { - drm_fd = _tbm_vigs_open_drm(); - } - - if (drm_fd < 0) { - TBM_EMULATOR_LOG_ERROR ("vigs drm device failed"); - goto fail; - } - - tbm_drm_helper_set_tbm_master_fd(drm_fd); - - } else { - if (!tbm_drm_helper_get_auth_info(&drm_fd, NULL, NULL)) { - TBM_EMULATOR_LOG_ERROR ("tbm_drm_helper_get_auth_info failed"); - goto fail; - } - } - - ret = vigs_drm_device_create(drm_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->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_import_fd = tbm_bufmgr_emulator_bo_import_fd; - backend->bo_export = tbm_bufmgr_emulator_bo_export; - backend->bo_export_fd = tbm_bufmgr_emulator_bo_export_fd; - 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_lock = tbm_bufmgr_emulator_bo_lock; - backend->bo_unlock = tbm_bufmgr_emulator_bo_unlock; - backend->surface_get_plane_data = tbm_bufmgr_emulator_surface_get_plane_data; - backend->surface_supported_format = tbm_bufmgr_emulator_surface_supported_format; - backend->bufmgr_bind_native_display = tbm_bufmgr_emulator_bind_native_display; - backend->surface_bo_alloc = tbm_bufmgr_emulator_surface_bo_alloc; - - 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); - } - - if (drm_fd >= 0) { - if (tbm_backend_is_display_server()) { - tbm_drm_helper_unset_tbm_master_fd(); - } - - close(drm_fd); - } - - return 0; + int ret = 0; + struct vigs_drm_device *drm_dev = NULL; + tbm_bufmgr_backend backend = NULL; + int drm_fd = -1; + + TBM_EMULATOR_LOG_DEBUG("enter"); + + if (!bufmgr) + return 0; + + if (tbm_backend_is_display_server()) { + drm_fd = tbm_drm_helper_get_master_fd(); + + if (drm_fd < 0) + drm_fd = _tbm_vigs_open_drm(); + + if (drm_fd < 0) { + TBM_EMULATOR_LOG_ERROR("vigs drm device failed"); + goto fail; + } + + tbm_drm_helper_set_tbm_master_fd(drm_fd); + + } else { + if (!tbm_drm_helper_get_auth_info(&drm_fd, NULL, NULL)) { + TBM_EMULATOR_LOG_ERROR("tbm_drm_helper_get_auth_info failed"); + goto fail; + } + } + + ret = vigs_drm_device_create(drm_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->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_import_fd = tbm_bufmgr_emulator_bo_import_fd; + backend->bo_export = tbm_bufmgr_emulator_bo_export; + backend->bo_export_fd = tbm_bufmgr_emulator_bo_export_fd; + 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_lock = tbm_bufmgr_emulator_bo_lock; + backend->bo_unlock = tbm_bufmgr_emulator_bo_unlock; + backend->surface_get_plane_data = tbm_bufmgr_emulator_surface_get_plane_data; + backend->surface_supported_format = tbm_bufmgr_emulator_surface_supported_format; + backend->bufmgr_bind_native_display = tbm_bufmgr_emulator_bind_native_display; + backend->surface_bo_alloc = tbm_bufmgr_emulator_surface_bo_alloc; + + 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); + + if (drm_fd >= 0) { + if (tbm_backend_is_display_server()) + tbm_drm_helper_unset_tbm_master_fd(); + + close(drm_fd); + } + + return 0; } diff --git a/src/tbm_emulator_log.c b/src/tbm_emulator_log.c index 365987e..10ead18 100644 --- a/src/tbm_emulator_log.c +++ b/src/tbm_emulator_log.c @@ -41,12 +41,11 @@ #include <unistd.h> #include <sys/time.h> -static const char *g_log_level_to_str[] = -{ - "OFF", - "ERROR", - "INFO", - "DEBUG" +static const char *g_log_level_to_str[] = { + "OFF", + "ERROR", + "INFO", + "DEBUG" }; static pthread_once_t g_log_init = PTHREAD_ONCE_INIT; @@ -54,60 +53,51 @@ 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; + 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); + 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; + char buff[128]; + struct tm tm; + struct timeval tv = { 0, 0 }; + time_t ti; - gettimeofday(&tv, NULL); + gettimeofday(&tv, NULL); - ti = tv.tv_sec; + ti = tv.tv_sec; - localtime_r(&ti, &tm); - strftime(buff, sizeof(buff), - "%H:%M:%S", &tm); - fprintf(stderr, "%s", buff); + 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, ...) +void tbm_emulator_log_event(tbm_emulator_log_level log_level, const char *func, int line, const char *format, ...) { - va_list args; + va_list args; - tbm_emulator_log_init(); + 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"); + 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(); + tbm_emulator_log_init(); - return g_debug_enabled; + return g_debug_enabled; } diff --git a/src/tbm_emulator_log.h b/src/tbm_emulator_log.h index 88212db..794b26f 100644 --- a/src/tbm_emulator_log.h +++ b/src/tbm_emulator_log.h @@ -35,29 +35,25 @@ #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, +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, ...); +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) + 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__) +#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 |