diff options
author | SooChan Lim <sc1.lim@samsung.com> | 2018-03-19 20:32:38 +0900 |
---|---|---|
committer | SooChan Lim <sc1.lim@samsung.com> | 2018-03-19 20:32:38 +0900 |
commit | d02e09b82d389b8b2a5d6d2f359f9bc90ffeeb1a (patch) | |
tree | 4f21001ea664fcd9e99ccff637d07b367ca61ed8 | |
parent | 0ab4f3e60a138a98dd07ed67f656c46e71446274 (diff) | |
download | libtbm-exynos-tgm-d02e09b82d389b8b2a5d6d2f359f9bc90ffeeb1a.tar.gz libtbm-exynos-tgm-d02e09b82d389b8b2a5d6d2f359f9bc90ffeeb1a.tar.bz2 libtbm-exynos-tgm-d02e09b82d389b8b2a5d6d2f359f9bc90ffeeb1a.zip |
re-arrange the static functions.
Change-Id: Ibc5d98842950e6551bb7a5bfdff629951cbe368d
-rw-r--r-- | src/tbm_bufmgr_exynos.c | 1225 |
1 files changed, 613 insertions, 612 deletions
diff --git a/src/tbm_bufmgr_exynos.c b/src/tbm_bufmgr_exynos.c index 41dc9f3..da711ae 100644 --- a/src/tbm_bufmgr_exynos.c +++ b/src/tbm_bufmgr_exynos.c @@ -56,13 +56,13 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define USE_DMAIMPORT #define TBM_COLOR_FORMAT_COUNT 4 -#define EXYNOS_DRM_NAME "tgm" - #ifdef DEBUG #define LOG_TAG "TBM_BACKEND" #include <dlog.h> static int bDebug; +#define EXYNOS_DRM_NAME "tgm" + char *target_name() { static char app_name[128] = {0, }; @@ -980,20 +980,401 @@ _exynos_bo_handle(tbm_bo_exynos bo_exynos, int device) } static int -tbm_exynos_bo_get_size(tbm_backend_bo_data *bo_data, tbm_error_e *error) +_new_calc_plane_nv12(int width, int height) { - tbm_bo_exynos bo_exynos = (tbm_bo_exynos)bo_data; + int mbX, mbY; - if (!bo_exynos) { - if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return 0; - } + mbX = DIV_ROUND_UP(width, S5P_FIMV_NUM_PIXELS_IN_MB_ROW); + mbY = DIV_ROUND_UP(height, S5P_FIMV_NUM_PIXELS_IN_MB_COL); + + if (width * height < S5P_FIMV_MAX_FRAME_SIZE) + mbY = (mbY + 1) / 2 * 2; + + return ((mbX * S5P_FIMV_NUM_PIXELS_IN_MB_COL) * (mbY * + S5P_FIMV_NUM_PIXELS_IN_MB_ROW)); +} + +static int +_calc_yplane_nv12(int width, int height) +{ + int mbX, mbY; + + mbX = SIZE_ALIGN(width + 24, S5P_FIMV_NV12MT_HALIGN); + mbY = SIZE_ALIGN(height + 16, S5P_FIMV_NV12MT_VALIGN); + + return SIZE_ALIGN(mbX * mbY, S5P_FIMV_DEC_BUF_ALIGN); +} + +static int +_calc_uvplane_nv12(int width, int height) +{ + int mbX, mbY; + + mbX = SIZE_ALIGN(width + 16, S5P_FIMV_NV12MT_HALIGN); + mbY = SIZE_ALIGN(height + 4, S5P_FIMV_NV12MT_VALIGN); + + return SIZE_ALIGN((mbX * mbY) >> 1, S5P_FIMV_DEC_BUF_ALIGN); +} + +static int +_new_calc_yplane_nv12(int width, int height) +{ + return SIZE_ALIGN(_new_calc_plane_nv12(width, + height) + S5P_FIMV_D_ALIGN_PLANE_SIZE, + TBM_SURFACE_ALIGNMENT_PLANE_NV12); +} + +static int +_new_calc_uvplane_nv12(int width, int height) +{ + return SIZE_ALIGN((_new_calc_plane_nv12(width, + height) >> 1) + S5P_FIMV_D_ALIGN_PLANE_SIZE, + TBM_SURFACE_ALIGNMENT_PLANE_NV12); +} + +static tbm_bufmgr_capability +tbm_exynos_bufmgr_get_capabilities(tbm_backend_bufmgr_data *bufmgr_data, tbm_error_e *error) +{ + tbm_bufmgr_capability capabilities = TBM_BUFMGR_CAPABILITY_NONE; + + capabilities = TBM_BUFMGR_CAPABILITY_SHARE_KEY|TBM_BUFMGR_CAPABILITY_SHARE_FD; if (error) *error = TBM_ERROR_NONE; - return bo_exynos->size; + return capabilities; +} + +static tbm_error_e +tbm_exynos_bufmgr_bind_native_display(tbm_backend_bufmgr_data *bufmgr_data, tbm_native_display *native_display) +{ + tbm_bufmgr_exynos bufmgr_exynos = (tbm_bufmgr_exynos)bufmgr_data; + EXYNOS_RETURN_VAL_IF_FAIL(bufmgr_exynos != NULL, TBM_ERROR_INVALID_PARAMETER); + + if (!tbm_drm_helper_wl_auth_server_init(native_display, bufmgr_exynos->fd, + bufmgr_exynos->device_name, 0)) { + TBM_EXYNOS_ERROR("fail to tbm_drm_helper_wl_server_init\n"); + return TBM_ERROR_OPERATION_FAILED; + } + + bufmgr_exynos->bind_display = native_display; + + return TBM_ERROR_NONE; +} + +static tbm_error_e +tbm_exynos_bufmgr_get_supported_formats(tbm_backend_bufmgr_data *bufmgr_data, + uint32_t **formats, uint32_t *num) +{ + tbm_bufmgr_exynos bufmgr_exynos = (tbm_bufmgr_exynos)bufmgr_data; + uint32_t *color_formats; + + EXYNOS_RETURN_VAL_IF_FAIL(bufmgr_exynos != NULL, TBM_ERROR_INVALID_PARAMETER); + + color_formats = (uint32_t *)calloc(1, sizeof(uint32_t) * TBM_COLOR_FORMAT_COUNT); + if (color_formats == NULL) + return TBM_ERROR_OUT_OF_MEMORY; + + memcpy(color_formats, tbm_exynos_color_format_list, sizeof(uint32_t)*TBM_COLOR_FORMAT_COUNT); + + *formats = color_formats; + *num = TBM_COLOR_FORMAT_COUNT; + + TBM_EXYNOS_DEBUG("supported format count = %d\n", *num); + + return TBM_ERROR_NONE; +} + +static tbm_error_e +tbm_exynos_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_exynos bufmgr_exynos = (tbm_bufmgr_exynos)bufmgr_data; + int bpp; + int _offset = 0; + int _pitch = 0; + int _size = 0; + int _bo_idx = 0; + + EXYNOS_RETURN_VAL_IF_FAIL(bufmgr_exynos != NULL, TBM_ERROR_INVALID_PARAMETER); + + switch (format) { + /* 16 bpp RGB */ + case TBM_FORMAT_XRGB4444: + case TBM_FORMAT_XBGR4444: + case TBM_FORMAT_RGBX4444: + case TBM_FORMAT_BGRX4444: + case TBM_FORMAT_ARGB4444: + case TBM_FORMAT_ABGR4444: + case TBM_FORMAT_RGBA4444: + case TBM_FORMAT_BGRA4444: + case TBM_FORMAT_XRGB1555: + case TBM_FORMAT_XBGR1555: + case TBM_FORMAT_RGBX5551: + case TBM_FORMAT_BGRX5551: + case TBM_FORMAT_ARGB1555: + case TBM_FORMAT_ABGR1555: + case TBM_FORMAT_RGBA5551: + case TBM_FORMAT_BGRA5551: + case TBM_FORMAT_RGB565: + bpp = 16; + _offset = 0; + _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_RGB); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + break; + /* 24 bpp RGB */ + case TBM_FORMAT_RGB888: + case TBM_FORMAT_BGR888: + bpp = 24; + _offset = 0; + _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_RGB); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + break; + /* 32 bpp RGB */ + case TBM_FORMAT_XRGB8888: + case TBM_FORMAT_XBGR8888: + case TBM_FORMAT_RGBX8888: + case TBM_FORMAT_BGRX8888: + case TBM_FORMAT_ARGB8888: + case TBM_FORMAT_ABGR8888: + case TBM_FORMAT_RGBA8888: + case TBM_FORMAT_BGRA8888: + bpp = 32; + _offset = 0; + _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_RGB); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + break; + + /* packed YCbCr */ + case TBM_FORMAT_YUYV: + case TBM_FORMAT_YVYU: + case TBM_FORMAT_UYVY: + case TBM_FORMAT_VYUY: + case TBM_FORMAT_AYUV: + bpp = 32; + _offset = 0; + _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + break; + + /* + * 2 plane YCbCr + * index 0 = Y plane, [7:0] Y + * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian + * or + * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian + */ + case TBM_FORMAT_NV12: + bpp = 12; + /*if (plane_idx == 0)*/ + { + _offset = 0; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = MAX(_calc_yplane_nv12(width, height), _new_calc_yplane_nv12(width, + height)); + _bo_idx = 0; + if (plane_idx == 0) + break; + } + /*else if (plane_idx == 1)*/ + { + _offset += _size; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = MAX(_calc_uvplane_nv12(width, height), _new_calc_uvplane_nv12(width, + height)); + _bo_idx = 0; + } + break; + case TBM_FORMAT_NV21: + bpp = 12; + /*if (plane_idx == 0)*/ + { + _offset = 0; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + if (plane_idx == 0) + break; + } + /*else if (plane_idx == 1)*/ + { + _offset += _size; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); + _size = SIZE_ALIGN(_pitch * (height / 2), TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + } + break; + + case TBM_FORMAT_NV16: + case TBM_FORMAT_NV61: + bpp = 16; + /*if(plane_idx == 0)*/ + { + _offset = 0; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + if (plane_idx == 0) + break; + } + /*else if( plane_idx ==1 )*/ + { + _offset += _size; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + } + break; + + /* + * 3 plane YCbCr + * index 0: Y plane, [7:0] Y + * index 1: Cb plane, [7:0] Cb + * index 2: Cr plane, [7:0] Cr + * or + * index 1: Cr plane, [7:0] Cr + * index 2: Cb plane, [7:0] Cb + */ + + /* + * NATIVE_BUFFER_FORMAT_YV12 + * NATIVE_BUFFER_FORMAT_I420 + */ + case TBM_FORMAT_YUV410: + case TBM_FORMAT_YVU410: + bpp = 9; + /*if(plane_idx == 0)*/ + { + _offset = 0; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + if (plane_idx == 0) + break; + } + /*else if(plane_idx == 1)*/ + { + _offset += _size; + _pitch = SIZE_ALIGN(width / 4, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 4); + _size = SIZE_ALIGN(_pitch * (height / 4), TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + if (plane_idx == 1) + break; + } + /*else if (plane_idx == 2)*/ + { + _offset += _size; + _pitch = SIZE_ALIGN(width / 4, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 4); + _size = SIZE_ALIGN(_pitch * (height / 4), TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + } + break; + case TBM_FORMAT_YUV411: + case TBM_FORMAT_YVU411: + case TBM_FORMAT_YUV420: + case TBM_FORMAT_YVU420: + bpp = 12; + /*if(plane_idx == 0)*/ + { + _offset = 0; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + if (plane_idx == 0) + break; + } + /*else if(plane_idx == 1)*/ + { + _offset += _size; + _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); + _size = SIZE_ALIGN(_pitch * (height / 2), TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + if (plane_idx == 1) + break; + } + /*else if (plane_idx == 2)*/ + { + _offset += _size; + _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); + _size = SIZE_ALIGN(_pitch * (height / 2), TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + } + break; + case TBM_FORMAT_YUV422: + case TBM_FORMAT_YVU422: + bpp = 16; + /*if(plane_idx == 0)*/ + { + _offset = 0; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + if (plane_idx == 0) + break; + } + /*else if(plane_idx == 1)*/ + { + _offset += _size; + _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); + _size = SIZE_ALIGN(_pitch * (height), TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + if (plane_idx == 1) + break; + } + /*else if (plane_idx == 2)*/ + { + _offset += _size; + _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); + _size = SIZE_ALIGN(_pitch * (height), TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + } + break; + case TBM_FORMAT_YUV444: + case TBM_FORMAT_YVU444: + bpp = 24; + /*if(plane_idx == 0)*/ + { + _offset = 0; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + if (plane_idx == 0) + break; + } + /*else if(plane_idx == 1)*/ + { + _offset += _size; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + if (plane_idx == 1) + break; + } + /*else if (plane_idx == 2)*/ + { + _offset += _size; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + } + break; + default: + bpp = 0; + break; + } + + *size = _size; + *offset = _offset; + *pitch = _pitch; + *bo_idx = _bo_idx; + + return TBM_ERROR_NONE; } static tbm_backend_bo_data * @@ -1086,71 +1467,16 @@ tbm_exynos_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, int size, tbm_b return (tbm_backend_bo_data *)bo_exynos; } -static void -tbm_exynos_bo_free(tbm_backend_bo_data *bo_data) -{ - tbm_bo_exynos bo_exynos = (tbm_bo_exynos)bo_data; - tbm_bo_exynos temp; - tbm_bufmgr_exynos bufmgr_exynos; - char buf[STRERR_BUFSIZE]; - int ret; - - if (!bo_data) - return; - - bufmgr_exynos = bo_exynos->bufmgr_exynos; - if (!bufmgr_exynos) - return; - - TBM_EXYNOS_DEBUG(" bo_exynos:%p, gem:%d(%d), fd:%d, size:%d\n", - bo_exynos, - bo_exynos->gem, bo_exynos->name, - bo_exynos->dmabuf, - bo_exynos->size); - - if (bo_exynos->pBase) { - if (munmap(bo_exynos->pBase, bo_exynos->size) == -1) { - TBM_EXYNOS_ERROR("bo_exynos:%p fail to munmap(%s)\n", - bo_exynos, strerror_r(errno, buf, STRERR_BUFSIZE)); - } - } - - /* close dmabuf */ - if (bo_exynos->dmabuf) { - close(bo_exynos->dmabuf); - bo_exynos->dmabuf = 0; - } - - /* delete bo_exynos from hash */ - ret = drmHashLookup(bufmgr_exynos->hashBos, bo_exynos->name, (void **)&temp); - if (ret == 0) - drmHashDelete(bufmgr_exynos->hashBos, bo_exynos->name); - else - TBM_EXYNOS_ERROR("Cannot find bo_exynos to Hash(%d), ret=%d\n", bo_exynos->name, ret); - - if (temp != bo_exynos) - TBM_EXYNOS_ERROR("hashBos probably has several BOs with same name!!!\n"); - - _bo_destroy_cache_state(bufmgr_exynos, bo_exynos); - - /* Free gem handle */ - struct drm_gem_close arg = {0, }; - - memset(&arg, 0, sizeof(arg)); - arg.handle = bo_exynos->gem; - if (drmIoctl(bo_exynos->fd, DRM_IOCTL_GEM_CLOSE, &arg)) - TBM_EXYNOS_ERROR("bo_exynos:%p fail to gem close.(%s)\n", - bo_exynos, strerror_r(errno, buf, STRERR_BUFSIZE)); - - free(bo_exynos); -} static tbm_backend_bo_data * -tbm_exynos_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tbm_error_e *error) +tbm_exynos_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_error_e *error) { tbm_bufmgr_exynos bufmgr_exynos = (tbm_bufmgr_exynos)bufmgr_data; tbm_bo_exynos bo_exynos; + unsigned int gem = 0; + unsigned int name; int ret; + char buf[STRERR_BUFSIZE]; if (bufmgr_exynos == NULL) { TBM_EXYNOS_ERROR("bufmgr_data is null\n"); @@ -1159,38 +1485,67 @@ tbm_exynos_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, return NULL; } - ret = drmHashLookup(bufmgr_exynos->hashBos, key, (void **)&bo_exynos); - if (ret == 0) { + /*getting handle from fd*/ + struct drm_prime_handle arg = {0, }; + + arg.fd = key; + arg.flags = 0; + if (drmIoctl(bufmgr_exynos->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &arg)) { + TBM_EXYNOS_ERROR("Cannot get gem handle from fd:%d (%s)\n", + arg.fd, strerror_r(errno, buf, STRERR_BUFSIZE)); if (error) - *error = TBM_ERROR_NONE; - return (tbm_backend_bo_data *)bo_exynos; + *error = TBM_ERROR_OPERATION_FAILED; + return NULL; } + gem = arg.handle; - struct drm_gem_open arg = {0, }; - struct drm_exynos_gem_info info = {0, }; - - arg.name = key; - if (drmIoctl(bufmgr_exynos->fd, DRM_IOCTL_GEM_OPEN, &arg)) { - TBM_EXYNOS_ERROR("Cannot open gem name=%d\n", key); + name = _get_name(bufmgr_exynos->fd, gem); + if (!name) { + TBM_EXYNOS_ERROR("Cannot get name from gem:%d, fd:%d (%s)\n", + gem, key, strerror_r(errno, buf, STRERR_BUFSIZE)); if (error) *error = TBM_ERROR_OPERATION_FAILED; return NULL; } - info.handle = arg.handle; + ret = drmHashLookup(bufmgr_exynos->hashBos, name, (void **)&bo_exynos); + if (ret == 0) { + if (gem == bo_exynos->gem) { + if (error) + *error = TBM_ERROR_NONE; + return bo_exynos; + } + } + + /* Determine size of bo_exynos. The fd-to-handle ioctl really should + * return the size, but it doesn't. If we have kernel 3.12 or + * later, we can lseek on the prime fd to get the size. Older + * kernels will just fail, in which case we fall back to the + * provided (estimated or guess size). + */ + unsigned int real_size = -1; + struct drm_exynos_gem_info info = {0, }; + + real_size = lseek(key, 0, SEEK_END); + + info.handle = gem; if (drmCommandWriteRead(bufmgr_exynos->fd, DRM_EXYNOS_GEM_GET, &info, sizeof(struct drm_exynos_gem_info))) { - TBM_EXYNOS_ERROR("Cannot get gem info=%d\n", key); + TBM_EXYNOS_ERROR("Cannot get gem info from gem:%d, fd:%d (%s)\n", + gem, key, strerror_r(errno, buf, STRERR_BUFSIZE)); if (error) *error = TBM_ERROR_OPERATION_FAILED; return NULL; } + if (real_size == -1) + real_size = info.size; + bo_exynos = calloc(1, sizeof(struct _tbm_bo_exynos)); if (!bo_exynos) { - TBM_EXYNOS_ERROR("fail to allocate the bo_exynos private\n"); + TBM_EXYNOS_ERROR("bo_exynos:%p fail to allocate the bo_exynos\n", bo_exynos); if (error) *error = TBM_ERROR_OUT_OF_MEMORY; return NULL; @@ -1198,11 +1553,11 @@ tbm_exynos_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, bo_exynos->bufmgr_exynos = bufmgr_exynos; bo_exynos->fd = bufmgr_exynos->fd; - bo_exynos->gem = arg.handle; - bo_exynos->size = arg.size; + bo_exynos->gem = gem; + bo_exynos->size = real_size; bo_exynos->flags_exynos = info.flags; - bo_exynos->name = key; bo_exynos->flags_tbm = _get_tbm_flag_from_exynos(bo_exynos->flags_exynos); + bo_exynos->name = name; if (!_bo_init_cache_state(bufmgr_exynos, bo_exynos, 1)) { TBM_EXYNOS_ERROR("fail init cache state(%d)\n", bo_exynos->name); @@ -1212,28 +1567,16 @@ tbm_exynos_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, return NULL; } - if (!bo_exynos->dmabuf) { - struct drm_prime_handle arg = {0, }; - - arg.handle = bo_exynos->gem; - if (drmIoctl(bo_exynos->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) { - TBM_EXYNOS_ERROR("fail to DRM_IOCTL_PRIME_HANDLE_TO_FD gem=%d\n", bo_exynos->gem); - if (error) - *error = TBM_ERROR_OPERATION_FAILED; - free(bo_exynos); - return NULL; - } - bo_exynos->dmabuf = arg.fd; - } - /* add bo_exynos to hash */ if (drmHashInsert(bufmgr_exynos->hashBos, bo_exynos->name, (void *)bo_exynos) < 0) - TBM_EXYNOS_ERROR("Cannot insert bo_exynos to Hash(%d)\n", bo_exynos->name); + TBM_EXYNOS_ERROR("bo_exynos:%p Cannot insert bo_exynos to Hash(%d) from gem:%d, fd:%d\n", + bo_exynos, bo_exynos->name, gem, key); - TBM_EXYNOS_DEBUG(" bo_exynos:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d\n", + TBM_EXYNOS_DEBUG(" bo_exynos:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", bo_exynos, bo_exynos->gem, bo_exynos->name, bo_exynos->dmabuf, + key, bo_exynos->flags_tbm, bo_exynos->flags_exynos, bo_exynos->size); @@ -1244,14 +1587,11 @@ tbm_exynos_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, } static tbm_backend_bo_data * -tbm_exynos_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_error_e *error) +tbm_exynos_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tbm_error_e *error) { tbm_bufmgr_exynos bufmgr_exynos = (tbm_bufmgr_exynos)bufmgr_data; tbm_bo_exynos bo_exynos; - unsigned int gem = 0; - unsigned int name; int ret; - char buf[STRERR_BUFSIZE]; if (bufmgr_exynos == NULL) { TBM_EXYNOS_ERROR("bufmgr_data is null\n"); @@ -1260,67 +1600,38 @@ tbm_exynos_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tb return NULL; } - /*getting handle from fd*/ - struct drm_prime_handle arg = {0, }; - - arg.fd = key; - arg.flags = 0; - if (drmIoctl(bufmgr_exynos->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &arg)) { - TBM_EXYNOS_ERROR("Cannot get gem handle from fd:%d (%s)\n", - arg.fd, strerror_r(errno, buf, STRERR_BUFSIZE)); + ret = drmHashLookup(bufmgr_exynos->hashBos, key, (void **)&bo_exynos); + if (ret == 0) { if (error) - *error = TBM_ERROR_OPERATION_FAILED; - return NULL; + *error = TBM_ERROR_NONE; + return (tbm_backend_bo_data *)bo_exynos; } - gem = arg.handle; - name = _get_name(bufmgr_exynos->fd, gem); - if (!name) { - TBM_EXYNOS_ERROR("Cannot get name from gem:%d, fd:%d (%s)\n", - gem, key, strerror_r(errno, buf, STRERR_BUFSIZE)); + struct drm_gem_open arg = {0, }; + struct drm_exynos_gem_info info = {0, }; + + arg.name = key; + if (drmIoctl(bufmgr_exynos->fd, DRM_IOCTL_GEM_OPEN, &arg)) { + TBM_EXYNOS_ERROR("Cannot open gem name=%d\n", key); if (error) *error = TBM_ERROR_OPERATION_FAILED; return NULL; } - ret = drmHashLookup(bufmgr_exynos->hashBos, name, (void **)&bo_exynos); - if (ret == 0) { - if (gem == bo_exynos->gem) { - if (error) - *error = TBM_ERROR_NONE; - return bo_exynos; - } - } - - /* Determine size of bo_exynos. The fd-to-handle ioctl really should - * return the size, but it doesn't. If we have kernel 3.12 or - * later, we can lseek on the prime fd to get the size. Older - * kernels will just fail, in which case we fall back to the - * provided (estimated or guess size). - */ - unsigned int real_size = -1; - struct drm_exynos_gem_info info = {0, }; - - real_size = lseek(key, 0, SEEK_END); - - info.handle = gem; + info.handle = arg.handle; if (drmCommandWriteRead(bufmgr_exynos->fd, DRM_EXYNOS_GEM_GET, &info, sizeof(struct drm_exynos_gem_info))) { - TBM_EXYNOS_ERROR("Cannot get gem info from gem:%d, fd:%d (%s)\n", - gem, key, strerror_r(errno, buf, STRERR_BUFSIZE)); + TBM_EXYNOS_ERROR("Cannot get gem info=%d\n", key); if (error) *error = TBM_ERROR_OPERATION_FAILED; return NULL; } - if (real_size == -1) - real_size = info.size; - bo_exynos = calloc(1, sizeof(struct _tbm_bo_exynos)); if (!bo_exynos) { - TBM_EXYNOS_ERROR("bo_exynos:%p fail to allocate the bo_exynos\n", bo_exynos); + TBM_EXYNOS_ERROR("fail to allocate the bo_exynos private\n"); if (error) *error = TBM_ERROR_OUT_OF_MEMORY; return NULL; @@ -1328,11 +1639,11 @@ tbm_exynos_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tb bo_exynos->bufmgr_exynos = bufmgr_exynos; bo_exynos->fd = bufmgr_exynos->fd; - bo_exynos->gem = gem; - bo_exynos->size = real_size; + bo_exynos->gem = arg.handle; + bo_exynos->size = arg.size; bo_exynos->flags_exynos = info.flags; + bo_exynos->name = key; bo_exynos->flags_tbm = _get_tbm_flag_from_exynos(bo_exynos->flags_exynos); - bo_exynos->name = name; if (!_bo_init_cache_state(bufmgr_exynos, bo_exynos, 1)) { TBM_EXYNOS_ERROR("fail init cache state(%d)\n", bo_exynos->name); @@ -1342,16 +1653,28 @@ tbm_exynos_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tb return NULL; } + if (!bo_exynos->dmabuf) { + struct drm_prime_handle arg = {0, }; + + arg.handle = bo_exynos->gem; + if (drmIoctl(bo_exynos->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) { + TBM_EXYNOS_ERROR("fail to DRM_IOCTL_PRIME_HANDLE_TO_FD gem=%d\n", bo_exynos->gem); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + free(bo_exynos); + return NULL; + } + bo_exynos->dmabuf = arg.fd; + } + /* add bo_exynos to hash */ if (drmHashInsert(bufmgr_exynos->hashBos, bo_exynos->name, (void *)bo_exynos) < 0) - TBM_EXYNOS_ERROR("bo_exynos:%p Cannot insert bo_exynos to Hash(%d) from gem:%d, fd:%d\n", - bo_exynos, bo_exynos->name, gem, key); + TBM_EXYNOS_ERROR("Cannot insert bo_exynos to Hash(%d)\n", bo_exynos->name); - TBM_EXYNOS_DEBUG(" bo_exynos:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", + TBM_EXYNOS_DEBUG(" bo_exynos:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d\n", bo_exynos, bo_exynos->gem, bo_exynos->name, bo_exynos->dmabuf, - key, bo_exynos->flags_tbm, bo_exynos->flags_exynos, bo_exynos->size); @@ -1361,77 +1684,97 @@ tbm_exynos_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tb return (tbm_backend_bo_data *)bo_exynos; } -static tbm_key -tbm_exynos_bo_export_key(tbm_backend_bo_data *bo_data, tbm_error_e *error) +static void +tbm_exynos_bo_free(tbm_backend_bo_data *bo_data) { tbm_bo_exynos bo_exynos = (tbm_bo_exynos)bo_data; + tbm_bo_exynos temp; + tbm_bufmgr_exynos bufmgr_exynos; + char buf[STRERR_BUFSIZE]; + int ret; - if (!bo_exynos) { - if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return 0; - } + if (!bo_data) + return; - if (!bo_exynos->name) { - bo_exynos->name = _get_name(bo_exynos->fd, bo_exynos->gem); - if (!bo_exynos->name) { - TBM_EXYNOS_ERROR("error Cannot get name\n"); - if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return 0; - } - } + bufmgr_exynos = bo_exynos->bufmgr_exynos; + if (!bufmgr_exynos) + return; - TBM_EXYNOS_DEBUG(" bo_exynos:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d\n", + TBM_EXYNOS_DEBUG(" bo_exynos:%p, gem:%d(%d), fd:%d, size:%d\n", bo_exynos, bo_exynos->gem, bo_exynos->name, bo_exynos->dmabuf, - bo_exynos->flags_tbm, bo_exynos->flags_exynos, bo_exynos->size); - if (error) - *error = TBM_ERROR_NONE; + if (bo_exynos->pBase) { + if (munmap(bo_exynos->pBase, bo_exynos->size) == -1) { + TBM_EXYNOS_ERROR("bo_exynos:%p fail to munmap(%s)\n", + bo_exynos, strerror_r(errno, buf, STRERR_BUFSIZE)); + } + } - return (tbm_key)bo_exynos->name; + /* close dmabuf */ + if (bo_exynos->dmabuf) { + close(bo_exynos->dmabuf); + bo_exynos->dmabuf = 0; + } + + /* delete bo_exynos from hash */ + ret = drmHashLookup(bufmgr_exynos->hashBos, bo_exynos->name, (void **)&temp); + if (ret == 0) + drmHashDelete(bufmgr_exynos->hashBos, bo_exynos->name); + else + TBM_EXYNOS_ERROR("Cannot find bo_exynos to Hash(%d), ret=%d\n", bo_exynos->name, ret); + + if (temp != bo_exynos) + TBM_EXYNOS_ERROR("hashBos probably has several BOs with same name!!!\n"); + + _bo_destroy_cache_state(bufmgr_exynos, bo_exynos); + + /* Free gem handle */ + struct drm_gem_close arg = {0, }; + + memset(&arg, 0, sizeof(arg)); + arg.handle = bo_exynos->gem; + if (drmIoctl(bo_exynos->fd, DRM_IOCTL_GEM_CLOSE, &arg)) + TBM_EXYNOS_ERROR("bo_exynos:%p fail to gem close.(%s)\n", + bo_exynos, strerror_r(errno, buf, STRERR_BUFSIZE)); + + free(bo_exynos); } -static tbm_fd -tbm_exynos_bo_export_fd(tbm_backend_bo_data *bo_data, tbm_error_e *error) +static int +tbm_exynos_bo_get_size(tbm_backend_bo_data *bo_data, tbm_error_e *error) { tbm_bo_exynos bo_exynos = (tbm_bo_exynos)bo_data; - int ret; - char buf[STRERR_BUFSIZE]; if (!bo_exynos) { if (error) *error = TBM_ERROR_INVALID_PARAMETER; - return -1; + return 0; } - struct drm_prime_handle arg = {0, }; + if (error) + *error = TBM_ERROR_NONE; - arg.handle = bo_exynos->gem; - ret = drmIoctl(bo_exynos->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg); - if (ret) { - TBM_EXYNOS_ERROR("bo_exynos:%p Cannot dmabuf=%d (%s)\n", - bo_exynos, bo_exynos->gem, strerror_r(errno, buf, STRERR_BUFSIZE)); + return bo_exynos->size; +} + +static tbm_bo_memory_type +tbm_exynos_bo_get_memory_type(tbm_backend_bo_data *bo_data, tbm_error_e *error) +{ + tbm_bo_exynos bo_exynos = (tbm_bo_exynos)bo_data; + + if (!bo_exynos) { if (error) - *error = TBM_ERROR_OPERATION_FAILED; - return (tbm_fd) ret; + *error = TBM_ERROR_INVALID_PARAMETER; + return TBM_BO_DEFAULT; } - TBM_EXYNOS_DEBUG(" bo_exynos:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", - bo_exynos, - bo_exynos->gem, bo_exynos->name, - bo_exynos->dmabuf, - arg.fd, - bo_exynos->flags_tbm, bo_exynos->flags_exynos, - bo_exynos->size); - if (error) *error = TBM_ERROR_NONE; - return (tbm_fd)arg.fd; + return bo_exynos->flags_tbm; } static tbm_bo_handle @@ -1648,6 +1991,79 @@ tbm_exynos_bo_unlock(tbm_backend_bo_data *bo_data) return TBM_ERROR_NONE; } +static tbm_fd +tbm_exynos_bo_export_fd(tbm_backend_bo_data *bo_data, tbm_error_e *error) +{ + tbm_bo_exynos bo_exynos = (tbm_bo_exynos)bo_data; + int ret; + char buf[STRERR_BUFSIZE]; + + if (!bo_exynos) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return -1; + } + + struct drm_prime_handle arg = {0, }; + + arg.handle = bo_exynos->gem; + ret = drmIoctl(bo_exynos->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg); + if (ret) { + TBM_EXYNOS_ERROR("bo_exynos:%p Cannot dmabuf=%d (%s)\n", + bo_exynos, bo_exynos->gem, strerror_r(errno, buf, STRERR_BUFSIZE)); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + return (tbm_fd) ret; + } + + TBM_EXYNOS_DEBUG(" bo_exynos:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", + bo_exynos, + bo_exynos->gem, bo_exynos->name, + bo_exynos->dmabuf, + arg.fd, + bo_exynos->flags_tbm, bo_exynos->flags_exynos, + bo_exynos->size); + + if (error) + *error = TBM_ERROR_NONE; + + return (tbm_fd)arg.fd; +} + +static tbm_key +tbm_exynos_bo_export_key(tbm_backend_bo_data *bo_data, tbm_error_e *error) +{ + tbm_bo_exynos bo_exynos = (tbm_bo_exynos)bo_data; + + if (!bo_exynos) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return 0; + } + + if (!bo_exynos->name) { + bo_exynos->name = _get_name(bo_exynos->fd, bo_exynos->gem); + if (!bo_exynos->name) { + TBM_EXYNOS_ERROR("error Cannot get name\n"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return 0; + } + } + + TBM_EXYNOS_DEBUG(" bo_exynos:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d\n", + bo_exynos, + bo_exynos->gem, bo_exynos->name, + bo_exynos->dmabuf, + bo_exynos->flags_tbm, bo_exynos->flags_exynos, + bo_exynos->size); + + if (error) + *error = TBM_ERROR_NONE; + + return (tbm_key)bo_exynos->name; +} + static void tbm_exynos_deinit(tbm_backend_bufmgr_data *bufmgr_data) { @@ -1692,421 +2108,6 @@ tbm_exynos_deinit(tbm_backend_bufmgr_data *bufmgr_data) free(bufmgr_exynos); } -static tbm_error_e -tbm_exynos_bufmgr_get_supported_formats(tbm_backend_bufmgr_data *bufmgr_data, - uint32_t **formats, uint32_t *num) -{ - tbm_bufmgr_exynos bufmgr_exynos = (tbm_bufmgr_exynos)bufmgr_data; - uint32_t *color_formats; - - EXYNOS_RETURN_VAL_IF_FAIL(bufmgr_exynos != NULL, TBM_ERROR_INVALID_PARAMETER); - - color_formats = (uint32_t *)calloc(1, sizeof(uint32_t) * TBM_COLOR_FORMAT_COUNT); - if (color_formats == NULL) - return TBM_ERROR_OUT_OF_MEMORY; - - memcpy(color_formats, tbm_exynos_color_format_list, sizeof(uint32_t)*TBM_COLOR_FORMAT_COUNT); - - *formats = color_formats; - *num = TBM_COLOR_FORMAT_COUNT; - - TBM_EXYNOS_DEBUG("supported format count = %d\n", *num); - - return TBM_ERROR_NONE; -} - -static int -_new_calc_plane_nv12(int width, int height) -{ - int mbX, mbY; - - mbX = DIV_ROUND_UP(width, S5P_FIMV_NUM_PIXELS_IN_MB_ROW); - mbY = DIV_ROUND_UP(height, S5P_FIMV_NUM_PIXELS_IN_MB_COL); - - if (width * height < S5P_FIMV_MAX_FRAME_SIZE) - mbY = (mbY + 1) / 2 * 2; - - return ((mbX * S5P_FIMV_NUM_PIXELS_IN_MB_COL) * (mbY * - S5P_FIMV_NUM_PIXELS_IN_MB_ROW)); -} - -static int -_calc_yplane_nv12(int width, int height) -{ - int mbX, mbY; - - mbX = SIZE_ALIGN(width + 24, S5P_FIMV_NV12MT_HALIGN); - mbY = SIZE_ALIGN(height + 16, S5P_FIMV_NV12MT_VALIGN); - - return SIZE_ALIGN(mbX * mbY, S5P_FIMV_DEC_BUF_ALIGN); -} - -static int -_calc_uvplane_nv12(int width, int height) -{ - int mbX, mbY; - - mbX = SIZE_ALIGN(width + 16, S5P_FIMV_NV12MT_HALIGN); - mbY = SIZE_ALIGN(height + 4, S5P_FIMV_NV12MT_VALIGN); - - return SIZE_ALIGN((mbX * mbY) >> 1, S5P_FIMV_DEC_BUF_ALIGN); -} - -static int -_new_calc_yplane_nv12(int width, int height) -{ - return SIZE_ALIGN(_new_calc_plane_nv12(width, - height) + S5P_FIMV_D_ALIGN_PLANE_SIZE, - TBM_SURFACE_ALIGNMENT_PLANE_NV12); -} - -static int -_new_calc_uvplane_nv12(int width, int height) -{ - return SIZE_ALIGN((_new_calc_plane_nv12(width, - height) >> 1) + S5P_FIMV_D_ALIGN_PLANE_SIZE, - TBM_SURFACE_ALIGNMENT_PLANE_NV12); -} - -static tbm_error_e -tbm_exynos_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_exynos bufmgr_exynos = (tbm_bufmgr_exynos)bufmgr_data; - int bpp; - int _offset = 0; - int _pitch = 0; - int _size = 0; - int _bo_idx = 0; - - EXYNOS_RETURN_VAL_IF_FAIL(bufmgr_exynos != NULL, TBM_ERROR_INVALID_PARAMETER); - - switch (format) { - /* 16 bpp RGB */ - case TBM_FORMAT_XRGB4444: - case TBM_FORMAT_XBGR4444: - case TBM_FORMAT_RGBX4444: - case TBM_FORMAT_BGRX4444: - case TBM_FORMAT_ARGB4444: - case TBM_FORMAT_ABGR4444: - case TBM_FORMAT_RGBA4444: - case TBM_FORMAT_BGRA4444: - case TBM_FORMAT_XRGB1555: - case TBM_FORMAT_XBGR1555: - case TBM_FORMAT_RGBX5551: - case TBM_FORMAT_BGRX5551: - case TBM_FORMAT_ARGB1555: - case TBM_FORMAT_ABGR1555: - case TBM_FORMAT_RGBA5551: - case TBM_FORMAT_BGRA5551: - case TBM_FORMAT_RGB565: - bpp = 16; - _offset = 0; - _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_RGB); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - break; - /* 24 bpp RGB */ - case TBM_FORMAT_RGB888: - case TBM_FORMAT_BGR888: - bpp = 24; - _offset = 0; - _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_RGB); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - break; - /* 32 bpp RGB */ - case TBM_FORMAT_XRGB8888: - case TBM_FORMAT_XBGR8888: - case TBM_FORMAT_RGBX8888: - case TBM_FORMAT_BGRX8888: - case TBM_FORMAT_ARGB8888: - case TBM_FORMAT_ABGR8888: - case TBM_FORMAT_RGBA8888: - case TBM_FORMAT_BGRA8888: - bpp = 32; - _offset = 0; - _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_RGB); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - break; - - /* packed YCbCr */ - case TBM_FORMAT_YUYV: - case TBM_FORMAT_YVYU: - case TBM_FORMAT_UYVY: - case TBM_FORMAT_VYUY: - case TBM_FORMAT_AYUV: - bpp = 32; - _offset = 0; - _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - break; - - /* - * 2 plane YCbCr - * index 0 = Y plane, [7:0] Y - * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian - * or - * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian - */ - case TBM_FORMAT_NV12: - bpp = 12; - /*if (plane_idx == 0)*/ - { - _offset = 0; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = MAX(_calc_yplane_nv12(width, height), _new_calc_yplane_nv12(width, - height)); - _bo_idx = 0; - if (plane_idx == 0) - break; - } - /*else if (plane_idx == 1)*/ - { - _offset += _size; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = MAX(_calc_uvplane_nv12(width, height), _new_calc_uvplane_nv12(width, - height)); - _bo_idx = 0; - } - break; - case TBM_FORMAT_NV21: - bpp = 12; - /*if (plane_idx == 0)*/ - { - _offset = 0; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 0) - break; - } - /*else if (plane_idx == 1)*/ - { - _offset += _size; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); - _size = SIZE_ALIGN(_pitch * (height / 2), TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - } - break; - - case TBM_FORMAT_NV16: - case TBM_FORMAT_NV61: - bpp = 16; - /*if(plane_idx == 0)*/ - { - _offset = 0; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 0) - break; - } - /*else if( plane_idx ==1 )*/ - { - _offset += _size; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - } - break; - - /* - * 3 plane YCbCr - * index 0: Y plane, [7:0] Y - * index 1: Cb plane, [7:0] Cb - * index 2: Cr plane, [7:0] Cr - * or - * index 1: Cr plane, [7:0] Cr - * index 2: Cb plane, [7:0] Cb - */ - - /* - * NATIVE_BUFFER_FORMAT_YV12 - * NATIVE_BUFFER_FORMAT_I420 - */ - case TBM_FORMAT_YUV410: - case TBM_FORMAT_YVU410: - bpp = 9; - /*if(plane_idx == 0)*/ - { - _offset = 0; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 0) - break; - } - /*else if(plane_idx == 1)*/ - { - _offset += _size; - _pitch = SIZE_ALIGN(width / 4, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 4); - _size = SIZE_ALIGN(_pitch * (height / 4), TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 1) - break; - } - /*else if (plane_idx == 2)*/ - { - _offset += _size; - _pitch = SIZE_ALIGN(width / 4, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 4); - _size = SIZE_ALIGN(_pitch * (height / 4), TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - } - break; - case TBM_FORMAT_YUV411: - case TBM_FORMAT_YVU411: - case TBM_FORMAT_YUV420: - case TBM_FORMAT_YVU420: - bpp = 12; - /*if(plane_idx == 0)*/ - { - _offset = 0; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 0) - break; - } - /*else if(plane_idx == 1)*/ - { - _offset += _size; - _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); - _size = SIZE_ALIGN(_pitch * (height / 2), TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 1) - break; - } - /*else if (plane_idx == 2)*/ - { - _offset += _size; - _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); - _size = SIZE_ALIGN(_pitch * (height / 2), TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - } - break; - case TBM_FORMAT_YUV422: - case TBM_FORMAT_YVU422: - bpp = 16; - /*if(plane_idx == 0)*/ - { - _offset = 0; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 0) - break; - } - /*else if(plane_idx == 1)*/ - { - _offset += _size; - _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); - _size = SIZE_ALIGN(_pitch * (height), TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 1) - break; - } - /*else if (plane_idx == 2)*/ - { - _offset += _size; - _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); - _size = SIZE_ALIGN(_pitch * (height), TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - } - break; - case TBM_FORMAT_YUV444: - case TBM_FORMAT_YVU444: - bpp = 24; - /*if(plane_idx == 0)*/ - { - _offset = 0; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 0) - break; - } - /*else if(plane_idx == 1)*/ - { - _offset += _size; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 1) - break; - } - /*else if (plane_idx == 2)*/ - { - _offset += _size; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - } - break; - default: - bpp = 0; - break; - } - - *size = _size; - *offset = _offset; - *pitch = _pitch; - *bo_idx = _bo_idx; - - return TBM_ERROR_NONE; -} - -static tbm_bo_memory_type -tbm_exynos_bo_get_memory_type(tbm_backend_bo_data *bo_data, tbm_error_e *error) -{ - tbm_bo_exynos bo_exynos = (tbm_bo_exynos)bo_data; - - if (!bo_exynos) { - if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return TBM_BO_DEFAULT; - } - - if (error) - *error = TBM_ERROR_NONE; - - return bo_exynos->flags_tbm; -} - -static tbm_bufmgr_capability -tbm_exynos_bufmgr_get_capabilities(tbm_backend_bufmgr_data *bufmgr_data, tbm_error_e *error) -{ - tbm_bufmgr_capability capabilities = TBM_BUFMGR_CAPABILITY_NONE; - - capabilities = TBM_BUFMGR_CAPABILITY_SHARE_KEY|TBM_BUFMGR_CAPABILITY_SHARE_FD; - - if (error) - *error = TBM_ERROR_NONE; - - return capabilities; -} - -static tbm_error_e -tbm_exynos_bufmgr_bind_native_display(tbm_backend_bufmgr_data *bufmgr_data, tbm_native_display *native_display) -{ - tbm_bufmgr_exynos bufmgr_exynos = (tbm_bufmgr_exynos)bufmgr_data; - EXYNOS_RETURN_VAL_IF_FAIL(bufmgr_exynos != NULL, TBM_ERROR_INVALID_PARAMETER); - - if (!tbm_drm_helper_wl_auth_server_init(native_display, bufmgr_exynos->fd, - bufmgr_exynos->device_name, 0)) { - TBM_EXYNOS_ERROR("fail to tbm_drm_helper_wl_server_init\n"); - return TBM_ERROR_OPERATION_FAILED; - } - - bufmgr_exynos->bind_display = native_display; - - return TBM_ERROR_NONE; -} - static tbm_backend_bufmgr_data * tbm_exynos_init(tbm_bufmgr bufmgr, tbm_error_e *error) { |