X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Ftdm_macro.h;h=acdc9f30d50d40119da0aec7ab2fa42331e5c2d4;hb=7138016dff2eb947ba4f1e60c8895210c0f61f63;hp=a547c0a4a82c5a88d054351b33c66e5f307821e2;hpb=9a9d836fb0d090ad6ce39ed002ead2f0c86187ab;p=platform%2Fcore%2Fuifw%2Flibtdm.git diff --git a/src/tdm_macro.h b/src/tdm_macro.h index a547c0a..acdc9f3 100644 --- a/src/tdm_macro.h +++ b/src/tdm_macro.h @@ -1,36 +1,36 @@ /************************************************************************** - -libtdm - -Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved. - -Contact: Eunchul Kim , - JinYoung Jeon , - Taeheon Kim , - YoungJun Cho , - SooChan Lim , - Boram Park - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sub license, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice (including the -next paragraph) shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. -IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - + * + * libtdm + * + * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved. + * + * Contact: Eunchul Kim , + * JinYoung Jeon , + * Taeheon Kim , + * YoungJun Cho , + * SooChan Lim , + * Boram Park + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * **************************************************************************/ #ifndef _TDM_MACRO_H_ @@ -41,10 +41,84 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include +#include + +#include "tdm_private_types.h" +#include "tdm_thread.h" + #ifdef __cplusplus extern "C" { #endif +/* not-categorized **********************************************************/ +#define TDM_NOT_DEFINED_VALUE (-1) +#define TDM_FRONT_VALUE(n) (((n) > 0) ? (n) : TDM_NOT_DEFINED_VALUE) + +#define TDM_MAX(x, y) (((x) > (y)) ? (x) : (y)) +#define TDM_MIN(x, y) (((x) < (y)) ? (x) : (y)) + +#define TDM_TIME(sec, usec) ((double)(sec) + ((double)(usec)) / 1000000.0) +#define TDM_TIME_SEC(time) ((unsigned int)(time)) +#define TDM_TIME_USEC(time) (unsigned int)(((time) - (unsigned int)(time)) * 1000000.0) + +#define C(b, m) (((b) >> (m)) & 0xFF) +#define B(c, s) ((((unsigned int)(c)) & 0xff) << (s)) +#define FOURCC(a, b, c, d) (B(d, 24) | B(c, 16) | B(b, 8) | B(a, 0)) +#define FOURCC_STR(id) C(id, 0), C(id, 8), C(id, 16), C(id, 24) +#define FOURCC_ID(str) FOURCC(((char*)str)[0], ((char*)str)[1], ((char*)str)[2], ((char*)str)[3]) +#define IS_RGB(f) ((f) == TBM_FORMAT_XRGB8888 || (f) == TBM_FORMAT_ARGB8888) + +/* don't using !,$,# */ +#define TDM_DELIM "@^&*+-|,:~" +#define TDM_ALIGN(a, b) (((a) + ((b) - 1)) & ~((b) - 1)) +#define TDM_SWAP(a, b) ({ int t; t = a; a = b; b = t; }) +#define TDM_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +#define TDM_SNPRINTF(p, len, fmt, ARG...) \ + do { \ + if (p && len && *len > 0) { \ + int s = snprintf(p, *len, fmt, ##ARG); \ + p += s; \ + *len -= s; \ + } \ + } while (0) + +/* common backend names *****************************************************/ +#define TDM_DEFAULT_MODULE "libtdm-default.so" +#define TDM_DUMMY_MODULE "libtdm-dummy.so" + +/* dump directory ***********************************************************/ +#define TDM_DUMP_DIR "/tmp" + +/* message length ***********************************************************/ +#define TDM_SERVER_REPLY_MSG_LEN 8192 +#define TDM_DEBUG_REPLY_MSG_LEN 2048 + +/* DPMS *********************************************************************/ +/* can't export VSYNC macro because we can't define the exact meaning of vsync off + * at this time. Does committing in standy mode work? Doesn't committing in suspend mode work? + */ +#define TDM_OUTPUT_DPMS_DEFAULT_MASK 0xF +#define TDM_OUTPUT_DPMS_VSYNC_OFF_MASK 0x2 +#define TDM_OUTPUT_DPMS_VSYNC_IS_OFF(dpms) ((dpms) & TDM_OUTPUT_DPMS_VSYNC_OFF_MASK) + +/* strtostr *****************************************************************/ +static inline char* +strtostr(char *buf, int len, char *str, char *delim) +{ + char *end; + end = strpbrk(str, delim); + if (end) + len = ((end - str + 1) < len) ? (end - str + 1) : len; + else { + int l = strlen(str); + len = ((l + 1) < len) ? (l + 1) : len; + } + snprintf(buf, len, "%s", str); + return str + len - 1; +} + +/* EXTERN, INTERN, DEPRECATED ***********************************************/ #undef EXTERN #undef DEPRECATED #undef INTERN @@ -67,56 +141,348 @@ extern "C" { #define DEPRECATED #endif -/* check condition */ -#define TDM_RETURN_IF_FAIL(cond) {\ - if (!(cond)) {\ - TDM_ERR ("'%s' failed", #cond);\ - return;\ - }\ -} -#define TDM_RETURN_VAL_IF_FAIL(cond, val) {\ - if (!(cond)) {\ - TDM_ERR ("'%s' failed", #cond);\ - return val;\ - }\ +/* type to string ***********************************************************/ +struct tdm_type_name { + int type; + const char *name; +}; + +#define TDM_TYPE_NAME_FN(res) \ +static inline const char * tdm_##res##_str(int type) \ +{ \ + unsigned int i; \ + for (i = 0; i < TDM_ARRAY_SIZE(tdm_##res##_names); i++) { \ + if (tdm_##res##_names[i].type == type) \ + return tdm_##res##_names[i].name; \ + } \ + return "(invalid)"; \ } -#define TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(cond, error_v, val) {\ - if (!(cond)) {\ - TDM_ERR ("'%s' failed", #cond);\ - ret = error_v;\ - if (error) *error = ret;\ - return val;\ - }\ + +static struct tdm_type_name tdm_error_names[] = { + { TDM_ERROR_NONE, "Success" }, + { TDM_ERROR_BAD_REQUEST, "bad request" }, + { TDM_ERROR_OPERATION_FAILED, "operaion failed" }, + { TDM_ERROR_INVALID_PARAMETER, "wrong input parameter" }, + { TDM_ERROR_PERMISSION_DENIED, "access denied" }, + { TDM_ERROR_BUSY, "hardware resource busy" }, + { TDM_ERROR_OUT_OF_MEMORY, "no free memory" }, + { TDM_ERROR_BAD_MODULE, "bad backend module" }, + { TDM_ERROR_NOT_IMPLEMENTED, "not implemented" }, + { TDM_ERROR_NO_CAPABILITY, "no capability" }, + { TDM_ERROR_DPMS_OFF, "dpms off" }, + { TDM_ERROR_OUTPUT_DISCONNECTED, "output disconnected" }, + { TDM_ERROR_PROTOCOL_ERROR, "protocol error" }, +}; +TDM_TYPE_NAME_FN(error) + +static struct tdm_type_name tdm_dpms_names[] = { + { TDM_OUTPUT_DPMS_ON, "on" }, + { TDM_OUTPUT_DPMS_STANDBY, "standby" }, + { TDM_OUTPUT_DPMS_SUSPEND, "suspend" }, + { TDM_OUTPUT_DPMS_OFF, "off" }, + { TDM_OUTPUT_DPMS_AOD, "aod" }, +}; +TDM_TYPE_NAME_FN(dpms) + +static struct tdm_type_name tdm_status_names[] = { + { TDM_OUTPUT_CONN_STATUS_DISCONNECTED, "disconnected" }, + { TDM_OUTPUT_CONN_STATUS_CONNECTED, "connected" }, + { TDM_OUTPUT_CONN_STATUS_MODE_SETTED, "mode_setted" }, +}; +TDM_TYPE_NAME_FN(status) + +static struct tdm_type_name tdm_conn_names[] = { + { TDM_OUTPUT_TYPE_Unknown, "Unknown" }, + { TDM_OUTPUT_TYPE_VGA, "VGA" }, + { TDM_OUTPUT_TYPE_DVII, "DVII" }, + { TDM_OUTPUT_TYPE_DVID, "DVID" }, + { TDM_OUTPUT_TYPE_DVIA, "DVIA" }, + { TDM_OUTPUT_TYPE_Composite, "Composite" }, + { TDM_OUTPUT_TYPE_SVIDEO, "SVIDEO" }, + { TDM_OUTPUT_TYPE_LVDS, "LVDS" }, + { TDM_OUTPUT_TYPE_Component, "Component" }, + { TDM_OUTPUT_TYPE_9PinDIN, "9PinDIN" }, + { TDM_OUTPUT_TYPE_DisplayPort, "DisplayPort" }, + { TDM_OUTPUT_TYPE_HDMIA, "HDMIA" }, + { TDM_OUTPUT_TYPE_HDMIB, "HDMIB" }, + { TDM_OUTPUT_TYPE_TV, "TV" }, + { TDM_OUTPUT_TYPE_eDP, "eDP" }, + { TDM_OUTPUT_TYPE_VIRTUAL, "VIRTUAL" }, + { TDM_OUTPUT_TYPE_DSI, "DSI" }, +}; +TDM_TYPE_NAME_FN(conn) + +static struct tdm_type_name tdm_capture_type_names[] = { + { TDM_CAPTURE_TYPE_ONESHOT, "none" }, + { TDM_CAPTURE_TYPE_STREAM, "90" }, +}; +TDM_TYPE_NAME_FN(capture_type) + +static struct tdm_type_name tdm_transform_names[] = { + { TDM_TRANSFORM_NORMAL, "none" }, + { TDM_TRANSFORM_90, "90" }, + { TDM_TRANSFORM_180, "180" }, + { TDM_TRANSFORM_270, "270" }, + { TDM_TRANSFORM_FLIPPED, "flipped" }, + { TDM_TRANSFORM_FLIPPED_90, "90,flipped" }, + { TDM_TRANSFORM_FLIPPED_180, "180,flipped" }, + { TDM_TRANSFORM_FLIPPED_270, "270,flipped" }, +}; +TDM_TYPE_NAME_FN(transform) + +static struct tdm_type_name tdm_value_type_names[] = { + { TDM_VALUE_TYPE_UNKNOWN, "unknown" }, + { TDM_VALUE_TYPE_PTR, "ptr" }, + { TDM_VALUE_TYPE_INT32, "int32" }, + { TDM_VALUE_TYPE_UINT32, "uint32" }, + { TDM_VALUE_TYPE_INT64, "int64" }, + { TDM_VALUE_TYPE_UINT64, "uint64" }, +}; +TDM_TYPE_NAME_FN(value_type) + +static struct tdm_type_name tdm_cb_type_names[] = { + { TDM_THREAD_CB_NONE, "none" }, + { TDM_THREAD_CB_OUTPUT_COMMIT, "output-commit" }, + { TDM_THREAD_CB_OUTPUT_VBLANK, "output-vblank" }, + { TDM_THREAD_CB_OUTPUT_STATUS, "output-status" }, + { TDM_THREAD_CB_OUTPUT_DPMS, "output-dpms" }, + { TDM_THREAD_CB_PP_DONE, "pp-done" }, + { TDM_THREAD_CB_CAPTURE_DONE, "capture-done" }, + { TDM_THREAD_CB_VBLANK_SW, "vblank-sw" }, + { TDM_THREAD_CB_VBLANK_CREATE, "vblank-create" }, + { TDM_THREAD_CB_NEED_VALIDATE, "need-validate" }, +}; +TDM_TYPE_NAME_FN(cb_type) + +#define TDM_BIT_NAME_FB(res) \ +static inline const char * tdm_##res##_str(int type, char **reply, int *len) \ +{ \ + unsigned int i; \ + const char *sep = ""; \ + if (type == 0) { \ + TDM_SNPRINTF(*reply, len, "none"); \ + return NULL; \ + } \ + for (i = 0; i < TDM_ARRAY_SIZE(tdm_##res##_names); i++) { \ + if (type & (1 << i)) { \ + TDM_SNPRINTF(*reply, len, "%s%s", sep, tdm_##res##_names[i]); \ + sep = ","; \ + } \ + } \ + return NULL; \ } -#define TDM_WARNING_IF_FAIL(cond) {\ - if (!(cond))\ - TDM_ERR ("'%s' failed", #cond);\ +static const char *tdm_mode_type_names[] = { + "builtin", + "clock_c", + "crtc_c", + "preferred", + "default", + "userdef", + "driver", +}; +TDM_BIT_NAME_FB(mode_type) + +static const char *tdm_mode_flag_names[] = { + "phsync", + "nhsync", + "pvsync", + "nvsync", + "interlace", + "dblscan", + "csync", + "pcsync", + "ncsync", + "hskew", + "bcast", + "pixmux", + "dblclk", + "clkdiv2" +}; +TDM_BIT_NAME_FB(mode_flag) + +static const char *tdm_layer_caps_names[] = { + "cursor", + "primary", + "overlay", + "", + "graphic", + "video", + "", + "", + "scale", + "transform", + "scanout", + "reserved", + "no_crop", +}; +TDM_BIT_NAME_FB(layer_caps) + +static const char *tdm_pp_caps_names[] = { + "sync", + "async", + "scale", + "transform", +}; +TDM_BIT_NAME_FB(pp_caps) + +static const char *tdm_capture_caps_names[] = { + "output", + "layer", + "scale", + "transform", +}; +TDM_BIT_NAME_FB(capture_caps) + +/* check condition **********************************************************/ +#define TDM_RETURN_IF_FAIL(cond) { \ + if (!(cond)) { \ + TDM_ERR("'%s' failed", #cond); \ + return; \ + } \ +} +#define TDM_RETURN_VAL_IF_FAIL(cond, val) { \ + if (!(cond)) { \ + TDM_ERR("'%s' failed", #cond); \ + return val; \ + } \ +} +#define TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(cond, error_v, val) { \ + if (!(cond)) { \ + TDM_ERR("'%s' failed", #cond); \ + ret = error_v; \ + if (error) *error = ret; \ + return val; \ + } \ +} +#define TDM_WARNING_IF_FAIL(cond) { \ + if (!(cond)) \ + TDM_WRN("'%s' failed", #cond); \ +} +#define TDM_GOTO_IF_FAIL(cond, dst) { \ + if (!(cond)) { \ + TDM_ERR("'%s' failed", #cond); \ + goto dst; \ + } \ +} +#define TDM_EXIT_IF_FAIL(cond) { \ + if (!(cond)) { \ + TDM_ERR("'%s' failed", #cond); \ + exit(0); \ + } \ +} +#define TDM_DBG_RETURN_IF_FAIL(cond) { \ + if (!(cond)) { \ + TDM_SNPRINTF(reply, len, "[%s %d] '%s' failed\n", __func__, __LINE__, #cond); \ + return; \ + } \ } -#define TDM_GOTO_IF_FAIL(cond, dst) {\ - if (!(cond)) {\ - TDM_ERR ("'%s' failed", #cond);\ - goto dst;\ - }\ +#define TDM_DBG_RETURN_VAL_IF_FAIL(cond, val) { \ + if (!(cond)) { \ + TDM_SNPRINTF(reply, len, "[%s %d] '%s' failed\n", __func__, __LINE__, #cond); \ + return val; \ + } \ +} +#define TDM_DBG_GOTO_IF_FAIL(cond, dst) { \ + if (!(cond)) { \ + TDM_SNPRINTF(reply, len, "[%s %d] '%s' failed\n", __func__, __LINE__, #cond); \ + goto dst; \ + } \ } -#define TDM_NEVER_GET_HERE() TDM_ERR("** NEVER GET HERE **") +/* trace ********************************************************************/ +#ifdef HAVE_TTRACE +#include +#define TDM_TRACE_BEGIN(fmt, ...) traceBegin(TTRACE_TAG_GRAPHICS, fmt, ##__VA_ARGS__) +#define TDM_TRACE_END() traceEnd(TTRACE_TAG_GRAPHICS) +#define TDM_TRACE_ASYNC_BEGIN(key, name,...) traceAsyncBegin(TTRACE_TAG_GRAPHICS, key, name, ##__VA_ARGS__) +#define TDM_TRACE_ASYNC_END(key, name,...) traceAsyncEnd(TTRACE_TAG_GRAPHICS, key, name, ##__VA_ARGS__) +#define TDM_TRACE_COUNT(count, fmt, ...) traceCounter(TTRACE_TAG_GRAPHICS, count, fmt, ##__VA_ARGS__) +#define TDM_TRACE_MARK(fmt, ...) traceMark(TTRACE_TAG_GRAPHICS, fmt, ##__VA_ARGS__) +#else +#define TDM_TRACE_BEGIN(fmt, ...) +#define TDM_TRACE_END() +#define TDM_TRACE_ASYNC_BEGIN(key, name,...) +#define TDM_TRACE_ASYNC_END(key, name,...) +#define TDM_TRACE_COUNT(count, fmt, ...) +#define TDM_TRACE_MARK(fmt, ...) +#endif -#define TDM_SNPRINTF(p, len, fmt, ARG...) \ - do { \ - if (p && len && *len > 0) \ - { \ - int s = snprintf(p, *len, fmt, ##ARG); \ - p += s; \ - *len -= s; \ - } \ - } while (0) - -#define C(b,m) (((b) >> (m)) & 0xFF) -#define B(c,s) ((((unsigned int)(c)) & 0xff) << (s)) -#define FOURCC(a,b,c,d) (B(d,24) | B(c,16) | B(b,8) | B(a,0)) -#define FOURCC_STR(id) C(id,0), C(id,8), C(id,16), C(id,24) -#define FOURCC_ID(str) FOURCC(((char*)str)[0],((char*)str)[1],((char*)str)[2],((char*)str)[3]) +/* display mutex ************************************************************/ +extern pthread_mutex_t tdm_mutex_check_lock; +extern int tdm_mutex_locked; +extern const char *tdm_mutex_lock_func; +extern int tdm_mutex_lock_line; +extern const char *tdm_mutex_unlock_func; +extern int tdm_mutex_unlock_line; +extern int tdm_debug_module; + +#define _pthread_mutex_lock(l) \ + do { \ + if (tdm_debug_module & TDM_DEBUG_MUTEX) \ + TDM_INFO("mutex lock"); \ + pthread_mutex_lock(l); \ + pthread_mutex_lock(&tdm_mutex_check_lock); \ + tdm_mutex_locked = 1; \ + tdm_mutex_lock_func = __FUNCTION__; \ + tdm_mutex_lock_line = __LINE__; \ + tdm_mutex_unlock_func = NULL; \ + tdm_mutex_unlock_line = 0; \ + pthread_mutex_unlock(&tdm_mutex_check_lock); \ + } while (0) + +#define _pthread_mutex_unlock(l) \ + do { \ + if (tdm_debug_module & TDM_DEBUG_MUTEX) \ + TDM_INFO("mutex unlock"); \ + pthread_mutex_lock(&tdm_mutex_check_lock); \ + tdm_mutex_locked = 0; \ + tdm_mutex_lock_func = NULL; \ + tdm_mutex_lock_line = 0; \ + tdm_mutex_unlock_func = __FUNCTION__; \ + tdm_mutex_unlock_line = __LINE__; \ + pthread_mutex_unlock(&tdm_mutex_check_lock); \ + pthread_mutex_unlock(l); \ + } while (0) + +static inline int TDM_MUTEX_IS_LOCKED(void) +{ + int ret; + /* if thread is not running, we don't need to consider mutex things. */ + if (!tdm_thread_is_running()) + return 1; + pthread_mutex_lock(&tdm_mutex_check_lock); + ret = (tdm_mutex_locked == 1); + pthread_mutex_unlock(&tdm_mutex_check_lock); + return ret; +} + +#define tdm_display_lock(dpy) _pthread_mutex_lock(&((tdm_private_display *)dpy)->lock) +#define tdm_display_unlock(dpy) _pthread_mutex_unlock(&((tdm_private_display *)dpy)->lock) + + +/* debugging mutex ************************************************************/ +extern pthread_mutex_t tdm_debug_mutex_check_lock; +extern const char *tdm_debug_mutex_lock_func; +extern int tdm_debug_mutex_lock_line; + +#define _debug_pthread_mutex_lock(l) \ + do { \ + pthread_mutex_lock(l); \ + pthread_mutex_lock(&tdm_debug_mutex_check_lock); \ + tdm_debug_mutex_lock_func = __FUNCTION__; \ + tdm_debug_mutex_lock_line = __LINE__; \ + pthread_mutex_unlock(&tdm_debug_mutex_check_lock); \ + } while (0) + +#define _debug_pthread_mutex_unlock(l) \ + do { \ + pthread_mutex_lock(&tdm_debug_mutex_check_lock); \ + tdm_debug_mutex_lock_func = NULL; \ + tdm_debug_mutex_lock_line = 0; \ + pthread_mutex_unlock(&tdm_debug_mutex_check_lock); \ + pthread_mutex_unlock(l); \ + } while (0) #ifdef __cplusplus }