Apply tizen coding rule
[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 tbm_surface_query_formats(uint32_t ** formats, uint32_t * num)
38 {
39         if (!tbm_surface_internal_query_supported_formats(formats, num))
40                 return TBM_SURFACE_ERROR_INVALID_OPERATION;
41
42         return TBM_SURFACE_ERROR_NONE;
43 }
44
45 tbm_surface_h tbm_surface_create(int width, int height, tbm_format format)
46 {
47         if (!(width > 0) || !(height > 0)) {
48 #ifdef HAVE_CAPI_0_1_1
49                 set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
50 #endif
51                 return NULL;
52         }
53
54         struct _tbm_surface *surf = NULL;
55
56         surf = tbm_surface_internal_create_with_flags(width, height, format, TBM_BO_DEFAULT);
57         if (!surf) {
58 #ifdef HAVE_CAPI_0_1_1
59                 set_last_result(TBM_SURFACE_ERROR_INVALID_OPERATION);
60 #endif
61                 return NULL;
62         }
63 #ifdef HAVE_CAPI_0_1_1
64         set_last_result(TBM_SURFACE_ERROR_NONE);
65 #endif
66         return surf;
67 }
68
69 int tbm_surface_destroy(tbm_surface_h surface)
70 {
71         if (!surface)
72                 return TBM_SURFACE_ERROR_INVALID_PARAMETER;
73
74         tbm_surface_internal_destroy(surface);
75
76         return TBM_SURFACE_ERROR_NONE;
77 }
78
79 int tbm_surface_map(tbm_surface_h surface, int opt, tbm_surface_info_s * info)
80 {
81         TBM_RETURN_VAL_IF_FAIL(surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
82         TBM_RETURN_VAL_IF_FAIL(info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
83
84         int ret = 0;
85
86         ret = tbm_surface_internal_get_info(surface, opt, info, 1);
87         if (ret == 0)
88                 return TBM_SURFACE_ERROR_INVALID_OPERATION;
89
90         return TBM_SURFACE_ERROR_NONE;
91 }
92
93 int tbm_surface_unmap(tbm_surface_h surface)
94 {
95         TBM_RETURN_VAL_IF_FAIL(surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
96
97         tbm_surface_internal_unmap(surface);
98
99         return TBM_SURFACE_ERROR_NONE;
100 }
101
102 int tbm_surface_get_info(tbm_surface_h surface, tbm_surface_info_s * info)
103 {
104         TBM_RETURN_VAL_IF_FAIL(surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
105         TBM_RETURN_VAL_IF_FAIL(info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
106
107         int ret = 0;
108
109         ret = tbm_surface_internal_get_info(surface, 0, info, 0);
110         if (ret == 0)
111                 return TBM_SURFACE_ERROR_INVALID_OPERATION;
112
113         return TBM_SURFACE_ERROR_NONE;
114 }
115
116 int tbm_surface_get_width(tbm_surface_h surface)
117 {
118         TBM_RETURN_VAL_IF_FAIL(surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
119
120         return tbm_surface_internal_get_width(surface);
121 }
122
123 int tbm_surface_get_height(tbm_surface_h surface)
124 {
125         TBM_RETURN_VAL_IF_FAIL(surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER);
126
127         return tbm_surface_internal_get_height(surface);
128 }
129
130 tbm_format tbm_surface_get_format(tbm_surface_h surface)
131 {
132         if (!surface) {
133 #ifdef HAVE_CAPI_0_1_1
134                 set_last_result(TBM_SURFACE_ERROR_INVALID_PARAMETER);
135 #endif
136                 return 0;
137         }
138 #ifdef HAVE_CAPI_0_1_1
139         set_last_result(TBM_SURFACE_ERROR_NONE);
140 #endif
141         return tbm_surface_internal_get_format(surface);
142 }