From bc34ae76ded35c3be06e409002ad6b631aac2da1 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Tue, 26 Jan 2016 17:08:51 +0900 Subject: [PATCH 01/16] Delete tpl_frame_t and change some APIs - Deleted codes(APIs) and file related to tpl_frame_t. - Add argument tbm_surface_h to API tpl_surface_post. Change-Id: Ib5e034aaafe2dc059ed98efe708759c24bfb1815 --- Makefile | 1 - src/tpl.h | 44 +---------- src/tpl_frame.c | 40 ---------- src/tpl_gbm.c | 43 +++-------- src/tpl_internal.h | 37 +-------- src/tpl_surface.c | 218 ++--------------------------------------------------- src/tpl_tbm.c | 33 +------- src/tpl_wayland.c | 125 +++++++++++------------------- 8 files changed, 70 insertions(+), 471 deletions(-) delete mode 100644 src/tpl_frame.c diff --git a/Makefile b/Makefile index f450666..4529297 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,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_frame.c TPL_SRCS += $(SRC_DIR)/tpl_object.c TPL_SRCS += $(SRC_DIR)/tpl_region.c TPL_SRCS += $(SRC_DIR)/tpl_surface.c diff --git a/src/tpl.h b/src/tpl.h index 96aabf8..07047a1 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -491,46 +491,6 @@ tpl_bool_t tpl_surface_get_size(tpl_surface_t *surface, int *width, int *height); -/** - * Begin a new frame of the given TPL surface. - * - * TPL forces users to process frames in begin/end manner. Information for a - * frame such as current buffer can be queried after the frame has begun via - * tpl_surface_begin_frame(). When a frame ends by calling - * tpl_surface_end_frame(), the frame is queued. Such queued frames are - * consumed one by one in FIFO order when tpl_surface_post() is called. - * - * If previous frame was not ended, this function will implicitly end previous - * one. - * - * This function has no effect if the surface type is not window. - * - * @param surface surface to begin a frame. - * - * @see tpl_surface_end_frame() - * @see tpl_surface_validate_frame() - * @see tpl_surface_post() - * @see tpl_surface_get_buffer() - */ -tpl_bool_t tpl_surface_begin_frame(tpl_surface_t *surface); - -/** - * End the current frame of the given TPL surface. - * - * The current frame will be queued in the "frame queue". Frame interval and - * damage region for the frame is copied from surface's current states. - * - * This function has no effect if the surface type is not window. - * - * @param surface surface to end a frame. - * - * @see tpl_surface_begin_frame() - * @see tpl_surface_validate_frame() - * @see tpl_surface_post() - * @see tpl_surface_set_post_interval() - * @see tpl_surface_set_damage() - */ -tpl_bool_t tpl_surface_end_frame(tpl_surface_t *surface); /** * Validate current frame of the given TPL surface. @@ -549,7 +509,7 @@ tpl_bool_t tpl_surface_end_frame(tpl_surface_t *surface); * @see tpl_surface_end_frame() * @see tpl_surface_get_buffer() */ -tpl_bool_t tpl_surface_validate_frame(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. @@ -592,7 +552,7 @@ tbm_surface_h tpl_surface_get_buffer(tpl_surface_t *surface, * @see tpl_surface_begin_frame() * @see tpl_surface_end_frame() */ -tpl_bool_t tpl_surface_post(tpl_surface_t *surface); +tpl_bool_t tpl_surface_post(tpl_surface_t *surface, tbm_surface_h tbm_surface); /** * Set frame interval of the given TPL surface. diff --git a/src/tpl_frame.c b/src/tpl_frame.c deleted file mode 100644 index a2b1dbf..0000000 --- a/src/tpl_frame.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "tpl_internal.h" - -tpl_frame_t * -__tpl_frame_alloc() -{ - tpl_frame_t *frame; - - frame = (tpl_frame_t *)calloc(1, sizeof(tpl_frame_t)); - - __tpl_region_init(&frame->damage); - - return frame; -} - -void -__tpl_frame_free(tpl_frame_t *frame) -{ - TPL_ASSERT(frame); - - TPL_LOG(9, "frame(%p)| tbm_surface(%p)", frame, frame->tbm_surface); - if (frame->tbm_surface) - tbm_surface_internal_unref(frame->tbm_surface); - - __tpl_region_fini(&frame->damage); - free(frame); -} - -void -__tpl_frame_set_buffer(tpl_frame_t *frame, tbm_surface_h tbm_surface) -{ - TPL_ASSERT(frame); - TPL_ASSERT(tbm_surface); - - TPL_LOG(9, "frame(%p)| tbm_surface(%p)", frame, tbm_surface); - if (frame->tbm_surface) - tbm_surface_internal_unref(frame->tbm_surface); - - tbm_surface_internal_ref(tbm_surface); - frame->tbm_surface = tbm_surface; -} diff --git a/src/tpl_gbm.c b/src/tpl_gbm.c index d3db3b9..ef500ee 100644 --- a/src/tpl_gbm.c +++ b/src/tpl_gbm.c @@ -41,6 +41,7 @@ struct _tpl_gbm_display struct _tpl_gbm_surface { tbm_surface_queue_h tbm_queue; + tbm_surface_h current_buffer; }; struct _tpl_gbm_buffer @@ -281,6 +282,7 @@ __tpl_gbm_surface_init(tpl_surface_t *surface) surface->backend.data = (void *)tpl_gbm_surface; tpl_gbm_surface->tbm_queue = NULL; + tpl_gbm_surface->current_buffer = NULL; if (surface->type == TPL_SURFACE_TYPE_WINDOW) { @@ -323,23 +325,24 @@ __tpl_gbm_surface_fini(tpl_surface_t *surface) TPL_LOG(3, "window(%p, %p)", surface, surface->native_handle); + if (gbm_surface->current_buffer) + tbm_surface_internal_unref(gbm_surface->current_buffer); + free(gbm_surface); surface->backend.data = NULL; } static void -__tpl_gbm_surface_post(tpl_surface_t *surface, tpl_frame_t *frame) +__tpl_gbm_surface_post(tpl_surface_t *surface, tbm_surface_h tbm_surface) { TPL_ASSERT(surface); TPL_ASSERT(surface->display); TPL_ASSERT(surface->display->native_handle); - TPL_ASSERT(frame); - TPL_ASSERT(frame->tbm_surface); + TPL_ASSERT(tbm_surface); TPL_LOG(3, "window(%p, %p)", surface, surface->native_handle); tpl_gbm_surface_t *gbm_surface = (tpl_gbm_surface_t*)surface->backend.data; - tbm_surface_h tbm_surface = frame->tbm_surface; tbm_surface_internal_unref(tbm_surface); @@ -351,37 +354,13 @@ __tpl_gbm_surface_post(tpl_surface_t *surface, tpl_frame_t *frame) } static tpl_bool_t -__tpl_gbm_surface_begin_frame(tpl_surface_t *surface) -{ - tpl_gbm_surface_t *gbm_surface; - - TPL_ASSERT(surface); - TPL_ASSERT(surface->display); - - gbm_surface = (tpl_gbm_surface_t *) surface->backend.data; - - TPL_LOG(3, "window(%p, %p)", surface, surface->native_handle); - - return TPL_TRUE; -} - -static tpl_bool_t -__tpl_gbm_surface_validate_frame(tpl_surface_t *surface) +__tpl_gbm_surface_validate(tpl_surface_t *surface) { TPL_IGNORE(surface); return TPL_TRUE; } -static tpl_bool_t -__tpl_gbm_surface_end_frame(tpl_surface_t *surface) -{ - TPL_ASSERT(surface); - TPL_ASSERT(surface->display); - - return TPL_TRUE; -} - static int __tpl_gbm_get_depth_from_format(tpl_format_t format) { @@ -478,6 +457,8 @@ __tpl_gbm_surface_create_buffer_from_gbm_surface(tpl_surface_t *surface, tpl_boo gbm_buffer->display = surface->display; gbm_buffer->bo = bo; + gbm_surface->current_buffer = tbm_surface; + if (reset_buffers != NULL) *reset_buffers = TPL_FALSE; @@ -584,9 +565,7 @@ __tpl_surface_init_backend_gbm(tpl_surface_backend_t *backend) backend->init = __tpl_gbm_surface_init; backend->fini = __tpl_gbm_surface_fini; - backend->begin_frame = __tpl_gbm_surface_begin_frame; - backend->end_frame = __tpl_gbm_surface_end_frame; - backend->validate_frame = __tpl_gbm_surface_validate_frame; + backend->validate = __tpl_gbm_surface_validate; backend->get_buffer = __tpl_gbm_surface_get_buffer; backend->post = __tpl_gbm_surface_post; } diff --git a/src/tpl_internal.h b/src/tpl_internal.h index 171350a..fcc4d91 100644 --- a/src/tpl_internal.h +++ b/src/tpl_internal.h @@ -21,29 +21,9 @@ 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_frame tpl_frame_t; typedef struct tpl_hlist tpl_hlist_t; - -typedef enum -{ - TPL_FRAME_ERROR = -1, - TPL_FRAME_STATE_INVALID, - TPL_FRAME_STATE_READY, - TPL_FRAME_STATE_QUEUED, - TPL_FRAME_STATE_POSTED, - TPL_FRAME_MAX -} tpl_frame_state_t; - -struct _tpl_frame -{ - tbm_surface_h tbm_surface; - int interval; - tpl_region_t damage; - tpl_frame_state_t state; -}; - struct _tpl_display_backend { tpl_backend_type_t type; @@ -79,12 +59,10 @@ struct _tpl_surface_backend tpl_bool_t (*init)(tpl_surface_t *surface); void (*fini)(tpl_surface_t *surface); - tpl_bool_t (*begin_frame)(tpl_surface_t *surface); - tpl_bool_t (*end_frame)(tpl_surface_t *surface); - tpl_bool_t (*validate_frame)(tpl_surface_t *surface); + 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, tpl_frame_t *frame); + 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); }; @@ -125,10 +103,8 @@ struct _tpl_surface tpl_format_t format; int width, height; - tpl_frame_t *frame; int post_interval; tpl_region_t damage; - tpl_list_t frame_queue; int dump_count; tpl_surface_backend_t backend; @@ -170,19 +146,10 @@ tpl_bool_t __tpl_object_lock(tpl_object_t *object); */ void __tpl_object_unlock(tpl_object_t *object); -/* Frame functions. */ -tpl_frame_t * __tpl_frame_alloc(); -void __tpl_frame_free(tpl_frame_t *frame); -void __tpl_frame_set_buffer(tpl_frame_t *frame, tbm_surface_h tbm_surface); - /* Display functions. */ tpl_handle_t __tpl_display_get_native_handle(tpl_display_t *display); void __tpl_display_flush(tpl_display_t *display); -/* Surface functions. */ -tpl_frame_t * __tpl_surface_get_latest_frame(tpl_surface_t *surface); -void __tpl_surface_wait_all_frames(tpl_surface_t *surface); - void __tpl_surface_set_backend_data(tpl_surface_t *surface, void *data); void * __tpl_surface_get_backend_data(tpl_surface_t *surface); diff --git a/src/tpl_surface.c b/src/tpl_surface.c index fbee278..6a2460c 100644 --- a/src/tpl_surface.c +++ b/src/tpl_surface.c @@ -6,10 +6,6 @@ __tpl_surface_fini(tpl_surface_t *surface) TPL_ASSERT(surface); __tpl_region_fini(&surface->damage); - __tpl_list_fini(&surface->frame_queue, (tpl_free_func_t) __tpl_frame_free); - - if (surface->frame) - __tpl_frame_free(surface->frame); surface->backend.fini(surface); } @@ -23,56 +19,6 @@ __tpl_surface_free(void *data) free(data); } -static tpl_bool_t -__tpl_surface_enqueue_frame(tpl_surface_t *surface) -{ - TPL_ASSERT(surface); - TPL_ASSERT(surface->frame); - - /* Set swap attributes. */ - surface->frame->interval = surface->post_interval; - if (TPL_TRUE != __tpl_region_copy(&surface->frame->damage, &surface->damage)) - return TPL_FALSE; - - /* Enqueue the frame object.*/ - if (TPL_TRUE != __tpl_list_push_back(&surface->frame_queue, surface->frame)) - return TPL_FALSE; - - surface->frame->state = TPL_FRAME_STATE_QUEUED; - - /* Reset surface frame to NULL. */ - if (surface->backend.end_frame) - surface->backend.end_frame(surface); - - surface->frame = NULL; - - return TPL_TRUE; -} - -tpl_frame_t * -__tpl_surface_get_latest_frame(tpl_surface_t *surface) -{ - TPL_ASSERT(surface); - - if (__tpl_list_is_empty(&surface->frame_queue)) - return NULL; - - return (tpl_frame_t *) __tpl_list_get_back(&surface->frame_queue); -} - -void -__tpl_surface_wait_all_frames(tpl_surface_t *surface) -{ - TPL_ASSERT(surface); - - while (!__tpl_list_is_empty(&surface->frame_queue)) - { - TPL_OBJECT_UNLOCK(surface); - __tpl_util_sys_yield(); - TPL_OBJECT_LOCK(surface); - } -} - tpl_surface_t * tpl_surface_create(tpl_display_t *display, tpl_handle_t handle, tpl_surface_type_t type, tpl_format_t format) { @@ -112,12 +58,10 @@ tpl_surface_create(tpl_display_t *display, tpl_handle_t handle, tpl_surface_type surface->type = type; surface->format = format; - surface->frame = NULL; surface->post_interval = 1; surface->dump_count = 0; __tpl_region_init(&surface->damage); - __tpl_list_init(&surface->frame_queue); /* Intialize backend. */ __tpl_surface_init_backend(surface, display->backend.type); @@ -186,104 +130,9 @@ tpl_surface_get_size(tpl_surface_t *surface, int *width, int *height) return TPL_TRUE; } -tpl_bool_t -tpl_surface_begin_frame(tpl_surface_t *surface) -{ - if (NULL == surface) - { - TPL_ERR("Surface is NULL!"); - return TPL_FALSE; - } - - if (TPL_SURFACE_TYPE_WINDOW != surface->type) - { - TPL_ERR("Surface is not of type window!"); - return TPL_FALSE; - } - - TRACE_BEGIN("TPL:BEGINFRAME"); - TPL_OBJECT_LOCK(surface); - - /* Queue previous frame if it has not been queued. */ - if (surface->frame) - { - if (TPL_TRUE != __tpl_surface_enqueue_frame(surface)) - { - TPL_OBJECT_UNLOCK(surface); - TRACE_END(); - TPL_ERR("Failed to enqueue frame!"); - return TPL_FALSE; - } - } - - /* Allocate a new frame. */ - surface->frame = __tpl_frame_alloc(); - if (NULL == surface->frame) - { - TPL_OBJECT_UNLOCK(surface); - TRACE_END(); - TPL_ERR("Failed to allocate frame!"); - return TPL_FALSE; - } - - surface->frame->state = TPL_FRAME_STATE_READY; - - TPL_LOG(9, "surface(%p)| surface->frame(%p)", surface, surface->frame); - TPL_LOG(5, "surface->frame:%p, surface->damage:%p, surface->frame->damage:%p", - surface->frame, &surface->damage, (surface->frame)?(&surface->frame->damage):NULL); - /* There might be some frames which is enqueued but not posted. Some backend requires native - * surface to be posted to be able to get the next output buffer (i.e. x11_dri2). Runtime - * just request buffer for the frame and it is totally upto backend if it calls post - * internally or not. - * - * In case of backend calling internal post, backend must mark the frame as posted. - * tpl_surface_post() will skip calling backend post if the frame is marked as posted and - * it will be just removed from the queue. */ - - /* Let backend handle the new frame event. */ - if (surface->backend.begin_frame) - surface->backend.begin_frame(surface); - - TPL_OBJECT_UNLOCK(surface); - TRACE_END(); - - return TPL_TRUE; -} tpl_bool_t -tpl_surface_end_frame(tpl_surface_t *surface) -{ - if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type) - { - TPL_ERR("Invalid surface!"); - return TPL_FALSE; - } - - TPL_LOG(5, "surface->frame:%p, surface->damage:%p, surface->frame->damage:%p", - surface->frame, &surface->damage, (surface->frame)?(&surface->frame->damage):NULL); - TPL_LOG(9, "surface(%p)| surface->frame(%p)", surface, surface->frame); - TRACE_BEGIN("TPL:ENDFRAME"); - TPL_OBJECT_LOCK(surface); - - if (surface->frame) - { - if (TPL_TRUE != __tpl_surface_enqueue_frame(surface)) - { - TPL_OBJECT_UNLOCK(surface); - TRACE_END(); - TPL_ERR("Failed to enqueue frame!"); - return TPL_FALSE; - } - } - - TPL_OBJECT_UNLOCK(surface); - TRACE_END(); - - return TPL_TRUE; -} - -tpl_bool_t -tpl_surface_validate_frame(tpl_surface_t *surface) +tpl_surface_validate(tpl_surface_t *surface) { tpl_bool_t was_valid = TPL_TRUE; @@ -293,13 +142,7 @@ tpl_surface_validate_frame(tpl_surface_t *surface) return TPL_FALSE; } - if (NULL == surface->frame) - { - TPL_ERR("Frame not registered in surface!"); - return TPL_FALSE; - } - - if (NULL == surface->backend.validate_frame) + if (NULL == surface->backend.validate) { TPL_ERR("Backend for surface has not been initialized!"); return TPL_FALSE; @@ -308,13 +151,9 @@ tpl_surface_validate_frame(tpl_surface_t *surface) TRACE_BEGIN("TPL:VALIDATEFRAME"); TPL_OBJECT_LOCK(surface); - if (!surface->backend.validate_frame(surface)) + if (!surface->backend.validate(surface)) was_valid = TPL_FALSE; - TPL_LOG(5, "surface->frame:%p, surface->damage:%p, %s", - surface->frame, &surface->damage, - was_valid?"VALID_FRAME":"INVALID_FRAME"); - TPL_OBJECT_UNLOCK(surface); TRACE_END(); @@ -415,9 +254,6 @@ tpl_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buffers) /* Update size of the surface. */ surface->width = tbm_surface_internal_get_width(tbm_surface); surface->height = tbm_surface_internal_get_height(tbm_surface); - - if (surface->frame) - __tpl_frame_set_buffer(surface->frame, tbm_surface); } TPL_OBJECT_UNLOCK(surface); @@ -475,9 +311,8 @@ tpl_surface_update_cached_buffers(tpl_surface_t *surface) } tpl_bool_t -tpl_surface_post(tpl_surface_t *surface) +tpl_surface_post(tpl_surface_t *surface, tbm_surface_h tbm_surface) { - tpl_frame_t *frame; if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type) { @@ -485,59 +320,20 @@ tpl_surface_post(tpl_surface_t *surface) return TPL_FALSE; } - TPL_LOG(5, "surface->frame:%p, surface->damage:%p, surface->frame->damage:%p", - surface->frame, &surface->damage, (surface->frame)?(&surface->frame->damage):NULL); - TRACE_BEGIN("TPL:POST"); TPL_OBJECT_LOCK(surface); - if (__tpl_list_is_empty(&surface->frame_queue)) - { - /* Queue is empty and swap is called. - * This means that current frame is not enqueued yet - * and there's no pending frames. - * So, this post is for the current frame. */ - if (NULL == surface->frame) - { - TPL_OBJECT_UNLOCK(surface); - TRACE_END(); - TPL_ERR("Frame not registered in surface!"); - return TPL_FALSE; - } - - if (TPL_TRUE != __tpl_surface_enqueue_frame(surface)) - { - TPL_OBJECT_UNLOCK(surface); - TRACE_END(); - TPL_ERR("Failed to enqueue frame!"); - return TPL_FALSE; - } - } - - /* Dequeue a frame from the queue. */ - frame = (tpl_frame_t *) __tpl_list_pop_front(&surface->frame_queue, NULL); - - if (NULL == frame) + if (NULL == tbm_surface) { TPL_OBJECT_UNLOCK(surface); TRACE_END(); - TPL_ERR("Frame to post received from the queue is invalid!"); + TPL_ERR("tbm surface is invalid."); return TPL_FALSE; } - if (frame->tbm_surface == NULL) - { - __tpl_frame_free(frame); - TPL_OBJECT_UNLOCK(surface); - TRACE_END(); - TPL_ERR("Buffer not initialized for frame!"); - return TPL_FALSE; - } /* Call backend post if it has not been called for the frame. */ - if (TPL_FRAME_STATE_POSTED != frame->state) - surface->backend.post(surface, frame); + surface->backend.post(surface, tbm_surface); - __tpl_frame_free(frame); TPL_OBJECT_UNLOCK(surface); TRACE_END(); diff --git a/src/tpl_tbm.c b/src/tpl_tbm.c index 71a4f56..24a15d0 100644 --- a/src/tpl_tbm.c +++ b/src/tpl_tbm.c @@ -247,15 +247,12 @@ __tpl_tbm_surface_fini(tpl_surface_t *surface) } static void -__tpl_tbm_surface_post(tpl_surface_t *surface, tpl_frame_t *frame) +__tpl_tbm_surface_post(tpl_surface_t *surface, tbm_surface_h tbm_surface) { TPL_ASSERT(surface); TPL_ASSERT(surface->display); TPL_ASSERT(surface->display->native_handle); - TPL_ASSERT(frame); - TPL_ASSERT(frame->tbm_surface); - - tbm_surface_h tbm_surface = frame->tbm_surface; + TPL_ASSERT(tbm_surface); tbm_surface_internal_unref(tbm_surface); @@ -277,33 +274,13 @@ __tpl_tbm_surface_post(tpl_surface_t *surface, tpl_frame_t *frame) } static tpl_bool_t -__tpl_tbm_surface_begin_frame(tpl_surface_t *surface) -{ - TPL_ASSERT(surface); - TPL_ASSERT(surface->display); - - TPL_LOG(3, "window(%p, %p)", surface, surface->native_handle); - - return TPL_TRUE; -} - -static tpl_bool_t -__tpl_tbm_surface_validate_frame(tpl_surface_t *surface) +__tpl_tbm_surface_validate(tpl_surface_t *surface) { TPL_IGNORE(surface); return TPL_TRUE; } -static tpl_bool_t -__tpl_tbm_surface_end_frame(tpl_surface_t *surface) -{ - TPL_ASSERT(surface); - TPL_ASSERT(surface->display); - - return TPL_TRUE; -} - static tbm_surface_h __tpl_tbm_surface_get_buffer_from_tbm_queue(tpl_surface_t *surface, tpl_bool_t *reset_buffers) { @@ -407,9 +384,7 @@ __tpl_surface_init_backend_tbm(tpl_surface_backend_t *backend) backend->init = __tpl_tbm_surface_init; backend->fini = __tpl_tbm_surface_fini; - backend->begin_frame = __tpl_tbm_surface_begin_frame; - backend->end_frame = __tpl_tbm_surface_end_frame; - backend->validate_frame = __tpl_tbm_surface_validate_frame; + backend->validate = __tpl_tbm_surface_validate; backend->get_buffer = __tpl_tbm_surface_get_buffer; backend->post = __tpl_tbm_surface_post; } diff --git a/src/tpl_wayland.c b/src/tpl_wayland.c index 56e0968..15cd708 100644 --- a/src/tpl_wayland.c +++ b/src/tpl_wayland.c @@ -207,8 +207,8 @@ __tpl_wayland_display_fini(tpl_display_t *display) static tpl_bool_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) + 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); @@ -392,6 +392,10 @@ __tpl_wayland_surface_fini(tpl_surface_t *surface) 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); + tbm_surface_queue_destroy(wayland_surface->tbm_queue); wayland_surface->tbm_queue = NULL; } @@ -401,25 +405,21 @@ __tpl_wayland_surface_fini(tpl_surface_t *surface) } static void -__tpl_wayland_surface_post(tpl_surface_t *surface, tpl_frame_t *frame) +__tpl_wayland_surface_post(tpl_surface_t *surface, tbm_surface_h tbm_surface) { TPL_ASSERT(surface); TPL_ASSERT(surface->display); TPL_ASSERT(surface->display->native_handle); - TPL_ASSERT(frame); - TPL_ASSERT(frame->tbm_surface); + 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_buffer_t *wayland_buffer = NULL; - tbm_surface_h tbm_surface = NULL; tbm_surface_queue_error_e tsqe; - int i; TPL_LOG(3, "window(%p, %p)", surface, surface->native_handle); - tbm_surface = frame->tbm_surface; wayland_buffer = __tpl_wayland_get_wayland_buffer_from_tbm_surface(tbm_surface); TPL_ASSERT(wayland_buffer); @@ -445,18 +445,22 @@ __tpl_wayland_surface_post(tpl_surface_t *surface, tpl_frame_t *frame) wl_egl_window->attached_width = wl_egl_window->width; wl_egl_window->attached_height = wl_egl_window->height; - for (i = 0; i < frame->damage.num_rects; i++) + + if (surface->damage.num_rects == 0) { wl_surface_damage(wl_egl_window->surface, - frame->damage.rects[i * 4 + 0], - frame->damage.rects[i * 4 + 1], - frame->damage.rects[i * 4 + 2], - frame->damage.rects[i * 4 + 3]); - } - if (frame->damage.num_rects == 0) { - 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++) + { + 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]); + } } { @@ -473,20 +477,7 @@ __tpl_wayland_surface_post(tpl_surface_t *surface, tpl_frame_t *frame) } static tpl_bool_t -__tpl_wayland_surface_begin_frame(tpl_surface_t *surface) -{ - TPL_ASSERT(surface); - TPL_ASSERT(surface->display); - - TPL_OBJECT_UNLOCK(surface); - __tpl_wayland_display_roundtrip(surface->display); - TPL_OBJECT_LOCK(surface); - - return TPL_TRUE; -} - -static tpl_bool_t -__tpl_wayland_surface_validate_frame(tpl_surface_t *surface) +__tpl_wayland_surface_validate(tpl_surface_t *surface) { TPL_ASSERT(surface); TPL_ASSERT(surface->backend.data); @@ -499,33 +490,6 @@ __tpl_wayland_surface_validate_frame(tpl_surface_t *surface) return TPL_TRUE; } -static tpl_bool_t -__tpl_wayland_surface_end_frame(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; - if (wayland_surface->current_buffer != NULL) - wayland_surface->current_buffer = NULL; - - return TPL_TRUE; -} - -static tpl_bool_t -__tpl_wayland_surface_destroy_cached_buffers(tpl_surface_t *surface) -{ - TPL_ASSERT(surface); - TPL_ASSERT(surface->backend.data); - - TPL_LOG(9, "surface(%p)| surface->frame(%p)", surface, surface->frame); - - tpl_wayland_surface_t *wayland_surface = (tpl_wayland_surface_t*)surface->backend.data; - if (wayland_surface->current_buffer) - tbm_surface_internal_unref(wayland_surface->current_buffer); - - return TPL_TRUE; -} static int __tpl_wayland_get_depth_from_format(tpl_format_t format) { @@ -574,7 +538,6 @@ __tpl_wayland_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buffe TPL_ASSERT(surface->backend.data); TPL_ASSERT(surface->display); - int width, height, format; 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; @@ -585,24 +548,7 @@ __tpl_wayland_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buffe if (reset_buffers != NULL) *reset_buffers = TPL_FALSE; - 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)) - { - TPL_LOG(9, "RESIZE!!|tpl_surface_t(%p)| wl_egl_window(%p)| wayland_surface(%p)", - surface, wl_egl_window, wayland_surface); - tbm_surface_queue_reset(wayland_surface->tbm_queue, width, height, format); - - if (reset_buffers != NULL) - *reset_buffers = TPL_TRUE; - - wayland_surface->resized = TPL_FALSE; - } + 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) @@ -728,13 +674,9 @@ __tpl_surface_init_backend_wayland(tpl_surface_backend_t *backend) backend->init = __tpl_wayland_surface_init; backend->fini = __tpl_wayland_surface_fini; - backend->begin_frame = __tpl_wayland_surface_begin_frame; - backend->end_frame = __tpl_wayland_surface_end_frame; - backend->validate_frame = __tpl_wayland_surface_validate_frame; + backend->validate = __tpl_wayland_surface_validate; backend->get_buffer = __tpl_wayland_surface_get_buffer; backend->post = __tpl_wayland_surface_post; - backend->destroy_cached_buffers = __tpl_wayland_surface_destroy_cached_buffers; - backend->update_cached_buffers = NULL; } static void @@ -804,10 +746,31 @@ static void __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; + 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); + + /* 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)) + { + 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 3fa5feeb8a1f1ebce6cf57667081f276face1dc7 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Thu, 11 Feb 2016 09:39:33 +0900 Subject: [PATCH 02/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 03/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 04/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 05/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 06/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 07/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 08/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 09/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 10/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 11/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 12/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 13/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 14/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 15/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 16/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