* Taeheon Kim <th908.kim@samsung.com>,
* YoungJun Cho <yj44.cho@samsung.com>,
* SooChan Lim <sc1.lim@samsung.com>,
- * Boram Park <sc1.lim@samsung.com>
+ * Boram Park <boram1288.park@samsung.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
#include <stdlib.h>
#include <sys/types.h>
-#include <tdm_common.h>
#include <tbm_surface.h>
+#include "tdm_private_types.h"
+#include "tdm_thread.h"
+
#ifdef __cplusplus
extern "C" {
#endif
-#define TDM_SERVER_REPLY_MSG_LEN 8192
-#define TDM_DEBUG_REPLY_MSG_LEN 2048
-
-#undef EXTERN
-#undef DEPRECATED
-#undef INTERN
-
-#if defined(__GNUC__) && __GNUC__ >= 4
-#define EXTERN __attribute__ ((visibility("default")))
-#else
-#define EXTERN
-#endif
-
-#if defined(__GNUC__) && __GNUC__ >= 4
-#define INTERN __attribute__ ((visibility("hidden")))
-#else
-#define INTERN
-#endif
-
-#if defined(__GNUC__) && __GNUC__ >= 4
-#define DEPRECATED __attribute__ ((deprecated))
-#else
-#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; \
- } \
-}
-#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_NEVER_GET_HERE() TDM_WRN("** NEVER GET HERE **")
-
-#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 TDM_DBG_RETURN_IF_FAIL(cond) { \
- if (!(cond)) { \
- TDM_SNPRINTF(reply, len, "[%s %d] '%s' failed\n", __func__, __LINE__, #cond); \
- return; \
- } \
-}
-#define TDM_DBG_GOTO_IF_FAIL(cond, dst) { \
- if (!(cond)) { \
- TDM_SNPRINTF(reply, len, "[%s %d] '%s' failed\n", __func__, __LINE__, #cond); \
- goto dst; \
- } \
-}
-
+/* not-categorized **********************************************************/
#define TDM_NOT_DEFINED_VALUE (-1)
#define TDM_FRONT_VALUE(n) (((n) > 0) ? (n) : TDM_NOT_DEFINED_VALUE)
#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
+
+#if defined(__GNUC__) && __GNUC__ >= 4
+#define EXTERN __attribute__ ((visibility("default")))
+#else
+#define EXTERN
+#endif
+
+#if defined(__GNUC__) && __GNUC__ >= 4
+#define INTERN __attribute__ ((visibility("hidden")))
+#else
+#define INTERN
+#endif
+
+#if defined(__GNUC__) && __GNUC__ >= 4
+#define DEPRECATED __attribute__ ((deprecated))
+#else
+#define DEPRECATED
+#endif
+
+/* type to string ***********************************************************/
struct tdm_type_name {
int type;
const char *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)
};
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_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) \
{ \
};
TDM_BIT_NAME_FB(capture_caps)
-static inline char*
-strtostr(char *buf, int len, char *str, char *delim)
+/* 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_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; \
+ } \
+}
+
+/* trace ********************************************************************/
+#ifdef HAVE_TTRACE
+#include <ttrace.h>
+#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
+
+/* 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)
{
- 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;
+ 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
}
#endif