validate check tbm surface
[platform/core/uifw/libtbm.git] / src / tbm_surface.c
1 /**************************************************************************
2
3 libtbm
4
5 Copyright 2014 Samsung Electronics co., Ltd. All Rights Reserved.
6
7 Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
8 Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
9
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
17
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
20 of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 **************************************************************************/
31
32 #include "config.h"
33 #include "tbm_bufmgr.h"
34 #include "tbm_bufmgr_int.h"
35 #include "tbm_surface_internal.h"
36
37 int
38 tbm_surface_query_formats(uint32_t **formats, uint32_t *num)
39 {
40         if (!tbm_surface_internal_query_supported_formats(formats, num))
41                 return TBM_SURFACE_ERROR_INVALID_OPERATION;
42
43         return TBM_SURFACE_ERROR_NONE;
44 }
45
46 tbm_surface_h
47 tbm_surface_create(int width, int height, tbm_format format)
48 {
49         if (!(width > 0) || !(height > 0)) {
50 #ifdef HAVE_CAPI_0_1_1
51                 set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
52 #endif
53                 return NULL;
54         }
55
56         struct _tbm_surface *surf = NULL;
57
58         surf = tbm_surface_internal_create_with_flags(width, height, format,
59                                                       TBM_BO_DEFAULT);
60         if (!surf) {
61 #ifdef HAVE_CAPI_0_1_1
62                 set_last_result(TBM_SURFACE_ERROR_INVALID_OPERATION);
63 #endif
64                 return NULL;
65         }
66 #ifdef HAVE_CAPI_0_1_1
67         set_last_result(TBM_SURFACE_ERROR_NONE);
68 #endif
69         return surf;
70 }
71
72 int
73 tbm_surface_destroy(tbm_surface_h surface)
74 {
75         if (!_tbm_surface_is_valid(surface))
76                 return TBM_SURFACE_ERROR_INVALID_PARAMETER;
77
78         tbm_surface_internal_destroy(surface);
79
80         return TBM_SURFACE_ERROR_NONE;
81 }
82
83 int
84 tbm_surface_map(tbm_surface_h surface, int opt, tbm_surface_info_s *info)
85 {
86         TBM_RETURN_VAL_IF_FAIL(_tbm_surface_is_valid(surface), TBM_SURFACE_ERROR_INVALID_PARAMETER);
87         TBM_RETURN_VAL_IF_FAIL(info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
88
89         int ret = 0;
90
91         ret = tbm_surface_internal_get_info(surface, opt, info, 1);
92         if (ret == 0)
93                 return TBM_SURFACE_ERROR_INVALID_OPERATION;
94
95         return TBM_SURFACE_ERROR_NONE;
96 }
97
98 int
99 tbm_surface_unmap(tbm_surface_h surface)
100 {
101         TBM_RETURN_VAL_IF_FAIL(_tbm_surface_is_valid(surface), TBM_SURFACE_ERROR_INVALID_PARAMETER);
102
103         tbm_surface_internal_unmap(surface);
104
105         return TBM_SURFACE_ERROR_NONE;
106 }
107
108 int
109 tbm_surface_get_info(tbm_surface_h surface, tbm_surface_info_s *info)
110 {
111         TBM_RETURN_VAL_IF_FAIL(_tbm_surface_is_valid(surface), TBM_SURFACE_ERROR_INVALID_PARAMETER);
112         TBM_RETURN_VAL_IF_FAIL(info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
113
114         int ret = 0;
115
116         ret = tbm_surface_internal_get_info(surface, 0, info, 0);
117         if (ret == 0)
118                 return TBM_SURFACE_ERROR_INVALID_OPERATION;
119
120         return TBM_SURFACE_ERROR_NONE;
121 }
122
123 int
124 tbm_surface_get_width(tbm_surface_h surface)
125 {
126         TBM_RETURN_VAL_IF_FAIL(_tbm_surface_is_valid(surface), TBM_SURFACE_ERROR_INVALID_PARAMETER);
127
128         return tbm_surface_internal_get_width(surface);
129 }
130
131 int
132 tbm_surface_get_height(tbm_surface_h surface)
133 {
134         TBM_RETURN_VAL_IF_FAIL(_tbm_surface_is_valid(surface), TBM_SURFACE_ERROR_INVALID_PARAMETER);
135
136         return tbm_surface_internal_get_height(surface);
137 }
138
139 tbm_format
140 tbm_surface_get_format(tbm_surface_h surface)
141 {
142         if (!_tbm_surface_is_valid(surface)) {
143 #ifdef HAVE_CAPI_0_1_1
144                 set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
145 #endif
146                 return 0;
147         }
148 #ifdef HAVE_CAPI_0_1_1
149         set_last_result(TBM_SURFACE_ERROR_NONE);
150 #endif
151         return tbm_surface_internal_get_format(surface);
152 }