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