tbm_module: add tbm_module_bo_map and use it
[platform/core/uifw/libtbm.git] / src / tbm_surface_internal.c
index 5f8ebcb..5089c60 100644 (file)
@@ -98,7 +98,8 @@ void _tbm_surface_mutex_unlock(void);
 #define TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(cond, val, error, error_type) {\
        if (!(cond)) {\
                TBM_ERR("'%s' failed.\n", #cond);\
-               error = error_type;\
+               if (error)\
+                       *error = error_type;\
                _tbm_set_last_result(error_type);\
                _tbm_surface_mutex_unlock();\
                return val;\
@@ -320,7 +321,6 @@ _tbm_surface_internal_query_plane_data(tbm_surface_h surface,
 
        struct _tbm_surface *surf = (struct _tbm_surface *)surface;
        struct _tbm_bufmgr *bufmgr = surf->bufmgr;
-       int ret = 0;
        tbm_error_e error;
 
        TBM_RETURN_VAL_IF_FAIL(bufmgr != NULL, 0);
@@ -328,54 +328,13 @@ _tbm_surface_internal_query_plane_data(tbm_surface_h surface,
        TBM_RETURN_VAL_IF_FAIL(surf->info.height > 0, 0);
        TBM_RETURN_VAL_IF_FAIL(surf->info.format > 0, 0);
 
-       if (bufmgr->use_hal_tbm) {
-               error = (tbm_error_e)hal_tbm_bufmgr_get_plane_data(bufmgr->hal_bufmgr, (hal_tbm_format)surf->info.format,
-                                                               plane_idx, surf->info.width, surf->info.height, size, offset, pitch, bo_idx);
-               /* LCOV_EXCL_START */
-               if (error == TBM_ERROR_NOT_SUPPORTED) {
-                       _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
-                       return 0;
-               } else if (error != TBM_ERROR_NONE) {
-                       TBM_ERR("Fail to surface_get_plane_data. surface(%p) error(%d)\n", surface, error);
-                       _tbm_set_last_result(error);
-                       return 0;
-               }
-               /* LCOV_EXCL_STOP */
-               ret = 1;
-       } else if (bufmgr->backend_module_data) {
-               if (!bufmgr->bufmgr_func->bufmgr_get_plane_data) {
-                       _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
-                       return 0;
-               }
-
-               error = bufmgr->bufmgr_func->bufmgr_get_plane_data(bufmgr->bufmgr_data, surf->info.format, plane_idx,
-                                               surf->info.width, surf->info.height, size, offset, pitch, bo_idx);
-               if (error != TBM_ERROR_NONE) {
-                       /* LCOV_EXCL_START */
-                       TBM_ERR("Fail to surface_get_plane_data. surface(%p) error(%d)\n", surface, error);
-                       _tbm_set_last_result(error);
-                       return 0;
-                       /* LCOV_EXCL_STOP */
-               }
-               ret = 1;
-       } else {
-               if (!bufmgr->backend->surface_get_plane_data) {
-                       _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
-                       return 0;
-               }
-
-               ret = bufmgr->backend->surface_get_plane_data(surf->info.width,
-                               surf->info.height, surf->info.format, plane_idx, size, offset, pitch, bo_idx);
-               if (!ret) {
-                       /* LCOV_EXCL_START */
-                       TBM_ERR("Fail to surface_get_plane_data. surface(%p)\n", surface);
-                       _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
-                       return 0;
-                       /* LCOV_EXCL_STOP */
-               }
+       error = tbm_module_bufmgr_get_plane_data(bufmgr->module, surf->info.format, plane_idx, surf->info.width, surf->info.height, size, offset, pitch, bo_idx);
+       if (error != TBM_ERROR_NONE) {
+               _tbm_set_last_result(error);
+               return 0;
        }
 
-       return ret;
+       return 1;
 }
 
 static void
@@ -703,60 +662,13 @@ _tbm_surface_internal_create_surface(tbm_bufmgr bufmgr, int width, int height, i
                                bo_size += surf->info.planes[j].size;
                }
 
-               if (bufmgr->use_hal_tbm) {
-                       surf->bos[i] = tbm_bo_alloc_with_format(bufmgr, format, i, width, height, surf->info.bpp/8, flags, error);
-                       if (*error == TBM_ERROR_NOT_SUPPORTED) {
-                               surf->bos[i] = tbm_bo_alloc(bufmgr, bo_size, flags);
-                               if (!surf->bos[i]) {
-                                       TBM_ERR("fail to alloc bo idx:%d\n", i);
-                                       *error = tbm_get_last_error();
-                                       goto alloc_bo_fail;
-                               }
-                       }
-               } else if (bufmgr->backend_module_data) {
-                       if (bufmgr->bufmgr_func->bufmgr_alloc_bo_with_format) {
-                               /* LCOV_EXCL_START */
-                               surf->bos[i] = tbm_bo_alloc_with_format(bufmgr, format, i, width, height, surf->info.bpp/8, flags, error);
-                               if (!surf->bos[i]) {
-                                       TBM_ERR("fail to tbm_bo_alloc_with_format idx:%d\n", i);
-                                       *error = tbm_get_last_error();
-                                       goto alloc_bo_fail;
-                               }
-                               /* LCOV_EXCL_STOP */
-                       } else if (bufmgr->bufmgr_func->bufmgr_alloc_bo_with_tiled_format && (flags & TBM_BO_TILED)) {
-                               /* LCOV_EXCL_START */
-                               surf->bos[i] = tbm_bo_alloc_with_tiled_format(bufmgr, width, height, surf->info.bpp/8, format, flags, i, error);
-                               if (!surf->bos[i]) {
-                                       TBM_ERR("fail to tbm_bo_alloc_with_tiled_format idx:%d\n", i);
-                                       *error = tbm_get_last_error();
-                                       goto alloc_bo_fail;
-                               }
-                               /* LCOV_EXCL_STOP */
-                       } else {
-                               surf->bos[i] = tbm_bo_alloc(bufmgr, bo_size, flags);
-                               if (!surf->bos[i]) {
-                                       TBM_ERR("fail to alloc bo idx:%d\n", i);
-                                       *error = tbm_get_last_error();
-                                       goto alloc_bo_fail;
-                               }
-                       }
-               } else {
-                       if (bufmgr->backend->surface_bo_alloc) {
-                               /* LCOV_EXCL_START */
-                               surf->bos[i] = tbm_bo_alloc_with_surface(bufmgr, width, height, format, flags, i);
-                               if (!surf->bos[i]) {
-                                       TBM_ERR("fail to tbm_bo_alloc_with_surface idx:%d\n", i);
-                                       *error = tbm_get_last_error();
-                                       goto alloc_bo_fail;
-                               /* LCOV_EXCL_STOP */
-                               }
-                       } else {
-                               surf->bos[i] = tbm_bo_alloc(bufmgr, bo_size, flags);
-                               if (!surf->bos[i]) {
-                                       TBM_ERR("fail to alloc bo idx:%d\n", i);
-                                       *error = tbm_get_last_error();
-                                       goto alloc_bo_fail;
-                               }
+               surf->bos[i] = tbm_bufmgr_internal_alloc_bo_with_format(bufmgr, format, i, width, height, surf->info.bpp/8, flags, error);
+               if (!surf->bos[i]) {
+                       surf->bos[i] = tbm_bo_alloc(bufmgr, bo_size, flags);
+                       if (!surf->bos[i]) {
+                               TBM_ERR("fail to alloc bo idx:%d\n", i);
+                               *error = tbm_get_last_error();
+                               goto alloc_bo_fail;
                        }
                }
 
@@ -855,7 +767,7 @@ _tbm_surface_internal_hal_tbm_create_surface(tbm_bufmgr bufmgr, int width, int h
                }
 
                for (i = 0; i < num_bos; i++) {
-                       surf->bos[i] = tbm_bo_alloc_with_bo_data(bufmgr, (tbm_backend_bo_data *)hal_bos[i], flags);
+                       surf->bos[i] = tbm_bufmgr_internal_alloc_bo_with_bo_data(bufmgr, (tbm_backend_bo_data *)hal_bos[i], flags);
                        if (!surf->bos[i]) {
                                TBM_ERR("fail to alloc bo idx:%d", i);
                                *error = tbm_get_last_error();
@@ -895,7 +807,7 @@ _tbm_surface_internal_hal_tbm_create_surface(tbm_bufmgr bufmgr, int width, int h
                                        bo_size += surf->info.planes[j].size;
                        }
 
-                       surf->bos[i] = tbm_bo_alloc_with_format(bufmgr, format, i, width, height, surf->info.bpp / 8, flags, error);
+                       surf->bos[i] = tbm_bufmgr_internal_alloc_bo_with_format(bufmgr, format, i, width, height, surf->info.bpp / 8, flags, error);
                        if (*error == TBM_ERROR_NOT_SUPPORTED) {
                                surf->bos[i] = tbm_bo_alloc(bufmgr, bo_size, flags);
                                if (!surf->bos[i]) {
@@ -975,7 +887,7 @@ _tbm_surface_internal_hal_tbm_import_surface(tbm_bufmgr bufmgr, int width, int h
        }
 
        // import surface
-       hal_surface = hal_tbm_bufmgr_import_surface(bufmgr->hal_bufmgr, 
+       hal_surface = hal_tbm_bufmgr_import_surface(bufmgr->hal_bufmgr,
                                                                                        (uint32_t)width,
                                                                                        (uint32_t)height,
                                                                                        (hal_tbm_format)format,
@@ -1024,7 +936,7 @@ _tbm_surface_internal_hal_tbm_import_surface(tbm_bufmgr bufmgr, int width, int h
        surf->flags = flags;
 
        for (i = 0; i < num_bos; i++) {
-               surf->bos[i] = tbm_bo_alloc_with_bo_data(bufmgr, (tbm_backend_bo_data *)hal_bos[i], flags);
+               surf->bos[i] = tbm_bufmgr_internal_alloc_bo_with_bo_data(bufmgr, (tbm_backend_bo_data *)hal_bos[i], flags);
                if (!surf->bos[i]) {
                        TBM_ERR("fail to alloc bo idx:%d", i);
                        *error = tbm_get_last_error();
@@ -1034,22 +946,17 @@ _tbm_surface_internal_hal_tbm_import_surface(tbm_bufmgr bufmgr, int width, int h
                _tbm_bo_set_surface(surf->bos[i], surf);
        }
 
-       *error = TBM_ERROR_NONE;
-
        return surf;
 
 get_bo_fail:
+       for (j = 0; j < i; j++) {
+               if (surf->bos[j])
+                       tbm_bo_unref(surf->bos[j]);
+       }
 get_memory_types_fail:
 get_bos_fail:
 query_plane_data_fail:
-       if (hal_surface) {
-               hal_tbm_surface_free(hal_surface);
-       } else {
-               for (j = 0; j < i; j++) {
-                       if (surf->bos[j])
-                               tbm_bo_unref(surf->bos[j]);
-               }
-       }
+       hal_tbm_surface_free(hal_surface);
 import_surface_fail:
 num_planes_fail:
 bpp_fail:
@@ -1087,7 +994,6 @@ tbm_surface_internal_query_supported_formats(uint32_t **formats,
                uint32_t *num)
 {
        struct _tbm_bufmgr *bufmgr;
-       int ret = 0;
        bool bufmgr_initialized = false;
        tbm_error_e error;
 
@@ -1110,46 +1016,10 @@ tbm_surface_internal_query_supported_formats(uint32_t **formats,
 
        bufmgr = g_surface_bufmgr;
 
-       if (bufmgr->use_hal_tbm) {
-               error = (tbm_error_e)hal_tbm_bufmgr_get_supported_formats(bufmgr->hal_bufmgr, formats, num);
-               /* LCOV_EXCL_START */
-               if (error == TBM_ERROR_NOT_SUPPORTED) {
-                       _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
-                       goto fail;
-               } else if (error != TBM_ERROR_NONE) {
-                       _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
-                       goto fail;
-               }
-               /* LCOV_EXCL_STOP */
-               ret = 1;
-       } else if (bufmgr->backend_module_data) {
-               if (!bufmgr->bufmgr_func->bufmgr_get_supported_formats) {
-                       _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
-                       goto fail;
-               }
-
-               error = bufmgr->bufmgr_func->bufmgr_get_supported_formats(bufmgr->bufmgr_data, formats, num);
-               if (error != TBM_ERROR_NONE) {
-                       /* LCOV_EXCL_START */
-                       TBM_ERR("Fail to surface_supported_format. error(%d)\n", error);
-                       goto fail;
-                       /* LCOV_EXCL_START */
-               }
-               ret = 1;
-       } else {
-               if (!bufmgr->backend->surface_supported_format) {
-                       _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
-                       goto fail;
-               }
-
-               ret = bufmgr->backend->surface_supported_format(formats, num);
-               if (!ret)  {
-                       /* LCOV_EXCL_START */
-                       TBM_ERR("Fail to surface_supported_format.\n");
-                       _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
-                       goto fail;
-                       /* LCOV_EXCL_START */
-               }
+       error = tbm_module_bufmgr_get_supported_formats(bufmgr->module, formats, num);
+       if (error != TBM_ERROR_NONE) {
+               _tbm_set_last_result(error);
+               goto fail;
        }
 
        TBM_TRACE_SURFACE_INTERNAL("tbm_bufmgr(%p) format num(%u)\n", g_surface_bufmgr, *num);
@@ -1161,7 +1031,7 @@ tbm_surface_internal_query_supported_formats(uint32_t **formats,
 
        _tbm_surface_mutex_unlock();
 
-       return ret;
+       return 1;
 
 /* LCOV_EXCL_START */
 fail:
@@ -3081,13 +2951,13 @@ tbm_surface_internal_export(tbm_surface_h surface, tbm_error_e *error)
        _tbm_surface_mutex_lock();
 
        surf = (struct _tbm_surface *)surface;
-       TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(_tbm_surface_internal_is_valid(surface), NULL, *error, TBM_ERROR_INVALID_PARAMETER);
+       TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(_tbm_surface_internal_is_valid(surface), NULL, error, TBM_ERROR_INVALID_PARAMETER);
 
        bufmgr = surf->bufmgr;
-       TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(bufmgr != NULL, NULL, *error, TBM_ERROR_INVALID_PARAMETER);
+       TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(bufmgr != NULL, NULL, error, TBM_ERROR_INVALID_PARAMETER);
 
        // this function supports when it comes to be use_hal.
-       TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(bufmgr->use_hal_tbm, NULL, *error, TBM_ERROR_NOT_SUPPORTED);
+       TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(bufmgr->use_hal_tbm, NULL, error, TBM_ERROR_NOT_SUPPORTED);
 
        // export a surface
        buffer_data = (tbm_surface_buffer_data *)hal_tbm_surface_export((hal_tbm_surface *)surf->hal_surface,
@@ -3096,9 +2966,6 @@ tbm_surface_internal_export(tbm_surface_h surface, tbm_error_e *error)
 
        TBM_TRACE_SURFACE_INTERNAL("tbm_surface(%p) buffer_data(%p)", surface, buffer_data);
 
-       if (error)
-               *error = TBM_ERROR_NONE;
-
        _tbm_set_last_result(TBM_ERROR_NONE);
        _tbm_surface_mutex_unlock();
 
@@ -3114,15 +2981,15 @@ tbm_surface_internal_import(tbm_surface_info_s *surface_info, tbm_surface_buffer
        _tbm_surface_mutex_lock();
 
        bufmgr = g_surface_bufmgr;
-       TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(bufmgr != NULL, NULL, *error, TBM_ERROR_INVALID_PARAMETER);
+       TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(bufmgr != NULL, NULL, error, TBM_ERROR_INVALID_PARAMETER);
 
        // this function supports when it comes to be use_hal.
-       TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(bufmgr->use_hal_tbm, NULL, *error, TBM_ERROR_NOT_SUPPORTED);
+       TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(bufmgr->use_hal_tbm, NULL, error, TBM_ERROR_NOT_SUPPORTED);
 
-       TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(surface_info != NULL, NULL, *error, TBM_ERROR_INVALID_PARAMETER);
-       TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(surface_info->width > 0, NULL, *error, TBM_ERROR_INVALID_PARAMETER);
-       TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(surface_info->height > 0, NULL, *error, TBM_ERROR_INVALID_PARAMETER);
-       TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(buffer_data != NULL, NULL, *error, TBM_ERROR_INVALID_PARAMETER);
+       TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(surface_info != NULL, NULL, error, TBM_ERROR_INVALID_PARAMETER);
+       TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(surface_info->width > 0, NULL, error, TBM_ERROR_INVALID_PARAMETER);
+       TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(surface_info->height > 0, NULL, error, TBM_ERROR_INVALID_PARAMETER);
+       TBM_SURFACE_RETURN_VAL_SET_ERR_IF_FAIL(buffer_data != NULL, NULL, error, TBM_ERROR_INVALID_PARAMETER);
 
        // import a surface
        surf = _tbm_surface_internal_hal_tbm_import_surface(bufmgr,
@@ -3141,9 +3008,6 @@ tbm_surface_internal_import(tbm_surface_info_s *surface_info, tbm_surface_buffer
 
        TBM_TRACE_SURFACE_INTERNAL("tbm_surface(%p)", surf);
 
-       if (error)
-               *error = TBM_ERROR_NONE;
-
        _tbm_set_last_result(TBM_ERROR_NONE);
        _tbm_surface_mutex_unlock();