1 /**************************************************************************
5 * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
7 * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8 * JinYoung Jeon <jy0.jeon@samsung.com>,
9 * Taeheon Kim <th908.kim@samsung.com>,
10 * YoungJun Cho <yj44.cho@samsung.com>,
11 * SooChan Lim <sc1.lim@samsung.com>,
12 * Boram Park <sc1.lim@samsung.com>
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the
16 * "Software"), to deal in the Software without restriction, including
17 * without limitation the rights to use, copy, modify, merge, publish,
18 * distribute, sub license, and/or sell copies of the Software, and to
19 * permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 **************************************************************************/
42 #include <sys/types.h>
44 #include <tdm_common.h>
45 #include <tbm_surface.h>
51 #define TDM_SERVER_REPLY_MSG_LEN 8192
57 #if defined(__GNUC__) && __GNUC__ >= 4
58 #define EXTERN __attribute__ ((visibility("default")))
63 #if defined(__GNUC__) && __GNUC__ >= 4
64 #define INTERN __attribute__ ((visibility("hidden")))
69 #if defined(__GNUC__) && __GNUC__ >= 4
70 #define DEPRECATED __attribute__ ((deprecated))
76 #define TDM_RETURN_IF_FAIL(cond) { \
78 TDM_ERR("'%s' failed", #cond); \
82 #define TDM_RETURN_VAL_IF_FAIL(cond, val) { \
84 TDM_ERR("'%s' failed", #cond); \
88 #define TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(cond, error_v, val) { \
90 TDM_ERR("'%s' failed", #cond); \
92 if (error) *error = ret; \
97 #define TDM_WARNING_IF_FAIL(cond) { \
99 TDM_ERR("'%s' failed", #cond); \
101 #define TDM_GOTO_IF_FAIL(cond, dst) { \
103 TDM_ERR("'%s' failed", #cond); \
107 #define TDM_EXIT_IF_FAIL(cond) { \
109 TDM_ERR("'%s' failed", #cond); \
114 #define TDM_NEVER_GET_HERE() TDM_WRN("** NEVER GET HERE **")
116 #define TDM_SNPRINTF(p, len, fmt, ARG...) \
118 if (p && len && *len > 0) { \
119 int s = snprintf(p, *len, fmt, ##ARG); \
125 #define TDM_DBG_RETURN_IF_FAIL(cond) { \
127 TDM_SNPRINTF(reply, len, "[%s %d] '%s' failed\n", __func__, __LINE__, #cond); \
131 #define TDM_DBG_GOTO_IF_FAIL(cond, dst) { \
133 TDM_SNPRINTF(reply, len, "[%s %d] '%s' failed\n", __func__, __LINE__, #cond); \
138 #define TDM_NOT_DEFINED_VALUE (-1)
139 #define TDM_FRONT_VALUE(n) (((n) > 0) ? (n) : TDM_NOT_DEFINED_VALUE)
141 #define TDM_TIME(sec, usec) ((double)(sec) + ((double)(usec)) / 1000000.0)
142 #define TDM_TIME_SEC(time) ((unsigned int)(time))
143 #define TDM_TIME_USEC(time) (unsigned int)(((time) - (unsigned int)(time)) * 1000000.0)
145 #define C(b, m) (((b) >> (m)) & 0xFF)
146 #define B(c, s) ((((unsigned int)(c)) & 0xff) << (s))
147 #define FOURCC(a, b, c, d) (B(d, 24) | B(c, 16) | B(b, 8) | B(a, 0))
148 #define FOURCC_STR(id) C(id, 0), C(id, 8), C(id, 16), C(id, 24)
149 #define FOURCC_ID(str) FOURCC(((char*)str)[0], ((char*)str)[1], ((char*)str)[2], ((char*)str)[3])
150 #define IS_RGB(f) ((f) == TBM_FORMAT_XRGB8888 || (f) == TBM_FORMAT_ARGB8888)
152 /* don't using !,$,# */
153 #define TDM_DELIM "@^&*+-|,:~"
154 #define TDM_ALIGN(a, b) (((a) + ((b) - 1)) & ~((b) - 1))
155 #define TDM_SWAP(a, b) ({ int t; t = a; a = b; b = t; })
156 #define TDM_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
158 struct tdm_type_name {
163 #define TDM_TYPE_NAME_FN(res) \
164 static inline const char * tdm_##res##_str(int type) \
167 for (i = 0; i < TDM_ARRAY_SIZE(tdm_##res##_names); i++) { \
168 if (tdm_##res##_names[i].type == type) \
169 return tdm_##res##_names[i].name; \
171 return "(invalid)"; \
174 static struct tdm_type_name tdm_dpms_names[] = {
175 { TDM_OUTPUT_DPMS_ON, "on" },
176 { TDM_OUTPUT_DPMS_STANDBY, "standby" },
177 { TDM_OUTPUT_DPMS_SUSPEND, "suspend" },
178 { TDM_OUTPUT_DPMS_OFF, "off" },
180 TDM_TYPE_NAME_FN(dpms)
182 static struct tdm_type_name tdm_status_names[] = {
183 { TDM_OUTPUT_CONN_STATUS_DISCONNECTED, "disconnected" },
184 { TDM_OUTPUT_CONN_STATUS_CONNECTED, "connected" },
185 { TDM_OUTPUT_CONN_STATUS_MODE_SETTED, "mode_setted" },
187 TDM_TYPE_NAME_FN(status)
189 static struct tdm_type_name tdm_conn_names[] = {
190 { TDM_OUTPUT_TYPE_Unknown, "Unknown" },
191 { TDM_OUTPUT_TYPE_VGA, "VGA" },
192 { TDM_OUTPUT_TYPE_DVII, "DVII" },
193 { TDM_OUTPUT_TYPE_DVID, "DVID" },
194 { TDM_OUTPUT_TYPE_DVIA, "DVIA" },
195 { TDM_OUTPUT_TYPE_Composite, "Composite" },
196 { TDM_OUTPUT_TYPE_SVIDEO, "SVIDEO" },
197 { TDM_OUTPUT_TYPE_LVDS, "LVDS" },
198 { TDM_OUTPUT_TYPE_Component, "Component" },
199 { TDM_OUTPUT_TYPE_9PinDIN, "9PinDIN" },
200 { TDM_OUTPUT_TYPE_DisplayPort, "DisplayPort" },
201 { TDM_OUTPUT_TYPE_HDMIA, "HDMIA" },
202 { TDM_OUTPUT_TYPE_HDMIB, "HDMIB" },
203 { TDM_OUTPUT_TYPE_TV, "TV" },
204 { TDM_OUTPUT_TYPE_eDP, "eDP" },
205 { TDM_OUTPUT_TYPE_VIRTUAL, "VIRTUAL" },
206 { TDM_OUTPUT_TYPE_DSI, "DSI" },
208 TDM_TYPE_NAME_FN(conn)
210 static struct tdm_type_name tdm_transform_names[] = {
211 { TDM_TRANSFORM_NORMAL, "none" },
212 { TDM_TRANSFORM_90, "90" },
213 { TDM_TRANSFORM_180, "180" },
214 { TDM_TRANSFORM_270, "270" },
215 { TDM_TRANSFORM_FLIPPED, "flipped" },
216 { TDM_TRANSFORM_FLIPPED_90, "90,flipped" },
217 { TDM_TRANSFORM_FLIPPED_180, "180,flipped" },
218 { TDM_TRANSFORM_FLIPPED_270, "270,flipped" },
220 TDM_TYPE_NAME_FN(transform)
223 #define TDM_BIT_NAME_FB(res) \
224 static inline const char * tdm_##res##_str(int type, char **reply, int *len) \
227 const char *sep = ""; \
229 TDM_SNPRINTF(*reply, len, "none"); \
232 for (i = 0; i < TDM_ARRAY_SIZE(tdm_##res##_names); i++) { \
233 if (type & (1 << i)) { \
234 TDM_SNPRINTF(*reply, len, "%s%s", sep, tdm_##res##_names[i]); \
241 static const char *tdm_mode_type_names[] = {
250 TDM_BIT_NAME_FB(mode_type)
252 static const char *tdm_mode_flag_names[] = {
268 TDM_BIT_NAME_FB(mode_flag)
270 static const char *tdm_layer_caps_names[] = {
285 TDM_BIT_NAME_FB(layer_caps)
287 static const char *tdm_pp_caps_names[] = {
293 TDM_BIT_NAME_FB(pp_caps)
295 static const char *tdm_capture_caps_names[] = {
301 TDM_BIT_NAME_FB(capture_caps)
304 strtostr(char *buf, int len, char *str, char *delim)
307 end = strpbrk(str, delim);
309 len = ((end - str + 1) < len) ? (end - str + 1) : len;
312 len = ((l + 1) < len) ? (l + 1) : len;
314 snprintf(buf, len, "%s", str);
315 return str + len - 1;
322 #endif /* _TDM_MACRO_H_ */