surface_internal: add _tbm_set_last_result() 91/177191/1
authorSooChan Lim <sc1.lim@samsung.com>
Mon, 23 Apr 2018 09:43:15 +0000 (18:43 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Tue, 24 Apr 2018 12:27:36 +0000 (21:27 +0900)
Change-Id: Ife69a768e592402f7b57b821d1093859ce5bdc7c

src/tbm_surface_internal.c

index bb70ff4..c32b881 100644 (file)
@@ -55,6 +55,7 @@ void _tbm_surface_mutex_unlock(void);
 #define TBM_SURFACE_RETURN_IF_FAIL(cond) {\
        if (!(cond)) {\
                TBM_ERR("'%s' failed.\n", #cond);\
+               _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);\
                _tbm_surface_mutex_unlock();\
                return;\
        } \
@@ -63,6 +64,7 @@ void _tbm_surface_mutex_unlock(void);
 #define TBM_SURFACE_RETURN_VAL_IF_FAIL(cond, val) {\
        if (!(cond)) {\
                TBM_ERR("'%s' failed.\n", #cond);\
+               _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);\
                _tbm_surface_mutex_unlock();\
                return val;\
        } \
@@ -287,6 +289,8 @@ _tbm_surface_internal_is_valid(tbm_surface_h surface)
                }
        }
 
+       _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
+
        TBM_ERR("error: No valid tbm_surface(%p)\n", surface);
 
        return 0;
