X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Ftdm_macro.h;h=5b8f861c69eca09393f5221b213694e1d90daf21;hb=dc0f94dbd2d214c19b3811ed424647906be77f75;hp=b87b4a0cc85c9c6938021fefabae9c490dd99b03;hpb=a96653d12ad8b320812307b3d1d6cb8b35fe9e78;p=platform%2Fcore%2Fuifw%2Flibtdm.git diff --git a/src/tdm_macro.h b/src/tdm_macro.h index b87b4a0..5b8f861 100644 --- a/src/tdm_macro.h +++ b/src/tdm_macro.h @@ -9,7 +9,7 @@ * Taeheon Kim , * YoungJun Cho , * SooChan Lim , - * Boram Park + * Boram Park * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the @@ -41,10 +41,86 @@ #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 *****************************************************************/ +/* LCOV_EXCL_START */ +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; +} +/* LCOV_EXCL_STOP */ + +/* EXTERN, INTERN, DEPRECATED ***********************************************/ #undef EXTERN #undef DEPRECATED #undef INTERN @@ -67,7 +143,201 @@ extern "C" { #define DEPRECATED #endif -/* check condition */ +/* 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)"; \ +} + +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_EXIT, "exit" }, + { 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_HWC_COMMIT, "hwc-commit" }, +}; +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; \ +} + +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); \ @@ -88,10 +358,9 @@ extern "C" { return val; \ } \ } - #define TDM_WARNING_IF_FAIL(cond) { \ if (!(cond)) \ - TDM_ERR("'%s' failed", #cond); \ + TDM_WRN("'%s' failed", #cond); \ } #define TDM_GOTO_IF_FAIL(cond, dst) { \ if (!(cond)) { \ @@ -99,23 +368,124 @@ extern "C" { 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_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...) \ +/* 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 (p && len && *len > 0) { \ - int s = snprintf(p, *len, fmt, ##ARG); \ - p += s; \ - *len -= s; \ - } \ + 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 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 _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 }