tbm_module: make tbm_module_bufmgr_bind_native_display
[platform/core/uifw/libtbm.git] / src / tbm_surface.c
index 1277c80..0766cf5 100644 (file)
@@ -30,6 +30,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 **************************************************************************/
 
 #include "config.h"
+
 #include "tbm_bufmgr.h"
 #include "tbm_bufmgr_int.h"
 #include "tbm_surface_internal.h"
@@ -37,10 +38,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 int
 tbm_surface_query_formats(uint32_t **formats, uint32_t *num)
 {
-       TBM_TRACE("\n");
+       TBM_TRACE_SURFACE("\n");
 
        if (!tbm_surface_internal_query_supported_formats(formats, num))
-               return TBM_SURFACE_ERROR_INVALID_OPERATION;
+               return tbm_get_last_error();
 
        return TBM_SURFACE_ERROR_NONE;
 }
@@ -48,12 +49,15 @@ tbm_surface_query_formats(uint32_t **formats, uint32_t *num)
 tbm_surface_h
 tbm_surface_create(int width, int height, tbm_format format)
 {
-       TBM_TRACE("width(%d) height(%d)\n", width, height);
+       TBM_TRACE_SURFACE("width(%d) height(%d)\n", width, height);
+
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        if (!(width > 0) || !(height > 0)) {
 #ifdef HAVE_CAPI_0_1_1
                set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
 #endif
+               _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
                return NULL;
        }
 
@@ -67,28 +71,30 @@ tbm_surface_create(int width, int height, tbm_format format)
 #endif
                return NULL;
        }
+
 #ifdef HAVE_CAPI_0_1_1
        set_last_result(TBM_SURFACE_ERROR_NONE);
 #endif