@@ -310,27 +314,33 @@ _tbm_surface_internal_query_plane_data(tbm_surface_h surface,
        TBM_RETURN_VAL_IF_FAIL(surf->info.format > 0, 0);
 
        if (bufmgr->backend_module_data) {
-               if (!bufmgr->bufmgr_func->bufmgr_get_plane_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)
+               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 */
                }
@@ -584,9 +594,11 @@ tbm_surface_internal_is_valid(tbm_surface_h surface)
        int ret = 0;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        /* Return silently if surface is null. */
        if (!surface) {
+               _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
                _tbm_surface_mutex_unlock();
                return 0;
        }
@@ -602,15 +614,16 @@ int
 tbm_surface_internal_query_supported_formats(uint32_t **formats,
                uint32_t *num)
 {
-       TBM_RETURN_VAL_IF_FAIL(formats, 0);
-       TBM_RETURN_VAL_IF_FAIL(num, 0);
-
        struct _tbm_bufmgr *bufmgr;
        int ret = 0;
        bool bufmgr_initialized = false;
        tbm_error_e error;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
+
+       TBM_SURFACE_RETURN_VAL_IF_FAIL(formats, 0);
+       TBM_SURFACE_RETURN_VAL_IF_FAIL(num, 0);
 
        if (!g_surface_bufmgr) {
                _init_surface_bufmgr();
@@ -621,8 +634,10 @@ tbm_surface_internal_query_supported_formats(uint32_t **formats,
        bufmgr = g_surface_bufmgr;
 
        if (bufmgr->backend_module_data) {
-               if (!bufmgr->bufmgr_func->bufmgr_get_supported_formats)
+               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) {
@@ -633,13 +648,16 @@ tbm_surface_internal_query_supported_formats(uint32_t **formats,
                }
                ret = 1;
        } else {
-               if (!bufmgr->backend->surface_supported_format)
+               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 */
                }
@@ -718,9 +736,6 @@ tbm_surface_h
 tbm_surface_internal_create_with_flags(int width, int height,
                                       int format, int flags)
 {
-       TBM_RETURN_VAL_IF_FAIL(width > 0, NULL);
-       TBM_RETURN_VAL_IF_FAIL(height > 0, NULL);
-
        struct _tbm_bufmgr *bufmgr;
        struct _tbm_surface *surf = NULL;
        uint32_t size = 0;
@@ -736,6 +751,10 @@ tbm_surface_internal_create_with_flags(int width, int height,
        tbm_error_e error;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
+
+       TBM_SURFACE_RETURN_VAL_IF_FAIL(width > 0, NULL);
+       TBM_SURFACE_RETURN_VAL_IF_FAIL(height > 0, NULL);
 
        if (!g_surface_bufmgr) {
                _init_surface_bufmgr();
@@ -753,6 +772,7 @@ tbm_surface_internal_create_with_flags(int width, int height,
        if (!surf) {
                /* LCOV_EXCL_START */
                TBM_ERR("fail to alloc surf\n");
+               _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
                goto alloc_surf_fail;
                /* LCOV_EXCL_STOP */
        }
@@ -811,6 +831,7 @@ tbm_surface_internal_create_with_flags(int width, int height,
                                bo = calloc(1, sizeof(struct _tbm_bo));
                                if (!bo) {
                                        TBM_ERR("fail to alloc bo struct\n");
+                                       _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
                                        goto alloc_bo_fail;
                                }
 
@@ -822,6 +843,7 @@ tbm_surface_internal_create_with_flags(int width, int height,
                                                                                                                                width, height, flags, &error);
                                if (!bo_data) {
                                        TBM_ERR("fail to alloc bo priv. error(%d)\n", error);
+                                       _tbm_set_last_result(error);
                                        free(bo);
                                        pthread_mutex_unlock(&surf->bufmgr->lock);
                                        goto alloc_bo_fail;
@@ -851,6 +873,7 @@ tbm_surface_internal_create_with_flags(int width, int height,
                                bo = calloc(1, sizeof(struct _tbm_bo));
                                if (!bo) {
                                        TBM_ERR("fail to alloc bo struct\n");
+                                       _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
                                        goto alloc_bo_fail;
                                }
 
@@ -861,6 +884,7 @@ tbm_surface_internal_create_with_flags(int width, int height,
                                bo_priv = bufmgr->backend->surface_bo_alloc(bo, width, height, format, flags, i);
                                if (!bo_priv) {
                                        TBM_ERR("fail to alloc bo priv\n");
+                                       _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
                                        free(bo);
                                        pthread_mutex_unlock(&surf->bufmgr->lock);
                                        goto alloc_bo_fail;
@@ -931,18 +955,19 @@ tbm_surface_h
 tbm_surface_internal_create_with_bos(tbm_surface_info_s *info,
                                     tbm_bo *bos, int num)
 {
-       TBM_RETURN_VAL_IF_FAIL(bos, NULL);
-       TBM_RETURN_VAL_IF_FAIL(info, NULL);
-       TBM_RETURN_VAL_IF_FAIL(info->num_planes > 0, NULL);
-       TBM_RETURN_VAL_IF_FAIL(num > 0, NULL);
-       TBM_RETURN_VAL_IF_FAIL(num == 1 || info->num_planes == num, NULL);
-
        struct _tbm_bufmgr *bufmgr;
        struct _tbm_surface *surf = NULL;
        int i;
        bool bufmgr_initialized = false;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
+
+       TBM_SURFACE_RETURN_VAL_IF_FAIL(bos, NULL);
+       TBM_SURFACE_RETURN_VAL_IF_FAIL(info, NULL);
+       TBM_SURFACE_RETURN_VAL_IF_FAIL(info->num_planes > 0, NULL);
+       TBM_SURFACE_RETURN_VAL_IF_FAIL(num > 0, NULL);
+       TBM_SURFACE_RETURN_VAL_IF_FAIL(num == 1 || info->num_planes == num, NULL);
 
        if (!g_surface_bufmgr) {
                _init_surface_bufmgr();
@@ -953,6 +978,7 @@ tbm_surface_internal_create_with_bos(tbm_surface_info_s *info,
        bufmgr = g_surface_bufmgr;
        if (!TBM_BUFMGR_IS_VALID(bufmgr)) {
                TBM_ERR("fail to validate the Bufmgr.\n");
+               _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
                goto check_valid_fail;
        }
 
@@ -960,6 +986,7 @@ tbm_surface_internal_create_with_bos(tbm_surface_info_s *info,
        if (!surf) {
                /* LCOV_EXCL_START */
                TBM_ERR("fail to allocate struct _tbm_surface.\n");
+               _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
                goto alloc_surf_fail;
                /* LCOV_EXCL_STOP */
        }
@@ -991,7 +1018,10 @@ tbm_surface_internal_create_with_bos(tbm_surface_info_s *info,
                        uint32_t size = 0, offset = 0, stride = 0;
                        int32_t bo_idx = 0;
 
-                       _tbm_surface_internal_query_plane_data(surf, i, &size, &offset, &stride, &bo_idx);
+                       if (!_tbm_surface_internal_query_plane_data(surf, i, &size, &offset, &stride, &bo_idx)) {
+                               TBM_ERR("fail to get plane_data. error(%s)\n", tbm_error_str(tbm_get_last_error()));
+                               goto plane_data_fail;
+                       }
                        surf->info.planes[i].size = size;
                }
 
@@ -1016,6 +1046,7 @@ tbm_surface_internal_create_with_bos(tbm_surface_info_s *info,
        for (i = 0; i < num; i++) {
                if (bos[i] == NULL) {
                        TBM_ERR("bos[%d] is null.\n", i);
+                       _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
                        goto check_bo_fail;
                }
 
@@ -1037,6 +1068,7 @@ tbm_surface_internal_create_with_bos(tbm_surface_info_s *info,
 
 /* LCOV_EXCL_START */
 check_bo_fail:
+plane_data_fail:
 bpp_fail:
        for (i = 0; i < num; i++) {
                if (surf->bos[i])
@@ -1063,6 +1095,7 @@ void
 tbm_surface_internal_destroy(tbm_surface_h surface)
 {
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_IF_FAIL(_tbm_surface_internal_is_valid(surface));
 
@@ -1086,6 +1119,7 @@ void
 tbm_surface_internal_ref(tbm_surface_h surface)
 {
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_IF_FAIL(_tbm_surface_internal_is_valid(surface));
 
@@ -1100,6 +1134,7 @@ void
 tbm_surface_internal_unref(tbm_surface_h surface)
 {
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_IF_FAIL(_tbm_surface_internal_is_valid(surface));
 
@@ -1126,12 +1161,16 @@ tbm_surface_internal_get_num_bos(tbm_surface_h surface)
        int num;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_VAL_IF_FAIL(_tbm_surface_internal_is_valid(surface), 0);
 
        surf = (struct _tbm_surface *)surface;
        num = surf->num_bos;
 
+       if (!num)
+               _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
+
        TBM_TRACE_SURFACE_INTERNAL("tbm_surface(%p) num_bos(%d)\n", surface, num);
 
        _tbm_surface_mutex_unlock();
@@ -1146,6 +1185,7 @@ tbm_surface_internal_get_bo(tbm_surface_h surface, int bo_idx)
        tbm_bo bo;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_VAL_IF_FAIL(_tbm_surface_internal_is_valid(surface), NULL);
        TBM_SURFACE_RETURN_VAL_IF_FAIL(bo_idx > -1, NULL);
@@ -1167,6 +1207,7 @@ tbm_surface_internal_get_size(tbm_surface_h surface)
        unsigned int size;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_VAL_IF_FAIL(_tbm_surface_internal_is_valid(surface), 0);
 
@@ -1187,6 +1228,7 @@ tbm_surface_internal_get_plane_data(tbm_surface_h surface, int plane_idx,
        struct _tbm_surface *surf;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_VAL_IF_FAIL(_tbm_surface_internal_is_valid(surface), 0);
        TBM_SURFACE_RETURN_VAL_IF_FAIL(plane_idx > -1, 0);
@@ -1195,6 +1237,7 @@ tbm_surface_internal_get_plane_data(tbm_surface_h surface, int plane_idx,
 
        if (plane_idx >= surf->info.num_planes) {
                TBM_TRACE_SURFACE_INTERNAL("error: tbm_surface(%p) plane_idx(%d)\n", surface, plane_idx);
+               _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
                _tbm_surface_mutex_unlock();
                return 0;
        }
@@ -1229,6 +1272,7 @@ tbm_surface_internal_get_info(tbm_surface_h surface, int opt,
        int i, j;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_VAL_IF_FAIL(_tbm_surface_internal_is_valid(surface), 0);
 
@@ -1299,6 +1343,7 @@ tbm_surface_internal_unmap(tbm_surface_h surface)
        int i;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_IF_FAIL(_tbm_surface_internal_is_valid(surface));
 
@@ -1319,6 +1364,7 @@ tbm_surface_internal_get_width(tbm_surface_h surface)
        unsigned int width;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_VAL_IF_FAIL(_tbm_surface_internal_is_valid(surface), 0);
 
@@ -1339,6 +1385,7 @@ tbm_surface_internal_get_height(tbm_surface_h surface)
        unsigned int height;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_VAL_IF_FAIL(_tbm_surface_internal_is_valid(surface), 0);
 
@@ -1360,6 +1407,7 @@ tbm_surface_internal_get_format(tbm_surface_h surface)
        tbm_format format;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_VAL_IF_FAIL(_tbm_surface_internal_is_valid(surface), 0);
 
@@ -1380,6 +1428,7 @@ tbm_surface_internal_get_plane_bo_idx(tbm_surface_h surface, int plane_idx)
        int bo_idx;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_VAL_IF_FAIL(_tbm_surface_internal_is_valid(surface), 0);
        TBM_SURFACE_RETURN_VAL_IF_FAIL(plane_idx > -1, 0);
@@ -1401,6 +1450,7 @@ tbm_surface_internal_add_user_data(tbm_surface_h surface, unsigned long key,
        tbm_user_data *data;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_VAL_IF_FAIL(_tbm_surface_internal_is_valid(surface), 0);
 
@@ -1408,6 +1458,7 @@ tbm_surface_internal_add_user_data(tbm_surface_h surface, unsigned long key,
        data = user_data_lookup(&surface->user_data_list, key);
        if (data) {
                TBM_TRACE_SURFACE_INTERNAL("warning: user data already exist tbm_surface(%p) key(%lu)\n", surface, key);
+               _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
                _tbm_surface_mutex_unlock();
                return 0;
        }
@@ -1435,12 +1486,14 @@ tbm_surface_internal_set_user_data(tbm_surface_h surface, unsigned long key,
        tbm_user_data *old_data;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_VAL_IF_FAIL(_tbm_surface_internal_is_valid(surface), 0);
 
        old_data = user_data_lookup(&surface->user_data_list, key);
        if (!old_data) {
                TBM_TRACE_SURFACE_INTERNAL("error: tbm_surface(%p) key(%lu)\n", surface, key);
+               _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
                _tbm_surface_mutex_unlock();
                return 0;
        }
@@ -1464,11 +1517,13 @@ tbm_surface_internal_get_user_data(tbm_surface_h surface, unsigned long key,
        tbm_user_data *old_data;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_VAL_IF_FAIL(_tbm_surface_internal_is_valid(surface), 0);
 
        if (!data) {
                TBM_ERR("error: tbm_surface(%p) key(%lu)\n", surface, key);
+               _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
                _tbm_surface_mutex_unlock();
                return 0;
        }
@@ -1477,6 +1532,7 @@ tbm_surface_internal_get_user_data(tbm_surface_h surface, unsigned long key,
        old_data = user_data_lookup(&surface->user_data_list, key);
        if (!old_data) {
                TBM_TRACE_SURFACE_INTERNAL("error: tbm_surface(%p) key(%lu)\n", surface, key);
+               _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
                _tbm_surface_mutex_unlock();
                return 0;
        }
@@ -1497,12 +1553,14 @@ tbm_surface_internal_delete_user_data(tbm_surface_h surface,
        tbm_user_data *old_data = (void *)0;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_VAL_IF_FAIL(_tbm_surface_internal_is_valid(surface), 0);
 
        old_data = user_data_lookup(&surface->user_data_list, key);
        if (!old_data) {
                TBM_TRACE_SURFACE_INTERNAL("error: tbm_surface(%p) key(%lu)\n", surface, key);
+               _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
                _tbm_surface_mutex_unlock();
                return 0;
        }
@@ -1529,6 +1587,7 @@ void
 tbm_surface_internal_set_debug_pid(tbm_surface_h surface, unsigned int pid)
 {
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_IF_FAIL(_tbm_surface_internal_is_valid(surface));
 
@@ -1543,8 +1602,11 @@ _tbm_surface_internal_debug_data_create(char *key, char *value)
        tbm_surface_debug_data *debug_data = NULL;
 
        debug_data = calloc(1, sizeof(tbm_surface_debug_data));
-       if (!debug_data)
+       if (!debug_data) {
+               _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
+               TBM_ERR("fail to allocate the debug_data.");
                return NULL;
+       }
 
        if (key) debug_data->key = strdup(key);
        if (value) debug_data->value = strdup(value);
@@ -1560,6 +1622,7 @@ tbm_surface_internal_set_debug_data(tbm_surface_h surface, char *key, char *valu
        tbm_bufmgr bufmgr = NULL;
 
        _tbm_surface_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        TBM_SURFACE_RETURN_VAL_IF_FAIL(_tbm_surface_internal_is_valid(surface), 0);
        TBM_SURFACE_RETURN_VAL_IF_FAIL(key, 0);