From 3fa5feeb8a1f1ebce6cf57667081f276face1dc7 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Thu, 11 Feb 2016 09:39:33 +0900 Subject: [PATCH 01/16] Delete tpl_format_t and replace with tbm_format. Change-Id: Ia5925408225262af23781e4862a40edac2e38b01 --- src/tpl.c | 4 +-- src/tpl.h | 47 ++------------------------------ src/tpl_gbm.c | 80 ++++++------------------------------------------------ src/tpl_internal.h | 6 ++-- src/tpl_surface.c | 2 +- src/tpl_tbm.c | 23 +++------------- src/tpl_wayland.c | 62 +++--------------------------------------- 7 files changed, 26 insertions(+), 198 deletions(-) diff --git a/src/tpl.c b/src/tpl.c index 903f439..3251324 100644 --- a/src/tpl.c +++ b/src/tpl.c @@ -328,14 +328,14 @@ __tpl_surface_init_backend(tpl_surface_t *surface, tpl_backend_type_t type) tpl_bool_t tpl_get_native_window_info(tpl_display_t *display, tpl_handle_t window, - int *width, int *height, tpl_format_t *format, int depth, int a_size) + int *width, int *height, tbm_format *format, int depth, int a_size) { return display->backend.get_window_info(display, window, width, height, format, depth, a_size); } tpl_bool_t tpl_get_native_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, - int *width, int *height, tpl_format_t *format) + int *width, int *height, tbm_format *format) { return display->backend.get_pixmap_info(display, pixmap, width, height, format); } diff --git a/src/tpl.h b/src/tpl.h index 07047a1..94ce400 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -156,47 +156,6 @@ typedef enum } tpl_surface_type_t; /** - * Format types. - * - * TPL specifies several supportable formats. This can be used to specify the - * format of a new surface. Each format explains its own depth, color sequence - * and color bits. and they are enough attributes to convert to the other - * formats (such as GPU drivers, Windowing systems, Buffer managers). - * - * @see tpl_surface_create() - */ -typedef enum -{ - TPL_FORMAT_INVALID = 0, - TPL_FORMAT_NOT_YET_SPECIFIED = 1, - TPL_FORMAT_BGR565, - TPL_FORMAT_RGB565 = 16 + (0 << 8), - TPL_FORMAT_XBGR8888, - TPL_FORMAT_XRGB8888 = 32 + (0 << 8), - TPL_FORMAT_ABGR8888, - TPL_FORMAT_ARGB8888 = 32 + (1 << 8), - TPL_FORMAT_BGRA8888, - TPL_FORMAT_RGBA8888, - TPL_FORMAT_BGRX8888, - TPL_FORMAT_RGBX8888, - TPL_FORMAT_BGR888, - TPL_FORMAT_RGB888, - TPL_FORMAT_ABGR4444, - TPL_FORMAT_ARGB4444, - TPL_FORMAT_BGRA4444, - TPL_FORMAT_RGBA4444, - TPL_FORMAT_ABGR1555, - TPL_FORMAT_ARGB1555, - TPL_FORMAT_BGRA5551, - TPL_FORMAT_RGBA5551, - TPL_FORMAT_YUV420, - TPL_FORMAT_NV12, - TPL_FORMAT_NV21 -} tpl_format_t; - -#define TPL_FORMAT_GET_DEPTH(format) (int)((format) & 0xFF) - -/** * Lock usage types. * * TPL provides buffer locks which are used for synchronization. This usage @@ -443,7 +402,7 @@ void tpl_display_flush(tpl_display_t *display); tpl_surface_t * tpl_surface_create(tpl_display_t *display, tpl_handle_t handle, tpl_surface_type_t type, - tpl_format_t format); + tbm_format format); /** * Get the TPL display where the given TPL surface was created from. @@ -629,7 +588,7 @@ tpl_bool_t tpl_get_native_window_info(tpl_display_t *display, tpl_handle_t window, int *width, int *height, - tpl_format_t *format, + tbm_format *format, int depth, int a_size); @@ -647,7 +606,7 @@ tpl_bool_t tpl_get_native_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, int *width, int *height, - tpl_format_t *format); + tbm_format *format); void tpl_display_wait_native(tpl_display_t *display); diff --git a/src/tpl_gbm.c b/src/tpl_gbm.c index ef500ee..c9e382b 100644 --- a/src/tpl_gbm.c +++ b/src/tpl_gbm.c @@ -160,8 +160,8 @@ __tpl_gbm_display_query_config(tpl_display_t *display, tpl_surface_type_t surfac if (alpha_size == 8) { if (gbm_device_is_format_supported((struct gbm_device *)display->native_handle, - GBM_FORMAT_ARGB8888, - GBM_BO_USE_RENDERING) == 1) + GBM_FORMAT_ARGB8888, + GBM_BO_USE_RENDERING) == 1) { if (native_visual_id != NULL) *native_visual_id = GBM_FORMAT_ARGB8888; } @@ -174,8 +174,8 @@ __tpl_gbm_display_query_config(tpl_display_t *display, tpl_surface_type_t surfac if (alpha_size == 0) { if (gbm_device_is_format_supported((struct gbm_device *)display->native_handle, - GBM_FORMAT_XRGB8888, - GBM_BO_USE_RENDERING) == 1) + GBM_FORMAT_XRGB8888, + GBM_BO_USE_RENDERING) == 1) { if (native_visual_id != NULL) *native_visual_id = GBM_FORMAT_XRGB8888; } @@ -207,7 +207,7 @@ __tpl_gbm_display_filter_config(tpl_display_t *display, static tpl_bool_t __tpl_gbm_display_get_window_info(tpl_display_t *display, tpl_handle_t window, - int *width, int *height, tpl_format_t *format, int depth, int a_size) + int *width, int *height, tbm_format *format, int depth, int a_size) { TPL_ASSERT(display); TPL_ASSERT(window); @@ -215,26 +215,16 @@ __tpl_gbm_display_get_window_info(tpl_display_t *display, tpl_handle_t 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 (format != NULL) - { - switch (tbm_surface_queue_get_format(surf_queue)) - { - case TBM_FORMAT_ARGB8888: *format = TPL_FORMAT_ARGB8888; break; - case TBM_FORMAT_XRGB8888: *format = TPL_FORMAT_XRGB8888; break; - case TBM_FORMAT_RGB565: *format = TPL_FORMAT_RGB565; break; - default: *format = TPL_FORMAT_INVALID; break; - } - } if (width != NULL) *width = tbm_surface_queue_get_width(surf_queue); if (height != NULL) *height = tbm_surface_queue_get_height(surf_queue); - return TPL_TRUE; + if (format != NULL) *format = tbm_surface_queue_get_format(surf_queue); - return TPL_FALSE; + return TPL_TRUE; } static tpl_bool_t __tpl_gbm_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, - int *width, int *height, tpl_format_t *format) + int *width, int *height, tbm_format *format) { tbm_surface_h tbm_surface = NULL; int tbm_format = -1; @@ -245,19 +235,7 @@ __tpl_gbm_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, if (width) *width = tbm_surface_get_width(tbm_surface); if (height) *height = tbm_surface_get_height(tbm_surface); - if (format) - { - tbm_format = tbm_surface_get_format(tbm_surface); - switch(tbm_format) - { - case TBM_FORMAT_ARGB8888: *format = TPL_FORMAT_ARGB8888; break; - case TBM_FORMAT_XRGB8888: *format = TPL_FORMAT_XRGB8888; break; - case TBM_FORMAT_RGB565: *format = TPL_FORMAT_RGB565; break; - default: - *format = TPL_FORMAT_INVALID; - return TPL_FALSE; - } - } + if (format) *format = tbm_surface_get_format(tbm_surface); return TPL_TRUE; } @@ -361,46 +339,6 @@ __tpl_gbm_surface_validate(tpl_surface_t *surface) return TPL_TRUE; } -static int -__tpl_gbm_get_depth_from_format(tpl_format_t format) -{ - int depth = 0; - - switch(format) - { - case TPL_FORMAT_BGR565: - case TPL_FORMAT_RGB565: - case TPL_FORMAT_ABGR4444: - case TPL_FORMAT_ARGB4444: - case TPL_FORMAT_BGRA4444: - case TPL_FORMAT_RGBA4444: - case TPL_FORMAT_ABGR1555: - case TPL_FORMAT_ARGB1555: - case TPL_FORMAT_BGRA5551: - case TPL_FORMAT_RGBA5551: - depth = 16; - break; - case TPL_FORMAT_ABGR8888: - case TPL_FORMAT_ARGB8888: - case TPL_FORMAT_BGRA8888: - case TPL_FORMAT_RGBA8888: - case TPL_FORMAT_XBGR8888: - case TPL_FORMAT_XRGB8888: - case TPL_FORMAT_BGRX8888: - case TPL_FORMAT_RGBX8888: - depth = 32; - break; - case TPL_FORMAT_BGR888: - case TPL_FORMAT_RGB888: - depth = 24; - break; - default: - depth = 32; - } - - return depth; -} - static tbm_surface_h __tpl_gbm_surface_create_buffer_from_gbm_surface(tpl_surface_t *surface, tpl_bool_t *reset_buffers) { diff --git a/src/tpl_internal.h b/src/tpl_internal.h index fcc4d91..d003048 100644 --- a/src/tpl_internal.h +++ b/src/tpl_internal.h @@ -42,9 +42,9 @@ struct _tpl_display_backend tpl_bool_t (*filter_config)(tpl_display_t *display, int *visual_id, int alpha_bits); tpl_bool_t (*get_window_info)(tpl_display_t *display, tpl_handle_t window, - int *width, int *height, tpl_format_t *format, int depth,int a_size); + int *width, int *height, tbm_format *format, int depth,int a_size); tpl_bool_t (*get_pixmap_info)(tpl_display_t *display, tpl_handle_t pixmap, - int *width, int *height, tpl_format_t *format); + int *width, int *height, tbm_format *format); void (*flush)(tpl_display_t *display); void (*wait_native)(tpl_display_t *display); @@ -100,7 +100,7 @@ struct _tpl_surface tpl_display_t *display; tpl_handle_t native_handle; tpl_surface_type_t type; - tpl_format_t format; + tbm_format format; int width, height; int post_interval; diff --git a/src/tpl_surface.c b/src/tpl_surface.c index 6a2460c..e89e29a 100644 --- a/src/tpl_surface.c +++ b/src/tpl_surface.c @@ -20,7 +20,7 @@ __tpl_surface_free(void *data) } tpl_surface_t * -tpl_surface_create(tpl_display_t *display, tpl_handle_t handle, tpl_surface_type_t type, tpl_format_t format) +tpl_surface_create(tpl_display_t *display, tpl_handle_t handle, tpl_surface_type_t type, tbm_format format) { tpl_surface_t *surface; diff --git a/src/tpl_tbm.c b/src/tpl_tbm.c index 24a15d0..3219cf1 100644 --- a/src/tpl_tbm.c +++ b/src/tpl_tbm.c @@ -22,21 +22,6 @@ struct _tpl_tbm_surface int dummy; }; -static inline tpl_format_t -__tpl_tbm_get_tpl_format(tbm_format format) -{ - tpl_format_t ret; - switch (format) - { - case TBM_FORMAT_ARGB8888: ret = TPL_FORMAT_ARGB8888; break; - case TBM_FORMAT_XRGB8888: ret = TPL_FORMAT_XRGB8888; break; - case TBM_FORMAT_RGB565: ret = TPL_FORMAT_RGB565; break; - default: ret = TPL_FORMAT_INVALID; break; - } - - return ret; -} - static tpl_bool_t __tpl_tbm_display_init(tpl_display_t *display) { @@ -131,7 +116,7 @@ __tpl_tbm_display_filter_config(tpl_display_t *display, static tpl_bool_t __tpl_tbm_display_get_window_info(tpl_display_t *display, tpl_handle_t window, - int *width, int *height, tpl_format_t *format, int depth, int a_size) + int *width, int *height, tbm_format *format, int depth, int a_size) { TPL_ASSERT(display); TPL_ASSERT(window); @@ -143,14 +128,14 @@ __tpl_tbm_display_get_window_info(tpl_display_t *display, tpl_handle_t window, if (height != NULL) *height = tbm_surface_queue_get_height(surf_queue); if (format != NULL) - *format = __tpl_tbm_get_tpl_format(tbm_surface_queue_get_format(surf_queue)); + *format = tbm_surface_queue_get_format(surf_queue); return TPL_TRUE; } static tpl_bool_t __tpl_tbm_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, - int *width, int *height, tpl_format_t *format) + int *width, int *height, tbm_format *format) { tbm_surface_h tbm_surface = NULL; @@ -163,7 +148,7 @@ __tpl_tbm_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, if (height) *height = tbm_surface_get_height(tbm_surface); if (format) - *format = __tpl_tbm_get_tpl_format(tbm_surface_get_format(tbm_surface)); + *format = tbm_surface_get_format(tbm_surface); return TPL_TRUE; } diff --git a/src/tpl_wayland.c b/src/tpl_wayland.c index 15cd708..d3f4bc7 100644 --- a/src/tpl_wayland.c +++ b/src/tpl_wayland.c @@ -246,7 +246,7 @@ __tpl_wayland_display_filter_config(tpl_display_t *display, int *visual_id, int static tpl_bool_t __tpl_wayland_display_get_window_info(tpl_display_t *display, tpl_handle_t window, - int *width, int *height, tpl_format_t *format, int depth, int a_size) + int *width, int *height, tbm_format *format, int depth, int a_size) { TPL_ASSERT(display); TPL_ASSERT(window); @@ -264,9 +264,9 @@ __tpl_wayland_display_get_window_info(tpl_display_t *display, tpl_handle_t windo else { if (a_size == 8) - *format = TPL_FORMAT_ARGB8888; + *format = TBM_FORMAT_ARGB8888; else if (a_size == 0) - *format = TPL_FORMAT_XRGB8888; + *format = TBM_FORMAT_XRGB8888; } } if (width != NULL) *width = wl_egl_window->width; @@ -290,7 +290,6 @@ static tpl_bool_t __tpl_wayland_surface_init(tpl_surface_t *surface) { tpl_wayland_surface_t *wayland_surface = NULL; - int tbm_format; struct wl_egl_window *wl_egl_window = (struct wl_egl_window *)surface->native_handle; @@ -307,24 +306,11 @@ __tpl_wayland_surface_init(tpl_surface_t *surface) wayland_surface->resized = TPL_FALSE; wayland_surface->current_buffer = NULL; - switch (surface->format) - { - case TPL_FORMAT_ARGB8888: tbm_format = TBM_FORMAT_ARGB8888; - break; - case TPL_FORMAT_XRGB8888: tbm_format = TBM_FORMAT_XRGB8888; - break; - case TPL_FORMAT_RGB565: tbm_format = TBM_FORMAT_RGB565; - break; - default: - TPL_ERR("Unsupported format found in surface!"); - return TPL_FALSE; - } - wayland_surface->tbm_queue = tbm_surface_queue_create( CLIENT_QUEUE_SIZE, wl_egl_window->width, wl_egl_window->height, - tbm_format, + surface->format, 0); TPL_LOG(9, "tbm_surface_queue_create!! || wl_egl_window(%p)| tbm_queue(%p)", wl_egl_window, wayland_surface->tbm_queue); @@ -490,46 +476,6 @@ __tpl_wayland_surface_validate(tpl_surface_t *surface) return TPL_TRUE; } -static int -__tpl_wayland_get_depth_from_format(tpl_format_t format) -{ - int depth = 0; - - switch(format) - { - case TPL_FORMAT_BGR565: - case TPL_FORMAT_RGB565: - case TPL_FORMAT_ABGR4444: - case TPL_FORMAT_ARGB4444: - case TPL_FORMAT_BGRA4444: - case TPL_FORMAT_RGBA4444: - case TPL_FORMAT_ABGR1555: - case TPL_FORMAT_ARGB1555: - case TPL_FORMAT_BGRA5551: - case TPL_FORMAT_RGBA5551: - depth = 16; - break; - case TPL_FORMAT_ABGR8888: - case TPL_FORMAT_ARGB8888: - case TPL_FORMAT_BGRA8888: - case TPL_FORMAT_RGBA8888: - case TPL_FORMAT_XBGR8888: - case TPL_FORMAT_XRGB8888: - case TPL_FORMAT_BGRX8888: - case TPL_FORMAT_RGBX8888: - depth = 32; - break; - case TPL_FORMAT_BGR888: - case TPL_FORMAT_RGB888: - depth = 24; - break; - default: - depth = 32; - } - - return depth; -} - static tbm_surface_h __tpl_wayland_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buffers) { -- 2.7.4 From fdd563d27e83dbab61781adabe131107266d4250 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Thu, 11 Feb 2016 13:54:28 +0900 Subject: [PATCH 02/16] Change API names about get_buffer & post. - tpl_surface_get_buffer changed to tpl_surface_dequeue_buffer. - tpl_surface_post changed to tpl_surface_enqueue_buffer. - Fix some build warnings. Change-Id: I9e49ccfa50bd44f7d875d33e9b3b1bb4982d2647 --- src/tpl.h | 57 ++++++++++++++++++------------------------------ src/tpl_gbm.c | 39 ++++++++------------------------- src/tpl_internal.h | 6 ++--- src/tpl_surface.c | 64 +++++++----------------------------------------------- src/tpl_tbm.c | 15 +++++-------- src/tpl_wayland.c | 26 ++++++++++++---------- 6 files changed, 61 insertions(+), 146 deletions(-) diff --git a/src/tpl.h b/src/tpl.h index 94ce400..d130e1e 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -34,13 +34,11 @@ * * while (1) * { - * tpl_surface_begin_frame(sfc); - * buf = tpl_surface_get_buffer(sfc); + * buf = tpl_surface_dequeue_buffer(sfc); * * draw something... * - * tpl_surface_end_frame(sfc); - * tpl_surface_post(sfc); + * tpl_surface_enqueue_buffer(sfc, buf); * } * * In GPU Vendor driver, "draw something..." part is what the GPU frame builder does. @@ -439,7 +437,7 @@ tpl_surface_type_t tpl_surface_get_type(tpl_surface_t *surface); * * Size of a surface might change when a user resizes window or server resizes * it. TPL updates such size information every time when a buffer is queried - * using tpl_surface_get_buffer(). User have to consider that there might be + * using tpl_surface_dequeue_buffer(). User have to consider that there might be * still mismatch between actual surface size and cached one. * * @param surface surface to get size. @@ -455,18 +453,14 @@ tpl_bool_t tpl_surface_get_size(tpl_surface_t *surface, * Validate current frame of the given TPL surface. * * Users should call this function before getting actual final render target - * buffer. Calling tpl_surface_get_buffer() after calling this function might + * buffer. Calling tpl_surface_dequeue_buffer() after calling this function might * give different output with previous one. Buffer returned after calling this - * function is guaranteed to be not changing. This is somewhat wierd but - * necessary to fully utilize CPU/GPU in a parallel way on tizen DRI2 protocol - * implementation (lazy swap). + * function is guaranteed to be not changing. * - * @param surface surface to validate its current frame. - * @return TPL_TRUE if current buffer is changed due to this validation, TPL_FALSE otherwise. + * @param surface surface to validate its current buffer. + * @return TPL_FALSE if current buffer is changed due to this validation, TPL_TRUE otherwise. * - * @see tpl_surface_begin_frame() - * @see tpl_surface_end_frame() - * @see tpl_surface_get_buffer() + * @see tpl_surface_dequeue_buffer() */ tpl_bool_t tpl_surface_validate(tpl_surface_t *surface); @@ -477,41 +471,37 @@ tpl_bool_t tpl_surface_validate(tpl_surface_t *surface); * communication with the server might be required. Returned buffers are used * for render target to draw current frame. * - * Returned buffers are valid until next tpl_surface_get_buffer() returns - * TPL_FALSE on reset_buffers parameter. If TPL_TRUE is returned on - * reset_buffers, all previsouly returned buffers should no longer be used. + * Returned buffers are valid until next tpl_surface_dequeue_buffer(). + * But if tpl_surface_validate() returns TPL_FALSE, previously returned buffers + * should no longer be used. Then, this function will be called again before drawing, + * and returns valid buffer. * * @param surface surface to get buffer for the current frame. - * @param reset_buffers pointer to receive whether previouly returned buffers should be reset or not. * @return buffer for the current frame. * * Calling this function multiple times within a single frame is not guranteed * to return a same buffer. * - * @see tpl_surface_begin_frame() - * @see tpl_surface_end_frame() + * @see tpl_surface_validate() */ -tbm_surface_h tpl_surface_get_buffer(tpl_surface_t *surface, - tpl_bool_t *reset_buffers); +tbm_surface_h tpl_surface_dequeue_buffer(tpl_surface_t *surface); + /** - * Post a frame from the frame queue of the given surface. + * Post a given tbm_surface. * * This function request display server to post a frame. This is the only - * function which can dequeue a frame from the frame queue. + * function which can enqueue a buffer to the tbm_surface_queue. * - * Make sure this function is called exactly once for a frame. Depending on - * backend, other TPL functions might wait for this function to be called. + * Make sure this function is called exactly once for a frame. * Scheduling post calls on a separate thread is recommended. * - * If tpl_surface_end_frame() was not called for the current frame, this - * function might implicitly end the current frame. + * This function might implicitly end the current frame. * * @param surface surface to post a frame. + * @param tbm_surface buffer to post. * - * @see tpl_surface_begin_frame() - * @see tpl_surface_end_frame() */ -tpl_bool_t tpl_surface_post(tpl_surface_t *surface, tbm_surface_h tbm_surface); +tpl_bool_t tpl_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface); /** * Set frame interval of the given TPL surface. @@ -569,11 +559,6 @@ tpl_bool_t tpl_surface_get_damage(tpl_surface_t *surface, int *num_rects, const int **rects); -tpl_bool_t tpl_surface_destroy_cached_buffers(tpl_surface_t *surface); - -tpl_bool_t tpl_surface_update_cached_buffers(tpl_surface_t *surface); - - /** * Query information on the given native window. * diff --git a/src/tpl_gbm.c b/src/tpl_gbm.c index c9e382b..fbcdbdd 100644 --- a/src/tpl_gbm.c +++ b/src/tpl_gbm.c @@ -117,13 +117,6 @@ __tpl_gbm_display_init(tpl_display_t *display) display->bufmgr_fd = -1; return TPL_TRUE; -free_gbm_display: - if (gbm_display != NULL) - { - free(gbm_display); - display->backend.data = NULL; - } - return TPL_FALSE; } static void @@ -227,7 +220,6 @@ __tpl_gbm_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, int *width, int *height, tbm_format *format) { tbm_surface_h tbm_surface = NULL; - int tbm_format = -1; tbm_surface = wayland_tbm_server_get_surface(NULL, (struct wl_resource*)pixmap); if (tbm_surface == NULL) @@ -311,7 +303,7 @@ __tpl_gbm_surface_fini(tpl_surface_t *surface) } static void -__tpl_gbm_surface_post(tpl_surface_t *surface, tbm_surface_h tbm_surface) +__tpl_gbm_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface) { TPL_ASSERT(surface); TPL_ASSERT(surface->display); @@ -340,7 +332,7 @@ __tpl_gbm_surface_validate(tpl_surface_t *surface) } static tbm_surface_h -__tpl_gbm_surface_create_buffer_from_gbm_surface(tpl_surface_t *surface, tpl_bool_t *reset_buffers) +__tpl_gbm_surface_dequeue_buffer_from_gbm_surface(tpl_surface_t *surface) { tbm_bo bo; tbm_surface_h tbm_surface = NULL; @@ -348,7 +340,6 @@ __tpl_gbm_surface_create_buffer_from_gbm_surface(tpl_surface_t *surface, tpl_boo tpl_gbm_buffer_t *gbm_buffer = NULL; tpl_gbm_surface_t *gbm_surface = NULL; - tpl_gbm_display_t *gbm_display = NULL; TPL_ASSERT(surface); TPL_ASSERT(surface->native_handle); @@ -356,7 +347,6 @@ __tpl_gbm_surface_create_buffer_from_gbm_surface(tpl_surface_t *surface, tpl_boo TPL_ASSERT(surface->display->native_handle); gbm_surface = (tpl_gbm_surface_t*)surface->backend.data; - gbm_display = (tpl_gbm_display_t*)surface->display->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) @@ -397,24 +387,16 @@ __tpl_gbm_surface_create_buffer_from_gbm_surface(tpl_surface_t *surface, tpl_boo gbm_surface->current_buffer = tbm_surface; - if (reset_buffers != NULL) - *reset_buffers = TPL_FALSE; - __tpl_gbm_set_gbm_buffer_to_tbm_surface(tbm_surface, gbm_buffer); return tbm_surface; } static tbm_surface_h -__tpl_gbm_surface_create_buffer_from_wl_tbm(tpl_surface_t *surface, tpl_bool_t *reset_buffers) +__tpl_gbm_surface_get_buffer_from_wl_tbm(tpl_surface_t *surface) { - tpl_gbm_buffer_t *gbm_buffer = NULL; tbm_surface_h tbm_surface = NULL; - /* TODO: If HW support getting of gem memory size, - use tbm_surface_get_info() with tbm_surface_info_s */ -#if 0 - tbm_surface_info_s tbm_surf_info; -#endif + TPL_ASSERT(surface); TPL_ASSERT(surface->display); TPL_ASSERT(surface->native_handle); @@ -430,23 +412,20 @@ __tpl_gbm_surface_create_buffer_from_wl_tbm(tpl_surface_t *surface, tpl_bool_t * } static tbm_surface_h -__tpl_gbm_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buffers) +__tpl_gbm_surface_dequeue_buffer(tpl_surface_t *surface) { tbm_surface_h tbm_surface = NULL; TPL_ASSERT(surface); TPL_ASSERT(surface->backend.data); - if (reset_buffers != NULL) - *reset_buffers = TPL_FALSE; - if (surface->type == TPL_SURFACE_TYPE_WINDOW) { - tbm_surface = __tpl_gbm_surface_create_buffer_from_gbm_surface(surface, reset_buffers); + tbm_surface = __tpl_gbm_surface_dequeue_buffer_from_gbm_surface(surface); } if (surface->type == TPL_SURFACE_TYPE_PIXMAP) { - tbm_surface = __tpl_gbm_surface_create_buffer_from_wl_tbm(surface, reset_buffers); + tbm_surface = __tpl_gbm_surface_get_buffer_from_wl_tbm(surface); } TPL_ASSERT(tbm_surface); @@ -504,8 +483,8 @@ __tpl_surface_init_backend_gbm(tpl_surface_backend_t *backend) backend->init = __tpl_gbm_surface_init; backend->fini = __tpl_gbm_surface_fini; backend->validate = __tpl_gbm_surface_validate; - backend->get_buffer = __tpl_gbm_surface_get_buffer; - backend->post = __tpl_gbm_surface_post; + backend->dequeue_buffer = __tpl_gbm_surface_dequeue_buffer; + backend->enqueue_buffer = __tpl_gbm_surface_enqueue_buffer; } #ifdef EGL_BIND_WL_DISPLAY diff --git a/src/tpl_internal.h b/src/tpl_internal.h index d003048..e6797ce 100644 --- a/src/tpl_internal.h +++ b/src/tpl_internal.h @@ -61,10 +61,8 @@ struct _tpl_surface_backend tpl_bool_t (*validate)(tpl_surface_t *surface); - tbm_surface_h (*get_buffer)(tpl_surface_t *surface, tpl_bool_t *reset_buffers); - void (*post)(tpl_surface_t *surface, tbm_surface_h tbm_surface); - tpl_bool_t (*destroy_cached_buffers)(tpl_surface_t *surface); - tpl_bool_t (*update_cached_buffers)(tpl_surface_t *surface); + tbm_surface_h (*dequeue_buffer)(tpl_surface_t *surface); + void (*enqueue_buffer)(tpl_surface_t *surface, tbm_surface_h tbm_surface); }; struct _tpl_object diff --git a/src/tpl_surface.c b/src/tpl_surface.c index e89e29a..983ad73 100644 --- a/src/tpl_surface.c +++ b/src/tpl_surface.c @@ -232,13 +232,13 @@ tpl_surface_get_damage(tpl_surface_t *surface, int *num_rects, const int **rects } tbm_surface_h -tpl_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buffers) +tpl_surface_dequeue_buffer(tpl_surface_t *surface) { TPL_ASSERT(surface); tbm_surface_h tbm_surface = NULL; - if (surface->backend.get_buffer == NULL) + if (surface->backend.dequeue_buffer == NULL) { TPL_ERR("TPL surface has not been initialized correctly!"); return NULL; @@ -247,71 +247,23 @@ tpl_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buffers) TRACE_BEGIN("TPL:GETBUFFER"); TPL_OBJECT_LOCK(surface); - tbm_surface = surface->backend.get_buffer(surface, reset_buffers); + tbm_surface = surface->backend.dequeue_buffer(surface); if(tbm_surface != NULL) { /* Update size of the surface. */ - surface->width = tbm_surface_internal_get_width(tbm_surface); - surface->height = tbm_surface_internal_get_height(tbm_surface); + surface->width = tbm_surface_get_width(tbm_surface); + surface->height = tbm_surface_get_height(tbm_surface); } TPL_OBJECT_UNLOCK(surface); TRACE_END(); - return (void*)tbm_surface; + return tbm_surface; } tpl_bool_t -tpl_surface_destroy_cached_buffers(tpl_surface_t *surface) -{ - tpl_bool_t retval = TPL_FALSE; - - if (NULL == surface) - { - TPL_ERR("Invalid surface!"); - return TPL_FALSE; - } - - if (NULL == surface->backend.destroy_cached_buffers) - { - TPL_ERR("TPL surface has not been initialized correctly!"); - return TPL_FALSE; - } - - TPL_OBJECT_LOCK(surface); - retval = surface->backend.destroy_cached_buffers(surface); - TPL_OBJECT_UNLOCK(surface); - - return retval; -} - -tpl_bool_t -tpl_surface_update_cached_buffers(tpl_surface_t *surface) -{ - tpl_bool_t retval = TPL_FALSE; - - if (NULL == surface) - { - TPL_ERR("Invalid surface!"); - return TPL_FALSE; - } - - if (NULL == surface->backend.destroy_cached_buffers) - { - TPL_ERR("TPL surface has not been initialized correctly!"); - return TPL_FALSE; - } - - TPL_OBJECT_LOCK(surface); - retval = surface->backend.update_cached_buffers(surface); - TPL_OBJECT_UNLOCK(surface); - - return retval; -} - -tpl_bool_t -tpl_surface_post(tpl_surface_t *surface, tbm_surface_h tbm_surface) +tpl_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface) { if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type) @@ -332,7 +284,7 @@ tpl_surface_post(tpl_surface_t *surface, tbm_surface_h tbm_surface) } /* Call backend post if it has not been called for the frame. */ - surface->backend.post(surface, tbm_surface); + surface->backend.enqueue_buffer(surface, tbm_surface); TPL_OBJECT_UNLOCK(surface); TRACE_END(); diff --git a/src/tpl_tbm.c b/src/tpl_tbm.c index 3219cf1..09eb386 100644 --- a/src/tpl_tbm.c +++ b/src/tpl_tbm.c @@ -232,7 +232,7 @@ __tpl_tbm_surface_fini(tpl_surface_t *surface) } static void -__tpl_tbm_surface_post(tpl_surface_t *surface, tbm_surface_h tbm_surface) +__tpl_tbm_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface) { TPL_ASSERT(surface); TPL_ASSERT(surface->display); @@ -267,7 +267,7 @@ __tpl_tbm_surface_validate(tpl_surface_t *surface) } static tbm_surface_h -__tpl_tbm_surface_get_buffer_from_tbm_queue(tpl_surface_t *surface, tpl_bool_t *reset_buffers) +__tpl_tbm_surface_dequeue_buffer_from_tbm_queue(tpl_surface_t *surface) { tbm_surface_h tbm_surface = NULL; tbm_surface_queue_h tbm_queue = NULL; @@ -295,19 +295,16 @@ __tpl_tbm_surface_get_buffer_from_tbm_queue(tpl_surface_t *surface, tpl_bool_t * } static tbm_surface_h -__tpl_tbm_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buffers) +__tpl_tbm_surface_dequeue_buffer(tpl_surface_t *surface) { tbm_surface_h tbm_surface = NULL; TPL_ASSERT(surface); TPL_ASSERT(surface->backend.data); - if (reset_buffers != NULL) - *reset_buffers = TPL_FALSE; - if (surface->type == TPL_SURFACE_TYPE_WINDOW) { - tbm_surface = __tpl_tbm_surface_get_buffer_from_tbm_queue(surface, reset_buffers); + tbm_surface = __tpl_tbm_surface_dequeue_buffer_from_tbm_queue(surface); } if (surface->type == TPL_SURFACE_TYPE_PIXMAP) { @@ -370,7 +367,7 @@ __tpl_surface_init_backend_tbm(tpl_surface_backend_t *backend) backend->init = __tpl_tbm_surface_init; backend->fini = __tpl_tbm_surface_fini; backend->validate = __tpl_tbm_surface_validate; - backend->get_buffer = __tpl_tbm_surface_get_buffer; - backend->post = __tpl_tbm_surface_post; + backend->dequeue_buffer = __tpl_tbm_surface_dequeue_buffer; + backend->enqueue_buffer = __tpl_tbm_surface_enqueue_buffer; } diff --git a/src/tpl_wayland.c b/src/tpl_wayland.c index d3f4bc7..3c04d23 100644 --- a/src/tpl_wayland.c +++ b/src/tpl_wayland.c @@ -81,7 +81,7 @@ __tpl_wayland_set_wayland_buffer_to_tbm_surface(tbm_surface_h surface, tpl_wayla tbm_bo bo; bo = tbm_surface_internal_get_bo(surface, 0); - tbm_bo_add_user_data(bo, KEY_TPL_WAYLAND_BUFFER, __tpl_wayland_buffer_free); + 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); } @@ -391,7 +391,7 @@ __tpl_wayland_surface_fini(tpl_surface_t *surface) } static void -__tpl_wayland_surface_post(tpl_surface_t *surface, tbm_surface_h tbm_surface) +__tpl_wayland_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface) { TPL_ASSERT(surface); TPL_ASSERT(surface->display); @@ -402,7 +402,7 @@ __tpl_wayland_surface_post(tpl_surface_t *surface, tbm_surface_h tbm_surface) 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 tsqe; + tbm_surface_queue_error_e tsq_err; TPL_LOG(3, "window(%p, %p)", surface, surface->native_handle); @@ -417,10 +417,16 @@ __tpl_wayland_surface_post(tpl_surface_t *surface, tbm_surface_h tbm_surface) tbm_surface_internal_unref(tbm_surface); TPL_LOG(9, "tbm_surface(%p) ----------", tbm_surface); - tsqe = tbm_surface_queue_enqueue(wayland_surface->tbm_queue, tbm_surface); - /* deprecated */ - tsqe = tbm_surface_queue_acquire(wayland_surface->tbm_queue, &tbm_surface); + tsq_err = tbm_surface_queue_enqueue(wayland_surface->tbm_queue, tbm_surface); + if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) + TPL_ERR("Failed to enqeueue tbm_surface. | tsq_err = %d", tsq_err); + + /* deprecated */ + 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); + tbm_surface_internal_ref(tbm_surface); TPL_LOG(9, "tbm_surface(%p) ++++++++++",tbm_surface); wl_surface_attach(wl_egl_window->surface, @@ -477,7 +483,7 @@ __tpl_wayland_surface_validate(tpl_surface_t *surface) } static tbm_surface_h -__tpl_wayland_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buffers) +__tpl_wayland_surface_dequeue_buffer(tpl_surface_t *surface) { TPL_ASSERT(surface); TPL_ASSERT(surface->native_handle); @@ -492,8 +498,6 @@ __tpl_wayland_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buffe struct wl_proxy *wl_proxy = NULL; tbm_surface_queue_error_e tsq_err = 0; - if (reset_buffers != NULL) *reset_buffers = TPL_FALSE; - if (wayland_surface->resized == TPL_TRUE) wayland_surface->resized = TPL_FALSE; TPL_OBJECT_UNLOCK(surface); @@ -621,8 +625,8 @@ __tpl_surface_init_backend_wayland(tpl_surface_backend_t *backend) backend->init = __tpl_wayland_surface_init; backend->fini = __tpl_wayland_surface_fini; backend->validate = __tpl_wayland_surface_validate; - backend->get_buffer = __tpl_wayland_surface_get_buffer; - backend->post = __tpl_wayland_surface_post; + backend->dequeue_buffer = __tpl_wayland_surface_dequeue_buffer; + backend->enqueue_buffer = __tpl_wayland_surface_enqueue_buffer; } static void -- 2.7.4 From deb91c00744a0a9ccc3d84b05fbadc9e0c0f9f81 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Fri, 12 Feb 2016 11:05:54 +0900 Subject: [PATCH 03/16] Add API tpl_get_native_buffer. - This API will be called by compositor when it needs native buffer from pixmap. Change-Id: I9ccb3a5aa93dfd79582cf587b8375cca3482b8c8 --- src/tpl.c | 24 +++++++++++++++++++++ src/tpl.h | 11 ++++++++++ src/tpl_gbm.c | 61 +++++++++++++++++------------------------------------- src/tpl_internal.h | 2 ++ src/tpl_tbm.c | 32 ++++++++-------------------- 5 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/tpl.c b/src/tpl.c index 3251324..6920f96 100644 --- a/src/tpl.c +++ b/src/tpl.c @@ -330,6 +330,12 @@ tpl_bool_t tpl_get_native_window_info(tpl_display_t *display, tpl_handle_t window, int *width, int *height, tbm_format *format, int depth, int a_size) { + if (display->backend.get_window_info == NULL) + { + TPL_ERR("Backend for display has not been initialized!"); + return TPL_FALSE; + } + return display->backend.get_window_info(display, window, width, height, format, depth, a_size); } @@ -337,5 +343,23 @@ tpl_bool_t tpl_get_native_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, int *width, int *height, tbm_format *format) { + if (display->backend.get_pixmap_info == NULL) + { + TPL_ERR("Backend for display has not been initialized!"); + return TPL_FALSE; + } + return display->backend.get_pixmap_info(display, pixmap, width, height, format); } + +tbm_surface_h +tpl_get_native_buffer(tpl_display_t *display, tpl_handle_t pixmap) +{ + if (display->backend.get_native_buffer == NULL) + { + TPL_ERR("Backend for display has not been initialized!"); + return NULL; + } + + return display->backend.get_native_buffer(pixmap); +} diff --git a/src/tpl.h b/src/tpl.h index d130e1e..75fcd87 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -593,6 +593,17 @@ tpl_bool_t tpl_get_native_pixmap_info(tpl_display_t *display, int *height, tbm_format *format); +/** + * Get native buffer from the given native pixmap. + * + * @param display display used for query. + * @param pixmap handle of the native pixmap. + * @return tbm_surface_h native buffer. + */ +tbm_surface_h tpl_get_native_buffer(tpl_display_t *display, + tpl_handle_t pixmap); + + void tpl_display_wait_native(tpl_display_t *display); /* Scheduled to deprecated API */ diff --git a/src/tpl_gbm.c b/src/tpl_gbm.c index fbcdbdd..ccc1670 100644 --- a/src/tpl_gbm.c +++ b/src/tpl_gbm.c @@ -232,6 +232,23 @@ __tpl_gbm_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, return TPL_TRUE; } +static tbm_surface_h +__tpl_gbm_display_get_native_buffer(tpl_handle_t pixmap) +{ + tbm_surface_h tbm_surface = NULL; + + TPL_ASSERT(pixmap); + + tbm_surface = wayland_tbm_server_get_surface(NULL, (struct wl_resource*)pixmap); + if (tbm_surface == NULL) + { + TPL_ERR("Failed to get tbm surface from wayland_tbm."); + return NULL; + } + + return tbm_surface; +} + static void __tpl_gbm_display_flush(tpl_display_t *display) { @@ -332,7 +349,7 @@ __tpl_gbm_surface_validate(tpl_surface_t *surface) } static tbm_surface_h -__tpl_gbm_surface_dequeue_buffer_from_gbm_surface(tpl_surface_t *surface) +__tpl_gbm_surface_dequeue_buffer(tpl_surface_t *surface) { tbm_bo bo; tbm_surface_h tbm_surface = NULL; @@ -391,47 +408,6 @@ __tpl_gbm_surface_dequeue_buffer_from_gbm_surface(tpl_surface_t *surface) return tbm_surface; } - -static tbm_surface_h -__tpl_gbm_surface_get_buffer_from_wl_tbm(tpl_surface_t *surface) -{ - tbm_surface_h tbm_surface = NULL; - - TPL_ASSERT(surface); - TPL_ASSERT(surface->display); - TPL_ASSERT(surface->native_handle); - - tbm_surface = wayland_tbm_server_get_surface(NULL, (struct wl_resource*)surface->native_handle); - if (tbm_surface == NULL) - { - TPL_ERR("Failed to get tbm surface!"); - return NULL; - } - - return tbm_surface; -} - -static tbm_surface_h -__tpl_gbm_surface_dequeue_buffer(tpl_surface_t *surface) -{ - tbm_surface_h tbm_surface = NULL; - - TPL_ASSERT(surface); - TPL_ASSERT(surface->backend.data); - - if (surface->type == TPL_SURFACE_TYPE_WINDOW) - { - tbm_surface = __tpl_gbm_surface_dequeue_buffer_from_gbm_surface(surface); - } - if (surface->type == TPL_SURFACE_TYPE_PIXMAP) - { - tbm_surface = __tpl_gbm_surface_get_buffer_from_wl_tbm(surface); - } - - TPL_ASSERT(tbm_surface); - - return tbm_surface; -} static void __tpl_gbm_buffer_free(tpl_gbm_buffer_t *gbm_buffer) { @@ -465,6 +441,7 @@ __tpl_display_init_backend_gbm(tpl_display_backend_t *backend) 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_native_buffer = __tpl_gbm_display_get_native_buffer; backend->flush = __tpl_gbm_display_flush; #ifdef EGL_BIND_WL_DISPLAY backend->bind_client_display_handle = __tpl_gbm_display_bind_client_wayland_display; diff --git a/src/tpl_internal.h b/src/tpl_internal.h index e6797ce..366dc59 100644 --- a/src/tpl_internal.h +++ b/src/tpl_internal.h @@ -46,6 +46,8 @@ struct _tpl_display_backend tpl_bool_t (*get_pixmap_info)(tpl_display_t *display, tpl_handle_t pixmap, int *width, int *height, tbm_format *format); + tbm_surface_h (*get_native_buffer)(tpl_handle_t pixmap); + void (*flush)(tpl_display_t *display); void (*wait_native)(tpl_display_t *display); diff --git a/src/tpl_tbm.c b/src/tpl_tbm.c index 09eb386..f9345dc 100644 --- a/src/tpl_tbm.c +++ b/src/tpl_tbm.c @@ -153,6 +153,13 @@ __tpl_tbm_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, return TPL_TRUE; } +static tbm_surface_h +__tpl_tbm_display_get_native_buffer(tpl_handle_t pixmap) +{ + TPL_ASSERT(pixmap); + return (tbm_surface_h)pixmap; +} + static void __tpl_tbm_display_flush(tpl_display_t *display) { @@ -267,7 +274,7 @@ __tpl_tbm_surface_validate(tpl_surface_t *surface) } static tbm_surface_h -__tpl_tbm_surface_dequeue_buffer_from_tbm_queue(tpl_surface_t *surface) +__tpl_tbm_surface_dequeue_buffer(tpl_surface_t *surface) { tbm_surface_h tbm_surface = NULL; tbm_surface_queue_h tbm_queue = NULL; @@ -291,28 +298,6 @@ __tpl_tbm_surface_dequeue_buffer_from_tbm_queue(tpl_surface_t *surface) } } - return tbm_surface; -} - -static tbm_surface_h -__tpl_tbm_surface_dequeue_buffer(tpl_surface_t *surface) -{ - tbm_surface_h tbm_surface = NULL; - - TPL_ASSERT(surface); - TPL_ASSERT(surface->backend.data); - - if (surface->type == TPL_SURFACE_TYPE_WINDOW) - { - tbm_surface = __tpl_tbm_surface_dequeue_buffer_from_tbm_queue(surface); - } - if (surface->type == TPL_SURFACE_TYPE_PIXMAP) - { - tbm_surface = (tbm_surface_h)surface->native_handle; - } - - TPL_ASSERT(tbm_surface); - /* Inc ref count about tbm_surface */ /* It will be dec when before tbm_surface_queue_enqueue called */ tbm_surface_internal_ref(tbm_surface); @@ -353,6 +338,7 @@ __tpl_display_init_backend_tbm(tpl_display_backend_t *backend) 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_native_buffer = __tpl_tbm_display_get_native_buffer; backend->flush = __tpl_tbm_display_flush; } -- 2.7.4 From 62fb22b5a25a6d71d800d6078ad8c476f407ec2c Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Mon, 15 Feb 2016 10:25:17 +0900 Subject: [PATCH 04/16] Rename some front-end APIs of tpl_display. - tpl_get_native_window_info -> tpl_display_get_native_window_info - tpl_get_native_pixmap_info -> tpl_display_get_native_pixmap_info - tpl_get_native_buffer -> tpl_display_get_buffer_from_native_pixmap Change-Id: I7ec481f4830c54a1aa87873dcf953c89929b2437 --- src/tpl.c | 37 ------------------------------------- src/tpl.h | 28 ++++++++++++++-------------- src/tpl_display.c | 38 ++++++++++++++++++++++++++++++++++++++ src/tpl_gbm.c | 4 ++-- src/tpl_internal.h | 2 +- src/tpl_tbm.c | 4 ++-- 6 files changed, 57 insertions(+), 56 deletions(-) diff --git a/src/tpl.c b/src/tpl.c index 6920f96..2b2feef 100644 --- a/src/tpl.c +++ b/src/tpl.c @@ -326,40 +326,3 @@ __tpl_surface_init_backend(tpl_surface_t *surface, tpl_backend_type_t type) } } -tpl_bool_t -tpl_get_native_window_info(tpl_display_t *display, tpl_handle_t window, - int *width, int *height, tbm_format *format, int depth, int a_size) -{ - if (display->backend.get_window_info == NULL) - { - TPL_ERR("Backend for display has not been initialized!"); - return TPL_FALSE; - } - - return display->backend.get_window_info(display, window, width, height, format, depth, a_size); -} - -tpl_bool_t -tpl_get_native_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, - int *width, int *height, tbm_format *format) -{ - if (display->backend.get_pixmap_info == NULL) - { - TPL_ERR("Backend for display has not been initialized!"); - return TPL_FALSE; - } - - return display->backend.get_pixmap_info(display, pixmap, width, height, format); -} - -tbm_surface_h -tpl_get_native_buffer(tpl_display_t *display, tpl_handle_t pixmap) -{ - if (display->backend.get_native_buffer == NULL) - { - TPL_ERR("Backend for display has not been initialized!"); - return NULL; - } - - return display->backend.get_native_buffer(pixmap); -} diff --git a/src/tpl.h b/src/tpl.h index 75fcd87..6765afc 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -569,13 +569,13 @@ tpl_bool_t tpl_surface_get_damage(tpl_surface_t *surface, * @param format pointer to receive format of the window. * @return TPL_TRUE if the window is valid, TPL_FALSE otherwise. */ -tpl_bool_t tpl_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_bool_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. @@ -587,11 +587,11 @@ tpl_bool_t tpl_get_native_window_info(tpl_display_t *display, * @param format pointer to receive format of the pixmap. * @return TPL_TRUE if the pixmap is valid, TPL_FALSE otherwise. */ -tpl_bool_t tpl_get_native_pixmap_info(tpl_display_t *display, - tpl_handle_t pixmap, - int *width, - int *height, - tbm_format *format); +tpl_bool_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. @@ -600,8 +600,8 @@ tpl_bool_t tpl_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_get_native_buffer(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); void tpl_display_wait_native(tpl_display_t *display); diff --git a/src/tpl_display.c b/src/tpl_display.c index 27ed858..776aa3d 100644 --- a/src/tpl_display.c +++ b/src/tpl_display.c @@ -228,3 +228,41 @@ tpl_display_get_bufmgr_fd(tpl_display_t *display) return display->bufmgr_fd; } + +tpl_bool_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) +{ + if (display->backend.get_window_info == NULL) + { + TPL_ERR("Backend for display has not been initialized!"); + return TPL_FALSE; + } + + return display->backend.get_window_info(display, window, width, height, format, depth, a_size); +} + +tpl_bool_t +tpl_display_get_native_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, + int *width, int *height, tbm_format *format) +{ + if (display->backend.get_pixmap_info == NULL) + { + TPL_ERR("Backend for display has not been initialized!"); + return TPL_FALSE; + } + + return display->backend.get_pixmap_info(display, pixmap, width, height, format); +} + +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) + { + TPL_ERR("Backend for display has not been initialized!"); + return NULL; + } + + return display->backend.get_buffer_from_native_pixmap(pixmap); +} diff --git a/src/tpl_gbm.c b/src/tpl_gbm.c index ccc1670..6266af7 100644 --- a/src/tpl_gbm.c +++ b/src/tpl_gbm.c @@ -233,7 +233,7 @@ __tpl_gbm_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, } static tbm_surface_h -__tpl_gbm_display_get_native_buffer(tpl_handle_t pixmap) +__tpl_gbm_display_get_buffer_from_native_pixmap(tpl_handle_t pixmap) { tbm_surface_h tbm_surface = NULL; @@ -441,7 +441,7 @@ __tpl_display_init_backend_gbm(tpl_display_backend_t *backend) 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_native_buffer = __tpl_gbm_display_get_native_buffer; + backend->get_buffer_from_native_pixmap = __tpl_gbm_display_get_buffer_from_native_pixmap; backend->flush = __tpl_gbm_display_flush; #ifdef EGL_BIND_WL_DISPLAY backend->bind_client_display_handle = __tpl_gbm_display_bind_client_wayland_display; diff --git a/src/tpl_internal.h b/src/tpl_internal.h index 366dc59..a9bbab8 100644 --- a/src/tpl_internal.h +++ b/src/tpl_internal.h @@ -46,7 +46,7 @@ struct _tpl_display_backend tpl_bool_t (*get_pixmap_info)(tpl_display_t *display, tpl_handle_t pixmap, int *width, int *height, tbm_format *format); - tbm_surface_h (*get_native_buffer)(tpl_handle_t pixmap); + tbm_surface_h (*get_buffer_from_native_pixmap)(tpl_handle_t pixmap); void (*flush)(tpl_display_t *display); void (*wait_native)(tpl_display_t *display); diff --git a/src/tpl_tbm.c b/src/tpl_tbm.c index f9345dc..61cdc5b 100644 --- a/src/tpl_tbm.c +++ b/src/tpl_tbm.c @@ -154,7 +154,7 @@ __tpl_tbm_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, } static tbm_surface_h -__tpl_tbm_display_get_native_buffer(tpl_handle_t pixmap) +__tpl_tbm_display_get_buffer_from_native_pixmap(tpl_handle_t pixmap) { TPL_ASSERT(pixmap); return (tbm_surface_h)pixmap; @@ -338,7 +338,7 @@ __tpl_display_init_backend_tbm(tpl_display_backend_t *backend) 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_native_buffer = __tpl_tbm_display_get_native_buffer; + backend->get_buffer_from_native_pixmap = __tpl_tbm_display_get_buffer_from_native_pixmap; backend->flush = __tpl_tbm_display_flush; } -- 2.7.4 From f8f4a0b48f42229c18165b3d6735fc70715887e3 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Mon, 15 Feb 2016 14:16:56 +0900 Subject: [PATCH 05/16] Delete API tpl_display_get_bufmgr_fd. Change-Id: I2617aa29b5d7716723b5f3715076453d6828e7a4 --- src/tpl.h | 15 --------------- src/tpl_display.c | 12 ------------ 2 files changed, 27 deletions(-) diff --git a/src/tpl.h b/src/tpl.h index 6765afc..736821e 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -606,19 +606,4 @@ tbm_surface_h tpl_display_get_buffer_from_native_pixmap(tpl_display_t *display, void tpl_display_wait_native(tpl_display_t *display); -/* Scheduled to deprecated API */ -/** - * Get file descriptor of the buffer manager for the given TPL display. - * - * There might be native buffer manager device (ex. DRM). This function exports - * such native buffer manager for users to be able to access buffers using the - * buffer manager. How returned buffer manager fd is used is fully dependent on - * native platform implementation. - * - * @param display display to get buffer manger fd. - * @return file descriptor handle for the buffer manager. - * @deprecated do not use tpl_display_get_bufmgr_fd(). - */ -int tpl_display_get_bufmgr_fd(tpl_display_t *display); - #endif /* TPL_H */ diff --git a/src/tpl_display.c b/src/tpl_display.c index 776aa3d..6b2c6cd 100644 --- a/src/tpl_display.c +++ b/src/tpl_display.c @@ -217,18 +217,6 @@ tpl_display_wait_native(tpl_display_t *display) display->backend.wait_native(display); } -int -tpl_display_get_bufmgr_fd(tpl_display_t *display) -{ - if(NULL == display || TPL_TRUE != __tpl_object_is_valid(&display->base)) - { - TPL_ERR("display is invalid!"); - return -1; - } - - return display->bufmgr_fd; -} - tpl_bool_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) -- 2.7.4 From b1726e4fc896843d6c29d4b5968040eb7ffef3ce Mon Sep 17 00:00:00 2001 From: "Mun, Gwan-gyeong" Date: Tue, 16 Feb 2016 11:40:05 +0900 Subject: [PATCH 06/16] Remove unused APIs on tpl_display. - Removed API: tpl_display_flush tpl_display_wait_native tpl_display_get_backend_type tpl_display_choose_backend_type Change-Id: Ic34210f80d024073570d4c726a1f764dd140edaf --- src/tpl.h | 21 --------------------- src/tpl_display.c | 52 ---------------------------------------------------- src/tpl_gbm.c | 9 --------- src/tpl_internal.h | 4 ---- src/tpl_tbm.c | 9 --------- src/tpl_wayland.c | 12 ------------ 6 files changed, 107 deletions(-) diff --git a/src/tpl.h b/src/tpl.h index 736821e..1d240c9 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -267,7 +267,6 @@ tpl_bool_t tpl_object_set_user_data(tpl_object_t *object, */ void * tpl_object_get_user_data(tpl_object_t *object); -tpl_backend_type_t tpl_display_choose_backend_type(tpl_handle_t native_dpy); /** * Create or get TPL display object for the given native display. * @@ -315,16 +314,6 @@ tpl_bool_t tpl_display_unbind_client_display_handle(tpl_display_t *display, tpl_handle_t native_dpy); /** - * Get the backend type of a TPL display. - * - * @param display display to get type. - * @return backend type of the given display. - * - * @see tpl_display_get() - */ -tpl_backend_type_t tpl_display_get_backend_type(tpl_display_t *display); - -/** * Get the native display handle which the given TPL display is created for. * * @param display display to get native handle. @@ -377,16 +366,6 @@ tpl_bool_t tpl_display_filter_config(tpl_display_t *display, int *visual_id, int alpha_size); -/** - * Flush the TPL display. - * - * @param display display to flush. - * - * There might be pending operations on the given TPL display such as X11 - * native rendering. Flushing TPL display ensures that those pending operations - * are done. - */ -void tpl_display_flush(tpl_display_t *display); /** * Create a TPL surface for the given native surface. diff --git a/src/tpl_display.c b/src/tpl_display.c index 6b2c6cd..17b45a8 100644 --- a/src/tpl_display.c +++ b/src/tpl_display.c @@ -1,14 +1,5 @@ #include "tpl_internal.h" -void -__tpl_display_flush(tpl_display_t *display) -{ - TPL_ASSERT(display); - - if (display->backend.flush) - display->backend.flush(display); -} - static void __tpl_display_fini(tpl_display_t *display) { @@ -29,12 +20,6 @@ __tpl_display_free(void *display) free(display); } -tpl_backend_type_t -tpl_display_choose_backend_type(tpl_handle_t native_dpy) -{ - return __tpl_display_choose_backend(native_dpy); -} - tpl_display_t * tpl_display_get(tpl_backend_type_t type, tpl_handle_t native_dpy) { @@ -136,18 +121,6 @@ tpl_display_unbind_client_display_handle(tpl_display_t *display, tpl_handle_t na return display->backend.unbind_client_display_handle(display, native_dpy); } -tpl_backend_type_t -tpl_display_get_backend_type(tpl_display_t *display) -{ - if(NULL == display || TPL_TRUE != __tpl_object_is_valid(&display->base)) - { - TPL_ERR("display is invalid!"); - return TPL_BACKEND_UNKNOWN; - } - - return display->backend.type; -} - tpl_handle_t tpl_display_get_native_handle(tpl_display_t *display) { @@ -192,31 +165,6 @@ tpl_display_filter_config(tpl_display_t *display, int *visual_id, int alpha_size return display->backend.filter_config(display, visual_id, alpha_size); } -void -tpl_display_flush(tpl_display_t *display) -{ - if (display == NULL) - __tpl_runtime_flush_all_display(); - else - { - TPL_OBJECT_LOCK(display); - __tpl_display_flush(display); - TPL_OBJECT_UNLOCK(display); - } -} - -void -tpl_display_wait_native(tpl_display_t *display) -{ - if(NULL == display || TPL_TRUE != __tpl_object_is_valid(&display->base)) - { - TPL_ERR("display is invalid!"); - return; - } - - display->backend.wait_native(display); -} - tpl_bool_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) diff --git a/src/tpl_gbm.c b/src/tpl_gbm.c index 6266af7..696d8c2 100644 --- a/src/tpl_gbm.c +++ b/src/tpl_gbm.c @@ -249,14 +249,6 @@ __tpl_gbm_display_get_buffer_from_native_pixmap(tpl_handle_t pixmap) return tbm_surface; } -static void -__tpl_gbm_display_flush(tpl_display_t *display) -{ - TPL_IGNORE(display); - - /* Do nothing. */ -} - static tpl_bool_t __tpl_gbm_surface_init(tpl_surface_t *surface) { @@ -442,7 +434,6 @@ __tpl_display_init_backend_gbm(tpl_display_backend_t *backend) 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->flush = __tpl_gbm_display_flush; #ifdef EGL_BIND_WL_DISPLAY backend->bind_client_display_handle = __tpl_gbm_display_bind_client_wayland_display; backend->unbind_client_display_handle = __tpl_gbm_display_unbind_client_wayland_display; diff --git a/src/tpl_internal.h b/src/tpl_internal.h index a9bbab8..ae3259b 100644 --- a/src/tpl_internal.h +++ b/src/tpl_internal.h @@ -47,10 +47,6 @@ struct _tpl_display_backend int *width, int *height, tbm_format *format); tbm_surface_h (*get_buffer_from_native_pixmap)(tpl_handle_t pixmap); - - void (*flush)(tpl_display_t *display); - void (*wait_native)(tpl_display_t *display); - }; struct _tpl_surface_backend diff --git a/src/tpl_tbm.c b/src/tpl_tbm.c index 61cdc5b..df29211 100644 --- a/src/tpl_tbm.c +++ b/src/tpl_tbm.c @@ -161,14 +161,6 @@ __tpl_tbm_display_get_buffer_from_native_pixmap(tpl_handle_t pixmap) } static void -__tpl_tbm_display_flush(tpl_display_t *display) -{ - TPL_IGNORE(display); - - /* Do nothing. */ -} - -static void __tpl_tbm_surface_queue_notify_cb(tbm_surface_queue_h surface_queue, void *data) { /* Do something */ @@ -339,7 +331,6 @@ __tpl_display_init_backend_tbm(tpl_display_backend_t *backend) 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->flush = __tpl_tbm_display_flush; } void diff --git a/src/tpl_wayland.c b/src/tpl_wayland.c index 3c04d23..ac9a6ce 100644 --- a/src/tpl_wayland.c +++ b/src/tpl_wayland.c @@ -276,14 +276,6 @@ __tpl_wayland_display_get_window_info(tpl_display_t *display, tpl_handle_t windo } static void -__tpl_wayland_display_flush(tpl_display_t *display) -{ - TPL_IGNORE(display); - - /* Do nothing. */ -} - -static void __cb_client_window_resize_callback(struct wl_egl_window* wl_egl_window, void* private); static tpl_bool_t @@ -608,10 +600,6 @@ __tpl_display_init_backend_wayland(tpl_display_backend_t *backend) 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->get_pixmap_info = NULL; - backend->flush = __tpl_wayland_display_flush; - backend->bind_client_display_handle = NULL; - backend->unbind_client_display_handle = NULL; } void -- 2.7.4 From fe9c3db486c549301a0a60e1fc9c8b49f8dbb574 Mon Sep 17 00:00:00 2001 From: "Mun, Gwan-gyeong" Date: Tue, 16 Feb 2016 12:48:53 +0900 Subject: [PATCH 07/16] Change API: tpl_display_get() seperate tpl_display_get() to tpl_display_create() and tpl_display_get() Change-Id: I8c044fba19bd522d23a32dbef72c3bb7b880b7c1 --- src/tpl.h | 24 +++++++++++++++++------- src/tpl_display.c | 18 ++++++++++++++---- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/tpl.h b/src/tpl.h index 1d240c9..6d41edc 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -29,7 +29,7 @@ * * Here is a simple example * - * dpy = tpl_display_get(NULL); + * dpy = tpl_display_create(...); * sfc = tpl_surface_create(dpy, ...); * * while (1) @@ -178,10 +178,9 @@ typedef enum * TPL provides platform independent APIs by implementing platform dependent * things in a backend. These types represent types of such backends. One of * these types should be specified when creating a TPL display object when - * calling tpl_display_get(). + * calling tpl_display_create(). * - * @see tpl_display_get() - * @see tpl_display_get_backend_type() + * @see tpl_display_create() */ typedef enum { @@ -268,7 +267,7 @@ tpl_bool_t tpl_object_set_user_data(tpl_object_t *object, void * tpl_object_get_user_data(tpl_object_t *object); /** - * Create or get TPL display object for the given native display. + * Create TPL display object for the given native display. * * Create a TPL display if there's no already existing TPL display for the * given native display. If given NULL for native_dpy, this function will @@ -278,8 +277,19 @@ void * tpl_object_get_user_data(tpl_object_t *object); * @param native_dpy handle to the native display. * @return pointer to the display on success, NULL on failure. */ -tpl_display_t * tpl_display_get(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. + * + * If there's already existing TPL display for the given native display, + * then return the TPL display. + * + * @param native_dpy handle to the native display. + * @return pointer to the display on success, NULL on failure. + */ +tpl_display_t * tpl_display_get(tpl_handle_t native_dpy); /** * Bind a client connection(display handle) to the existed TPL display. diff --git a/src/tpl_display.c b/src/tpl_display.c index 17b45a8..6a0a42a 100644 --- a/src/tpl_display.c +++ b/src/tpl_display.c @@ -21,7 +21,7 @@ __tpl_display_free(void *display) } tpl_display_t * -tpl_display_get(tpl_backend_type_t type, tpl_handle_t native_dpy) +tpl_display_create(tpl_backend_type_t type, tpl_handle_t native_dpy) { tpl_display_t *display; tpl_bool_t ret; @@ -29,9 +29,8 @@ tpl_display_get(tpl_backend_type_t type, tpl_handle_t native_dpy) /* Search for an already connected display for the given native display. */ display = __tpl_runtime_find_display(type, native_dpy); - /* exact match found, can return immediately */ - if (NULL != display) - return display; + /* If tpl_display already exists, then return NULL */ + if (display) return NULL; /* if backend is unknown, try to find the best match from the list of supported types */ if (TPL_BACKEND_UNKNOWN == type) @@ -85,6 +84,17 @@ tpl_display_get(tpl_backend_type_t type, tpl_handle_t native_dpy) return display; } +tpl_display_t * +tpl_display_get(tpl_handle_t native_dpy) +{ + tpl_display_t *display; + + /* Search for an already connected display for the given native display. */ + display = __tpl_runtime_find_display(TPL_BACKEND_UNKNOWN, native_dpy); + + return display; +} + tpl_bool_t tpl_display_bind_client_display_handle(tpl_display_t *display, tpl_handle_t native_dpy) { -- 2.7.4 From 8cc1943d352ad90bf107fd3e640860654ddfab78 Mon Sep 17 00:00:00 2001 From: Sangjin Lee Date: Tue, 16 Feb 2016 14:00:51 +0900 Subject: [PATCH 08/16] Support tpl_objet_set_user_data() by key - add utils apis for map tpl_map support int32, int64 and pointer data type to hash key. and tpl_object use the pointer type map, key is treated as a normal variable. Thus, tpl_object_set/get_user_data() is modified to use the pointer value itself as a key. Change-Id: I0bffd9dba61aeeedcb498eaff1f8099c628aca8d --- Makefile | 1 + src/tpl.h | 6 +- src/tpl_internal.h | 8 +- src/tpl_object.c | 13 ++- src/tpl_utils.h | 71 ++++++++++++ src/tpl_utils_map.c | 305 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 392 insertions(+), 12 deletions(-) create mode 100644 src/tpl_utils_map.c diff --git a/Makefile b/Makefile index 4529297..ee9b725 100644 --- a/Makefile +++ b/Makefile @@ -64,6 +64,7 @@ TPL_SRCS += $(SRC_DIR)/tpl_object.c TPL_SRCS += $(SRC_DIR)/tpl_region.c TPL_SRCS += $(SRC_DIR)/tpl_surface.c TPL_SRCS += $(SRC_DIR)/tpl_utils_hlist.c +TPL_SRCS += $(SRC_DIR)/tpl_utils_map.c ifneq ($(call is-feature-enabled,winsys_wl),) TPL_SRCS += $(SRC_DIR)/tpl_wayland.c diff --git a/src/tpl.h b/src/tpl.h index 6d41edc..4d6d46c 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -244,8 +244,10 @@ tpl_object_type_t tpl_object_get_type(tpl_object_t *object); * Users want to relate some data with a TPL object. This function provides * registering a pointer to such data which can be retrieved later using * tpl_object_get_user_data(). + * key should the pointer value itself as a key * * @param object object to set user data to. + * @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. @@ -253,6 +255,7 @@ tpl_object_type_t tpl_object_get_type(tpl_object_t *object); * @see tpl_object_get_user_data() */ tpl_bool_t tpl_object_set_user_data(tpl_object_t *object, + void *key, void *data, tpl_free_func_t free_func); @@ -260,11 +263,12 @@ tpl_bool_t tpl_object_set_user_data(tpl_object_t *object, * Get registered user data of a TPL object. * * @param object object to get user data. + * @param key pointer to the key. * @return pointer to the registered user data on success, NULL on error. * * @see tpl_object_set_user_data() */ -void * tpl_object_get_user_data(tpl_object_t *object); +void * tpl_object_get_user_data(tpl_object_t *object, void *key); /** * Create TPL display object for the given native display. diff --git a/src/tpl_internal.h b/src/tpl_internal.h index ae3259b..009ca71 100644 --- a/src/tpl_internal.h +++ b/src/tpl_internal.h @@ -15,6 +15,8 @@ #include #include +#define TPL_OBJECT_BUCKET_BITS 5 + #define TPL_OBJECT_LOCK(object) __tpl_object_lock((tpl_object_t *)(object)) #define TPL_OBJECT_UNLOCK(object) __tpl_object_unlock((tpl_object_t *)(object)) @@ -70,10 +72,8 @@ struct _tpl_object tpl_free_func_t free; pthread_mutex_t mutex; - struct { - void *data; - tpl_free_func_t free; - } user_data; + tpl_util_map_t user_data_map; + tpl_util_map_entry_t *buckets[1 << TPL_OBJECT_BUCKET_BITS]; }; struct _tpl_display diff --git a/src/tpl_object.c b/src/tpl_object.c index 418146b..3558908 100644 --- a/src/tpl_object.c +++ b/src/tpl_object.c @@ -18,6 +18,7 @@ __tpl_object_init(tpl_object_t *object, tpl_object_type_t type, tpl_free_func_t object->type = type; object->free = free_func; + tpl_util_map_pointer_init(&object->user_data_map, TPL_OBJECT_BUCKET_BITS, &object->buckets[0]); __tpl_util_atomic_set(&object->reference, 1); @@ -35,8 +36,7 @@ __tpl_object_fini(tpl_object_t *object) if (0 != pthread_mutex_destroy(&object->mutex)) return TPL_FALSE; - if (object->user_data.free) - object->user_data.free(object->user_data.data); + tpl_util_map_fini(&object->user_data_map); return TPL_TRUE; } @@ -119,7 +119,7 @@ tpl_object_get_type(tpl_object_t *object) } tpl_bool_t -tpl_object_set_user_data(tpl_object_t *object, 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) { if (TPL_TRUE != __tpl_object_is_valid(object)) { @@ -128,15 +128,14 @@ tpl_object_set_user_data(tpl_object_t *object, void *data, tpl_free_func_t free_ } __tpl_object_lock(object); - object->user_data.data = data; - object->user_data.free = free_func; + tpl_util_map_set(&object->user_data_map, key, data, free_func); __tpl_object_unlock(object); return TPL_TRUE; } void * -tpl_object_get_user_data(tpl_object_t *object) +tpl_object_get_user_data(tpl_object_t *object, void *key) { void *data; @@ -147,7 +146,7 @@ tpl_object_get_user_data(tpl_object_t *object) } __tpl_object_lock(object); - data = object->user_data.data; + data = tpl_util_map_get(&object->user_data_map, key); __tpl_object_unlock(object); return data; diff --git a/src/tpl_utils.h b/src/tpl_utils.h index 28cbd55..02a3eed 100644 --- a/src/tpl_utils.h +++ b/src/tpl_utils.h @@ -7,6 +7,11 @@ #include #define TPL_MIN_REGION_RECTS 16 +#if defined(__GNUC__) && __GNUC__ >= 4 +# define TPL_API __attribute__ ((visibility("default"))) +#else +# define TPL_API +#endif #define TPL_ASSERT(expr) assert(expr) #define TPL_INLINE __inline__ #define TPL_IGNORE(x) (void)x @@ -849,4 +854,70 @@ 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 int (*tpl_util_hash_func_t)(const void *key, int key_length); +typedef int (*tpl_util_key_length_func_t)(const void *key); +typedef int (*tpl_util_key_compare_func_t)(const void *key0, int key0_length, + const void *key1, int key1_length); + +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; +}; + +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); + +void +tpl_util_map_int32_init(tpl_util_map_t *map, int bucket_bits, void *buckets); + +void +tpl_util_map_int64_init(tpl_util_map_t *map, int bucket_bits, void *buckets); + +void +tpl_util_map_pointer_init(tpl_util_map_t *map, int bucket_bits, void *buckets); + +void +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_t * +tpl_util_map_int32_create(int bucket_bits); + +tpl_util_map_t * +tpl_util_map_int64_create(int bucket_bits); + +tpl_util_map_t * +tpl_util_map_pointer_create(int bucket_bits); + +void +tpl_util_map_destroy(tpl_util_map_t *map); + +void +tpl_util_map_clear(tpl_util_map_t *map); + +void * +tpl_util_map_get(tpl_util_map_t *map, const void *key); + +void +tpl_util_map_set(tpl_util_map_t *map, const void *key, void *data, tpl_free_func_t free_func); #endif /* TPL_UTILS_H */ diff --git a/src/tpl_utils_map.c b/src/tpl_utils_map.c new file mode 100644 index 0000000..e42ef31 --- /dev/null +++ b/src/tpl_utils_map.c @@ -0,0 +1,305 @@ +#include "tpl_internal.h" + +struct tpl_util_map_entry +{ + const void *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 void *key) +{ + int key_length = 0; + int hash; + + if (map->key_length_func) + key_length = map->key_length_func(key); + + hash = map->hash_func(key, key_length); + return hash & map->bucket_mask; +} + +static inline tpl_util_map_entry_t ** +__get_bucket(tpl_util_map_t *map, const void *key) +{ + return &map->buckets[__get_bucket_index(map, key)]; +} + +static int +__int64_hash(const void *key, int key_length) +{ + uint64_t _key = (uint64_t)key; + + /* Hash functions from Thomas Wang https://gist.github.com/badboy/6267743 */ + _key = ~_key + (_key << 15); + _key ^= _key >> 12; + _key += _key << 2; + _key ^= _key >> 4; + _key *= 2057; + _key ^= _key >> 16; + + return (int)_key; +} + +static int +__int64_key_compare(const void *key0, int key0_length, + const void *key1, int key1_length) +{ + return (int)(key0 - key1); +} + +static int +__int32_hash(const void *key, int key_length) +{ + uint32_t _key = (uint32_t)key; + + /* Hash functions from Thomas Wang https://gist.github.com/badboy/6267743 */ + _key = ~_key + (_key << 15); + _key ^= _key >> 12; + _key += _key << 2; + _key ^= _key >> 4; + _key *= 2057; + _key ^= _key >> 16; + + return _key; +} + +static int +__int32_key_compare(const void *key0, int key0_length, + const void *key1, int key1_length) +{ + return (int)(key0 - key1); +} + +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) +{ + map->hash_func = hash_func; + map->key_length_func = key_length_func; + map->key_compare_func = key_compare_func; + + map->bucket_bits = bucket_bits; + map->bucket_size = 1 << bucket_bits; + map->bucket_mask = map->bucket_size - 1; + + map->buckets = buckets; +} + +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); +} + +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); +} + +void +tpl_util_map_pointer_init(tpl_util_map_t *map, int bucket_bits, void *buckets) +{ +#if INTPTR_MAX == INT32_MAX + tpl_util_map_init(map, bucket_bits, __int32_hash, NULL, __int32_key_compare, buckets); +#elif INTPTR_MAX == INT64_MAX + tpl_util_map_init(map, bucket_bits, __int64_hash, NULL, __int64_key_compare, buckets); +#else + #error "Not 32 or 64bit system" +#endif +} + + void +tpl_util_map_fini(tpl_util_map_t *map) +{ + tpl_util_map_clear(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_t *map; + int bucket_size = 1 << bucket_bits; + + 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); + 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); +} + + 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); +} + + tpl_util_map_t * +tpl_util_map_pointer_create(int bucket_bits) +{ +#if INTPTR_MAX == INT32_MAX + return tpl_util_map_create(bucket_bits, __int32_hash, NULL, __int32_key_compare); +#elif INTPTR_MAX == INT64_MAX + return tpl_util_map_create(bucket_bits, __int64_hash, NULL, __int64_key_compare); +#else + #error "Not 32 or 64bit system" +#endif + + return NULL; +} + + void +tpl_util_map_destroy(tpl_util_map_t *map) +{ + tpl_util_map_fini(map); + free(map); +} + + void +tpl_util_map_clear(tpl_util_map_t *map) +{ + int i; + + if (!map->buckets) + return; + + for (i = 0; i < map->bucket_size; i++) + { + tpl_util_map_entry_t *curr = map->buckets[i]; + + while (curr) + { + tpl_util_map_entry_t *next = curr->next; + + if (curr->free_func) + curr->free_func(curr->data); + + free(curr); + curr = next; + } + } + + memset(map->buckets, 0x00, map->bucket_size * sizeof(tpl_util_map_entry_t *)); +} + + void * +tpl_util_map_get(tpl_util_map_t *map, const void *key) +{ + tpl_util_map_entry_t *curr = *__get_bucket(map, key); + + while (curr) + { + int len0 = 0; + int len1 = 0; + + 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) + return curr->data; + + curr = curr->next; + } + + return NULL; +} + + void +tpl_util_map_set(tpl_util_map_t *map, const void *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; + + /* Find existing entry for the key. */ + while (curr) + { + int len0 = 0; + int len1 = 0; + + 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) + { + /* Free previous data. */ + if (curr->free_func) + curr->free_func(curr->data); + + if (data) + { + /* Set new data. */ + curr->data = data; + curr->free_func = free_func; + } + else + { + /* Delete entry. */ + if (prev) + prev->next = curr->next; + else + *bucket = curr->next; + + free(curr); + } + + return; + } + + prev = curr; + curr = curr->next; + } + + if (data == NULL) + { + /* Nothing to delete. */ + return; + } + + /* Allocate a new entry. */ + 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) + { + memcpy(curr + 1, key, key_length); + curr->key = (const void *)(curr + 1); + } + else + { + curr->key = key; + } + + curr->data = data; + curr->free_func = free_func; + + /* Insert at the head of the bucket. */ + curr->next = *bucket; + *bucket = curr; +} -- 2.7.4 From cdfed9b0d8baed43e618f1068c5f3a9b04bec3ca Mon Sep 17 00:00:00 2001 From: Sangjin Lee Date: Tue, 16 Feb 2016 20:59:44 +0900 Subject: [PATCH 09/16] revise tpl_util_map Change-Id: I9474d38989c4ad6c79ac32c0f892a4d262789384 --- src/tpl_object.c | 9 +- src/tpl_utils.h | 22 ++- src/tpl_utils_map.c | 431 +++++++++++++++++++++++++++------------------------- 3 files changed, 250 insertions(+), 212 deletions(-) diff --git a/src/tpl_object.c b/src/tpl_object.c index 3558908..43a5443 100644 --- a/src/tpl_object.c +++ b/src/tpl_object.c @@ -121,6 +121,8 @@ tpl_object_get_type(tpl_object_t *object) tpl_bool_t 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)) { TPL_ERR("input object is invalid!"); @@ -128,7 +130,8 @@ tpl_object_set_user_data(tpl_object_t *object, void *key, void *data, tpl_free_f } __tpl_object_lock(object); - tpl_util_map_set(&object->user_data_map, key, data, free_func); + _key.ptr = key; + tpl_util_map_set(&object->user_data_map, _key, data, free_func); __tpl_object_unlock(object); return TPL_TRUE; @@ -137,6 +140,7 @@ tpl_object_set_user_data(tpl_object_t *object, void *key, void *data, tpl_free_f void * 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)) @@ -146,7 +150,8 @@ tpl_object_get_user_data(tpl_object_t *object, void *key) } __tpl_object_lock(object); - data = tpl_util_map_get(&object->user_data_map, key); + _key.ptr = key; + data = tpl_util_map_get(&object->user_data_map, _key); __tpl_object_unlock(object); return data; diff --git a/src/tpl_utils.h b/src/tpl_utils.h index 02a3eed..bbd336e 100644 --- a/src/tpl_utils.h +++ b/src/tpl_utils.h @@ -429,7 +429,7 @@ secUtilDumpPng(const char *file, const void *data, int width, int height) } #endif -static void +static inline void __tpl_util_image_dump(const char * func, const void * data, int type, int width, int height, int num) { char name[200]; @@ -856,11 +856,19 @@ tpl_list_pop_back(tpl_list_t *list, tpl_free_func_t func) 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; -typedef int (*tpl_util_hash_func_t)(const void *key, int key_length); -typedef int (*tpl_util_key_length_func_t)(const void *key); -typedef int (*tpl_util_key_compare_func_t)(const void *key0, int key0_length, - const void *key1, int key1_length); +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); + +union tpl_util_key +{ + uint32_t key32; + uint64_t key64; + void* ptr; /*pointer key or user defined key(string)*/ +}; struct tpl_util_map { @@ -916,8 +924,8 @@ void tpl_util_map_clear(tpl_util_map_t *map); void * -tpl_util_map_get(tpl_util_map_t *map, const void *key); +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 void *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); #endif /* TPL_UTILS_H */ diff --git a/src/tpl_utils_map.c b/src/tpl_utils_map.c index e42ef31..3b5880c 100644 --- a/src/tpl_utils_map.c +++ b/src/tpl_utils_map.c @@ -2,304 +2,329 @@ struct tpl_util_map_entry { - const void *key; - void *data; - tpl_free_func_t free_func; - tpl_util_map_entry_t *next; + 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 void *key) +__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; + hash = map->hash_func(key, key_length); + return hash & map->bucket_mask; } static inline tpl_util_map_entry_t ** -__get_bucket(tpl_util_map_t *map, const void *key) +__get_bucket(tpl_util_map_t *map, const tpl_util_key_t key) { - return &map->buckets[__get_bucket_index(map, key)]; + return &map->buckets[__get_bucket_index(map, key)]; } static int -__int64_hash(const void *key, int key_length) +__int64_hash(const tpl_util_key_t key, int key_length) { - uint64_t _key = (uint64_t)key; + uint64_t _key = key.key64; /* Hash functions from Thomas Wang https://gist.github.com/badboy/6267743 */ - _key = ~_key + (_key << 15); - _key ^= _key >> 12; - _key += _key << 2; - _key ^= _key >> 4; - _key *= 2057; - _key ^= _key >> 16; - - return (int)_key; + _key = ~_key + (_key << 18); + _key ^= _key >> 31; + _key *= 21; + _key ^= _key >> 11; + _key += _key << 6; + _key ^= _key >> 22; + + return (int)_key;; } static int -__int64_key_compare(const void *key0, int key0_length, - const void *key1, int key1_length) +__int64_key_compare(const tpl_util_key_t key0, int key0_length, + const tpl_util_key_t key1, int key1_length) { - return (int)(key0 - key1); + return (int)(key0.key64 - key1.key64); } static int -__int32_hash(const void *key, int key_length) +__int32_hash(const tpl_util_key_t key, int key_length) { - uint32_t _key = (uint32_t)key; + uint32_t _key = (uint32_t)key.key32; /* Hash functions from Thomas Wang https://gist.github.com/badboy/6267743 */ - _key = ~_key + (_key << 15); - _key ^= _key >> 12; - _key += _key << 2; - _key ^= _key >> 4; - _key *= 2057; - _key ^= _key >> 16; - - return _key; + _key = ~_key + (_key << 15); + _key ^= _key >> 12; + _key += _key << 2; + _key ^= _key >> 4; + _key *= 2057; + _key ^= _key >> 16; + + return (int)_key; } static int -__int32_key_compare(const void *key0, int key0_length, - const void *key1, int key1_length) +__int32_key_compare(const tpl_util_key_t key0, int key0_length, + const tpl_util_key_t key1, int key1_length) { - return (int)(key0 - key1); + return (int)(key0.key32 - key1.key32); +} + +static int +__pointer_hash(const tpl_util_key_t key, int key_length) +{ +#if INTPTR_MAX == INT32_MAX + uint32_t _key = (uint32_t)key.ptr; + + _key = ~_key + (_key << 15); + _key ^= _key >> 12; + _key += _key << 2; + _key ^= _key >> 4; + _key *= 2057; + _key ^= _key >> 16; + + return (int)_key; +#elif INTPTR_MAX == INT64_MAX + uint64_t _key = (uint64_t)key.ptr; + + _key = ~_key + (_key << 18); + _key ^= _key >> 31; + _key *= 21; + _key ^= _key >> 11; + _key += _key << 6; + _key ^= _key >> 22; + + return (int)_key; +#else + #error "Not 32 or 64bit system" +#endif + + return 0; +} + +static int +__pointer_key_compare(const tpl_util_key_t key0, int key0_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; - map->key_compare_func = key_compare_func; + map->hash_func = hash_func; + map->key_length_func = key_length_func; + map->key_compare_func = key_compare_func; - map->bucket_bits = bucket_bits; - map->bucket_size = 1 << bucket_bits; - map->bucket_mask = map->bucket_size - 1; + map->bucket_bits = bucket_bits; + map->bucket_size = 1 << bucket_bits; + map->bucket_mask = map->bucket_size - 1; - map->buckets = buckets; + map->buckets = buckets; } 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) { -#if INTPTR_MAX == INT32_MAX - tpl_util_map_init(map, bucket_bits, __int32_hash, NULL, __int32_key_compare, buckets); -#elif INTPTR_MAX == INT64_MAX - tpl_util_map_init(map, bucket_bits, __int64_hash, NULL, __int64_key_compare, buckets); -#else - #error "Not 32 or 64bit system" -#endif + tpl_util_map_init(map, bucket_bits, __pointer_hash, NULL, __pointer_key_compare, buckets); } - void +void tpl_util_map_fini(tpl_util_map_t *map) { - tpl_util_map_clear(map); + tpl_util_map_clear(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_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_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 *)); - TPL_CHECK_ON_FALSE_RETURN_VAL(map, NULL); + 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); - return map; + 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_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_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_t * tpl_util_map_pointer_create(int bucket_bits) { -#if INTPTR_MAX == INT32_MAX - return tpl_util_map_create(bucket_bits, __int32_hash, NULL, __int32_key_compare); -#elif INTPTR_MAX == INT64_MAX - return tpl_util_map_create(bucket_bits, __int64_hash, NULL, __int64_key_compare); -#else - #error "Not 32 or 64bit system" -#endif - - return NULL; + return tpl_util_map_create(bucket_bits, __pointer_hash, NULL, __pointer_key_compare); } - void +void tpl_util_map_destroy(tpl_util_map_t *map) { - tpl_util_map_fini(map); - free(map); + tpl_util_map_fini(map); + free(map); } - void +void tpl_util_map_clear(tpl_util_map_t *map) { - int i; + int i; - if (!map->buckets) - return; + if (!map->buckets) + return; - for (i = 0; i < map->bucket_size; i++) - { - tpl_util_map_entry_t *curr = map->buckets[i]; + for (i = 0; i < map->bucket_size; i++) + { + tpl_util_map_entry_t *curr = map->buckets[i]; - while (curr) - { - tpl_util_map_entry_t *next = curr->next; + 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; - } - } + free(curr); + curr = next; + } + } - memset(map->buckets, 0x00, map->bucket_size * sizeof(tpl_util_map_entry_t *)); + memset(map->buckets, 0x00, map->bucket_size * sizeof(tpl_util_map_entry_t *)); } - void * -tpl_util_map_get(tpl_util_map_t *map, const void *key) +void * +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); + tpl_util_map_entry_t *curr = *__get_bucket(map, key); - while (curr) - { - int len0 = 0; - int len1 = 0; + while (curr) + { + int len0 = 0; + int len1 = 0; - if (map->key_length_func) - { - len0 = map->key_length_func(curr->key); - len1 = map->key_length_func(key); - } + 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) - return curr->data; + if (map->key_compare_func(curr->key, len0, key, len1) == 0) + return curr->data; - curr = curr->next; - } + curr = curr->next; + } - return NULL; + return NULL; } - void -tpl_util_map_set(tpl_util_map_t *map, const void *key, void *data, tpl_free_func_t free_func) +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_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) - { - int len0 = 0; - int len1 = 0; - - 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) - { - /* Free previous data. */ - if (curr->free_func) - curr->free_func(curr->data); - - if (data) - { - /* Set new data. */ - curr->data = data; - curr->free_func = free_func; - } - else - { - /* Delete entry. */ - if (prev) - prev->next = curr->next; - else - *bucket = curr->next; - - free(curr); - } - - return; - } - - prev = curr; - curr = curr->next; - } - - if (data == NULL) - { - /* Nothing to delete. */ - return; - } - - /* Allocate a new entry. */ - 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) - { - memcpy(curr + 1, key, key_length); - curr->key = (const void *)(curr + 1); - } - else - { - curr->key = key; - } - - curr->data = data; - curr->free_func = free_func; - - /* Insert at the head of the bucket. */ - curr->next = *bucket; - *bucket = curr; + 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) + { + int len0 = 0; + int len1 = 0; + + 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) + { + /* Free previous data. */ + if (curr->free_func) + curr->free_func(curr->data); + + if (data) + { + /* Set new data. */ + curr->data = data; + curr->free_func = free_func; + } + else + { + /* Delete entry. */ + if (prev) + prev->next = curr->next; + else + *bucket = curr->next; + + free(curr); + } + + return; + } + + prev = curr; + curr = curr->next; + } + + if (data == NULL) + { + /* Nothing to delete. */ + return; + } + + /* Allocate a new entry. */ + 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) + { + memcpy(curr + 1, key.ptr, key_length); + curr->key.ptr = (void *)(curr + 1); + } + else + { + curr->key = key; + } + + curr->data = data; + curr->free_func = free_func; + + /* Insert at the head of the bucket. */ + curr->next = *bucket; + *bucket = curr; } -- 2.7.4 From ea11a2bae6b1ab003603288d09bbc1a851427830 Mon Sep 17 00:00:00 2001 From: "Mun, Gwan-gyeong" Date: Tue, 16 Feb 2016 20:48:24 +0900 Subject: [PATCH 10/16] Remove meanless APIs - tpl_display_bind_client_display_handle() - tpl_display_unbind_client_display_handle() wayland client's tbm_bufmgr_init() is called by wayland_tbm protocol(). ( when the tpl_egl used wayland-drm protocol, explicity, tpl-egl calls client's tbm_bufmgr_init(). But current implementation wayland-tbm calls tbm_bufmgr_init() internally.) Change-Id: If97466b45298c567b737e2467dc6e932daff43aa --- Makefile | 5 +---- packaging/libtpl-egl.spec | 2 -- src/tpl.h | 32 ---------------------------- src/tpl_display.c | 36 ------------------------------- src/tpl_gbm.c | 54 ++++------------------------------------------- src/tpl_internal.h | 3 --- 6 files changed, 5 insertions(+), 127 deletions(-) diff --git a/Makefile b/Makefile index ee9b725..5ba5bb1 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ ifneq ($(call is-feature-enabled,winsys_dri3),) endif ifneq ($(call is-feature-enabled,winsys_wl),) - CFLAGS += -DTPL_WINSYS_WL=1 -DEGL_BIND_WL_DISPLAY + CFLAGS += -DTPL_WINSYS_WL=1 CFLAGS += `pkg-config --cflags gbm` LDFLAGS += `pkg-config --libs gbm wayland-tbm-client wayland-tbm-server` endif @@ -42,9 +42,6 @@ endif ifneq ($(call is-feature-enabled,dlog),) CFLAGS += -DDLOG_DEFAULT_ENABLE endif -ifneq ($(call is-feature-enabled,egl_bind_wl_display),) - CFLAGS += -DEGL_BIND_WL_DISPLAY -endif ifneq ($(call is-feature-enabled,pngdump),) CFLAGS += -DPNG_DUMP_ENABLE LDFLAGS += `pkg-config libpng` diff --git a/packaging/libtpl-egl.spec b/packaging/libtpl-egl.spec index 59faeb7..18901c8 100644 --- a/packaging/libtpl-egl.spec +++ b/packaging/libtpl-egl.spec @@ -140,8 +140,6 @@ TPL_OPTIONS=${TPL_OPTIONS}-pngdump TPL_OPTIONS=${TPL_OPTIONS}-arm_atomic_operation %endif -TPL_OPTIONS=${TPL_OPTIONS}-egl_bind_wl_display - # do not change the following line export TPL_OPTIONS=${TPL_OPTIONS}- diff --git a/src/tpl.h b/src/tpl.h index 4d6d46c..c7ee2e1 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -296,38 +296,6 @@ tpl_display_t * tpl_display_create(tpl_backend_type_t type, tpl_display_t * tpl_display_get(tpl_handle_t native_dpy); /** - * Bind a client connection(display handle) to the existed TPL display. - * - * After bound, The TPL display knows a handle of client connection display and - * it can recognize client objects (e.g. pixmap surfaces from client - * application) which were contained by the client connection. So this function - * must be called by the server process (such as compositor) before using - * client buffers. - * - * @param display display to bind a client connection. - * @param native_dpy handle of the native client display connection. - * - * @see tpl_display_unbind_client_display_handle() - */ -tpl_bool_t tpl_display_bind_client_display_handle(tpl_display_t *display, - tpl_handle_t native_dpy); - -/** - * Unbind a client connection(display handle) from the existed TPL display. - * - * After being unbound, the TPL display no longer knows about client - * connection, and all resources from the connection can be unreferenced. If - * the specified connection was not a bound handle, error occurs. - * - * @param display display to unbind a client connection. - * @param native_dpy handle of the native client display connection. - * - * @see tpl_display_bind_client_display_handle() - */ -tpl_bool_t tpl_display_unbind_client_display_handle(tpl_display_t *display, - tpl_handle_t native_dpy); - -/** * Get the native display handle which the given TPL display is created for. * * @param display display to get native handle. diff --git a/src/tpl_display.c b/src/tpl_display.c index 6a0a42a..311f443 100644 --- a/src/tpl_display.c +++ b/src/tpl_display.c @@ -95,42 +95,6 @@ tpl_display_get(tpl_handle_t native_dpy) return display; } -tpl_bool_t -tpl_display_bind_client_display_handle(tpl_display_t *display, tpl_handle_t native_dpy) -{ - if(NULL == display || TPL_TRUE != __tpl_object_is_valid(&display->base) || NULL == display->backend.bind_client_display_handle) - { - TPL_ERR("display is invalid!"); - return TPL_FALSE; - } - - if (NULL == native_dpy) - { - TPL_ERR("native_dpy is NULL!"); - return TPL_FALSE; - } - - return display->backend.bind_client_display_handle(display, native_dpy); -} - -tpl_bool_t -tpl_display_unbind_client_display_handle(tpl_display_t *display, tpl_handle_t native_dpy) -{ - if(NULL == display || TPL_TRUE != __tpl_object_is_valid(&display->base) || NULL == display->backend.unbind_client_display_handle) - { - TPL_ERR("display is invalid!"); - return TPL_FALSE; - } - - if (NULL == native_dpy) - { - TPL_ERR("native_dpy is NULL!"); - return TPL_FALSE; - } - - return display->backend.unbind_client_display_handle(display, native_dpy); -} - tpl_handle_t tpl_display_get_native_handle(tpl_display_t *display) { diff --git a/src/tpl_gbm.c b/src/tpl_gbm.c index 696d8c2..3e58284 100644 --- a/src/tpl_gbm.c +++ b/src/tpl_gbm.c @@ -35,7 +35,6 @@ typedef struct _tpl_gbm_buffer tpl_gbm_buffer_t; struct _tpl_gbm_display { tbm_bufmgr bufmgr; - tpl_bool_t bound_client_display; }; struct _tpl_gbm_surface @@ -54,11 +53,6 @@ struct _tpl_gbm_buffer struct wl_listener destroy_listener; }; -#ifdef EGL_BIND_WL_DISPLAY -unsigned int __tpl_gbm_display_bind_client_wayland_display(tpl_display_t *tpl_display, tpl_handle_t native_dpy); -unsigned int __tpl_gbm_display_unbind_client_wayland_display(tpl_display_t *tpl_display, tpl_handle_t native_dpy); -#endif - static int tpl_gbm_buffer_key; #define KEY_TPL_GBM_BUFFER (unsigned long)(&tpl_gbm_buffer_key) @@ -113,8 +107,9 @@ __tpl_gbm_display_init(tpl_display_t *display) if (gbm_display == NULL) return TPL_FALSE; + display->bufmgr_fd = dup(gbm_device_get_fd(display->native_handle)); + gbm_display->bufmgr = tbm_bufmgr_init(display->bufmgr_fd); display->backend.data = gbm_display; - display->bufmgr_fd = -1; return TPL_TRUE; } @@ -129,11 +124,10 @@ __tpl_gbm_display_fini(tpl_display_t *display) gbm_display = (tpl_gbm_display_t *)display->backend.data; if (gbm_display != NULL) { - if (gbm_display->bound_client_display) - __tpl_gbm_display_unbind_client_wayland_display(display, NULL); - + tbm_bufmgr_deinit(gbm_display->bufmgr); free(gbm_display); } + close(display->bufmgr_fd); display->backend.data = NULL; } @@ -434,10 +428,6 @@ __tpl_display_init_backend_gbm(tpl_display_backend_t *backend) 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; -#ifdef EGL_BIND_WL_DISPLAY - backend->bind_client_display_handle = __tpl_gbm_display_bind_client_wayland_display; - backend->unbind_client_display_handle = __tpl_gbm_display_unbind_client_wayland_display; -#endif } void @@ -454,39 +444,3 @@ __tpl_surface_init_backend_gbm(tpl_surface_backend_t *backend) backend->dequeue_buffer = __tpl_gbm_surface_dequeue_buffer; backend->enqueue_buffer = __tpl_gbm_surface_enqueue_buffer; } - -#ifdef EGL_BIND_WL_DISPLAY -unsigned int __tpl_gbm_display_bind_client_wayland_display(tpl_display_t *tpl_display, tpl_handle_t native_dpy) -{ - tpl_gbm_display_t *tpl_gbm_display; - - TPL_ASSERT(tpl_display); - TPL_ASSERT(native_dpy); - - tpl_gbm_display = (tpl_gbm_display_t *) tpl_display->backend.data; - tpl_display->bufmgr_fd = dup(gbm_device_get_fd(tpl_display->native_handle)); - tpl_gbm_display->bufmgr = tbm_bufmgr_init(tpl_display->bufmgr_fd); - if (tpl_gbm_display->bufmgr == NULL) - { - TPL_ERR("TBM buffer manager initialization failed!"); - return TPL_FALSE; - } - - tpl_gbm_display->bound_client_display = TPL_TRUE; - return TPL_TRUE; -} - -unsigned int __tpl_gbm_display_unbind_client_wayland_display(tpl_display_t *tpl_display, tpl_handle_t native_dpy) -{ - tpl_gbm_display_t *tpl_gbm_display; - - TPL_ASSERT(tpl_display); - - tpl_gbm_display = (tpl_gbm_display_t *) tpl_display->backend.data; - - tbm_bufmgr_deinit(tpl_gbm_display->bufmgr); - close(tpl_display->bufmgr_fd); - tpl_gbm_display->bound_client_display = TPL_FALSE; - return TPL_TRUE; -} -#endif diff --git a/src/tpl_internal.h b/src/tpl_internal.h index 009ca71..487f586 100644 --- a/src/tpl_internal.h +++ b/src/tpl_internal.h @@ -34,9 +34,6 @@ struct _tpl_display_backend tpl_bool_t (*init)(tpl_display_t *display); void (*fini)(tpl_display_t *display); - tpl_bool_t (*bind_client_display_handle)(tpl_display_t *display, tpl_handle_t native_dpy); - tpl_bool_t (*unbind_client_display_handle)(tpl_display_t *display, tpl_handle_t native_dpy); - tpl_bool_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, -- 2.7.4 From 104f88712d29d32180f26e3bbfc62fe13454d479 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Tue, 16 Feb 2016 17:09:32 +0900 Subject: [PATCH 11/16] Delete API tpl_surface_set/get_damage. Change-Id: I911464516280f88d802c99f79aac8f7940f88ae6 --- src/tpl.h | 31 ------------------------------- src/tpl_surface.c | 37 ------------------------------------- 2 files changed, 68 deletions(-) diff --git a/src/tpl.h b/src/tpl.h index c7ee2e1..3994178 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -490,37 +490,6 @@ tpl_bool_t tpl_surface_set_post_interval(tpl_surface_t *surface, int tpl_surface_get_post_interval(tpl_surface_t *surface); /** - * Set damaged region of the given TPL surface. - * - * Damage information is used for reducing number of pixels composited in the - * compositor. When a frame ends, the frames' damage area is copied from the - * surface's current damage region. Setting num_rects to 0 or rects to NULL - * means entire area is damaged. - * - * @param surface surface to set damage region. - * @param num_rects number of rectangles of the damage region. - * @param rects pointer to coordinates of rectangles. x0, y0, w0, h0, x1, y1, w1, h1... - * - * @see tpl_surface_get_damage() - */ -tpl_bool_t tpl_surface_set_damage(tpl_surface_t *surface, - int num_rects, - const int *rects); - -/** - * Get damaged region of the given TPL surface. - * - * @param surface surface to get damage region. - * @param num_rects Pointer to receive the number of rectangles. - * @param rects Pointer to receive the pointer to rectangle coordinate array. - * - * @see tpl_surface_set_damage() - */ -tpl_bool_t tpl_surface_get_damage(tpl_surface_t *surface, - int *num_rects, - const int **rects); - -/** * Query information on the given native window. * * @param display display used for query. diff --git a/src/tpl_surface.c b/src/tpl_surface.c index 983ad73..58431fb 100644 --- a/src/tpl_surface.c +++ b/src/tpl_surface.c @@ -194,43 +194,6 @@ tpl_surface_get_post_interval(tpl_surface_t *surface) return interval; } -tpl_bool_t -tpl_surface_set_damage(tpl_surface_t *surface, int num_rects, const int *rects) -{ - tpl_bool_t ret; - - if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type) - { - TPL_ERR("Invalid surface!"); - return TPL_FALSE; - } - - TPL_OBJECT_LOCK(surface); - ret = __tpl_region_set_rects(&surface->damage, num_rects, rects); - TPL_OBJECT_UNLOCK(surface); - - return ret; -} - -tpl_bool_t -tpl_surface_get_damage(tpl_surface_t *surface, int *num_rects, const int **rects) -{ - if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type) - { - TPL_ERR("Invalid surface!"); - *num_rects = 0; - *rects = NULL; - return TPL_FALSE; - } - - TPL_OBJECT_LOCK(surface); - *num_rects = surface->damage.num_rects; - *rects = surface->damage.rects; - TPL_OBJECT_UNLOCK(surface); - - return TPL_TRUE; -} - tbm_surface_h tpl_surface_dequeue_buffer(tpl_surface_t *surface) { -- 2.7.4 From 871f4e7951745b4578f4d60e83519aac2845b40c Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Tue, 16 Feb 2016 18:51:18 +0900 Subject: [PATCH 12/16] Add API tpl_surface_enqueue_buffer_with_damage. - Deleted usages of tpl_region_t and file because the need that tpl_surface_t has tpl_region_t(damage info) disappeared. Change-Id: I076352c21042007ebf166f80229658c963cafa30 --- Makefile | 1 - src/tpl.h | 29 ++++++++++++-- src/tpl_gbm.c | 5 ++- src/tpl_internal.h | 15 +------- src/tpl_region.c | 110 ----------------------------------------------------- src/tpl_surface.c | 39 +++++++++++++++---- src/tpl_tbm.c | 5 ++- src/tpl_utils.h | 19 --------- src/tpl_wayland.c | 15 ++++---- 9 files changed, 75 insertions(+), 163 deletions(-) delete mode 100644 src/tpl_region.c diff --git a/Makefile b/Makefile index 5ba5bb1..d8344cf 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,6 @@ TPL_HEADERS += $(SRC_DIR)/tpl_utils.h TPL_SRCS += $(SRC_DIR)/tpl.c TPL_SRCS += $(SRC_DIR)/tpl_display.c TPL_SRCS += $(SRC_DIR)/tpl_object.c -TPL_SRCS += $(SRC_DIR)/tpl_region.c TPL_SRCS += $(SRC_DIR)/tpl_surface.c TPL_SRCS += $(SRC_DIR)/tpl_utils_hlist.c TPL_SRCS += $(SRC_DIR)/tpl_utils_map.c diff --git a/src/tpl.h b/src/tpl.h index 3994178..69c0eba 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -450,14 +450,12 @@ tbm_surface_h tpl_surface_dequeue_buffer(tpl_surface_t *surface); /** * Post a given tbm_surface. * - * This function request display server to post a frame. This is the only + * This function request display server to post a frame. This is the * function which can enqueue a buffer to the tbm_surface_queue. * * Make sure this function is called exactly once for a frame. * Scheduling post calls on a separate thread is recommended. * - * This function might implicitly end the current frame. - * * @param surface surface to post a frame. * @param tbm_surface buffer to post. * @@ -465,6 +463,31 @@ tbm_surface_h tpl_surface_dequeue_buffer(tpl_surface_t *surface); tpl_bool_t tpl_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface); /** + * Post a given tbm_surface with region of damage. + * + * Damage information is used for reducing number of pixels composited in the + * compositor. Setting num_rects to 0 or rects to NULL means entire area is damaged. + * + * This function request display server to post a frame. + * This function is identical with tpl_surface_enqueue_buffer except delivering + * the damage information for updating. + * + * Make sure this function is called exactly once for a frame. + * Scheduling post calls on a separate thread is recommended. + * + * @param surface surface to post a frame. + * @param tbm_surface buffer to post. + * @param num_rects the number of rectangles of the damage region. + * @param rects pointer to coordinates of rectangles. x0, y0, w0, h0, x1, y1, w1, h1... + * + * @see tpl_surface_enqueue_buffer() + */ +tpl_bool_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. * * Frame interval ensures that only a single frame is posted within the diff --git a/src/tpl_gbm.c b/src/tpl_gbm.c index 3e58284..bad80c3 100644 --- a/src/tpl_gbm.c +++ b/src/tpl_gbm.c @@ -306,12 +306,15 @@ __tpl_gbm_surface_fini(tpl_surface_t *surface) } static void -__tpl_gbm_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface) +__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(rects); TPL_LOG(3, "window(%p, %p)", surface, surface->native_handle); diff --git a/src/tpl_internal.h b/src/tpl_internal.h index 487f586..51b5daf 100644 --- a/src/tpl_internal.h +++ b/src/tpl_internal.h @@ -59,7 +59,8 @@ struct _tpl_surface_backend tpl_bool_t (*validate)(tpl_surface_t *surface); tbm_surface_h (*dequeue_buffer)(tpl_surface_t *surface); - void (*enqueue_buffer)(tpl_surface_t *surface, tbm_surface_h tbm_surface); + void (*enqueue_buffer)(tpl_surface_t *surface, tbm_surface_h tbm_surface, + int num_rects, const int *rects); }; struct _tpl_object @@ -95,10 +96,7 @@ struct _tpl_surface tpl_surface_type_t type; tbm_format format; int width, height; - int post_interval; - tpl_region_t damage; - int dump_count; tpl_surface_backend_t backend; }; @@ -176,15 +174,6 @@ void __tpl_surface_init_backend_wayland(tpl_surface_backend_t *backend); void __tpl_surface_init_backend_x11_dri2(tpl_surface_backend_t *backend); void __tpl_surface_init_backend_x11_dri3(tpl_surface_backend_t *backend); -/* Region functions. */ -void __tpl_region_init(tpl_region_t *region); -void __tpl_region_fini(tpl_region_t *region); -tpl_region_t * __tpl_region_alloc(); -void __tpl_region_free(tpl_region_t **region); -tpl_bool_t __tpl_region_is_empty(const tpl_region_t *region); -tpl_bool_t __tpl_region_copy(tpl_region_t *dst, const tpl_region_t *src); -tpl_bool_t __tpl_region_set_rects(tpl_region_t *region, int num_rects, const int *rects); - /* OS related functions */ void __tpl_util_sys_yield(void); int __tpl_util_clz(int input); diff --git a/src/tpl_region.c b/src/tpl_region.c deleted file mode 100644 index 3b55268..0000000 --- a/src/tpl_region.c +++ /dev/null @@ -1,110 +0,0 @@ -#include -#include "tpl_internal.h" - -void -__tpl_region_init(tpl_region_t *region) -{ - TPL_ASSERT(region); - - region->num_rects = 0; - - /* tpl_region_t will initially provide TPL_MIN_REGION_RECTS number of - storage space for rects after which heap memory will be allocated - if the number of required space exceeds TPL_MIN_REGION_RECTS - */ - region->rects = ®ion->rects_static[0]; - region->num_rects_allocated = TPL_MIN_REGION_RECTS; - - TPL_LOG(3, "region:%p {%d, %p, %p, %d}", region, region->num_rects, region->rects, - ®ion->rects_static[0], region->num_rects_allocated); -} - -void -__tpl_region_fini(tpl_region_t *region) -{ - TPL_ASSERT(region); - TPL_ASSERT(region->rects); - - TPL_LOG(3, "region:%p {%d, %p, %p, %d}", region, region->num_rects, region->rects, - ®ion->rects_static[0], region->num_rects_allocated); - - if (region->rects != ®ion->rects_static[0]) - free(region->rects); -} - -tpl_region_t * -__tpl_region_alloc() -{ - tpl_region_t *region; - - region = (tpl_region_t *) calloc(1, sizeof(tpl_region_t)); - if (NULL == region) - return NULL; - - __tpl_region_init(region); - - return region; -} - -void -__tpl_region_free(tpl_region_t **region) -{ - TPL_ASSERT(region); - TPL_ASSERT(*region); - - __tpl_region_fini(*region); - free(*region); - - *region = NULL; -} - -tpl_bool_t -__tpl_region_is_empty(const tpl_region_t *region) -{ - TPL_ASSERT(region); - - TPL_LOG(3, "region:%p {%d, %p, %p, %d}", region, region->num_rects, - region->rects, ®ion->rects_static[0], region->num_rects_allocated); - - return (region->num_rects == 0); -} - -tpl_bool_t -__tpl_region_copy(tpl_region_t *dst, const tpl_region_t *src) -{ - TPL_ASSERT(src); - TPL_ASSERT(dst); - - return __tpl_region_set_rects(dst, src->num_rects, src->rects); -} - -tpl_bool_t -__tpl_region_set_rects(tpl_region_t *region, int num_rects, const int *rects) -{ - TPL_ASSERT(region); - TPL_ASSERT(num_rects >= 0); - - TPL_LOG(3, "region:%p {%d, %p, %p, %d}, num_rects:%d, rects:%p", region, - region->num_rects, region->rects, ®ion->rects_static[0], - region->num_rects_allocated, num_rects, rects); - - /* allocate memory if the number of rects exceed the allocated memory */ - if (num_rects > region->num_rects_allocated) - { - if (region->rects != ®ion->rects_static[0]) - free(region->rects); - - region->rects = (int *) malloc(num_rects * 4 * sizeof(int)); - if (NULL == region->rects) - return TPL_FALSE; - - region->num_rects_allocated = num_rects; - } - - region->num_rects = num_rects; - - if (0 < num_rects) - memcpy(region->rects, rects, num_rects * 4 * sizeof(int)); - - return TPL_TRUE; -} diff --git a/src/tpl_surface.c b/src/tpl_surface.c index 58431fb..b18de35 100644 --- a/src/tpl_surface.c +++ b/src/tpl_surface.c @@ -5,8 +5,6 @@ __tpl_surface_fini(tpl_surface_t *surface) { TPL_ASSERT(surface); - __tpl_region_fini(&surface->damage); - surface->backend.fini(surface); } @@ -43,9 +41,6 @@ tpl_surface_create(tpl_display_t *display, tpl_handle_t handle, tpl_surface_type return NULL; } - TPL_LOG(5, "surface->damage:%p {%d, %p, %p, %d}", &surface->damage, surface->damage.num_rects, - surface->damage.rects, &surface->damage.rects_static[0], surface->damage.num_rects_allocated); - if (TPL_TRUE != __tpl_object_init(&surface->base, TPL_OBJECT_SURFACE, __tpl_surface_free)) { TPL_ERR("Failed to initialize surface's base class!"); @@ -61,7 +56,6 @@ tpl_surface_create(tpl_display_t *display, tpl_handle_t handle, tpl_surface_type surface->post_interval = 1; surface->dump_count = 0; - __tpl_region_init(&surface->damage); /* Intialize backend. */ __tpl_surface_init_backend(surface, display->backend.type); @@ -228,7 +222,36 @@ tpl_surface_dequeue_buffer(tpl_surface_t *surface) tpl_bool_t tpl_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface) { + if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type) + { + TPL_ERR("Invalid surface!"); + return TPL_FALSE; + } + TRACE_BEGIN("TPL:POST"); + TPL_OBJECT_LOCK(surface); + + if (NULL == tbm_surface) + { + TPL_OBJECT_UNLOCK(surface); + TRACE_END(); + TPL_ERR("tbm surface is invalid."); + return TPL_FALSE; + } + + /* Call backend post */ + surface->backend.enqueue_buffer(surface, tbm_surface, 0, NULL); + + TPL_OBJECT_UNLOCK(surface); + TRACE_END(); + + return TPL_TRUE; +} + +tpl_bool_t +tpl_surface_enqueue_buffer_with_damage(tpl_surface_t *surface, tbm_surface_h tbm_surface, + int num_rects, const int *rects) +{ if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type) { TPL_ERR("Invalid surface!"); @@ -246,8 +269,8 @@ tpl_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface) return TPL_FALSE; } - /* Call backend post if it has not been called for the frame. */ - surface->backend.enqueue_buffer(surface, tbm_surface); + /* Call backend post */ + surface->backend.enqueue_buffer(surface, tbm_surface, num_rects, rects); TPL_OBJECT_UNLOCK(surface); TRACE_END(); diff --git a/src/tpl_tbm.c b/src/tpl_tbm.c index df29211..479201a 100644 --- a/src/tpl_tbm.c +++ b/src/tpl_tbm.c @@ -231,12 +231,15 @@ __tpl_tbm_surface_fini(tpl_surface_t *surface) } static void -__tpl_tbm_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface) +__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); TPL_ASSERT(surface->display->native_handle); TPL_ASSERT(tbm_surface); + TPL_IGNORE(num_rects); + TPL_IGNORE(rects); tbm_surface_internal_unref(tbm_surface); diff --git a/src/tpl_utils.h b/src/tpl_utils.h index bbd336e..1bd9328 100644 --- a/src/tpl_utils.h +++ b/src/tpl_utils.h @@ -5,7 +5,6 @@ #include #include #include -#define TPL_MIN_REGION_RECTS 16 #if defined(__GNUC__) && __GNUC__ >= 4 # define TPL_API __attribute__ ((visibility("default"))) @@ -487,7 +486,6 @@ __tpl_util_image_dump(const char * func, const void * data, int type, int width, typedef struct _tpl_list_node tpl_list_node_t; typedef struct _tpl_list tpl_list_t; -typedef struct _tpl_region tpl_region_t; enum _tpl_occurrence { @@ -511,23 +509,6 @@ struct _tpl_list int count; }; -/** -* num_rects: number of rects. -* rects: collection of rects where each rect is specified by 4 integers which -* are upper left (x, y) and lower right (x, y) coordinates. -* rects_static: initial storage space for rects. will be replaced by heap heap -* memory if num_rects exceeds TPL_MIN_REGION_RECTS. -* num_rects_allocated: number of rects currently allocated. minimum is -* TPL_MIN_REGION_RECTS (initial value). -*/ -struct _tpl_region -{ - int num_rects; - int *rects; - int rects_static[TPL_MIN_REGION_RECTS * 4]; - int num_rects_allocated; -}; - static TPL_INLINE int __tpl_list_get_count(const tpl_list_t *list) { diff --git a/src/tpl_wayland.c b/src/tpl_wayland.c index ac9a6ce..70bc564 100644 --- a/src/tpl_wayland.c +++ b/src/tpl_wayland.c @@ -383,7 +383,8 @@ __tpl_wayland_surface_fini(tpl_surface_t *surface) } static void -__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); TPL_ASSERT(surface->display); @@ -430,20 +431,20 @@ __tpl_wayland_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_s wl_egl_window->attached_height = wl_egl_window->height; - if (surface->damage.num_rects == 0) + 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); } else { int i; - for (i = 0; i < surface->damage.num_rects; i++) + for (i = 0; i < num_rects; i++) { wl_surface_damage(wl_egl_window->surface, - surface->damage.rects[i * 4 + 0], - surface->damage.rects[i * 4 + 1], - surface->damage.rects[i * 4 + 2], - surface->damage.rects[i * 4 + 3]); + rects[i * 4 + 0], + rects[i * 4 + 1], + rects[i * 4 + 2], + rects[i * 4 + 3]); } } -- 2.7.4 From 275da5ba764dfcc0238490a94455bd96a6db4582 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Wed, 17 Feb 2016 13:36:49 +0900 Subject: [PATCH 13/16] Add enumeration for tpl result type. - Enum TPL_ERROR_NONE : Successful TPL_ERROR_INVALID_PARAMETER : Error, Invalid parameter TPL_ERROR_INVALID_OPERATION : Error, Invalid operation Change-Id: Idc7d9112ccb146b83aa7f96a0a49e3736f0957cf --- src/tpl.c | 38 +++++++++++++------- src/tpl.h | 42 +++++++++++++--------- src/tpl_display.c | 26 +++++++------- src/tpl_gbm.c | 98 +++++++++++++++++++++++++++++++++++---------------- src/tpl_internal.h | 32 ++++++++--------- src/tpl_object.c | 34 +++++++++++------- src/tpl_surface.c | 41 +++++++++++---------- src/tpl_tbm.c | 82 ++++++++++++++++++++++++++++-------------- src/tpl_utils.h | 11 +++--- src/tpl_utils_hlist.c | 18 +++++++--- src/tpl_wayland.c | 90 ++++++++++++++++++++++------------------------ 11 files changed, 308 insertions(+), 204 deletions(-) diff --git a/src/tpl.c b/src/tpl.c index 2b2feef..59b5ed5 100644 --- a/src/tpl.c +++ b/src/tpl.c @@ -11,17 +11,20 @@ struct _tpl_runtime static tpl_runtime_t *runtime = NULL; static pthread_mutex_t runtime_mutex = PTHREAD_MUTEX_INITIALIZER; -static tpl_bool_t +static tpl_result_t __tpl_runtime_init() { if (runtime == NULL) { runtime = (tpl_runtime_t *) calloc(1, sizeof(tpl_runtime_t)); if (runtime == NULL) - return TPL_FALSE; + { + TPL_ERR("Failed to allocate new tpl_runtime_t."); + return TPL_ERROR_INVALID_OPERATION; + } } - return TPL_TRUE; + return TPL_ERROR_NONE; } static void __attribute__((destructor)) @@ -135,10 +138,10 @@ __tpl_runtime_find_display(tpl_backend_type_t type, tpl_handle_t native_display) return display; } -tpl_bool_t +tpl_result_t __tpl_runtime_add_display(tpl_display_t *display) { - tpl_bool_t ret; + tpl_result_t ret; tpl_handle_t handle; tpl_backend_type_t type; @@ -150,28 +153,39 @@ __tpl_runtime_add_display(tpl_display_t *display) TPL_ASSERT(0 <= type && TPL_BACKEND_COUNT > type); if (0 != pthread_mutex_lock(&runtime_mutex)) - return TPL_FALSE; + { + TPL_ERR("runtime_mutex pthread_mutex_lock filed."); + return TPL_ERROR_INVALID_OPERATION; + } - if (TPL_TRUE != __tpl_runtime_init()) - return TPL_FALSE; + if (TPL_ERROR_NONE != __tpl_runtime_init()) + { + TPL_ERR("__tpl_runtime_init() failed."); + return TPL_ERROR_INVALID_OPERATION; + } if (NULL == runtime->displays[type]) { runtime->displays[type] = __tpl_hashlist_create(); if (NULL == runtime->displays[type]) - return TPL_FALSE; + { + 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_TRUE != ret) + if (TPL_ERROR_NONE != ret) { + TPL_ERR("__tpl_hashlist_insert failed. list(%p), handle(%d), display(%p)", + runtime->displays[type], handle, display); __tpl_hashlist_destroy(&runtime->displays[type]); - return TPL_FALSE; + return TPL_ERROR_INVALID_OPERATION; } pthread_mutex_unlock(&runtime_mutex); - return TPL_TRUE; + return TPL_ERROR_NONE; } void diff --git a/src/tpl.h b/src/tpl.h index 69c0eba..d8bd293 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -195,6 +195,17 @@ typedef enum } tpl_backend_type_t; /** + * Enumeration for TPL result type. + * + */ +typedef enum +{ + TPL_ERROR_NONE = 0, /* Successfull */ + TPL_ERROR_INVALID_PARAMETER, /* Invalid parmeter */ + TPL_ERROR_INVALID_OPERATION /* Invalid operation */ +} tpl_result_t; + +/** * Increase reference count of a TPL object. * * All TPL objects are reference-counted. They have reference count 1 on @@ -254,7 +265,7 @@ tpl_object_type_t tpl_object_get_type(tpl_object_t *object); * * @see tpl_object_get_user_data() */ -tpl_bool_t tpl_object_set_user_data(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); @@ -321,9 +332,9 @@ tpl_handle_t tpl_display_get_native_handle(tpl_display_t *display); * @param depth_size Size of a pixel in bits (Color depth). * @param native_visual_id Pointer to receive native visual id. * @param is_slow Pointer to receive whether the given config is slow. - * @return TPL_TRUE is the given config is supported, TPL_FALSE otherwise. + * @return TPL_ERROR_NONE is the given config is supported, TPL_ERROR otherwise. */ -tpl_bool_t tpl_display_query_config(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, @@ -342,9 +353,9 @@ tpl_bool_t tpl_display_query_config(tpl_display_t *display, * @param display display to query pixel formats. * @param visual_id Pointer to receive native visual id. * @param alpha_size Size of the alpha component in bits. - * @return TPL_TRUE if the given config has been modified, TPL_FALSE otherwise. + * @return TPL_ERROR_NONE if the given config has been modified, TPL_ERROR otherwise. */ -tpl_bool_t tpl_display_filter_config(tpl_display_t *display, +tpl_result_t tpl_display_filter_config(tpl_display_t *display, int *visual_id, int alpha_size); @@ -405,7 +416,7 @@ 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_bool_t tpl_surface_get_size(tpl_surface_t *surface, +tpl_result_t tpl_surface_get_size(tpl_surface_t *surface, int *width, int *height); @@ -460,7 +471,7 @@ tbm_surface_h tpl_surface_dequeue_buffer(tpl_surface_t *surface); * @param tbm_surface buffer to post. * */ -tpl_bool_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. @@ -482,7 +493,7 @@ tpl_bool_t tpl_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_ * * @see tpl_surface_enqueue_buffer() */ -tpl_bool_t tpl_surface_enqueue_buffer_with_damage(tpl_surface_t *surface, +tpl_result_t tpl_surface_enqueue_buffer_with_damage(tpl_surface_t *surface, tbm_surface_h tbm_surface, int num_rects, const int *rects); @@ -499,8 +510,8 @@ tpl_bool_t tpl_surface_enqueue_buffer_with_damage(tpl_surface_t *surface, * * @see tpl_surface_get_post_interval() */ -tpl_bool_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. @@ -520,9 +531,9 @@ int tpl_surface_get_post_interval(tpl_surface_t *surface); * @param width pointer to receive width of the window. * @param height pointer to receive height of the window. * @param format pointer to receive format of the window. - * @return TPL_TRUE if the window is valid, TPL_FALSE otherwise. + * @return TPL_ERROR_NONE if the window is valid, TPL_ERROR otherwise. */ -tpl_bool_t tpl_display_get_native_window_info(tpl_display_t *display, +tpl_result_t tpl_display_get_native_window_info(tpl_display_t *display, tpl_handle_t window, int *width, int *height, @@ -538,9 +549,9 @@ tpl_bool_t tpl_display_get_native_window_info(tpl_display_t *display, * @param width pointer to receive width of the pixmap. * @param height pointer to receive height of the pixmap. * @param format pointer to receive format of the pixmap. - * @return TPL_TRUE if the pixmap is valid, TPL_FALSE otherwise. + * @return TPL_ERROR_NONE if the pixmap is valid, TPL_ERROR otherwise. */ -tpl_bool_t tpl_display_get_native_pixmap_info(tpl_display_t *display, +tpl_result_t tpl_display_get_native_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, int *width, int *height, @@ -556,7 +567,4 @@ tpl_bool_t tpl_display_get_native_pixmap_info(tpl_display_t *display, tbm_surface_h tpl_display_get_buffer_from_native_pixmap(tpl_display_t *display, tpl_handle_t pixmap); - -void tpl_display_wait_native(tpl_display_t *display); - #endif /* TPL_H */ diff --git a/src/tpl_display.c b/src/tpl_display.c index 311f443..a62174d 100644 --- a/src/tpl_display.c +++ b/src/tpl_display.c @@ -5,7 +5,7 @@ __tpl_display_fini(tpl_display_t *display) { TPL_ASSERT(display); - if (display->backend.fini) + if (display->backend.fini != NULL) display->backend.fini(display); __tpl_runtime_remove_display(display); @@ -24,7 +24,7 @@ tpl_display_t * tpl_display_create(tpl_backend_type_t type, tpl_handle_t native_dpy) { tpl_display_t *display; - tpl_bool_t ret; + tpl_result_t ret; /* Search for an already connected display for the given native display. */ display = __tpl_runtime_find_display(type, native_dpy); @@ -52,7 +52,7 @@ tpl_display_create(tpl_backend_type_t type, tpl_handle_t native_dpy) /* Initialize object base class. */ ret = __tpl_object_init(&display->base, TPL_OBJECT_DISPLAY, __tpl_display_free); - if (TPL_TRUE != ret) + if (TPL_ERROR_NONE != ret) { TPL_ERR("Failed to initialize display's base class!"); free(display); @@ -65,7 +65,7 @@ tpl_display_create(tpl_backend_type_t type, tpl_handle_t native_dpy) /* Initialize backend. */ __tpl_display_init_backend(display, type); - if (!display->backend.init(display)) + if (TPL_ERROR_NONE != display->backend.init(display)) { TPL_ERR("Failed to initialize display's backend!"); tpl_object_unreference((tpl_object_t *) display); @@ -74,7 +74,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_TRUE != ret) + if (TPL_ERROR_NONE != ret) { TPL_ERR("Failed to add display to runtime list!"); tpl_object_unreference((tpl_object_t *) display); @@ -107,7 +107,7 @@ tpl_display_get_native_handle(tpl_display_t *display) return display->native_handle; } -tpl_bool_t +tpl_result_t tpl_display_query_config(tpl_display_t *display, tpl_surface_type_t surface_type, int red_size, @@ -121,45 +121,45 @@ tpl_display_query_config(tpl_display_t *display, if(NULL == display || TPL_TRUE != __tpl_object_is_valid(&display->base) || NULL == display->backend.query_config) { TPL_ERR("display is invalid!"); - return TPL_FALSE; + 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); } -tpl_bool_t +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) { TPL_ERR("display is invalid!"); - return TPL_FALSE; + return TPL_ERROR_INVALID_PARAMETER; } return display->backend.filter_config(display, visual_id, alpha_size); } -tpl_bool_t +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) { if (display->backend.get_window_info == NULL) { TPL_ERR("Backend for display has not been initialized!"); - return TPL_FALSE; + return TPL_ERROR_INVALID_OPERATION; } return display->backend.get_window_info(display, window, width, height, format, depth, a_size); } -tpl_bool_t +tpl_result_t tpl_display_get_native_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, int *width, int *height, tbm_format *format) { if (display->backend.get_pixmap_info == NULL) { TPL_ERR("Backend for display has not been initialized!"); - return TPL_FALSE; + return TPL_ERROR_INVALID_OPERATION; } return display->backend.get_pixmap_info(display, pixmap, width, height, format); diff --git a/src/tpl_gbm.c b/src/tpl_gbm.c index bad80c3..e2cf093 100644 --- a/src/tpl_gbm.c +++ b/src/tpl_gbm.c @@ -92,7 +92,7 @@ __tpl_gbm_display_is_gbm_device(tpl_handle_t native_dpy) return TPL_FALSE; } -static tpl_bool_t +static tpl_result_t __tpl_gbm_display_init(tpl_display_t *display) { tpl_gbm_display_t *gbm_display = NULL; @@ -101,17 +101,17 @@ __tpl_gbm_display_init(tpl_display_t *display) /* Do not allow default display in gbm. */ if (display->native_handle == NULL) - return TPL_FALSE; + return TPL_ERROR_INVALID_PARAMETER; gbm_display = (tpl_gbm_display_t *) calloc(1, sizeof(tpl_gbm_display_t)); if (gbm_display == NULL) - return TPL_FALSE; + 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); display->backend.data = gbm_display; - return TPL_TRUE; + return TPL_ERROR_NONE; } static void @@ -131,7 +131,7 @@ __tpl_gbm_display_fini(tpl_display_t *display) display->backend.data = NULL; } -static tpl_bool_t +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) @@ -153,10 +153,10 @@ __tpl_gbm_display_query_config(tpl_display_t *display, tpl_surface_type_t surfac if (native_visual_id != NULL) *native_visual_id = GBM_FORMAT_ARGB8888; } else - return TPL_FALSE; + return TPL_ERROR_INVALID_PARAMETER; if (is_slow != NULL) *is_slow = TPL_FALSE; - return TPL_TRUE; + return TPL_ERROR_NONE; } if (alpha_size == 0) { @@ -167,17 +167,17 @@ __tpl_gbm_display_query_config(tpl_display_t *display, tpl_surface_type_t surfac if (native_visual_id != NULL) *native_visual_id = GBM_FORMAT_XRGB8888; } else - return TPL_FALSE; + return TPL_ERROR_INVALID_PARAMETER; if (is_slow != NULL) *is_slow = TPL_FALSE; - return TPL_TRUE; + return TPL_ERROR_NONE; } } - return TPL_FALSE; + return TPL_ERROR_INVALID_PARAMETER; } -static tpl_bool_t +static tpl_result_t __tpl_gbm_display_filter_config(tpl_display_t *display, int *visual_id, int alpha_size) { @@ -186,13 +186,13 @@ __tpl_gbm_display_filter_config(tpl_display_t *display, if (visual_id != NULL && *visual_id == GBM_FORMAT_ARGB8888 && alpha_size == 0) { *visual_id = GBM_FORMAT_XRGB8888; - return TPL_TRUE; + return TPL_ERROR_NONE; } - return TPL_FALSE; + return TPL_ERROR_INVALID_PARAMETER; } -static tpl_bool_t +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) { @@ -201,15 +201,20 @@ __tpl_gbm_display_get_window_info(tpl_display_t *display, tpl_handle_t 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) + { + 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); - return TPL_TRUE; + return TPL_ERROR_NONE; } -static tpl_bool_t +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) { @@ -217,13 +222,16 @@ __tpl_gbm_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, tbm_surface = wayland_tbm_server_get_surface(NULL, (struct wl_resource*)pixmap); if (tbm_surface == NULL) - return TPL_FALSE; + { + TPL_ERR("Failed to get tbm_surface_h from native pixmap."); + return TPL_ERROR_INVALID_OPERATION; + } 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_TRUE; + return TPL_ERROR_NONE; } static tbm_surface_h @@ -236,22 +244,25 @@ __tpl_gbm_display_get_buffer_from_native_pixmap(tpl_handle_t pixmap) tbm_surface = wayland_tbm_server_get_surface(NULL, (struct wl_resource*)pixmap); if (tbm_surface == NULL) { - TPL_ERR("Failed to get tbm surface from wayland_tbm."); + TPL_ERR("Failed to get tbm_surface_h from wayland_tbm."); return NULL; } return tbm_surface; } -static tpl_bool_t +static tpl_result_t __tpl_gbm_surface_init(tpl_surface_t *surface) { tpl_gbm_surface_t *tpl_gbm_surface = NULL; TPL_ASSERT(surface); tpl_gbm_surface = (tpl_gbm_surface_t *) calloc(1, sizeof(tpl_gbm_surface_t)); - if (NULL == tpl_gbm_surface) - return TPL_FALSE; + if (tpl_gbm_surface == NULL) + { + TPL_ERR("Failed to allocate new gbm backend surface."); + return TPL_ERROR_INVALID_OPERATION; + } surface->backend.data = (void *)tpl_gbm_surface; tpl_gbm_surface->tbm_queue = NULL; @@ -261,27 +272,38 @@ __tpl_gbm_surface_init(tpl_surface_t *surface) { 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) + { + TPL_ERR("Failed to get tbm_surface_queue from gbm_surface."); + goto error; + } - if (TPL_TRUE != __tpl_gbm_display_get_window_info(surface->display, surface->native_handle, + if (TPL_ERROR_NONE != __tpl_gbm_display_get_window_info(surface->display, surface->native_handle, &surface->width, &surface->height, NULL, 0, 0)) + { + 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_TRUE; + return TPL_ERROR_NONE; } else if (surface->type == TPL_SURFACE_TYPE_PIXMAP) { - if (TPL_TRUE != __tpl_gbm_display_get_pixmap_info(surface->display, surface->native_handle, + if (TPL_ERROR_NONE != __tpl_gbm_display_get_pixmap_info(surface->display, surface->native_handle, &surface->width, &surface->height, NULL)) + { + TPL_ERR("Failed to get native pixmap info."); goto error; + } - return TPL_TRUE; + return TPL_ERROR_NONE; } error: free(tpl_gbm_surface); - return TPL_FALSE; + return TPL_ERROR_INVALID_OPERATION; } static void @@ -305,7 +327,7 @@ __tpl_gbm_surface_fini(tpl_surface_t *surface) surface->backend.data = NULL; } -static void +static tpl_result_t __tpl_gbm_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface, int num_rects, const int *rects) { @@ -319,14 +341,28 @@ __tpl_gbm_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surfa 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); + return TPL_ERROR_INVALID_PARAMETER; + } tbm_surface_internal_unref(tbm_surface); - if (gbm_surface->tbm_queue) + if (gbm_surface->tbm_queue == NULL) { - tbm_surface_queue_enqueue(gbm_surface->tbm_queue, tbm_surface); - TPL_LOG(6, "tbm_surface ENQUEUED!!"); + 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) + { + TPL_ERR("tbm_surface_queue_enqueue failed. tbm_surface_queue(%p) tbm_surface(%p)", + gbm_surface->tbm_queue, tbm_surface); + return TPL_ERROR_INVALID_PARAMETER; + } + + return TPL_ERROR_NONE; } static tpl_bool_t diff --git a/src/tpl_internal.h b/src/tpl_internal.h index 51b5daf..6df9739 100644 --- a/src/tpl_internal.h +++ b/src/tpl_internal.h @@ -31,18 +31,18 @@ struct _tpl_display_backend tpl_backend_type_t type; void *data; - tpl_bool_t (*init)(tpl_display_t *display); + tpl_result_t (*init)(tpl_display_t *display); void (*fini)(tpl_display_t *display); - tpl_bool_t (*query_config)(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_bool_t (*filter_config)(tpl_display_t *display, int *visual_id, int alpha_bits); + tpl_result_t (*filter_config)(tpl_display_t *display, int *visual_id, int alpha_bits); - tpl_bool_t (*get_window_info)(tpl_display_t *display, tpl_handle_t window, + 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_bool_t (*get_pixmap_info)(tpl_display_t *display, tpl_handle_t pixmap, + 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); @@ -53,13 +53,13 @@ struct _tpl_surface_backend tpl_backend_type_t type; void *data; - tpl_bool_t (*init)(tpl_surface_t *surface); + 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); - void (*enqueue_buffer)(tpl_surface_t *surface, tbm_surface_h tbm_surface, + tpl_result_t (*enqueue_buffer)(tpl_surface_t *surface, tbm_surface_h tbm_surface, int num_rects, const int *rects); }; @@ -107,7 +107,7 @@ struct _tpl_surface /** brief check wether a TPL object is valid * @param object the TPL object to check - * @return TPL_TRUE on success, TPL_FALSE on error + * @return TPL_ERROR_NONE on success, TPL_ERROR on error */ tpl_bool_t __tpl_object_is_valid(tpl_object_t *object); @@ -115,22 +115,22 @@ tpl_bool_t __tpl_object_is_valid(tpl_object_t *object); * @param object the TPL object to initialize * @param type type of the TPL object * @param free_func customized deallocation routine for this TPL object - * @return TPL_TRUE on success, TPL_FALSE on error + * @return TPL_ERROR_NONE on success, TPL_ERROR on error */ -tpl_bool_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 - * @return TPL_TRUE on success, TPL_FALSE on error + * @return TPL_ERROR_NONE on success, TPL_ERROR on error * @warning this function is automatically called when the reference count reaches 0, therefore it should not be expliclity called */ -tpl_bool_t __tpl_object_fini(tpl_object_t *object); +tpl_result_t __tpl_object_fini(tpl_object_t *object); /** brief lock a TPL object * @param object the TPL object to lock - * @return TPL_TRUE on success, TPL_FALSE on error + * @return TPL_ERROR_NONE on success, TPL_ERROR on error */ -tpl_bool_t __tpl_object_lock(tpl_object_t *object); +tpl_result_t __tpl_object_lock(tpl_object_t *object); /** brief unlock a TPL object * @param object the TPL object to unlock @@ -146,7 +146,7 @@ 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_bool_t __tpl_runtime_add_display(tpl_display_t *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(); @@ -196,7 +196,7 @@ unsigned int __tpl_util_atomic_dec(tpl_util_atomic_uint * const atom ); /* Data structure functions */ tpl_hlist_t * __tpl_hashlist_create(); void __tpl_hashlist_destroy(tpl_hlist_t **list); -tpl_bool_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); void __tpl_hashlist_delete(tpl_hlist_t *list, size_t key); void __tpl_hashlist_do_for_all_nodes(tpl_hlist_t *list, void (*cb_func)(void *)); void * __tpl_hashlist_lookup(tpl_hlist_t *list, size_t key); diff --git a/src/tpl_object.c b/src/tpl_object.c index 43a5443..33f756c 100644 --- a/src/tpl_object.c +++ b/src/tpl_object.c @@ -10,7 +10,7 @@ __tpl_object_is_valid(tpl_object_t *object) return (0 != __tpl_util_atomic_get(&object->reference)); } -tpl_bool_t +tpl_result_t __tpl_object_init(tpl_object_t *object, tpl_object_type_t type, tpl_free_func_t free_func) { TPL_ASSERT(object); @@ -23,33 +23,41 @@ __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)) - return TPL_FALSE; + { + TPL_ERR("tpl_object_t pthread_mutex_init failed."); + return TPL_ERROR_INVALID_OPERATION; + } - return TPL_TRUE; + return TPL_ERROR_NONE; } -tpl_bool_t +tpl_result_t __tpl_object_fini(tpl_object_t *object) { TPL_ASSERT(object); if (0 != pthread_mutex_destroy(&object->mutex)) - return TPL_FALSE; + { + TPL_ERR("tpl_object_t pthread_mutex_destroy failed."); + return TPL_ERROR_INVALID_OPERATION; + } tpl_util_map_fini(&object->user_data_map); - return TPL_TRUE; + return TPL_ERROR_NONE; } -tpl_bool_t +tpl_result_t __tpl_object_lock(tpl_object_t *object) { TPL_ASSERT(object); if (0 != pthread_mutex_lock(&object->mutex)) - return TPL_FALSE; - - return TPL_TRUE; + { + TPL_ERR("tpl_object_t pthread_mutex_lock failed."); + return TPL_ERROR_INVALID_OPERATION; + } + return TPL_ERROR_NONE; } void @@ -118,7 +126,7 @@ tpl_object_get_type(tpl_object_t *object) return object->type; } -tpl_bool_t +tpl_result_t tpl_object_set_user_data(tpl_object_t *object, void *key, void *data, tpl_free_func_t free_func) { tpl_util_key_t _key; @@ -126,7 +134,7 @@ tpl_object_set_user_data(tpl_object_t *object, void *key, void *data, tpl_free_f if (TPL_TRUE != __tpl_object_is_valid(object)) { TPL_ERR("input object is invalid!"); - return TPL_FALSE; + return TPL_ERROR_INVALID_PARAMETER; } __tpl_object_lock(object); @@ -134,7 +142,7 @@ tpl_object_set_user_data(tpl_object_t *object, void *key, void *data, tpl_free_f tpl_util_map_set(&object->user_data_map, _key, data, free_func); __tpl_object_unlock(object); - return TPL_TRUE; + return TPL_ERROR_NONE; } void * diff --git a/src/tpl_surface.c b/src/tpl_surface.c index b18de35..a86cc6d 100644 --- a/src/tpl_surface.c +++ b/src/tpl_surface.c @@ -12,7 +12,6 @@ static void __tpl_surface_free(void *data) { TPL_ASSERT(data); - TPL_LOG(9, "tpl_surface_t(%p)", data); __tpl_surface_fini((tpl_surface_t *) data); free(data); } @@ -41,7 +40,7 @@ tpl_surface_create(tpl_display_t *display, tpl_handle_t handle, tpl_surface_type return NULL; } - if (TPL_TRUE != __tpl_object_init(&surface->base, TPL_OBJECT_SURFACE, __tpl_surface_free)) + if (TPL_ERROR_NONE != __tpl_object_init(&surface->base, TPL_OBJECT_SURFACE, __tpl_surface_free)) { TPL_ERR("Failed to initialize surface's base class!"); free(surface); @@ -60,7 +59,7 @@ tpl_surface_create(tpl_display_t *display, tpl_handle_t handle, tpl_surface_type /* Intialize backend. */ __tpl_surface_init_backend(surface, display->backend.type); - if (NULL == surface->backend.init || TPL_TRUE != surface->backend.init(surface)) + if (NULL == surface->backend.init || TPL_ERROR_NONE != surface->backend.init(surface)) { TPL_ERR("Failed to initialize surface's backend!"); tpl_object_unreference(&surface->base); @@ -106,13 +105,13 @@ tpl_surface_get_type(tpl_surface_t *surface) return surface->type; } -tpl_bool_t +tpl_result_t tpl_surface_get_size(tpl_surface_t *surface, int *width, int *height) { if (NULL == surface) { TPL_ERR("Surface is NULL!"); - return TPL_FALSE; + return TPL_ERROR_INVALID_PARAMETER; } if (width) @@ -121,7 +120,7 @@ tpl_surface_get_size(tpl_surface_t *surface, int *width, int *height) if (height) *height = surface->height; - return TPL_TRUE; + return TPL_ERROR_NONE; } @@ -154,20 +153,20 @@ tpl_surface_validate(tpl_surface_t *surface) return was_valid; } -tpl_bool_t +tpl_result_t tpl_surface_set_post_interval(tpl_surface_t *surface, int interval) { if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type) { TPL_ERR("Invalid surface!"); - return TPL_FALSE; + return TPL_ERROR_INVALID_PARAMETER; } TPL_OBJECT_LOCK(surface); surface->post_interval = interval; TPL_OBJECT_UNLOCK(surface); - return TPL_TRUE; + return TPL_ERROR_NONE; } int @@ -219,13 +218,15 @@ tpl_surface_dequeue_buffer(tpl_surface_t *surface) return tbm_surface; } -tpl_bool_t +tpl_result_t 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) { TPL_ERR("Invalid surface!"); - return TPL_FALSE; + return TPL_ERROR_INVALID_PARAMETER; } TRACE_BEGIN("TPL:POST"); @@ -236,26 +237,28 @@ tpl_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface) TPL_OBJECT_UNLOCK(surface); TRACE_END(); TPL_ERR("tbm surface is invalid."); - return TPL_FALSE; + return TPL_ERROR_INVALID_PARAMETER; } /* Call backend post */ - surface->backend.enqueue_buffer(surface, tbm_surface, 0, NULL); + ret = surface->backend.enqueue_buffer(surface, tbm_surface, 0, NULL); TPL_OBJECT_UNLOCK(surface); TRACE_END(); - return TPL_TRUE; + return ret; } -tpl_bool_t +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 ret = TPL_ERROR_INVALID_OPERATION; + if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type) { TPL_ERR("Invalid surface!"); - return TPL_FALSE; + return TPL_ERROR_INVALID_PARAMETER; } TRACE_BEGIN("TPL:POST"); @@ -266,14 +269,14 @@ tpl_surface_enqueue_buffer_with_damage(tpl_surface_t *surface, tbm_surface_h tbm TPL_OBJECT_UNLOCK(surface); TRACE_END(); TPL_ERR("tbm surface is invalid."); - return TPL_FALSE; + return TPL_ERROR_INVALID_PARAMETER; } /* Call backend post */ - surface->backend.enqueue_buffer(surface, tbm_surface, num_rects, rects); + ret = surface->backend.enqueue_buffer(surface, tbm_surface, num_rects, rects); TPL_OBJECT_UNLOCK(surface); TRACE_END(); - return TPL_TRUE; + return ret; } diff --git a/src/tpl_tbm.c b/src/tpl_tbm.c index 479201a..6d81c01 100644 --- a/src/tpl_tbm.c +++ b/src/tpl_tbm.c @@ -22,7 +22,7 @@ struct _tpl_tbm_surface int dummy; }; -static tpl_bool_t +static tpl_result_t __tpl_tbm_display_init(tpl_display_t *display) { tpl_tbm_display_t *tbm_display = NULL; @@ -36,12 +36,15 @@ __tpl_tbm_display_init(tpl_display_t *display) tbm_display = (tpl_tbm_display_t *) calloc(1, sizeof(tpl_tbm_display_t)); if (tbm_display == NULL) - return TPL_FALSE; + { + TPL_ERR("Failed to allocate memory for new tpl_tbm_display_t."); + return TPL_ERROR_INVALID_OPERATION; + } display->backend.data = tbm_display; display->bufmgr_fd = -1; - return TPL_TRUE; + return TPL_ERROR_NONE; } static void @@ -61,7 +64,7 @@ __tpl_tbm_display_fini(tpl_display_t *display) tbm_bufmgr_deinit((tbm_bufmgr)display->native_handle); } -static tpl_bool_t +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) @@ -82,7 +85,7 @@ __tpl_tbm_display_query_config(tpl_display_t *display, tpl_surface_type_t surfac if (is_slow != NULL) *is_slow = TPL_FALSE; - return TPL_TRUE; + return TPL_ERROR_NONE; } if (alpha_size == 0) { @@ -92,14 +95,14 @@ __tpl_tbm_display_query_config(tpl_display_t *display, tpl_surface_type_t surfac if (is_slow != NULL) *is_slow = TPL_FALSE; - return TPL_TRUE; + return TPL_ERROR_NONE; } } - return TPL_FALSE; + return TPL_ERROR_INVALID_PARAMETER; } -static tpl_bool_t +static tpl_result_t __tpl_tbm_display_filter_config(tpl_display_t *display, int *visual_id, int alpha_size) { @@ -108,13 +111,13 @@ __tpl_tbm_display_filter_config(tpl_display_t *display, if (visual_id != NULL && *visual_id == TBM_FORMAT_ARGB8888 && alpha_size == 0) { *visual_id = TBM_FORMAT_XRGB8888; - return TPL_TRUE; + return TPL_ERROR_NONE; } - return TPL_FALSE; + return TPL_ERROR_INVALID_PARAMETER; } -static tpl_bool_t +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) { @@ -122,6 +125,11 @@ __tpl_tbm_display_get_window_info(tpl_display_t *display, tpl_handle_t window, TPL_ASSERT(window); tbm_surface_queue_h surf_queue = (tbm_surface_queue_h)window; + if (surf_queue == NULL) + { + TPL_ERR("Native widow(%p) is invalid.", window); + return TPL_ERROR_INVALID_PARAMETER; + } if (width != NULL) *width = tbm_surface_queue_get_width(surf_queue); @@ -130,10 +138,10 @@ __tpl_tbm_display_get_window_info(tpl_display_t *display, tpl_handle_t window, if (format != NULL) *format = tbm_surface_queue_get_format(surf_queue); - return TPL_TRUE; + return TPL_ERROR_NONE; } -static tpl_bool_t +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) { @@ -141,7 +149,10 @@ __tpl_tbm_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, tbm_surface = (tbm_surface_h)pixmap; if (tbm_surface == NULL) - return TPL_FALSE; + { + TPL_ERR("Native pixmap(%p) is invalid.", pixmap); + return TPL_ERROR_INVALID_PARAMETER; + } if (width) *width = tbm_surface_get_width(tbm_surface); @@ -150,7 +161,7 @@ __tpl_tbm_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, if (format) *format = tbm_surface_get_format(tbm_surface); - return TPL_TRUE; + return TPL_ERROR_NONE; } static tbm_surface_h @@ -166,7 +177,7 @@ __tpl_tbm_surface_queue_notify_cb(tbm_surface_queue_h surface_queue, void *data) /* Do something */ } -static tpl_bool_t +static tpl_result_t __tpl_tbm_surface_init(tpl_surface_t *surface) { tpl_tbm_surface_t *tpl_tbm_surface = NULL; @@ -174,39 +185,48 @@ __tpl_tbm_surface_init(tpl_surface_t *surface) tpl_tbm_surface = (tpl_tbm_surface_t *) calloc(1, sizeof(tpl_tbm_surface_t)); if (NULL == tpl_tbm_surface) - return TPL_FALSE; + { + 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_TRUE != __tpl_tbm_display_get_window_info(surface->display, surface->native_handle, + 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); goto error; + } tbm_surface_queue_set_destroy_cb((tbm_surface_queue_h)surface->native_handle, __tpl_tbm_surface_queue_notify_cb, surface); TPL_LOG(3, "window(%p, %p) %dx%d", surface, surface->native_handle, surface->width, surface->height); - return TPL_TRUE; + 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); 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); - return TPL_TRUE; + return TPL_ERROR_NONE; } error: free(tpl_tbm_surface); surface->backend.data = NULL; - return TPL_FALSE; + return TPL_ERROR_INVALID_OPERATION; } static void @@ -230,7 +250,7 @@ __tpl_tbm_surface_fini(tpl_surface_t *surface) surface->backend.data = NULL; } -static void +static tpl_result_t __tpl_tbm_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface, int num_rects, const int *rects) { @@ -245,19 +265,27 @@ __tpl_tbm_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surfa if (surface->type == TPL_SURFACE_TYPE_PIXMAP) { - TPL_WARN("Pixmap cannot post(%p, %p)",surface, surface->native_handle); - return; + 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) + { + TPL_ERR("tbm_surface_queue is invalid."); + return TPL_ERROR_INVALID_PARAMETER; + } - if (tbm_queue) + if (tbm_surface_queue_enqueue(tbm_queue, tbm_surface) != TBM_SURFACE_QUEUE_ERROR_NONE) { - tbm_surface_queue_enqueue(tbm_queue, tbm_surface); - TPL_LOG(6, "tbm_surface ENQUEUED!!"); + TPL_ERR("tbm_surface_queue_enqueue failed. tbm_queue(%p) tbm_surface(%p)", + tbm_queue, tbm_surface); + return TPL_ERROR_INVALID_OPERATION; } + + return TPL_ERROR_NONE; } static tpl_bool_t diff --git a/src/tpl_utils.h b/src/tpl_utils.h index 1bd9328..98aae4d 100644 --- a/src/tpl_utils.h +++ b/src/tpl_utils.h @@ -686,12 +686,15 @@ __tpl_list_remove(tpl_list_node_t *node, tpl_free_func_t func) free(node); } -static TPL_INLINE tpl_bool_t +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) - return TPL_FALSE; + { + TPL_ERR("Failed to allocate new tpl_list_node_t."); + return TPL_ERROR_INVALID_OPERATION; + } node->data = data; node->list = pos->list; @@ -704,7 +707,7 @@ __tpl_list_insert(tpl_list_node_t *pos, void *data) pos->list->count++; - return TPL_TRUE; + return TPL_ERROR_NONE; } static TPL_INLINE void @@ -795,7 +798,7 @@ __tpl_list_push_front(tpl_list_t *list, void *data) __tpl_list_insert(&list->head, data); } -static TPL_INLINE tpl_bool_t +static TPL_INLINE tpl_result_t __tpl_list_push_back(tpl_list_t *list, void *data) { TPL_ASSERT(list); diff --git a/src/tpl_utils_hlist.c b/src/tpl_utils_hlist.c index e44a24e..d16a881 100644 --- a/src/tpl_utils_hlist.c +++ b/src/tpl_utils_hlist.c @@ -118,7 +118,9 @@ tpl_hlist_node_t * __tpl_hlist_get_tail_node(tpl_hlist_t *list, size_t key) hash = CALC_HASH(key); if (__tpl_hlist_empty(&list->heads[hash])) + { return NULL; + } /* iterate until next node is NULL */ for (pos = list->heads[hash].first; pos->next; pos = pos->next); @@ -181,24 +183,30 @@ void __tpl_hashlist_destroy(tpl_hlist_t **list) *list = NULL; } -tpl_bool_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_FALSE; + 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) - return TPL_FALSE; + { + 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) - return TPL_FALSE; + { + TPL_ERR("Failed to allocate new tpl_hlist_node_t."); + return TPL_ERROR_INVALID_OPERATION; + } hash = CALC_HASH(key); __tpl_hlist_init_node(new_node); @@ -208,7 +216,7 @@ tpl_bool_t __tpl_hashlist_insert(tpl_hlist_t *list, size_t key, void *data) /* add new node to head */ __tpl_hlist_add_head(new_node, &list->heads[hash]); - return TPL_TRUE; + return TPL_ERROR_NONE; } void __tpl_hashlist_delete(tpl_hlist_t *list, size_t key) diff --git a/src/tpl_wayland.c b/src/tpl_wayland.c index 70bc564..c7b7e57 100644 --- a/src/tpl_wayland.c +++ b/src/tpl_wayland.c @@ -135,7 +135,7 @@ __tpl_wayland_display_roundtrip(tpl_display_t *display) return ret; } -static tpl_bool_t +static tpl_result_t __tpl_wayland_display_init(tpl_display_t *display) { tpl_wayland_display_t *wayland_display = NULL; @@ -144,11 +144,17 @@ __tpl_wayland_display_init(tpl_display_t *display) /* Do not allow default display in wayland. */ if (display->native_handle == NULL) - return TPL_FALSE; + { + 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) - return TPL_FALSE; + { + TPL_ERR("Failed to allocate memory for new tpl_wayland_display_t."); + return TPL_ERROR_INVALID_OPERATION; + } display->backend.data = wayland_display; display->bufmgr_fd = -1; @@ -157,7 +163,6 @@ __tpl_wayland_display_init(tpl_display_t *display) { 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) { TPL_ERR("Wayland TBM initialization failed!"); @@ -166,18 +171,25 @@ __tpl_wayland_display_init(tpl_display_t *display) wayland_display->wl_queue = wl_display_create_queue(wl_dpy); if (NULL == 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) + { + 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 goto free_wl_display; - return TPL_TRUE; + return TPL_ERROR_NONE; + destroy_queue: wl_event_queue_destroy(wayland_display->wl_queue); free_wl_display: @@ -186,7 +198,7 @@ free_wl_display: free(wayland_display); display->backend.data = NULL; } - return TPL_FALSE; + return TPL_ERROR_INVALID_OPERATION; } static void @@ -205,7 +217,7 @@ __tpl_wayland_display_fini(tpl_display_t *display) display->backend.data = NULL; } -static tpl_bool_t +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) @@ -222,29 +234,29 @@ __tpl_wayland_display_query_config(tpl_display_t *display, tpl_surface_type_t su { if (native_visual_id != NULL) *native_visual_id = TBM_FORMAT_ARGB8888; if (is_slow != NULL) *is_slow = TPL_FALSE; - return TPL_TRUE; + 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; - return TPL_TRUE; + return TPL_ERROR_NONE; } } - return TPL_FALSE; + return TPL_ERROR_INVALID_PARAMETER; } -static tpl_bool_t +static tpl_result_t __tpl_wayland_display_filter_config(tpl_display_t *display, int *visual_id, int alpha_size) { TPL_IGNORE(display); TPL_IGNORE(visual_id); TPL_IGNORE(alpha_size); - return TPL_TRUE; + return TPL_ERROR_NONE; } -static tpl_bool_t +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) { @@ -272,26 +284,28 @@ __tpl_wayland_display_get_window_info(tpl_display_t *display, tpl_handle_t windo if (width != NULL) *width = wl_egl_window->width; if (height != NULL) *height = wl_egl_window->height; - return TPL_TRUE; + return TPL_ERROR_NONE; } static void __cb_client_window_resize_callback(struct wl_egl_window* wl_egl_window, void* private); -static tpl_bool_t +static tpl_result_t __tpl_wayland_surface_init(tpl_surface_t *surface) { tpl_wayland_surface_t *wayland_surface = NULL; struct wl_egl_window *wl_egl_window = (struct wl_egl_window *)surface->native_handle; - TPL_ASSERT(surface); TPL_ASSERT(surface->type == TPL_SURFACE_TYPE_WINDOW); TPL_ASSERT(surface->native_handle); wayland_surface = (tpl_wayland_surface_t *) calloc(1, sizeof(tpl_wayland_surface_t)); if (NULL == wayland_surface) - return TPL_FALSE; + { + TPL_ERR("Failed to allocate memory for new tpl_wayland_surface_t."); + return TPL_ERROR_INVALID_OPERATION; + } surface->backend.data = (void *)wayland_surface; wayland_surface->tbm_queue = NULL; @@ -304,13 +318,12 @@ __tpl_wayland_surface_init(tpl_surface_t *surface) wl_egl_window->height, surface->format, 0); - TPL_LOG(9, "tbm_surface_queue_create!! || wl_egl_window(%p)| tbm_queue(%p)", - wl_egl_window, wayland_surface->tbm_queue); if (wayland_surface->tbm_queue == NULL) { TPL_ERR("TBM surface queue creation failed!"); - goto error; + free(wayland_surface); + return TPL_ERROR_INVALID_OPERATION; } surface->width = wl_egl_window->width; @@ -320,12 +333,8 @@ __tpl_wayland_surface_init(tpl_surface_t *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); - return TPL_TRUE; -error: - free(wayland_surface); - - return TPL_FALSE; + return TPL_ERROR_NONE; } static void @@ -352,8 +361,6 @@ __tpl_wayland_surface_fini(tpl_surface_t *surface) TPL_ASSERT(wl_egl_window); /* TPL_ASSERT(wl_egl_window->surface); */ /* to be enabled once evas/gl patch is in place */ - TPL_LOG(9, "tpl_surface_t(%p)| wl_egl_window(%p)| wayland_surface(%p)", - surface, wl_egl_window, wayland_surface); wl_egl_window->private = NULL; /* Detach all pending buffers */ @@ -368,9 +375,6 @@ __tpl_wayland_surface_fini(tpl_surface_t *surface) wl_display_flush(surface->display->native_handle); __tpl_wayland_display_roundtrip(surface->display); - TPL_LOG(9, "tbm_surface_queue_destroy || wl_egl_window(%p)| tbm_queue(%p)", - wl_egl_window, wayland_surface->tbm_queue); - if (wayland_surface->current_buffer) tbm_surface_internal_unref(wayland_surface->current_buffer); @@ -382,7 +386,7 @@ __tpl_wayland_surface_fini(tpl_surface_t *surface) surface->backend.data = NULL; } -static void +static tpl_result_t __tpl_wayland_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_surface, int num_rects, const int *rects) { @@ -409,19 +413,23 @@ __tpl_wayland_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_s wl_egl_window = (struct wl_egl_window *)surface->native_handle; tbm_surface_internal_unref(tbm_surface); - TPL_LOG(9, "tbm_surface(%p) ----------", tbm_surface); tsq_err = tbm_surface_queue_enqueue(wayland_surface->tbm_queue, tbm_surface); 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) + { TPL_ERR("Failed to acquire tbm_surface. | tsq_err = %d", tsq_err); + return TPL_ERROR_INVALID_OPERATION; + } tbm_surface_internal_ref(tbm_surface); - TPL_LOG(9, "tbm_surface(%p) ++++++++++",tbm_surface); wl_surface_attach(wl_egl_window->surface, (void *)wayland_buffer->wl_proxy, wl_egl_window->dx, @@ -430,7 +438,6 @@ __tpl_wayland_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_s wl_egl_window->attached_width = wl_egl_window->width; wl_egl_window->attached_height = wl_egl_window->height; - if (num_rects < 1 || rects == NULL) { wl_surface_damage(wl_egl_window->surface, @@ -459,6 +466,8 @@ __tpl_wayland_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_h tbm_s wl_surface_commit(wl_egl_window->surface); wl_display_flush(surface->display->native_handle); + + return TPL_ERROR_NONE; } static tpl_bool_t @@ -479,7 +488,6 @@ static tbm_surface_h __tpl_wayland_surface_dequeue_buffer(tpl_surface_t *surface) { TPL_ASSERT(surface); - TPL_ASSERT(surface->native_handle); TPL_ASSERT(surface->backend.data); TPL_ASSERT(surface->display); @@ -487,7 +495,6 @@ __tpl_wayland_surface_dequeue_buffer(tpl_surface_t *surface) 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_egl_window *wl_egl_window = (struct wl_egl_window *)surface->native_handle; struct wl_proxy *wl_proxy = NULL; tbm_surface_queue_error_e tsq_err = 0; @@ -514,7 +521,6 @@ __tpl_wayland_surface_dequeue_buffer(tpl_surface_t *surface) tbm_surface_internal_ref(tbm_surface); - TPL_LOG(9, "tbm_surface(%p) ++++++++++",tbm_surface); if ((wayland_buffer = __tpl_wayland_get_wayland_buffer_from_tbm_surface(tbm_surface)) != NULL) { return tbm_surface; @@ -531,8 +537,6 @@ __tpl_wayland_surface_dequeue_buffer(tpl_surface_t *surface) wl_proxy = (struct wl_proxy *)wayland_tbm_client_create_buffer( wayland_display->wl_tbm_client, tbm_surface); - TPL_LOG(9, "wl_proxy(%p)CREATED| wl_egl_window(%p)| tbm_surface(%p)| wayland_surface(%p)", - wl_proxy, wl_egl_window, tbm_surface, wayland_surface); if (wl_proxy == NULL) { TPL_ERR("Failed to create TBM client buffer!"); @@ -568,8 +572,6 @@ __tpl_wayland_buffer_free(tpl_wayland_buffer_t *wayland_buffer) wl_display_flush((struct wl_display *)wayland_buffer->display->native_handle); - TPL_LOG(9, "wl_proxy(%p) DESTROYED| wayland_surface(%p)| wayland_buffer(%p)", - wayland_buffer->wl_proxy, wayland_buffer->wayland_surface, wayland_buffer); if (wayland_buffer->wl_proxy != NULL) wayland_tbm_client_destroy_buffer(wayland_display->wl_tbm_client, (void *)wayland_buffer->wl_proxy); @@ -672,7 +674,6 @@ __cb_client_buffer_release_callback(void *data, struct wl_proxy *proxy) tbm_surface_internal_unref(tbm_surface); - TPL_LOG(9, "tbm_surface(%p) ----------",tbm_surface); tbm_surface_queue_release(wayland_surface->tbm_queue, tbm_surface); } } @@ -702,14 +703,9 @@ __cb_client_window_resize_callback(struct wl_egl_window* wl_egl_window, void* pr width != tbm_surface_queue_get_width(wayland_surface->tbm_queue) || height != tbm_surface_queue_get_height(wayland_surface->tbm_queue)) { - TPL_LOG(9, "RESIZE!!|tpl_surface_t(%p)| wl_egl_window(%p)| wayland_surface(%p)", - surface, wl_egl_window, wayland_surface); if (wayland_surface->current_buffer != NULL) tbm_surface_internal_unref(wayland_surface->current_buffer); tbm_surface_queue_reset(wayland_surface->tbm_queue, width, height, format); } - - TPL_LOG(9, "tpl_surface_t(%p)| wl_egl_window(%p)| wayland_surface(%p)", - surface, wl_egl_window, wayland_surface); } -- 2.7.4 From bc0ad21111fda197697985f7792a917637e0e3e3 Mon Sep 17 00:00:00 2001 From: "Mun, Gwan-gyeong" Date: Thu, 18 Feb 2016 02:25:48 +0900 Subject: [PATCH 14/16] 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 From 9462686fc86a7789b977085a3455e1b438eeceda Mon Sep 17 00:00:00 2001 From: "Mun, Gwan-gyeong" Date: Thu, 18 Feb 2016 11:41:32 +0900 Subject: [PATCH 15/16] Increment version to 1.0.0 Add coding style guide. Change-Id: I30511764157000b01db040e8b35ba4a85aea0a7b --- coding_guide.txt | 52 +++++++++++++++++++++++++++++++++++++++++------ packaging/libtpl-egl.spec | 6 +++--- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/coding_guide.txt b/coding_guide.txt index 2b6a927..9643ec5 100644 --- a/coding_guide.txt +++ b/coding_guide.txt @@ -1,8 +1,48 @@ -1. Function names +1. Coding Style + + You should follow the style of the file you're editing. In general, we + try to follow the rules below. + + 1) indent with tabs, and a tab is always 8 characters wide + 2) opening braces are on the same line as the if statement + 3) no braces in an if-body with just one statement + 4) if one of the branches of an if-else codition has braces, than the + other branch should also have braces + 5) there is always an empty line between variable declarations and the code + + static int + my_function(void) + { + int a = 0; + if (a) + b(); + else + c(); + if (a) { + b(); + c(); + } else { + d(); + } + } + + 6) lines should be less than 80 characters wide + 7) when breaking lines with functions calls, the parameters are aligned + with the opening parenthesis + 8) when assigning a variable with the result of a function call, if the + line would be longer we break it around the equal '=' sign if it makes sense + + long_variable_name = + function_with_a_really_long_name(parameter1, parameter2, + parameter3, parameter4); + x = function_with_a_really_long_name(parameter1, parameter2, + parameter3, parameter4); + +2. Function names 1) all internal function names should start with '__tpl' 2) externally exposed function names should start with 'tpl' -2. Input argument checking +3. Input argument checking 1) internal functions should TPL_ASSERT on non-null for all pointer type argumentxs Exception: @@ -17,12 +57,12 @@ 4) when externally exposed function is return due to error, TPL_ERR should be called with appropriate error message -3. Function calling +4. Function calling 1) before calling internal function, caller function *MUST* check for value validity before passing it to the callee (internal functions do not check for input validity) -4. Return value +5. Return value 1) functions should return a value Exception: - failure is ignorable @@ -33,11 +73,11 @@ 4) other functions which return values useful to other callee may return that value -5. Documentation +6. Documentation 1) *ALL* functions in libtpl-egl *MUST* be documented in Doxygen format 2) functions *MUST* have at least brief, param, and return sections -6. Enumeration type +7. Enumeration type 1) *ALL* enums *MUST* start with error code, 'xxx_ERROR' and assigned value of -1 2) *ALL* enums *MUST* have identifier named 'xxx_MAX' to signify the end diff --git a/packaging/libtpl-egl.spec b/packaging/libtpl-egl.spec index 18901c8..f9a868d 100644 --- a/packaging/libtpl-egl.spec +++ b/packaging/libtpl-egl.spec @@ -1,7 +1,7 @@ #TPL VERSION MACROS -%define TPL_VER_MAJOR 0 -%define TPL_VER_MINOR 8 -%define TPL_RELEASE 9 +%define TPL_VER_MAJOR 1 +%define TPL_VER_MINOR 0 +%define TPL_RELEASE 0 %define TPL_VERSION %{TPL_VER_MAJOR}.%{TPL_VER_MINOR} %define TPL_VER_FULL %{TPL_VERSION}.%{TPL_RELEASE} -- 2.7.4 From a2c0cd9a2a21afc14630f230b2ee79f221c97da0 Mon Sep 17 00:00:00 2001 From: "Mun, Gwan-gyeong" Date: Fri, 19 Feb 2016 14:37:35 +0900 Subject: [PATCH 16/16] Apply coding style Change-Id: I5c3d76f1ba6fcabb98d3d472a9985eb7887ba86a --- src/tpl.c | 18 +- src/tpl.h | 49 ++-- src/tpl_display.c | 23 +- src/tpl_gbm.c | 58 ++-- src/tpl_internal.h | 28 +- src/tpl_object.c | 6 +- src/tpl_surface.c | 9 +- src/tpl_tbm.c | 28 +- src/tpl_utils.h | 67 ++--- src/tpl_utils_hlist.c | 9 +- src/tpl_utils_map.c | 18 +- src/tpl_wayland.c | 109 +++---- src/tpl_x11_common.c | 301 +++++++++---------- src/tpl_x11_dri2.c | 146 ++++------ src/tpl_x11_dri3.c | 654 ++++++++++++++++++------------------------ src/tpl_x11_internal.h | 17 +- src/wayland-egl/wayland-egl.c | 21 +- tc/src/main.c | 347 +++++++++++----------- tc/src/tpl_test_buffer.c | 221 +++++++------- tc/src/tpl_test_display.c | 188 ++++++------ tc/src/tpl_test_object.c | 80 +++--- tc/src/tpl_test_surface.c | 229 +++++++-------- tc/src/tpl_test_util.h | 155 +++++----- 23 files changed, 1294 insertions(+), 1487 deletions(-) diff --git a/src/tpl.c b/src/tpl.c index c12b934..9946217 100644 --- a/src/tpl.c +++ b/src/tpl.c @@ -61,7 +61,7 @@ __tpl_util_clz(int val) } int -__tpl_util_atomic_get(const tpl_util_atomic_uint * const atom) +__tpl_util_atomic_get(const tpl_util_atomic_uint *const atom) { unsigned int ret; @@ -75,7 +75,7 @@ __tpl_util_atomic_get(const tpl_util_atomic_uint * const atom) } void -__tpl_util_atomic_set(tpl_util_atomic_uint * const atom, unsigned int val) +__tpl_util_atomic_set(tpl_util_atomic_uint *const atom, unsigned int val) { TPL_ASSERT(atom); @@ -85,7 +85,7 @@ __tpl_util_atomic_set(tpl_util_atomic_uint * const atom, unsigned int val) } unsigned int -__tpl_util_atomic_inc(tpl_util_atomic_uint * const atom ) +__tpl_util_atomic_inc(tpl_util_atomic_uint *const atom ) { TPL_ASSERT(atom); @@ -93,7 +93,7 @@ __tpl_util_atomic_inc(tpl_util_atomic_uint * const atom ) } unsigned int -__tpl_util_atomic_dec( tpl_util_atomic_uint * const atom ) +__tpl_util_atomic_dec( tpl_util_atomic_uint *const atom ) { TPL_ASSERT(atom); @@ -114,7 +114,7 @@ __tpl_runtime_find_display(tpl_backend_type_t type, tpl_handle_t native_display) 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 { int i; @@ -122,7 +122,7 @@ __tpl_runtime_find_display(tpl_backend_type_t type, tpl_handle_t native_display) 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; } @@ -166,7 +166,7 @@ __tpl_runtime_add_display(tpl_display_t *display) } ret = __tpl_hashlist_insert(runtime->displays[type], - (size_t) handle, (void *) display); + (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); @@ -190,7 +190,7 @@ __tpl_runtime_remove_display(tpl_display_t *display) if (type != TPL_BACKEND_UNKNOWN) { if (runtime != NULL && runtime->displays[type] != NULL) __tpl_hashlist_delete(runtime->displays[type], - (size_t) handle); + (size_t) handle); } pthread_mutex_unlock(&runtime_mutex); @@ -216,7 +216,7 @@ __tpl_runtime_flush_all_display() 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); diff --git a/src/tpl.h b/src/tpl.h index 62004d2..b81f4ae 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -76,7 +76,7 @@ typedef unsigned int tpl_bool_t; * Represent a handle to a native object like pixmap, window, wl_display and * etc. */ -typedef void * tpl_handle_t; +typedef void *tpl_handle_t; /** * Structure containing function pointers to DDK's EGL layer. @@ -212,7 +212,8 @@ typedef enum { * @see tpl_object_unreference() * @see tpl_object_get_reference() */ -int tpl_object_reference(tpl_object_t *object); +int +tpl_object_reference(tpl_object_t *object); /** * Decrease reference count of a TPL object. @@ -223,7 +224,8 @@ int tpl_object_reference(tpl_object_t *object); * @see tpl_object_reference() * @see tpl_object_get_reference() */ -int tpl_object_unreference(tpl_object_t *object); +int +tpl_object_unreference(tpl_object_t *object); /** * Get reference count of a TPL object. @@ -234,7 +236,8 @@ int tpl_object_unreference(tpl_object_t *object); * @see tpl_object_reference() * @see tpl_object_get_reference() */ -int tpl_object_get_reference(tpl_object_t *object); +int +tpl_object_get_reference(tpl_object_t *object); /** * Get the type of a TPL object. @@ -260,8 +263,9 @@ tpl_object_type_t tpl_object_get_type(tpl_object_t *object); * * @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. @@ -272,7 +276,8 @@ tpl_result_t tpl_object_set_user_data(tpl_object_t *object, void *key, * * @see tpl_object_set_user_data() */ -void * tpl_object_get_user_data(tpl_object_t *object, void *key); +void * +tpl_object_get_user_data(tpl_object_t *object, void *key); /** * Create TPL display object for the given native display. @@ -297,7 +302,8 @@ tpl_display_create(tpl_backend_type_t type, tpl_handle_t native_dpy); * @param native_dpy handle to the native display. * @return pointer to the display on success, NULL on failure. */ -tpl_display_t * tpl_display_get(tpl_handle_t native_dpy); +tpl_display_t * +tpl_display_get(tpl_handle_t native_dpy); /** * Get the native display handle which the given TPL display is created for. @@ -307,7 +313,8 @@ tpl_display_t * tpl_display_get(tpl_handle_t native_dpy); * * @see tpl_display_get() */ -tpl_handle_t tpl_display_get_native_handle(tpl_display_t *display); +tpl_handle_t +tpl_display_get_native_handle(tpl_display_t *display); /** * Query supported pixel formats for the given TPL display. @@ -328,7 +335,8 @@ tpl_handle_t tpl_display_get_native_handle(tpl_display_t *display); * @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, +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); @@ -345,7 +353,8 @@ tpl_display_query_config(tpl_display_t *display, tpl_surface_type_t surface_type * @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_display_filter_config(tpl_display_t *display, int *visual_id, + int alpha_size); /** * Create a TPL surface for the given native surface. @@ -368,7 +377,8 @@ tpl_surface_create(tpl_display_t *display, tpl_handle_t handle, * * @see tpl_surface_create() */ -tpl_display_t * tpl_surface_get_display(tpl_surface_t *surface); +tpl_display_t * +tpl_surface_get_display(tpl_surface_t *surface); /** * Get the native surface handle of the given TPL surface. @@ -378,7 +388,8 @@ tpl_display_t * tpl_surface_get_display(tpl_surface_t *surface); * * @see tpl_surface_create() */ -tpl_handle_t tpl_surface_get_native_handle(tpl_surface_t *surface); +tpl_handle_t +tpl_surface_get_native_handle(tpl_surface_t *surface); /** * Get the type of the given TPL surface. @@ -388,7 +399,8 @@ tpl_handle_t tpl_surface_get_native_handle(tpl_surface_t *surface); * * @see tpl_surface_create() */ -tpl_surface_type_t tpl_surface_get_type(tpl_surface_t *surface); +tpl_surface_type_t +tpl_surface_get_type(tpl_surface_t *surface); /** * Get the current size of the given TPL surface. @@ -418,7 +430,8 @@ tpl_surface_get_size(tpl_surface_t *surface, int *width, int *height); * * @see tpl_surface_dequeue_buffer() */ -tpl_bool_t tpl_surface_validate(tpl_surface_t *surface); +tpl_bool_t +tpl_surface_validate(tpl_surface_t *surface); /** * Get the buffer of the current frame for the given TPL surface. @@ -440,7 +453,8 @@ tpl_bool_t tpl_surface_validate(tpl_surface_t *surface); * * @see tpl_surface_validate() */ -tbm_surface_h tpl_surface_dequeue_buffer(tpl_surface_t *surface); +tbm_surface_h +tpl_surface_dequeue_buffer(tpl_surface_t *surface); /** * Post a given tbm_surface. @@ -506,7 +520,8 @@ tpl_surface_set_post_interval(tpl_surface_t *surface, int interval); * * @see tpl_surface_set_post_interval() */ -int tpl_surface_get_post_interval(tpl_surface_t *surface); +int +tpl_surface_get_post_interval(tpl_surface_t *surface); /** * Query information on the given native window. diff --git a/src/tpl_display.c b/src/tpl_display.c index c933199..d61bc0f 100644 --- a/src/tpl_display.c +++ b/src/tpl_display.c @@ -38,7 +38,7 @@ tpl_display_create(tpl_backend_type_t type, tpl_handle_t 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)) { + || (TPL_BACKEND_MAX <= type)) { TPL_ERR("Invalid backend type!"); return NULL; } @@ -94,7 +94,7 @@ tpl_display_get(tpl_handle_t native_dpy) tpl_handle_t tpl_display_get_native_handle(tpl_display_t *display) { - if(!display || (__tpl_object_is_valid(&display->base) != TPL_TRUE)) { + if (!display || (__tpl_object_is_valid(&display->base) != TPL_TRUE)) { TPL_ERR("display is invalid!"); return NULL; } @@ -103,27 +103,29 @@ 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, +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 (!display || (__tpl_object_is_valid(&display->base) != TPL_TRUE) - || (!display->backend.query_config)) { + || (!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); + 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) +tpl_display_filter_config(tpl_display_t *display, int *visual_id, + int alpha_size) { if (!display || (__tpl_object_is_valid(&display->base) != TPL_TRUE) - || (!display->backend.filter_config)) { + || (!display->backend.filter_config)) { TPL_ERR("display is invalid!"); return TPL_ERROR_INVALID_PARAMETER; } @@ -142,7 +144,7 @@ tpl_display_get_native_window_info(tpl_display_t *display, tpl_handle_t window, } return display->backend.get_window_info(display, window, width, height, - format, depth, a_size); + format, depth, a_size); } tpl_result_t @@ -158,7 +160,8 @@ 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) +tpl_display_get_buffer_from_native_pixmap(tpl_display_t *display, + tpl_handle_t pixmap) { if (!display->backend.get_buffer_from_native_pixmap) { TPL_ERR("Backend for display has not been initialized!"); diff --git a/src/tpl_gbm.c b/src/tpl_gbm.c index 6d38c75..ba52105 100644 --- a/src/tpl_gbm.c +++ b/src/tpl_gbm.c @@ -57,7 +57,7 @@ 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; + 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); @@ -73,7 +73,7 @@ __tpl_gbm_set_gbm_buffer_to_tbm_surface(tbm_surface_h surface, 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_data_free)__tpl_gbm_buffer_free); tbm_bo_set_user_data(bo, KEY_TPL_GBM_BUFFER, buf); } @@ -136,12 +136,12 @@ __tpl_gbm_display_query_config(tpl_display_t *display, 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))) { + && (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) { + (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; @@ -152,9 +152,9 @@ __tpl_gbm_display_query_config(tpl_display_t *display, } if (alpha_size == 0) { if (gbm_device_is_format_supported( - (struct gbm_device *)display->native_handle, - GBM_FORMAT_XRGB8888, - GBM_BO_USE_RENDERING) == 1) { + (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; @@ -175,7 +175,7 @@ __tpl_gbm_display_filter_config(tpl_display_t *display, int *visual_id, TPL_IGNORE(display); if (visual_id != NULL && *visual_id == GBM_FORMAT_ARGB8888 - && alpha_size == 0) { + && alpha_size == 0) { *visual_id = GBM_FORMAT_XRGB8888; return TPL_ERROR_NONE; } @@ -192,7 +192,8 @@ __tpl_gbm_display_get_window_info(tpl_display_t *display, tpl_handle_t window, 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); + tbm_surface_queue_h surf_queue = (tbm_surface_queue_h)gbm_tbm_get_surface_queue( + gbm_surface); if (!surf_queue) { TPL_ERR("Failed to get tbm_surface_queue from gbm_surface."); return TPL_ERROR_INVALID_OPERATION; @@ -211,7 +212,8 @@ __tpl_gbm_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, { tbm_surface_h tbm_surface = NULL; - tbm_surface = wayland_tbm_server_get_surface(NULL, (struct wl_resource*)pixmap); + tbm_surface = wayland_tbm_server_get_surface(NULL, + (struct wl_resource *)pixmap); if (!tbm_surface) { TPL_ERR("Failed to get tbm_surface_h from native pixmap."); return TPL_ERROR_INVALID_OPERATION; @@ -231,7 +233,8 @@ __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); + tbm_surface = wayland_tbm_server_get_surface(NULL, + (struct wl_resource *)pixmap); if (!tbm_surface) { TPL_ERR("Failed to get tbm_surface_h from wayland_tbm."); return NULL; @@ -257,26 +260,28 @@ __tpl_gbm_surface_init(tpl_surface_t *surface) tpl_gbm_surface->current_buffer = NULL; 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); + 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) { TPL_ERR("Failed to get tbm_surface_queue from gbm_surface."); goto error; } if (__tpl_gbm_display_get_window_info(surface->display, - surface->native_handle, &surface->width, - &surface->height, NULL, 0, 0) != TPL_ERROR_NONE) { + 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); + 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_gbm_display_get_pixmap_info(surface->display, - surface->native_handle, &surface->width, - &surface->height, NULL) != TPL_ERROR_NONE) { + surface->native_handle, &surface->width, + &surface->height, NULL) != TPL_ERROR_NONE) { TPL_ERR("Failed to get native pixmap info."); goto error; } @@ -324,7 +329,7 @@ __tpl_gbm_surface_enqueue_buffer(tpl_surface_t *surface, TPL_LOG(3, "window(%p, %p)", surface, surface->native_handle); - tpl_gbm_surface_t *gbm_surface = (tpl_gbm_surface_t*)surface->backend.data; + tpl_gbm_surface_t *gbm_surface = (tpl_gbm_surface_t *)surface->backend.data; if (!gbm_surface) { TPL_ERR("tpl_gbm_surface_t is invalid. tpl_surface_t(%p)", surface); @@ -340,7 +345,7 @@ __tpl_gbm_surface_enqueue_buffer(tpl_surface_t *surface, } if (tbm_surface_queue_enqueue(gbm_surface->tbm_queue, tbm_surface) - != TBM_SURFACE_QUEUE_ERROR_NONE) { + != 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); return TPL_ERROR_INVALID_PARAMETER; @@ -372,11 +377,11 @@ __tpl_gbm_surface_dequeue_buffer(tpl_surface_t *surface) TPL_ASSERT(surface->display); TPL_ASSERT(surface->display->native_handle); - gbm_surface = (tpl_gbm_surface_t*)surface->backend.data; + gbm_surface = (tpl_gbm_surface_t *)surface->backend.data; tsq_err = tbm_surface_queue_dequeue(gbm_surface->tbm_queue, &tbm_surface); - if(!tbm_surface - && 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) { TPL_ERR("Failed to get tbm_surface from tbm_surface_queue | tsq_err = %d", @@ -448,7 +453,8 @@ __tpl_display_init_backend_gbm(tpl_display_backend_t *backend) 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->get_buffer_from_native_pixmap = + __tpl_gbm_display_get_buffer_from_native_pixmap; } void diff --git a/src/tpl_internal.h b/src/tpl_internal.h index 429040f..5b0fca4 100644 --- a/src/tpl_internal.h +++ b/src/tpl_internal.h @@ -40,9 +40,9 @@ struct _tpl_display_backend { 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, + tpl_handle_t window, int *width, int *height, tbm_format *format, - int depth,int a_size); + 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); @@ -139,7 +139,8 @@ 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_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(); @@ -151,8 +152,10 @@ 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(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); @@ -172,23 +175,24 @@ int __tpl_util_clz(int input); * @param atom storage for the value to retrieve of * @return value stored on success, 0 or error */ -int __tpl_util_atomic_get(const tpl_util_atomic_uint * const atom); +int __tpl_util_atomic_get(const tpl_util_atomic_uint *const atom); /** brief set the atomic variable's value * @param atom storage for the value to set of * @param val the value to set * @return TPL_TRUE on succes, TPL_FALSE on error */ -void __tpl_util_atomic_set(tpl_util_atomic_uint * const atom, unsigned int val); -unsigned int __tpl_util_atomic_inc(tpl_util_atomic_uint * const atom ); -unsigned int __tpl_util_atomic_dec(tpl_util_atomic_uint * const atom ); +void __tpl_util_atomic_set(tpl_util_atomic_uint *const atom, unsigned int val); +unsigned int __tpl_util_atomic_inc(tpl_util_atomic_uint *const atom ); +unsigned int __tpl_util_atomic_dec(tpl_util_atomic_uint *const atom ); /* Data structure functions */ -tpl_hlist_t * __tpl_hashlist_create(); +tpl_hlist_t *__tpl_hashlist_create(); void __tpl_hashlist_destroy(tpl_hlist_t **list); tpl_result_t __tpl_hashlist_insert(tpl_hlist_t *list, size_t key, void *data); void __tpl_hashlist_delete(tpl_hlist_t *list, size_t key); -void __tpl_hashlist_do_for_all_nodes(tpl_hlist_t *list, void (*cb_func)(void *)); -void * __tpl_hashlist_lookup(tpl_hlist_t *list, size_t key); +void __tpl_hashlist_do_for_all_nodes(tpl_hlist_t *list, + void (*cb_func)(void *)); +void *__tpl_hashlist_lookup(tpl_hlist_t *list, size_t key); #endif /* TPL_INTERNAL_H */ diff --git a/src/tpl_object.c b/src/tpl_object.c index d75af47..8e1991d 100644 --- a/src/tpl_object.c +++ b/src/tpl_object.c @@ -11,14 +11,16 @@ __tpl_object_is_valid(tpl_object_t *object) } tpl_result_t -__tpl_object_init(tpl_object_t *object, tpl_object_type_t type, tpl_free_func_t free_func) +__tpl_object_init(tpl_object_t *object, tpl_object_type_t type, + tpl_free_func_t free_func) { TPL_ASSERT(object); TPL_ASSERT(type >= 0 && type < TPL_OBJECT_MAX); object->type = type; object->free = free_func; - tpl_util_map_pointer_init(&object->user_data_map, TPL_OBJECT_BUCKET_BITS, &object->buckets[0]); + tpl_util_map_pointer_init(&object->user_data_map, TPL_OBJECT_BUCKET_BITS, + &object->buckets[0]); __tpl_util_atomic_set(&object->reference, 1); diff --git a/src/tpl_surface.c b/src/tpl_surface.c index 3f19dd6..a17b592 100644 --- a/src/tpl_surface.c +++ b/src/tpl_surface.c @@ -17,7 +17,8 @@ __tpl_surface_free(void *data) } tpl_surface_t * -tpl_surface_create(tpl_display_t *display, tpl_handle_t handle, tpl_surface_type_t type, tbm_format format) +tpl_surface_create(tpl_display_t *display, tpl_handle_t handle, + tpl_surface_type_t type, tbm_format format) { tpl_surface_t *surface; @@ -38,7 +39,7 @@ tpl_surface_create(tpl_display_t *display, tpl_handle_t handle, tpl_surface_type } if (__tpl_object_init(&surface->base, TPL_OBJECT_SURFACE, - __tpl_surface_free) != TPL_ERROR_NONE) { + __tpl_surface_free) != TPL_ERROR_NONE) { TPL_ERR("Failed to initialize surface's base class!"); free(surface); return NULL; @@ -57,7 +58,7 @@ tpl_surface_create(tpl_display_t *display, tpl_handle_t handle, tpl_surface_type __tpl_surface_init_backend(surface, display->backend.type); if ((!surface->backend.init) - || (surface->backend.init(surface) != TPL_ERROR_NONE)) { + || (surface->backend.init(surface) != TPL_ERROR_NONE)) { TPL_ERR("Failed to initialize surface's backend!"); tpl_object_unreference(&surface->base); return NULL; @@ -190,7 +191,7 @@ tpl_surface_dequeue_buffer(tpl_surface_t *surface) tbm_surface = surface->backend.dequeue_buffer(surface); - if(tbm_surface) { + if (tbm_surface) { /* Update size of the surface. */ surface->width = tbm_surface_get_width(tbm_surface); surface->height = tbm_surface_get_height(tbm_surface); diff --git a/src/tpl_tbm.c b/src/tpl_tbm.c index 65cbe6d..64477c8 100644 --- a/src/tpl_tbm.c +++ b/src/tpl_tbm.c @@ -70,8 +70,8 @@ __tpl_tbm_display_query_config(tpl_display_t *display, 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)) { + && 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; @@ -176,16 +176,16 @@ __tpl_tbm_surface_init(tpl_surface_t *surface) 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) { + 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); @@ -193,8 +193,8 @@ __tpl_tbm_surface_init(tpl_surface_t *surface) return TPL_ERROR_NONE; } 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) { + surface->native_handle, &surface->width, + &surface->height, NULL) != TPL_TRUE) { TPL_ERR("Failed to get native pixmap(%p) info.", surface->native_handle); @@ -222,7 +222,7 @@ __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->type == TPL_SURFACE_TYPE_WINDOW) ? "window" : "pixmap"), surface, surface->native_handle); if (surface->type == TPL_SURFACE_TYPE_PIXMAP) @@ -251,7 +251,7 @@ __tpl_tbm_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_internal_unref(tbm_surface); if (surface->type == TPL_SURFACE_TYPE_PIXMAP) { - TPL_ERR("Pixmap cannot post(%p, %p)",surface, + TPL_ERR("Pixmap cannot post(%p, %p)", surface, surface->native_handle); return TPL_ERROR_INVALID_PARAMETER; } @@ -266,7 +266,7 @@ __tpl_tbm_surface_enqueue_buffer(tpl_surface_t *surface, } if (tbm_surface_queue_enqueue(tbm_queue, tbm_surface) - != TBM_SURFACE_QUEUE_ERROR_NONE) { + != TBM_SURFACE_QUEUE_ERROR_NONE) { TPL_ERR("tbm_surface_queue_enqueue failed. tbm_queue(%p) tbm_surface(%p)", tbm_queue, tbm_surface); return TPL_ERROR_INVALID_OPERATION; @@ -301,7 +301,8 @@ __tpl_tbm_surface_dequeue_buffer(tpl_surface_t *surface) 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) { - TPL_ERR("Failed to get tbm_surface from tbm_surface_queue | tsq_err = %d",tsq_err); + TPL_ERR("Failed to get tbm_surface from tbm_surface_queue | tsq_err = %d", + tsq_err); return NULL; } } @@ -344,7 +345,8 @@ __tpl_display_init_backend_tbm(tpl_display_backend_t *backend) 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->get_buffer_from_native_pixmap = + __tpl_tbm_display_get_buffer_from_native_pixmap; } void diff --git a/src/tpl_utils.h b/src/tpl_utils.h index d5e5557..34912ee 100644 --- a/src/tpl_utils.h +++ b/src/tpl_utils.h @@ -256,9 +256,9 @@ typedef union tpl_util_key tpl_util_key_t; 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); + int key0_length, + const tpl_util_key_t key1, + int key1_length); enum _tpl_occurrence { TPL_FIRST, @@ -301,11 +301,14 @@ void tpl_util_map_init(tpl_util_map_t *map, int bucket_bits, tpl_util_key_compare_func_t key_compare_func, void *buckets); -void tpl_util_map_int32_init(tpl_util_map_t *map, int bucket_bits, void *buckets); +void tpl_util_map_int32_init(tpl_util_map_t *map, int bucket_bits, + void *buckets); -void tpl_util_map_int64_init(tpl_util_map_t *map, int bucket_bits, void *buckets); +void tpl_util_map_int64_init(tpl_util_map_t *map, int bucket_bits, + void *buckets); -void tpl_util_map_pointer_init(tpl_util_map_t *map, int bucket_bits, void *buckets); +void tpl_util_map_pointer_init(tpl_util_map_t *map, int bucket_bits, + void *buckets); void tpl_util_map_fini(tpl_util_map_t *map); @@ -637,7 +640,7 @@ tpl_list_pop_back(tpl_list_t *list, tpl_free_func_t func) } static TPL_INLINE int -__tpl_util_image_dump_bmp(const char * file, const void * data, int width, +__tpl_util_image_dump_bmp(const char *file, const void *data, int width, int height) { int i; @@ -666,15 +669,15 @@ __tpl_util_image_dump_bmp(const char * file, const void * data, int width, 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; + unsigned int *blocks; if (data == NULL) return -1; if (width <= 0 || height <= 0) return -1; - FILE * fp = NULL; + FILE *fp = NULL; if ((fp = fopen (file, "wb")) == NULL) { - printf("FILE ERROR:%s\t",strerror(errno)); + printf("FILE ERROR:%s\t", strerror(errno)); return -2; } else { bmpfile_header.filesz = sizeof (bmpfile_magic) + sizeof (bmpfile_header) + @@ -698,8 +701,8 @@ __tpl_util_image_dump_bmp(const char * file, const void * data, int width, return -1; } - blocks = (unsigned int*)data; - for (i=0; iheads[hash].first; pos; pos = pos->next) { if (pos->key == key) - return pos; + return pos; } return NULL; @@ -147,7 +147,8 @@ __tpl_hashlist_create() if (list == NULL) return NULL; - list->heads = (tpl_hlist_head_t *) malloc(sizeof(tpl_hlist_head_t) * NUM_OF_HEADS); + list->heads = (tpl_hlist_head_t *) malloc(sizeof(tpl_hlist_head_t) * + NUM_OF_HEADS); if (list->heads == NULL) { free(list); return NULL; diff --git a/src/tpl_utils_map.c b/src/tpl_utils_map.c index f838570..f5454a4 100644 --- a/src/tpl_utils_map.c +++ b/src/tpl_utils_map.c @@ -97,7 +97,7 @@ __pointer_hash(const tpl_util_key_t key, int key_length) return (int)_key; #else - #error "Not 32 or 64bit system" +#error "Not 32 or 64bit system" #endif return 0; @@ -132,21 +132,21 @@ 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); + __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); + __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); + __pointer_key_compare, buckets); } void @@ -164,11 +164,11 @@ tpl_util_map_create(int bucket_bits, tpl_util_hash_func_t hash_func, int bucket_size = 1 << bucket_bits; map = calloc(1, - sizeof(tpl_util_map_t) + bucket_size * sizeof(tpl_util_map_entry_t *)); + 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); + key_compare_func, map + 1); return map; } @@ -177,21 +177,21 @@ 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); + __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); + __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); + __pointer_key_compare); } void diff --git a/src/tpl_wayland.c b/src/tpl_wayland.c index 935ec82..ccf0c70 100644 --- a/src/tpl_wayland.c +++ b/src/tpl_wayland.c @@ -65,7 +65,7 @@ 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; + 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); @@ -75,14 +75,14 @@ __tpl_wayland_get_wayland_buffer_from_tbm_surface(tbm_surface_h surface) static TPL_INLINE void __tpl_wayland_set_wayland_buffer_to_tbm_surface(tbm_surface_h surface, - tpl_wayland_buffer_t *buf) + tpl_wayland_buffer_t *buf) { 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); + (tbm_data_free)__tpl_wayland_buffer_free); tbm_bo_set_user_data(bo, KEY_TPL_WAYLAND_BUFFER, buf); } @@ -101,7 +101,7 @@ __tpl_wayland_display_is_wl_display(tpl_handle_t native_dpy) } if (strncmp(wl_egl_native_dpy->name, wl_display_interface.name, - strlen(wl_display_interface.name)) == 0) { + strlen(wl_display_interface.name)) == 0) { return TPL_TRUE; } @@ -148,7 +148,8 @@ __tpl_wayland_display_init(tpl_display_t *display) return TPL_ERROR_INVALID_PARAMETER; } - wayland_display = (tpl_wayland_display_t *) calloc(1, sizeof(tpl_wayland_display_t)); + wayland_display = (tpl_wayland_display_t *) calloc(1, + sizeof(tpl_wayland_display_t)); if (!wayland_display) { TPL_ERR("Failed to allocate memory for new tpl_wayland_display_t."); return TPL_ERROR_INVALID_OPERATION; @@ -181,7 +182,7 @@ __tpl_wayland_display_init(tpl_display_t *display) } wl_proxy_set_queue((struct wl_proxy *)wayland_display->wl_registry, - wayland_display->wl_queue); + wayland_display->wl_queue); } else { goto free_wl_display; } @@ -225,8 +226,8 @@ __tpl_wayland_display_query_config(tpl_display_t *display, 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)) { + 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; @@ -282,20 +283,22 @@ __tpl_wayland_display_get_window_info(tpl_display_t *display, } 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) { tpl_wayland_surface_t *wayland_surface = NULL; - struct wl_egl_window *wl_egl_window = (struct wl_egl_window *)surface->native_handle; + struct wl_egl_window *wl_egl_window = (struct wl_egl_window *) + surface->native_handle; TPL_ASSERT(surface); TPL_ASSERT(surface->type == TPL_SURFACE_TYPE_WINDOW); TPL_ASSERT(surface->native_handle); - wayland_surface = (tpl_wayland_surface_t *) calloc(1, sizeof(tpl_wayland_surface_t)); + wayland_surface = (tpl_wayland_surface_t *) calloc(1, + sizeof(tpl_wayland_surface_t)); if (!wayland_surface) { TPL_ERR("Failed to allocate memory for new tpl_wayland_surface_t."); return TPL_ERROR_INVALID_OPERATION; @@ -307,7 +310,7 @@ __tpl_wayland_surface_init(tpl_surface_t *surface) 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); + wl_egl_window->width, wl_egl_window->height, surface->format, 0); if (!wayland_surface->tbm_queue) { TPL_ERR("TBM surface queue creation failed!"); @@ -319,7 +322,7 @@ __tpl_wayland_surface_init(tpl_surface_t *surface) surface->height = wl_egl_window->height; wl_egl_window->private = surface; - wl_egl_window->resize_callback = (void*)__cb_client_window_resize_callback; + 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); @@ -345,7 +348,8 @@ __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) { - struct wl_egl_window *wl_egl_window = (struct wl_egl_window *)surface->native_handle; + struct wl_egl_window *wl_egl_window = (struct wl_egl_window *) + surface->native_handle; TPL_ASSERT(wl_egl_window); /* TPL_ASSERT(wl_egl_window->surface); */ /* to be enabled once evas/gl patch is in place */ @@ -353,9 +357,10 @@ __tpl_wayland_surface_fini(tpl_surface_t *surface) wl_egl_window->private = NULL; /* 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) { + 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_surface_attach(wl_egl_window->surface, NULL, 0, 0); wl_surface_commit(wl_egl_window->surface); @@ -387,9 +392,9 @@ __tpl_wayland_surface_enqueue_buffer(tpl_surface_t *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_display_t *) surface->display->backend.data; tpl_wayland_surface_t *wayland_surface = - (tpl_wayland_surface_t*) surface->backend.data; + (tpl_wayland_surface_t *) surface->backend.data; tpl_wayland_buffer_t *wayland_buffer = NULL; tbm_surface_queue_error_e tsq_err; @@ -404,7 +409,7 @@ __tpl_wayland_surface_enqueue_buffer(tpl_surface_t *surface, if (bo_handle.ptr) TPL_IMAGE_DUMP(bo_handle.ptr, surface->width, surface->height, - surface->dump_count++); + surface->dump_count++); wl_egl_window = (struct wl_egl_window *)surface->native_handle; @@ -425,21 +430,21 @@ __tpl_wayland_surface_enqueue_buffer(tpl_surface_t *surface, 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->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) { 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++) { 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]); } } @@ -450,7 +455,7 @@ __tpl_wayland_surface_enqueue_buffer(tpl_surface_t *surface, 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); + wayland_display->wl_queue); } wl_surface_commit(wl_egl_window->surface); @@ -466,7 +471,7 @@ __tpl_wayland_surface_validate(tpl_surface_t *surface) TPL_ASSERT(surface->backend.data); tpl_wayland_surface_t *wayland_surface = - (tpl_wayland_surface_t*)surface->backend.data; + (tpl_wayland_surface_t *)surface->backend.data; if (wayland_surface->resized) return TPL_FALSE; @@ -483,20 +488,20 @@ __tpl_wayland_surface_dequeue_buffer(tpl_surface_t *surface) 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_surface_t *)surface->backend.data; tpl_wayland_display_t *wayland_display = - (tpl_wayland_display_t*)surface->display->backend.data; + (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) { + wayland_display->wl_queue) == -1) { TPL_OBJECT_LOCK(surface); return NULL; } @@ -505,18 +510,20 @@ __tpl_wayland_surface_dequeue_buffer(tpl_surface_t *surface) tsq_err = tbm_surface_queue_dequeue(wayland_surface->tbm_queue, &tbm_surface); if (!tbm_surface) { - TPL_ERR("Failed to get tbm_surface from tbm_surface_queue | tsq_err = %d",tsq_err); + 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) { + __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)); + wayland_buffer = (tpl_wayland_buffer_t *) calloc(1, + sizeof(tpl_wayland_buffer_t)); if (!wayland_buffer) { TPL_ERR("Mem alloc for wayland_buffer failed!"); tbm_surface_internal_unref(tbm_surface); @@ -524,7 +531,7 @@ __tpl_wayland_surface_dequeue_buffer(tpl_surface_t *surface) } wl_proxy = (struct wl_proxy *)wayland_tbm_client_create_buffer( - wayland_display->wl_tbm_client, tbm_surface); + wayland_display->wl_tbm_client, tbm_surface); if (!wl_proxy) { TPL_ERR("Failed to create TBM client buffer!"); tbm_surface_internal_unref(tbm_surface); @@ -534,7 +541,7 @@ __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); + tbm_surface); wl_display_flush((struct wl_display *)surface->display->native_handle); @@ -562,7 +569,7 @@ __tpl_wayland_buffer_free(tpl_wayland_buffer_t *wayland_buffer) if (wayland_buffer->wl_proxy) wayland_tbm_client_destroy_buffer(wayland_display->wl_tbm_client, - (void *)wayland_buffer->wl_proxy); + (void *)wayland_buffer->wl_proxy); free(wayland_buffer); } @@ -609,7 +616,8 @@ __tpl_surface_init_backend_wayland(tpl_surface_backend_t *backend) } static void -__cb_client_sync_callback(void *data, struct wl_callback *callback, uint32_t serial) +__cb_client_sync_callback(void *data, struct wl_callback *callback, + uint32_t serial) { int *done; @@ -621,13 +629,13 @@ __cb_client_sync_callback(void *data, struct wl_callback *callback, uint32_t ser wl_callback_destroy(callback); } -static const struct wl_callback_listener sync_listener = -{ +static const struct wl_callback_listener sync_listener = { __cb_client_sync_callback }; static void -__cb_client_frame_callback(void *data, struct wl_callback *callback, uint32_t time) +__cb_client_frame_callback(void *data, struct wl_callback *callback, + uint32_t time) { /* We moved the buffer reclaim logic to buffer_release_callback(). buffer_release_callback() is more suitable point to delete or reuse buffer instead of frame_callback(). @@ -638,8 +646,7 @@ __cb_client_frame_callback(void *data, struct wl_callback *callback, uint32_t ti wl_callback_destroy(callback); } -static const struct wl_callback_listener frame_listener = -{ +static const struct wl_callback_listener frame_listener = { __cb_client_frame_callback }; @@ -671,14 +678,16 @@ static const struct wl_buffer_listener buffer_release_listener = { }; 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) { TPL_ASSERT(private); TPL_ASSERT(wl_egl_window); int width, height, format; - tpl_surface_t *surface = (tpl_surface_t*)private; - tpl_wayland_surface_t *wayland_surface = (tpl_wayland_surface_t*)surface->backend.data; + tpl_surface_t *surface = (tpl_surface_t *)private; + tpl_wayland_surface_t *wayland_surface = (tpl_wayland_surface_t *) + surface->backend.data; wayland_surface->resized = TPL_TRUE; @@ -688,8 +697,8 @@ __cb_client_window_resize_callback(struct wl_egl_window* wl_egl_window, void* pr /* 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))) { + || (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); diff --git a/src/tpl_x11_common.c b/src/tpl_x11_common.c index 8122ab1..00c2adb 100644 --- a/src/tpl_x11_common.c +++ b/src/tpl_x11_common.c @@ -40,8 +40,7 @@ __tpl_x11_swap_str_to_swap_type(char *str, tpl_x11_swap_type_t *type) swap_type = strtol(str, NULL, 0); - switch (swap_type) - { + switch (swap_type) { case TPL_X11_SWAP_TYPE_SYNC: case TPL_X11_SWAP_TYPE_ASYNC: case TPL_X11_SWAP_TYPE_LAZY: @@ -53,7 +52,8 @@ __tpl_x11_swap_str_to_swap_type(char *str, tpl_x11_swap_type_t *type) } tpl_buffer_t * -__tpl_x11_surface_buffer_cache_find(tpl_list_t *buffer_cache, unsigned int name) +__tpl_x11_surface_buffer_cache_find(tpl_list_t *buffer_cache, + unsigned int name) { tpl_list_node_t *node; @@ -61,8 +61,7 @@ __tpl_x11_surface_buffer_cache_find(tpl_list_t *buffer_cache, unsigned int name node = __tpl_list_get_front_node(buffer_cache); - while (node) - { + while (node) { tpl_buffer_t *buffer = (tpl_buffer_t *) __tpl_list_node_get_data(node); TPL_ASSERT(buffer); @@ -77,7 +76,8 @@ __tpl_x11_surface_buffer_cache_find(tpl_list_t *buffer_cache, unsigned int name } void -__tpl_x11_surface_buffer_cache_remove(tpl_list_t *buffer_cache, unsigned int name) +__tpl_x11_surface_buffer_cache_remove(tpl_list_t *buffer_cache, + unsigned int name) { tpl_list_node_t *node; @@ -85,14 +85,12 @@ __tpl_x11_surface_buffer_cache_remove(tpl_list_t *buffer_cache, unsigned int nam node = __tpl_list_get_front_node(buffer_cache); - while (node) - { + while (node) { tpl_buffer_t *buffer = (tpl_buffer_t *) __tpl_list_node_get_data(node); TPL_ASSERT(buffer); - if (buffer->key == name) - { + if (buffer->key == name) { tpl_object_unreference(&buffer->base); __tpl_list_remove(node, NULL); return; @@ -103,13 +101,13 @@ __tpl_x11_surface_buffer_cache_remove(tpl_list_t *buffer_cache, unsigned int nam } tpl_bool_t -__tpl_x11_surface_buffer_cache_add(tpl_list_t *buffer_cache, tpl_buffer_t *buffer) +__tpl_x11_surface_buffer_cache_add(tpl_list_t *buffer_cache, + tpl_buffer_t *buffer) { TPL_ASSERT(buffer_cache); TPL_ASSERT(buffer); - if (__tpl_list_get_count(buffer_cache) >= TPL_BUFFER_CACHE_MAX_ENTRIES) - { + if (__tpl_list_get_count(buffer_cache) >= TPL_BUFFER_CACHE_MAX_ENTRIES) { tpl_buffer_t *evict = __tpl_list_pop_front(buffer_cache, NULL); TPL_ASSERT(evict); @@ -148,10 +146,8 @@ __tpl_x11_display_query_config(tpl_display_t *display, native_display = (Display *)display->native_handle; if (red_size != TPL_DONT_CARE || green_size != TPL_DONT_CARE || - blue_size != TPL_DONT_CARE || color_depth != TPL_DONT_CARE) - { - if (surface_type == TPL_SURFACE_TYPE_WINDOW) - { + blue_size != TPL_DONT_CARE || color_depth != TPL_DONT_CARE) { + if (surface_type == TPL_SURFACE_TYPE_WINDOW) { XVisualInfo *visual_formats; int num_visual_formats; int i; @@ -159,8 +155,7 @@ __tpl_x11_display_query_config(tpl_display_t *display, visual_formats = XGetVisualInfo(native_display, 0, NULL, &num_visual_formats); TPL_ASSERT(visual_formats); - for (i = 0; i < num_visual_formats; i++) - { + for (i = 0; i < num_visual_formats; i++) { int clz[3]; int col_size[3]; @@ -174,8 +169,7 @@ __tpl_x11_display_query_config(tpl_display_t *display, if ((red_size == TPL_DONT_CARE || col_size[0] == red_size) && (green_size == TPL_DONT_CARE || col_size[1] == green_size) && - (blue_size == TPL_DONT_CARE || col_size[2] == blue_size)) - { + (blue_size == TPL_DONT_CARE || col_size[2] == blue_size)) { if (native_visual_id != NULL) *native_visual_id = visual_formats[i].visualid; @@ -189,19 +183,16 @@ __tpl_x11_display_query_config(tpl_display_t *display, visual_formats = NULL; } - if (surface_type == TPL_SURFACE_TYPE_PIXMAP) - { + if (surface_type == TPL_SURFACE_TYPE_PIXMAP) { XPixmapFormatValues *pixmap_formats; int num_pixmap_formats; int i; pixmap_formats = XListPixmapFormats(native_display, &num_pixmap_formats); TPL_ASSERT(pixmap_formats); - for (i = 0; i < num_pixmap_formats; i++) - { + for (i = 0; i < num_pixmap_formats; i++) { if (color_depth == TPL_DONT_CARE || - pixmap_formats[i].depth == color_depth) - { + pixmap_formats[i].depth == color_depth) { if (is_slow != NULL) *is_slow = TPL_FALSE; @@ -220,42 +211,39 @@ __tpl_x11_display_query_config(tpl_display_t *display, } #if 0 -static void tpl_handle_and_free_error( Display *dpy, xcb_generic_error_t *error, const char* request_string ) +static void tpl_handle_and_free_error( Display *dpy, xcb_generic_error_t *error, + const char *request_string ) { char error_txt[256]; - if( error ) - { - int len = sizeof(error_txt)/sizeof(error_txt[0]); + if ( error ) { + int len = sizeof(error_txt) / sizeof(error_txt[0]); XGetErrorText( dpy, error->error_code, error_txt, len ); error_txt[ len - 1] = '\0'; - TPL_WARN("%s failed \"[%d]:%s\"", request_string, error->error_code, error_txt ); + TPL_WARN("%s failed \"[%d]:%s\"", request_string, error->error_code, + error_txt ); free(error); - } - else - { + } else { TPL_WARN("%s failed \"Unknown error\"", request_string ); } } -static tpl_bool_t tpl_check_reply_for_error(Display *dpy, xcb_generic_reply_t *reply, xcb_generic_error_t *error, +static tpl_bool_t tpl_check_reply_for_error(Display *dpy, + xcb_generic_reply_t *reply, xcb_generic_error_t *error, const char *request_string) { tpl_bool_t retval = TPL_FALSE; - if (error || reply == NULL) - { + if (error || reply == NULL) { tpl_handle_and_free_error( dpy, error, request_string ); - } - else - { + } else { retval = TPL_TRUE; } return retval; } -static XVisualInfo* tpl_find_visual( Display *dpy, xcb_visualid_t visual_id ) +static XVisualInfo *tpl_find_visual( Display *dpy, xcb_visualid_t visual_id ) { XVisualInfo *visual_info; XVisualInfo visual_info_template; @@ -263,28 +251,27 @@ static XVisualInfo* tpl_find_visual( Display *dpy, xcb_visualid_t visual_id ) visual_info_template.visualid = visual_id; - visual_info = XGetVisualInfo(dpy, VisualIDMask, &visual_info_template, &matching_count); + visual_info = XGetVisualInfo(dpy, VisualIDMask, &visual_info_template, + &matching_count); return visual_info; } -static int tpl_get_alpha_offset( int offset_r, int offset_g, int offset_b, int bpp ) +static int tpl_get_alpha_offset( int offset_r, int offset_g, int offset_b, + int bpp ) { int ret = -1; - TPL_CHECK_ON_FALSE_ASSERT_FAIL( bpp == 32, "alpha only supported for 32bits pixel formats"); + TPL_CHECK_ON_FALSE_ASSERT_FAIL( bpp == 32, + "alpha only supported for 32bits pixel formats"); - if( offset_r != 0 && offset_g != 0 && offset_b != 0 ) - { + if ( offset_r != 0 && offset_g != 0 && offset_b != 0 ) { ret = 0; - } - else if( offset_r != 24 && offset_g != 24 && offset_b != 24 ) - { + } else if ( offset_r != 24 && offset_g != 24 && offset_b != 24 ) { ret = 24; - } - else - { - TPL_CHECK_ON_FALSE_ASSERT_FAIL(TPL_FALSE, "Alpha component has to be at either the offset 0 or 24"); + } else { + TPL_CHECK_ON_FALSE_ASSERT_FAIL(TPL_FALSE, + "Alpha component has to be at either the offset 0 or 24"); } return ret; @@ -294,10 +281,8 @@ static int tpl_get_offset( unsigned long mask, int depth ) int res = -1; int count; - for (count = 0; count < depth; count++) - { - if (mask & 1) - { + for (count = 0; count < depth; count++) { + if (mask & 1) { res = count; break; } @@ -307,100 +292,86 @@ static int tpl_get_offset( unsigned long mask, int depth ) return res; } /* Convert the given combination of offsets and bpp into a color buffer format */ -static tpl_format_t tpl_offsets_to_color_buffer_format( int offset_r, int offset_g, int offset_b, int offset_a, int bpp ) +static tpl_format_t tpl_offsets_to_color_buffer_format( int offset_r, + int offset_g, int offset_b, int offset_a, int bpp ) { tpl_format_t retval = TPL_FORMAT_INVALID; - if ( offset_b == 11 && offset_g == 5 && offset_r == 0 && offset_a == -1 && bpp == 16) - { + if ( offset_b == 11 && offset_g == 5 && offset_r == 0 && offset_a == -1 && + bpp == 16) { retval = TPL_FORMAT_BGR565; - } - else if( offset_r == 11 && offset_g == 5 && offset_b == 0 && offset_a == -1 && bpp == 16) - { + } else if ( offset_r == 11 && offset_g == 5 && offset_b == 0 && + offset_a == -1 && bpp == 16) { retval = TPL_FORMAT_RGB565; } - else if( offset_a == 24 && offset_b == 16 && offset_g == 8 && offset_r == 0 && bpp == 32) - { + else if ( offset_a == 24 && offset_b == 16 && offset_g == 8 && + offset_r == 0 && bpp == 32) { retval = TPL_FORMAT_ABGR8888; - } - else if( offset_a == 24 && offset_r == 16 && offset_g == 8 && offset_b == 0 && bpp == 32) - { + } else if ( offset_a == 24 && offset_r == 16 && offset_g == 8 && + offset_b == 0 && bpp == 32) { retval = TPL_FORMAT_ARGB8888; - } - else if( offset_b == 24 && offset_g == 16 && offset_r == 8 && offset_a == 0 && bpp == 32) - { + } else if ( offset_b == 24 && offset_g == 16 && offset_r == 8 && + offset_a == 0 && bpp == 32) { retval = TPL_FORMAT_BGRA8888; - } - else if( offset_r == 24 && offset_g == 16 && offset_b == 8 && offset_a == 0 && bpp == 32) - { + } else if ( offset_r == 24 && offset_g == 16 && offset_b == 8 && + offset_a == 0 && bpp == 32) { retval = TPL_FORMAT_RGBA8888; } - else if( offset_b == 16 && offset_g == 8 && offset_r == 0 && offset_a == -1 && bpp == 32) - { + else if ( offset_b == 16 && offset_g == 8 && offset_r == 0 && + offset_a == -1 && bpp == 32) { retval = TPL_FORMAT_XBGR8888; - } - else if( offset_r == 16 && offset_g == 8 && offset_b == 0 && offset_a == -1 && bpp == 32) - { + } else if ( offset_r == 16 && offset_g == 8 && offset_b == 0 && + offset_a == -1 && bpp == 32) { retval = TPL_FORMAT_XRGB8888; - } - else if( offset_b == 24 && offset_g == 16 && offset_r == 8 && offset_a == -1 && bpp == 32) - { + } else if ( offset_b == 24 && offset_g == 16 && offset_r == 8 && + offset_a == -1 && bpp == 32) { retval = TPL_FORMAT_BGRX8888; - } - else if( offset_r == 24 && offset_g == 16 && offset_b == 8 && offset_a == -1 && bpp == 32) - { + } else if ( offset_r == 24 && offset_g == 16 && offset_b == 8 && + offset_a == -1 && bpp == 32) { retval = TPL_FORMAT_RGBX8888; } - else if( offset_b == 16 && offset_g == 8 && offset_r == 0 && offset_a == -1 && bpp == 24) - { + else if ( offset_b == 16 && offset_g == 8 && offset_r == 0 && + offset_a == -1 && bpp == 24) { retval = TPL_FORMAT_BGR888; - } - else if( offset_r == 16 && offset_g == 8 && offset_b == 0 && offset_a == -1 && bpp == 24) - { + } else if ( offset_r == 16 && offset_g == 8 && offset_b == 0 && + offset_a == -1 && bpp == 24) { retval = TPL_FORMAT_RGB888; } - else if( offset_a == 12 && offset_b == 8 && offset_g == 4 && offset_r == 0 && bpp == 16) - { + else if ( offset_a == 12 && offset_b == 8 && offset_g == 4 && + offset_r == 0 && bpp == 16) { retval = TPL_FORMAT_ABGR4444; - } - else if( offset_a == 12 && offset_r == 8 && offset_g == 4 && offset_b == 0 && bpp == 16) - { + } else if ( offset_a == 12 && offset_r == 8 && offset_g == 4 && + offset_b == 0 && bpp == 16) { retval = TPL_FORMAT_ARGB4444; - } - else if( offset_b == 12 && offset_g == 8 && offset_r == 4 && offset_a == 0 && bpp == 16) - { + } else if ( offset_b == 12 && offset_g == 8 && offset_r == 4 && + offset_a == 0 && bpp == 16) { retval = TPL_FORMAT_BGRA4444; - } - else if( offset_r == 12 && offset_g == 8 && offset_b == 4 && offset_a == 0 && bpp == 16) - { + } else if ( offset_r == 12 && offset_g == 8 && offset_b == 4 && + offset_a == 0 && bpp == 16) { retval = TPL_FORMAT_RGBA4444; } - else if( offset_a == 15 && offset_b == 10 && offset_g == 5 && offset_r == 0 && bpp == 16) - { + else if ( offset_a == 15 && offset_b == 10 && offset_g == 5 && + offset_r == 0 && bpp == 16) { retval = TPL_FORMAT_ABGR1555; - } - else if( offset_a == 15 && offset_r == 10 && offset_g == 5 && offset_b == 0 && bpp == 16) - { + } else if ( offset_a == 15 && offset_r == 10 && offset_g == 5 && + offset_b == 0 && bpp == 16) { retval = TPL_FORMAT_ARGB1555; - } - else if( offset_b == 11 && offset_g == 6 && offset_r == 1 && offset_a == 0 && bpp == 16) - { + } else if ( offset_b == 11 && offset_g == 6 && offset_r == 1 && + offset_a == 0 && bpp == 16) { retval = TPL_FORMAT_BGRA5551; - } - else if( offset_r == 11 && offset_g == 6 && offset_b == 1 && offset_a == 0 && bpp == 16) - { + } else if ( offset_r == 11 && offset_g == 6 && offset_b == 1 && + offset_a == 0 && bpp == 16) { retval = TPL_FORMAT_RGBA5551; } - else - { + else { TPL_WARN("Format not supported: offset_r=%d, offset_g=%d, offset_b=%d, offset_a=%d, bpp=%d", - offset_r, offset_g, offset_b, offset_a, bpp); + offset_r, offset_g, offset_b, offset_a, bpp); } return retval; @@ -409,7 +380,7 @@ static tpl_format_t tpl_offsets_to_color_buffer_format( int offset_r, int offset tpl_bool_t __tpl_x11_display_get_window_info(tpl_display_t *display, tpl_handle_t window, - int *width, int *height, tpl_format_t *format, int depth, int a_size) + int *width, int *height, tpl_format_t *format, int depth, int a_size) { Status x_res; XWindowAttributes att; @@ -420,18 +391,24 @@ __tpl_x11_display_get_window_info(tpl_display_t *display, tpl_handle_t window, TPL_ASSERT(display); TPL_ASSERT(display->native_handle); - x_res = XGetWindowAttributes((Display *)display->native_handle, (Window)window, &att); - - if (x_res != BadWindow) - { - if (format != NULL) - { - switch (att.depth) - { - case 32: *format = TPL_FORMAT_ARGB8888; break; - case 24: *format = TPL_FORMAT_XRGB8888; break; - case 16: *format = TPL_FORMAT_RGB565; break; - default: *format = TPL_FORMAT_INVALID; break; + x_res = XGetWindowAttributes((Display *)display->native_handle, (Window)window, + &att); + + if (x_res != BadWindow) { + if (format != NULL) { + switch (att.depth) { + case 32: + *format = TPL_FORMAT_ARGB8888; + break; + case 24: + *format = TPL_FORMAT_XRGB8888; + break; + case 16: + *format = TPL_FORMAT_RGB565; + break; + default: + *format = TPL_FORMAT_INVALID; + break; } } if (width != NULL) *width = att.width; @@ -444,7 +421,7 @@ __tpl_x11_display_get_window_info(tpl_display_t *display, tpl_handle_t window, tpl_bool_t __tpl_x11_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, - int *width, int *height, tpl_format_t *format) + int *width, int *height, tpl_format_t *format) { Status x_res; Window root = None; @@ -457,16 +434,21 @@ __tpl_x11_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, x_res = XGetGeometry((Display *)display->native_handle, (Pixmap)pixmap, &root, &x, &y, &w, &h, &bw, &d); - if (x_res != BadDrawable) - { - if (format != NULL) - { - switch (d) - { - case 32: *format = TPL_FORMAT_ARGB8888; break; - case 24: *format = TPL_FORMAT_XRGB8888; break; - case 16: *format = TPL_FORMAT_RGB565; break; - default: *format = TPL_FORMAT_INVALID; break; + if (x_res != BadDrawable) { + if (format != NULL) { + switch (d) { + case 32: + *format = TPL_FORMAT_ARGB8888; + break; + case 24: + *format = TPL_FORMAT_XRGB8888; + break; + case 16: + *format = TPL_FORMAT_RGB565; + break; + default: + *format = TPL_FORMAT_INVALID; + break; } } if (width != NULL) *width = w; @@ -505,8 +487,7 @@ __tpl_x11_buffer_fini(tpl_buffer_t *buffer) { TPL_ASSERT(buffer); - if (buffer->backend.data) - { + if (buffer->backend.data) { tbm_bo_map((tbm_bo)buffer->backend.data, TBM_DEVICE_3D, TBM_OPTION_READ); tbm_bo_unmap((tbm_bo)buffer->backend.data); tbm_bo_unref((tbm_bo)buffer->backend.data); @@ -552,23 +533,22 @@ __tpl_x11_buffer_lock(tpl_buffer_t *buffer, tpl_lock_usage_t usage) TPL_OBJECT_UNLOCK(buffer); - switch (usage) - { - case TPL_LOCK_USAGE_GPU_READ: - handle = tbm_bo_map(bo, TBM_DEVICE_3D, TBM_OPTION_READ); - break; - case TPL_LOCK_USAGE_GPU_WRITE: - handle = tbm_bo_map(bo, TBM_DEVICE_3D, TBM_OPTION_WRITE); - break; - case TPL_LOCK_USAGE_CPU_READ: - handle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_READ); - break; - case TPL_LOCK_USAGE_CPU_WRITE: - handle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE); - break; - default: - TPL_ASSERT(TPL_FALSE); - return TPL_FALSE; + switch (usage) { + case TPL_LOCK_USAGE_GPU_READ: + handle = tbm_bo_map(bo, TBM_DEVICE_3D, TBM_OPTION_READ); + break; + case TPL_LOCK_USAGE_GPU_WRITE: + handle = tbm_bo_map(bo, TBM_DEVICE_3D, TBM_OPTION_WRITE); + break; + case TPL_LOCK_USAGE_CPU_READ: + handle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_READ); + break; + case TPL_LOCK_USAGE_CPU_WRITE: + handle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE); + break; + default: + TPL_ASSERT(TPL_FALSE); + return TPL_FALSE; } TPL_OBJECT_LOCK(buffer); @@ -611,8 +591,7 @@ void __tpl_x11_display_wait_native(tpl_display_t *display) TPL_ASSERT(display); xlib_display = (Display *) display->native_handle; - if (xlib_display != NULL) - { + if (xlib_display != NULL) { /* Leave events in the queue since we only care they have arrived. */ XSync(xlib_display, 0); } diff --git a/src/tpl_x11_dri2.c b/src/tpl_x11_dri2.c index ef6201c..59ad49a 100644 --- a/src/tpl_x11_dri2.c +++ b/src/tpl_x11_dri2.c @@ -25,8 +25,7 @@ typedef struct _tpl_x11_dri2_surface tpl_x11_dri2_surface_t; -struct _tpl_x11_dri2_surface -{ +struct _tpl_x11_dri2_surface { int latest_post_interval; XserverRegion damage; tpl_list_t buffer_cache; @@ -35,8 +34,7 @@ struct _tpl_x11_dri2_surface -static tpl_x11_global_t global = -{ +static tpl_x11_global_t global = { 0, NULL, -1, @@ -64,7 +62,7 @@ __tpl_x11_dri2_get_worker_display(void) static void __tpl_x11_dri2_surface_post_internal(tpl_surface_t *surface, tpl_frame_t *frame, - tpl_bool_t is_worker) + tpl_bool_t is_worker) { Display *display; Drawable drawable; @@ -90,32 +88,24 @@ __tpl_x11_dri2_surface_post_internal(tpl_surface_t *surface, tpl_frame_t *frame, if (interval < 1) interval = 1; - if (interval != x11_surface->latest_post_interval) - { + if (interval != x11_surface->latest_post_interval) { DRI2SwapInterval(display, drawable, interval); x11_surface->latest_post_interval = interval; } - if (__tpl_region_is_empty(&frame->damage)) - { + if (__tpl_region_is_empty(&frame->damage)) { DRI2SwapBuffers(display, drawable, 0, 0, 0, &swap_count); - } - else - { + } else { int i; - if (frame->damage.num_rects > TPL_STACK_XRECTANGLE_SIZE) - { + if (frame->damage.num_rects > TPL_STACK_XRECTANGLE_SIZE) { xrects = (XRectangle *) malloc(sizeof(XRectangle) * - frame->damage.num_rects); - } - else - { + frame->damage.num_rects); + } else { xrects = &xrects_stack[0]; } - for (i = 0; i < frame->damage.num_rects; i++) - { + for (i = 0; i < frame->damage.num_rects; i++) { const int *rects = &frame->damage.rects[i * 4]; xrects[i].x = rects[0]; @@ -124,13 +114,10 @@ __tpl_x11_dri2_surface_post_internal(tpl_surface_t *surface, tpl_frame_t *frame, xrects[i].height = rects[3]; } - if (x11_surface->damage == None) - { + if (x11_surface->damage == None) { x11_surface->damage = XFixesCreateRegion(display, xrects, frame->damage.num_rects); - } - else - { + } else { XFixesSetRegion(display, x11_surface->damage, xrects, frame->damage.num_rects); } @@ -150,26 +137,23 @@ __tpl_x11_dri2_display_init(tpl_display_t *display) mutex = __tpl_x11_get_global_mutex(); - if (display->native_handle == NULL) - { + if (display->native_handle == NULL) { display->native_handle = XOpenDisplay(NULL); - if (NULL == display->native_handle) - { + if (NULL == display->native_handle) { TPL_ERR("XOpenDisplay failed!"); return TPL_FALSE; } } - display->xcb_connection = XGetXCBConnection( (Display*)display->native_handle ); - if( NULL == display->xcb_connection ) - { + display->xcb_connection = XGetXCBConnection( (Display *) + display->native_handle ); + if ( NULL == display->xcb_connection ) { TPL_WARN("XGetXCBConnection failed"); } pthread_mutex_lock(&mutex); - if (global.display_count == 0) - { + if (global.display_count == 0) { Bool xres = False; char *drv = NULL; char *dev = NULL; @@ -182,8 +166,7 @@ __tpl_x11_dri2_display_init(tpl_display_t *display) /* Open a dummy display connection. */ global.worker_display = XOpenDisplay(NULL); - if (NULL == global.worker_display) - { + if (NULL == global.worker_display) { TPL_ERR("XOpenDisplay failed!"); return TPL_FALSE; } @@ -193,22 +176,19 @@ __tpl_x11_dri2_display_init(tpl_display_t *display) /* Initialize DRI2. */ xres = DRI2QueryExtension(global.worker_display, &event_base, &error_base); - if (True != xres) - { + if (True != xres) { TPL_ERR("DRI2QueryExtension failed!"); return TPL_FALSE; } xres = DRI2QueryVersion(global.worker_display, &major, &minor); - if (True != xres) - { + if (True != xres) { TPL_ERR("DRI2QueryVersion failed!"); return TPL_FALSE; } xres = DRI2Connect(global.worker_display, root, &drv, &dev); - if (True != xres) - { + if (True != xres) { TPL_ERR("DRI2Connect failed!"); return TPL_FALSE; } @@ -219,8 +199,7 @@ __tpl_x11_dri2_display_init(tpl_display_t *display) /* DRI2 authentication. */ xres = DRI2Authenticate(global.worker_display, root, magic); - if (True != xres) - { + if (True != xres) { TPL_ERR("DRI2Authenciate failed!"); return TPL_FALSE; } @@ -229,10 +208,10 @@ __tpl_x11_dri2_display_init(tpl_display_t *display) /* Initialize swap type configuration. */ __tpl_x11_swap_str_to_swap_type(getenv(EGL_X11_WINDOW_SWAP_TYPE_ENV_NAME), - &global.win_swap_type); + &global.win_swap_type); __tpl_x11_swap_str_to_swap_type(getenv(EGL_X11_FB_SWAP_TYPE_ENV_NAME), - &global.fb_swap_type); + &global.fb_swap_type); } global.display_count++; @@ -252,8 +231,7 @@ __tpl_x11_dri2_display_fini(tpl_display_t *display) pthread_mutex_lock(&mutex); - if (--global.display_count == 0) - { + if (--global.display_count == 0) { tbm_bufmgr_deinit(global.bufmgr); close(global.bufmgr_fd); XCloseDisplay(global.worker_display); @@ -277,23 +255,20 @@ __tpl_x11_dri2_surface_init(tpl_surface_t *surface) TPL_ASSERT(surface); - if (surface->type == TPL_SURFACE_TYPE_WINDOW) - { + if (surface->type == TPL_SURFACE_TYPE_WINDOW) { if (!__tpl_x11_display_get_window_info(surface->display, surface->native_handle, - &surface->width, &surface->height, NULL,0,0)) + &surface->width, &surface->height, NULL, 0, 0)) return TPL_FALSE; - } - else - { + } else { if (!__tpl_x11_display_get_pixmap_info(surface->display, surface->native_handle, &surface->width, &surface->height, &format)) return TPL_FALSE; } - x11_surface = (tpl_x11_dri2_surface_t *) calloc(1, sizeof(tpl_x11_dri2_surface_t)); + x11_surface = (tpl_x11_dri2_surface_t *) calloc(1, + sizeof(tpl_x11_dri2_surface_t)); - if (x11_surface == NULL) - { + if (x11_surface == NULL) { TPL_ERR("Failed to allocate memory for X11 surface!"); return TPL_FALSE; } @@ -325,8 +300,7 @@ __tpl_x11_dri2_surface_fini(tpl_surface_t *surface) drawable = (Drawable)surface->native_handle; x11_surface = (tpl_x11_dri2_surface_t *)surface->backend.data; - if (x11_surface) - { + if (x11_surface) { __tpl_x11_surface_buffer_cache_clear(&x11_surface->buffer_cache); if (x11_surface->damage) @@ -356,21 +330,18 @@ __tpl_x11_surface_begin_frame(tpl_surface_t *surface) TPL_ASSERT(surface); - if (surface->type != TPL_SURFACE_TYPE_WINDOW) - { + if (surface->type != TPL_SURFACE_TYPE_WINDOW) { TPL_ERR("Surface type is not of window type!"); return; } prev_frame = __tpl_surface_get_latest_frame(surface); - if (prev_frame && prev_frame->state != TPL_FRAME_STATE_POSTED) - { + if (prev_frame && prev_frame->state != TPL_FRAME_STATE_POSTED) { if ((DRI2_BUFFER_IS_FB(prev_frame->buffer->backend.flags) && global.fb_swap_type == TPL_X11_SWAP_TYPE_SYNC) || (!DRI2_BUFFER_IS_FB(prev_frame->buffer->backend.flags) && - global.win_swap_type == TPL_X11_SWAP_TYPE_SYNC)) - { + global.win_swap_type == TPL_X11_SWAP_TYPE_SYNC)) { __tpl_surface_wait_all_frames(surface); } } @@ -395,10 +366,8 @@ __tpl_x11_surface_validate_frame(tpl_surface_t *surface) if ((DRI2_BUFFER_IS_FB(surface->frame->buffer->backend.flags) && global.fb_swap_type == TPL_X11_SWAP_TYPE_LAZY) || (!DRI2_BUFFER_IS_FB(surface->frame->buffer->backend.flags) && - global.win_swap_type == TPL_X11_SWAP_TYPE_LAZY)) - { - if (x11_surface->latest_render_target == surface->frame->buffer) - { + global.win_swap_type == TPL_X11_SWAP_TYPE_LAZY)) { + if (x11_surface->latest_render_target == surface->frame->buffer) { __tpl_surface_wait_all_frames(surface); return TPL_FALSE; } @@ -419,22 +388,21 @@ __tpl_x11_surface_end_frame(tpl_surface_t *surface) frame = __tpl_surface_get_latest_frame(surface); x11_surface = (tpl_x11_dri2_surface_t *) surface->backend.data; - if (frame) - { + if (frame) { x11_surface->latest_render_target = frame->buffer; if ((DRI2_BUFFER_IS_FB(frame->buffer->backend.flags) && global.fb_swap_type == TPL_X11_SWAP_TYPE_ASYNC) || (!DRI2_BUFFER_IS_FB(frame->buffer->backend.flags) && - global.win_swap_type == TPL_X11_SWAP_TYPE_ASYNC)) - { + global.win_swap_type == TPL_X11_SWAP_TYPE_ASYNC)) { __tpl_x11_dri2_surface_post_internal(surface, frame, TPL_FALSE); } } } static tpl_buffer_t * -__tpl_x11_dri2_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buffers) +__tpl_x11_dri2_surface_get_buffer(tpl_surface_t *surface, + tpl_bool_t *reset_buffers) { tpl_buffer_t *buffer = NULL; Display *display; @@ -460,21 +428,19 @@ __tpl_x11_dri2_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buff /* Get the current buffer via DRI2. */ dri2_buffers = DRI2GetBuffers(display, drawable, &width, &height, attachments, 1, &num_buffers); - if (dri2_buffers == NULL) - { + if (dri2_buffers == NULL) { TPL_ERR("DRI2GetBuffers failed!"); goto err_buffer; } - if (DRI2_BUFFER_IS_REUSED(dri2_buffers[0].flags)) - { + if (DRI2_BUFFER_IS_REUSED(dri2_buffers[0].flags)) { /* Buffer is reused. So it should be in the buffer cache. * However, sometimes we get a strange result of having reused flag for a newly * received buffer. I don't know the meaning of such cases but just handle it. */ - buffer = __tpl_x11_surface_buffer_cache_find(&x11_surface->buffer_cache, dri2_buffers[0].name); + buffer = __tpl_x11_surface_buffer_cache_find(&x11_surface->buffer_cache, + dri2_buffers[0].name); - if (buffer) - { + if (buffer) { /* Need to update buffer flag */ buffer->backend.flags = dri2_buffers[0].flags; /* just update the buffer age. */ @@ -483,9 +449,7 @@ __tpl_x11_dri2_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buff #endif goto done; } - } - else - { + } else { /* Buffer configuration of the server is changed. We have to reset all previsouly * received buffers. */ __tpl_x11_surface_buffer_cache_clear(&x11_surface->buffer_cache); @@ -494,8 +458,7 @@ __tpl_x11_dri2_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buff /* Create a TBM buffer object for the buffer name. */ bo = tbm_bo_import(global.bufmgr, dri2_buffers[0].name); - if (bo == NULL) - { + if (bo == NULL) { TPL_ERR("TBM bo import failed!"); goto done; } @@ -503,10 +466,10 @@ __tpl_x11_dri2_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buff bo_handle = tbm_bo_get_handle(bo, TBM_DEVICE_3D); /* Create tpl buffer. */ - buffer = __tpl_buffer_alloc(surface, (size_t) dri2_buffers[0].name, (int) bo_handle.u32, + buffer = __tpl_buffer_alloc(surface, (size_t) dri2_buffers[0].name, + (int) bo_handle.u32, width, height, dri2_buffers[0].cpp * 8, dri2_buffers[0].pitch); - if (NULL == buffer) - { + if (NULL == buffer) { TPL_ERR("TPL buffer alloc failed!"); goto err_buffer; } @@ -522,11 +485,10 @@ __tpl_x11_dri2_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buff tpl_object_unreference(&buffer->base); done: - if (reset_buffers) - { + if (reset_buffers) { /* Users use this output value to check if they have to reset previous buffers. */ *reset_buffers = !DRI2_BUFFER_IS_REUSED(dri2_buffers[0].flags) || - width != surface->width || height != surface->height; + width != surface->width || height != surface->height; } XFree(dri2_buffers); diff --git a/src/tpl_x11_dri3.c b/src/tpl_x11_dri3.c index e94bb87..f1e972d 100644 --- a/src/tpl_x11_dri3.c +++ b/src/tpl_x11_dri3.c @@ -45,8 +45,7 @@ static int dri3_max_back = 0;/*max number of back buffer*/ typedef struct _tpl_x11_dri3_surface tpl_x11_dri3_surface_t; -struct _tpl_x11_dri3_surface -{ +struct _tpl_x11_dri3_surface { int latest_post_interval; XserverRegion damage; tpl_list_t buffer_cache; @@ -55,21 +54,18 @@ struct _tpl_x11_dri3_surface void *drawable; }; -enum dri3_buffer_type -{ +enum dri3_buffer_type { dri3_buffer_back = 0, dri3_buffer_front = 1 }; -enum dri3_buffer_status -{ - dri3_buffer_idle = 0, - dri3_buffer_busy = 1, - dri3_buffer_posted = 2 +enum dri3_buffer_status { + dri3_buffer_idle = 0, + dri3_buffer_busy = 1, + dri3_buffer_posted = 2 }; -typedef struct _dri3_buffer -{ +typedef struct _dri3_buffer { tbm_bo tbo; uint32_t pixmap; enum dri3_buffer_status status; /* Set on swap, cleared on IdleNotify */ @@ -87,20 +83,19 @@ typedef struct _dri3_buffer uint32_t dma_buf_fd; /* fd of dma buffer */ /* [BEGIN: 20141125-xuelian.bai] Add old dma fd to save old fd * before use new fd */ - /* 2015-04-08 joonbum.ko@samsung.com */ - /* Change old buffer name to old_bo_name from old_dma_fd */ + /* 2015-04-08 joonbum.ko@samsung.com */ + /* Change old buffer name to old_bo_name from old_dma_fd */ /* uint32_t old_dma_fd; */ - uint32_t old_bo_name; + uint32_t old_bo_name; /* [END: 20141125-xuelian.bai] */ enum dri3_buffer_type buffer_type; /* back=0,front=1 */ - /* [BEGIN: 20140119-leiba.sun] Add support for buffer age */ - uint32_t buffer_age; - /* [END:20150119-leiba.sun] */ + /* [BEGIN: 20140119-leiba.sun] Add support for buffer age */ + uint32_t buffer_age; + /* [END:20150119-leiba.sun] */ } dri3_buffer; -typedef struct _dri3_drawable -{ +typedef struct _dri3_drawable { Display *dpy; XID xDrawable; @@ -129,14 +124,12 @@ typedef struct _dri3_drawable xcb_special_event_t *special_event; } dri3_drawable; -typedef struct _dri3_drawable_node -{ +typedef struct _dri3_drawable_node { XID xDrawable; dri3_drawable *drawable; } dri3_drawable_node; -static tpl_x11_global_t global = -{ +static tpl_x11_global_t global = { 0, NULL, -1, @@ -163,18 +156,16 @@ dri3_open(Display *dpy, Window root, CARD32 provider) c = XGetXCBConnection(dpy); cookie = xcb_dri3_open(c, - root, - provider); + root, + provider); reply = xcb_dri3_open_reply(c, cookie, NULL); - if (!reply) - { + if (!reply) { TPL_ERR("XCB DRI3 open failed!"); return -1; } - if (reply->nfd != 1) - { + if (reply->nfd != 1) { TPL_ERR("XCB DRI3 open reply failed!"); free(reply); return -1; @@ -209,25 +200,22 @@ dri3_display_init(Display *dpy) xcb_prefetch_extension_data(c, &xcb_present_id); extension = xcb_get_extension_data(c, &xcb_dri3_id); - if (!(extension && extension->present)) - { + if (!(extension && extension->present)) { TPL_ERR("XCB get extension failed!"); return TPL_FALSE; } extension = xcb_get_extension_data(c, &xcb_present_id); - if (!(extension && extension->present)) - { + if (!(extension && extension->present)) { TPL_ERR("XCB get extension failed!"); return TPL_FALSE; } dri3_cookie = xcb_dri3_query_version(c, - XCB_DRI3_MAJOR_VERSION, - XCB_DRI3_MINOR_VERSION); + XCB_DRI3_MAJOR_VERSION, + XCB_DRI3_MINOR_VERSION); dri3_reply = xcb_dri3_query_version_reply(c, dri3_cookie, &error); - if (!dri3_reply) - { + if (!dri3_reply) { TPL_ERR("XCB version query failed!"); free(error); return TPL_FALSE; @@ -235,11 +223,10 @@ dri3_display_init(Display *dpy) free(dri3_reply); present_cookie = xcb_present_query_version(c, - XCB_PRESENT_MAJOR_VERSION, - XCB_PRESENT_MINOR_VERSION); + XCB_PRESENT_MAJOR_VERSION, + XCB_PRESENT_MINOR_VERSION); present_reply = xcb_present_query_version_reply(c, present_cookie, &error); - if (!present_reply) - { + if (!present_reply) { TPL_ERR("Present version query failed!"); free(error); return TPL_FALSE; @@ -265,28 +252,25 @@ dri3_create_drawable(Display *dpy, XID xDrawable) /* Check drawable list to find that if it has been created*/ node = __tpl_list_get_front_node(&dri3_drawable_list); - while (node) - { - dri3_drawable_node *drawable = (dri3_drawable_node *) __tpl_list_node_get_data(node); + while (node) { + dri3_drawable_node *drawable = (dri3_drawable_node *) __tpl_list_node_get_data( + node); - if (drawable->xDrawable == xDrawable) - { + if (drawable->xDrawable == xDrawable) { pdraw = drawable->drawable; return (void *)pdraw;/* Reuse old drawable */ } node = __tpl_list_node_next(node); } pdraw = calloc(1, sizeof(*pdraw)); - if (NULL == pdraw) - { + if (NULL == pdraw) { TPL_ERR("Failed to allocate memory!"); return NULL; } geom_cookie = xcb_get_geometry(c, xDrawable); geom_reply = xcb_get_geometry_reply(c, geom_cookie, NULL); - if (NULL == geom_reply) - { + if (NULL == geom_reply) { TPL_ERR("XCB get geometry failed!"); free(pdraw); return NULL; @@ -302,13 +286,12 @@ dri3_create_drawable(Display *dpy, XID xDrawable) pdraw->dpy = global.worker_display; pdraw->xDrawable = xDrawable; - for (i = 0; i < dri3_max_back + 1;i++) + for (i = 0; i < dri3_max_back + 1; i++) pdraw->buffers[i] = NULL; /* Add new allocated drawable to drawable list */ drawable_node = calloc(1, sizeof(dri3_drawable_node)); - if (NULL == drawable_node) - { + if (NULL == drawable_node) { TPL_ERR("Failed to allocate memory for drawable node!"); free(pdraw); return NULL; @@ -316,15 +299,15 @@ dri3_create_drawable(Display *dpy, XID xDrawable) drawable_node->drawable = pdraw; drawable_node->xDrawable = xDrawable; - if (TPL_TRUE != __tpl_list_push_back(&dri3_drawable_list, (void *)drawable_node)) - { + if (TPL_TRUE != __tpl_list_push_back(&dri3_drawable_list, + (void *)drawable_node)) { TPL_ERR("List operation failed!"); free(pdraw); free(drawable_node); return NULL; } - return (void*)pdraw; + return (void *)pdraw; } static void @@ -342,19 +325,16 @@ dri3_destroy_drawable(Display *dpy, XID xDrawable) /* Remove drawable from list */ node = __tpl_list_get_front_node(&dri3_drawable_list); - while (node) - { + while (node) { drawable = (dri3_drawable_node *) __tpl_list_node_get_data(node); - if (drawable->xDrawable== xDrawable) - { + if (drawable->xDrawable == xDrawable) { pdraw = drawable->drawable; if (!pdraw) return; - for (i = 0; i < dri3_max_back + 1; i++) - { + for (i = 0; i < dri3_max_back + 1; i++) { if (pdraw->buffers[i]) dri3_free_render_buffer(pdraw, pdraw->buffers[i]); } @@ -394,8 +374,7 @@ dri3_update_drawable(void *loaderPrivate) /* First time through, go get the current drawable geometry */ /*TODO*/ - if (priv->special_event == NULL) - { + if (priv->special_event == NULL) { xcb_get_geometry_cookie_t geom_cookie; xcb_get_geometry_reply_t *geom_reply; xcb_void_cookie_t cookie; @@ -416,25 +395,25 @@ dri3_update_drawable(void *loaderPrivate) cookie = xcb_present_select_input_checked(c, (priv->eid = xcb_generate_id(c)), priv->xDrawable, - XCB_PRESENT_EVENT_MASK_CONFIGURE_NOTIFY| - XCB_PRESENT_EVENT_MASK_COMPLETE_NOTIFY| + XCB_PRESENT_EVENT_MASK_CONFIGURE_NOTIFY | + XCB_PRESENT_EVENT_MASK_COMPLETE_NOTIFY | XCB_PRESENT_EVENT_MASK_IDLE_NOTIFY); - present_capabilities_cookie = xcb_present_query_capabilities(c, priv->xDrawable); + present_capabilities_cookie = xcb_present_query_capabilities(c, + priv->xDrawable); /* Create an XCB event queue to hold present events outside of the usual * application event queue */ priv->special_event = xcb_register_for_special_xge(c, - &xcb_present_id, - priv->eid, - &priv->stamp); + &xcb_present_id, + priv->eid, + &priv->stamp); geom_cookie = xcb_get_geometry(c, priv->xDrawable); geom_reply = xcb_get_geometry_reply(c, geom_cookie, NULL); - if (NULL == geom_reply) - { + if (NULL == geom_reply) { TPL_ERR("Failed to get geometry reply!"); return TPL_FALSE; } @@ -455,20 +434,17 @@ dri3_update_drawable(void *loaderPrivate) error = xcb_request_check(c, cookie); present_capabilities_reply = xcb_present_query_capabilities_reply(c, - present_capabilities_cookie, - NULL); + present_capabilities_cookie, + NULL); - if (present_capabilities_reply) - { + if (present_capabilities_reply) { priv->present_capabilities = present_capabilities_reply->capabilities; free(present_capabilities_reply); } else priv->present_capabilities = 0; - if (error) - { - if (error->error_code != BadWindow) - { + if (error) { + if (error->error_code != BadWindow) { free(error); return TPL_FALSE; } @@ -491,83 +467,73 @@ dri3_handle_present_event(dri3_drawable *priv, xcb_present_generic_event_t *ge) TPL_ASSERT(priv); TPL_ASSERT(ge); - switch (ge->evtype) - { - case XCB_PRESENT_CONFIGURE_NOTIFY: - { - TRACE_BEGIN("DRI3:PRESENT_CONFIGURE_NOTIFY"); - xcb_present_configure_notify_event_t *ce = (void *) ge; - priv->width = ce->width; - priv->height = ce->height; - TRACE_END(); - break; - } + switch (ge->evtype) { + case XCB_PRESENT_CONFIGURE_NOTIFY: { + TRACE_BEGIN("DRI3:PRESENT_CONFIGURE_NOTIFY"); + xcb_present_configure_notify_event_t *ce = (void *) ge; + priv->width = ce->width; + priv->height = ce->height; + TRACE_END(); + break; + } - case XCB_PRESENT_COMPLETE_NOTIFY: - { - TRACE_BEGIN("DRI3:PRESENT_COMPLETE_NOTIFY"); - xcb_present_complete_notify_event_t *ce = (void *) ge; - /* Compute the processed SBC number from the received - * 32-bit serial number merged with the upper 32-bits - * of the sent 64-bit serial number while checking for - * wrap - */ - if (ce->kind == XCB_PRESENT_COMPLETE_KIND_PIXMAP) - { - priv->recv_sbc = - (priv->send_sbc & 0xffffffff00000000LL) | - ce->serial; - if (priv->recv_sbc > priv->send_sbc) - priv->recv_sbc -= 0x100000000; - switch (ce->mode) - { - case XCB_PRESENT_COMPLETE_MODE_FLIP: - priv->flipping = 1; - break; - case XCB_PRESENT_COMPLETE_MODE_COPY: - priv->flipping = 0; - break; - } - } - else - { - priv->recv_msc_serial = ce->serial; + case XCB_PRESENT_COMPLETE_NOTIFY: { + TRACE_BEGIN("DRI3:PRESENT_COMPLETE_NOTIFY"); + xcb_present_complete_notify_event_t *ce = (void *) ge; + /* Compute the processed SBC number from the received + * 32-bit serial number merged with the upper 32-bits + * of the sent 64-bit serial number while checking for + * wrap + */ + if (ce->kind == XCB_PRESENT_COMPLETE_KIND_PIXMAP) { + priv->recv_sbc = + (priv->send_sbc & 0xffffffff00000000LL) | + ce->serial; + if (priv->recv_sbc > priv->send_sbc) + priv->recv_sbc -= 0x100000000; + switch (ce->mode) { + case XCB_PRESENT_COMPLETE_MODE_FLIP: + priv->flipping = 1; + break; + case XCB_PRESENT_COMPLETE_MODE_COPY: + priv->flipping = 0; + break; } - - priv->ust = ce->ust; - priv->msc = ce->msc; - TRACE_END(); - break; + } else { + priv->recv_msc_serial = ce->serial; } - case XCB_PRESENT_EVENT_IDLE_NOTIFY: - { - xcb_present_idle_notify_event_t *ie = (void *) ge; - uint32_t b; - - for (b = 0; b < sizeof (priv->buffers) / sizeof (priv->buffers[0]); b++) - { - dri3_buffer *buf = priv->buffers[b]; - - if (buf && buf->pixmap == ie->pixmap) - { - TRACE_MARK("IDLE:%d",tbm_bo_export(priv->buffers[b]->tbo)); - buf->status = dri3_buffer_idle; - break; - } + priv->ust = ce->ust; + priv->msc = ce->msc; + TRACE_END(); + break; + } + + case XCB_PRESENT_EVENT_IDLE_NOTIFY: { + xcb_present_idle_notify_event_t *ie = (void *) ge; + uint32_t b; + + for (b = 0; b < sizeof (priv->buffers) / sizeof (priv->buffers[0]); b++) { + dri3_buffer *buf = priv->buffers[b]; + + if (buf && buf->pixmap == ie->pixmap) { + TRACE_MARK("IDLE:%d", tbm_bo_export(priv->buffers[b]->tbo)); + buf->status = dri3_buffer_idle; + break; } - break; } + break; + } } free(ge); - } +} - /****************************************************** - * dri3_flush_present_events - * - * Process any present events that have been received from the X server - * called when get buffer or swap buffer - ******************************************************/ +/****************************************************** +* dri3_flush_present_events +* +* Process any present events that have been received from the X server +* called when get buffer or swap buffer +******************************************************/ static void dri3_flush_present_events(dri3_drawable *priv) { @@ -578,16 +544,14 @@ dri3_flush_present_events(dri3_drawable *priv) c = XGetXCBConnection(priv->dpy); - TRACE_BEGIN("DRI3:FLUSH_PRESENT_EVENTS"); + TRACE_BEGIN("DRI3:FLUSH_PRESENT_EVENTS"); /* Check to see if any configuration changes have occurred * since we were last invoked */ - if (priv->special_event) - { + if (priv->special_event) { xcb_generic_event_t *ev; - while ((ev = xcb_poll_for_special_event(c, priv->special_event)) != NULL) - { + while ((ev = xcb_poll_for_special_event(c, priv->special_event)) != NULL) { xcb_present_generic_event_t *ge = (void *) ev; dri3_handle_present_event(priv, ge); } @@ -606,23 +570,19 @@ dri3_wait_for_notify(xcb_connection_t *c, dri3_drawable *priv) TRACE_BEGIN("TPL:DRI3:WAIT_FOR_NOTIFY"); - if (((uint32_t)priv->send_sbc) == 0) - { + if (((uint32_t)priv->send_sbc) == 0) { TRACE_END(); return TPL_TRUE; } - for (;;) - { - if( (uint32_t)priv->send_sbc <= (uint32_t)priv->recv_sbc ) - { + for (;;) { + if ( (uint32_t)priv->send_sbc <= (uint32_t)priv->recv_sbc ) { TRACE_END(); return TPL_TRUE; } xcb_flush(c); ev = xcb_wait_for_special_event(c, priv->special_event); - if (!ev) - { + if (!ev) { TRACE_END(); return TPL_FALSE; } @@ -646,10 +606,8 @@ dri3_find_back(xcb_connection_t *c, dri3_drawable *priv) TPL_ASSERT(c); TPL_ASSERT(priv); - for (;;) - { - for (b = 0; b < dri3_max_back; b++) - { + for (;;) { + for (b = 0; b < dri3_max_back; b++) { int id = (b + priv->cur_back + 1) % dri3_max_back; int pre_id = (id + dri3_max_back - 2) % dri3_max_back; @@ -657,10 +615,9 @@ dri3_find_back(xcb_connection_t *c, dri3_drawable *priv) dri3_buffer *pre_buffer = priv->buffers[pre_id]; if (pre_buffer && pre_buffer->status != dri3_buffer_posted) - pre_buffer->status = dri3_buffer_idle; + pre_buffer->status = dri3_buffer_idle; - if (!buffer || buffer->status == dri3_buffer_idle) - { + if (!buffer || buffer->status == dri3_buffer_idle) { priv->cur_back = id; return id; } @@ -671,8 +628,7 @@ dri3_find_back(xcb_connection_t *c, dri3_drawable *priv) ev = xcb_wait_for_special_event(c, priv->special_event); TRACE_END(); - if (!ev) - { + if (!ev) { return -1; } @@ -688,14 +644,14 @@ dri3_find_back(xcb_connection_t *c, dri3_drawable *priv) */ static dri3_buffer * dri3_alloc_render_buffer(dri3_drawable *priv, - int width, int height, int depth, int cpp) + int width, int height, int depth, int cpp) { Display *dpy; Drawable draw; dri3_buffer *buffer = NULL; xcb_connection_t *c; xcb_pixmap_t pixmap = 0; - int buffer_fd; + int buffer_fd; int size; tbm_bo_handle handle; xcb_void_cookie_t cookie; @@ -712,8 +668,7 @@ dri3_alloc_render_buffer(dri3_drawable *priv, /* Allocate the image from the driver */ buffer = calloc(1, sizeof (dri3_buffer)); - if (!buffer) - { + if (!buffer) { TPL_ERR("Failed to allocate buffer!"); goto no_buffer; } @@ -724,13 +679,12 @@ dri3_alloc_render_buffer(dri3_drawable *priv, /* buffer->pitch = width*(cpp/8); */ /* Modify the calculation of pitch (strdie) */ - buffer->pitch = SIZE_ALIGN((width * cpp)>>3, ALIGNMENT_PITCH_ARGB); + buffer->pitch = SIZE_ALIGN((width * cpp) >> 3, ALIGNMENT_PITCH_ARGB); - size = buffer->pitch*height; + size = buffer->pitch * height; buffer->tbo = tbm_bo_alloc(priv->bufmgr, size, TBM_BO_DEFAULT); - if (NULL == buffer->tbo) - { + if (NULL == buffer->tbo) { TPL_ERR("TBM bo alloc failed!"); free(buffer); goto no_buffer; @@ -761,13 +715,11 @@ dri3_alloc_render_buffer(dri3_drawable *priv, /* buffer_fd is unuseful */ /* close(buffer_fd);*/ - if (error) - { + if (error) { TPL_ERR("No pixmap!"); goto no_pixmap; } - if (0 == pixmap) - { + if (0 == pixmap) { TPL_ERR("No pixmap!"); goto no_pixmap; } @@ -804,8 +756,7 @@ dri3_free_render_buffer(dri3_drawable *pdraw, dri3_buffer *buffer) /* 2015-04-08 joonbum.ko@samsung.com */ /* if drawable type is pixmap, it requires only free buffer */ - if (!pdraw->is_pixmap) - { + if (!pdraw->is_pixmap) { if (buffer->own_pixmap) xcb_free_pixmap(c, buffer->pixmap); tbm_bo_unref(buffer->tbo); @@ -829,7 +780,7 @@ dri3_get_window_buffer(void *loaderPrivate, int cpp) dri3_drawable *priv = loaderPrivate; xcb_connection_t *c; dri3_buffer *backbuffer = NULL; - int back_buf_id,reuse = 1; + int back_buf_id, reuse = 1; uint32_t old_bo_name = 0; TPL_ASSERT(priv); @@ -848,24 +799,21 @@ dri3_get_window_buffer(void *loaderPrivate, int cpp) * old one is the wrong size. */ if (!backbuffer || backbuffer->width != priv->width || - backbuffer->height != priv->height ) - { + backbuffer->height != priv->height ) { dri3_buffer *new_buffer; /* Allocate the new buffers */ TRACE_BEGIN("DDK:DRI3:ALLOCRENDERBUFFER"); new_buffer = dri3_alloc_render_buffer(priv, - priv->width, priv->height, priv->depth, cpp); + priv->width, priv->height, priv->depth, cpp); TRACE_END(); - if (!new_buffer) - { + if (!new_buffer) { TRACE_END(); return NULL; } - if (backbuffer) - { + if (backbuffer) { /* [BEGIN: 20141125-xuelian.bai] Size not match,this buffer * must be removed from buffer cache, so we have to save * dma_buf_fd of old buffer.*/ @@ -884,14 +832,13 @@ dri3_get_window_buffer(void *loaderPrivate, int cpp) backbuffer->flags = DRI2_BUFFER_FB; backbuffer->status = dri3_buffer_busy; - if(reuse) - { + if (reuse) { backbuffer->flags |= DRI2_BUFFER_REUSED; } /* Return the requested buffer */ TRACE_END(); - TRACE_MARK("%d",tbm_bo_export(backbuffer->tbo)); + TRACE_MARK("%d", tbm_bo_export(backbuffer->tbo)); return backbuffer; } @@ -900,7 +847,8 @@ dri3_get_window_buffer(void *loaderPrivate, int cpp) /* modify internal flow of dri3_get_pixmap_buffer */ /* add 3rd argument for stride information */ static dri3_buffer * -dri3_get_pixmap_buffer(void *loaderPrivate, Pixmap pixmap, int cpp)/*TODO:format*/ +dri3_get_pixmap_buffer(void *loaderPrivate, Pixmap pixmap, + int cpp)/*TODO:format*/ { dri3_drawable *pdraw = loaderPrivate; dri3_buffer *buffer = NULL; @@ -923,16 +871,14 @@ dri3_get_pixmap_buffer(void *loaderPrivate, Pixmap pixmap, int cpp)/*TODO:format */ bp_cookie = xcb_dri3_buffer_from_pixmap(c, pixmap); bp_reply = xcb_dri3_buffer_from_pixmap_reply(c, bp_cookie, NULL); - if (!bp_reply) - { + if (!bp_reply) { goto no_image; } fds = xcb_dri3_buffer_from_pixmap_reply_fds(c, bp_reply); - tbo = tbm_bo_import_fd(pdraw->bufmgr,(tbm_fd)(*fds)); + tbo = tbm_bo_import_fd(pdraw->bufmgr, (tbm_fd)(*fds)); - if (!buffer) - { + if (!buffer) { buffer = calloc(1, sizeof (dri3_buffer)); if (!buffer) goto no_buffer; @@ -962,8 +908,8 @@ dri3_get_pixmap_buffer(void *loaderPrivate, Pixmap pixmap, int cpp)/*TODO:format TRACE_END(); return buffer; -/* 2015-04-09 joonbum.ko@samsung.com */ -/* change the lable order */ + /* 2015-04-09 joonbum.ko@samsung.com */ + /* change the lable order */ no_image: if (buffer) free(buffer); @@ -973,7 +919,7 @@ no_buffer: } static dri3_buffer *dri3_get_buffers(XID drawable, void *loaderPrivate, - unsigned int *attachments, int cpp) + unsigned int *attachments, int cpp) { dri3_drawable *priv = loaderPrivate; dri3_buffer *buffer = NULL; @@ -983,15 +929,13 @@ static dri3_buffer *dri3_get_buffers(XID drawable, void *loaderPrivate, TRACE_BEGIN("DDK:DRI3:GETBUFFERS"); - if (drawable != priv->xDrawable) - { + if (drawable != priv->xDrawable) { TPL_ERR("Drawable mismatch!"); TRACE_END(); return NULL; } - if (!dri3_update_drawable(loaderPrivate)) - { + if (!dri3_update_drawable(loaderPrivate)) { TPL_ERR("Update drawable failed!"); TRACE_END(); return NULL; @@ -999,12 +943,11 @@ static dri3_buffer *dri3_get_buffers(XID drawable, void *loaderPrivate, if (*attachments == dri3_buffer_front) buffer = dri3_get_pixmap_buffer(loaderPrivate, - priv->xDrawable, cpp); + priv->xDrawable, cpp); else buffer = dri3_get_window_buffer(loaderPrivate, cpp); - if (NULL == buffer) - { + if (NULL == buffer) { TPL_ERR("Get buffer failed!"); return NULL; } @@ -1021,7 +964,8 @@ static dri3_buffer *dri3_get_buffers(XID drawable, void *loaderPrivate, * if (region_t==0),swap whole frame, else swap with region ******************************************************/ static int64_t -dri3_swap_buffers(Display *dpy, void *priv, tpl_buffer_t *frame_buffer, int interval, XID region_t) +dri3_swap_buffers(Display *dpy, void *priv, tpl_buffer_t *frame_buffer, + int interval, XID region_t) { int64_t ret = -1; @@ -1031,7 +975,7 @@ dri3_swap_buffers(Display *dpy, void *priv, tpl_buffer_t *frame_buffer, int inte xcb_connection_t *c; dri3_drawable *pDrawable; dri3_buffer *back = NULL; - int i = 0; + int i = 0; TPL_ASSERT(dpy); TPL_ASSERT(priv); @@ -1039,11 +983,10 @@ dri3_swap_buffers(Display *dpy, void *priv, tpl_buffer_t *frame_buffer, int inte c = XGetXCBConnection(dpy); - pDrawable = (dri3_drawable*) priv; - back = (dri3_buffer*) frame_buffer->backend.data; + pDrawable = (dri3_drawable *) priv; + back = (dri3_buffer *) frame_buffer->backend.data; - if ((back == NULL)||(pDrawable == NULL)||(pDrawable->is_pixmap != 0)) - { + if ((back == NULL) || (pDrawable == NULL) || (pDrawable->is_pixmap != 0)) { TRACE_END(); return ret; } @@ -1051,16 +994,14 @@ dri3_swap_buffers(Display *dpy, void *priv, tpl_buffer_t *frame_buffer, int inte /* Process any present events that have been received from the X * server until receive complete notify. */ - if (!dri3_wait_for_notify(c, pDrawable)) - { + if (!dri3_wait_for_notify(c, pDrawable)) { TRACE_END(); return ret; } - /* [BEGIN: 20140119-leiba.sun] Add support for buffer age - * When swap buffer, increase buffer age of every back buffer */ - for(i = 0; i < dri3_max_back; i++) - { - if((pDrawable->buffers[i] != NULL)&&(pDrawable->buffers[i]->buffer_age > 0)) + /* [BEGIN: 20140119-leiba.sun] Add support for buffer age + * When swap buffer, increase buffer age of every back buffer */ + for (i = 0; i < dri3_max_back; i++) { + if ((pDrawable->buffers[i] != NULL) && (pDrawable->buffers[i]->buffer_age > 0)) pDrawable->buffers[i]->buffer_age++; } back->buffer_age = 1; @@ -1078,26 +1019,26 @@ dri3_swap_buffers(Display *dpy, void *priv, tpl_buffer_t *frame_buffer, int inte ++pDrawable->send_sbc; if (target_msc == 0) target_msc = pDrawable->msc + pDrawable->swap_interval * - (pDrawable->send_sbc - pDrawable->recv_sbc); + (pDrawable->send_sbc - pDrawable->recv_sbc); back->last_swap = pDrawable->send_sbc; TRACE_MARK("SWAP:%d", tbm_bo_export(back->tbo)) ; xcb_present_pixmap(c, - pDrawable->xDrawable, /* dst */ - back->pixmap, /* src */ - (uint32_t) pDrawable->send_sbc, - 0, /* valid */ - region_t, /* update */ - 0, /* x_off */ - 0, /* y_off */ - None, /* target_crtc */ - None, - 0, - XCB_PRESENT_OPTION_NONE, - /*target_msc*/0, - divisor, - remainder, 0, NULL); + pDrawable->xDrawable, /* dst */ + back->pixmap, /* src */ + (uint32_t) pDrawable->send_sbc, + 0, /* valid */ + region_t, /* update */ + 0, /* x_off */ + 0, /* y_off */ + None, /* target_crtc */ + None, + 0, + XCB_PRESENT_OPTION_NONE, + /*target_msc*/0, + divisor, + remainder, 0, NULL); ret = (int64_t) pDrawable->send_sbc; @@ -1118,14 +1059,13 @@ __tpl_x11_dri3_buffer_init(tpl_buffer_t *buffer) void __tpl_x11_dri3_buffer_fini(tpl_buffer_t *buffer) { - dri3_buffer* back; + dri3_buffer *back; TPL_ASSERT(buffer); - back = (dri3_buffer*)buffer->backend.data; + back = (dri3_buffer *)buffer->backend.data; - if (back) - { + if (back) { tbm_bo bo = back->tbo; tbm_bo_map(bo, TBM_DEVICE_3D, TBM_OPTION_READ); tbm_bo_unmap(bo); @@ -1144,7 +1084,7 @@ __tpl_x11_dri3_buffer_map(tpl_buffer_t *buffer, int size) TPL_ASSERT(buffer); TPL_IGNORE(size); - bo = ((dri3_buffer*)buffer->backend.data)->tbo; + bo = ((dri3_buffer *)buffer->backend.data)->tbo; TPL_ASSERT(bo); handle = tbm_bo_get_handle(bo, TBM_DEVICE_CPU); @@ -1166,47 +1106,44 @@ __tpl_x11_dri3_buffer_lock(tpl_buffer_t *buffer, tpl_lock_usage_t usage) { tbm_bo bo; tbm_bo_handle handle; - dri3_buffer* back; + dri3_buffer *back; TPL_ASSERT(buffer); TPL_ASSERT(buffer->backend.data); - back = (dri3_buffer*) buffer->backend.data; + back = (dri3_buffer *) buffer->backend.data; bo = back->tbo; - if (NULL == bo) - { + if (NULL == bo) { TPL_ERR("bo is NULL!"); return TPL_FALSE; } - TRACE_BEGIN("TPL:BUFFERLOCK:%d",tbm_bo_export(bo)); + TRACE_BEGIN("TPL:BUFFERLOCK:%d", tbm_bo_export(bo)); TPL_OBJECT_UNLOCK(buffer); - switch (usage) - { - case TPL_LOCK_USAGE_GPU_READ: - handle = tbm_bo_map(bo, TBM_DEVICE_3D, TBM_OPTION_READ); - break; - case TPL_LOCK_USAGE_GPU_WRITE: - handle = tbm_bo_map(bo, TBM_DEVICE_3D, TBM_OPTION_WRITE); - break; - case TPL_LOCK_USAGE_CPU_READ: - handle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_READ); - break; - case TPL_LOCK_USAGE_CPU_WRITE: - handle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE); - break; - default: - TPL_ASSERT(TPL_FALSE); - return TPL_FALSE; + switch (usage) { + case TPL_LOCK_USAGE_GPU_READ: + handle = tbm_bo_map(bo, TBM_DEVICE_3D, TBM_OPTION_READ); + break; + case TPL_LOCK_USAGE_GPU_WRITE: + handle = tbm_bo_map(bo, TBM_DEVICE_3D, TBM_OPTION_WRITE); + break; + case TPL_LOCK_USAGE_CPU_READ: + handle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_READ); + break; + case TPL_LOCK_USAGE_CPU_WRITE: + handle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE); + break; + default: + TPL_ASSERT(TPL_FALSE); + return TPL_FALSE; } TPL_OBJECT_LOCK(buffer); - if (handle.u32 != 0 || handle.ptr != NULL) - { + if (handle.u32 != 0 || handle.ptr != NULL) { TRACE_END(); return TPL_FALSE; } @@ -1222,16 +1159,15 @@ __tpl_x11_dri3_buffer_unlock(tpl_buffer_t *buffer) TPL_ASSERT(buffer); - back = (dri3_buffer*) buffer->backend.data; + back = (dri3_buffer *) buffer->backend.data; bo = back->tbo; - if (NULL == bo) - { + if (NULL == bo) { TPL_ERR("bo is NULL!"); return; } - TRACE_BEGIN("TPL:BUFFERUNLOCK:%d",tbm_bo_export(back->tbo)); + TRACE_BEGIN("TPL:BUFFERUNLOCK:%d", tbm_bo_export(back->tbo)); TPL_OBJECT_UNLOCK(buffer); tbm_bo_unmap(bo); @@ -1264,17 +1200,15 @@ __tpl_x11_dri3_display_init(tpl_display_t *display) TPL_ASSERT(display); - XInitThreads(); - if (display->native_handle == NULL) - { + XInitThreads(); + if (display->native_handle == NULL) { display->native_handle = XOpenDisplay(NULL); TPL_ASSERT(display->native_handle != NULL); } pthread_mutex_lock(&mutex); - if (global.display_count == 0) - { + if (global.display_count == 0) { tpl_bool_t xres = TPL_FALSE; Window root = 0; drm_magic_t magic; @@ -1304,12 +1238,11 @@ __tpl_x11_dri3_display_init(tpl_display_t *display) const char *backend_env = NULL; int count = 0; backend_env = getenv("MALI_EGL_DRI3_BUF_NUM"); - /* 2015-05-13 joonbum.ko@samsung.com */ - /* Change the value of dri3_max_back 5 to 3 */ + /* 2015-05-13 joonbum.ko@samsung.com */ + /* Change the value of dri3_max_back 5 to 3 */ if (!backend_env || strlen(backend_env) == 0) dri3_max_back = 3; /* Default value is 3*/ - else - { + else { count = atoi(backend_env); if (count == 1)/* one buffer doesn't work,min is 2 */ dri3_max_back = 2; @@ -1336,8 +1269,7 @@ __tpl_x11_dri3_display_fini(tpl_display_t *display) TPL_IGNORE(display); pthread_mutex_lock(&mutex); - if (--global.display_count == 0) - { + if (--global.display_count == 0) { tbm_bufmgr_deinit(global.bufmgr); close(global.bufmgr_fd); XCloseDisplay(global.worker_display); @@ -1362,9 +1294,9 @@ __tpl_x11_dri3_surface_init(tpl_surface_t *surface) TPL_ASSERT(surface); - x11_surface = (tpl_x11_dri3_surface_t *)calloc(1, sizeof(tpl_x11_dri3_surface_t)); - if (x11_surface == NULL) - { + x11_surface = (tpl_x11_dri3_surface_t *)calloc(1, + sizeof(tpl_x11_dri3_surface_t)); + if (x11_surface == NULL) { TPL_ERR("Failed to allocate buffer!"); return TPL_FALSE; } @@ -1378,17 +1310,14 @@ __tpl_x11_dri3_surface_init(tpl_surface_t *surface) x11_surface->drawable = dri3_create_drawable(display, drawable); surface->backend.data = (void *)x11_surface; - if (surface->type == TPL_SURFACE_TYPE_WINDOW) - { + if (surface->type == TPL_SURFACE_TYPE_WINDOW) { __tpl_x11_display_get_window_info(surface->display, - surface->native_handle, - &surface->width, &surface->height, NULL, 0, 0); - } - else - { + surface->native_handle, + &surface->width, &surface->height, NULL, 0, 0); + } else { __tpl_x11_display_get_pixmap_info(surface->display, - surface->native_handle, - &surface->width, &surface->height, NULL); + surface->native_handle, + &surface->width, &surface->height, NULL); } return TPL_TRUE; @@ -1407,10 +1336,9 @@ __tpl_x11_dri3_surface_fini(tpl_surface_t *surface) display = (Display *) surface->display->native_handle; x11_surface = (tpl_x11_dri3_surface_t *) surface->backend.data; - dri3_destroy_drawable(display, (XID)surface->native_handle); + dri3_destroy_drawable(display, (XID)surface->native_handle); - if (x11_surface) - { + if (x11_surface) { __tpl_x11_surface_buffer_cache_clear(&x11_surface->buffer_cache); @@ -1425,8 +1353,8 @@ __tpl_x11_dri3_surface_fini(tpl_surface_t *surface) static void __tpl_x11_dri3_surface_post_internal(tpl_surface_t *surface, - tpl_frame_t *frame, - tpl_bool_t is_worker) + tpl_frame_t *frame, + tpl_bool_t is_worker) { Display *display = NULL; tpl_x11_dri3_surface_t *x11_surface; @@ -1441,54 +1369,43 @@ __tpl_x11_dri3_surface_post_internal(tpl_surface_t *surface, display = __tpl_x11_dri3_get_worker_display(); - if (frame->interval != x11_surface->latest_post_interval) - { + if (frame->interval != x11_surface->latest_post_interval) { x11_surface->latest_post_interval = frame->interval;/*FIXME:set interval?*/ } - if (__tpl_region_is_empty(&frame->damage)) - { - dri3_swap_buffers(display, x11_surface->drawable, frame->buffer, 0,0); - } - else - { + if (__tpl_region_is_empty(&frame->damage)) { + dri3_swap_buffers(display, x11_surface->drawable, frame->buffer, 0, 0); + } else { int i; - if (frame->damage.num_rects > TPL_STACK_XRECTANGLE_SIZE) - { + if (frame->damage.num_rects > TPL_STACK_XRECTANGLE_SIZE) { xrects = (XRectangle *)malloc(sizeof(XRectangle) * - frame->damage.num_rects); - } - else - { + frame->damage.num_rects); + } else { xrects = &xrects_stack[0]; } - for (i = 0; i < frame->damage.num_rects; i++) - { + for (i = 0; i < frame->damage.num_rects; i++) { const int *rects = &frame->damage.rects[i * 4]; xrects[i].x = rects[0]; xrects[i].y = frame->buffer->height - rects[1] - - rects[3]; + rects[3]; xrects[i].width = rects[2]; xrects[i].height = rects[3]; } - if (x11_surface->damage == None) - { + if (x11_surface->damage == None) { x11_surface->damage = - XFixesCreateRegion(display, xrects, - frame->damage.num_rects); - } - else - { + XFixesCreateRegion(display, xrects, + frame->damage.num_rects); + } else { XFixesSetRegion(display, x11_surface->damage, xrects, frame->damage.num_rects); } dri3_swap_buffers(display, x11_surface->drawable, frame->buffer, 0, - x11_surface->damage); + x11_surface->damage); } frame->state = TPL_FRAME_STATE_POSTED; @@ -1516,13 +1433,11 @@ __tpl_x11_dri3_surface_begin_frame(tpl_surface_t *surface) prev_frame = __tpl_surface_get_latest_frame(surface); - if (prev_frame && prev_frame->state != TPL_FRAME_STATE_POSTED) - { + if (prev_frame && prev_frame->state != TPL_FRAME_STATE_POSTED) { if ((DRI2_BUFFER_IS_FB(prev_frame->buffer->backend.flags) && global.fb_swap_type == TPL_X11_SWAP_TYPE_SYNC) || (!DRI2_BUFFER_IS_FB(prev_frame->buffer->backend.flags) && - global.win_swap_type == TPL_X11_SWAP_TYPE_SYNC)) - { + global.win_swap_type == TPL_X11_SWAP_TYPE_SYNC)) { __tpl_surface_wait_all_frames(surface); } } @@ -1542,13 +1457,11 @@ __tpl_x11_dri3_surface_validate_frame(tpl_surface_t *surface) prev_frame = __tpl_surface_get_latest_frame(surface); - if (prev_frame && prev_frame->state != TPL_FRAME_STATE_POSTED) - { + if (prev_frame && prev_frame->state != TPL_FRAME_STATE_POSTED) { if ((DRI2_BUFFER_IS_FB(prev_frame->buffer->backend.flags) && - global.fb_swap_type == TPL_X11_SWAP_TYPE_LAZY) || - (!DRI2_BUFFER_IS_FB(prev_frame->buffer->backend.flags) && - global.win_swap_type == TPL_X11_SWAP_TYPE_LAZY)) - { + global.fb_swap_type == TPL_X11_SWAP_TYPE_LAZY) || + (!DRI2_BUFFER_IS_FB(prev_frame->buffer->backend.flags) && + global.win_swap_type == TPL_X11_SWAP_TYPE_LAZY)) { __tpl_surface_wait_all_frames(surface); return TPL_TRUE; } @@ -1568,15 +1481,13 @@ __tpl_x11_dri3_surface_end_frame(tpl_surface_t *surface) frame = __tpl_surface_get_latest_frame(surface); x11_surface = (tpl_x11_dri3_surface_t *) surface->backend.data; - if (frame) - { + if (frame) { x11_surface->latest_render_target = frame->buffer; if ((DRI2_BUFFER_IS_FB(frame->buffer->backend.flags) && - global.fb_swap_type == TPL_X11_SWAP_TYPE_ASYNC) || - (!DRI2_BUFFER_IS_FB(frame->buffer->backend.flags) && - global.win_swap_type == TPL_X11_SWAP_TYPE_ASYNC)) - { + global.fb_swap_type == TPL_X11_SWAP_TYPE_ASYNC) || + (!DRI2_BUFFER_IS_FB(frame->buffer->backend.flags) && + global.win_swap_type == TPL_X11_SWAP_TYPE_ASYNC)) { __tpl_x11_dri3_surface_post_internal(surface, frame, TPL_FALSE); } } @@ -1587,7 +1498,8 @@ __tpl_x11_dri3_surface_end_frame(tpl_surface_t *surface) /* 2015-04-08 joonbum.ko@samsung.com */ /* change the key value of tpl_buffer_t from dma_buf_fd to tbo name */ static tpl_buffer_t * -__tpl_x11_dri3_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buffers) +__tpl_x11_dri3_surface_get_buffer(tpl_surface_t *surface, + tpl_bool_t *reset_buffers) { Drawable drawable; dri3_buffer *buffer = NULL; @@ -1602,8 +1514,7 @@ __tpl_x11_dri3_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buff x11_surface = (tpl_x11_dri3_surface_t *)surface->backend.data; - if (surface->type == TPL_SURFACE_TYPE_PIXMAP) - { + if (surface->type == TPL_SURFACE_TYPE_PIXMAP) { attachments[0] = dri3_buffer_front; } @@ -1615,14 +1526,12 @@ __tpl_x11_dri3_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buff buffer = dri3_get_buffers(drawable, x11_surface->drawable, attachments, cpp); - if (DRI2_BUFFER_IS_REUSED(buffer->flags)) - { + if (DRI2_BUFFER_IS_REUSED(buffer->flags)) { tpl_buffer = __tpl_x11_surface_buffer_cache_find( - &x11_surface->buffer_cache, - tbm_bo_export(buffer->tbo)); + &x11_surface->buffer_cache, + tbm_bo_export(buffer->tbo)); - if (tpl_buffer) - { + if (tpl_buffer) { /* If the buffer name is reused and there's a cache * entry for that name, just update the buffer age * and return. */ @@ -1637,25 +1546,22 @@ __tpl_x11_dri3_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buff } } - if (!tpl_buffer) - { + if (!tpl_buffer) { /* Remove the buffer from the cache. */ - __tpl_x11_surface_buffer_cache_remove( - &x11_surface->buffer_cache, - tbm_bo_export(buffer->tbo)); - if(buffer->old_bo_name != 0) - { + __tpl_x11_surface_buffer_cache_remove( + &x11_surface->buffer_cache, + tbm_bo_export(buffer->tbo)); + if (buffer->old_bo_name != 0) { __tpl_x11_surface_buffer_cache_remove( - &x11_surface->buffer_cache, - buffer->old_bo_name); + &x11_surface->buffer_cache, + buffer->old_bo_name); buffer->old_bo_name = 0; } } bo = buffer->tbo; - if (bo == NULL) - { + if (bo == NULL) { TPL_ERR("bo is NULL!"); goto done; } @@ -1664,10 +1570,9 @@ __tpl_x11_dri3_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buff /* Create tpl buffer. */ tpl_buffer = __tpl_buffer_alloc(surface, (size_t) tbm_bo_export(buffer->tbo), - (int)bo_handle.u32, - buffer->width, buffer->height, buffer->cpp * 8, buffer->pitch); - if (NULL == tpl_buffer) - { + (int)bo_handle.u32, + buffer->width, buffer->height, buffer->cpp * 8, buffer->pitch); + if (NULL == tpl_buffer) { TPL_ERR("TPL buffer alloc failed!"); goto done; } @@ -1686,11 +1591,10 @@ __tpl_x11_dri3_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buff __tpl_x11_surface_buffer_cache_add(&x11_surface->buffer_cache, tpl_buffer); tpl_object_unreference(&tpl_buffer->base); done: - if (reset_buffers) - { + if (reset_buffers) { /* Users use this output value to check if they have to reset previous buffers. */ *reset_buffers = !DRI2_BUFFER_IS_REUSED(buffer->flags) || - buffer->width != surface->width || buffer->height != surface->height; + buffer->width != surface->width || buffer->height != surface->height; } return tpl_buffer; @@ -1700,15 +1604,15 @@ done: int __tpl_x11_dri3_get_buffer_age(tpl_buffer_t *buffer) { - dri3_buffer *back; + dri3_buffer *back; TPL_ASSERT(buffer); - back = (dri3_buffer*) buffer->backend.data; + back = (dri3_buffer *) buffer->backend.data; - TPL_ASSERT(back); + TPL_ASSERT(back); - return back->buffer_age; + return back->buffer_age; } /* [END:20150119-leiba.sun] */ @@ -1769,7 +1673,7 @@ __tpl_buffer_init_backend_x11_dri3(tpl_buffer_backend_t *backend) backend->unmap = __tpl_x11_dri3_buffer_unmap; backend->lock = __tpl_x11_dri3_buffer_lock; backend->unlock = __tpl_x11_dri3_buffer_unlock; - /* [BEGIN: 20140119-leiba.sun] Add support for buffer age */ - backend->get_buffer_age = __tpl_x11_dri3_get_buffer_age; - /* [END:20150119-leiba.sun] */ + /* [BEGIN: 20140119-leiba.sun] Add support for buffer age */ + backend->get_buffer_age = __tpl_x11_dri3_get_buffer_age; + /* [END:20150119-leiba.sun] */ } diff --git a/src/tpl_x11_internal.h b/src/tpl_x11_internal.h index 5014326..fa14d04 100644 --- a/src/tpl_x11_internal.h +++ b/src/tpl_x11_internal.h @@ -29,8 +29,7 @@ typedef struct _tpl_x11_global tpl_x11_global_t; -typedef enum -{ +typedef enum { TPL_X11_SWAP_TYPE_ERROR = -1, TPL_X11_SWAP_TYPE_SYNC = 0, TPL_X11_SWAP_TYPE_ASYNC, @@ -38,8 +37,7 @@ typedef enum TPL_X11_SWAP_TYPE_MAX } tpl_x11_swap_type_t; -struct _tpl_x11_global -{ +struct _tpl_x11_global { int display_count; Display *worker_display; @@ -57,11 +55,14 @@ void __tpl_x11_swap_str_to_swap_type(char *str, tpl_x11_swap_type_t *type); tpl_buffer_t * -__tpl_x11_surface_buffer_cache_find(tpl_list_t *buffer_cache, unsigned int name); +__tpl_x11_surface_buffer_cache_find(tpl_list_t *buffer_cache, + unsigned int name); void -__tpl_x11_surface_buffer_cache_remove(tpl_list_t *buffer_cache, unsigned int name); +__tpl_x11_surface_buffer_cache_remove(tpl_list_t *buffer_cache, + unsigned int name); tpl_bool_t -__tpl_x11_surface_buffer_cache_add(tpl_list_t *buffer_cache, tpl_buffer_t *buffer); +__tpl_x11_surface_buffer_cache_add(tpl_list_t *buffer_cache, + tpl_buffer_t *buffer); void __tpl_x11_surface_buffer_cache_clear(tpl_list_t *buffer_cache); tpl_bool_t @@ -71,7 +72,7 @@ __tpl_x11_display_query_config(tpl_display_t *display, int color_depth, int *native_visual_id, tpl_bool_t *is_slow); tpl_bool_t __tpl_x11_display_get_window_info(tpl_display_t *display, tpl_handle_t window, - int *width, int *height, tpl_format_t *format,int depth,int a_size); + int *width, int *height, tpl_format_t *format, int depth, int a_size); tpl_bool_t __tpl_x11_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap, int *width, int *height, tpl_format_t *format); diff --git a/src/wayland-egl/wayland-egl.c b/src/wayland-egl/wayland-egl.c index acb35f7..0602209 100644 --- a/src/wayland-egl/wayland-egl.c +++ b/src/wayland-egl/wayland-egl.c @@ -59,8 +59,7 @@ wl_egl_window_resize(struct wl_egl_window *egl_window, int width, int height, int dx, int dy) { - if (egl_window == NULL) - { + if (egl_window == NULL) { WL_EGL_ERR("egl_window is NULL"); return; } @@ -74,8 +73,8 @@ wl_egl_window_resize(struct wl_egl_window *egl_window, egl_window->resize_callback(egl_window, egl_window->private); WL_EGL_LOG(2, "egl_win:%10p WxH:%dx%d dx:%d dy:%d rsz_cb:%10p", - egl_window, egl_window->width, egl_window->height, - egl_window->dx, egl_window->dy, egl_window->resize_callback); + egl_window, egl_window->width, egl_window->height, + egl_window->dx, egl_window->dy, egl_window->resize_callback); } WL_EGL_EXPORT struct wl_egl_window * @@ -84,9 +83,8 @@ wl_egl_window_create(struct wl_surface *surface, { struct wl_egl_window *egl_window; - egl_window = malloc(sizeof *egl_window); - if (!egl_window) - { + egl_window = malloc(sizeof * egl_window); + if (!egl_window) { WL_EGL_ERR("failed to allocate memory for egl_window"); return NULL; } @@ -99,7 +97,7 @@ wl_egl_window_create(struct wl_surface *surface, egl_window->attached_height = 0; WL_EGL_LOG(2, "surf:%10p WxH:%dx%d egl_win:%10p priv:%10p", - surface, width, height, egl_window, egl_window->private); + surface, width, height, egl_window, egl_window->private); return egl_window; } @@ -107,8 +105,7 @@ wl_egl_window_create(struct wl_surface *surface, WL_EGL_EXPORT void wl_egl_window_destroy(struct wl_egl_window *egl_window) { - if(egl_window == NULL) - { + if (egl_window == NULL) { WL_EGL_ERR("egl_window is NULL"); return; } @@ -128,6 +125,6 @@ wl_egl_window_get_attached_size(struct wl_egl_window *egl_window, *height = egl_window->attached_height; WL_EGL_LOG(2, "egl_win:%10p w:%10p h:%10p att_w:%d att_h:%d", - egl_window, width, height, egl_window->attached_width, - egl_window->attached_height); + egl_window, width, height, egl_window->attached_width, + egl_window->attached_height); } diff --git a/tc/src/main.c b/tc/src/main.c index 7304391..241dca7 100644 --- a/tc/src/main.c +++ b/tc/src/main.c @@ -13,8 +13,7 @@ typedef struct _ProgOption ProgOption; -typedef struct _ProgOption -{ +typedef struct _ProgOption { int egl_r; int egl_g; int egl_b; @@ -34,8 +33,7 @@ typedef struct _ProgOption bool show_names; }; -ProgOption g_option = -{ +ProgOption g_option = { 8, 8, 8, 8, 24, 0, @@ -53,7 +51,7 @@ ProgOption g_option = /* log related */ #ifdef TPL_ENABLE_LOG bool -__LOG( const char* func, int line, const char* fmt, ... ) +__LOG( const char *func, int line, const char *fmt, ... ) { char buff[NUM_ERR_STR] = { (char)0, }; char str[NUM_ERR_STR] = { (char)0, }; @@ -71,7 +69,7 @@ __LOG( const char* func, int line, const char* fmt, ... ) } void -__LOG_BEGIN( const char* func ) +__LOG_BEGIN( const char *func ) { char str[NUM_ERR_STR] = { (char)0, }; sprintf( str, "[tpl_test][B] %s", func ); @@ -80,7 +78,7 @@ __LOG_BEGIN( const char* func ) } void -__LOG_END( const char* func ) +__LOG_END( const char *func ) { char str[NUM_ERR_STR] = { (char)0, }; sprintf( str, "[tpl_test][E] %s", func ); @@ -89,7 +87,7 @@ __LOG_END( const char* func ) } bool -__tpl_test_log_display_msg( const char* msg ) +__tpl_test_log_display_msg( const char *msg ) { fprintf( DEFAULT_LOG_STREAM, "%s\n", msg ); fflush( DEFAULT_LOG_STREAM ); @@ -97,7 +95,7 @@ __tpl_test_log_display_msg( const char* msg ) } bool -__LOG_ERR( const char* func, int line, const char* fmt, ... ) +__LOG_ERR( const char *func, int line, const char *fmt, ... ) { char buff[NUM_ERR_STR] = { (char)0, }; char str[NUM_ERR_STR] = { (char)0, }; @@ -117,20 +115,16 @@ __LOG_ERR( const char* func, int line, const char* fmt, ... ) #endif /* TPL_ENABLE_LOG */ /* wayland native related */ -registry_handle_global(void *data, struct wl_registry *registry,uint32_t id, const char *interface,uint32_t version) +registry_handle_global(void *data, struct wl_registry *registry, uint32_t id, + const char *interface, uint32_t version) { - TPLNativeWnd* that = (TPLNativeWnd *)(data); + TPLNativeWnd *that = (TPLNativeWnd *)(data); - if (strcmp(interface, "wl_compositor") == 0) - { - that->compositor = wl_registry_bind(registry,id, &wl_compositor_interface, 1); - } - else if (strcmp(interface, "wl_shell") == 0) - { - that->shell = wl_registry_bind(registry,id, &wl_shell_interface, 1); - } - else if (strcmp(interface, "wl_output") == 0) - { + if (strcmp(interface, "wl_compositor") == 0) { + that->compositor = wl_registry_bind(registry, id, &wl_compositor_interface, 1); + } else if (strcmp(interface, "wl_shell") == 0) { + that->shell = wl_registry_bind(registry, id, &wl_shell_interface, 1); + } else if (strcmp(interface, "wl_output") == 0) { /*struct my_output *my_output = new struct my_output; memset(my_output, 0, sizeof(*my_output)); my_output->output = wl_registry_bind(registry,id, &wl_output_interface, 2);*/ @@ -138,28 +132,32 @@ registry_handle_global(void *data, struct wl_registry *registry,uint32_t id, con } void -registry_handle_global_remove(void * data,struct wl_registry * registry,uint32_t name) +registry_handle_global_remove(void *data, struct wl_registry *registry, + uint32_t name) { } -const struct wl_registry_listener registry_listener_ = -{ +const struct wl_registry_listener registry_listener_ = { registry_handle_global, registry_handle_global_remove }; -shell_surface_handle_ping(void * data, struct wl_shell_surface *shell_surface,uint32_t serial) +shell_surface_handle_ping(void *data, struct wl_shell_surface *shell_surface, + uint32_t serial) { wl_shell_surface_pong(shell_surface, serial); } void -shell_surface_handle_popup_done(void * data,struct wl_shell_surface * shell_surface) +shell_surface_handle_popup_done(void *data, + struct wl_shell_surface *shell_surface) { } void -shell_surface_handle_configure(void *data, struct wl_shell_surface * shell_surface,uint32_t edges, int32_t width, int32_t height) +shell_surface_handle_configure(void *data, + struct wl_shell_surface *shell_surface, uint32_t edges, int32_t width, + int32_t height) { TPLNativeWnd *that = (TPLNativeWnd *)(data); that->width = width; @@ -168,8 +166,7 @@ shell_surface_handle_configure(void *data, struct wl_shell_surface * shell_surfa } -const struct wl_shell_surface_listener shell_surface_listener_ = -{ +const struct wl_shell_surface_listener shell_surface_listener_ = { shell_surface_handle_ping, shell_surface_handle_configure, shell_surface_handle_popup_done @@ -177,34 +174,35 @@ const struct wl_shell_surface_listener shell_surface_listener_ = /* wayland native end */ /* tpl_test related */ -TPLNativeWnd* +TPLNativeWnd * tpl_test_native_wnd_create( void ) { - TPLNativeWnd* wnd = NULL; + TPLNativeWnd *wnd = NULL; TPL_RSM_MALLOC( wnd, TPLNativeWnd ); //wnd->dpy = (NativeDisplayType)NULL; - wnd->dpy = (void*)NULL; + wnd->dpy = (void *)NULL; wnd->screen = 0; //wnd->root = (NativeWindowType)NULL; - wnd->root = (void*)NULL; + wnd->root = (void *)NULL; //wnd->wnd = (NativeWindowType)NULL; - wnd->wnd = (void*)NULL; + wnd->wnd = (void *)NULL; wnd->x = 0; wnd->y = 0; wnd->width = 0; wnd->height = 0; wnd->depth = 0; - tpl_display_t * tpl_display = NULL; - tpl_surface_t * tpl_surf = NULL; - tpl_buffer_t * tpl_buf = NULL; + tpl_display_t *tpl_display = NULL; + tpl_surface_t *tpl_surf = NULL; + tpl_buffer_t *tpl_buf = NULL; finish: return wnd; } bool -tpl_test_native_wnd_initialize( TPLNativeWnd* wnd, int x, int y, int width, int height ) +tpl_test_native_wnd_initialize( TPLNativeWnd *wnd, int x, int y, int width, + int height ) { bool res = false; @@ -215,9 +213,8 @@ tpl_test_native_wnd_initialize( TPLNativeWnd* wnd, int x, int y, int width, int TPL_CHK_PARAM( height <= 0 ); //wnd->dpy = (NativeDisplayType)wl_display_connect(NULL); - wnd->dpy = (void*)wl_display_connect(NULL); - if( !wnd->dpy ) - { + wnd->dpy = (void *)wl_display_connect(NULL); + if ( !wnd->dpy ) { __log_err( "wl_display_connect() is failed."); return res; } @@ -234,15 +231,15 @@ tpl_test_native_wnd_initialize( TPLNativeWnd* wnd, int x, int y, int width, int wnd->height = height; wnd->depth = 32; - wnd->surface= wl_compositor_create_surface(wnd->compositor); - wnd->wnd = wl_egl_window_create(wnd->surface,wnd->width, wnd->height); + wnd->surface = wl_compositor_create_surface(wnd->compositor); + wnd->wnd = wl_egl_window_create(wnd->surface, wnd->width, wnd->height); - wnd->shell_surface = wl_shell_get_shell_surface(wnd->shell,wnd->surface); + wnd->shell_surface = wl_shell_get_shell_surface(wnd->shell, wnd->surface); wl_shell_surface_set_toplevel(wnd->shell_surface); - if (wnd->shell_surface) - { - wl_shell_surface_add_listener(wnd->shell_surface,&shell_surface_listener_, wnd); + if (wnd->shell_surface) { + wl_shell_surface_add_listener(wnd->shell_surface, &shell_surface_listener_, + wnd); } wl_shell_surface_set_title(wnd->shell_surface, "tpl_testtest"); @@ -253,7 +250,7 @@ finish: } bool -tpl_test_native_wnd_finalize( TPLNativeWnd* wnd ) +tpl_test_native_wnd_finalize( TPLNativeWnd *wnd ) { bool res = false; @@ -282,19 +279,17 @@ finish: } bool -tpl_test_finalize( TPLNativeWnd* wnd ) +tpl_test_finalize( TPLNativeWnd *wnd ) { bool res = true; TPL_CHK_PARAM( !wnd ); - if(NULL != wnd->tpl_display) - { - tpl_object_unreference((tpl_object_t*)wnd->tpl_display); + if (NULL != wnd->tpl_display) { + tpl_object_unreference((tpl_object_t *)wnd->tpl_display); } - if(NULL != wnd->tpl_surf) - { - tpl_object_unreference((tpl_object_t*)wnd->tpl_surf); + if (NULL != wnd->tpl_surf) { + tpl_object_unreference((tpl_object_t *)wnd->tpl_surf); } res = true; @@ -304,7 +299,7 @@ finish: void -tpl_test_native_wnd_release( TPLNativeWnd* wnd ) +tpl_test_native_wnd_release( TPLNativeWnd *wnd ) { TPL_CHK_PARAM( !wnd ); @@ -345,93 +340,91 @@ print_usage( char *name ) fprintf( stderr, "\n" ); fprintf( stderr, "Options:\n" ); - fprintf( stderr, " -w Set width size of the window default: %d\n", g_option.wnd_w ); - fprintf( stderr, " -h Set height size of the window default: %d\n", g_option.wnd_h ); - - fprintf( stderr, " -t Specify the test case number default: %d\n", g_option.tc_num ); - fprintf( stderr, " -a Run all test cases default: %s\n", g_option.all ? "true" : "false" ); - fprintf( stderr, " -l Show TC name default: %s\n", g_option.show_names ? "true" : "false" ); + fprintf( stderr, " -w Set width size of the window default: %d\n", + g_option.wnd_w ); + fprintf( stderr, " -h Set height size of the window default: %d\n", + g_option.wnd_h ); + + fprintf( stderr, " -t Specify the test case number default: %d\n", + g_option.tc_num ); + fprintf( stderr, " -a Run all test cases default: %s\n", + g_option.all ? "true" : "false" ); + fprintf( stderr, " -l Show TC name default: %s\n", + g_option.show_names ? "true" : "false" ); fprintf( stderr, "\n" ); exit( 1 ); } static void -check_option( int argc, char** argv ) +check_option( int argc, char **argv ) { int c; - char* opt_str = NULL; - - while( (c = getopt(argc, argv, "alc:d:s:p:x:y:w:h:f:t:F:i:")) != EOF ) - { - switch( c ) - { - case 'c': - opt_str = optarg; - if( strcmp(opt_str, "888") == 0 ) - { - g_option.egl_r = 8; - g_option.egl_g = 8; - g_option.egl_b = 8; - g_option.egl_a = 0; - } - else if( strcmp(opt_str, "8888") == 0 ) - { - g_option.egl_r = 8; - g_option.egl_g = 8; - g_option.egl_b = 8; - g_option.egl_a = 8; - } - else if( strcmp(opt_str, "565") == 0 ) - { - g_option.egl_r = 5; - g_option.egl_g = 6; - g_option.egl_b = 5; - g_option.egl_a = 0; - } - break; - case 'd': - g_option.egl_d = atol( optarg ); - break; - case 's': - g_option.egl_s = atol( optarg ); - break; - case 'p': - g_option.egl_preserved = atol( optarg ); - break; - case 'i': - g_option.egl_swap_interval = atol( optarg ); - break; - case 'x': - g_option.wnd_x = atol( optarg ); - break; - case 'y': - g_option.wnd_y = atol( optarg ); - break; - case 'w': - g_option.wnd_w = atol( optarg ); - break; - case 'h': - g_option.wnd_h = atol( optarg ); - break; - case 'f': - g_option.frames = atol( optarg ); - break; - case 't': - g_option.tc_num = atol( optarg ); - g_option.all = false; - break; - case 'F': - g_option.fps = atol( optarg ); - break; - case 'a': - g_option.all = true; - break; - case 'l': - g_option.show_names = true; - break; - default: - print_usage( argv[0] ); - break; + char *opt_str = NULL; + + while ( (c = getopt(argc, argv, "alc:d:s:p:x:y:w:h:f:t:F:i:")) != EOF ) { + switch ( c ) { + case 'c': + opt_str = optarg; + if ( strcmp(opt_str, "888") == 0 ) { + g_option.egl_r = 8; + g_option.egl_g = 8; + g_option.egl_b = 8; + g_option.egl_a = 0; + } else if ( strcmp(opt_str, "8888") == 0 ) { + g_option.egl_r = 8; + g_option.egl_g = 8; + g_option.egl_b = 8; + g_option.egl_a = 8; + } else if ( strcmp(opt_str, "565") == 0 ) { + g_option.egl_r = 5; + g_option.egl_g = 6; + g_option.egl_b = 5; + g_option.egl_a = 0; + } + break; + case 'd': + g_option.egl_d = atol( optarg ); + break; + case 's': + g_option.egl_s = atol( optarg ); + break; + case 'p': + g_option.egl_preserved = atol( optarg ); + break; + case 'i': + g_option.egl_swap_interval = atol( optarg ); + break; + case 'x': + g_option.wnd_x = atol( optarg ); + break; + case 'y': + g_option.wnd_y = atol( optarg ); + break; + case 'w': + g_option.wnd_w = atol( optarg ); + break; + case 'h': + g_option.wnd_h = atol( optarg ); + break; + case 'f': + g_option.frames = atol( optarg ); + break; + case 't': + g_option.tc_num = atol( optarg ); + g_option.all = false; + break; + case 'F': + g_option.fps = atol( optarg ); + break; + case 'a': + g_option.all = true; + break; + case 'l': + g_option.show_names = true; + break; + default: + print_usage( argv[0] ); + break; } } @@ -440,11 +433,12 @@ check_option( int argc, char** argv ) int tpl_test_log_level = 5; int -main( int argc, char** argv ) +main( int argc, char **argv ) { - TPLNativeWnd* wnd = NULL; + TPLNativeWnd *wnd = NULL; bool res = false; - int i = 0;int k=0; + int i = 0; + int k = 0; int total_num_test = ( sizeof(tpl_test) / sizeof(TPLTest) ) - 1; int tc_num = 0; char *log_env; @@ -454,30 +448,25 @@ main( int argc, char** argv ) check_option( argc, argv ); log_env = getenv("TPL_TEST_LOG_LEVEL"); - if (log_env != NULL) - { + if (log_env != NULL) { tpl_test_log_level = atoi(log_env); } - LOG("INFO",LOG_LEVEL_LOW,"tpl_test_log_level = %d",tpl_test_log_level); + LOG("INFO", LOG_LEVEL_LOW, "tpl_test_log_level = %d", tpl_test_log_level); env = getenv("TEST_SLEEP"); - if (env && !strcmp(env,"yes")) - { - while(k<20) - { - usleep(1000*1000); - printf("sleep %d\n",k++); + if (env && !strcmp(env, "yes")) { + while (k < 20) { + usleep(1000 * 1000); + printf("sleep %d\n", k++); } } - if( g_option.show_names ) - { + if ( g_option.show_names ) { printf( "-------------------------------------------------\n" ); printf( " number of test cass: %d \n", total_num_test ); printf( "-------------------------------------------------\n" ); - while( tpl_test[i].name ) - { + while ( tpl_test[i].name ) { printf( " [%2d] %s\n", i, tpl_test[i].name ); i++; } @@ -487,51 +476,46 @@ main( int argc, char** argv ) } wnd = tpl_test_native_wnd_create(); - if( !wnd ) goto finish; + if ( !wnd ) goto finish; res = tpl_test_native_wnd_initialize( wnd, - g_option.wnd_x, - g_option.wnd_y, - g_option.wnd_w, - g_option.wnd_h ); - if( !res ) goto finish; + g_option.wnd_x, + g_option.wnd_y, + g_option.wnd_w, + g_option.wnd_h ); + if ( !res ) goto finish; printf( "-------------------tpl test begin!!!-----------------------------------\n"); - if( g_option.all ) - { + if ( g_option.all ) { i = 0; - while( tpl_test[i].name ) - { + while ( tpl_test[i].name ) { printf( "[%4d] %-50s", i, tpl_test[i].name ); - if( tpl_test[i].run ) - { - if(true == tpl_test[i].run( wnd )) + if ( tpl_test[i].run ) { + if (true == tpl_test[i].run( wnd )) printf("[PASS]\n"); else printf("[FAIL]\n"); } i++; } - } - else - { + } else { tc_num = g_option.tc_num; - if( tc_num < 0 || tc_num > total_num_test-1 ) goto finish; + if ( tc_num < 0 || tc_num > total_num_test - 1 ) goto finish; //printf( "----------------------------------------------\n\n" ); - if( tpl_test[tc_num].name ) printf( "[%4d] %-50s", tc_num, tpl_test[tc_num].name ); + if ( tpl_test[tc_num].name ) printf( "[%4d] %-50s", tc_num, + tpl_test[tc_num].name ); else printf( "[%4d] No test name\n", tc_num ); - if( tpl_test[tc_num].run ) - { - if(true == tpl_test[tc_num].run( wnd )) - printf("[PASS]\n"); - else - printf("[FAIL]\n"); + if ( tpl_test[tc_num].run ) { + if (true == tpl_test[tc_num].run( wnd )) + printf("[PASS]\n"); + else + printf("[FAIL]\n"); } //printf( "\n----------------------------------------------\n\n" ); } @@ -539,12 +523,11 @@ main( int argc, char** argv ) printf("-------------------tpl test end!!!-------------------------------------\n"); finish: - if( wnd ) - { - tpl_test_native_wnd_finalize( wnd ); - tpl_test_native_wnd_release( wnd ); - tpl_test_finalize( wnd ); - } + if ( wnd ) { + tpl_test_native_wnd_finalize( wnd ); + tpl_test_native_wnd_release( wnd ); + tpl_test_finalize( wnd ); + } return 0; diff --git a/tc/src/tpl_test_buffer.c b/tc/src/tpl_test_buffer.c index 3c8e816..1c411dd 100644 --- a/tc/src/tpl_test_buffer.c +++ b/tc/src/tpl_test_buffer.c @@ -4,17 +4,16 @@ #include "tpl_test_util.h" -bool tpl_buffer_map_unmap_test(TPLNativeWnd* wnd ) +bool tpl_buffer_map_unmap_test(TPLNativeWnd *wnd ) { TPL_CHK_PARAM( !wnd ); bool ret = true; - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); //1.tpl_display_get wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; @@ -22,9 +21,9 @@ bool tpl_buffer_map_unmap_test(TPLNativeWnd* wnd ) //2.tpl_surface_create wnd->tpl_surf = NULL; - wnd->tpl_surf = tpl_surface_create(wnd->tpl_display , (tpl_handle_t)wnd->wnd, TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); - if(wnd->tpl_surf == NULL) - { + wnd->tpl_surf = tpl_surface_create(wnd->tpl_display , (tpl_handle_t)wnd->wnd, + TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); + if (wnd->tpl_surf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_create"); ret = false; goto finish; @@ -36,8 +35,7 @@ bool tpl_buffer_map_unmap_test(TPLNativeWnd* wnd ) //4.get buffer wnd->tpl_buf = NULL; wnd->tpl_buf = tpl_surface_get_buffer(wnd->tpl_surf, NULL); - if (wnd->tpl_buf == NULL) - { + if (wnd->tpl_buf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_get_buffer"); ret = false; goto finish; @@ -47,40 +45,39 @@ bool tpl_buffer_map_unmap_test(TPLNativeWnd* wnd ) void *ptr = NULL; //int size = tpl_buf->width * tpl_buf->height * tpl_buf->depth; int size = wnd->width * wnd->height ; - LOG("INFO", LOG_LEVEL_LOW ,"width=%d,height=%d,size=%d\n",wnd->width , wnd->height , size); + LOG("INFO", LOG_LEVEL_LOW , "width=%d,height=%d,size=%d\n", wnd->width , + wnd->height , size); ptr = tpl_buffer_map(wnd->tpl_buf, size); - if (ptr == NULL) - { + if (ptr == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_buffer_map"); ret = false; goto finish; } //5.buffer unmap - tpl_buffer_unmap(wnd->tpl_buf,ptr,size); + tpl_buffer_unmap(wnd->tpl_buf, ptr, size); finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; } -bool tpl_buffer_lock_unlock_test(TPLNativeWnd* wnd ) +bool tpl_buffer_lock_unlock_test(TPLNativeWnd *wnd ) { TPL_CHK_PARAM( !wnd ); bool ret = true; - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); //1.tpl_display_get wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; @@ -88,9 +85,9 @@ bool tpl_buffer_lock_unlock_test(TPLNativeWnd* wnd ) //2.tpl_surface_create wnd->tpl_surf = NULL; - wnd->tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); - if(wnd->tpl_surf == NULL) - { + wnd->tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, + TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); + if (wnd->tpl_surf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_create"); ret = false; goto finish; @@ -102,8 +99,7 @@ bool tpl_buffer_lock_unlock_test(TPLNativeWnd* wnd ) //4.get buffer wnd->tpl_buf = NULL; wnd->tpl_buf = tpl_surface_get_buffer(wnd->tpl_surf, NULL); - if (wnd->tpl_buf == NULL) - { + if (wnd->tpl_buf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_get_buffer"); ret = false; goto finish; @@ -111,9 +107,8 @@ bool tpl_buffer_lock_unlock_test(TPLNativeWnd* wnd ) //5.buffer lock tpl_bool_t result = false; - result = tpl_buffer_lock(wnd->tpl_buf,TPL_LOCK_USAGE_GPU_READ); - if(result == true) - { + result = tpl_buffer_lock(wnd->tpl_buf, TPL_LOCK_USAGE_GPU_READ); + if (result == true) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_buffer_lock"); ret = false; goto finish; @@ -121,9 +116,8 @@ bool tpl_buffer_lock_unlock_test(TPLNativeWnd* wnd ) tpl_buffer_unlock(wnd->tpl_buf); //TPL_LOCK_USAGE_GPU_WRITE - result = tpl_buffer_lock(wnd->tpl_buf,TPL_LOCK_USAGE_GPU_WRITE); - if(result == true) - { + result = tpl_buffer_lock(wnd->tpl_buf, TPL_LOCK_USAGE_GPU_WRITE); + if (result == true) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_buffer_lock"); ret = false; goto finish; @@ -131,9 +125,8 @@ bool tpl_buffer_lock_unlock_test(TPLNativeWnd* wnd ) tpl_buffer_unlock(wnd->tpl_buf); //TPL_LOCK_USAGE_CPU_READ - result = tpl_buffer_lock(wnd->tpl_buf,TPL_LOCK_USAGE_CPU_READ); - if(result == true) - { + result = tpl_buffer_lock(wnd->tpl_buf, TPL_LOCK_USAGE_CPU_READ); + if (result == true) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_buffer_lock"); ret = false; goto finish; @@ -141,9 +134,8 @@ bool tpl_buffer_lock_unlock_test(TPLNativeWnd* wnd ) tpl_buffer_unlock(wnd->tpl_buf); //TPL_LOCK_USAGE_CPU_WRITE - result = tpl_buffer_lock(wnd->tpl_buf,TPL_LOCK_USAGE_CPU_WRITE); - if(result == true) - { + result = tpl_buffer_lock(wnd->tpl_buf, TPL_LOCK_USAGE_CPU_WRITE); + if (result == true) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_buffer_lock"); ret = false; goto finish; @@ -152,27 +144,26 @@ bool tpl_buffer_lock_unlock_test(TPLNativeWnd* wnd ) finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; } -bool tpl_buffer_get_arg_test(TPLNativeWnd* wnd ) +bool tpl_buffer_get_arg_test(TPLNativeWnd *wnd ) { TPL_CHK_PARAM( !wnd ); bool ret = true; - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); //1.tpl_display_get wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; @@ -180,9 +171,9 @@ bool tpl_buffer_get_arg_test(TPLNativeWnd* wnd ) //2.tpl_surface_create wnd->tpl_surf = NULL; - wnd->tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); - if(wnd->tpl_surf == NULL) - { + wnd->tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, + TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); + if (wnd->tpl_surf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_create"); ret = false; goto finish; @@ -194,8 +185,7 @@ bool tpl_buffer_get_arg_test(TPLNativeWnd* wnd ) //4.get buffer wnd->tpl_buf = NULL; wnd->tpl_buf = tpl_surface_get_buffer(wnd->tpl_surf, NULL); - if (wnd->tpl_buf == NULL) - { + if (wnd->tpl_buf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_get_buffer"); ret = false; goto finish; @@ -204,8 +194,7 @@ bool tpl_buffer_get_arg_test(TPLNativeWnd* wnd ) //tpl_buffer_get_key unsigned int key = 0; key = tpl_buffer_get_key(wnd->tpl_buf); - if (key == 0) - { + if (key == 0) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_buffer_get_key"); ret = false; goto finish; @@ -214,8 +203,7 @@ bool tpl_buffer_get_arg_test(TPLNativeWnd* wnd ) //tpl_buffer_get_fd int fd = -1; fd = tpl_buffer_get_fd(wnd->tpl_buf); - if (fd == -1) - { + if (fd == -1) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_buffer_get_fd"); ret = false; goto finish; @@ -224,8 +212,7 @@ bool tpl_buffer_get_arg_test(TPLNativeWnd* wnd ) //tpl_buffer_get_age int age = -1; age = tpl_buffer_get_age(wnd->tpl_buf); - if (age == 0) - { + if (age == 0) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_buffer_get_age"); ret = false; goto finish; @@ -234,8 +221,7 @@ bool tpl_buffer_get_arg_test(TPLNativeWnd* wnd ) //tpl_buffer_get_surface tpl_surface_t *test_surf = NULL; test_surf = tpl_buffer_get_surface(wnd->tpl_buf); - if (test_surf == NULL) - { + if (test_surf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_buffer_get_surface"); ret = false; goto finish; @@ -244,8 +230,7 @@ bool tpl_buffer_get_arg_test(TPLNativeWnd* wnd ) //tpl_buffer_get_size int width = 0, heigh = 0; tpl_buffer_get_size(wnd->tpl_buf, &width, &heigh); - if ((width == 0)||(heigh == 0)) - { + if ((width == 0) || (heigh == 0)) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_buffer_get_size"); ret = false; goto finish; @@ -254,8 +239,7 @@ bool tpl_buffer_get_arg_test(TPLNativeWnd* wnd ) //tpl_buffer_get_depth int depth = 0; depth = tpl_buffer_get_depth(wnd->tpl_buf); - if (depth == 0) - { + if (depth == 0) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_buffer_get_depth"); ret = false; goto finish; @@ -263,8 +247,7 @@ bool tpl_buffer_get_arg_test(TPLNativeWnd* wnd ) //tpl_buffer_get_pitch int pitch = 0; pitch = tpl_buffer_get_fd(wnd->tpl_buf); - if (pitch == 0) - { + if (pitch == 0) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_buffer_get_fd"); ret = false; goto finish; @@ -272,27 +255,26 @@ bool tpl_buffer_get_arg_test(TPLNativeWnd* wnd ) finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; } -bool tpl_buffer_create_native_buffer_test(TPLNativeWnd* wnd ) +bool tpl_buffer_create_native_buffer_test(TPLNativeWnd *wnd ) { TPL_CHK_PARAM( !wnd ); bool ret = true; - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s---",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s---", __func__); //1.tpl_display_get wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; @@ -300,9 +282,9 @@ bool tpl_buffer_create_native_buffer_test(TPLNativeWnd* wnd ) //2.tpl_surface_create wnd->tpl_surf = NULL; - wnd->tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); - if(wnd->tpl_surf == NULL) - { + wnd->tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, + TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); + if (wnd->tpl_surf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_create"); ret = false; goto finish; @@ -314,8 +296,7 @@ bool tpl_buffer_create_native_buffer_test(TPLNativeWnd* wnd ) //4.get buffer wnd->tpl_buf = NULL; wnd->tpl_buf = tpl_surface_get_buffer(wnd->tpl_surf, NULL); - if (wnd->tpl_buf == NULL) - { + if (wnd->tpl_buf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_get_buffer"); ret = false; goto finish; @@ -324,33 +305,31 @@ bool tpl_buffer_create_native_buffer_test(TPLNativeWnd* wnd ) //create native buffer void *native_buffer = NULL; native_buffer = tpl_buffer_create_native_buffer(wnd->tpl_buf); - if (native_buffer == NULL) - { + if (native_buffer == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_buffer_create_native_buffer"); ret = false; goto finish; } finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; } -bool tpl_buffer_abnormal_test(TPLNativeWnd* wnd ) +bool tpl_buffer_abnormal_test(TPLNativeWnd *wnd ) { TPL_CHK_PARAM( !wnd ); bool ret = true; - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); //1.tpl_display_get wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; @@ -358,9 +337,9 @@ bool tpl_buffer_abnormal_test(TPLNativeWnd* wnd ) //2.tpl_surface_create wnd->tpl_surf = NULL; - wnd->tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); - if(wnd->tpl_surf == NULL) - { + wnd->tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, + TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); + if (wnd->tpl_surf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_create"); ret = false; goto finish; @@ -372,8 +351,7 @@ bool tpl_buffer_abnormal_test(TPLNativeWnd* wnd ) //4.get buffer wnd->tpl_buf = NULL; wnd->tpl_buf = tpl_surface_get_buffer(wnd->tpl_surf, NULL); - if (wnd->tpl_buf == NULL) - { + if (wnd->tpl_buf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_get_buffer"); ret = false; goto finish; @@ -381,11 +359,11 @@ bool tpl_buffer_abnormal_test(TPLNativeWnd* wnd ) //abnormal test - tpl_buffer_lock(wnd->tpl_buf,TPL_LOCK_USAGE_INVALID); - int test_width = 0,test_heigh = 0; + tpl_buffer_lock(wnd->tpl_buf, TPL_LOCK_USAGE_INVALID); + int test_width = 0, test_heigh = 0; tpl_buffer_map(NULL, 0); - tpl_buffer_unmap(NULL,NULL,0); - tpl_buffer_lock(NULL,TPL_LOCK_USAGE_INVALID); + tpl_buffer_unmap(NULL, NULL, 0); + tpl_buffer_lock(NULL, TPL_LOCK_USAGE_INVALID); tpl_buffer_unlock(NULL); tpl_buffer_get_key(NULL); tpl_buffer_get_fd(NULL); @@ -397,28 +375,28 @@ bool tpl_buffer_abnormal_test(TPLNativeWnd* wnd ) tpl_buffer_create_native_buffer(NULL); finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; } -bool tpl_buffer_stress_test(TPLNativeWnd* wnd ) +bool tpl_buffer_stress_test(TPLNativeWnd *wnd ) { TPL_CHK_PARAM( !wnd ); bool ret = true; - int index = 0;int size = 0; - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + int index = 0; + int size = 0; + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); //1.tpl_display _get wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; @@ -426,21 +404,19 @@ bool tpl_buffer_stress_test(TPLNativeWnd* wnd ) //2.tpl_surface_create wnd->tpl_surf = NULL; - wnd->tpl_surf = tpl_surface_create(wnd->tpl_display , (tpl_handle_t)wnd->wnd, TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); - if(wnd->tpl_surf == NULL) - { + wnd->tpl_surf = tpl_surface_create(wnd->tpl_display , (tpl_handle_t)wnd->wnd, + TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); + if (wnd->tpl_surf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_create"); ret = false; goto finish; } - tpl_buffer_t *buf_array[STRESS_NUM]={0}; - for(index = 0;indextpl_surf); buf_array[index] = tpl_surface_get_buffer(wnd->tpl_surf, NULL); - if (buf_array[index] == NULL) - { + if (buf_array[index] == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_get_buffer"); ret = false; goto finish; @@ -449,36 +425,35 @@ bool tpl_buffer_stress_test(TPLNativeWnd* wnd ) void *ptr = NULL; size = wnd->width * wnd->height ; ptr = tpl_buffer_map(buf_array[index], size); - if (ptr == NULL) - { + if (ptr == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_buffer_map"); ret = false; goto finish; } //6.write - int *p = NULL;int j=0; - for(j = 0; j tpl_surf); tpl_surface_post(wnd->tpl_surf); - usleep(500*1000);//0.5s + usleep(500 * 1000); //0.5s } finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; - } +} #endif diff --git a/tc/src/tpl_test_display.c b/tc/src/tpl_test_display.c index 9bbdff6..e7ccd88 100644 --- a/tc/src/tpl_test_display.c +++ b/tc/src/tpl_test_display.c @@ -4,37 +4,35 @@ #include "tpl_test_util.h" -bool tpl_display_get_test (TPLNativeWnd* wnd) +bool tpl_display_get_test (TPLNativeWnd *wnd) { TPL_CHK_PARAM( !wnd ); - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); bool ret = true; wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; } - finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); +finish: + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; } -bool tpl_display_bind_client_display_test(TPLNativeWnd* wnd) +bool tpl_display_bind_client_display_test(TPLNativeWnd *wnd) { TPL_CHK_PARAM( !wnd ); - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s---",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s---", __func__); bool ret = true; wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; @@ -42,9 +40,9 @@ bool tpl_display_bind_client_display_test(TPLNativeWnd* wnd) // bind display handle tpl_bool_t result = false; - result = tpl_display_bind_client_display_handle(wnd->tpl_display,(tpl_handle_t)wnd->dpy); - if(result == false) - { + result = tpl_display_bind_client_display_handle(wnd->tpl_display, + (tpl_handle_t)wnd->dpy); + if (result == false) { LOG("ERRO", LOG_LEVEL_HIGH , " failed:tpl_display_bind_client_display_handle"); ret = false; goto finish; @@ -52,41 +50,41 @@ bool tpl_display_bind_client_display_test(TPLNativeWnd* wnd) // unbind display handle result = false; - result = tpl_display_unbind_client_display_handle(wnd->tpl_display,(tpl_handle_t)wnd->dpy); - if(result == false) - { - LOG("ERRO", LOG_LEVEL_HIGH , " failed:tpl_display_unbind_client_display_handle"); + result = tpl_display_unbind_client_display_handle(wnd->tpl_display, + (tpl_handle_t)wnd->dpy); + if (result == false) { + LOG("ERRO", LOG_LEVEL_HIGH , + " failed:tpl_display_unbind_client_display_handle"); ret = false; goto finish; } finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; } -bool tpl_display_get_arg_test (TPLNativeWnd* wnd) +bool tpl_display_get_arg_test (TPLNativeWnd *wnd) { TPL_CHK_PARAM( !wnd ); - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); bool ret = true; wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; } //tpl_display_get_backend_type - tpl_backend_type_t backend_type = tpl_display_get_backend_type(wnd->tpl_display); - if(backend_type != TPL_BACKEND_WAYLAND) - { + tpl_backend_type_t backend_type = tpl_display_get_backend_type( + wnd->tpl_display); + if (backend_type != TPL_BACKEND_WAYLAND) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get_backend_type"); ret = false; goto finish; @@ -95,31 +93,29 @@ bool tpl_display_get_arg_test (TPLNativeWnd* wnd) //tpl_display_get_native_handle tpl_handle_t test_handle = NULL; test_handle = tpl_display_get_native_handle(wnd->tpl_display); - if(test_handle == NULL) - { + if (test_handle == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get_native_handle"); ret = false; goto finish; } finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; } -bool tpl_display_query_config_test (TPLNativeWnd* wnd) +bool tpl_display_query_config_test (TPLNativeWnd *wnd) { TPL_CHK_PARAM( !wnd ); - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); bool ret = true; wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; @@ -127,70 +123,66 @@ bool tpl_display_query_config_test (TPLNativeWnd* wnd) //query config tpl_bool_t result = false; result = tpl_display_query_config(wnd->tpl_display, - TPL_SURFACE_TYPE_WINDOW, - 8, - 8, - 8, - 8, - 32, - NULL, - NULL); - if(result == false ) - { + TPL_SURFACE_TYPE_WINDOW, + 8, + 8, + 8, + 8, + 32, + NULL, + NULL); + if (result == false ) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_query_config"); ret = false; goto finish; } result = tpl_display_query_config(wnd->tpl_display, - TPL_SURFACE_TYPE_WINDOW, - 8, - 8, - 8, - 8, - 24, - NULL, - NULL); - if(result == false ) - { + TPL_SURFACE_TYPE_WINDOW, + 8, + 8, + 8, + 8, + 24, + NULL, + NULL); + if (result == false ) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_query_config"); ret = false; goto finish; } result = tpl_display_query_config(wnd->tpl_display, - TPL_SURFACE_TYPE_WINDOW, - 0, - 8, - 8, - 8, - 24, - NULL, - NULL); - if(result != false )//unmatched case - { + TPL_SURFACE_TYPE_WINDOW, + 0, + 8, + 8, + 8, + 24, + NULL, + NULL); + if (result != false ) { //unmatched case LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_query_config"); ret = false; goto finish; } finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; } -bool tpl_display_filter_config_test (TPLNativeWnd* wnd) +bool tpl_display_filter_config_test (TPLNativeWnd *wnd) { TPL_CHK_PARAM( !wnd ); - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); bool ret = true; wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; @@ -199,26 +191,23 @@ bool tpl_display_filter_config_test (TPLNativeWnd* wnd) //filt config tpl_bool_t result = false; int test_visual_id = GBM_FORMAT_ARGB8888; - result = tpl_display_filter_config(wnd->tpl_display,&test_visual_id,0); - if(result == false ) - { + result = tpl_display_filter_config(wnd->tpl_display, &test_visual_id, 0); + if (result == false ) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_filter_config"); ret = false; goto finish; } //filt config, unmatched case - result = tpl_display_filter_config(wnd->tpl_display,&test_visual_id,8); - if(result != false ) - { + result = tpl_display_filter_config(wnd->tpl_display, &test_visual_id, 8); + if (result != false ) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_filter_config"); ret = false; goto finish; } test_visual_id = GBM_FORMAT_XRGB8888; - result = tpl_display_filter_config(wnd->tpl_display,&test_visual_id,0); - if(result != false ) - { + result = tpl_display_filter_config(wnd->tpl_display, &test_visual_id, 0); + if (result != false ) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_filter_config"); ret = false; goto finish; @@ -226,23 +215,22 @@ bool tpl_display_filter_config_test (TPLNativeWnd* wnd) finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; } -bool tpl_display_abnormal_test (TPLNativeWnd* wnd) +bool tpl_display_abnormal_test (TPLNativeWnd *wnd) { TPL_CHK_PARAM( !wnd ); - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); bool ret = true; wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; @@ -250,8 +238,7 @@ bool tpl_display_abnormal_test (TPLNativeWnd* wnd) //abnormal test wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, NULL); - if(wnd->tpl_display != NULL) - { + if (wnd->tpl_display != NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "abnormal test failed:tpl_display_get"); ret = false; goto finish; @@ -259,19 +246,20 @@ bool tpl_display_abnormal_test (TPLNativeWnd* wnd) //abnormal test - tpl_display_bind_client_display_handle(NULL,NULL); - tpl_display_unbind_client_display_handle(NULL,NULL); + tpl_display_bind_client_display_handle(NULL, NULL); + tpl_display_unbind_client_display_handle(NULL, NULL); tpl_display_get_backend_type(NULL); tpl_display_get_native_handle(NULL); - tpl_display_filter_config(NULL,NULL,0); - tpl_display_query_config(NULL,TPL_SURFACE_TYPE_PIXMAP,0,8,8,8,24,NULL,NULL); + tpl_display_filter_config(NULL, NULL, 0); + tpl_display_query_config(NULL, TPL_SURFACE_TYPE_PIXMAP, 0, 8, 8, 8, 24, NULL, + NULL); finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; } diff --git a/tc/src/tpl_test_object.c b/tc/src/tpl_test_object.c index e4a1776..1f6eb81 100644 --- a/tc/src/tpl_test_object.c +++ b/tc/src/tpl_test_object.c @@ -4,17 +4,16 @@ #include "tpl_test_util.h" -bool tpl_object_get_type_test(TPLNativeWnd* wnd ) +bool tpl_object_get_type_test(TPLNativeWnd *wnd ) { TPL_CHK_PARAM( !wnd ); bool ret = true; - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); //1.tpl_display_get wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; @@ -22,9 +21,9 @@ bool tpl_object_get_type_test(TPLNativeWnd* wnd ) //2.tpl_surface_create wnd->tpl_surf = NULL; - wnd->tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); - if(wnd->tpl_surf == NULL) - { + wnd->tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, + TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); + if (wnd->tpl_surf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_create"); ret = false; goto finish; @@ -36,8 +35,7 @@ bool tpl_object_get_type_test(TPLNativeWnd* wnd ) //4.get buffer wnd->tpl_buf = NULL; wnd->tpl_buf = tpl_surface_get_buffer(wnd->tpl_surf, NULL); - if (wnd->tpl_buf == NULL) - { + if (wnd->tpl_buf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_get_buffer"); ret = false; goto finish; @@ -46,8 +44,7 @@ bool tpl_object_get_type_test(TPLNativeWnd* wnd ) //tpl_object_get_type:DISPLAY int obj_type = -1; obj_type = tpl_object_get_type((tpl_object_t *)wnd->tpl_display); - if (obj_type != TPL_OBJECT_DISPLAY) - { + if (obj_type != TPL_OBJECT_DISPLAY) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_object_get_type"); ret = false; goto finish; @@ -56,48 +53,46 @@ bool tpl_object_get_type_test(TPLNativeWnd* wnd ) //tpl_object_get_type:SURFACE obj_type = -1; obj_type = tpl_object_get_type((tpl_object_t *)wnd->tpl_surf); - if (obj_type != TPL_OBJECT_SURFACE) - { + if (obj_type != TPL_OBJECT_SURFACE) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_object_get_type"); ret = false; goto finish; } finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; } -bool tpl_object_userdata_test(TPLNativeWnd* wnd ) +bool tpl_object_userdata_test(TPLNativeWnd *wnd ) { TPL_CHK_PARAM( !wnd ); bool ret = true; - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); //1.tpl_display_get wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; } //2. set userdate - tpl_object_set_user_data((tpl_object_t *)wnd->tpl_display,(void *)wnd->dpy,NULL); + tpl_object_set_user_data((tpl_object_t *)wnd->tpl_display, (void *)wnd->dpy, + NULL); //3.get userdate - void* get_dpy = NULL; + void *get_dpy = NULL; get_dpy = (void *)tpl_object_get_user_data((tpl_object_t *)wnd->tpl_display); - if(get_dpy == NULL) - { + if (get_dpy == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_object_get_user_data"); ret = false; goto finish; @@ -105,26 +100,25 @@ bool tpl_object_userdata_test(TPLNativeWnd* wnd ) finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; } -bool tpl_object_reference_test(TPLNativeWnd* wnd ) +bool tpl_object_reference_test(TPLNativeWnd *wnd ) { TPL_CHK_PARAM( !wnd ); bool ret = true; - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); //1.tpl_display_get wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; @@ -136,8 +130,7 @@ bool tpl_object_reference_test(TPLNativeWnd* wnd ) //3.tpl_object_get_reference int ref_count = -1; ref_count = tpl_object_get_reference((tpl_object_t *)wnd->tpl_display); - if(ref_count == -1) - { + if (ref_count == -1) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_object_get_reference"); ret = false; goto finish; @@ -146,33 +139,32 @@ bool tpl_object_reference_test(TPLNativeWnd* wnd ) //4.tpl_object_unreference int unref_count = -1; unref_count = tpl_object_unreference((tpl_object_t *)wnd->tpl_display); - if(unref_count != ref_count-1) - { + if (unref_count != ref_count - 1) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_object_unreference"); ret = false; goto finish; } finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; } -bool tpl_object_abnormal_test(TPLNativeWnd* wnd ) +bool tpl_object_abnormal_test(TPLNativeWnd *wnd ) { TPL_CHK_PARAM( !wnd ); bool ret = true; - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); //abnormal test tpl_object_get_type(NULL); - tpl_object_set_user_data(NULL,NULL,NULL); + tpl_object_set_user_data(NULL, NULL, NULL); tpl_object_get_user_data(NULL); tpl_object_reference(NULL); tpl_object_get_reference(NULL); @@ -180,10 +172,10 @@ bool tpl_object_abnormal_test(TPLNativeWnd* wnd ) finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; diff --git a/tc/src/tpl_test_surface.c b/tc/src/tpl_test_surface.c index ac8a30f..bc6fd48 100644 --- a/tc/src/tpl_test_surface.c +++ b/tc/src/tpl_test_surface.c @@ -4,114 +4,108 @@ #include "tpl_test_util.h" -bool tpl_surface_create_test(TPLNativeWnd* wnd) +bool tpl_surface_create_test(TPLNativeWnd *wnd) { TPL_CHK_PARAM( !wnd ); - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); bool ret = true; wnd->tpl_display = NULL; //1.tpl_display_get wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; } //2.tpl_surface_create tpl_surface_t *tpl_surf = NULL; - tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); - if(tpl_surf == NULL) - { + tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, + TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); + if (tpl_surf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_create"); ret = false; goto finish; } finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; } -bool tpl_surface_get_arg_test(TPLNativeWnd* wnd) +bool tpl_surface_get_arg_test(TPLNativeWnd *wnd) { TPL_CHK_PARAM( !wnd ); - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); bool ret = true; wnd->tpl_display = NULL; //1.tpl_display_get wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; } //2.tpl_surface_create tpl_surface_t *tpl_surf = NULL; - tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); - if(tpl_surf == NULL) - { + tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, + TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); + if (tpl_surf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_create"); ret = false; goto finish; } //tpl_surface_get_display test - tpl_display_t* test_dpy = tpl_surface_get_display(tpl_surf); - if(test_dpy == NULL) - { + tpl_display_t *test_dpy = tpl_surface_get_display(tpl_surf); + if (test_dpy == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_get_display"); ret = false; goto finish; } //tpl_surface_get_native_handle tpl_handle_t test_handle = tpl_surface_get_native_handle(tpl_surf); - if(test_handle == NULL) - { + if (test_handle == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_get_native_handle"); ret = false; goto finish; } //tpl_surface_get_type test tpl_surface_type_t test_type = tpl_surface_get_type(tpl_surf); - if(test_type != TPL_SURFACE_TYPE_WINDOW) - { + if (test_type != TPL_SURFACE_TYPE_WINDOW) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_get_type"); ret = false; goto finish; } - finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); +finish: + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; } -bool tpl_surface_frame_test(TPLNativeWnd* wnd) +bool tpl_surface_frame_test(TPLNativeWnd *wnd) { TPL_CHK_PARAM( !wnd ); - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); bool ret = true; wnd->tpl_display = NULL; //1.tpl_display_get wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; } //2.tpl_surface_create tpl_surface_t *tpl_surf = NULL; - tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); - if(tpl_surf == NULL) - { + tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, + TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); + if (tpl_surf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_create"); ret = false; goto finish; @@ -128,26 +122,25 @@ bool tpl_surface_frame_test(TPLNativeWnd* wnd) finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; } -bool tpl_surface_get_buffer_test(TPLNativeWnd* wnd ) +bool tpl_surface_get_buffer_test(TPLNativeWnd *wnd ) { TPL_CHK_PARAM( !wnd ); bool ret = true; - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); //1.tpl_display_get wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; @@ -155,9 +148,9 @@ bool tpl_surface_get_buffer_test(TPLNativeWnd* wnd ) //2.tpl_surface_create tpl_surface_t *tpl_surf = NULL; - tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); - if(tpl_surf == NULL) - { + tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, + TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); + if (tpl_surf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_create"); ret = false; goto finish; @@ -169,8 +162,7 @@ bool tpl_surface_get_buffer_test(TPLNativeWnd* wnd ) //4.get buffer wnd->tpl_buf = NULL; wnd->tpl_buf = tpl_surface_get_buffer(tpl_surf, NULL); - if (wnd->tpl_buf == NULL) - { + if (wnd->tpl_buf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_get_buffer"); ret = false; goto finish; @@ -180,18 +172,17 @@ bool tpl_surface_get_buffer_test(TPLNativeWnd* wnd ) tpl_buffer_t *tpl_buf_r = NULL; tpl_bool_t reset; tpl_buf_r = tpl_surface_get_buffer(tpl_surf, &reset); - if (tpl_buf_r == NULL) - { + if (tpl_buf_r == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_get_buffer"); ret = false; goto finish; } finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; @@ -200,17 +191,16 @@ finish: -bool tpl_surface_post_test(TPLNativeWnd* wnd ) +bool tpl_surface_post_test(TPLNativeWnd *wnd ) { TPL_CHK_PARAM( !wnd ); bool ret = true; - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); //1.tpl_display_get wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; @@ -218,9 +208,9 @@ bool tpl_surface_post_test(TPLNativeWnd* wnd ) //2.tpl_surface_create tpl_surface_t *tpl_surf = NULL; - tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); - if(tpl_surf == NULL) - { + tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, + TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); + if (tpl_surf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_create"); ret = false; goto finish; @@ -232,8 +222,7 @@ bool tpl_surface_post_test(TPLNativeWnd* wnd ) //4.get buffer wnd->tpl_buf = NULL; wnd->tpl_buf = tpl_surface_get_buffer(tpl_surf, NULL); - if (wnd->tpl_buf == NULL) - { + if (wnd->tpl_buf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_get_buffer"); ret = false; goto finish; @@ -243,21 +232,21 @@ bool tpl_surface_post_test(TPLNativeWnd* wnd ) void *ptr = NULL; //int size = tpl_buf->width * tpl_buf->height * tpl_buf->depth; int size = wnd->width * wnd->height ; - LOG("INFO", LOG_LEVEL_LOW ,"width=%d,height=%d,size=%d",wnd->width , wnd->height , size); + LOG("INFO", LOG_LEVEL_LOW , "width=%d,height=%d,size=%d", wnd->width , + wnd->height , size); ptr = tpl_buffer_map(wnd->tpl_buf, size); - if (ptr == NULL) - { + if (ptr == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_buffer_map"); ret = false; goto finish; } //6.write - int *p = NULL;int j=0; - for(j = 0; j tpl_surf = NULL; //1.tpl_display_get wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; @@ -322,23 +308,26 @@ bool tpl_surface_abnormal_test(TPLNativeWnd* wnd) //abnormal test wnd->tpl_surf = NULL; - wnd->tpl_surf = tpl_surface_create(NULL, NULL, TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); - wnd->tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, 10, TPL_FORMAT_ARGB8888); - wnd->tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_INVALID); - /* if(tpl_surf != NULL) + wnd->tpl_surf = tpl_surface_create(NULL, NULL, TPL_SURFACE_TYPE_WINDOW, + TPL_FORMAT_ARGB8888); + wnd->tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, 10, + TPL_FORMAT_ARGB8888); + wnd->tpl_surf = tpl_surface_create(wnd->tpl_display, (tpl_handle_t)wnd->wnd, + TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_INVALID); + /* if(tpl_surf != NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "abnormal test failed:%s",__func__); ret = false; goto finish; } - */ + */ //abnormal test int width = 0, height = 0; tpl_surface_get_display(NULL); tpl_surface_get_native_handle(NULL); tpl_surface_get_type(NULL); - tpl_surface_get_size(NULL,&width,&height); - tpl_surface_get_buffer(NULL,NULL); + tpl_surface_get_size(NULL, &width, &height); + tpl_surface_get_buffer(NULL, NULL); tpl_surface_set_post_interval(NULL, 2); tpl_surface_get_post_interval(NULL); tpl_surface_post(NULL); @@ -346,28 +335,27 @@ bool tpl_surface_abnormal_test(TPLNativeWnd* wnd) tpl_surface_validate_frame(NULL); tpl_surface_end_frame(NULL); - finish: - if(true == ret) - LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s",__func__); +finish: + if (true == ret) + LOG("PASS", LOG_LEVEL_HIGH , "Pass:%s", __func__); else - LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s",__func__); + LOG("FAIL", LOG_LEVEL_HIGH , "Failed:%s", __func__); return ret; } -bool tpl_surface_stress_test(TPLNativeWnd* wnd ) +bool tpl_surface_stress_test(TPLNativeWnd *wnd ) { TPL_CHK_PARAM( !wnd ); bool ret = true; int index = 0; - LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------",__func__); + LOG("INFO", LOG_LEVEL_LOW , "-------begin:%s-------", __func__); //1.tpl_display _get wnd->tpl_display = NULL; wnd->tpl_display = tpl_display_get(TPL_BACKEND_WAYLAND, (tpl_handle_t)wnd->dpy); - if(wnd->tpl_display == NULL) - { + if (wnd->tpl_display == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_display_get"); ret = false; goto finish; @@ -375,9 +363,9 @@ bool tpl_surface_stress_test(TPLNativeWnd* wnd ) //2.tpl_surface_create wnd->tpl_surf = NULL; - wnd->tpl_surf = tpl_surface_create(wnd->tpl_display , (tpl_handle_t)wnd->wnd, TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); - if(wnd->tpl_surf == NULL) - { + wnd->tpl_surf = tpl_surface_create(wnd->tpl_display , (tpl_handle_t)wnd->wnd, + TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); + if (wnd->tpl_surf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_create"); ret = false; goto finish; @@ -389,28 +377,25 @@ bool tpl_surface_stress_test(TPLNativeWnd* wnd ) //4.get buffer wnd->tpl_buf = NULL; wnd->tpl_buf = tpl_surface_get_buffer(wnd->tpl_surf, NULL); - if (wnd->tpl_buf == NULL) - { + if (wnd->tpl_buf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_get_buffer"); ret = false; goto finish; } - tpl_buffer_t *surf_array[STRESS_NUM]={0}; - tpl_buffer_t *buf_array[STRESS_NUM]={0}; - for(index = 0;indextpl_display , (tpl_handle_t)wnd->wnd, TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); - if(wnd->tpl_surf == NULL) - { + tpl_buffer_t *surf_array[STRESS_NUM] = {0}; + tpl_buffer_t *buf_array[STRESS_NUM] = {0}; + for (index = 0; index < STRESS_NUM; index++) { + surf_array[index] = tpl_surface_create(wnd->tpl_display , + (tpl_handle_t)wnd->wnd, TPL_SURFACE_TYPE_WINDOW, TPL_FORMAT_ARGB8888); + if (wnd->tpl_surf == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_create"); ret = false; goto finish; } buf_array[index] = tpl_surface_get_buffer(wnd->tpl_surf, NULL); - if (buf_array[index] == NULL) - { + if (buf_array[index] == NULL) { LOG("ERRO", LOG_LEVEL_HIGH , "failed:tpl_surface_get_buffer"); ret = false; goto finish; @@ -419,19 +404,17 @@ bool tpl_surface_stress_test(TPLNativeWnd* wnd ) finish: - for(index = 0;index