tbm_module: add tbm_module_import_surface_data
[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
34 #include "tbm_bufmgr.h"
35 #include "tbm_bufmgr_int.h"
36 #include "tbm_surface_internal.h"
37
38 int
39 tbm_surface_query_formats(uint32_t **formats, uint32_t *num)
40 {
41         TBM_TRACE_SURFACE("\n");
42
43         if (!tbm_surface_internal_query_supported_formats(formats, num))
44                 return tbm_get_last_error();
45
46         return TBM_SURFACE_ERROR_NONE;
47 }
48
49 tbm_surface_h
50 tbm_surface_create(int width, int height, tbm_format format)
51 {
52         TBM_TRACE_SURFACE("width(%d) height(%d)\n", width, height);
53
54         _tbm_set_last_result(TBM_ERROR_NONE);
55
56         if (!(width > 0) || !(height > 0)) {
57 #ifdef HAVE_CAPI_0_1_1
58                 set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
59 #endif
60                 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
61                 return NULL;
62         }
63
64         struct _tbm_surface *surf = NULL;
65
66         surf = tbm_surface_internal_create_with_flags(width, height, format,
67                                                       TBM_BO_DEFAULT);
68         if (!surf) {
69 #ifdef HAVE_CAPI_0_1_1
70                 set_last_result(TBM_SURFACE_ERROR_INVALID_OPERATION);
71 #endif
72                 return NULL;
73         }
74
75 #ifdef HAVE_CAPI_0_1_1
76         set_last_result(TBM_SURFACE_ERROR_NONE);
77 #endif
78
79         return surf;
80 }
81
82 int
83 tbm_surface_destroy(tbm_surface_h surface)
84 {
85         TBM_TRACE_SURFACE("tbm_surface(%p)\n", surface);
86
87         TBM_RETURN_VAL_IF_FAIL(surface, TBM_SURFACE_ERROR_INVALID_PARAMETER);
88
89         tbm_surface_internal_destroy(surface);
90
91         return tbm_get_last_error();
92 }
93
94 int
95 tbm_surface_map(tbm_surface_h surface, int opt, tbm_surface_info_s *info)
96 {
97         TBM_TRACE_SURFACE("tbm_surface(%p)\n", surface);
98
99         TBM_RETURN_VAL_IF_FAIL(surface, TBM_SURFACE_ERROR_INVALID_PARAMETER);
100         TBM_RETURN_VAL_IF_FAIL(info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
101
102         int ret = 0;
103
104         ret = tbm_surface_internal_get_info(surface, opt, info, 1);
105         if (ret == 0)
106                 return tbm_get_last_error();
107
108         return TBM_SURFACE_ERROR_NONE;
109 }
110
111 int
112 tbm_surface_unmap(tbm_surface_h surface)
113 {
114         TBM_TRACE_SURFACE("tbm_surface(%p)\n", surface);
115
116         TBM_RETURN_VAL_IF_FAIL(surface, TBM_SURFACE_ERROR_INVALID_PARAMETER);
117
118         tbm_surface_internal_unmap(surface);
119
120         return tbm_get_last_error();
121 }
122
123 int
124 tbm_surface_get_info(tbm_surface_h surface, tbm_surface_info_s *info)
125 {
126         TBM_TRACE_SURFACE("tbm_surface(%p)\n", surface);
127
128         TBM_RETURN_VAL_IF_FAIL(surface, TBM_SURFACE_ERROR_INVALID_PARAMETER);
129         TBM_RETURN_VAL_IF_FAIL(info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
130
131         int ret = 0;
132
133         ret = tbm_surface_internal_get_info(surface, 0, info, 0);
134         if (ret == 0)
135                 return tbm_get_last_error();
136
137         return TBM_SURFACE_ERROR_NONE;
138 }
139
140 int
141 tbm_surface_get_width(tbm_surface_h surface)
142 {
143         TBM_TRACE_SURFACE("tbm_surface(%p)\n", surface);
144
145         int width = 0;
146
147         _tbm_set_last_result(TBM_ERROR_NONE);
148
149         if (!surface) {
150 #ifdef HAVE_CAPI_0_1_1
151                 set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
152 #endif
153                 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
154                 return TBM_SURFACE_ERROR_INVALID_PARAMETER;
155         }
156
157         width = tbm_surface_internal_get_width(surface);
158         if (tbm_get_last_error() != TBM_ERROR_NONE) {
159 #ifdef HAVE_CAPI_0_1_1
160                 set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
161 #endif
162                 return TBM_SURFACE_ERROR_INVALID_PARAMETER;
163         }
164
165 #ifdef HAVE_CAPI_0_1_1
166         set_last_result(TBM_SURFACE_ERROR_NONE);
167 #endif
168
169         return width;
170 }
171
172 int
173 tbm_surface_get_height(tbm_surface_h surface)
174 {
175         TBM_TRACE_SURFACE("tbm_surface(%p)\n", surface);
176
177         int height = 0;
178
179         _tbm_set_last_result(TBM_ERROR_NONE);
180
181         if (!surface) {
182 #ifdef HAVE_CAPI_0_1_1
183                 set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
184 #endif
185                 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
186                 return TBM_SURFACE_ERROR_INVALID_PARAMETER;
187         }
188
189         height = tbm_surface_internal_get_height(surface);
190         if (tbm_get_last_error() != TBM_ERROR_NONE) {
191 #ifdef HAVE_CAPI_0_1_1
192                 set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
193 #endif
194                 return TBM_SURFACE_ERROR_INVALID_PARAMETER;
195         }
196
197 #ifdef HAVE_CAPI_0_1_1
198         set_last_result(TBM_SURFACE_ERROR_NONE);
199 #endif
200
201         return height;
202 }
203
204 tbm_format
205 tbm_surface_get_format(tbm_surface_h surface)
206 {
207         TBM_TRACE_SURFACE("tbm_surface(%p)\n", surface);
208
209         _tbm_set_last_result(TBM_ERROR_NONE);
210
211         if (!surface) {
212 #ifdef HAVE_CAPI_0_1_1
213                 set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
214 #endif
215                 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
216                 return 0;
217         }
218
219 #ifdef HAVE_CAPI_0_1_1
220         set_last_result(TBM_SURFACE_ERROR_NONE);
221 #endif
222
223         return tbm_surface_internal_get_format(surface);
224 }