1277c80cf03d87570e3102c65eed160f75a11245
[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         TBM_TRACE("\n");
41
42         if (!tbm_surface_internal_query_supported_formats(formats, num))
43                 return TBM_SURFACE_ERROR_INVALID_OPERATION;
44
45         return TBM_SURFACE_ERROR_NONE;
46 }
47
48 tbm_surface_h
49 tbm_surface_create(int width, int height, tbm_format format)
50 {
51         TBM_TRACE("width(%d) height(%d)\n", width, height);
52
53         if (!(width > 0) || !(height > 0)) {
54 #ifdef HAVE_CAPI_0_1_1
55                 set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
56 #endif
57                 return NULL;
58         }
59
60         struct _tbm_surface *surf = NULL;
61
62         surf = tbm_surface_internal_create_with_flags(width, height, format,
63                                                       TBM_BO_DEFAULT);
64         if (!surf) {
65 #ifdef HAVE_CAPI_0_1_1
66                 set_last_result(TBM_SURFACE_ERROR_INVALID_OPERATION);
67 #endif
68                 return NULL;
69         }
70 #ifdef HAVE_CAPI_0_1_1
71         set_last_result(TBM_SURFACE_ERROR_NONE);
72 #endif
73         return surf;
74 }
75
76 int
77 tbm_surface_destroy(tbm_surface_h surface)
78 {
79         TBM_TRACE("tbm_surface(%p)\n", surface);
80
81         TBM_RETURN_VAL_IF_FAIL(surface, TBM_SURFACE_ERROR_INVALID_PARAMETER);
82
83         tbm_surface_internal_destroy(surface);
84
85         return TBM_SURFACE_ERROR_NONE;
86 }
87
88 int
89 tbm_surface_map(tbm_surface_h surface, int opt, tbm_surface_info_s *info)
90 {
91         TBM_TRACE("tbm_surface(%p)\n", surface);
92
93         TBM_RETURN_VAL_IF_FAIL(surface, TBM_SURFACE_ERROR_INVALID_PARAMETER);
94         TBM_RETURN_VAL_IF_FAIL(info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
95
96         int ret = 0;
97
98         ret = tbm_surface_internal_get_info(surface, opt, info, 1);
99         if (ret == 0)
100                 return TBM_SURFACE_ERROR_INVALID_OPERATION;
101
102         return TBM_SURFACE_ERROR_NONE;
103 }
104
105 int
106 tbm_surface_unmap(tbm_surface_h surface)
107 {
108         TBM_TRACE("tbm_surface(%p)\n", surface);
109
110         TBM_RETURN_VAL_IF_FAIL(surface, TBM_SURFACE_ERROR_INVALID_PARAMETER);
111
112         tbm_surface_internal_unmap(surface);
113
114         return TBM_SURFACE_ERROR_NONE;
115 }
116
117 int
118 tbm_surface_get_info(tbm_surface_h surface, tbm_surface_info_s *info)
119 {
120         TBM_TRACE("tbm_surface(%p)\n", surface);
121
122         TBM_RETURN_VAL_IF_FAIL(surface, TBM_SURFACE_ERROR_INVALID_PARAMETER);
123         TBM_RETURN_VAL_IF_FAIL(info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
124
125         int ret = 0;
126
127         ret = tbm_surface_internal_get_info(surface, 0, info, 0);
128         if (ret == 0)
129                 return TBM_SURFACE_ERROR_INVALID_OPERATION;
130
131         return TBM_SURFACE_ERROR_NONE;
132 }
133
134 int
135 tbm_surface_get_width(tbm_surface_h surface)
136 {
137         TBM_TRACE("tbm_surface(%p)\n", surface);
138
139         TBM_RETURN_VAL_IF_FAIL(surface, TBM_SURFACE_ERROR_INVALID_PARAMETER);
140
141         return tbm_surface_internal_get_width(surface);
142 }
143
144 int
145 tbm_surface_get_height(tbm_surface_h surface)
146 {
147         TBM_TRACE("tbm_surface(%p)\n", surface);
148
149         TBM_RETURN_VAL_IF_FAIL(surface, TBM_SURFACE_ERROR_INVALID_PARAMETER);
150
151         return tbm_surface_internal_get_height(surface);
152 }
153
154 tbm_format
155 tbm_surface_get_format(tbm_surface_h surface)
156 {
157         TBM_TRACE("tbm_surface(%p)\n", surface);
158
159         if (!surface) {
160 #ifdef HAVE_CAPI_0_1_1
161                 set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
162 #endif
163                 return 0;
164         }
165 #ifdef HAVE_CAPI_0_1_1
166         set_last_result(TBM_SURFACE_ERROR_NONE);
167 #endif
168         return tbm_surface_internal_get_format(surface);
169 }