+
        return surf;
 }
 
 int
 tbm_surface_destroy(tbm_surface_h surface)
 {
-       TBM_TRACE("tbm_surface(%p)\n", surface);
+       TBM_TRACE_SURFACE("tbm_surface(%p)\n", surface);
 
        TBM_RETURN_VAL_IF_FAIL(surface, TBM_SURFACE_ERROR_INVALID_PARAMETER);
 
        tbm_surface_internal_destroy(surface);
 
-       return TBM_SURFACE_ERROR_NONE;
+       return tbm_get_last_error();
 }
 
 int
 tbm_surface_map(tbm_surface_h surface, int opt, tbm_surface_info_s *info)
 {
-       TBM_TRACE("tbm_surface(%p)\n", surface);
+       TBM_TRACE_SURFACE("tbm_surface(%p)\n", surface);
 
        TBM_RETURN_VAL_IF_FAIL(surface, TBM_SURFACE_ERROR_INVALID_PARAMETER);
        TBM_RETURN_VAL_IF_FAIL(info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
@@ -97,7 +103,7 @@ tbm_surface_map(tbm_surface_h surface, int opt, tbm_surface_info_s *info)
 
        ret = tbm_surface_internal_get_info(surface, opt, info, 1);
        if (ret == 0)
-               return TBM_SURFACE_ERROR_INVALID_OPERATION;
+               return tbm_get_last_error();
 
        return TBM_SURFACE_ERROR_NONE;
 }
@@ -105,19 +111,19 @@ tbm_surface_map(tbm_surface_h surface, int opt, tbm_surface_info_s *info)
 int
 tbm_surface_unmap(tbm_surface_h surface)
 {
-       TBM_TRACE("tbm_surface(%p)\n", surface);
+       TBM_TRACE_SURFACE("tbm_surface(%p)\n", surface);
 
        TBM_RETURN_VAL_IF_FAIL(surface, TBM_SURFACE_ERROR_INVALID_PARAMETER);
 
        tbm_surface_internal_unmap(surface);
 
-       return TBM_SURFACE_ERROR_NONE;
+       return tbm_get_last_error();
 }
 
 int
 tbm_surface_get_info(tbm_surface_h surface, tbm_surface_info_s *info)
 {
-       TBM_TRACE("tbm_surface(%p)\n", surface);
+       TBM_TRACE_SURFACE("tbm_surface(%p)\n", surface);
 
        TBM_RETURN_VAL_IF_FAIL(surface, TBM_SURFACE_ERROR_INVALID_PARAMETER);
        TBM_RETURN_VAL_IF_FAIL(info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
@@ -126,7 +132,7 @@ tbm_surface_get_info(tbm_surface_h surface, tbm_surface_info_s *info)
 
        ret = tbm_surface_internal_get_info(surface, 0, info, 0);
        if (ret == 0)
-               return TBM_SURFACE_ERROR_INVALID_OPERATION;
+               return tbm_get_last_error();
 
        return TBM_SURFACE_ERROR_NONE;
 }
@@ -134,36 +140,85 @@ tbm_surface_get_info(tbm_surface_h surface, tbm_surface_info_s *info)
 int
 tbm_surface_get_width(tbm_surface_h surface)
 {
-       TBM_TRACE("tbm_surface(%p)\n", surface);
+       TBM_TRACE_SURFACE("tbm_surface(%p)\n", surface);
 
-       TBM_RETURN_VAL_IF_FAIL(surface, TBM_SURFACE_ERROR_INVALID_PARAMETER);
+       int width = 0;
+
+       _tbm_set_last_result(TBM_ERROR_NONE);
+
+       if (!surface) {
+#ifdef HAVE_CAPI_0_1_1
+               set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
+#endif
+               _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
+               return TBM_SURFACE_ERROR_INVALID_PARAMETER;
+       }
 
-       return tbm_surface_internal_get_width(surface);
+       width = tbm_surface_internal_get_width(surface);
+       if (tbm_get_last_error() != TBM_ERROR_NONE) {
+#ifdef HAVE_CAPI_0_1_1
+               set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
+#endif
+               return TBM_SURFACE_ERROR_INVALID_PARAMETER;
+       }
+
+#ifdef HAVE_CAPI_0_1_1
+       set_last_result(TBM_SURFACE_ERROR_NONE);
+#endif
+
+       return width;
 }
 
 int
 tbm_surface_get_height(tbm_surface_h surface)
 {
-       TBM_TRACE("tbm_surface(%p)\n", surface);
+       TBM_TRACE_SURFACE("tbm_surface(%p)\n", surface);
 
-       TBM_RETURN_VAL_IF_FAIL(surface, TBM_SURFACE_ERROR_INVALID_PARAMETER);
+       int height = 0;
+
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
-       return tbm_surface_internal_get_height(surface);
+       if (!surface) {
+#ifdef HAVE_CAPI_0_1_1
+               set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
+#endif
+               _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
+               return TBM_SURFACE_ERROR_INVALID_PARAMETER;
+       }
+
+       height = tbm_surface_internal_get_height(surface);
+       if (tbm_get_last_error() != TBM_ERROR_NONE) {
+#ifdef HAVE_CAPI_0_1_1
+               set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
+#endif
+               return TBM_SURFACE_ERROR_INVALID_PARAMETER;
+       }
+
+#ifdef HAVE_CAPI_0_1_1
+       set_last_result(TBM_SURFACE_ERROR_NONE);
+#endif
+
+       return height;
 }
 
 tbm_format
 tbm_surface_get_format(tbm_surface_h surface)
 {
-       TBM_TRACE("tbm_surface(%p)\n", surface);
+       TBM_TRACE_SURFACE("tbm_surface(%p)\n", surface);
+
+       _tbm_set_last_result(TBM_ERROR_NONE);
 
        if (!surface) {
 #ifdef HAVE_CAPI_0_1_1
                set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
 #endif
+               _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
                return 0;
        }
+
 #ifdef HAVE_CAPI_0_1_1
        set_last_result(TBM_SURFACE_ERROR_NONE);
 #endif
+
        return tbm_surface_internal_get_format(surface);
 }