From bc0ad21111fda197697985f7792a917637e0e3e3 Mon Sep 17 00:00:00 2001 From: "Mun, Gwan-gyeong" Date: Thu, 18 Feb 2016 02:25:48 +0900 Subject: [PATCH] Fix indent, typo, build warnning Change-Id: I0430791e127f5d3035cc2b57550b66022eff100b --- src/tpl.c | 99 ++++---- src/tpl.h | 103 ++++---- src/tpl_display.c | 65 +++-- src/tpl_gbm.c | 234 ++++++++--------- src/tpl_internal.h | 150 ++++++----- src/tpl_object.c | 35 +-- src/tpl_surface.c | 73 ++---- src/tpl_tbm.c | 201 +++++++-------- src/tpl_utils.h | 679 +++++++++++++++++++++++--------------------------- src/tpl_utils_hlist.c | 115 ++++----- src/tpl_utils_map.c | 138 +++++----- src/tpl_wayland.c | 354 +++++++++++++------------- 12 files changed, 1025 insertions(+), 1221 deletions(-) diff --git a/src/tpl.c b/src/tpl.c index 59b5ed5..c12b934 100644 --- a/src/tpl.c +++ b/src/tpl.c @@ -3,8 +3,7 @@ unsigned int tpl_log_lvl; unsigned int tpl_dump_lvl; -struct _tpl_runtime -{ +struct _tpl_runtime { tpl_hlist_t *displays[TPL_BACKEND_COUNT]; }; @@ -14,11 +13,9 @@ static pthread_mutex_t runtime_mutex = PTHREAD_MUTEX_INITIALIZER; static tpl_result_t __tpl_runtime_init() { - if (runtime == NULL) - { + if (runtime == NULL) { runtime = (tpl_runtime_t *) calloc(1, sizeof(tpl_runtime_t)); - if (runtime == NULL) - { + if (runtime == NULL) { TPL_ERR("Failed to allocate new tpl_runtime_t."); return TPL_ERROR_INVALID_OPERATION; } @@ -30,12 +27,10 @@ __tpl_runtime_init() static void __attribute__((destructor)) __tpl_runtime_fini() { - if (runtime != NULL) - { + if (runtime != NULL) { int i; - for (i = 0; i < TPL_BACKEND_COUNT; i++) - { + for (i = 0; i < TPL_BACKEND_COUNT; i++) { if (runtime->displays[i] != NULL) __tpl_hashlist_destroy(&(runtime->displays[i])); } @@ -46,25 +41,27 @@ __tpl_runtime_fini() } /* Begin: OS dependent function definition */ -void __tpl_util_sys_yield(void) +void +__tpl_util_sys_yield(void) { int status; status = sched_yield(); - if (0 != status) - { + if (status != 0) { /* non-fatal on error, warning is enough */ TPL_WARN("Yield failed, ret=%.8x\n", status); } } -int __tpl_util_clz(int val) +int +__tpl_util_clz(int val) { return __builtin_clz( val ); } -int __tpl_util_atomic_get(const tpl_util_atomic_uint * const atom) +int +__tpl_util_atomic_get(const tpl_util_atomic_uint * const atom) { unsigned int ret; @@ -77,7 +74,8 @@ int __tpl_util_atomic_get(const tpl_util_atomic_uint * const atom) return ret; } -void __tpl_util_atomic_set(tpl_util_atomic_uint * const atom, unsigned int val) +void +__tpl_util_atomic_set(tpl_util_atomic_uint * const atom, unsigned int val) { TPL_ASSERT(atom); @@ -86,13 +84,16 @@ void __tpl_util_atomic_set(tpl_util_atomic_uint * const atom, unsigned int val) TPL_DMB(); } -unsigned int __tpl_util_atomic_inc(tpl_util_atomic_uint * const atom ) +unsigned int +__tpl_util_atomic_inc(tpl_util_atomic_uint * const atom ) { TPL_ASSERT(atom); return __sync_add_and_fetch(atom, 1); } -unsigned int __tpl_util_atomic_dec( tpl_util_atomic_uint * const atom ) + +unsigned int +__tpl_util_atomic_dec( tpl_util_atomic_uint * const atom ) { TPL_ASSERT(atom); @@ -110,24 +111,18 @@ __tpl_runtime_find_display(tpl_backend_type_t type, tpl_handle_t native_display) pthread_mutex_lock(&runtime_mutex); - if (type != TPL_BACKEND_UNKNOWN) - { - if (runtime->displays[type] != NULL) - { + if (type != TPL_BACKEND_UNKNOWN) { + if (runtime->displays[type] != NULL) { display = (tpl_display_t *) __tpl_hashlist_lookup(runtime->displays[type], - (size_t) native_display); + (size_t) native_display); } - } - else - { + } else { int i; - for (i = 0; i < TPL_BACKEND_COUNT; i++) - { - if (runtime->displays[i] != NULL) - { + for (i = 0; i < TPL_BACKEND_COUNT; i++) { + if (runtime->displays[i] != NULL) { display = (tpl_display_t *) __tpl_hashlist_lookup(runtime->displays[i], - (size_t) native_display); + (size_t) native_display); } if (display != NULL) break; } @@ -152,33 +147,29 @@ __tpl_runtime_add_display(tpl_display_t *display) TPL_ASSERT(0 <= type && TPL_BACKEND_COUNT > type); - if (0 != pthread_mutex_lock(&runtime_mutex)) - { + if (0 != pthread_mutex_lock(&runtime_mutex)) { TPL_ERR("runtime_mutex pthread_mutex_lock filed."); return TPL_ERROR_INVALID_OPERATION; } - if (TPL_ERROR_NONE != __tpl_runtime_init()) - { + if (TPL_ERROR_NONE != __tpl_runtime_init()) { TPL_ERR("__tpl_runtime_init() failed."); return TPL_ERROR_INVALID_OPERATION; } - if (NULL == runtime->displays[type]) - { + if (NULL == runtime->displays[type]) { runtime->displays[type] = __tpl_hashlist_create(); - if (NULL == runtime->displays[type]) - { + if (NULL == runtime->displays[type]) { TPL_ERR("__tpl_hashlist_create failed."); return TPL_ERROR_INVALID_OPERATION; } } - ret = __tpl_hashlist_insert(runtime->displays[type], (size_t) handle, (void *) display); - if (TPL_ERROR_NONE != ret) - { + ret = __tpl_hashlist_insert(runtime->displays[type], + (size_t) handle, (void *) display); + if (TPL_ERROR_NONE != ret) { TPL_ERR("__tpl_hashlist_insert failed. list(%p), handle(%d), display(%p)", - runtime->displays[type], handle, display); + runtime->displays[type], handle, display); __tpl_hashlist_destroy(&runtime->displays[type]); return TPL_ERROR_INVALID_OPERATION; } @@ -196,10 +187,10 @@ __tpl_runtime_remove_display(tpl_display_t *display) pthread_mutex_lock(&runtime_mutex); - if (type != TPL_BACKEND_UNKNOWN) - { + if (type != TPL_BACKEND_UNKNOWN) { if (runtime != NULL && runtime->displays[type] != NULL) - __tpl_hashlist_delete(runtime->displays[type], (size_t) handle); + __tpl_hashlist_delete(runtime->displays[type], + (size_t) handle); } pthread_mutex_unlock(&runtime_mutex); @@ -222,11 +213,10 @@ __tpl_runtime_flush_all_display() pthread_mutex_lock(&runtime_mutex); - for (i = 0; i < TPL_BACKEND_COUNT; i++) - { + for (i = 0; i < TPL_BACKEND_COUNT; i++) { if (runtime->displays[i] != NULL) __tpl_hashlist_do_for_all_nodes(runtime->displays[i], - __tpl_runtime_flush_cb); + __tpl_runtime_flush_cb); } pthread_mutex_unlock(&runtime_mutex); @@ -238,8 +228,7 @@ __tpl_display_choose_backend(tpl_handle_t native_dpy) const char *plat_name = NULL; plat_name = getenv("EGL_PLATFORM"); - if (plat_name) - { + if (plat_name) { #ifdef TPL_WINSYS_DRI2 if (strcmp(plat_name, "x11") == 0) return TPL_BACKEND_X11_DRI2; #endif @@ -255,7 +244,7 @@ __tpl_display_choose_backend(tpl_handle_t native_dpy) #ifdef TPL_WINSYS_WL if (__tpl_display_choose_backend_tbm(native_dpy) == TPL_TRUE) - return TPL_BACKEND_TBM; + return TPL_BACKEND_TBM; if (__tpl_display_choose_backend_gbm(native_dpy) == TPL_TRUE) return TPL_BACKEND_GBM; if (__tpl_display_choose_backend_wayland(native_dpy) == TPL_TRUE) @@ -278,8 +267,7 @@ __tpl_display_init_backend(tpl_display_t *display, tpl_backend_type_t type) TPL_ASSERT(display); TPL_ASSERT(0 <= type && TPL_BACKEND_COUNT > type); - switch (type) - { + switch (type) { #ifdef TPL_WINSYS_WL case TPL_BACKEND_GBM: __tpl_display_init_backend_gbm(&display->backend); @@ -312,8 +300,7 @@ __tpl_surface_init_backend(tpl_surface_t *surface, tpl_backend_type_t type) TPL_ASSERT(surface); TPL_ASSERT(0 <= type && TPL_BACKEND_COUNT > type); - switch (type) - { + switch (type) { #ifdef TPL_WINSYS_WL case TPL_BACKEND_GBM: __tpl_surface_init_backend_gbm(&surface->backend); diff --git a/src/tpl.h b/src/tpl.h index d8bd293..62004d2 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -127,8 +127,7 @@ typedef void (*tpl_free_func_t)(void *data); * * @see tpl_object_get_type() */ -typedef enum -{ +typedef enum { TPL_OBJECT_ERROR = -1, TPL_OBJECT_DISPLAY, TPL_OBJECT_SURFACE, @@ -145,11 +144,10 @@ typedef enum * @see tpl_surface_create() * @see tpl_surface_get_type() */ -typedef enum -{ +typedef enum { TPL_SURFACE_ERROR = -1, - TPL_SURFACE_TYPE_WINDOW, /**< surface gets displayed by the display server. */ - TPL_SURFACE_TYPE_PIXMAP, /**< surface is an offscreen pixmap. */ + TPL_SURFACE_TYPE_WINDOW, /**< surface gets displayed by the display server. */ + TPL_SURFACE_TYPE_PIXMAP, /**< surface is an offscreen pixmap. */ TPL_SURFACE_MAX } tpl_surface_type_t; @@ -163,8 +161,7 @@ typedef enum * * @see tpl_buffer_lock() */ -typedef enum -{ +typedef enum { TPL_LOCK_USAGE_INVALID = 0, TPL_LOCK_USAGE_GPU_READ, TPL_LOCK_USAGE_GPU_WRITE, @@ -182,8 +179,7 @@ typedef enum * * @see tpl_display_create() */ -typedef enum -{ +typedef enum { TPL_BACKEND_UNKNOWN = -1, TPL_BACKEND_WAYLAND, TPL_BACKEND_GBM, @@ -198,8 +194,7 @@ typedef enum * Enumeration for TPL result type. * */ -typedef enum -{ +typedef enum { TPL_ERROR_NONE = 0, /* Successfull */ TPL_ERROR_INVALID_PARAMETER, /* Invalid parmeter */ TPL_ERROR_INVALID_OPERATION /* Invalid operation */ @@ -261,14 +256,12 @@ tpl_object_type_t tpl_object_get_type(tpl_object_t *object); * @param key pointer to the key. * @param data pointer to the user data. * @param free_func free function which is used for freeing the user data when the object is destroyed. - * @return TPL_TRUE on success, TPL_FALSE on error. + * @return TPL_ERROR_NONE on success, TPL_ERROR_INVALID_PARAMETER on error. * * @see tpl_object_get_user_data() */ -tpl_result_t tpl_object_set_user_data(tpl_object_t *object, - void *key, - void *data, - tpl_free_func_t free_func); +tpl_result_t tpl_object_set_user_data(tpl_object_t *object, void *key, + void *data, tpl_free_func_t free_func); /** * Get registered user data of a TPL object. @@ -292,8 +285,8 @@ void * tpl_object_get_user_data(tpl_object_t *object, void *key); * @param native_dpy handle to the native display. * @return pointer to the display on success, NULL on failure. */ -tpl_display_t * tpl_display_create(tpl_backend_type_t type, - tpl_handle_t native_dpy); +tpl_display_t * +tpl_display_create(tpl_backend_type_t type, tpl_handle_t native_dpy); /** * Get TPL display object for the given native display. @@ -334,15 +327,11 @@ tpl_handle_t tpl_display_get_native_handle(tpl_display_t *display); * @param is_slow Pointer to receive whether the given config is slow. * @return TPL_ERROR_NONE is the given config is supported, TPL_ERROR otherwise. */ -tpl_result_t tpl_display_query_config(tpl_display_t *display, - tpl_surface_type_t surface_type, - int red_size, - int green_size, - int blue_size, - int alpha_size, - int depth_size, - int *native_visual_id, - tpl_bool_t *is_slow); +tpl_result_t +tpl_display_query_config(tpl_display_t *display, tpl_surface_type_t surface_type, + int red_size, int green_size, int blue_size, + int alpha_size, int depth_size, int *native_visual_id, + tpl_bool_t *is_slow); /** * Filter config according to given TPL display. @@ -355,10 +344,8 @@ tpl_result_t tpl_display_query_config(tpl_display_t *display, * @param alpha_size Size of the alpha component in bits. * @return TPL_ERROR_NONE if the given config has been modified, TPL_ERROR otherwise. */ -tpl_result_t tpl_display_filter_config(tpl_display_t *display, - int *visual_id, - int alpha_size); - +tpl_result_t +tpl_display_filter_config(tpl_display_t *display, int *visual_id, int alpha_size); /** * Create a TPL surface for the given native surface. @@ -369,10 +356,9 @@ tpl_result_t tpl_display_filter_config(tpl_display_t *display, * @param format Pixel format of the surface. * @return Created surface on success, NULL otherwise. */ -tpl_surface_t * tpl_surface_create(tpl_display_t *display, - tpl_handle_t handle, - tpl_surface_type_t type, - tbm_format format); +tpl_surface_t * +tpl_surface_create(tpl_display_t *display, tpl_handle_t handle, + tpl_surface_type_t type, tbm_format format); /** * Get the TPL display where the given TPL surface was created from. @@ -416,10 +402,8 @@ tpl_surface_type_t tpl_surface_get_type(tpl_surface_t *surface); * @param width pointer to receive width value. * @param height pointer to receive height value. */ -tpl_result_t tpl_surface_get_size(tpl_surface_t *surface, - int *width, - int *height); - +tpl_result_t +tpl_surface_get_size(tpl_surface_t *surface, int *width, int *height); /** * Validate current frame of the given TPL surface. @@ -471,7 +455,8 @@ tbm_surface_h tpl_surface_dequeue_buffer(tpl_surface_t *surface); * @param tbm_surface buffer to post. * */ -tpl_result_t tpl_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface); +tpl_result_t +tpl_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface); /** * Post a given tbm_surface with region of damage. @@ -493,10 +478,10 @@ tpl_result_t tpl_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tb * * @see tpl_surface_enqueue_buffer() */ -tpl_result_t tpl_surface_enqueue_buffer_with_damage(tpl_surface_t *surface, - tbm_surface_h tbm_surface, - int num_rects, - const int *rects); +tpl_result_t +tpl_surface_enqueue_buffer_with_damage(tpl_surface_t *surface, + tbm_surface_h tbm_surface, + int num_rects, const int *rects); /** * Set frame interval of the given TPL surface. @@ -510,8 +495,8 @@ tpl_result_t tpl_surface_enqueue_buffer_with_damage(tpl_surface_t *surface, * * @see tpl_surface_get_post_interval() */ -tpl_result_t tpl_surface_set_post_interval(tpl_surface_t *surface, - int interval); +tpl_result_t +tpl_surface_set_post_interval(tpl_surface_t *surface, int interval); /** * Get frame interval of the given TPL surface. @@ -533,13 +518,10 @@ int tpl_surface_get_post_interval(tpl_surface_t *surface); * @param format pointer to receive format of the window. * @return TPL_ERROR_NONE if the window is valid, TPL_ERROR otherwise. */ -tpl_result_t tpl_display_get_native_window_info(tpl_display_t *display, - tpl_handle_t window, - int *width, - int *height, - tbm_format *format, - int depth, - int a_size); +tpl_result_t +tpl_display_get_native_window_info(tpl_display_t *display, tpl_handle_t window, + int *width, int *height, tbm_format *format, + int depth, int a_size); /** * Query information on the given native pixmap. @@ -551,11 +533,9 @@ tpl_result_t tpl_display_get_native_window_info(tpl_display_t *display, * @param format pointer to receive format of the pixmap. * @return TPL_ERROR_NONE if the pixmap is valid, TPL_ERROR otherwise. */ -tpl_result_t tpl_display_get_native_pixmap_info(tpl_display_t *display, - tpl_handle_t pixmap, - int *width, - int *height, - tbm_format *format); +tpl_result_t +tpl_display_get_native_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, + int *width, int *height, tbm_format *format); /** * Get native buffer from the given native pixmap. @@ -564,7 +544,8 @@ tpl_result_t tpl_display_get_native_pixmap_info(tpl_display_t *display, * @param pixmap handle of the native pixmap. * @return tbm_surface_h native buffer. */ -tbm_surface_h tpl_display_get_buffer_from_native_pixmap(tpl_display_t *display, - tpl_handle_t pixmap); +tbm_surface_h +tpl_display_get_buffer_from_native_pixmap(tpl_display_t *display, + tpl_handle_t pixmap); #endif /* TPL_H */ diff --git a/src/tpl_display.c b/src/tpl_display.c index a62174d..c933199 100644 --- a/src/tpl_display.c +++ b/src/tpl_display.c @@ -37,23 +37,21 @@ tpl_display_create(tpl_backend_type_t type, tpl_handle_t native_dpy) type = __tpl_display_choose_backend(native_dpy); /* if still not found, then there's no compatible display */ - if (TPL_BACKEND_UNKNOWN == type || TPL_BACKEND_COUNT == type || TPL_BACKEND_MAX <= type) - { + if ((TPL_BACKEND_UNKNOWN == type) || (TPL_BACKEND_COUNT == type) + || (TPL_BACKEND_MAX <= type)) { TPL_ERR("Invalid backend type!"); return NULL; } display = (tpl_display_t *)calloc(1, sizeof(tpl_display_t)); - if (NULL == display) - { + if (!display) { TPL_ERR("Failed to allocate memory for display!"); return NULL; } /* Initialize object base class. */ ret = __tpl_object_init(&display->base, TPL_OBJECT_DISPLAY, __tpl_display_free); - if (TPL_ERROR_NONE != ret) - { + if (ret != TPL_ERROR_NONE) { TPL_ERR("Failed to initialize display's base class!"); free(display); return NULL; @@ -65,8 +63,7 @@ tpl_display_create(tpl_backend_type_t type, tpl_handle_t native_dpy) /* Initialize backend. */ __tpl_display_init_backend(display, type); - if (TPL_ERROR_NONE != display->backend.init(display)) - { + if (display->backend.init(display) != TPL_ERROR_NONE) { TPL_ERR("Failed to initialize display's backend!"); tpl_object_unreference((tpl_object_t *) display); return NULL; @@ -74,8 +71,7 @@ tpl_display_create(tpl_backend_type_t type, tpl_handle_t native_dpy) /* Add it to the runtime. */ ret = __tpl_runtime_add_display(display); - if (TPL_ERROR_NONE != ret) - { + if (ret != TPL_ERROR_NONE) { TPL_ERR("Failed to add display to runtime list!"); tpl_object_unreference((tpl_object_t *) display); return NULL; @@ -98,8 +94,7 @@ tpl_display_get(tpl_handle_t native_dpy) tpl_handle_t tpl_display_get_native_handle(tpl_display_t *display) { - if(NULL == display || TPL_TRUE != __tpl_object_is_valid(&display->base)) - { + if(!display || (__tpl_object_is_valid(&display->base) != TPL_TRUE)) { TPL_ERR("display is invalid!"); return NULL; } @@ -108,30 +103,27 @@ tpl_display_get_native_handle(tpl_display_t *display) } tpl_result_t -tpl_display_query_config(tpl_display_t *display, - tpl_surface_type_t surface_type, - int red_size, - int green_size, - int blue_size, - int alpha_size, - int depth_size, - int *native_visual_id, +tpl_display_query_config(tpl_display_t *display, tpl_surface_type_t surface_type, + int red_size, int green_size, int blue_size, + int alpha_size, int depth_size, int *native_visual_id, tpl_bool_t *is_slow) { - if(NULL == display || TPL_TRUE != __tpl_object_is_valid(&display->base) || NULL == display->backend.query_config) - { + if (!display || (__tpl_object_is_valid(&display->base) != TPL_TRUE) + || (!display->backend.query_config)) { TPL_ERR("display is invalid!"); return TPL_ERROR_INVALID_PARAMETER; } - return display->backend.query_config(display, surface_type, red_size, green_size, blue_size, alpha_size, depth_size, native_visual_id, is_slow); + return display->backend.query_config(display, surface_type, red_size, + green_size, blue_size, alpha_size, depth_size, + native_visual_id, is_slow); } tpl_result_t tpl_display_filter_config(tpl_display_t *display, int *visual_id, int alpha_size) { - if(NULL == display || TPL_TRUE != __tpl_object_is_valid(&display->base) || NULL == display->backend.filter_config) - { + if (!display || (__tpl_object_is_valid(&display->base) != TPL_TRUE) + || (!display->backend.filter_config)) { TPL_ERR("display is invalid!"); return TPL_ERROR_INVALID_PARAMETER; } @@ -141,25 +133,25 @@ tpl_display_filter_config(tpl_display_t *display, int *visual_id, int alpha_size tpl_result_t tpl_display_get_native_window_info(tpl_display_t *display, tpl_handle_t window, - int *width, int *height, tbm_format *format, int depth, int a_size) + int *width, int *height, tbm_format *format, + int depth, int a_size) { - if (display->backend.get_window_info == NULL) - { + if (!display->backend.get_window_info) { TPL_ERR("Backend for display has not been initialized!"); - return TPL_ERROR_INVALID_OPERATION; + return TPL_ERROR_INVALID_OPERATION; } - return display->backend.get_window_info(display, window, width, height, format, depth, a_size); + return display->backend.get_window_info(display, window, width, height, + format, depth, a_size); } tpl_result_t tpl_display_get_native_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, - int *width, int *height, tbm_format *format) + int *width, int *height, tbm_format *format) { - if (display->backend.get_pixmap_info == NULL) - { + if (!display->backend.get_pixmap_info) { TPL_ERR("Backend for display has not been initialized!"); - return TPL_ERROR_INVALID_OPERATION; + return TPL_ERROR_INVALID_OPERATION; } return display->backend.get_pixmap_info(display, pixmap, width, height, format); @@ -168,10 +160,9 @@ tpl_display_get_native_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, tbm_surface_h tpl_display_get_buffer_from_native_pixmap(tpl_display_t *display, tpl_handle_t pixmap) { - if (display->backend.get_buffer_from_native_pixmap == NULL) - { + if (!display->backend.get_buffer_from_native_pixmap) { TPL_ERR("Backend for display has not been initialized!"); - return NULL; + return NULL; } return display->backend.get_buffer_from_native_pixmap(pixmap); diff --git a/src/tpl_gbm.c b/src/tpl_gbm.c index e2cf093..6d38c75 100644 --- a/src/tpl_gbm.c +++ b/src/tpl_gbm.c @@ -32,25 +32,21 @@ typedef struct _tpl_gbm_display tpl_gbm_display_t; typedef struct _tpl_gbm_surface tpl_gbm_surface_t; typedef struct _tpl_gbm_buffer tpl_gbm_buffer_t; -struct _tpl_gbm_display -{ - tbm_bufmgr bufmgr; +struct _tpl_gbm_display { + tbm_bufmgr bufmgr; }; -struct _tpl_gbm_surface -{ - tbm_surface_queue_h tbm_queue; - tbm_surface_h current_buffer; +struct _tpl_gbm_surface { + tbm_surface_queue_h tbm_queue; + tbm_surface_h current_buffer; }; -struct _tpl_gbm_buffer -{ - tpl_display_t *display; - tpl_gbm_buffer_t* *tpl_gbm_surface; - tbm_bo bo; - - struct gbm_bo *gbm_bo; - struct wl_listener destroy_listener; +struct _tpl_gbm_buffer { + tpl_display_t *display; + tpl_gbm_buffer_t **tpl_gbm_surface; + tbm_bo bo; + struct gbm_bo *gbm_bo; + struct wl_listener destroy_listener; }; static int tpl_gbm_buffer_key; @@ -60,23 +56,25 @@ static void __tpl_gbm_buffer_free(tpl_gbm_buffer_t *gbm_buffer); static inline tpl_gbm_buffer_t * __tpl_gbm_get_gbm_buffer_from_tbm_surface(tbm_surface_h surface) { - tbm_bo bo; - tpl_gbm_buffer_t *buf=NULL; + tbm_bo bo; + tpl_gbm_buffer_t *buf=NULL; - bo = tbm_surface_internal_get_bo(surface, 0); - tbm_bo_get_user_data(bo, KEY_TPL_GBM_BUFFER, (void **)&buf); + bo = tbm_surface_internal_get_bo(surface, 0); + tbm_bo_get_user_data(bo, KEY_TPL_GBM_BUFFER, (void **)&buf); - return buf; + return buf; } static inline void -__tpl_gbm_set_gbm_buffer_to_tbm_surface(tbm_surface_h surface, tpl_gbm_buffer_t *buf) +__tpl_gbm_set_gbm_buffer_to_tbm_surface(tbm_surface_h surface, + tpl_gbm_buffer_t *buf) { - tbm_bo bo; + tbm_bo bo; - bo = tbm_surface_internal_get_bo(surface, 0); - tbm_bo_add_user_data(bo, KEY_TPL_GBM_BUFFER, (tbm_data_free)__tpl_gbm_buffer_free); - tbm_bo_set_user_data(bo, KEY_TPL_GBM_BUFFER, buf); + bo = tbm_surface_internal_get_bo(surface, 0); + tbm_bo_add_user_data(bo, KEY_TPL_GBM_BUFFER, + (tbm_data_free)__tpl_gbm_buffer_free); + tbm_bo_set_user_data(bo, KEY_TPL_GBM_BUFFER, buf); } static TPL_INLINE tpl_bool_t @@ -100,12 +98,10 @@ __tpl_gbm_display_init(tpl_display_t *display) TPL_ASSERT(display); /* Do not allow default display in gbm. */ - if (display->native_handle == NULL) - return TPL_ERROR_INVALID_PARAMETER; + if (!display->native_handle) return TPL_ERROR_INVALID_PARAMETER; gbm_display = (tpl_gbm_display_t *) calloc(1, sizeof(tpl_gbm_display_t)); - if (gbm_display == NULL) - return TPL_ERROR_INVALID_PARAMETER; + if (!gbm_display) return TPL_ERROR_INVALID_PARAMETER; display->bufmgr_fd = dup(gbm_device_get_fd(display->native_handle)); gbm_display->bufmgr = tbm_bufmgr_init(display->bufmgr_fd); @@ -122,8 +118,7 @@ __tpl_gbm_display_fini(tpl_display_t *display) TPL_ASSERT(display); gbm_display = (tpl_gbm_display_t *)display->backend.data; - if (gbm_display != NULL) - { + if (gbm_display) { tbm_bufmgr_deinit(gbm_display->bufmgr); free(gbm_display); } @@ -132,44 +127,40 @@ __tpl_gbm_display_fini(tpl_display_t *display) } static tpl_result_t -__tpl_gbm_display_query_config(tpl_display_t *display, tpl_surface_type_t surface_type, - int red_size, int green_size, int blue_size, int alpha_size, - int color_depth, int *native_visual_id, tpl_bool_t *is_slow) +__tpl_gbm_display_query_config(tpl_display_t *display, + tpl_surface_type_t surface_type, int red_size, + int green_size, int blue_size, int alpha_size, + int color_depth, int *native_visual_id, + tpl_bool_t *is_slow) { TPL_ASSERT(display); - if (surface_type == TPL_SURFACE_TYPE_WINDOW && - red_size == 8 && - green_size == 8 && - blue_size == 8 && - (color_depth == 32 || color_depth == 24)) - { - if (alpha_size == 8) - { - if (gbm_device_is_format_supported((struct gbm_device *)display->native_handle, - GBM_FORMAT_ARGB8888, - GBM_BO_USE_RENDERING) == 1) - { - if (native_visual_id != NULL) *native_visual_id = GBM_FORMAT_ARGB8888; - } - else - return TPL_ERROR_INVALID_PARAMETER; + if ((surface_type == TPL_SURFACE_TYPE_WINDOW) && (red_size == 8) + && (green_size == 8) && (blue_size == 8) + && ((color_depth == 32) || (color_depth == 24))) { + if (alpha_size == 8) { + if (gbm_device_is_format_supported( + (struct gbm_device *)display->native_handle, + GBM_FORMAT_ARGB8888, GBM_BO_USE_RENDERING) == 1) { + if (native_visual_id) + *native_visual_id = GBM_FORMAT_ARGB8888; + } else return TPL_ERROR_INVALID_PARAMETER; if (is_slow != NULL) *is_slow = TPL_FALSE; + return TPL_ERROR_NONE; } - if (alpha_size == 0) - { - if (gbm_device_is_format_supported((struct gbm_device *)display->native_handle, - GBM_FORMAT_XRGB8888, - GBM_BO_USE_RENDERING) == 1) - { - if (native_visual_id != NULL) *native_visual_id = GBM_FORMAT_XRGB8888; - } - else - return TPL_ERROR_INVALID_PARAMETER; + if (alpha_size == 0) { + if (gbm_device_is_format_supported( + (struct gbm_device *)display->native_handle, + GBM_FORMAT_XRGB8888, + GBM_BO_USE_RENDERING) == 1) { + if (native_visual_id) + *native_visual_id = GBM_FORMAT_XRGB8888; + } else return TPL_ERROR_INVALID_PARAMETER; if (is_slow != NULL) *is_slow = TPL_FALSE; + return TPL_ERROR_NONE; } } @@ -178,13 +169,13 @@ __tpl_gbm_display_query_config(tpl_display_t *display, tpl_surface_type_t surfac } static tpl_result_t -__tpl_gbm_display_filter_config(tpl_display_t *display, - int *visual_id, int alpha_size) +__tpl_gbm_display_filter_config(tpl_display_t *display, int *visual_id, + int alpha_size) { TPL_IGNORE(display); - if (visual_id != NULL && *visual_id == GBM_FORMAT_ARGB8888 && alpha_size == 0) - { + if (visual_id != NULL && *visual_id == GBM_FORMAT_ARGB8888 + && alpha_size == 0) { *visual_id = GBM_FORMAT_XRGB8888; return TPL_ERROR_NONE; } @@ -194,35 +185,34 @@ __tpl_gbm_display_filter_config(tpl_display_t *display, static tpl_result_t __tpl_gbm_display_get_window_info(tpl_display_t *display, tpl_handle_t window, - int *width, int *height, tbm_format *format, int depth, int a_size) + int *width, int *height, tbm_format *format, + int depth, int a_size) { TPL_ASSERT(display); TPL_ASSERT(window); struct gbm_surface *gbm_surface = (struct gbm_surface *)window; tbm_surface_queue_h surf_queue = (tbm_surface_queue_h)gbm_tbm_get_surface_queue(gbm_surface); - if (surf_queue == NULL) - { + if (!surf_queue) { TPL_ERR("Failed to get tbm_surface_queue from gbm_surface."); return TPL_ERROR_INVALID_OPERATION; } - if (width != NULL) *width = tbm_surface_queue_get_width(surf_queue); - if (height != NULL) *height = tbm_surface_queue_get_height(surf_queue); - if (format != NULL) *format = tbm_surface_queue_get_format(surf_queue); + if (width) *width = tbm_surface_queue_get_width(surf_queue); + if (height) *height = tbm_surface_queue_get_height(surf_queue); + if (format) *format = tbm_surface_queue_get_format(surf_queue); return TPL_ERROR_NONE; } static tpl_result_t __tpl_gbm_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, - int *width, int *height, tbm_format *format) + int *width, int *height, tbm_format *format) { tbm_surface_h tbm_surface = NULL; tbm_surface = wayland_tbm_server_get_surface(NULL, (struct wl_resource*)pixmap); - if (tbm_surface == NULL) - { + if (!tbm_surface) { TPL_ERR("Failed to get tbm_surface_h from native pixmap."); return TPL_ERROR_INVALID_OPERATION; } @@ -242,8 +232,7 @@ __tpl_gbm_display_get_buffer_from_native_pixmap(tpl_handle_t pixmap) TPL_ASSERT(pixmap); tbm_surface = wayland_tbm_server_get_surface(NULL, (struct wl_resource*)pixmap); - if (tbm_surface == NULL) - { + if (!tbm_surface) { TPL_ERR("Failed to get tbm_surface_h from wayland_tbm."); return NULL; } @@ -258,8 +247,7 @@ __tpl_gbm_surface_init(tpl_surface_t *surface) TPL_ASSERT(surface); tpl_gbm_surface = (tpl_gbm_surface_t *) calloc(1, sizeof(tpl_gbm_surface_t)); - if (tpl_gbm_surface == NULL) - { + if (!tpl_gbm_surface) { TPL_ERR("Failed to allocate new gbm backend surface."); return TPL_ERROR_INVALID_OPERATION; } @@ -268,31 +256,27 @@ __tpl_gbm_surface_init(tpl_surface_t *surface) tpl_gbm_surface->tbm_queue = NULL; tpl_gbm_surface->current_buffer = NULL; - if (surface->type == TPL_SURFACE_TYPE_WINDOW) - { + if (surface->type == TPL_SURFACE_TYPE_WINDOW) { struct gbm_surface *gbm_surface = (struct gbm_surface*)surface->native_handle; tpl_gbm_surface->tbm_queue = (tbm_surface_queue_h)gbm_tbm_get_surface_queue(gbm_surface); - if (tpl_gbm_surface->tbm_queue == NULL) - { + if (!tpl_gbm_surface->tbm_queue) { TPL_ERR("Failed to get tbm_surface_queue from gbm_surface."); goto error; } - if (TPL_ERROR_NONE != __tpl_gbm_display_get_window_info(surface->display, surface->native_handle, - &surface->width, &surface->height, NULL, 0, 0)) - { + if (__tpl_gbm_display_get_window_info(surface->display, + surface->native_handle, &surface->width, + &surface->height, NULL, 0, 0) != TPL_ERROR_NONE) { TPL_ERR("Failed to get native window info."); goto error; } TPL_LOG(3, "window(%p, %p) %dx%d", surface, surface->native_handle, surface->width, surface->height); return TPL_ERROR_NONE; - } - else if (surface->type == TPL_SURFACE_TYPE_PIXMAP) - { - if (TPL_ERROR_NONE != __tpl_gbm_display_get_pixmap_info(surface->display, surface->native_handle, - &surface->width, &surface->height, NULL)) - { + } else if (surface->type == TPL_SURFACE_TYPE_PIXMAP) { + if (__tpl_gbm_display_get_pixmap_info(surface->display, + surface->native_handle, &surface->width, + &surface->height, NULL) != TPL_ERROR_NONE) { TPL_ERR("Failed to get native pixmap info."); goto error; } @@ -315,8 +299,7 @@ __tpl_gbm_surface_fini(tpl_surface_t *surface) TPL_ASSERT(surface->display); gbm_surface = (tpl_gbm_surface_t *) surface->backend.data; - if (NULL == gbm_surface) - return; + if (!gbm_surface) return; TPL_LOG(3, "window(%p, %p)", surface, surface->native_handle); @@ -328,37 +311,38 @@ __tpl_gbm_surface_fini(tpl_surface_t *surface) } static tpl_result_t -__tpl_gbm_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface, - int num_rects, const int *rects) +__tpl_gbm_surface_enqueue_buffer(tpl_surface_t *surface, + tbm_surface_h tbm_surface, int num_rects, + const int *rects) { TPL_ASSERT(surface); TPL_ASSERT(surface->display); TPL_ASSERT(surface->display->native_handle); TPL_ASSERT(tbm_surface); - TPL_IGNORE(num_rects); + TPL_IGNORE(num_rects); TPL_IGNORE(rects); TPL_LOG(3, "window(%p, %p)", surface, surface->native_handle); tpl_gbm_surface_t *gbm_surface = (tpl_gbm_surface_t*)surface->backend.data; - if (gbm_surface == NULL) - { - TPL_ERR("tpl_gbm_surface_t is invalid. tpl_surface_t(%p)", surface); + if (!gbm_surface) { + TPL_ERR("tpl_gbm_surface_t is invalid. tpl_surface_t(%p)", + surface); return TPL_ERROR_INVALID_PARAMETER; } tbm_surface_internal_unref(tbm_surface); - if (gbm_surface->tbm_queue == NULL) - { - TPL_ERR("tbm_surface_queue is invalid. tpl_gbm_surface_t(%p)", gbm_surface); + if (!gbm_surface->tbm_queue) { + TPL_ERR("tbm_surface_queue is invalid. tpl_gbm_surface_t(%p)", + gbm_surface); return TPL_ERROR_INVALID_PARAMETER; } - if (tbm_surface_queue_enqueue(gbm_surface->tbm_queue, tbm_surface) != TBM_SURFACE_QUEUE_ERROR_NONE) - { + if (tbm_surface_queue_enqueue(gbm_surface->tbm_queue, tbm_surface) + != TBM_SURFACE_QUEUE_ERROR_NONE) { TPL_ERR("tbm_surface_queue_enqueue failed. tbm_surface_queue(%p) tbm_surface(%p)", - gbm_surface->tbm_queue, tbm_surface); + gbm_surface->tbm_queue, tbm_surface); return TPL_ERROR_INVALID_PARAMETER; } @@ -391,12 +375,12 @@ __tpl_gbm_surface_dequeue_buffer(tpl_surface_t *surface) gbm_surface = (tpl_gbm_surface_t*)surface->backend.data; tsq_err = tbm_surface_queue_dequeue(gbm_surface->tbm_queue, &tbm_surface); - if(tbm_surface == NULL && tbm_surface_queue_can_dequeue(gbm_surface->tbm_queue, 1) == 1) - { + if(!tbm_surface + && tbm_surface_queue_can_dequeue(gbm_surface->tbm_queue, 1) == 1) { tsq_err = tbm_surface_queue_dequeue(gbm_surface->tbm_queue, &tbm_surface); - if (tbm_surface == NULL) - { - TPL_ERR("Failed to get tbm_surface from tbm_surface_queue | tsq_err = %d",tsq_err); + if (!tbm_surface) { + TPL_ERR("Failed to get tbm_surface from tbm_surface_queue | tsq_err = %d", + tsq_err); return NULL; } } @@ -404,21 +388,18 @@ __tpl_gbm_surface_dequeue_buffer(tpl_surface_t *surface) /* It will be dec when before tbm_surface_queue_enqueue called */ tbm_surface_internal_ref(tbm_surface); - if ((gbm_buffer = __tpl_gbm_get_gbm_buffer_from_tbm_surface(tbm_surface)) != NULL) - { + if (gbm_buffer = __tpl_gbm_get_gbm_buffer_from_tbm_surface(tbm_surface)) { return tbm_surface; } - if ((bo = tbm_surface_internal_get_bo(tbm_surface, 0)) == NULL) - { + if (!(bo = tbm_surface_internal_get_bo(tbm_surface, 0))) { TPL_ERR("Failed to get tbm_bo from tbm_surface"); tbm_surface_internal_unref(tbm_surface); return NULL; } gbm_buffer = (tpl_gbm_buffer_t *) calloc(1, sizeof(tpl_gbm_buffer_t)); - if (gbm_buffer == NULL) - { + if (!gbm_buffer) { TPL_ERR("Mem alloc for gbm_buffer failed!"); tbm_surface_internal_unref(tbm_surface); return NULL; @@ -433,6 +414,7 @@ __tpl_gbm_surface_dequeue_buffer(tpl_surface_t *surface) return tbm_surface; } + static void __tpl_gbm_buffer_free(tpl_gbm_buffer_t *gbm_buffer) { @@ -460,13 +442,13 @@ __tpl_display_init_backend_gbm(tpl_display_backend_t *backend) backend->type = TPL_BACKEND_GBM; backend->data = NULL; - backend->init = __tpl_gbm_display_init; - backend->fini = __tpl_gbm_display_fini; - backend->query_config = __tpl_gbm_display_query_config; - backend->filter_config = __tpl_gbm_display_filter_config; - backend->get_window_info = __tpl_gbm_display_get_window_info; - backend->get_pixmap_info = __tpl_gbm_display_get_pixmap_info; - backend->get_buffer_from_native_pixmap = __tpl_gbm_display_get_buffer_from_native_pixmap; + backend->init = __tpl_gbm_display_init; + backend->fini = __tpl_gbm_display_fini; + backend->query_config = __tpl_gbm_display_query_config; + backend->filter_config = __tpl_gbm_display_filter_config; + backend->get_window_info = __tpl_gbm_display_get_window_info; + backend->get_pixmap_info = __tpl_gbm_display_get_pixmap_info; + backend->get_buffer_from_native_pixmap = __tpl_gbm_display_get_buffer_from_native_pixmap; } void @@ -477,9 +459,9 @@ __tpl_surface_init_backend_gbm(tpl_surface_backend_t *backend) backend->type = TPL_BACKEND_GBM; backend->data = NULL; - backend->init = __tpl_gbm_surface_init; - backend->fini = __tpl_gbm_surface_fini; - backend->validate = __tpl_gbm_surface_validate; - backend->dequeue_buffer = __tpl_gbm_surface_dequeue_buffer; + backend->init = __tpl_gbm_surface_init; + backend->fini = __tpl_gbm_surface_fini; + backend->validate = __tpl_gbm_surface_validate; + backend->dequeue_buffer = __tpl_gbm_surface_dequeue_buffer; backend->enqueue_buffer = __tpl_gbm_surface_enqueue_buffer; } diff --git a/src/tpl_internal.h b/src/tpl_internal.h index 6df9739..429040f 100644 --- a/src/tpl_internal.h +++ b/src/tpl_internal.h @@ -20,85 +20,77 @@ #define TPL_OBJECT_LOCK(object) __tpl_object_lock((tpl_object_t *)(object)) #define TPL_OBJECT_UNLOCK(object) __tpl_object_unlock((tpl_object_t *)(object)) -typedef struct _tpl_runtime tpl_runtime_t; +typedef struct _tpl_runtime tpl_runtime_t; typedef struct _tpl_display_backend tpl_display_backend_t; typedef struct _tpl_surface_backend tpl_surface_backend_t; - -typedef struct tpl_hlist tpl_hlist_t; - -struct _tpl_display_backend -{ - tpl_backend_type_t type; - void *data; - - tpl_result_t (*init)(tpl_display_t *display); - void (*fini)(tpl_display_t *display); - - tpl_result_t (*query_config)(tpl_display_t *display, - tpl_surface_type_t surface_type, int red_bits, - int green_bits, int blue_bits, int alpha_bits, - int color_depth, int *native_visual_id, tpl_bool_t *is_slow); - tpl_result_t (*filter_config)(tpl_display_t *display, int *visual_id, int alpha_bits); - - tpl_result_t (*get_window_info)(tpl_display_t *display, tpl_handle_t window, - int *width, int *height, tbm_format *format, int depth,int a_size); - tpl_result_t (*get_pixmap_info)(tpl_display_t *display, tpl_handle_t pixmap, - int *width, int *height, tbm_format *format); - - tbm_surface_h (*get_buffer_from_native_pixmap)(tpl_handle_t pixmap); +typedef struct tpl_hlist tpl_hlist_t; + +struct _tpl_display_backend { + tpl_backend_type_t type; + void *data; + + tpl_result_t (*init)(tpl_display_t *display); + void (*fini)(tpl_display_t *display); + tpl_result_t (*query_config)(tpl_display_t *display, + tpl_surface_type_t surface_type, + int red_bits, int green_bits, + int blue_bits, int alpha_bits, + int color_depth, int *native_visual_id, + tpl_bool_t *is_slow); + tpl_result_t (*filter_config)(tpl_display_t *display, int *visual_id, + int alpha_bits); + tpl_result_t (*get_window_info)(tpl_display_t *display, + tpl_handle_t window, int *width, + int *height, tbm_format *format, + int depth,int a_size); + tpl_result_t (*get_pixmap_info)(tpl_display_t *display, + tpl_handle_t pixmap, int *width, + int *height, tbm_format *format); + tbm_surface_h (*get_buffer_from_native_pixmap)(tpl_handle_t pixmap); }; -struct _tpl_surface_backend -{ - tpl_backend_type_t type; - void *data; - - tpl_result_t (*init)(tpl_surface_t *surface); - void (*fini)(tpl_surface_t *surface); - - tpl_bool_t (*validate)(tpl_surface_t *surface); - - tbm_surface_h (*dequeue_buffer)(tpl_surface_t *surface); - tpl_result_t (*enqueue_buffer)(tpl_surface_t *surface, tbm_surface_h tbm_surface, - int num_rects, const int *rects); +struct _tpl_surface_backend { + tpl_backend_type_t type; + void *data; + + tpl_result_t (*init)(tpl_surface_t *surface); + void (*fini)(tpl_surface_t *surface); + tpl_bool_t (*validate)(tpl_surface_t *surface); + tbm_surface_h (*dequeue_buffer)(tpl_surface_t *surface); + tpl_result_t (*enqueue_buffer)(tpl_surface_t *surface, + tbm_surface_h tbm_surface, + int num_rects, const int *rects); }; -struct _tpl_object -{ - tpl_object_type_t type; - tpl_util_atomic_uint reference; - tpl_free_func_t free; - pthread_mutex_t mutex; - +struct _tpl_object { + tpl_object_type_t type; + tpl_util_atomic_uint reference; + tpl_free_func_t free; + pthread_mutex_t mutex; tpl_util_map_t user_data_map; - tpl_util_map_entry_t *buckets[1 << TPL_OBJECT_BUCKET_BITS]; + tpl_util_map_entry_t *buckets[1 << TPL_OBJECT_BUCKET_BITS]; }; -struct _tpl_display -{ - tpl_object_t base; - - tpl_handle_t native_handle; - - int bufmgr_fd; - tpl_display_backend_t backend; +struct _tpl_display { + tpl_object_t base; + tpl_handle_t native_handle; + int bufmgr_fd; + tpl_display_backend_t backend; #if defined(TPL_WINSYS_DRI2) || defined(TPL_WINSYS_DRI3) - xcb_connection_t *xcb_connection; + xcb_connection_t *xcb_connection; #endif }; -struct _tpl_surface -{ - tpl_object_t base; - - tpl_display_t *display; - tpl_handle_t native_handle; - tpl_surface_type_t type; - tbm_format format; - int width, height; - int post_interval; - int dump_count; - tpl_surface_backend_t backend; +struct _tpl_surface { + tpl_object_t base; + tpl_display_t *display; + tpl_handle_t native_handle; + tpl_surface_type_t type; + tbm_format format; + int width, height; + int post_interval; + int dump_count; + tpl_surface_backend_t backend; }; /******************************************************************************* @@ -117,7 +109,9 @@ tpl_bool_t __tpl_object_is_valid(tpl_object_t *object); * @param free_func customized deallocation routine for this TPL object * @return TPL_ERROR_NONE on success, TPL_ERROR on error */ -tpl_result_t __tpl_object_init(tpl_object_t *object, tpl_object_type_t type, tpl_free_func_t free_func); +tpl_result_t +__tpl_object_init(tpl_object_t *object, tpl_object_type_t type, + tpl_free_func_t free_func); /** brief destroy a TPL object * @param object the TPL object to destroy @@ -138,36 +132,32 @@ tpl_result_t __tpl_object_lock(tpl_object_t *object); void __tpl_object_unlock(tpl_object_t *object); /* Display functions. */ -tpl_handle_t __tpl_display_get_native_handle(tpl_display_t *display); -void __tpl_display_flush(tpl_display_t *display); - -void __tpl_surface_set_backend_data(tpl_surface_t *surface, void *data); -void * __tpl_surface_get_backend_data(tpl_surface_t *surface); +tpl_handle_t __tpl_display_get_native_handle(tpl_display_t *display); +void __tpl_display_flush(tpl_display_t *display); +void __tpl_surface_set_backend_data(tpl_surface_t *surface, void *data); +void *__tpl_surface_get_backend_data(tpl_surface_t *surface); /* Runtime functions. */ -tpl_display_t * __tpl_runtime_find_display(tpl_backend_type_t type, tpl_handle_t native_display); -tpl_result_t __tpl_runtime_add_display(tpl_display_t *display); -void __tpl_runtime_remove_display(tpl_display_t *display); -void __tpl_runtime_flush_all_display(); +tpl_display_t * +__tpl_runtime_find_display(tpl_backend_type_t type, tpl_handle_t native_display); +tpl_result_t __tpl_runtime_add_display(tpl_display_t *display); +void __tpl_runtime_remove_display(tpl_display_t *display); +void __tpl_runtime_flush_all_display(); /* Backend initialization functions. */ tpl_backend_type_t __tpl_display_choose_backend(tpl_handle_t native_dpy); - tpl_bool_t __tpl_display_choose_backend_gbm(tpl_handle_t native_dpy); tpl_bool_t __tpl_display_choose_backend_tbm(tpl_handle_t native_dpy); tpl_bool_t __tpl_display_choose_backend_wayland(tpl_handle_t native_dpy); tpl_bool_t __tpl_display_choose_backend_x11_dri2(tpl_handle_t native_dpy); tpl_bool_t __tpl_display_choose_backend_x11_dri3(tpl_handle_t native_dpy); - void __tpl_display_init_backend(tpl_display_t *display, tpl_backend_type_t type); void __tpl_surface_init_backend(tpl_surface_t *surface, tpl_backend_type_t type); - void __tpl_display_init_backend_gbm(tpl_display_backend_t *backend); void __tpl_display_init_backend_tbm(tpl_display_backend_t *backend); void __tpl_display_init_backend_wayland(tpl_display_backend_t *backend); void __tpl_display_init_backend_x11_dri2(tpl_display_backend_t *backend); void __tpl_display_init_backend_x11_dri3(tpl_display_backend_t *backend); - void __tpl_surface_init_backend_gbm(tpl_surface_backend_t *backend); void __tpl_surface_init_backend_tbm(tpl_surface_backend_t *backend); void __tpl_surface_init_backend_wayland(tpl_surface_backend_t *backend); diff --git a/src/tpl_object.c b/src/tpl_object.c index 33f756c..d75af47 100644 --- a/src/tpl_object.c +++ b/src/tpl_object.c @@ -7,7 +7,7 @@ __tpl_object_is_valid(tpl_object_t *object) if (NULL == object) return TPL_FALSE; - return (0 != __tpl_util_atomic_get(&object->reference)); + return (__tpl_util_atomic_get(&object->reference) != 0); } tpl_result_t @@ -22,8 +22,7 @@ __tpl_object_init(tpl_object_t *object, tpl_object_type_t type, tpl_free_func_t __tpl_util_atomic_set(&object->reference, 1); - if (0 != pthread_mutex_init(&object->mutex, NULL)) - { + if (pthread_mutex_init(&object->mutex, NULL) != 0) { TPL_ERR("tpl_object_t pthread_mutex_init failed."); return TPL_ERROR_INVALID_OPERATION; } @@ -36,8 +35,7 @@ __tpl_object_fini(tpl_object_t *object) { TPL_ASSERT(object); - if (0 != pthread_mutex_destroy(&object->mutex)) - { + if (pthread_mutex_destroy(&object->mutex) != 0) { TPL_ERR("tpl_object_t pthread_mutex_destroy failed."); return TPL_ERROR_INVALID_OPERATION; } @@ -52,8 +50,7 @@ __tpl_object_lock(tpl_object_t *object) { TPL_ASSERT(object); - if (0 != pthread_mutex_lock(&object->mutex)) - { + if (pthread_mutex_lock(&object->mutex) != 0) { TPL_ERR("tpl_object_t pthread_mutex_lock failed."); return TPL_ERROR_INVALID_OPERATION; } @@ -71,8 +68,7 @@ __tpl_object_unlock(tpl_object_t *object) int tpl_object_reference(tpl_object_t *object) { - if (TPL_TRUE != __tpl_object_is_valid(object)) - { + if (__tpl_object_is_valid(object) != TPL_TRUE) { TPL_ERR("input object is invalid!"); return -1; } @@ -85,16 +81,14 @@ tpl_object_unreference(tpl_object_t *object) { unsigned int reference; - if (TPL_TRUE != __tpl_object_is_valid(object)) - { + if (__tpl_object_is_valid(object) != TPL_TRUE) { TPL_ERR("input object is invalid!"); return -1; } reference = __tpl_util_atomic_dec(&object->reference); - if (0 == reference) - { + if (reference == 0) { __tpl_object_fini(object); object->free(object); } @@ -105,8 +99,7 @@ tpl_object_unreference(tpl_object_t *object) int tpl_object_get_reference(tpl_object_t *object) { - if (TPL_TRUE != __tpl_object_is_valid(object)) - { + if (__tpl_object_is_valid(object) != TPL_TRUE) { TPL_ERR("input object is invalid!"); return -1; } @@ -117,8 +110,7 @@ tpl_object_get_reference(tpl_object_t *object) tpl_object_type_t tpl_object_get_type(tpl_object_t *object) { - if (TPL_TRUE != __tpl_object_is_valid(object)) - { + if (__tpl_object_is_valid(object) != TPL_TRUE) { TPL_ERR("input object is invalid!"); return TPL_OBJECT_ERROR; } @@ -127,12 +119,12 @@ tpl_object_get_type(tpl_object_t *object) } tpl_result_t -tpl_object_set_user_data(tpl_object_t *object, void *key, void *data, tpl_free_func_t free_func) +tpl_object_set_user_data(tpl_object_t *object, void *key, void *data, + tpl_free_func_t free_func) { tpl_util_key_t _key; - if (TPL_TRUE != __tpl_object_is_valid(object)) - { + if (__tpl_object_is_valid(object) != TPL_TRUE) { TPL_ERR("input object is invalid!"); return TPL_ERROR_INVALID_PARAMETER; } @@ -151,8 +143,7 @@ tpl_object_get_user_data(tpl_object_t *object, void *key) tpl_util_key_t _key; void *data; - if (TPL_TRUE != __tpl_object_is_valid(object)) - { + if (__tpl_object_is_valid(object) != TPL_TRUE) { TPL_ERR("input object is invalid!"); return NULL; } diff --git a/src/tpl_surface.c b/src/tpl_surface.c index a86cc6d..3f19dd6 100644 --- a/src/tpl_surface.c +++ b/src/tpl_surface.c @@ -21,27 +21,24 @@ tpl_surface_create(tpl_display_t *display, tpl_handle_t handle, tpl_surface_type { tpl_surface_t *surface; - if (NULL == display) - { + if (!display) { TPL_ERR("Display is NULL!"); return NULL; } - if (NULL == handle) - { + if (!handle) { TPL_ERR("Handle is NULL!"); return NULL; } surface = (tpl_surface_t *) calloc(1, sizeof(tpl_surface_t)); - if (NULL == surface) - { + if (!surface) { TPL_ERR("Failed to allocate memory for surface!"); return NULL; } - if (TPL_ERROR_NONE != __tpl_object_init(&surface->base, TPL_OBJECT_SURFACE, __tpl_surface_free)) - { + if (__tpl_object_init(&surface->base, TPL_OBJECT_SURFACE, + __tpl_surface_free) != TPL_ERROR_NONE) { TPL_ERR("Failed to initialize surface's base class!"); free(surface); return NULL; @@ -54,13 +51,13 @@ tpl_surface_create(tpl_display_t *display, tpl_handle_t handle, tpl_surface_type surface->post_interval = 1; - surface->dump_count = 0; + surface->dump_count = 0; /* Intialize backend. */ __tpl_surface_init_backend(surface, display->backend.type); - if (NULL == surface->backend.init || TPL_ERROR_NONE != surface->backend.init(surface)) - { + if ((!surface->backend.init) + || (surface->backend.init(surface) != TPL_ERROR_NONE)) { TPL_ERR("Failed to initialize surface's backend!"); tpl_object_unreference(&surface->base); return NULL; @@ -72,8 +69,7 @@ tpl_surface_create(tpl_display_t *display, tpl_handle_t handle, tpl_surface_type tpl_display_t * tpl_surface_get_display(tpl_surface_t *surface) { - if (NULL == surface) - { + if (!surface) { TPL_ERR("Surface is NULL!"); return NULL; } @@ -84,8 +80,7 @@ tpl_surface_get_display(tpl_surface_t *surface) tpl_handle_t tpl_surface_get_native_handle(tpl_surface_t *surface) { - if (NULL == surface) - { + if (!surface) { TPL_ERR("Surface is NULL!"); return NULL; } @@ -96,8 +91,7 @@ tpl_surface_get_native_handle(tpl_surface_t *surface) tpl_surface_type_t tpl_surface_get_type(tpl_surface_t *surface) { - if (NULL == surface) - { + if (!surface) { TPL_ERR("Surface is NULL!"); return TPL_SURFACE_ERROR; } @@ -108,17 +102,14 @@ tpl_surface_get_type(tpl_surface_t *surface) tpl_result_t tpl_surface_get_size(tpl_surface_t *surface, int *width, int *height) { - if (NULL == surface) - { + if (!surface) { TPL_ERR("Surface is NULL!"); return TPL_ERROR_INVALID_PARAMETER; } - if (width) - *width = surface->width; + if (width) *width = surface->width; - if (height) - *height = surface->height; + if (height) *height = surface->height; return TPL_ERROR_NONE; } @@ -129,14 +120,12 @@ tpl_surface_validate(tpl_surface_t *surface) { tpl_bool_t was_valid = TPL_TRUE; - if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type) - { + if (!surface || (surface->type != TPL_SURFACE_TYPE_WINDOW)) { TPL_ERR("Invalid surface!"); return TPL_FALSE; } - if (NULL == surface->backend.validate) - { + if (!surface->backend.validate) { TPL_ERR("Backend for surface has not been initialized!"); return TPL_FALSE; } @@ -144,8 +133,7 @@ tpl_surface_validate(tpl_surface_t *surface) TRACE_BEGIN("TPL:VALIDATEFRAME"); TPL_OBJECT_LOCK(surface); - if (!surface->backend.validate(surface)) - was_valid = TPL_FALSE; + if (!surface->backend.validate(surface)) was_valid = TPL_FALSE; TPL_OBJECT_UNLOCK(surface); TRACE_END(); @@ -156,8 +144,7 @@ tpl_surface_validate(tpl_surface_t *surface) tpl_result_t tpl_surface_set_post_interval(tpl_surface_t *surface, int interval) { - if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type) - { + if (!surface || (surface->type != TPL_SURFACE_TYPE_WINDOW)) { TPL_ERR("Invalid surface!"); return TPL_ERROR_INVALID_PARAMETER; } @@ -174,8 +161,7 @@ tpl_surface_get_post_interval(tpl_surface_t *surface) { int interval; - if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type) - { + if (!surface || (surface->type != TPL_SURFACE_TYPE_WINDOW)) { TPL_ERR("Invalid surface!"); return -1; } @@ -194,8 +180,7 @@ tpl_surface_dequeue_buffer(tpl_surface_t *surface) tbm_surface_h tbm_surface = NULL; - if (surface->backend.dequeue_buffer == NULL) - { + if (!surface->backend.dequeue_buffer) { TPL_ERR("TPL surface has not been initialized correctly!"); return NULL; } @@ -205,8 +190,7 @@ tpl_surface_dequeue_buffer(tpl_surface_t *surface) tbm_surface = surface->backend.dequeue_buffer(surface); - if(tbm_surface != NULL) - { + if(tbm_surface) { /* Update size of the surface. */ surface->width = tbm_surface_get_width(tbm_surface); surface->height = tbm_surface_get_height(tbm_surface); @@ -223,8 +207,7 @@ tpl_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface) { tpl_result_t ret = TPL_ERROR_INVALID_OPERATION; - if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type) - { + if (!surface || (surface->type != TPL_SURFACE_TYPE_WINDOW)) { TPL_ERR("Invalid surface!"); return TPL_ERROR_INVALID_PARAMETER; } @@ -232,8 +215,7 @@ tpl_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface) TRACE_BEGIN("TPL:POST"); TPL_OBJECT_LOCK(surface); - if (NULL == tbm_surface) - { + if (!tbm_surface) { TPL_OBJECT_UNLOCK(surface); TRACE_END(); TPL_ERR("tbm surface is invalid."); @@ -250,13 +232,13 @@ tpl_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface) } tpl_result_t -tpl_surface_enqueue_buffer_with_damage(tpl_surface_t *surface, tbm_surface_h tbm_surface, +tpl_surface_enqueue_buffer_with_damage(tpl_surface_t *surface, + tbm_surface_h tbm_surface, int num_rects, const int *rects) { tpl_result_t ret = TPL_ERROR_INVALID_OPERATION; - if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type) - { + if (!surface || (surface->type != TPL_SURFACE_TYPE_WINDOW)) { TPL_ERR("Invalid surface!"); return TPL_ERROR_INVALID_PARAMETER; } @@ -264,8 +246,7 @@ tpl_surface_enqueue_buffer_with_damage(tpl_surface_t *surface, tbm_surface_h tbm TRACE_BEGIN("TPL:POST"); TPL_OBJECT_LOCK(surface); - if (NULL == tbm_surface) - { + if (!tbm_surface) { TPL_OBJECT_UNLOCK(surface); TRACE_END(); TPL_ERR("tbm surface is invalid."); diff --git a/src/tpl_tbm.c b/src/tpl_tbm.c index 6d81c01..65cbe6d 100644 --- a/src/tpl_tbm.c +++ b/src/tpl_tbm.c @@ -9,16 +9,14 @@ #include #include -typedef struct _tpl_tbm_display tpl_tbm_display_t; -typedef struct _tpl_tbm_surface tpl_tbm_surface_t; +typedef struct _tpl_tbm_display tpl_tbm_display_t; +typedef struct _tpl_tbm_surface tpl_tbm_surface_t; -struct _tpl_tbm_display -{ +struct _tpl_tbm_display { int dummy; }; -struct _tpl_tbm_surface -{ +struct _tpl_tbm_surface { int dummy; }; @@ -29,14 +27,13 @@ __tpl_tbm_display_init(tpl_display_t *display) TPL_ASSERT(display); - if (display->native_handle == NULL) - { + if (!display->native_handle) { display->native_handle = tbm_bufmgr_init(-1); } tbm_display = (tpl_tbm_display_t *) calloc(1, sizeof(tpl_tbm_display_t)); - if (tbm_display == NULL) - { + + if (!tbm_display) { TPL_ERR("Failed to allocate memory for new tpl_tbm_display_t."); return TPL_ERROR_INVALID_OPERATION; } @@ -55,45 +52,39 @@ __tpl_tbm_display_fini(tpl_display_t *display) TPL_ASSERT(display); tbm_display = (tpl_tbm_display_t *)display->backend.data; - if (tbm_display != NULL) - { - free(tbm_display); - } + + if (tbm_display) free(tbm_display); + display->backend.data = NULL; tbm_bufmgr_deinit((tbm_bufmgr)display->native_handle); } static tpl_result_t -__tpl_tbm_display_query_config(tpl_display_t *display, tpl_surface_type_t surface_type, - int red_size, int green_size, int blue_size, int alpha_size, - int color_depth, int *native_visual_id, tpl_bool_t *is_slow) +__tpl_tbm_display_query_config(tpl_display_t *display, + tpl_surface_type_t surface_type, int red_size, + int green_size, int blue_size, int alpha_size, + int color_depth, int *native_visual_id, + tpl_bool_t *is_slow) { TPL_ASSERT(display); - if (surface_type == TPL_SURFACE_TYPE_WINDOW && - red_size == 8 && - green_size == 8 && - blue_size == 8 && - (color_depth == 32 || color_depth == 24)) - { - if (alpha_size == 8) - { - if (native_visual_id != NULL) + if (surface_type == TPL_SURFACE_TYPE_WINDOW && red_size == 8 + && green_size == 8 && blue_size == 8 + && (color_depth == 32 || color_depth == 24)) { + if (alpha_size == 8) { + if (native_visual_id) *native_visual_id = TBM_FORMAT_ARGB8888; - if (is_slow != NULL) - *is_slow = TPL_FALSE; + if (is_slow) *is_slow = TPL_FALSE; return TPL_ERROR_NONE; } - if (alpha_size == 0) - { - if (native_visual_id != NULL) + if (alpha_size == 0) { + if (native_visual_id) *native_visual_id = TBM_FORMAT_XRGB8888; - if (is_slow != NULL) - *is_slow = TPL_FALSE; + if (is_slow) *is_slow = TPL_FALSE; return TPL_ERROR_NONE; } @@ -103,13 +94,12 @@ __tpl_tbm_display_query_config(tpl_display_t *display, tpl_surface_type_t surfac } static tpl_result_t -__tpl_tbm_display_filter_config(tpl_display_t *display, - int *visual_id, int alpha_size) +__tpl_tbm_display_filter_config(tpl_display_t *display, int *visual_id, + int alpha_size) { TPL_IGNORE(display); - if (visual_id != NULL && *visual_id == TBM_FORMAT_ARGB8888 && alpha_size == 0) - { + if (visual_id && *visual_id == TBM_FORMAT_ARGB8888 && alpha_size == 0) { *visual_id = TBM_FORMAT_XRGB8888; return TPL_ERROR_NONE; } @@ -119,47 +109,40 @@ __tpl_tbm_display_filter_config(tpl_display_t *display, static tpl_result_t __tpl_tbm_display_get_window_info(tpl_display_t *display, tpl_handle_t window, - int *width, int *height, tbm_format *format, int depth, int a_size) + int *width, int *height, tbm_format *format, + int depth, int a_size) { TPL_ASSERT(display); TPL_ASSERT(window); tbm_surface_queue_h surf_queue = (tbm_surface_queue_h)window; - if (surf_queue == NULL) - { + if (!surf_queue) { TPL_ERR("Native widow(%p) is invalid.", window); return TPL_ERROR_INVALID_PARAMETER; } - if (width != NULL) - *width = tbm_surface_queue_get_width(surf_queue); - if (height != NULL) - *height = tbm_surface_queue_get_height(surf_queue); - if (format != NULL) - *format = tbm_surface_queue_get_format(surf_queue); + if (width) *width = tbm_surface_queue_get_width(surf_queue); + if (height) *height = tbm_surface_queue_get_height(surf_queue); + if (format) *format = tbm_surface_queue_get_format(surf_queue); return TPL_ERROR_NONE; } static tpl_result_t __tpl_tbm_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, - int *width, int *height, tbm_format *format) + int *width, int *height, tbm_format *format) { tbm_surface_h tbm_surface = NULL; tbm_surface = (tbm_surface_h)pixmap; - if (tbm_surface == NULL) - { + if (!tbm_surface) { TPL_ERR("Native pixmap(%p) is invalid.", pixmap); return TPL_ERROR_INVALID_PARAMETER; } - if (width) - *width = tbm_surface_get_width(tbm_surface); - if (height) - *height = tbm_surface_get_height(tbm_surface); - if (format) - *format = tbm_surface_get_format(tbm_surface); + if (width) *width = tbm_surface_get_width(tbm_surface); + if (height) *height = tbm_surface_get_height(tbm_surface); + if (format) *format = tbm_surface_get_format(tbm_surface); return TPL_ERROR_NONE; } @@ -184,41 +167,44 @@ __tpl_tbm_surface_init(tpl_surface_t *surface) TPL_ASSERT(surface); tpl_tbm_surface = (tpl_tbm_surface_t *) calloc(1, sizeof(tpl_tbm_surface_t)); - if (NULL == tpl_tbm_surface) - { + if (!tpl_tbm_surface) { TPL_ERR("Failed to allocate memory for new tpl_tbm_surface_t"); return TPL_ERROR_INVALID_OPERATION; } surface->backend.data = (void *)tpl_tbm_surface; - if (surface->type == TPL_SURFACE_TYPE_WINDOW) - { - if (TPL_ERROR_NONE != __tpl_tbm_display_get_window_info(surface->display, surface->native_handle, - &surface->width, &surface->height, NULL, 0, 0)) - { - TPL_ERR("Failed to get native window(%p) info.", surface->native_handle); + if (surface->type == TPL_SURFACE_TYPE_WINDOW) { + if (__tpl_tbm_display_get_window_info(surface->display, + surface->native_handle, &surface->width, + &surface->height, NULL, 0, 0) != TPL_ERROR_NONE) { + TPL_ERR("Failed to get native window(%p) info.", + surface->native_handle); goto error; } tbm_surface_queue_set_destroy_cb((tbm_surface_queue_h)surface->native_handle, - __tpl_tbm_surface_queue_notify_cb, surface); + __tpl_tbm_surface_queue_notify_cb, + surface); + + TPL_LOG(3, "window(%p, %p) %dx%d", surface, + surface->native_handle, surface->width, surface->height); - TPL_LOG(3, "window(%p, %p) %dx%d", surface, surface->native_handle, surface->width, surface->height); return TPL_ERROR_NONE; - } - else if (surface->type == TPL_SURFACE_TYPE_PIXMAP) - { - if (TPL_TRUE != __tpl_tbm_display_get_pixmap_info(surface->display, surface->native_handle, - &surface->width, &surface->height, NULL)) - { - TPL_ERR("Failed to get native pixmap(%p) info.", surface->native_handle); + } else if (surface->type == TPL_SURFACE_TYPE_PIXMAP) { + if (__tpl_tbm_display_get_pixmap_info(surface->display, + surface->native_handle, &surface->width, + &surface->height, NULL) != TPL_TRUE) { + TPL_ERR("Failed to get native pixmap(%p) info.", + surface->native_handle); + goto error; } tbm_surface_internal_ref((tbm_surface_h)surface->native_handle); - TPL_LOG(3, "pixmap(%p, %p) %dx%d", surface, surface->native_handle, surface->width, surface->height); + TPL_LOG(3, "pixmap(%p, %p) %dx%d", surface, + surface->native_handle, surface->width, surface->height); return TPL_ERROR_NONE; } @@ -236,13 +222,13 @@ __tpl_tbm_surface_fini(tpl_surface_t *surface) TPL_ASSERT(surface->display); TPL_LOG(3, "%s(%p, %p)", - ((surface->type == TPL_SURFACE_TYPE_WINDOW)?"window":"pixmap"), - surface, - surface->native_handle); + ((surface->type == TPL_SURFACE_TYPE_WINDOW)?"window":"pixmap"), + surface, surface->native_handle); + if (surface->type == TPL_SURFACE_TYPE_PIXMAP) tbm_surface_internal_unref((tbm_surface_h)surface->native_handle); - if (surface->type == TPL_SURFACE_TYPE_WINDOW) - { + + if (surface->type == TPL_SURFACE_TYPE_WINDOW) { /*TODO: we need fix for dequeued surface*/ } @@ -251,8 +237,9 @@ __tpl_tbm_surface_fini(tpl_surface_t *surface) } static tpl_result_t -__tpl_tbm_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface, - int num_rects, const int *rects) +__tpl_tbm_surface_enqueue_buffer(tpl_surface_t *surface, + tbm_surface_h tbm_surface, int num_rects, + const int *rects) { TPL_ASSERT(surface); TPL_ASSERT(surface->display); @@ -263,25 +250,25 @@ __tpl_tbm_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surfa tbm_surface_internal_unref(tbm_surface); - if (surface->type == TPL_SURFACE_TYPE_PIXMAP) - { - TPL_ERR("Pixmap cannot post(%p, %p)",surface, surface->native_handle); + if (surface->type == TPL_SURFACE_TYPE_PIXMAP) { + TPL_ERR("Pixmap cannot post(%p, %p)",surface, + surface->native_handle); return TPL_ERROR_INVALID_PARAMETER; } TPL_LOG(3, "window(%p, %p)", surface, surface->native_handle); tbm_surface_queue_h tbm_queue = (tbm_surface_queue_h)surface->native_handle; - if (tbm_queue == NULL) - { + + if (!tbm_queue) { TPL_ERR("tbm_surface_queue is invalid."); return TPL_ERROR_INVALID_PARAMETER; } - if (tbm_surface_queue_enqueue(tbm_queue, tbm_surface) != TBM_SURFACE_QUEUE_ERROR_NONE) - { + if (tbm_surface_queue_enqueue(tbm_queue, tbm_surface) + != TBM_SURFACE_QUEUE_ERROR_NONE) { TPL_ERR("tbm_surface_queue_enqueue failed. tbm_queue(%p) tbm_surface(%p)", - tbm_queue, tbm_surface); + tbm_queue, tbm_surface); return TPL_ERROR_INVALID_OPERATION; } @@ -311,11 +298,9 @@ __tpl_tbm_surface_dequeue_buffer(tpl_surface_t *surface) tbm_queue = (tbm_surface_queue_h)surface->native_handle; tsq_err = tbm_surface_queue_dequeue(tbm_queue, &tbm_surface); - if(tbm_surface == NULL && tbm_surface_queue_can_dequeue(tbm_queue, 1) == 1) - { + if (!tbm_surface && tbm_surface_queue_can_dequeue(tbm_queue, 1) == 1) { tsq_err = tbm_surface_queue_dequeue(tbm_queue, &tbm_surface); - if (tbm_surface == NULL) - { + if (!tbm_surface) { TPL_ERR("Failed to get tbm_surface from tbm_surface_queue | tsq_err = %d",tsq_err); return NULL; } @@ -334,15 +319,13 @@ __tpl_display_choose_backend_tbm(tpl_handle_t native_dpy) tpl_bool_t ret = TPL_FALSE; tbm_bufmgr bufmgr = NULL; - if (native_dpy == NULL) - return TPL_FALSE; + if (!native_dpy) return TPL_FALSE; bufmgr = tbm_bufmgr_init(-1); - if (bufmgr == (tbm_bufmgr)native_dpy) - ret = TPL_TRUE; - if (bufmgr) - tbm_bufmgr_deinit(bufmgr); + if (bufmgr == (tbm_bufmgr)native_dpy) ret = TPL_TRUE; + + if (bufmgr) tbm_bufmgr_deinit(bufmgr); return ret; } @@ -355,13 +338,13 @@ __tpl_display_init_backend_tbm(tpl_display_backend_t *backend) backend->type = TPL_BACKEND_TBM; backend->data = NULL; - backend->init = __tpl_tbm_display_init; - backend->fini = __tpl_tbm_display_fini; - backend->query_config = __tpl_tbm_display_query_config; - backend->filter_config = __tpl_tbm_display_filter_config; - backend->get_window_info = __tpl_tbm_display_get_window_info; - backend->get_pixmap_info = __tpl_tbm_display_get_pixmap_info; - backend->get_buffer_from_native_pixmap = __tpl_tbm_display_get_buffer_from_native_pixmap; + backend->init = __tpl_tbm_display_init; + backend->fini = __tpl_tbm_display_fini; + backend->query_config = __tpl_tbm_display_query_config; + backend->filter_config = __tpl_tbm_display_filter_config; + backend->get_window_info = __tpl_tbm_display_get_window_info; + backend->get_pixmap_info = __tpl_tbm_display_get_pixmap_info; + backend->get_buffer_from_native_pixmap = __tpl_tbm_display_get_buffer_from_native_pixmap; } void @@ -372,10 +355,10 @@ __tpl_surface_init_backend_tbm(tpl_surface_backend_t *backend) backend->type = TPL_BACKEND_TBM; backend->data = NULL; - backend->init = __tpl_tbm_surface_init; - backend->fini = __tpl_tbm_surface_fini; - backend->validate = __tpl_tbm_surface_validate; - backend->dequeue_buffer = __tpl_tbm_surface_dequeue_buffer; + backend->init = __tpl_tbm_surface_init; + backend->fini = __tpl_tbm_surface_fini; + backend->validate = __tpl_tbm_surface_validate; + backend->dequeue_buffer = __tpl_tbm_surface_dequeue_buffer; backend->enqueue_buffer = __tpl_tbm_surface_enqueue_buffer; } diff --git a/src/tpl_utils.h b/src/tpl_utils.h index 98aae4d..d5e5557 100644 --- a/src/tpl_utils.h +++ b/src/tpl_utils.h @@ -11,12 +11,12 @@ #else # define TPL_API #endif -#define TPL_ASSERT(expr) assert(expr) -#define TPL_INLINE __inline__ -#define TPL_IGNORE(x) (void)x +#define TPL_ASSERT(expr) assert(expr) +#define TPL_INLINE __inline__ +#define TPL_IGNORE(x) (void)x #ifdef ARM_ATOMIC_OPERATION -#define TPL_DMB() __asm__ volatile("dmb sy" : : : "memory") +#define TPL_DMB() __asm__ volatile("dmb sy" : : : "memory") #else #define TPL_DMB() #endif @@ -245,269 +245,90 @@ extern unsigned int tpl_dump_lvl; } \ } -static int -secUtilDumpBmp (const char * file, const void * data, int width, int height) -{ - int i; - - struct - { - unsigned char magic[2]; - } bmpfile_magic = { {'B', 'M'} }; - - struct - { - unsigned int filesz; - unsigned short creator1; - unsigned short creator2; - unsigned int bmp_offset; - } bmpfile_header = { 0, 0, 0, 0x36 }; - - struct - { - unsigned int header_sz; - unsigned int width; - unsigned int height; - unsigned short nplanes; - unsigned short bitspp; - unsigned int compress_type; - unsigned int bmp_bytesz; - unsigned int hres; - unsigned int vres; - unsigned int ncolors; - unsigned int nimpcolors; - } bmp_dib_v3_header_t = { 0x28, 0, 0, 1, 24, 0, 0, 0, 0, 0, 0 }; - unsigned int * blocks; - - if ( data == NULL ) - return -1; - - if ( width <= 0 || height <= 0) - return -1; - - FILE * fp = NULL; - if ((fp = fopen (file, "wb")) == NULL) - { - printf("FILE ERROR:%s\t",strerror(errno)); - - return -2; - } - else - { - bmpfile_header.filesz = sizeof (bmpfile_magic) + sizeof (bmpfile_header) + - sizeof (bmp_dib_v3_header_t) + width * height * 3; - bmp_dib_v3_header_t.header_sz = sizeof (bmp_dib_v3_header_t); - bmp_dib_v3_header_t.width = width; - bmp_dib_v3_header_t.height = -height; - bmp_dib_v3_header_t.nplanes = 1; - bmp_dib_v3_header_t.bmp_bytesz = width * height * 3; - - if ( fwrite (&bmpfile_magic, sizeof (bmpfile_magic), 1, fp) < 0 ) - { - fclose (fp); - return -1; - } - if ( fwrite (&bmpfile_header, sizeof (bmpfile_header), 1, fp) < 0) - { - fclose (fp); - return -1; - } - if ( fwrite (&bmp_dib_v3_header_t, sizeof (bmp_dib_v3_header_t), 1, fp) < 0) - { - fclose (fp); - return -1; - } - - blocks = (unsigned int*)data; - for (i=0; i 0, -1); - TPL_CHECK_ON_FALSE_RETURN_VAL(height > 0, -1); - FILE *fp = fopen(file, "wb"); - int res = -2; - - if (fp) - { - res = -1; - png_structp pPngStruct = - png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (pPngStruct) - { - png_infop pPngInfo = png_create_info_struct(pPngStruct); - - if (pPngInfo) - { - png_init_io(pPngStruct, fp); - png_set_IHDR(pPngStruct, - pPngInfo, - width, - height, - PNG_DEPTH, - PNG_COLOR_TYPE_RGBA, - PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, - PNG_FILTER_TYPE_DEFAULT); - - png_set_bgr(pPngStruct); - png_write_info(pPngStruct, pPngInfo); - - const int pixel_size = 4; // RGBA - png_bytep *row_pointers = - png_malloc(pPngStruct, height * sizeof(png_byte *)); - if (!row_pointers) - { - fclose(fp); - return res; - } - unsigned int *blocks = (unsigned int *) data; - int y = 0; - int x = 0; +typedef struct _tpl_list_node tpl_list_node_t; +typedef struct _tpl_list tpl_list_t; +typedef struct tpl_util_map_entry tpl_util_map_entry_t; +typedef struct tpl_util_map tpl_util_map_t; +typedef union tpl_util_key tpl_util_key_t; - for (; y < height; ++y) - { - png_bytep row = png_malloc(pPngStruct, - sizeof(png_byte) * width * - pixel_size); - if (!row) - { - fclose(fp); - return res; - } +typedef int (*tpl_util_hash_func_t)(const tpl_util_key_t key, int key_length); +typedef int (*tpl_util_key_length_func_t)(const tpl_util_key_t key); +typedef int (*tpl_util_key_compare_func_t)(const tpl_util_key_t key0, + int key0_length, + const tpl_util_key_t key1, + int key1_length); - row_pointers[y] = (png_bytep) row; +enum _tpl_occurrence { + TPL_FIRST, + TPL_LAST, + TPL_ALL +}; - for (x = 0; x < width; ++x) - { - unsigned int curBlock = blocks[y * width + x]; +union tpl_util_key { + uint32_t key32; + uint64_t key64; + void *ptr; /*pointer key or user defined key(string)*/ +}; - row[x * pixel_size] = (curBlock & 0xFF); - row[1 + x * pixel_size] = (curBlock >> 8) & 0xFF; - row[2 + x * pixel_size] = (curBlock >> 16) & 0xFF; - row[3 + x * pixel_size] = (curBlock >> 24) & 0xFF; - } - } +struct _tpl_list_node { + tpl_list_node_t *prev; + tpl_list_node_t *next; + void *data; + tpl_list_t *list; +}; - png_write_image(pPngStruct, row_pointers); - png_write_end(pPngStruct, pPngInfo); +struct _tpl_list { + tpl_list_node_t head; + tpl_list_node_t tail; + int count; +}; - for (y = 0; y < height; y++) { - png_free(pPngStruct, row_pointers[y]); - } - png_free(pPngStruct, row_pointers); +struct tpl_util_map { + tpl_util_hash_func_t hash_func; + tpl_util_key_length_func_t key_length_func; + tpl_util_key_compare_func_t key_compare_func; + int bucket_bits; + int bucket_size; + int bucket_mask; + tpl_util_map_entry_t **buckets; +}; - png_destroy_write_struct(&pPngStruct, &pPngInfo); +void tpl_util_map_init(tpl_util_map_t *map, int bucket_bits, + tpl_util_hash_func_t hash_func, + tpl_util_key_length_func_t key_length_func, + tpl_util_key_compare_func_t key_compare_func, + void *buckets); - res = 0; - } - } - fclose(fp); - } +void tpl_util_map_int32_init(tpl_util_map_t *map, int bucket_bits, void *buckets); - return res; -} -#endif +void tpl_util_map_int64_init(tpl_util_map_t *map, int bucket_bits, void *buckets); -static inline void -__tpl_util_image_dump(const char * func, const void * data, int type, int width, int height, int num) -{ - char name[200]; - char path_name[20] = "/tmp/tpl_dump"; +void tpl_util_map_pointer_init(tpl_util_map_t *map, int bucket_bits, void *buckets); - if(mkdir (path_name, 0755) == -1) - { - if (errno != EEXIST) - { - TPL_LOG(3,"Directory creation error!"); - return; - } - } +void tpl_util_map_fini(tpl_util_map_t *map); - if (type == 1) - { - snprintf(name, sizeof(name),"%s/[%d][%s][%d][%d][%04d].bmp", path_name, getpid(), func, width, height, num); +tpl_util_map_t * +tpl_util_map_create(int bucket_bits, tpl_util_hash_func_t hash_func, + tpl_util_key_length_func_t key_length_func, + tpl_util_key_compare_func_t key_compare_func); - /*snprintf(name, sizeof(name), "[%d][%04d]", getpid(), num);*/ - switch(secUtilDumpBmp(name, data, width, height)) - { - case 0: - TPL_LOG(6,"%s file is dumped\n", name); - break; - case -1: - TPL_LOG(6, "Dump failed..internal error (data = %p)(width = %d)(height = %d)\n", data, width, height); - break; - case -2: - TPL_LOG(6, "Dump failed..file pointer error\n"); - break; - } - } -#ifdef PNG_DUMP_ENABLE - else - { - snprintf(name, sizeof(name),"%s/[%d][%s][%d][%d][%04d].png", path_name, getpid(), func, width, height, num); +tpl_util_map_t *tpl_util_map_int32_create(int bucket_bits); - /*snprintf(name, sizeof(name), "[%d][%04d]", getpid(), num);*/ - switch(secUtilDumpPng(name, data, width, height)) - { - case 0: - TPL_LOG(6,"%s file is dumped\n", name); - break; - case -1: - TPL_LOG(6, "Dump failed..internal error (data = %p)(width = %d)(height = %d)\n", data, width, height); - break; - case -2: - TPL_LOG(6, "Dump failed..file pointer error\n"); - break; - } - } -#endif -} +tpl_util_map_t *tpl_util_map_int64_create(int bucket_bits); +tpl_util_map_t *tpl_util_map_pointer_create(int bucket_bits); -typedef struct _tpl_list_node tpl_list_node_t; -typedef struct _tpl_list tpl_list_t; +void tpl_util_map_destroy(tpl_util_map_t *map); -enum _tpl_occurrence -{ - TPL_FIRST, - TPL_LAST, - TPL_ALL -}; +void tpl_util_map_clear(tpl_util_map_t *map); -struct _tpl_list_node -{ - tpl_list_node_t *prev; - tpl_list_node_t *next; - void *data; - tpl_list_t *list; -}; +void *tpl_util_map_get(tpl_util_map_t *map, const tpl_util_key_t key); -struct _tpl_list -{ - tpl_list_node_t head; - tpl_list_node_t tail; - int count; -}; +void +tpl_util_map_set(tpl_util_map_t *map, const tpl_util_key_t key, void *data, + tpl_free_func_t free_func); static TPL_INLINE int __tpl_list_get_count(const tpl_list_t *list) @@ -550,15 +371,13 @@ __tpl_list_fini(tpl_list_t *list, tpl_free_func_t func) node = list->head.next; - while (node != &list->tail) - { + while (node != &list->tail) { tpl_list_node_t *free_node = node; node = node->next; TPL_ASSERT(free_node); - if (func) - func(free_node->data); + if (func) func(free_node->data); free(free_node); } @@ -572,8 +391,7 @@ __tpl_list_alloc() tpl_list_t *list; list = (tpl_list_t *) malloc(sizeof(tpl_list_t)); - if (NULL == list) - return NULL; + if (!list) return NULL; __tpl_list_init(list); @@ -602,8 +420,7 @@ __tpl_list_get_front_node(tpl_list_t *list) { TPL_ASSERT(list); - if (__tpl_list_is_empty(list)) - return NULL; + if (__tpl_list_is_empty(list)) return NULL; return list->head.next; } @@ -613,8 +430,7 @@ __tpl_list_get_back_node(tpl_list_t *list) { TPL_ASSERT(list); - if (__tpl_list_is_empty(list)) - return NULL; + if (__tpl_list_is_empty(list)) return NULL; return list->tail.prev; } @@ -661,8 +477,7 @@ __tpl_list_get_back(const tpl_list_t *list) { TPL_ASSERT(list); - if (__tpl_list_is_empty(list)) - return NULL; + if (__tpl_list_is_empty(list)) return NULL; TPL_ASSERT(list->tail.prev); @@ -679,8 +494,7 @@ __tpl_list_remove(tpl_list_node_t *node, tpl_free_func_t func) node->prev->next = node->next; node->next->prev = node->prev; - if (func) - func(node->data); + if (func) func(node->data); node->list->count--; free(node); @@ -690,8 +504,7 @@ static TPL_INLINE tpl_result_t __tpl_list_insert(tpl_list_node_t *pos, void *data) { tpl_list_node_t *node = (tpl_list_node_t *)malloc(sizeof(tpl_list_node_t)); - if (NULL == node) - { + if (!node) { TPL_ERR("Failed to allocate new tpl_list_node_t."); return TPL_ERROR_INVALID_OPERATION; } @@ -711,42 +524,36 @@ __tpl_list_insert(tpl_list_node_t *pos, void *data) } static TPL_INLINE void -__tpl_list_remove_data(tpl_list_t *list, void *data, int occurrence, tpl_free_func_t func) +__tpl_list_remove_data(tpl_list_t *list, void *data, int occurrence, + tpl_free_func_t func) { tpl_list_node_t *node; TPL_ASSERT(list); - if (occurrence == TPL_FIRST) - { - node = list->head.next; + if (occurrence == TPL_FIRST) { + node = list->head.next; - while (node != &list->tail) - { - tpl_list_node_t *curr; + while (node != &list->tail) { + tpl_list_node_t *curr; - curr = node; - node = node->next; + curr = node; + node = node->next; - TPL_ASSERT(curr); - TPL_ASSERT(node); + TPL_ASSERT(curr); + TPL_ASSERT(node); - if (curr->data == data) - { - if (func) - func(data); + if (curr->data == data) { + if (func) func(data); - __tpl_list_remove(curr, func); - return; - } - } - } - else if (occurrence == TPL_LAST) - { + __tpl_list_remove(curr, func); + return; + } + } + } else if (occurrence == TPL_LAST) { node = list->tail.prev; - while (node != &list->head) - { + while (node != &list->head) { tpl_list_node_t *curr; curr = node; @@ -755,38 +562,31 @@ __tpl_list_remove_data(tpl_list_t *list, void *data, int occurrence, tpl_free_fu TPL_ASSERT(curr); TPL_ASSERT(node); - if (curr->data == data) - { - if (func) - func(data); + if (curr->data == data) { + if (func) func(data); __tpl_list_remove(curr, func); return; } } - } - else if (occurrence == TPL_ALL) - { - node = list->head.next; + } else if (occurrence == TPL_ALL) { + node = list->head.next; - while (node != &list->tail) - { - tpl_list_node_t *curr; + while (node != &list->tail) { + tpl_list_node_t *curr; - curr = node; - node = node->next; + curr = node; + node = node->next; - TPL_ASSERT(curr); - TPL_ASSERT(node); + TPL_ASSERT(curr); + TPL_ASSERT(node); - if (curr->data == data) - { - if (func) - func(data); + if (curr->data == data) { + if (func) func(data); - __tpl_list_remove(curr, func); - } - } + __tpl_list_remove(curr, func); + } + } } } @@ -813,8 +613,7 @@ __tpl_list_pop_front(tpl_list_t *list, tpl_free_func_t func) TPL_ASSERT(list); - if (__tpl_list_is_empty(list)) - return NULL; + if (__tpl_list_is_empty(list)) return NULL; data = list->head.next->data; __tpl_list_remove(list->head.next, func); @@ -829,8 +628,7 @@ tpl_list_pop_back(tpl_list_t *list, tpl_free_func_t func) TPL_ASSERT(list); - if (__tpl_list_is_empty(list)) - return NULL; + if (__tpl_list_is_empty(list)) return NULL; data = list->tail.prev->data; __tpl_list_remove(list->tail.prev, func); @@ -838,78 +636,221 @@ tpl_list_pop_back(tpl_list_t *list, tpl_free_func_t func) return data; } -typedef struct tpl_util_map_entry tpl_util_map_entry_t; -typedef struct tpl_util_map tpl_util_map_t; -typedef union tpl_util_key tpl_util_key_t; +static TPL_INLINE int +__tpl_util_image_dump_bmp(const char * file, const void * data, int width, + int height) +{ + int i; + + struct { + unsigned char magic[2]; + } bmpfile_magic = { {'B', 'M'} }; + + struct { + unsigned int filesz; + unsigned short creator1; + unsigned short creator2; + unsigned int bmp_offset; + } bmpfile_header = { 0, 0, 0, 0x36 }; + + struct { + unsigned int header_sz; + unsigned int width; + unsigned int height; + unsigned short nplanes; + unsigned short bitspp; + unsigned int compress_type; + unsigned int bmp_bytesz; + unsigned int hres; + unsigned int vres; + unsigned int ncolors; + unsigned int nimpcolors; + } bmp_dib_v3_header_t = { 0x28, 0, 0, 1, 24, 0, 0, 0, 0, 0, 0 }; + unsigned int * blocks; + + if (data == NULL) return -1; + + if (width <= 0 || height <= 0) return -1; + + FILE * fp = NULL; + if ((fp = fopen (file, "wb")) == NULL) { + printf("FILE ERROR:%s\t",strerror(errno)); + return -2; + } else { + bmpfile_header.filesz = sizeof (bmpfile_magic) + sizeof (bmpfile_header) + + sizeof (bmp_dib_v3_header_t) + width * height * 3; + bmp_dib_v3_header_t.header_sz = sizeof (bmp_dib_v3_header_t); + bmp_dib_v3_header_t.width = width; + bmp_dib_v3_header_t.height = -height; + bmp_dib_v3_header_t.nplanes = 1; + bmp_dib_v3_header_t.bmp_bytesz = width * height * 3; + + if (fwrite(&bmpfile_magic, sizeof (bmpfile_magic), 1, fp) < 0) { + fclose (fp); + return -1; + } + if (fwrite(&bmpfile_header, sizeof (bmpfile_header), 1, fp) < 0) { + fclose (fp); + return -1; + } + if (fwrite (&bmp_dib_v3_header_t, sizeof (bmp_dib_v3_header_t), 1, fp) < 0) { + fclose (fp); + return -1; + } -typedef int (*tpl_util_hash_func_t)(const tpl_util_key_t key, int key_length); -typedef int (*tpl_util_key_length_func_t)(const tpl_util_key_t key); -typedef int (*tpl_util_key_compare_func_t)(const tpl_util_key_t key0, int key0_length, - const tpl_util_key_t key1, int key1_length); + blocks = (unsigned int*)data; + for (i=0; i 0, -1); + TPL_CHECK_ON_FALSE_RETURN_VAL(height > 0, -1); -void -tpl_util_map_init(tpl_util_map_t *map, - int bucket_bits, - tpl_util_hash_func_t hash_func, - tpl_util_key_length_func_t key_length_func, - tpl_util_key_compare_func_t key_compare_func, - void *buckets); + FILE *fp = fopen(file, "wb"); + int res = -2; -void -tpl_util_map_int32_init(tpl_util_map_t *map, int bucket_bits, void *buckets); + if (fp) { + res = -1; + png_structp pPngStruct = + png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (pPngStruct) { + png_infop pPngInfo = png_create_info_struct(pPngStruct); -void -tpl_util_map_int64_init(tpl_util_map_t *map, int bucket_bits, void *buckets); + if (pPngInfo) { + png_init_io(pPngStruct, fp); + png_set_IHDR(pPngStruct, + pPngInfo, + width, + height, + PNG_DEPTH, + PNG_COLOR_TYPE_RGBA, + PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_DEFAULT, + PNG_FILTER_TYPE_DEFAULT); -void -tpl_util_map_pointer_init(tpl_util_map_t *map, int bucket_bits, void *buckets); + png_set_bgr(pPngStruct); + png_write_info(pPngStruct, pPngInfo); -void -tpl_util_map_fini(tpl_util_map_t *map); + const int pixel_size = 4; // RGBA + png_bytep *row_pointers = + png_malloc(pPngStruct, height * sizeof(png_byte *)); + if (!row_pointers) { + fclose(fp); + return res; + } -tpl_util_map_t * -tpl_util_map_create(int bucket_bits, - tpl_util_hash_func_t hash_func, - tpl_util_key_length_func_t key_length_func, - tpl_util_key_compare_func_t key_compare_func); + unsigned int *blocks = (unsigned int *) data; + int y = 0; + int x = 0; -tpl_util_map_t * -tpl_util_map_int32_create(int bucket_bits); + for (; y < height; ++y) { + png_bytep row = png_malloc(pPngStruct, + sizeof(png_byte) * width * + pixel_size); + if (!row) { + fclose(fp); + return res; + } -tpl_util_map_t * -tpl_util_map_int64_create(int bucket_bits); + row_pointers[y] = (png_bytep) row; -tpl_util_map_t * -tpl_util_map_pointer_create(int bucket_bits); + for (x = 0; x < width; ++x) { + unsigned int curBlock = blocks[y * width + x]; -void -tpl_util_map_destroy(tpl_util_map_t *map); + row[x * pixel_size] = (curBlock & 0xFF); + row[1 + x * pixel_size] = (curBlock >> 8) & 0xFF; + row[2 + x * pixel_size] = (curBlock >> 16) & 0xFF; + row[3 + x * pixel_size] = (curBlock >> 24) & 0xFF; + } + } -void -tpl_util_map_clear(tpl_util_map_t *map); + png_write_image(pPngStruct, row_pointers); + png_write_end(pPngStruct, pPngInfo); -void * -tpl_util_map_get(tpl_util_map_t *map, const tpl_util_key_t key); + for (y = 0; y < height; y++) { + png_free(pPngStruct, row_pointers[y]); + } + png_free(pPngStruct, row_pointers); -void -tpl_util_map_set(tpl_util_map_t *map, const tpl_util_key_t key, void *data, tpl_free_func_t free_func); + png_destroy_write_struct(&pPngStruct, &pPngInfo); + + res = 0; + } + } + fclose(fp); + } + + return res; +} +#endif + +static TPL_INLINE void +__tpl_util_image_dump(const char * func, const void * data, int type, + int width, int height, int num) +{ + char name[200]; + char path_name[20] = "/tmp/tpl_dump"; + + if (mkdir (path_name, 0755) == -1) { + if (errno != EEXIST) { + TPL_LOG(3,"Directory creation error!"); + return; + } + } + + if (type == 1) { + snprintf(name, sizeof(name),"%s/[%d][%s][%d][%d][%04d].bmp", + path_name, getpid(), func, width, height, num); + + /*snprintf(name, sizeof(name), "[%d][%04d]", getpid(), num);*/ + switch(__tpl_util_image_dump_bmp(name, data, width, height)) { + case 0: + TPL_LOG(6,"%s file is dumped\n", name); + break; + case -1: + TPL_LOG(6, "Dump failed..internal error (data = %p)(width = %d)(height = %d)\n", + data, width, height); + break; + case -2: + TPL_LOG(6, "Dump failed..file pointer error\n"); + break; + } + } +#ifdef PNG_DUMP_ENABLE + else { + snprintf(name, sizeof(name),"%s/[%d][%s][%d][%d][%04d].png", + path_name, getpid(), func, width, height, num); + + /*snprintf(name, sizeof(name), "[%d][%04d]", getpid(), num);*/ + switch(__tpl_util_image_dump_png(name, data, width, height)) { + case 0: + TPL_LOG(6,"%s file is dumped\n", name); + break; + case -1: + TPL_LOG(6, "Dump failed..internal error (data = %p)(width = %d)(height = %d)\n", + data, width, height); + break; + case -2: + TPL_LOG(6, "Dump failed..file pointer error\n"); + break; + } + } +#endif +} #endif /* TPL_UTILS_H */ diff --git a/src/tpl_utils_hlist.c b/src/tpl_utils_hlist.c index d16a881..bc3cfb2 100644 --- a/src/tpl_utils_hlist.c +++ b/src/tpl_utils_hlist.c @@ -2,8 +2,8 @@ #include -#define HASH_HEAD_BITS 8 -#define NUM_OF_HEADS (1 << HASH_HEAD_BITS) +#define HASH_HEAD_BITS 8 +#define NUM_OF_HEADS (1 << HASH_HEAD_BITS) #define CALC_HASH(key) ( (((unsigned int) (key)) * 0x9e406cb5U) >> (32 - (HASH_HEAD_BITS)) ); @@ -11,12 +11,18 @@ typedef struct tpl_hlist_head tpl_hlist_head_t; typedef struct tpl_hlist_node tpl_hlist_node_t; /* Prototypes for internal hash list functions */ -static inline void __tpl_hlist_init_node(tpl_hlist_node_t *n); -static inline int __tpl_hlist_empty(const tpl_hlist_head_t *h); -static inline void __tpl_hlist_del(tpl_hlist_node_t *n); -static inline void __tpl_hlist_add_head(tpl_hlist_node_t *n, tpl_hlist_head_t *h); -static inline void __tpl_hlist_add_before(tpl_hlist_node_t *n, tpl_hlist_node_t *next); -static inline void __tpl_hlist_add_behind(tpl_hlist_node_t *n, tpl_hlist_node_t *prev); +static TPL_INLINE void __tpl_hlist_init_node(tpl_hlist_node_t *n); +static TPL_INLINE int __tpl_hlist_empty(const tpl_hlist_head_t *h); +static TPL_INLINE void __tpl_hlist_del(tpl_hlist_node_t *n); + +static TPL_INLINE void +__tpl_hlist_add_head(tpl_hlist_node_t *n, tpl_hlist_head_t *h); + +static TPL_INLINE void +__tpl_hlist_add_before(tpl_hlist_node_t *n, tpl_hlist_node_t *next); + +static TPL_INLINE void +__tpl_hlist_add_behind(tpl_hlist_node_t *n, tpl_hlist_node_t *prev); tpl_hlist_node_t * __tpl_hlist_get_node(tpl_hlist_t *list, size_t key); tpl_hlist_node_t * __tpl_hlist_get_tail_node(tpl_hlist_t *list, size_t key); @@ -38,45 +44,48 @@ struct tpl_hlist_node { }; /* Definitions for internal hash list functions */ -static inline void __tpl_hlist_init_node(tpl_hlist_node_t *n) +static TPL_INLINE void +__tpl_hlist_init_node(tpl_hlist_node_t *n) { n->next = NULL; n->pprev = NULL; } -static inline int __tpl_hlist_empty(const tpl_hlist_head_t *h) +static TPL_INLINE int +__tpl_hlist_empty(const tpl_hlist_head_t *h) { return !h->first; } -static inline void __tpl_hlist_del(tpl_hlist_node_t *n) +static TPL_INLINE void +__tpl_hlist_del(tpl_hlist_node_t *n) { tpl_hlist_node_t *next = n->next; tpl_hlist_node_t **pprev = n->pprev; *pprev = next; - if (next) - next->pprev = pprev; + if (next) next->pprev = pprev; n->next = NULL; n->pprev = NULL; } -static inline void __tpl_hlist_add_head(tpl_hlist_node_t *n, tpl_hlist_head_t *h) +static TPL_INLINE void +__tpl_hlist_add_head(tpl_hlist_node_t *n, tpl_hlist_head_t *h) { tpl_hlist_node_t *first = h->first; n->next = first; - if (first) - first->pprev = &n->next; + if (first) first->pprev = &n->next; h->first = n; n->pprev = &h->first; } /* next must be != NULL */ -static inline void __tpl_hlist_add_before(tpl_hlist_node_t *n, tpl_hlist_node_t *next) +static TPL_INLINE void +__tpl_hlist_add_before(tpl_hlist_node_t *n, tpl_hlist_node_t *next) { n->pprev = next->pprev; n->next = next; @@ -84,25 +93,25 @@ static inline void __tpl_hlist_add_before(tpl_hlist_node_t *n, tpl_hlist_node_t *(n->pprev) = n; } -static inline void __tpl_hlist_add_behind(tpl_hlist_node_t *n, tpl_hlist_node_t *prev) +static TPL_INLINE void +__tpl_hlist_add_behind(tpl_hlist_node_t *n, tpl_hlist_node_t *prev) { n->next = prev->next; prev->next = n; n->pprev = &prev->next; - if (n->next) - n->next->pprev = &n->next; + if (n->next) n->next->pprev = &n->next; } -tpl_hlist_node_t * __tpl_hlist_get_node(tpl_hlist_t *list, size_t key) +tpl_hlist_node_t * +__tpl_hlist_get_node(tpl_hlist_t *list, size_t key) { tpl_hlist_node_t *pos; size_t hash; hash = CALC_HASH(key); - for (pos = list->heads[hash].first; pos; pos = pos->next) - { + for (pos = list->heads[hash].first; pos; pos = pos->next) { if (pos->key == key) return pos; } @@ -110,15 +119,15 @@ tpl_hlist_node_t * __tpl_hlist_get_node(tpl_hlist_t *list, size_t key) return NULL; } -tpl_hlist_node_t * __tpl_hlist_get_tail_node(tpl_hlist_t *list, size_t key) +tpl_hlist_node_t * +__tpl_hlist_get_tail_node(tpl_hlist_t *list, size_t key) { tpl_hlist_node_t *pos; size_t hash; hash = CALC_HASH(key); - if (__tpl_hlist_empty(&list->heads[hash])) - { + if (__tpl_hlist_empty(&list->heads[hash])) { return NULL; } @@ -129,7 +138,8 @@ tpl_hlist_node_t * __tpl_hlist_get_tail_node(tpl_hlist_t *list, size_t key) } /* Definitions for exposed hash list functions */ -tpl_hlist_t * __tpl_hashlist_create() +tpl_hlist_t * +__tpl_hashlist_create() { tpl_hlist_t *list; @@ -138,8 +148,7 @@ tpl_hlist_t * __tpl_hashlist_create() return NULL; list->heads = (tpl_hlist_head_t *) malloc(sizeof(tpl_hlist_head_t) * NUM_OF_HEADS); - if (list->heads == NULL) - { + if (list->heads == NULL) { free(list); return NULL; } @@ -149,24 +158,22 @@ tpl_hlist_t * __tpl_hashlist_create() return list; } -void __tpl_hashlist_destroy(tpl_hlist_t **list) +void +__tpl_hashlist_destroy(tpl_hlist_t **list) { int i; tpl_hlist_node_t *pos; tpl_hlist_node_t *next; - if (*list == NULL) - return; + if (*list == NULL) return; - for (i = 0; i < NUM_OF_HEADS; i++) - { + for (i = 0; i < NUM_OF_HEADS; i++) { if (__tpl_hlist_empty(&(*list)->heads[i])) continue; pos = (*list)->heads[i].first; - while (pos) - { + while (pos) { next = pos->next; __tpl_hlist_del(pos); @@ -183,27 +190,25 @@ void __tpl_hashlist_destroy(tpl_hlist_t **list) *list = NULL; } -tpl_result_t __tpl_hashlist_insert(tpl_hlist_t *list, size_t key, void *data) +tpl_result_t +__tpl_hashlist_insert(tpl_hlist_t *list, size_t key, void *data) { size_t hash; tpl_hlist_node_t *prev_node; tpl_hlist_node_t *new_node; - if (list == NULL) - return TPL_ERROR_INVALID_PARAMETER; + if (!list) return TPL_ERROR_INVALID_PARAMETER; /* check if key already exists in the list */ prev_node = __tpl_hlist_get_node(list, key); - if (prev_node != NULL) - { + if (prev_node) { TPL_ERR("key(%d) already exists in tpl_hlist_t(%p).", key, list); return TPL_ERROR_INVALID_PARAMETER; } /* create new node and assign given values */ new_node = (tpl_hlist_node_t *) malloc(sizeof(tpl_hlist_node_t)); - if (new_node == NULL) - { + if (!new_node) { TPL_ERR("Failed to allocate new tpl_hlist_node_t."); return TPL_ERROR_INVALID_OPERATION; } @@ -219,42 +224,40 @@ tpl_result_t __tpl_hashlist_insert(tpl_hlist_t *list, size_t key, void *data) return TPL_ERROR_NONE; } -void __tpl_hashlist_delete(tpl_hlist_t *list, size_t key) +void +__tpl_hashlist_delete(tpl_hlist_t *list, size_t key) { tpl_hlist_node_t *node; node = __tpl_hlist_get_node(list, key); - if (node == NULL) - return; + if (!node) return; __tpl_hlist_del(node); free(node); } -void __tpl_hashlist_do_for_all_nodes(tpl_hlist_t *list, void (*cb_func)(void *)) +void +__tpl_hashlist_do_for_all_nodes(tpl_hlist_t *list, void (*cb_func)(void *)) { tpl_hlist_node_t *pos; size_t hidx; - if (cb_func == NULL) - return; + if (!cb_func) return; - for (hidx = 0; hidx < NUM_OF_HEADS; hidx++) - { - for (pos = list->heads[hidx].first; pos; pos = pos->next) - { + for (hidx = 0; hidx < NUM_OF_HEADS; hidx++) { + for (pos = list->heads[hidx].first; pos; pos = pos->next) { cb_func(pos->data); } } } -void * __tpl_hashlist_lookup(tpl_hlist_t *list, size_t key) +void * +__tpl_hashlist_lookup(tpl_hlist_t *list, size_t key) { tpl_hlist_node_t *node; node = __tpl_hlist_get_node(list, key); - if (node == NULL) - return NULL; + if (!node) return NULL; return node->data; } diff --git a/src/tpl_utils_map.c b/src/tpl_utils_map.c index 3b5880c..f838570 100644 --- a/src/tpl_utils_map.c +++ b/src/tpl_utils_map.c @@ -1,21 +1,19 @@ #include "tpl_internal.h" -struct tpl_util_map_entry -{ - tpl_util_key_t key; - void *data; - tpl_free_func_t free_func; - tpl_util_map_entry_t *next; +struct tpl_util_map_entry { + tpl_util_key_t key; + void *data; + tpl_free_func_t free_func; + tpl_util_map_entry_t *next; }; static inline int __get_bucket_index(tpl_util_map_t *map, const tpl_util_key_t key) { - int key_length = 0; - int hash; + int key_length = 0; + int hash; - if (map->key_length_func) - key_length = map->key_length_func(key); + if (map->key_length_func) key_length = map->key_length_func(key); hash = map->hash_func(key, key_length); return hash & map->bucket_mask; @@ -45,7 +43,7 @@ __int64_hash(const tpl_util_key_t key, int key_length) static int __int64_key_compare(const tpl_util_key_t key0, int key0_length, - const tpl_util_key_t key1, int key1_length) + const tpl_util_key_t key1, int key1_length) { return (int)(key0.key64 - key1.key64); } @@ -68,7 +66,7 @@ __int32_hash(const tpl_util_key_t key, int key_length) static int __int32_key_compare(const tpl_util_key_t key0, int key0_length, - const tpl_util_key_t key1, int key1_length) + const tpl_util_key_t key1, int key1_length) { return (int)(key0.key32 - key1.key32); } @@ -107,18 +105,17 @@ __pointer_hash(const tpl_util_key_t key, int key_length) static int __pointer_key_compare(const tpl_util_key_t key0, int key0_length, - const tpl_util_key_t key1, int key1_length) + const tpl_util_key_t key1, int key1_length) { return (int)(key0.ptr - key1.ptr); } void -tpl_util_map_init(tpl_util_map_t *map, - int bucket_bits, - tpl_util_hash_func_t hash_func, - tpl_util_key_length_func_t key_length_func, - tpl_util_key_compare_func_t key_compare_func, - void *buckets) +tpl_util_map_init(tpl_util_map_t *map, int bucket_bits, + tpl_util_hash_func_t hash_func, + tpl_util_key_length_func_t key_length_func, + tpl_util_key_compare_func_t key_compare_func, + void *buckets) { map->hash_func = hash_func; map->key_length_func = key_length_func; @@ -134,19 +131,22 @@ tpl_util_map_init(tpl_util_map_t *map, void tpl_util_map_int32_init(tpl_util_map_t *map, int bucket_bits, void *buckets) { - tpl_util_map_init(map, bucket_bits, __int32_hash, NULL, __int32_key_compare, buckets); + tpl_util_map_init(map, bucket_bits, __int32_hash, NULL, + __int32_key_compare, buckets); } void tpl_util_map_int64_init(tpl_util_map_t *map, int bucket_bits, void *buckets) { - tpl_util_map_init(map, bucket_bits, __int64_hash, NULL, __int64_key_compare, buckets); + tpl_util_map_init(map, bucket_bits, __int64_hash, NULL, + __int64_key_compare, buckets); } void tpl_util_map_pointer_init(tpl_util_map_t *map, int bucket_bits, void *buckets) { - tpl_util_map_init(map, bucket_bits, __pointer_hash, NULL, __pointer_key_compare, buckets); + tpl_util_map_init(map, bucket_bits, __pointer_hash, NULL, + __pointer_key_compare, buckets); } void @@ -156,37 +156,42 @@ tpl_util_map_fini(tpl_util_map_t *map) } tpl_util_map_t * -tpl_util_map_create(int bucket_bits, - tpl_util_hash_func_t hash_func, - tpl_util_key_length_func_t key_length_func, - tpl_util_key_compare_func_t key_compare_func) +tpl_util_map_create(int bucket_bits, tpl_util_hash_func_t hash_func, + tpl_util_key_length_func_t key_length_func, + tpl_util_key_compare_func_t key_compare_func) { - tpl_util_map_t *map; - int bucket_size = 1 << bucket_bits; + tpl_util_map_t *map; + int bucket_size = 1 << bucket_bits; - map = calloc(1, sizeof(tpl_util_map_t) + bucket_size * sizeof(tpl_util_map_entry_t *)); + map = calloc(1, + sizeof(tpl_util_map_t) + bucket_size * sizeof(tpl_util_map_entry_t *)); TPL_CHECK_ON_FALSE_RETURN_VAL(map, NULL); - tpl_util_map_init(map, bucket_bits, hash_func, key_length_func, key_compare_func, map + 1); + tpl_util_map_init(map, bucket_bits, hash_func, key_length_func, + key_compare_func, map + 1); + return map; } tpl_util_map_t * tpl_util_map_int32_create(int bucket_bits) { - return tpl_util_map_create(bucket_bits, __int32_hash, NULL, __int32_key_compare); + return tpl_util_map_create(bucket_bits, __int32_hash, NULL, + __int32_key_compare); } tpl_util_map_t * tpl_util_map_int64_create(int bucket_bits) { - return tpl_util_map_create(bucket_bits, __int64_hash, NULL, __int64_key_compare); + return tpl_util_map_create(bucket_bits, __int64_hash, NULL, + __int64_key_compare); } tpl_util_map_t * tpl_util_map_pointer_create(int bucket_bits) { - return tpl_util_map_create(bucket_bits, __pointer_hash, NULL, __pointer_key_compare); + return tpl_util_map_create(bucket_bits, __pointer_hash, NULL, + __pointer_key_compare); } void @@ -201,19 +206,15 @@ tpl_util_map_clear(tpl_util_map_t *map) { int i; - if (!map->buckets) - return; + if (!map->buckets) return; - for (i = 0; i < map->bucket_size; i++) - { + for (i = 0; i < map->bucket_size; i++) { tpl_util_map_entry_t *curr = map->buckets[i]; - while (curr) - { + while (curr) { tpl_util_map_entry_t *next = curr->next; - if (curr->free_func) - curr->free_func(curr->data); + if (curr->free_func) curr->free_func(curr->data); free(curr); curr = next; @@ -228,13 +229,11 @@ tpl_util_map_get(tpl_util_map_t *map, const tpl_util_key_t key) { tpl_util_map_entry_t *curr = *__get_bucket(map, key); - while (curr) - { + while (curr) { int len0 = 0; int len1 = 0; - if (map->key_length_func) - { + if (map->key_length_func) { len0 = map->key_length_func(curr->key); len1 = map->key_length_func(key); } @@ -249,44 +248,36 @@ tpl_util_map_get(tpl_util_map_t *map, const tpl_util_key_t key) } void -tpl_util_map_set(tpl_util_map_t *map, const tpl_util_key_t key, void *data, tpl_free_func_t free_func) +tpl_util_map_set(tpl_util_map_t *map, const tpl_util_key_t key, void *data, + tpl_free_func_t free_func) { - tpl_util_map_entry_t **bucket = __get_bucket(map, key); - tpl_util_map_entry_t *curr = *bucket; - tpl_util_map_entry_t *prev = NULL; - int key_length = 0; + tpl_util_map_entry_t **bucket = __get_bucket(map, key); + tpl_util_map_entry_t *curr = *bucket; + tpl_util_map_entry_t *prev = NULL; + int key_length = 0; /* Find existing entry for the key. */ - while (curr) - { + while (curr) { int len0 = 0; int len1 = 0; - if (map->key_length_func) - { + if (map->key_length_func) { len0 = map->key_length_func(curr->key); len1 = map->key_length_func(key); } - if (map->key_compare_func(curr->key, len0, key, len1) == 0) - { + if (map->key_compare_func(curr->key, len0, key, len1) == 0) { /* Free previous data. */ - if (curr->free_func) - curr->free_func(curr->data); + if (curr->free_func) curr->free_func(curr->data); - if (data) - { + if (data) { /* Set new data. */ curr->data = data; curr->free_func = free_func; - } - else - { + } else { /* Delete entry. */ - if (prev) - prev->next = curr->next; - else - *bucket = curr->next; + if (prev) prev->next = curr->next; + else *bucket = curr->next; free(curr); } @@ -298,26 +289,21 @@ tpl_util_map_set(tpl_util_map_t *map, const tpl_util_key_t key, void *data, tpl_ curr = curr->next; } - if (data == NULL) - { + if (!data) { /* Nothing to delete. */ return; } /* Allocate a new entry. */ - if (map->key_length_func) - key_length = map->key_length_func(key); + if (map->key_length_func) key_length = map->key_length_func(key); curr = malloc(sizeof(tpl_util_map_entry_t) + key_length); TPL_CHECK_ON_FALSE_RETURN(curr); - if (key_length > 0) - { + if (key_length > 0) { memcpy(curr + 1, key.ptr, key_length); curr->key.ptr = (void *)(curr + 1); - } - else - { + } else { curr->key = key; } diff --git a/src/tpl_wayland.c b/src/tpl_wayland.c index c7b7e57..935ec82 100644 --- a/src/tpl_wayland.c +++ b/src/tpl_wayland.c @@ -23,33 +23,30 @@ #include /* In wayland, application and compositor create its own drawing buffers. Recommend size is more than 2. */ -#define CLIENT_QUEUE_SIZE 3 +#define CLIENT_QUEUE_SIZE 3 -typedef struct _tpl_wayland_display tpl_wayland_display_t; -typedef struct _tpl_wayland_surface tpl_wayland_surface_t; -typedef struct _tpl_wayland_buffer tpl_wayland_buffer_t; +typedef struct _tpl_wayland_display tpl_wayland_display_t; +typedef struct _tpl_wayland_surface tpl_wayland_surface_t; +typedef struct _tpl_wayland_buffer tpl_wayland_buffer_t; -struct _tpl_wayland_display -{ - tbm_bufmgr bufmgr; - struct wayland_tbm_client *wl_tbm_client; - struct wl_event_queue *wl_queue; - struct wl_registry *wl_registry; +struct _tpl_wayland_display { + tbm_bufmgr bufmgr; + struct wayland_tbm_client *wl_tbm_client; + struct wl_event_queue *wl_queue; + struct wl_registry *wl_registry; }; -struct _tpl_wayland_surface -{ - tbm_surface_queue_h tbm_queue; - tbm_surface_h current_buffer; - tpl_bool_t resized; +struct _tpl_wayland_surface { + tbm_surface_queue_h tbm_queue; + tbm_surface_h current_buffer; + tpl_bool_t resized; }; -struct _tpl_wayland_buffer -{ - tpl_display_t *display; - tbm_bo bo; - tpl_wayland_surface_t *wayland_surface; - struct wl_proxy *wl_proxy; +struct _tpl_wayland_buffer { + tpl_display_t *display; + tbm_bo bo; + tpl_wayland_surface_t *wayland_surface; + struct wl_proxy *wl_proxy; }; static const struct wl_registry_listener registry_listener; @@ -63,26 +60,31 @@ static int tpl_wayland_buffer_key; #define KEY_TPL_WAYLAND_BUFFER (unsigned long)(&tpl_wayland_buffer_key) static void __tpl_wayland_buffer_free(tpl_wayland_buffer_t *wayland_buffer); -static inline tpl_wayland_buffer_t * + +static TPL_INLINE tpl_wayland_buffer_t * __tpl_wayland_get_wayland_buffer_from_tbm_surface(tbm_surface_h surface) { - tbm_bo bo; - tpl_wayland_buffer_t *buf=NULL; + tbm_bo bo; + tpl_wayland_buffer_t *buf=NULL; - bo = tbm_surface_internal_get_bo(surface, 0); - tbm_bo_get_user_data(bo, KEY_TPL_WAYLAND_BUFFER, (void **)&buf); + bo = tbm_surface_internal_get_bo(surface, 0); + tbm_bo_get_user_data(bo, KEY_TPL_WAYLAND_BUFFER, (void **)&buf); - return buf; + return buf; } -static inline void -__tpl_wayland_set_wayland_buffer_to_tbm_surface(tbm_surface_h surface, tpl_wayland_buffer_t *buf) +static TPL_INLINE void +__tpl_wayland_set_wayland_buffer_to_tbm_surface(tbm_surface_h surface, + tpl_wayland_buffer_t *buf) { - tbm_bo bo; + tbm_bo bo; + + bo = tbm_surface_internal_get_bo(surface, 0); + + tbm_bo_add_user_data(bo, KEY_TPL_WAYLAND_BUFFER, + (tbm_data_free)__tpl_wayland_buffer_free); - bo = tbm_surface_internal_get_bo(surface, 0); - tbm_bo_add_user_data(bo, KEY_TPL_WAYLAND_BUFFER, (tbm_data_free)__tpl_wayland_buffer_free); - tbm_bo_set_user_data(bo, KEY_TPL_WAYLAND_BUFFER, buf); + tbm_bo_set_user_data(bo, KEY_TPL_WAYLAND_BUFFER, buf); } static TPL_INLINE tpl_bool_t @@ -94,13 +96,12 @@ __tpl_wayland_display_is_wl_display(tpl_handle_t native_dpy) /* MAGIC CHECK: A native display handle is a wl_display if the de-referenced first value is a memory address pointing the structure of wl_display_interface. */ - if ( wl_egl_native_dpy == &wl_display_interface ) - { + if ( wl_egl_native_dpy == &wl_display_interface ) { return TPL_TRUE; } - if(strncmp(wl_egl_native_dpy->name, wl_display_interface.name, strlen(wl_display_interface.name)) == 0) - { + if (strncmp(wl_egl_native_dpy->name, wl_display_interface.name, + strlen(wl_display_interface.name)) == 0) { return TPL_TRUE; } @@ -127,8 +128,7 @@ __tpl_wayland_display_roundtrip(tpl_display_t *display) wl_proxy_set_queue((struct wl_proxy *) callback, wayland_display->wl_queue); - while (ret != -1 && !done) - { + while (ret != -1 && !done) { ret = wl_display_dispatch_queue(wl_dpy, wayland_display->wl_queue); } @@ -143,15 +143,13 @@ __tpl_wayland_display_init(tpl_display_t *display) TPL_ASSERT(display); /* Do not allow default display in wayland. */ - if (display->native_handle == NULL) - { + if (!display->native_handle) { TPL_ERR("Invalid native handle for display."); return TPL_ERROR_INVALID_PARAMETER; } wayland_display = (tpl_wayland_display_t *) calloc(1, sizeof(tpl_wayland_display_t)); - if (wayland_display == NULL) - { + if (!wayland_display) { TPL_ERR("Failed to allocate memory for new tpl_wayland_display_t."); return TPL_ERROR_INVALID_OPERATION; } @@ -159,42 +157,42 @@ __tpl_wayland_display_init(tpl_display_t *display) display->backend.data = wayland_display; display->bufmgr_fd = -1; - if (__tpl_wayland_display_is_wl_display(display->native_handle)) - { - struct wl_display *wl_dpy = (struct wl_display *)display->native_handle; - wayland_display->wl_tbm_client = wayland_tbm_client_init((struct wl_display *) wl_dpy); - if (wayland_display->wl_tbm_client == NULL) - { + if (__tpl_wayland_display_is_wl_display(display->native_handle)) { + struct wl_display *wl_dpy = + (struct wl_display *)display->native_handle; + wayland_display->wl_tbm_client = + wayland_tbm_client_init((struct wl_display *) wl_dpy); + + if (!wayland_display->wl_tbm_client) { TPL_ERR("Wayland TBM initialization failed!"); goto free_wl_display; } wayland_display->wl_queue = wl_display_create_queue(wl_dpy); - if (NULL == wayland_display->wl_queue) - { + if (!wayland_display->wl_queue) { TPL_ERR("Failed to create wl_queue with wl_dpy(%p).", wl_dpy); goto free_wl_display; } wayland_display->wl_registry = wl_display_get_registry(wl_dpy); - if (NULL == wayland_display->wl_registry) - { + if (!wayland_display->wl_registry) { TPL_ERR("Failed to get wl_registry with wl_dpy(%p).", wl_dpy); goto destroy_queue; } - wl_proxy_set_queue((struct wl_proxy *)wayland_display->wl_registry, wayland_display->wl_queue); - } - else + wl_proxy_set_queue((struct wl_proxy *)wayland_display->wl_registry, + wayland_display->wl_queue); + } else { goto free_wl_display; + } return TPL_ERROR_NONE; destroy_queue: wl_event_queue_destroy(wayland_display->wl_queue); + free_wl_display: - if (wayland_display != NULL) - { + if (wayland_display) { free(wayland_display); display->backend.data = NULL; } @@ -209,8 +207,7 @@ __tpl_wayland_display_fini(tpl_display_t *display) TPL_ASSERT(display); wayland_display = (tpl_wayland_display_t *)display->backend.data; - if (wayland_display != NULL) - { + if (wayland_display) { wayland_tbm_client_deinit(wayland_display->wl_tbm_client); free(wayland_display); } @@ -218,28 +215,27 @@ __tpl_wayland_display_fini(tpl_display_t *display) } static tpl_result_t -__tpl_wayland_display_query_config(tpl_display_t *display, tpl_surface_type_t surface_type, - int red_size, int green_size, int blue_size, int alpha_size, - int color_depth, int *native_visual_id, tpl_bool_t *is_slow) +__tpl_wayland_display_query_config(tpl_display_t *display, + tpl_surface_type_t surface_type, + int red_size, int green_size, + int blue_size, int alpha_size, + int color_depth, int *native_visual_id, + tpl_bool_t *is_slow) { TPL_ASSERT(display); - if (surface_type == TPL_SURFACE_TYPE_WINDOW && - red_size == 8 && - green_size == 8 && - blue_size == 8 && - (color_depth == 32 || color_depth == 24)) - { - if (alpha_size == 8) - { - if (native_visual_id != NULL) *native_visual_id = TBM_FORMAT_ARGB8888; - if (is_slow != NULL) *is_slow = TPL_FALSE; + if (surface_type == TPL_SURFACE_TYPE_WINDOW && red_size == 8 && + green_size == 8 && blue_size == 8 && + (color_depth == 32 || color_depth == 24)) { + + if (alpha_size == 8) { + if (native_visual_id) *native_visual_id = TBM_FORMAT_ARGB8888; + if (is_slow) *is_slow = TPL_FALSE; return TPL_ERROR_NONE; } - if (alpha_size == 0) - { - if (native_visual_id != NULL) *native_visual_id = TBM_FORMAT_XRGB8888; - if (is_slow != NULL) *is_slow = TPL_FALSE; + if (alpha_size == 0) { + if (native_visual_id) *native_visual_id = TBM_FORMAT_XRGB8888; + if (is_slow) *is_slow = TPL_FALSE; return TPL_ERROR_NONE; } } @@ -248,7 +244,8 @@ __tpl_wayland_display_query_config(tpl_display_t *display, tpl_surface_type_t su } static tpl_result_t -__tpl_wayland_display_filter_config(tpl_display_t *display, int *visual_id, int alpha_size) +__tpl_wayland_display_filter_config(tpl_display_t *display, int *visual_id, + int alpha_size) { TPL_IGNORE(display); TPL_IGNORE(visual_id); @@ -257,28 +254,25 @@ __tpl_wayland_display_filter_config(tpl_display_t *display, int *visual_id, int } static tpl_result_t -__tpl_wayland_display_get_window_info(tpl_display_t *display, tpl_handle_t window, - int *width, int *height, tbm_format *format, int depth, int a_size) +__tpl_wayland_display_get_window_info(tpl_display_t *display, + tpl_handle_t window, int *width, + int *height, tbm_format *format, + int depth, int a_size) { TPL_ASSERT(display); TPL_ASSERT(window); struct wl_egl_window *wl_egl_window = (struct wl_egl_window *)window; - if (format != NULL) - { + if (format) { /* Wayland-egl window doesn't have native format information. It is fixed from 'EGLconfig' when called eglCreateWindowSurface(). So we use the tpl_surface format instead. */ tpl_surface_t *surface = wl_egl_window->private; - if (surface != NULL) - *format = surface->format; - else - { - if (a_size == 8) - *format = TBM_FORMAT_ARGB8888; - else if (a_size == 0) - *format = TBM_FORMAT_XRGB8888; + if (surface) *format = surface->format; + else { + if (a_size == 8) *format = TBM_FORMAT_ARGB8888; + else if (a_size == 0) *format = TBM_FORMAT_XRGB8888; } } if (width != NULL) *width = wl_egl_window->width; @@ -288,7 +282,8 @@ __tpl_wayland_display_get_window_info(tpl_display_t *display, tpl_handle_t windo } static void -__cb_client_window_resize_callback(struct wl_egl_window* wl_egl_window, void* private); +__cb_client_window_resize_callback(struct wl_egl_window* wl_egl_window, + void* private); static tpl_result_t __tpl_wayland_surface_init(tpl_surface_t *surface) @@ -301,8 +296,7 @@ __tpl_wayland_surface_init(tpl_surface_t *surface) TPL_ASSERT(surface->native_handle); wayland_surface = (tpl_wayland_surface_t *) calloc(1, sizeof(tpl_wayland_surface_t)); - if (NULL == wayland_surface) - { + if (!wayland_surface) { TPL_ERR("Failed to allocate memory for new tpl_wayland_surface_t."); return TPL_ERROR_INVALID_OPERATION; } @@ -312,15 +306,10 @@ __tpl_wayland_surface_init(tpl_surface_t *surface) wayland_surface->resized = TPL_FALSE; wayland_surface->current_buffer = NULL; - wayland_surface->tbm_queue = tbm_surface_queue_create( - CLIENT_QUEUE_SIZE, - wl_egl_window->width, - wl_egl_window->height, - surface->format, - 0); + wayland_surface->tbm_queue = tbm_surface_queue_create(CLIENT_QUEUE_SIZE, + wl_egl_window->width, wl_egl_window->height, surface->format, 0); - if (wayland_surface->tbm_queue == NULL) - { + if (!wayland_surface->tbm_queue) { TPL_ERR("TBM surface queue creation failed!"); free(wayland_surface); return TPL_ERROR_INVALID_OPERATION; @@ -332,7 +321,8 @@ __tpl_wayland_surface_init(tpl_surface_t *surface) wl_egl_window->private = surface; wl_egl_window->resize_callback = (void*)__cb_client_window_resize_callback; - TPL_LOG(3, "window(%p, %p) %dx%d", surface, surface->native_handle, surface->width, surface->height); + TPL_LOG(3, "window(%p, %p) %dx%d", surface, surface->native_handle, + surface->width, surface->height); return TPL_ERROR_NONE; } @@ -354,8 +344,7 @@ __tpl_wayland_surface_fini(tpl_surface_t *surface) TPL_LOG(3, "window(%p, %p)", surface, surface->native_handle); - if (surface->type == TPL_SURFACE_TYPE_WINDOW) - { + if (surface->type == TPL_SURFACE_TYPE_WINDOW) { struct wl_egl_window *wl_egl_window = (struct wl_egl_window *)surface->native_handle; TPL_ASSERT(wl_egl_window); @@ -365,9 +354,9 @@ __tpl_wayland_surface_fini(tpl_surface_t *surface) /* Detach all pending buffers */ if (wl_egl_window->surface && /* if-statement to be removed once evas/gl patch is in place */ - wl_egl_window->width == wl_egl_window->attached_width && - wl_egl_window->height == wl_egl_window->attached_height) - { + wl_egl_window->width == wl_egl_window->attached_width && + wl_egl_window->height == wl_egl_window->attached_height) { + wl_surface_attach(wl_egl_window->surface, NULL, 0, 0); wl_surface_commit(wl_egl_window->surface); } @@ -387,7 +376,8 @@ __tpl_wayland_surface_fini(tpl_surface_t *surface) } static tpl_result_t -__tpl_wayland_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface, +__tpl_wayland_surface_enqueue_buffer(tpl_surface_t *surface, + tbm_surface_h tbm_surface, int num_rects, const int *rects) { TPL_ASSERT(surface); @@ -396,62 +386,60 @@ __tpl_wayland_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_s TPL_ASSERT(tbm_surface); struct wl_egl_window *wl_egl_window = NULL; - tpl_wayland_display_t *wayland_display = (tpl_wayland_display_t*) surface->display->backend.data; - tpl_wayland_surface_t *wayland_surface = (tpl_wayland_surface_t*) surface->backend.data; + tpl_wayland_display_t *wayland_display = + (tpl_wayland_display_t*) surface->display->backend.data; + tpl_wayland_surface_t *wayland_surface = + (tpl_wayland_surface_t*) surface->backend.data; tpl_wayland_buffer_t *wayland_buffer = NULL; tbm_surface_queue_error_e tsq_err; TPL_LOG(3, "window(%p, %p)", surface, surface->native_handle); - wayland_buffer = __tpl_wayland_get_wayland_buffer_from_tbm_surface(tbm_surface); + wayland_buffer = + __tpl_wayland_get_wayland_buffer_from_tbm_surface(tbm_surface); TPL_ASSERT(wayland_buffer); - tbm_bo_handle bo_handle = tbm_bo_get_handle(wayland_buffer->bo , TBM_DEVICE_CPU); - if (bo_handle.ptr != NULL) - TPL_IMAGE_DUMP(bo_handle.ptr, surface->width, surface->height, surface->dump_count++); + tbm_bo_handle bo_handle = + tbm_bo_get_handle(wayland_buffer->bo , TBM_DEVICE_CPU); + + if (bo_handle.ptr) + TPL_IMAGE_DUMP(bo_handle.ptr, surface->width, surface->height, + surface->dump_count++); wl_egl_window = (struct wl_egl_window *)surface->native_handle; tbm_surface_internal_unref(tbm_surface); tsq_err = tbm_surface_queue_enqueue(wayland_surface->tbm_queue, tbm_surface); - if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) - { + if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) { TPL_ERR("Failed to enqeueue tbm_surface. | tsq_err = %d", tsq_err); return TPL_ERROR_INVALID_OPERATION; } /* deprecated */ - tsq_err = tbm_surface_queue_acquire(wayland_surface->tbm_queue, &tbm_surface); - if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) - { + tsq_err = tbm_surface_queue_acquire(wayland_surface->tbm_queue, &tbm_surface); + if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) { TPL_ERR("Failed to acquire tbm_surface. | tsq_err = %d", tsq_err); return TPL_ERROR_INVALID_OPERATION; } - tbm_surface_internal_ref(tbm_surface); - wl_surface_attach(wl_egl_window->surface, - (void *)wayland_buffer->wl_proxy, - wl_egl_window->dx, - wl_egl_window->dy); + tbm_surface_internal_ref(tbm_surface); + wl_surface_attach(wl_egl_window->surface, (void *)wayland_buffer->wl_proxy, + wl_egl_window->dx, wl_egl_window->dy); wl_egl_window->attached_width = wl_egl_window->width; wl_egl_window->attached_height = wl_egl_window->height; - if (num_rects < 1 || rects == NULL) - { + if (num_rects < 1 || rects == NULL) { wl_surface_damage(wl_egl_window->surface, - wl_egl_window->dx, wl_egl_window->dy, - wl_egl_window->width, wl_egl_window->height); + wl_egl_window->dx, wl_egl_window->dy, + wl_egl_window->width, wl_egl_window->height); } else { - int i; - for (i = 0; i < num_rects; i++) - { + int i; + for (i = 0; i < num_rects; i++) { wl_surface_damage(wl_egl_window->surface, - rects[i * 4 + 0], - rects[i * 4 + 1], - rects[i * 4 + 2], - rects[i * 4 + 3]); + rects[i * 4 + 0], rects[i * 4 + 1], + rects[i * 4 + 2], rects[i * 4 + 3]); } } @@ -461,7 +449,8 @@ __tpl_wayland_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_s struct wl_callback *frame_callback = NULL; frame_callback = wl_surface_frame(wl_egl_window->surface); wl_callback_add_listener(frame_callback, &frame_listener, tbm_surface); - wl_proxy_set_queue((struct wl_proxy *)frame_callback, wayland_display->wl_queue); + wl_proxy_set_queue((struct wl_proxy *)frame_callback, + wayland_display->wl_queue); } wl_surface_commit(wl_egl_window->surface); @@ -476,10 +465,10 @@ __tpl_wayland_surface_validate(tpl_surface_t *surface) TPL_ASSERT(surface); TPL_ASSERT(surface->backend.data); - tpl_wayland_surface_t *wayland_surface = (tpl_wayland_surface_t*)surface->backend.data; + tpl_wayland_surface_t *wayland_surface = + (tpl_wayland_surface_t*)surface->backend.data; - if (wayland_surface->resized) - return TPL_FALSE; + if (wayland_surface->resized) return TPL_FALSE; return TPL_TRUE; } @@ -491,21 +480,23 @@ __tpl_wayland_surface_dequeue_buffer(tpl_surface_t *surface) TPL_ASSERT(surface->backend.data); TPL_ASSERT(surface->display); - tbm_surface_h tbm_surface = NULL; - tpl_wayland_buffer_t *wayland_buffer = NULL; - tpl_wayland_surface_t *wayland_surface = (tpl_wayland_surface_t*)surface->backend.data; - tpl_wayland_display_t *wayland_display = (tpl_wayland_display_t*)surface->display->backend.data; - struct wl_proxy *wl_proxy = NULL; + tbm_surface_h tbm_surface = NULL; + tpl_wayland_buffer_t *wayland_buffer = NULL; + tpl_wayland_surface_t *wayland_surface = + (tpl_wayland_surface_t*)surface->backend.data; + tpl_wayland_display_t *wayland_display = + (tpl_wayland_display_t*)surface->display->backend.data; + struct wl_proxy *wl_proxy = NULL; tbm_surface_queue_error_e tsq_err = 0; if (wayland_surface->resized == TPL_TRUE) wayland_surface->resized = TPL_FALSE; TPL_OBJECT_UNLOCK(surface); - while(tbm_surface_queue_can_dequeue(wayland_surface->tbm_queue, 0) == 0) - { + while(tbm_surface_queue_can_dequeue( + wayland_surface->tbm_queue, 0) == 0) { /* Application sent all buffers to the server. Wait for server response. */ - if (wl_display_dispatch_queue(surface->display->native_handle, wayland_display->wl_queue) == -1) - { + if (wl_display_dispatch_queue(surface->display->native_handle, + wayland_display->wl_queue) == -1) { TPL_OBJECT_LOCK(surface); return NULL; } @@ -513,32 +504,28 @@ __tpl_wayland_surface_dequeue_buffer(tpl_surface_t *surface) TPL_OBJECT_LOCK(surface); tsq_err = tbm_surface_queue_dequeue(wayland_surface->tbm_queue, &tbm_surface); - if (tbm_surface == NULL) - { + if (!tbm_surface) { TPL_ERR("Failed to get tbm_surface from tbm_surface_queue | tsq_err = %d",tsq_err); return NULL; } tbm_surface_internal_ref(tbm_surface); - if ((wayland_buffer = __tpl_wayland_get_wayland_buffer_from_tbm_surface(tbm_surface)) != NULL) - { + if ((wayland_buffer = + __tpl_wayland_get_wayland_buffer_from_tbm_surface(tbm_surface)) != NULL) { return tbm_surface; } wayland_buffer = (tpl_wayland_buffer_t *) calloc(1, sizeof(tpl_wayland_buffer_t)); - if (wayland_buffer == NULL) - { + if (!wayland_buffer) { TPL_ERR("Mem alloc for wayland_buffer failed!"); tbm_surface_internal_unref(tbm_surface); return NULL; } wl_proxy = (struct wl_proxy *)wayland_tbm_client_create_buffer( - wayland_display->wl_tbm_client, - tbm_surface); - if (wl_proxy == NULL) - { + wayland_display->wl_tbm_client, tbm_surface); + if (!wl_proxy) { TPL_ERR("Failed to create TBM client buffer!"); tbm_surface_internal_unref(tbm_surface); free(wayland_buffer); @@ -546,7 +533,8 @@ __tpl_wayland_surface_dequeue_buffer(tpl_surface_t *surface) } wl_proxy_set_queue(wl_proxy, wayland_display->wl_queue); - wl_buffer_add_listener((void *)wl_proxy, &buffer_release_listener, tbm_surface); + wl_buffer_add_listener((void *)wl_proxy, &buffer_release_listener, + tbm_surface); wl_display_flush((struct wl_display *)surface->display->native_handle); @@ -572,8 +560,9 @@ __tpl_wayland_buffer_free(tpl_wayland_buffer_t *wayland_buffer) wl_display_flush((struct wl_display *)wayland_buffer->display->native_handle); - if (wayland_buffer->wl_proxy != NULL) - wayland_tbm_client_destroy_buffer(wayland_display->wl_tbm_client, (void *)wayland_buffer->wl_proxy); + if (wayland_buffer->wl_proxy) + wayland_tbm_client_destroy_buffer(wayland_display->wl_tbm_client, + (void *)wayland_buffer->wl_proxy); free(wayland_buffer); } @@ -581,8 +570,7 @@ __tpl_wayland_buffer_free(tpl_wayland_buffer_t *wayland_buffer) tpl_bool_t __tpl_display_choose_backend_wayland(tpl_handle_t native_dpy) { - if (native_dpy == NULL) - return TPL_FALSE; + if (!native_dpy) return TPL_FALSE; if (__tpl_wayland_display_is_wl_display(native_dpy)) return TPL_TRUE; @@ -598,11 +586,11 @@ __tpl_display_init_backend_wayland(tpl_display_backend_t *backend) backend->type = TPL_BACKEND_WAYLAND; backend->data = NULL; - backend->init = __tpl_wayland_display_init; - backend->fini = __tpl_wayland_display_fini; - backend->query_config = __tpl_wayland_display_query_config; - backend->filter_config = __tpl_wayland_display_filter_config; - backend->get_window_info = __tpl_wayland_display_get_window_info; + backend->init = __tpl_wayland_display_init; + backend->fini = __tpl_wayland_display_fini; + backend->query_config = __tpl_wayland_display_query_config; + backend->filter_config = __tpl_wayland_display_filter_config; + backend->get_window_info = __tpl_wayland_display_get_window_info; } void @@ -613,10 +601,10 @@ __tpl_surface_init_backend_wayland(tpl_surface_backend_t *backend) backend->type = TPL_BACKEND_WAYLAND; backend->data = NULL; - backend->init = __tpl_wayland_surface_init; - backend->fini = __tpl_wayland_surface_fini; - backend->validate = __tpl_wayland_surface_validate; - backend->dequeue_buffer = __tpl_wayland_surface_dequeue_buffer; + backend->init = __tpl_wayland_surface_init; + backend->fini = __tpl_wayland_surface_fini; + backend->validate = __tpl_wayland_surface_validate; + backend->dequeue_buffer = __tpl_wayland_surface_dequeue_buffer; backend->enqueue_buffer = __tpl_wayland_surface_enqueue_buffer; } @@ -666,10 +654,10 @@ __cb_client_buffer_release_callback(void *data, struct wl_proxy *proxy) tbm_surface = (tbm_surface_h) data; - wayland_buffer = __tpl_wayland_get_wayland_buffer_from_tbm_surface(tbm_surface); + wayland_buffer = + __tpl_wayland_get_wayland_buffer_from_tbm_surface(tbm_surface); - if (wayland_buffer != NULL) - { + if (wayland_buffer) { wayland_surface = wayland_buffer->wayland_surface; tbm_surface_internal_unref(tbm_surface); @@ -694,16 +682,16 @@ __cb_client_window_resize_callback(struct wl_egl_window* wl_egl_window, void* pr wayland_surface->resized = TPL_TRUE; - width = wl_egl_window->width; - height = wl_egl_window->height; - format = tbm_surface_queue_get_format(wayland_surface->tbm_queue); + width = wl_egl_window->width; + height = wl_egl_window->height; + format = tbm_surface_queue_get_format(wayland_surface->tbm_queue); /* Check whether the surface was resized by wayland_egl */ - if (wayland_surface->resized == TPL_TRUE || - width != tbm_surface_queue_get_width(wayland_surface->tbm_queue) || - height != tbm_surface_queue_get_height(wayland_surface->tbm_queue)) - { - if (wayland_surface->current_buffer != NULL) + if ((wayland_surface->resized == TPL_TRUE) + || (width != tbm_surface_queue_get_width(wayland_surface->tbm_queue)) + || (height != tbm_surface_queue_get_height(wayland_surface->tbm_queue))) { + + if (wayland_surface->current_buffer) tbm_surface_internal_unref(wayland_surface->current_buffer); tbm_surface_queue_reset(wayland_surface->tbm_queue, width, height, format); -- 2.7.4