From: SooChan Lim Date: Thu, 15 Mar 2018 05:30:31 +0000 (+0900) Subject: make the new backend inteface with tbm_backend.h X-Git-Tag: submit/tizen/20180320.042059~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6b2586ccb92bda696836c4bdd725c3c4b5ef1004;p=platform%2Fadaptation%2Fsamsung_exynos%2Flibtbm-exynos.git make the new backend inteface with tbm_backend.h Change-Id: I2f78226f8bc6b74c7a54ce7783ec39679a24c6a5 --- diff --git a/src/tbm_bufmgr_exynos.c b/src/tbm_bufmgr_exynos.c index e893881..a528361 100644 --- a/src/tbm_bufmgr_exynos.c +++ b/src/tbm_bufmgr_exynos.c @@ -32,6 +32,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "config.h" #endif +#include + #include #include #include @@ -44,18 +46,11 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include -#include -#include #include #include -#include -#include +#include #include - -#include - #include - #include "tbm_bufmgr_tgl.h" #define DEBUG @@ -71,25 +66,24 @@ static int bDebug; char *target_name() { - FILE *f; - char *slash; + static char app_name[128] = {0, }; static int initialized = 0; - static char app_name[128]; + char *slash; + FILE *f; if (initialized) return app_name; /* get the application name */ f = fopen("/proc/self/cmdline", "r"); - if (!f) - return 0; + return NULL; memset(app_name, 0x00, sizeof(app_name)); if (fgets(app_name, 100, f) == NULL) { fclose(f); - return 0; + return NULL; } fclose(f); @@ -228,6 +222,8 @@ struct _tbm_bo_exynos { tbm_bo_cache_state cache_state; unsigned int map_cnt; int last_map_device; + + tbm_bufmgr_exynos bufmgr_exynos; }; /* tbm bufmgr private for exynos */ @@ -242,6 +238,11 @@ struct _tbm_bufmgr_exynos { char *device_name; void *bind_display; + + tbm_backend_bufmgr_func *bufmgr_func; + tbm_backend_bo_func *bo_func; + + tbm_bufmgr bufmgr; }; char *STR_DEVICE[] = { @@ -277,7 +278,8 @@ _tgl_get_version(int fd) err = ioctl(fd, TGL_IOCTL_GET_VERSION, &data); if (err) { - TBM_EXYNOS_ERROR("error(%s) %s:%d\n", strerror_r(errno, buf, STRERR_BUFSIZE)); + TBM_EXYNOS_ERROR("error(%s) %s:%d\n", + strerror_r(errno, buf, STRERR_BUFSIZE)); return 0; } @@ -299,7 +301,8 @@ _tgl_init(int fd, unsigned int key) err = ioctl(fd, TGL_IOCTL_REGISTER, &data); if (err) { - TBM_EXYNOS_ERROR("error(%s) key:%d\n", strerror_r(errno, buf, STRERR_BUFSIZE), key); + TBM_EXYNOS_ERROR("error(%s) key:%d\n", + strerror_r(errno, buf, STRERR_BUFSIZE), key); return 0; } @@ -316,7 +319,8 @@ _tgl_destroy(int fd, unsigned int key) data.key = key; err = ioctl(fd, TGL_IOCTL_UNREGISTER, &data); if (err) { - TBM_EXYNOS_ERROR("error(%s) key:%d\n", strerror_r(errno, buf, STRERR_BUFSIZE), key); + TBM_EXYNOS_ERROR("error(%s) key:%d\n", + strerror_r(errno, buf, STRERR_BUFSIZE), key); return 0; } @@ -513,7 +517,7 @@ _bo_set_cache_state(tbm_bufmgr_exynos bufmgr_exynos, tbm_bo_exynos bo_exynos, in if (!(bo_exynos->flags_exynos & EXYNOS_BO_CACHABLE)) return 1; - /* get cache state of a bo */ + /* get cache state of a bo_exynos */ bo_exynos->cache_state.val = _tgl_get_data(bufmgr_exynos->tgl_fd, bo_exynos->name); @@ -608,7 +612,7 @@ _bo_destroy_cache_state(tbm_bufmgr_exynos bufmgr_exynos, tbm_bo_exynos bo_exynos static int _bufmgr_init_cache_state(tbm_bufmgr_exynos bufmgr_exynos) { - /* check whether cache control do or not */ + /* check whether cache control do or not */ if (!g_enable_cache_ctrl) return 1; @@ -621,18 +625,18 @@ _bufmgr_init_cache_state(tbm_bufmgr_exynos bufmgr_exynos) bufmgr_exynos->tgl_fd = open(tgl_devfile, O_RDWR); if (bufmgr_exynos->tgl_fd < 0) { - bufmgr_exynos->tgl_fd = open(tgl_devfile1, O_RDWR); - if (bufmgr_exynos->tgl_fd < 0) { + bufmgr_exynos->tgl_fd = open(tgl_devfile1, O_RDWR); + if (bufmgr_exynos->tgl_fd < 0) { TBM_EXYNOS_ERROR("fail to open global_lock:%s\n", tgl_devfile1); - return 0; - } + return 0; + } } #ifdef TGL_GET_VERSION if (!_tgl_get_version(bufmgr_exynos->tgl_fd)) { TBM_EXYNOS_ERROR("fail to get tgl_version. tgl init failed.\n"); - close(bufmgr_sprd->tgl_fd); + close(bufmgr_exynos->tgl_fd); return 0; } #endif @@ -751,15 +755,14 @@ _tbm_exynos_open_drm() static int _check_render_node(void) { +#ifndef USE_RENDER_NODE + return 0; +#else struct udev *udev = NULL; struct udev_enumerate *e = NULL; struct udev_list_entry *entry = NULL; struct udev_device *device = NULL, *drm_device = NULL, *device_parent = NULL; -#ifndef USE_RENDER_NODE - return 0; -#endif - udev = udev_new(); if (!udev) { TBM_EXYNOS_ERROR("udev_new() failed.\n"); @@ -798,6 +801,7 @@ _check_render_node(void) udev_device_unref(drm_device); return 1; +#endif } static int @@ -1008,35 +1012,44 @@ _exynos_bo_handle(tbm_bo_exynos bo_exynos, int device) } static int -tbm_exynos_bo_size(tbm_bo bo) +tbm_exynos_bo_get_size(tbm_backend_bo_data *bo_data, tbm_error_e *error) { - EXYNOS_RETURN_VAL_IF_FAIL(bo != NULL, 0); + tbm_bo_exynos bo_exynos = (tbm_bo_exynos)bo_data; - tbm_bo_exynos bo_exynos; + if (!bo_exynos) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return 0; + } - bo_exynos = (tbm_bo_exynos)tbm_backend_get_bo_priv(bo); - EXYNOS_RETURN_VAL_IF_FAIL(bo_exynos != NULL, 0); + if (error) + *error = TBM_ERROR_NONE; return bo_exynos->size; } -static void * -tbm_exynos_bo_alloc(tbm_bo bo, int size, int flags) +static tbm_backend_bo_data * +tbm_exynos_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, int size, tbm_bo_memory_type flags, tbm_error_e *error) { - EXYNOS_RETURN_VAL_IF_FAIL(bo != NULL, 0); - + tbm_bufmgr_exynos bufmgr_exynos = (tbm_bufmgr_exynos)bufmgr_data; tbm_bo_exynos bo_exynos; - tbm_bufmgr_exynos bufmgr_exynos; unsigned int exynos_flags; - bufmgr_exynos = (tbm_bufmgr_exynos)tbm_backend_get_bufmgr_priv(bo); - EXYNOS_RETURN_VAL_IF_FAIL(bufmgr_exynos != NULL, 0); + if (bufmgr_exynos == NULL) { + TBM_EXYNOS_ERROR("bufmgr_data is null\n"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return NULL; + } bo_exynos = calloc(1, sizeof(struct _tbm_bo_exynos)); if (!bo_exynos) { - TBM_EXYNOS_ERROR("fail to allocate the bo private\n"); - return 0; + TBM_EXYNOS_ERROR("fail to allocate the bo_exynos private\n"); + if (error) + *error = TBM_ERROR_OUT_OF_MEMORY; + return NULL; } + bo_exynos->bufmgr_exynos = bufmgr_exynos; exynos_flags = _get_exynos_flag_from_tbm(flags); if ((flags & TBM_BO_SCANOUT) && @@ -1050,10 +1063,12 @@ tbm_exynos_bo_alloc(tbm_bo bo, int size, int flags) arg.flags = exynos_flags; if (drmCommandWriteRead(bufmgr_exynos->fd, DRM_EXYNOS_GEM_CREATE, &arg, sizeof(arg))) { - TBM_EXYNOS_ERROR("Cannot create bo(flag:%x, size:%d)\n", arg.flags, + TBM_EXYNOS_ERROR("Cannot create bo_exynos(flag:%x, size:%d)\n", arg.flags, (unsigned int)arg.size); free(bo_exynos); - return 0; + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + return NULL; } bo_exynos->fd = bufmgr_exynos->fd; @@ -1066,64 +1081,69 @@ tbm_exynos_bo_alloc(tbm_bo bo, int size, int flags) if (!_bo_init_cache_state(bufmgr_exynos, bo_exynos, 0)) { TBM_EXYNOS_ERROR("fail init cache state(%d)\n", bo_exynos->name); free(bo_exynos); - return 0; + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + return NULL; } pthread_mutex_init(&bo_exynos->mutex, NULL); - if (bufmgr_exynos->use_dma_fence - && !bo_exynos->dmabuf) { + if (bufmgr_exynos->use_dma_fence && !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("Cannot dmabuf=%d\n", bo_exynos->gem); free(bo_exynos); - return 0; + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + return NULL; } bo_exynos->dmabuf = arg.fd; } - if (drmHashInsert(bufmgr_exynos->hashBos, bo_exynos->name, - (void *)bo_exynos) < 0) { - TBM_EXYNOS_ERROR("Cannot insert bo to Hash(%d)\n", bo_exynos->name); - } + /* 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_DEBUG(" bo:%p, gem:%d(%d), flags:%d(%d), size:%d\n", - bo, - bo_exynos->gem, bo_exynos->name, - flags, exynos_flags, - bo_exynos->size); + TBM_EXYNOS_DEBUG(" bo_exynos:%p, gem:%d(%d), flags:%d(%d), size:%d\n", + bo_exynos, + bo_exynos->gem, bo_exynos->name, + flags, exynos_flags, + bo_exynos->size); + + if (error) + *error = TBM_ERROR_NONE; - return (void *)bo_exynos; + return (tbm_backend_bo_data *)bo_exynos; } static void -tbm_exynos_bo_free(tbm_bo bo) +tbm_exynos_bo_free(tbm_backend_bo_data *bo_data) { - tbm_bo_exynos bo_exynos, temp; + 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) + if (!bo_data) return; - bufmgr_exynos = (tbm_bufmgr_exynos)tbm_backend_get_bufmgr_priv(bo); - EXYNOS_RETURN_IF_FAIL(bufmgr_exynos != NULL); - - bo_exynos = (tbm_bo_exynos)tbm_backend_get_bo_priv(bo); - EXYNOS_RETURN_IF_FAIL(bo_exynos != NULL); + bufmgr_exynos = bo_exynos->bufmgr_exynos; + if (!bufmgr_exynos) + return; - TBM_EXYNOS_DEBUG(" bo:%p, gem:%d(%d), fd:%d, size:%d\n", - bo, + 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:%p fail to munmap(%s)\n", - bo, strerror_r(errno, buf, STRERR_BUFSIZE)); + TBM_EXYNOS_ERROR("bo_exynos:%p fail to munmap(%s)\n", + bo_exynos, strerror_r(errno, buf, STRERR_BUFSIZE)); } } @@ -1133,17 +1153,12 @@ tbm_exynos_bo_free(tbm_bo bo) bo_exynos->dmabuf = 0; } - /* delete bo from hash */ - int ret; - - ret = drmHashLookup(bufmgr_exynos->hashBos, bo_exynos->name, - (void **)&temp); - if (ret == 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 to Hash(%d), ret=%d\n", - bo_exynos->name, ret); - } + 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"); @@ -1155,30 +1170,33 @@ tbm_exynos_bo_free(tbm_bo bo) memset(&arg, 0, sizeof(arg)); arg.handle = bo_exynos->gem; - if (drmIoctl(bo_exynos->fd, DRM_IOCTL_GEM_CLOSE, &arg)) { - TBM_EXYNOS_ERROR("bo:%p fail to gem close.(%s)\n", - bo, strerror_r(errno, buf, STRERR_BUFSIZE)); - } + 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 void * -tbm_exynos_bo_import(tbm_bo bo, unsigned int key) +static tbm_backend_bo_data * +tbm_exynos_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tbm_error_e *error) { - EXYNOS_RETURN_VAL_IF_FAIL(bo != NULL, 0); - - tbm_bufmgr_exynos bufmgr_exynos; + tbm_bufmgr_exynos bufmgr_exynos = (tbm_bufmgr_exynos)bufmgr_data; tbm_bo_exynos bo_exynos; int ret; - bufmgr_exynos = (tbm_bufmgr_exynos)tbm_backend_get_bufmgr_priv(bo); - EXYNOS_RETURN_VAL_IF_FAIL(bufmgr_exynos != NULL, 0); + if (bufmgr_exynos == NULL) { + TBM_EXYNOS_ERROR("bufmgr_data is null\n"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return NULL; + } ret = drmHashLookup(bufmgr_exynos->hashBos, key, (void **)&bo_exynos); - if (ret == 0) - return bo_exynos; + if (ret == 0) { + if (error) + *error = TBM_ERROR_NONE; + return (tbm_backend_bo_data *)bo_exynos; + } struct drm_gem_open arg = {0, }; struct drm_exynos_gem_info info = {0, }; @@ -1186,7 +1204,9 @@ tbm_exynos_bo_import(tbm_bo bo, unsigned int key) arg.name = key; if (drmIoctl(bufmgr_exynos->fd, DRM_IOCTL_GEM_OPEN, &arg)) { TBM_EXYNOS_ERROR("Cannot open gem name=%d\n", key); - return 0; + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + return NULL; } info.handle = arg.handle; @@ -1195,14 +1215,19 @@ tbm_exynos_bo_import(tbm_bo bo, unsigned int key) &info, sizeof(struct drm_exynos_gem_info))) { TBM_EXYNOS_ERROR("Cannot get gem info=%d\n", key); - return 0; + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + return NULL; } bo_exynos = calloc(1, sizeof(struct _tbm_bo_exynos)); if (!bo_exynos) { - TBM_EXYNOS_ERROR("fail to allocate the bo private\n"); - return 0; + TBM_EXYNOS_ERROR("fail to allocate the bo_exynos private\n"); + if (error) + *error = TBM_ERROR_OUT_OF_MEMORY; + return NULL; } + bo_exynos->bufmgr_exynos = bufmgr_exynos; bo_exynos->fd = bufmgr_exynos->fd; bo_exynos->gem = arg.handle; @@ -1214,7 +1239,9 @@ tbm_exynos_bo_import(tbm_bo bo, unsigned int key) if (!_bo_init_cache_state(bufmgr_exynos, bo_exynos, 1)) { TBM_EXYNOS_ERROR("fail init cache state(%d)\n", bo_exynos->name); free(bo_exynos); - return 0; + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + return NULL; } if (!bo_exynos->dmabuf) { @@ -1223,77 +1250,89 @@ tbm_exynos_bo_import(tbm_bo bo, unsigned int key) 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 0; + return NULL; } bo_exynos->dmabuf = arg.fd; } - /* add bo to hash */ - if (drmHashInsert(bufmgr_exynos->hashBos, bo_exynos->name, - (void *)bo_exynos) < 0) { - TBM_EXYNOS_ERROR("Cannot insert bo to Hash(%d)\n", bo_exynos->name); - } + /* 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_DEBUG(" bo:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d\n", - bo, + 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); - return (void *)bo_exynos; + if (error) + *error = TBM_ERROR_NONE; + + return (tbm_backend_bo_data *)bo_exynos; } -static void * -tbm_exynos_bo_import_fd(tbm_bo bo, tbm_fd key) +static tbm_backend_bo_data * +tbm_exynos_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_error_e *error) { - EXYNOS_RETURN_VAL_IF_FAIL(bo != NULL, 0); - - tbm_bufmgr_exynos bufmgr_exynos; + 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]; - bufmgr_exynos = (tbm_bufmgr_exynos)tbm_backend_get_bufmgr_priv(bo); - EXYNOS_RETURN_VAL_IF_FAIL(bufmgr_exynos != NULL, 0); + if (bufmgr_exynos == NULL) { + TBM_EXYNOS_ERROR("bufmgr_data is null\n"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return NULL; + } /*getting handle from fd*/ - unsigned int gem = 0; 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("bo:%p Cannot get gem handle from fd:%d (%s)\n", - bo, arg.fd, strerror_r(errno, buf, STRERR_BUFSIZE)); + 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_OPERATION_FAILED; return NULL; } gem = arg.handle; name = _get_name(bufmgr_exynos->fd, gem); if (!name) { - TBM_EXYNOS_ERROR("bo:%p Cannot get name from gem:%d, fd:%d (%s)\n", - bo, gem, key, strerror_r(errno, buf, STRERR_BUFSIZE)); - return 0; + 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; } ret = drmHashLookup(bufmgr_exynos->hashBos, name, (void **)&bo_exynos); if (ret == 0) { - if (gem == bo_exynos->gem) + if (gem == bo_exynos->gem) { + if (error) + *error = TBM_ERROR_NONE; return bo_exynos; + } } - unsigned int real_size = -1; - struct drm_exynos_gem_info info = {0, }; - - /* Determine size of bo. The fd-to-handle ioctl really should + /* 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; @@ -1301,9 +1340,11 @@ tbm_exynos_bo_import_fd(tbm_bo bo, tbm_fd key) DRM_EXYNOS_GEM_GET, &info, sizeof(struct drm_exynos_gem_info))) { - TBM_EXYNOS_ERROR("bo:%p Cannot get gem info from gem:%d, fd:%d (%s)\n", - bo, gem, key, strerror_r(errno, buf, STRERR_BUFSIZE)); - return 0; + 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) @@ -1311,9 +1352,12 @@ tbm_exynos_bo_import_fd(tbm_bo bo, tbm_fd key) bo_exynos = calloc(1, sizeof(struct _tbm_bo_exynos)); if (!bo_exynos) { - TBM_EXYNOS_ERROR("bo:%p fail to allocate the bo private\n", bo); - return 0; + 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; } + bo_exynos->bufmgr_exynos = bufmgr_exynos; bo_exynos->fd = bufmgr_exynos->fd; bo_exynos->gem = gem; @@ -1325,106 +1369,124 @@ tbm_exynos_bo_import_fd(tbm_bo bo, tbm_fd key) if (!_bo_init_cache_state(bufmgr_exynos, bo_exynos, 1)) { TBM_EXYNOS_ERROR("fail init cache state(%d)\n", bo_exynos->name); free(bo_exynos); - return 0; + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + return NULL; } - /* add bo to hash */ - if (drmHashInsert(bufmgr_exynos->hashBos, bo_exynos->name, - (void *)bo_exynos) < 0) { - TBM_EXYNOS_ERROR("bo:%p Cannot insert bo to Hash(%d) from gem:%d, fd:%d\n", - bo, bo_exynos->name, gem, key); - } + /* 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_DEBUG(" bo:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", - bo, + 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); - return (void *)bo_exynos; + if (error) + *error = TBM_ERROR_NONE; + + return (tbm_backend_bo_data *)bo_exynos; } -static unsigned int -tbm_exynos_bo_export(tbm_bo bo) +static tbm_key +tbm_exynos_bo_export_key(tbm_backend_bo_data *bo_data, tbm_error_e *error) { - EXYNOS_RETURN_VAL_IF_FAIL(bo != NULL, 0); - - tbm_bo_exynos bo_exynos; + tbm_bo_exynos bo_exynos = (tbm_bo_exynos)bo_data; - bo_exynos = (tbm_bo_exynos)tbm_backend_get_bo_priv(bo); - EXYNOS_RETURN_VAL_IF_FAIL(bo_exynos != NULL, 0); + 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("Cannot get name\n"); + TBM_EXYNOS_ERROR("error Cannot get name\n"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; return 0; } } - TBM_EXYNOS_DEBUG(" bo:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d\n", - bo, + 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); - return (unsigned int)bo_exynos->name; + if (error) + *error = TBM_ERROR_NONE; + + return (tbm_key)bo_exynos->name; } -tbm_fd -tbm_exynos_bo_export_fd(tbm_bo bo) +static tbm_fd +tbm_exynos_bo_export_fd(tbm_backend_bo_data *bo_data, tbm_error_e *error) { - EXYNOS_RETURN_VAL_IF_FAIL(bo != NULL, -1); - - tbm_bo_exynos bo_exynos; + tbm_bo_exynos bo_exynos = (tbm_bo_exynos)bo_data; int ret; char buf[STRERR_BUFSIZE]; - bo_exynos = (tbm_bo_exynos)tbm_backend_get_bo_priv(bo); - EXYNOS_RETURN_VAL_IF_FAIL(bo_exynos != NULL, -1); + 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:%p Cannot dmabuf=%d (%s)\n", - bo, bo_exynos->gem, strerror_r(errno, buf, STRERR_BUFSIZE)); + 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:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", - bo, + 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_bo_handle -tbm_exynos_bo_get_handle(tbm_bo bo, int device) +tbm_exynos_bo_get_handle(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, tbm_error_e *error) { - EXYNOS_RETURN_VAL_IF_FAIL(bo != NULL, (tbm_bo_handle) NULL); - + tbm_bo_exynos bo_exynos = (tbm_bo_exynos)bo_data; tbm_bo_handle bo_handle; - tbm_bo_exynos bo_exynos; - bo_exynos = (tbm_bo_exynos)tbm_backend_get_bo_priv(bo); - EXYNOS_RETURN_VAL_IF_FAIL(bo_exynos != NULL, (tbm_bo_handle) NULL); + if (!bo_exynos) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return (tbm_bo_handle) NULL; + } if (!bo_exynos->gem) { TBM_EXYNOS_ERROR("Cannot map gem=%d\n", bo_exynos->gem); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; return (tbm_bo_handle) NULL; } - TBM_EXYNOS_DEBUG("bo:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d, %s\n", - bo, + TBM_EXYNOS_DEBUG("bo_exynos:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d, %s\n", + bo_exynos, bo_exynos->gem, bo_exynos->name, bo_exynos->dmabuf, bo_exynos->flags_tbm, bo_exynos->flags_exynos, @@ -1436,34 +1498,47 @@ tbm_exynos_bo_get_handle(tbm_bo bo, int device) if (bo_handle.ptr == NULL) { TBM_EXYNOS_ERROR("Cannot get handle: gem:%d, device:%d\n", bo_exynos->gem, device); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; return (tbm_bo_handle) NULL; } + if (error) + *error = TBM_ERROR_NONE; + return bo_handle; } static tbm_bo_handle -tbm_exynos_bo_map(tbm_bo bo, int device, int opt) +tbm_exynos_bo_map(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, + tbm_bo_access_option opt, tbm_error_e *error) { - EXYNOS_RETURN_VAL_IF_FAIL(bo != NULL, (tbm_bo_handle) NULL); - + tbm_bo_exynos bo_exynos = (tbm_bo_exynos)bo_data; tbm_bo_handle bo_handle; - tbm_bo_exynos bo_exynos; tbm_bufmgr_exynos bufmgr_exynos; - bufmgr_exynos = (tbm_bufmgr_exynos)tbm_backend_get_bufmgr_priv(bo); - EXYNOS_RETURN_VAL_IF_FAIL(bufmgr_exynos != NULL, (tbm_bo_handle)NULL); + if (!bo_exynos) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return (tbm_bo_handle) NULL; + } - bo_exynos = (tbm_bo_exynos)tbm_backend_get_bo_priv(bo); - EXYNOS_RETURN_VAL_IF_FAIL(bo_exynos != NULL, (tbm_bo_handle) NULL); + bufmgr_exynos = bo_exynos->bufmgr_exynos; + if (!bufmgr_exynos) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return (tbm_bo_handle) NULL; + } if (!bo_exynos->gem) { TBM_EXYNOS_ERROR("Cannot map gem=%d\n", bo_exynos->gem); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; return (tbm_bo_handle) NULL; } - TBM_EXYNOS_DEBUG(" bo:%p, gem:%d(%d), fd:%d, %s, %s\n", - bo, + TBM_EXYNOS_DEBUG(" bo_exynos:%p, gem:%d(%d), fd:%d, %s, %s\n", + bo_exynos, bo_exynos->gem, bo_exynos->name, bo_exynos->dmabuf, STR_DEVICE[device], @@ -1474,6 +1549,8 @@ tbm_exynos_bo_map(tbm_bo bo, int device, int opt) if (bo_handle.ptr == NULL) { TBM_EXYNOS_ERROR("Cannot get handle: gem:%d, device:%d, opt:%d\n", bo_exynos->gem, device, opt); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; return (tbm_bo_handle) NULL; } @@ -1484,26 +1561,27 @@ tbm_exynos_bo_map(tbm_bo bo, int device, int opt) bo_exynos->map_cnt++; + if (error) + *error = TBM_ERROR_NONE; + return bo_handle; } -static int -tbm_exynos_bo_unmap(tbm_bo bo) +static tbm_error_e +tbm_exynos_bo_unmap(tbm_backend_bo_data *bo_data) { - EXYNOS_RETURN_VAL_IF_FAIL(bo != NULL, 0); - - tbm_bo_exynos bo_exynos; + tbm_bo_exynos bo_exynos = (tbm_bo_exynos)bo_data; tbm_bufmgr_exynos bufmgr_exynos; - bufmgr_exynos = (tbm_bufmgr_exynos)tbm_backend_get_bufmgr_priv(bo); - EXYNOS_RETURN_VAL_IF_FAIL(bufmgr_exynos != NULL, 0); - - bo_exynos = (tbm_bo_exynos)tbm_backend_get_bo_priv(bo); - EXYNOS_RETURN_VAL_IF_FAIL(bo_exynos != NULL, 0); + if (!bo_exynos) + return TBM_ERROR_INVALID_PARAMETER; + bufmgr_exynos = bo_exynos->bufmgr_exynos; + if (!bufmgr_exynos) + return TBM_ERROR_INVALID_PARAMETER; if (!bo_exynos->gem) - return 0; + return TBM_ERROR_INVALID_PARAMETER; bo_exynos->map_cnt--; @@ -1516,38 +1594,38 @@ tbm_exynos_bo_unmap(tbm_bo bo) bo_exynos->last_map_device = -1; - TBM_EXYNOS_DEBUG(" bo:%p, gem:%d(%d), fd:%d\n", - bo, + TBM_EXYNOS_DEBUG(" bo_exynos:%p, gem:%d(%d), fd:%d\n", + bo_exynos, bo_exynos->gem, bo_exynos->name, bo_exynos->dmabuf); - return 1; + return TBM_ERROR_NONE; } -static int -tbm_exynos_bo_lock(tbm_bo bo, int device, int opt) +static tbm_error_e +tbm_exynos_bo_lock(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, + tbm_bo_access_option opt) { - EXYNOS_RETURN_VAL_IF_FAIL(bo != NULL, 0); - #ifndef ALWAYS_BACKEND_CTRL + tbm_bo_exynos bo_exynos = (tbm_bo_exynos)bo_data; tbm_bufmgr_exynos bufmgr_exynos; - tbm_bo_exynos bo_exynos; struct dma_buf_fence fence; struct flock filelock; int ret = 0; char buf[STRERR_BUFSIZE]; + if (!bo_exynos) + return TBM_ERROR_INVALID_PARAMETER; + + bufmgr_exynos = bo_exynos->bufmgr_exynos; + if (!bufmgr_exynos) + return TBM_ERROR_INVALID_PARAMETER; + if (device != TBM_DEVICE_3D && device != TBM_DEVICE_CPU) { TBM_EXYNOS_DEBUG("Not support device type,\n"); - return 0; + return TBM_ERROR_OPERATION_FAILED; } - bo_exynos = (tbm_bo_exynos)tbm_backend_get_bo_priv(bo); - EXYNOS_RETURN_VAL_IF_FAIL(bo_exynos != NULL, 0); - - bufmgr_exynos = (tbm_bufmgr_exynos)tbm_backend_get_bufmgr_priv(bo); - EXYNOS_RETURN_VAL_IF_FAIL(bufmgr_exynos != NULL, 0); - memset(&fence, 0, sizeof(struct dma_buf_fence)); /* Check if the given type is valid or not. */ @@ -1559,13 +1637,13 @@ tbm_exynos_bo_lock(tbm_bo bo, int device, int opt) fence.type = DMA_BUF_ACCESS_READ | DMA_BUF_ACCESS_DMA; } else { TBM_EXYNOS_ERROR("Invalid argument\n"); - return 0; + return TBM_ERROR_INVALID_PARAMETER; } /* Check if the tbm manager supports dma fence or not. */ if (!bufmgr_exynos->use_dma_fence) { TBM_EXYNOS_ERROR("Not support DMA FENCE(%s)\n", strerror_r(errno, buf, STRERR_BUFSIZE)); - return 0; + return TBM_ERROR_OPERATION_FAILED; } @@ -1573,7 +1651,7 @@ tbm_exynos_bo_lock(tbm_bo bo, int device, int opt) ret = ioctl(bo_exynos->dmabuf, DMABUF_IOCTL_GET_FENCE, &fence); if (ret < 0) { TBM_EXYNOS_ERROR("Cannot set GET FENCE(%s)\n", strerror_r(errno, buf, STRERR_BUFSIZE)); - return 0; + return TBM_ERROR_OPERATION_FAILED; } } else { if (opt & TBM_OPTION_WRITE) @@ -1586,7 +1664,7 @@ tbm_exynos_bo_lock(tbm_bo bo, int device, int opt) filelock.l_len = 0; if (-1 == fcntl(bo_exynos->dmabuf, F_SETLKW, &filelock)) - return 0; + return TBM_ERROR_OPERATION_FAILED; } pthread_mutex_lock(&bo_exynos->mutex); @@ -1610,42 +1688,41 @@ tbm_exynos_bo_lock(tbm_bo bo, int device, int opt) pthread_mutex_unlock(&bo_exynos->mutex); - TBM_EXYNOS_DEBUG("DMABUF_IOCTL_GET_FENCE! bo:%p, gem:%d(%d), fd:%ds\n", - bo, + TBM_EXYNOS_DEBUG("DMABUF_IOCTL_GET_FENCE! bo_exynos:%p, gem:%d(%d), fd:%ds\n", + bo_exynos, bo_exynos->gem, bo_exynos->name, bo_exynos->dmabuf); #endif /* ALWAYS_BACKEND_CTRL */ - return 1; + return TBM_ERROR_NONE; } -static int -tbm_exynos_bo_unlock(tbm_bo bo) +static tbm_error_e +tbm_exynos_bo_unlock(tbm_backend_bo_data *bo_data) { - EXYNOS_RETURN_VAL_IF_FAIL(bo != NULL, 0); - #ifndef ALWAYS_BACKEND_CTRL - tbm_bo_exynos bo_exynos; + tbm_bo_exynos bo_exynos = (tbm_bo_exynos)bo_data; struct dma_buf_fence fence; struct flock filelock; unsigned int dma_type = 0; int ret = 0; char buf[STRERR_BUFSIZE]; - bo_exynos = (tbm_bo_exynos)tbm_backend_get_bo_priv(bo); - EXYNOS_RETURN_VAL_IF_FAIL(bo_exynos != NULL, 0); + bufmgr_exynos = bo_exynos->bufmgr_exynos; + if (!bufmgr_exynos) + return TBM_ERROR_INVALID_PARAMETER; if (bo_exynos->dma_fence[0].type & DMA_BUF_ACCESS_DMA) dma_type = 1; if (!bo_exynos->dma_fence[0].ctx && dma_type) { TBM_EXYNOS_DEBUG("FENCE not support or ignored,\n"); - return 0; + return TBM_ERROR_OPERATION_FAILED; } if (!bo_exynos->dma_fence[0].ctx && dma_type) { TBM_EXYNOS_DEBUG("device type is not 3D/CPU,\n"); - return 0; + return TBM_ERROR_OPERATION_FAILED; } pthread_mutex_lock(&bo_exynos->mutex); @@ -1668,7 +1745,7 @@ tbm_exynos_bo_unlock(tbm_bo bo) ret = ioctl(bo_exynos->dmabuf, DMABUF_IOCTL_PUT_FENCE, &fence); if (ret < 0) { TBM_EXYNOS_ERROR("Can not set PUT FENCE(%s)\n", strerror_r(errno, buf, STRERR_BUFSIZE)); - return 0; + return TBM_ERROR_OPERATION_FAILED; } } else { filelock.l_type = F_UNLCK; @@ -1677,31 +1754,35 @@ tbm_exynos_bo_unlock(tbm_bo bo) filelock.l_len = 0; if (-1 == fcntl(bo_exynos->dmabuf, F_SETLKW, &filelock)) - return 0; + return TBM_ERROR_OPERATION_FAILED; } - TBM_EXYNOS_DEBUG("DMABUF_IOCTL_PUT_FENCE! bo:%p, gem:%d(%d), fd:%ds\n", - bo, + TBM_EXYNOS_DEBUG("DMABUF_IOCTL_PUT_FENCE! bo_exynos:%p, gem:%d(%d), fd:%ds\n", + bo_exynos, bo_exynos->gem, bo_exynos->name, bo_exynos->dmabuf); #endif /* ALWAYS_BACKEND_CTRL */ - return 1; + return TBM_ERROR_NONE; } static void -tbm_exynos_bufmgr_deinit(void *priv) +tbm_exynos_deinit(tbm_backend_bufmgr_data *bufmgr_data) { - EXYNOS_RETURN_IF_FAIL(priv != NULL); + tbm_bufmgr_exynos bufmgr_exynos = (tbm_bufmgr_exynos)bufmgr_data; + tbm_bufmgr bufmgr; + tbm_error_e error; + unsigned long key; + void *value; - tbm_bufmgr_exynos bufmgr_exynos; + EXYNOS_RETURN_IF_FAIL(bufmgr_exynos != NULL); - bufmgr_exynos = (tbm_bufmgr_exynos)priv; + bufmgr = bufmgr_exynos->bufmgr; - if (bufmgr_exynos->hashBos) { - unsigned long key; - void *value; + tbm_backend_bufmgr_free_bufmgr_func(bufmgr, bufmgr_exynos->bufmgr_func); + tbm_backend_bufmgr_free_bo_func(bufmgr, bufmgr_exynos->bo_func); + if (bufmgr_exynos->hashBos) { while (drmHashFirst(bufmgr_exynos->hashBos, &key, &value) > 0) { free(value); drmHashDelete(bufmgr_exynos->hashBos, key); @@ -1719,7 +1800,7 @@ tbm_exynos_bufmgr_deinit(void *priv) if (bufmgr_exynos->device_name) free(bufmgr_exynos->device_name); - if (tbm_backend_is_display_server()) + if (tbm_backend_bufmgr_query_display_server(bufmgr, &error)) tbm_drm_helper_unset_tbm_master_fd(); else tbm_drm_helper_unset_fd(); @@ -1729,26 +1810,27 @@ tbm_exynos_bufmgr_deinit(void *priv) free(bufmgr_exynos); } -int -tbm_exynos_surface_supported_format(uint32_t **formats, uint32_t *num) +static tbm_error_e +tbm_exynos_bufmgr_get_supported_formats(tbm_backend_bufmgr_data *bufmgr_data, + uint32_t **formats, uint32_t *num) { - uint32_t *color_formats = NULL; + tbm_bufmgr_exynos bufmgr_exynos = (tbm_bufmgr_exynos)bufmgr_data; + uint32_t *color_formats; - color_formats = (uint32_t *)calloc(1, - sizeof(uint32_t) * TBM_COLOR_FORMAT_COUNT); + 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 0; + return TBM_ERROR_OUT_OF_MEMORY; - memcpy(color_formats, tbm_exynos_color_format_list, - sizeof(uint32_t)*TBM_COLOR_FORMAT_COUNT); + 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("tbm_exynos_surface_supported_format count = %d\n", *num); + TBM_EXYNOS_DEBUG("supported format count = %d\n", *num); - return 1; + return TBM_ERROR_NONE; } static int @@ -1804,30 +1886,21 @@ _new_calc_uvplane_nv12(int width, int height) TBM_SURFACE_ALIGNMENT_PLANE_NV12); } -/** - * @brief get the plane data of the surface. - * @param[in] width : the width of the surface - * @param[in] height : the height of the surface - * @param[in] format : the format of the surface - * @param[in] plane_idx : the format of the surface - * @param[out] size : the size of the plane - * @param[out] offset : the offset of the plane - * @param[out] pitch : the pitch of the plane - * @param[out] padding : the padding of the plane - * @return 1 if this function succeeds, otherwise 0. - */ -int -tbm_exynos_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 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) { - int ret = 1; + 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: @@ -2092,74 +2165,89 @@ tbm_exynos_surface_get_plane_data(int width, int height, *pitch = _pitch; *bo_idx = _bo_idx; - return ret; + return TBM_ERROR_NONE; } -int -tbm_exynos_bo_get_flags(tbm_bo bo) +static tbm_bo_memory_type +tbm_exynos_bo_get_memory_type(tbm_backend_bo_data *bo_data, tbm_error_e *error) { - EXYNOS_RETURN_VAL_IF_FAIL(bo != NULL, 0); + tbm_bo_exynos bo_exynos = (tbm_bo_exynos)bo_data; - tbm_bo_exynos bo_exynos; + if (!bo_exynos) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return TBM_BO_DEFAULT; + } - bo_exynos = (tbm_bo_exynos)tbm_backend_get_bo_priv(bo); - EXYNOS_RETURN_VAL_IF_FAIL(bo_exynos != NULL, 0); + if (error) + *error = TBM_ERROR_NONE; return bo_exynos->flags_tbm; } -int -tbm_exynos_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *native_display) +static tbm_bufmgr_capability +tbm_exynos_bufmgr_get_capabilities(tbm_backend_bufmgr_data *bufmgr_data, tbm_error_e *error) { - tbm_bufmgr_exynos bufmgr_exynos; + tbm_bufmgr_capability capabilities = TBM_BUFMGR_CAPABILITY_NONE; - bufmgr_exynos = tbm_backend_get_priv_from_bufmgr(bufmgr); - EXYNOS_RETURN_VAL_IF_FAIL(bufmgr_exynos != NULL, 0); + 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 0; + return TBM_ERROR_OPERATION_FAILED; } bufmgr_exynos->bind_display = native_display; - return 1; + return TBM_ERROR_NONE; } -MODULEINITPPROTO(init_tbm_bufmgr_priv); - -static TBMModuleVersionInfo ExynosVersRec = { - "exynos", - "Samsung", - TBM_ABI_VERSION, -}; - -TBMModuleData tbmModuleData = { &ExynosVersRec, init_tbm_bufmgr_priv}; - -int -init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd) +static tbm_backend_bufmgr_data * +tbm_exynos_init(tbm_bufmgr bufmgr, tbm_error_e *error) { - tbm_bufmgr_backend bufmgr_backend; - tbm_bufmgr_exynos bufmgr_exynos; + tbm_bufmgr_exynos bufmgr_exynos = NULL; + tbm_backend_bufmgr_func *bufmgr_func = NULL; + tbm_backend_bo_func *bo_func = NULL; int fp; + tbm_error_e err; char *value = NULL; - if (!bufmgr) - return 0; + if (!bufmgr) { + TBM_EXYNOS_ERROR("bufmgr is null.\n"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return NULL; + } bufmgr_exynos = calloc(1, sizeof(struct _tbm_bufmgr_exynos)); if (!bufmgr_exynos) { TBM_EXYNOS_ERROR("fail to alloc bufmgr_exynos!\n"); - return 0; + if (error) + *error = TBM_ERROR_OUT_OF_MEMORY; + return NULL; } - if (tbm_backend_is_display_server()) { + if (tbm_backend_bufmgr_query_display_server(bufmgr, &err)) { bufmgr_exynos->fd = tbm_drm_helper_get_master_fd(); if (bufmgr_exynos->fd < 0) { bufmgr_exynos->fd = _tbm_exynos_open_drm(); if (bufmgr_exynos->fd < 0) { - TBM_EXYNOS_ERROR("fail to open drm!\n", getpid()); + TBM_EXYNOS_ERROR("fail to open drm!\n"); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; goto fail_open_drm; } } @@ -2168,9 +2256,10 @@ init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd) bufmgr_exynos->device_name = drmGetDeviceNameFromFd(bufmgr_exynos->fd); if (!bufmgr_exynos->device_name) { - TBM_EXYNOS_ERROR("fail to get device name!\n", getpid()); - + TBM_EXYNOS_ERROR("fail to get device name!\n"); tbm_drm_helper_unset_tbm_master_fd(); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; goto fail_get_device_name; } } else { @@ -2178,15 +2267,18 @@ init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd) bufmgr_exynos->fd = _get_render_node(); if (bufmgr_exynos->fd < 0) { TBM_EXYNOS_ERROR("fail to get render node\n"); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; goto fail_get_render_node; } TBM_EXYNOS_DEBUG("Use render node:%d\n", bufmgr_exynos->fd); } else { if (!tbm_drm_helper_get_auth_info(&(bufmgr_exynos->fd), &(bufmgr_exynos->device_name), NULL)) { TBM_EXYNOS_ERROR("fail to get auth drm info!\n"); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; goto fail_get_auth_info; } - tbm_drm_helper_set_fd(bufmgr_exynos->fd); } } @@ -2226,43 +2318,70 @@ init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd) if (!_bufmgr_init_cache_state(bufmgr_exynos)) { TBM_EXYNOS_ERROR("fail to init bufmgr cache state\n"); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; goto fail_init_cache_state; } /*Create Hash Table*/ bufmgr_exynos->hashBos = drmHashCreate(); - bufmgr_backend = tbm_backend_alloc(); - if (!bufmgr_backend) { - TBM_EXYNOS_ERROR("fail to alloc backend!\n"); - goto fail_alloc_backend; - } - - bufmgr_backend->priv = (void *)bufmgr_exynos; - bufmgr_backend->bufmgr_deinit = tbm_exynos_bufmgr_deinit; - bufmgr_backend->bo_size = tbm_exynos_bo_size; - bufmgr_backend->bo_alloc = tbm_exynos_bo_alloc; - bufmgr_backend->bo_free = tbm_exynos_bo_free; - bufmgr_backend->bo_import = tbm_exynos_bo_import; - bufmgr_backend->bo_import_fd = tbm_exynos_bo_import_fd; - bufmgr_backend->bo_export = tbm_exynos_bo_export; - bufmgr_backend->bo_export_fd = tbm_exynos_bo_export_fd; - bufmgr_backend->bo_get_handle = tbm_exynos_bo_get_handle; - bufmgr_backend->bo_map = tbm_exynos_bo_map; - bufmgr_backend->bo_unmap = tbm_exynos_bo_unmap; - bufmgr_backend->surface_get_plane_data = tbm_exynos_surface_get_plane_data; - bufmgr_backend->surface_supported_format = tbm_exynos_surface_supported_format; - bufmgr_backend->bo_get_flags = tbm_exynos_bo_get_flags; - bufmgr_backend->bo_lock = tbm_exynos_bo_lock; - bufmgr_backend->bo_unlock = tbm_exynos_bo_unlock; - - if (tbm_backend_is_display_server() && !_check_render_node()) - bufmgr_backend->bufmgr_bind_native_display = tbm_exynos_bufmgr_bind_native_display; - - if (!tbm_backend_init(bufmgr, bufmgr_backend)) { - TBM_EXYNOS_ERROR("fail to init backend!\n"); - goto fail_init_backend; - } + /* alloc and register bufmgr_funcs */ + bufmgr_func = tbm_backend_bufmgr_alloc_bufmgr_func(bufmgr, &err); + if (!bufmgr_func) { + TBM_EXYNOS_ERROR("fail to alloc bufmgr_func! err(%d)\n", err); + if (error) + *error = TBM_ERROR_OUT_OF_MEMORY; + goto fail_alloc_bufmgr_func; + } + + bufmgr_func->bufmgr_get_capabilities = tbm_exynos_bufmgr_get_capabilities; + //if (tbm_backend_bufmgr_query_display_server(bufmgr, &err) && !_check_render_node()) + bufmgr_func->bufmgr_bind_native_display = tbm_exynos_bufmgr_bind_native_display; + bufmgr_func->bufmgr_get_supported_formats = tbm_exynos_bufmgr_get_supported_formats; + bufmgr_func->bufmgr_get_plane_data = tbm_exynos_bufmgr_get_plane_data; + bufmgr_func->bufmgr_alloc_bo = tbm_exynos_bufmgr_alloc_bo; + bufmgr_func->bufmgr_alloc_bo_with_format = NULL; + bufmgr_func->bufmgr_import_fd = tbm_exynos_bufmgr_import_fd; + bufmgr_func->bufmgr_import_key = tbm_exynos_bufmgr_import_key; + + err = tbm_backend_bufmgr_register_bufmgr_func(bufmgr, bufmgr_func); + if (err != TBM_ERROR_NONE) { + TBM_EXYNOS_ERROR("fail to register bufmgr_func! err(%d)\n", err); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + goto fail_register_bufmgr_func; + } + bufmgr_exynos->bufmgr_func = bufmgr_func; + + /* alloc and register bo_funcs */ + bo_func = tbm_backend_bufmgr_alloc_bo_func(bufmgr, &err); + if (!bo_func) { + TBM_EXYNOS_ERROR("fail to alloc bo_func! err(%d)\n", err); + if (error) + *error = TBM_ERROR_OUT_OF_MEMORY; + goto fail_alloc_bo_func; + } + + bo_func->bo_free = tbm_exynos_bo_free; + bo_func->bo_get_size = tbm_exynos_bo_get_size; + bo_func->bo_get_memory_types = tbm_exynos_bo_get_memory_type; + bo_func->bo_get_handle = tbm_exynos_bo_get_handle; + bo_func->bo_map = tbm_exynos_bo_map; + bo_func->bo_unmap = tbm_exynos_bo_unmap; + bo_func->bo_lock = tbm_exynos_bo_lock; + bo_func->bo_unlock = tbm_exynos_bo_unlock; + bo_func->bo_export_fd = tbm_exynos_bo_export_fd; + bo_func->bo_export_key = tbm_exynos_bo_export_key; + + err = tbm_backend_bufmgr_register_bo_func(bufmgr, bo_func); + if (err != TBM_ERROR_NONE) { + TBM_EXYNOS_ERROR("fail to register bo_func! err(%d)\n", err); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + goto fail_register_bo_func; + } + bufmgr_exynos->bo_func = bo_func; #ifdef DEBUG { @@ -2279,16 +2398,24 @@ init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd) TBM_EXYNOS_DEBUG("drm_fd:%d\n", bufmgr_exynos->fd); - return 1; + if (error) + *error = TBM_ERROR_NONE; + + bufmgr_exynos->bufmgr = bufmgr; + + return (tbm_backend_bufmgr_data *)bufmgr_exynos; -fail_init_backend: - tbm_backend_free(bufmgr_backend); -fail_alloc_backend: +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: + _bufmgr_deinit_cache_state(bufmgr_exynos); if (bufmgr_exynos->hashBos) drmHashDestroy(bufmgr_exynos->hashBos); - _bufmgr_deinit_cache_state(bufmgr_exynos); fail_init_cache_state: - if (tbm_backend_is_display_server()) + if (tbm_backend_bufmgr_query_display_server(bufmgr, &err)) tbm_drm_helper_unset_tbm_master_fd(); else tbm_drm_helper_unset_fd(); @@ -2298,6 +2425,13 @@ fail_get_auth_info: fail_get_render_node: fail_open_drm: free(bufmgr_exynos); - return 0; + return NULL; } +tbm_backend_module tbm_backend_module_data = { + "exynos", + "Samsung", + TBM_BACKEND_ABI_VERSION_2_0, + tbm_exynos_init, + tbm_exynos_deinit +};