clean up type casting lines for readability 49/302049/1
authorJoonbum Ko <joonbum.ko@samsung.com>
Thu, 30 Nov 2023 04:53:26 +0000 (13:53 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Thu, 30 Nov 2023 04:53:26 +0000 (13:53 +0900)
Change-Id: Ic7910b7e474cc796db67a4cf8c509dab0d8f641d
Signed-off-by: Joonbum Ko <joonbum.ko@samsung.com>
src/tpl_wl_egl_thread.c

index d4b8902..785e7bd 100755 (executable)
@@ -44,6 +44,11 @@ typedef struct _tpl_wl_egl_surface tpl_wl_egl_surface_t;
 typedef struct _tpl_wl_egl_buffer  tpl_wl_egl_buffer_t;
 typedef struct _surface_vblank     tpl_surface_vblank_t;
 
+#define wl_egl_display(ptr) *wl_egl_display = (tpl_wl_egl_display_t *)ptr;
+#define wl_egl_surface(ptr) *wl_egl_surface = (tpl_wl_egl_surface_t *)ptr;
+#define wl_egl_buffer(ptr) *wl_egl_buffer = (tpl_wl_egl_buffer_t *)ptr;
+#define tizen_private(ptr) *tizen_private = (struct tizen_private *)ptr;
+
 struct _tpl_wl_egl_display {
        tpl_gsource                  *disp_source;
        tpl_gthread                  *thread;
@@ -287,8 +292,7 @@ __cb_surface_vblank_free(void *data);
 static struct tizen_private *
 tizen_private_create()
 {
-       struct tizen_private *private = NULL;
-       private = (struct tizen_private *)calloc(1, sizeof(struct tizen_private));
+       struct tizen_private *private = calloc(1, sizeof(struct tizen_private));
        if (private) {
                private->magic = WL_EGL_TIZEN_MAGIC;
                private->rotation = 0;
@@ -336,12 +340,11 @@ _check_native_handle_is_wl_display(tpl_handle_t display)
 static tpl_bool_t
 __thread_func_tdm_dispatch(tpl_gsource *gsource, uint64_t message)
 {
-       tpl_wl_egl_display_t       *wl_egl_display = NULL;
+       tpl_wl_egl_display_t wl_egl_display(tpl_gsource_get_data(gsource));
        tdm_error                   tdm_err = TDM_ERROR_NONE;
 
        TPL_IGNORE(message);
 
-       wl_egl_display = (tpl_wl_egl_display_t *)tpl_gsource_get_data(gsource);
        if (!wl_egl_display) {
                TPL_ERR("Failed to get wl_egl_display from gsource(%p)", gsource);
                TPL_WARN("tdm_source(%p) will be removed from thread.", gsource);
@@ -373,9 +376,7 @@ __thread_func_tdm_dispatch(tpl_gsource *gsource, uint64_t message)
 static void
 __thread_func_tdm_finalize(tpl_gsource *gsource)
 {
-       tpl_wl_egl_display_t *wl_egl_display = NULL;
-
-       wl_egl_display = (tpl_wl_egl_display_t *)tpl_gsource_get_data(gsource);
+       tpl_wl_egl_display_t wl_egl_display(tpl_gsource_get_data(gsource));
 
        tpl_gmutex_lock(&wl_egl_display->tdm.tdm_mutex);
 
@@ -455,7 +456,7 @@ __cb_wl_resistry_global_callback(void *data, struct wl_registry *wl_registry,
                                                          uint32_t version)
 {
 #if TIZEN_FEATURE_ENABLE
-       tpl_wl_egl_display_t *wl_egl_display = (tpl_wl_egl_display_t *)data;
+       tpl_wl_egl_display_t wl_egl_display(data);
 
        if (!strcmp(interface, "tizen_surface_shm")) {
                wl_egl_display->tss =
@@ -718,7 +719,7 @@ _thread_wl_display_fini(tpl_wl_egl_display_t *wl_egl_display)
 static void*
 _thread_init(void *data)
 {
-       tpl_wl_egl_display_t *wl_egl_display = (tpl_wl_egl_display_t *)data;
+       tpl_wl_egl_display_t wl_egl_display(data);
 
        if (_thread_wl_display_init(wl_egl_display) != TPL_ERROR_NONE) {
                TPL_ERR("Failed to initialize wl_egl_display(%p) with wl_display(%p)",
@@ -736,8 +737,7 @@ _thread_init(void *data)
 static tpl_bool_t
 __thread_func_disp_prepare(tpl_gsource *gsource)
 {
-       tpl_wl_egl_display_t *wl_egl_display =
-               (tpl_wl_egl_display_t *)tpl_gsource_get_data(gsource);
+       tpl_wl_egl_display_t wl_egl_display(tpl_gsource_get_data(gsource));
 
        /* If this wl_egl_display is already prepared,
         * do nothing in this function. */
@@ -768,8 +768,7 @@ __thread_func_disp_prepare(tpl_gsource *gsource)
 static tpl_bool_t
 __thread_func_disp_check(tpl_gsource *gsource)
 {
-       tpl_wl_egl_display_t *wl_egl_display =
-               (tpl_wl_egl_display_t *)tpl_gsource_get_data(gsource);
+       tpl_wl_egl_display_t wl_egl_display(tpl_gsource_get_data(gsource));
        tpl_bool_t ret = TPL_FALSE;
 
        if (!wl_egl_display->prepared)
@@ -802,8 +801,7 @@ __thread_func_disp_check(tpl_gsource *gsource)
 static tpl_bool_t
 __thread_func_disp_dispatch(tpl_gsource *gsource, uint64_t message)
 {
-       tpl_wl_egl_display_t *wl_egl_display =
-               (tpl_wl_egl_display_t *)tpl_gsource_get_data(gsource);
+       tpl_wl_egl_display_t wl_egl_display(tpl_gsource_get_data(gsource));
 
        TPL_IGNORE(message);
 
@@ -831,8 +829,7 @@ __thread_func_disp_dispatch(tpl_gsource *gsource, uint64_t message)
 static void
 __thread_func_disp_finalize(tpl_gsource *gsource)
 {
-       tpl_wl_egl_display_t *wl_egl_display =
-               (tpl_wl_egl_display_t *)tpl_gsource_get_data(gsource);
+       tpl_wl_egl_display_t wl_egl_display(tpl_gsource_get_data(gsource));
 
        tpl_gmutex_lock(&wl_egl_display->disp_mutex);
        TPL_LOG_D("[D_FINALIZE]", "wl_egl_display(%p) tpl_gsource(%p)",
@@ -875,8 +872,7 @@ __tpl_wl_egl_display_init(tpl_display_t *display)
                return TPL_ERROR_INVALID_PARAMETER;
        }
 
-       wl_egl_display = (tpl_wl_egl_display_t *) calloc(1,
-                                                 sizeof(tpl_wl_egl_display_t));
+       wl_egl_display = calloc(1, sizeof(tpl_wl_egl_display_t));
        if (!wl_egl_display) {
                TPL_ERR("Failed to allocate memory for new tpl_wl_egl_display_t.");
                return TPL_ERROR_OUT_OF_MEMORY;
@@ -1015,11 +1011,7 @@ free_display:
 static void
 __tpl_wl_egl_display_fini(tpl_display_t *display)
 {
-       tpl_wl_egl_display_t *wl_egl_display;
-
-       TPL_ASSERT(display);
-
-       wl_egl_display = (tpl_wl_egl_display_t *)display->backend.data;
+       tpl_wl_egl_display_t wl_egl_display(display->backend.data);
        if (wl_egl_display) {
                TPL_INFO("[DISPLAY_FINI]",
                                  "wl_egl_display(%p) tpl_gthread(%p) wl_display(%p)",
@@ -1125,9 +1117,6 @@ __tpl_wl_egl_display_get_window_info(tpl_display_t *display,
        tpl_result_t ret = TPL_ERROR_NONE;
        struct wl_egl_window *wl_egl_window = (struct wl_egl_window *)window;
 
-       TPL_ASSERT(display);
-       TPL_ASSERT(window);
-
        if (!wl_egl_window) {
                TPL_ERR("Invalid parameter. tpl_handle_t(%p)", window);
                return TPL_ERROR_INVALID_PARAMETER;
@@ -1136,11 +1125,9 @@ __tpl_wl_egl_display_get_window_info(tpl_display_t *display,
        if (width) *width = wl_egl_window->width;
        if (height) *height = wl_egl_window->height;
        if (format) {
-               struct tizen_private *tizen_private =
-                               (struct tizen_private *)wl_egl_window->driver_private;
+               struct tizen_private tizen_private(wl_egl_window->driver_private);
                if (tizen_private && tizen_private->data) {
-                       tpl_wl_egl_surface_t *wl_egl_surface =
-                               (tpl_wl_egl_surface_t *)tizen_private->data;
+                       tpl_wl_egl_surface_t wl_egl_surface(tizen_private->data);
                        *format = wl_egl_surface->format;
                } else {
                        if (a_size == 8)
@@ -1220,15 +1207,14 @@ __tpl_display_choose_backend_wl_egl_thread(tpl_handle_t native_dpy)
 static void
 __cb_destroy_callback(void *private)
 {
-       struct tizen_private *tizen_private  = (struct tizen_private *)private;
-       tpl_wl_egl_surface_t *wl_egl_surface = NULL;
+       struct tizen_private tizen_private(private);
 
        if (!tizen_private) {
                TPL_LOG_D("[WL_EGL_WINDOW_DESTROY_CALLBACK]", "Already destroyed surface");
                return;
        }
 
-       wl_egl_surface = (tpl_wl_egl_surface_t *)tizen_private->data;
+       tpl_wl_egl_surface_t wl_egl_surface(tizen_private->data);
        if (wl_egl_surface) {
                TPL_WARN("[DESTROY_CB][!!!ABNORMAL BEHAVIOR!!!] wl_egl_window(%p) is destroyed.",
                                 wl_egl_surface->wl_egl_window);
@@ -1259,10 +1245,9 @@ static void
 __cb_resize_callback(struct wl_egl_window *wl_egl_window, void *private)
 {
        TPL_ASSERT(private);
-       TPL_ASSERT(wl_egl_window);
 
-       struct tizen_private *tizen_private  = (struct tizen_private *)private;
-       tpl_wl_egl_surface_t *wl_egl_surface = (tpl_wl_egl_surface_t *)tizen_private->data;
+       struct tizen_private tizen_private(private);
+       tpl_wl_egl_surface_t wl_egl_surface(tizen_private->data);
        int cur_w, cur_h, req_w, req_h, format;
 
        if (!wl_egl_surface) {
@@ -1296,10 +1281,9 @@ static void
 __cb_rotate_callback(struct wl_egl_window *wl_egl_window, void *private)
 {
        TPL_ASSERT(private);
-       TPL_ASSERT(wl_egl_window);
 
-       struct tizen_private *tizen_private  = (struct tizen_private *)private;
-       tpl_wl_egl_surface_t *wl_egl_surface = (tpl_wl_egl_surface_t *)tizen_private->data;
+       struct tizen_private tizen_private(private);
+       tpl_wl_egl_surface_t wl_egl_surface(tizen_private->data);
        int rotation = tizen_private->rotation;
 
        if (!wl_egl_surface) {
@@ -1322,11 +1306,10 @@ __cb_get_rotation_capability(struct wl_egl_window *wl_egl_window,
                                                         void *private)
 {
        TPL_ASSERT(private);
-       TPL_ASSERT(wl_egl_window);
 
        int rotation_capability              = WL_EGL_WINDOW_TIZEN_CAPABILITY_NONE;
-       struct tizen_private *tizen_private  = (struct tizen_private *)private;
-       tpl_wl_egl_surface_t *wl_egl_surface = (tpl_wl_egl_surface_t *)tizen_private->data;
+       struct tizen_private tizen_private(private);
+       tpl_wl_egl_surface_t wl_egl_surface(tizen_private->data);
 
        if (!wl_egl_surface) {
                TPL_ERR("Invalid wl_egl_window(%p) tizen_private->data is null.",
@@ -1348,10 +1331,9 @@ __cb_set_window_serial_callback(struct wl_egl_window *wl_egl_window,
                                                                void *private, unsigned int serial)
 {
        TPL_ASSERT(private);
-       TPL_ASSERT(wl_egl_window);
 
-       struct tizen_private *tizen_private  = (struct tizen_private *)private;
-       tpl_wl_egl_surface_t *wl_egl_surface = (tpl_wl_egl_surface_t *)tizen_private->data;
+       struct tizen_private tizen_private(private);
+       tpl_wl_egl_surface_t wl_egl_surface(tizen_private->data);
 
        if (!wl_egl_surface) {
                TPL_ERR("Invalid wl_egl_window(%p) tizen_private->data is null.",
@@ -1371,8 +1353,8 @@ __cb_create_commit_sync_fd(struct wl_egl_window *wl_egl_window, void *private)
 
        int commit_sync_fd = -1;
 
-       struct tizen_private *tizen_private  = (struct tizen_private *)private;
-       tpl_wl_egl_surface_t *wl_egl_surface = (tpl_wl_egl_surface_t *)tizen_private->data;
+       struct tizen_private tizen_private(private);
+       tpl_wl_egl_surface_t wl_egl_surface(tizen_private->data);
 
        if (!wl_egl_surface) {
                TPL_ERR("Invalid parameter. wl_egl_surface(%p) is NULL", wl_egl_surface);
@@ -1417,8 +1399,8 @@ __cb_client_window_set_frontbuffer_mode(struct wl_egl_window *wl_egl_window,
 {
        TPL_ASSERT(private);
        TPL_ASSERT(wl_egl_window);
-       struct tizen_private *tizen_private = (struct tizen_private *)private;
-       tpl_wl_egl_surface_t *wl_egl_surface = (tpl_wl_egl_surface_t *)tizen_private->data;
+       struct tizen_private tizen_private(private);
+       tpl_wl_egl_surface_t wl_egl_surface(tizen_private->data);
        TPL_CHECK_ON_NULL_RETURN(wl_egl_surface);
 
        tpl_surface_t *surface = wl_egl_surface->tpl_surface;
@@ -1451,8 +1433,8 @@ __cb_create_presentation_sync_fd(struct wl_egl_window *wl_egl_window, void *priv
 
        int presentation_sync_fd = -1;
 
-       struct tizen_private *tizen_private  = (struct tizen_private *)private;
-       tpl_wl_egl_surface_t *wl_egl_surface = (tpl_wl_egl_surface_t *)tizen_private->data;
+       struct tizen_private tizen_private(private);
+       tpl_wl_egl_surface_t wl_egl_surface(tizen_private->data);
 
        if (!wl_egl_surface) {
                TPL_ERR("Invalid parameter. wl_egl_surface is NULL");
@@ -1494,7 +1476,7 @@ __cb_create_presentation_sync_fd(struct wl_egl_window *wl_egl_window, void *priv
 static void __cb_tss_flusher_flush_callback(void *data,
                struct tizen_surface_shm_flusher *tss_flusher)
 {
-       tpl_wl_egl_surface_t *wl_egl_surface = (tpl_wl_egl_surface_t *)data;
+       tpl_wl_egl_surface_t wl_egl_surface(data);
        tbm_surface_queue_error_e tsq_err = TBM_SURFACE_QUEUE_ERROR_NONE;
 
        TPL_INFO("[BUFFER_FLUSH]", "wl_egl_surface(%p) tbm_queue(%p)",
@@ -1510,7 +1492,7 @@ static void __cb_tss_flusher_flush_callback(void *data,
 static void __cb_tss_flusher_free_flush_callback(void *data,
                struct tizen_surface_shm_flusher *tss_flusher)
 {
-       tpl_wl_egl_surface_t *wl_egl_surface = (tpl_wl_egl_surface_t *)data;
+       tpl_wl_egl_surface_t wl_egl_surface(data);
        tbm_surface_queue_error_e tsq_err    = TBM_SURFACE_QUEUE_ERROR_NONE;
 
        TPL_INFO("[FREE_BUFFER_FLUSH]", "wl_egl_surface(%p) tbm_queue(%p)",
@@ -1536,13 +1518,12 @@ static void
 __cb_tbm_queue_reset_callback(tbm_surface_queue_h tbm_queue,
                                                                          void *data)
 {
-       tpl_wl_egl_surface_t *wl_egl_surface = NULL;
        tpl_wl_egl_display_t *wl_egl_display = NULL;
        tpl_surface_t *surface = NULL;
        tpl_bool_t is_activated = TPL_FALSE;
        int width, height;
 
-       wl_egl_surface = (tpl_wl_egl_surface_t *)data;
+       tpl_wl_egl_surface_t wl_egl_surface(data);
        TPL_CHECK_ON_NULL_RETURN(wl_egl_surface);
 
        wl_egl_display = wl_egl_surface->wl_egl_display;
@@ -1591,7 +1572,7 @@ __cb_tbm_queue_acquirable_callback(tbm_surface_queue_h tbm_queue,
 {
        TPL_IGNORE(tbm_queue);
 
-       tpl_wl_egl_surface_t *wl_egl_surface = (tpl_wl_egl_surface_t *)data;
+       tpl_wl_egl_surface_t wl_egl_surface(data);
        TPL_CHECK_ON_NULL_RETURN(wl_egl_surface);
 
        tpl_gmutex_lock(&wl_egl_surface->surf_mutex);
@@ -1685,9 +1666,7 @@ _thread_wl_egl_surface_fini(tpl_wl_egl_surface_t *wl_egl_surface)
 static tpl_bool_t
 __thread_func_surf_dispatch(tpl_gsource *gsource, uint64_t message)
 {
-       tpl_wl_egl_surface_t *wl_egl_surface = NULL;
-
-       wl_egl_surface = (tpl_wl_egl_surface_t *)tpl_gsource_get_data(gsource);
+       tpl_wl_egl_surface_t wl_egl_surface(tpl_gsource_get_data(gsource));
 
        tpl_gmutex_lock(&wl_egl_surface->surf_mutex);
        if (message == INIT_SURFACE) { /* Initialize surface */
@@ -1712,9 +1691,7 @@ __thread_func_surf_dispatch(tpl_gsource *gsource, uint64_t message)
 static void
 __thread_func_surf_finalize(tpl_gsource *gsource)
 {
-       tpl_wl_egl_surface_t *wl_egl_surface = NULL;
-
-       wl_egl_surface = (tpl_wl_egl_surface_t *)tpl_gsource_get_data(gsource);
+       tpl_wl_egl_surface_t wl_egl_surface(tpl_gsource_get_data(gsource));
        TPL_CHECK_ON_NULL_RETURN(wl_egl_surface);
 
        tpl_gmutex_lock(&wl_egl_surface->surf_mutex);
@@ -1739,28 +1716,18 @@ static tpl_gsource_functions surf_funcs = {
 static tpl_result_t
 __tpl_wl_egl_surface_init(tpl_surface_t *surface)
 {
-       tpl_wl_egl_display_t *wl_egl_display    = NULL;
+       tpl_wl_egl_display_t wl_egl_display(surface->display->backend.data);
        tpl_wl_egl_surface_t *wl_egl_surface    = NULL;
        tpl_gsource *surf_source                = NULL;
 
        struct wl_egl_window *wl_egl_window =
                (struct wl_egl_window *)surface->native_handle;
 
-       TPL_ASSERT(surface);
-       TPL_ASSERT(surface->display);
        TPL_ASSERT(surface->type == TPL_SURFACE_TYPE_WINDOW);
        TPL_ASSERT(surface->native_handle);
+       TPL_CHECK_ON_NULL_RETURN_VAL(wl_egl_display, TPL_ERROR_INVALID_PARAMETER);
 
-       wl_egl_display =
-               (tpl_wl_egl_display_t *)surface->display->backend.data;
-       if (!wl_egl_display) {
-               TPL_ERR("Invalid parameter. wl_egl_display(%p)",
-                               wl_egl_display);
-               return TPL_ERROR_INVALID_PARAMETER;
-       }
-
-       wl_egl_surface = (tpl_wl_egl_surface_t *) calloc(1,
-                                                 sizeof(tpl_wl_egl_surface_t));
+       wl_egl_surface = calloc(1, sizeof(tpl_wl_egl_surface_t));
        if (!wl_egl_surface) {
                TPL_ERR("Failed to allocate memory for new tpl_wl_egl_surface_t.");
                return TPL_ERROR_OUT_OF_MEMORY;
@@ -2116,7 +2083,6 @@ _tpl_wl_egl_surface_buffer_clear(tpl_wl_egl_surface_t *wl_egl_surface)
 {
        tbm_surface_queue_error_e tsq_err       = TBM_SURFACE_QUEUE_ERROR_NONE;
        tpl_wl_egl_display_t *wl_egl_display    = wl_egl_surface->wl_egl_display;
-       tpl_wl_egl_buffer_t *wl_egl_buffer      = NULL;
        tpl_bool_t need_to_release              = TPL_FALSE;
        tpl_bool_t need_to_cancel               = TPL_FALSE;
        buffer_status_t status                  = RELEASED;
@@ -2128,8 +2094,8 @@ _tpl_wl_egl_surface_buffer_clear(tpl_wl_egl_surface_t *wl_egl_surface)
        buffer_cnt = __tpl_list_get_count(wl_egl_surface->buffers);
 
        while (!__tpl_list_is_empty(wl_egl_surface->buffers)) {
-               wl_egl_buffer = (tpl_wl_egl_buffer_t *)__tpl_list_pop_front(wl_egl_surface->buffers,
-                                                                                                                                       NULL);
+               tpl_wl_egl_buffer_t wl_egl_buffer(__tpl_list_pop_front(wl_egl_surface->buffers,
+                                                                                                                          NULL));
 
                tpl_gmutex_lock(&wl_egl_buffer->mutex);
 
@@ -2198,7 +2164,6 @@ _tpl_wl_egl_surface_buffer_clear(tpl_wl_egl_surface_t *wl_egl_surface)
 static void
 __tpl_wl_egl_surface_fini(tpl_surface_t *surface)
 {
-       tpl_wl_egl_surface_t *wl_egl_surface = NULL;
        tpl_wl_egl_display_t *wl_egl_display = NULL;
 
        TPL_ASSERT(surface);
@@ -2206,7 +2171,7 @@ __tpl_wl_egl_surface_fini(tpl_surface_t *surface)
 
        TPL_CHECK_ON_FALSE_RETURN(surface->type == TPL_SURFACE_TYPE_WINDOW);
 
-       wl_egl_surface = (tpl_wl_egl_surface_t *) surface->backend.data;
+       tpl_wl_egl_surface_t wl_egl_surface(surface->backend.data);
        TPL_CHECK_ON_NULL_RETURN(wl_egl_surface);
 
        wl_egl_display = wl_egl_surface->wl_egl_display;
@@ -2236,13 +2201,13 @@ __tpl_wl_egl_surface_fini(tpl_surface_t *surface)
        }
 
        if (wl_egl_surface->wl_egl_window) {
-               struct tizen_private *tizen_private = NULL;
                struct wl_egl_window *wl_egl_window = wl_egl_surface->wl_egl_window;
+               struct tizen_private tizen_private(wl_egl_window->driver_private);
                TPL_INFO("[WL_EGL_WINDOW_FINI]",
                                 "wl_egl_surface(%p) wl_egl_window(%p) wl_surface(%p)",
                                 wl_egl_surface, wl_egl_window,
                                 wl_egl_surface->wl_surface);
-               tizen_private = (struct tizen_private *)wl_egl_window->driver_private;
+
                if (tizen_private) {
                        tizen_private->set_window_serial_callback = NULL;
                        tizen_private->rotate_callback = NULL;
@@ -2298,11 +2263,9 @@ static tpl_result_t
 __tpl_wl_egl_surface_set_rotation_capability(tpl_surface_t *surface,
                                                                                         tpl_bool_t set)
 {
-       tpl_wl_egl_surface_t *wl_egl_surface = NULL;
-
        TPL_CHECK_ON_NULL_RETURN_VAL(surface, TPL_ERROR_INVALID_PARAMETER);
 
-       wl_egl_surface = (tpl_wl_egl_surface_t *)surface->backend.data;
+       tpl_wl_egl_surface_t wl_egl_surface(surface->backend.data);
 
        TPL_CHECK_ON_NULL_RETURN_VAL(wl_egl_surface, TPL_ERROR_INVALID_PARAMETER);
 
@@ -2318,11 +2281,9 @@ static tpl_result_t
 __tpl_wl_egl_surface_set_post_interval(tpl_surface_t *surface,
                                                                           int post_interval)
 {
-       tpl_wl_egl_surface_t *wl_egl_surface = NULL;
-
        TPL_CHECK_ON_NULL_RETURN_VAL(surface, TPL_ERROR_INVALID_PARAMETER);
 
-       wl_egl_surface = (tpl_wl_egl_surface_t *)surface->backend.data;
+       tpl_wl_egl_surface_t wl_egl_surface(surface->backend.data);
 
        TPL_CHECK_ON_NULL_RETURN_VAL(wl_egl_surface, TPL_ERROR_INVALID_PARAMETER);
 
@@ -2343,8 +2304,7 @@ __tpl_wl_egl_surface_validate(tpl_surface_t *surface)
        TPL_ASSERT(surface);
        TPL_ASSERT(surface->backend.data);
 
-       tpl_wl_egl_surface_t *wl_egl_surface =
-               (tpl_wl_egl_surface_t *)surface->backend.data;
+       tpl_wl_egl_surface_t wl_egl_surface(surface->backend.data);
 
        retval = !(wl_egl_surface->reset);
 
@@ -2354,8 +2314,7 @@ __tpl_wl_egl_surface_validate(tpl_surface_t *surface)
 static void
 __tpl_wl_egl_surface_get_size(tpl_surface_t *surface, int *width, int *height)
 {
-       tpl_wl_egl_surface_t *wl_egl_surface =
-               (tpl_wl_egl_surface_t *)surface->backend.data;
+       tpl_wl_egl_surface_t wl_egl_surface(surface->backend.data);
 
        if (width)
                *width = tbm_surface_queue_get_width(wl_egl_surface->tbm_queue);
@@ -2366,8 +2325,7 @@ __tpl_wl_egl_surface_get_size(tpl_surface_t *surface, int *width, int *height)
 static tpl_bool_t
 __tpl_wl_egl_surface_fence_sync_is_available(tpl_surface_t *surface)
 {
-       tpl_wl_egl_surface_t *wl_egl_surface =
-               (tpl_wl_egl_surface_t *)surface->backend.data;
+       tpl_wl_egl_surface_t wl_egl_surface(surface->backend.data);
 
        return !wl_egl_surface->frontbuffer_activated;
 }
@@ -2399,9 +2357,8 @@ _tbm_queue_force_flush(tpl_wl_egl_surface_t *wl_egl_surface)
 
        while (!__tpl_list_is_empty(wl_egl_surface->buffers)) {
                tpl_bool_t need_to_release = TPL_FALSE;
-               tpl_wl_egl_buffer_t *wl_egl_buffer =
-                       (tpl_wl_egl_buffer_t *)__tpl_list_pop_front(wl_egl_surface->buffers,
-                                                                                                               NULL);
+               tpl_wl_egl_buffer_t wl_egl_buffer(
+                       __tpl_list_pop_front(wl_egl_surface->buffers, NULL));
                need_to_release = (wl_egl_buffer->status >= ACQUIRED) &&
                                                        (wl_egl_buffer->status <= COMMITTED);
 
@@ -2429,8 +2386,7 @@ _wl_egl_buffer_init(tpl_wl_egl_buffer_t *wl_egl_buffer,
                                        tpl_wl_egl_surface_t *wl_egl_surface)
 {
        struct wl_egl_window *wl_egl_window = wl_egl_surface->wl_egl_window;
-       struct tizen_private *tizen_private =
-               (struct tizen_private *)wl_egl_window->driver_private;
+       struct tizen_private tizen_private(wl_egl_window->driver_private);
 
        TPL_ASSERT(tizen_private);
 
@@ -2478,7 +2434,7 @@ _wl_egl_buffer_create(tpl_wl_egl_surface_t *wl_egl_surface,
        wl_egl_buffer = _get_wl_egl_buffer(tbm_surface);
 
        if (!wl_egl_buffer) {
-               wl_egl_buffer = (tpl_wl_egl_buffer_t *)calloc(1, sizeof(tpl_wl_egl_buffer_t));
+               wl_egl_buffer = calloc(1, sizeof(tpl_wl_egl_buffer_t));
                TPL_CHECK_ON_NULL_RETURN_VAL(wl_egl_buffer, NULL);
 
                tbm_surface_internal_add_user_data(tbm_surface, KEY_WL_EGL_BUFFER,
@@ -2527,16 +2483,12 @@ static tbm_surface_h
 __tpl_wl_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeout_ns,
                                                                        int32_t *release_fence)
 {
-       TPL_ASSERT(surface);
        TPL_ASSERT(surface->backend.data);
        TPL_ASSERT(surface->display);
        TPL_ASSERT(surface->display->backend.data);
-       TPL_OBJECT_CHECK_RETURN(surface, NULL);
 
-       tpl_wl_egl_surface_t *wl_egl_surface =
-               (tpl_wl_egl_surface_t *)surface->backend.data;
-       tpl_wl_egl_display_t *wl_egl_display =
-               (tpl_wl_egl_display_t *)surface->display->backend.data;
+       tpl_wl_egl_surface_t wl_egl_surface(surface->backend.data);
+       tpl_wl_egl_display_t wl_egl_display(surface->display->backend.data);
        tpl_wl_egl_buffer_t *wl_egl_buffer   = NULL;
 
        tbm_surface_queue_error_e tsq_err    = TBM_SURFACE_QUEUE_ERROR_NONE;
@@ -2735,8 +2687,7 @@ __tpl_wl_egl_surface_cancel_buffer(tpl_surface_t *surface,
        TPL_ASSERT(surface);
        TPL_ASSERT(surface->backend.data);
 
-       tpl_wl_egl_surface_t *wl_egl_surface    =
-               (tpl_wl_egl_surface_t *)surface->backend.data;
+       tpl_wl_egl_surface_t wl_egl_surface(surface->backend.data);
        tpl_wl_egl_buffer_t *wl_egl_buffer      = NULL;
        tbm_surface_queue_error_e tsq_err       = TBM_SURFACE_QUEUE_ERROR_NONE;
 
@@ -2779,8 +2730,7 @@ __tpl_wl_egl_surface_enqueue_buffer(tpl_surface_t *surface,
        TPL_ASSERT(tbm_surface);
        TPL_OBJECT_CHECK_RETURN(surface, TPL_ERROR_INVALID_PARAMETER);
 
-       tpl_wl_egl_surface_t *wl_egl_surface    =
-               (tpl_wl_egl_surface_t *) surface->backend.data;
+       tpl_wl_egl_surface_t wl_egl_surface(surface->backend.data);
        tpl_wl_egl_buffer_t *wl_egl_buffer      = NULL;
        tbm_surface_queue_error_e tsq_err       = TBM_SURFACE_QUEUE_ERROR_NONE;
        int bo_name                             = -1;
@@ -2903,8 +2853,7 @@ __tpl_wl_egl_surface_enqueue_buffer(tpl_surface_t *surface,
 static tpl_bool_t
 __thread_func_waiting_source_dispatch(tpl_gsource *gsource, uint64_t message)
 {
-       tpl_wl_egl_buffer_t *wl_egl_buffer      =
-               (tpl_wl_egl_buffer_t *)tpl_gsource_get_data(gsource);
+       tpl_wl_egl_buffer_t wl_egl_buffer(tpl_gsource_get_data(gsource));
        TPL_CHECK_ON_NULL_RETURN_VAL(wl_egl_buffer, TPL_FALSE);
 
        tpl_wl_egl_surface_t *wl_egl_surface    = wl_egl_buffer->wl_egl_surface;
@@ -3050,8 +2999,7 @@ __cb_tdm_client_vblank(tdm_client_vblank *vblank, tdm_error error,
                                           unsigned int sequence, unsigned int tv_sec,
                                           unsigned int tv_usec, void *user_data)
 {
-       tpl_wl_egl_surface_t *wl_egl_surface = (tpl_wl_egl_surface_t *)user_data;
-       tpl_wl_egl_buffer_t *wl_egl_buffer   = NULL;
+       tpl_wl_egl_surface_t wl_egl_surface(user_data);
 
        TRACE_ASYNC_END((intptr_t)wl_egl_surface, "WAIT_VBLANK");
        TPL_LOG_D("[VBLANK_DONE]", "wl_egl_surface(%p)", wl_egl_surface);
@@ -3067,9 +3015,8 @@ __cb_tdm_client_vblank(tdm_client_vblank *vblank, tdm_error error,
                tpl_bool_t is_empty = TPL_TRUE;
                do {
                        tpl_gmutex_lock(&wl_egl_surface->vblank->mutex);
-                       wl_egl_buffer = (tpl_wl_egl_buffer_t *)__tpl_list_pop_front(
-                                                               wl_egl_surface->vblank->waiting_buffers,
-                                                               NULL);
+                       tpl_wl_egl_buffer_t wl_egl_buffer(
+                               __tpl_list_pop_front( wl_egl_surface->vblank->waiting_buffers, NULL));
                        is_empty = __tpl_list_is_empty(wl_egl_surface->vblank->waiting_buffers);
                        tpl_gmutex_unlock(&wl_egl_surface->vblank->mutex);
 
@@ -3093,7 +3040,7 @@ static void
 __cb_buffer_fenced_release(void *data,
                                struct zwp_linux_buffer_release_v1 *release, int32_t fence)
 {
-       tpl_wl_egl_buffer_t *wl_egl_buffer  = (tpl_wl_egl_buffer_t *)data;
+       tpl_wl_egl_buffer_t wl_egl_buffer(data);
        tbm_surface_h tbm_surface           = NULL;
 
        TPL_CHECK_ON_NULL_RETURN(wl_egl_buffer);
@@ -3145,7 +3092,7 @@ static void
 __cb_buffer_immediate_release(void *data,
                                                          struct zwp_linux_buffer_release_v1 *release)
 {
-       tpl_wl_egl_buffer_t *wl_egl_buffer  = (tpl_wl_egl_buffer_t *)data;
+       tpl_wl_egl_buffer_t wl_egl_buffer(data);
        tbm_surface_h tbm_surface           = NULL;
 
        TPL_CHECK_ON_NULL_RETURN(wl_egl_buffer);
@@ -3200,7 +3147,7 @@ static const struct zwp_linux_buffer_release_v1_listener zwp_release_listner = {
 static void
 __cb_wl_buffer_release(void *data, struct wl_proxy *wl_buffer)
 {
-       tpl_wl_egl_buffer_t *wl_egl_buffer = (tpl_wl_egl_buffer_t *)data;
+       tpl_wl_egl_buffer_t wl_egl_buffer(data);
        tbm_surface_h tbm_surface = NULL;
 
        TPL_CHECK_ON_NULL_RETURN(wl_egl_buffer)
@@ -3729,7 +3676,6 @@ static void
 _print_buffer_lists(tpl_wl_egl_surface_t *wl_egl_surface)
 {
        tpl_list_node_t *node = NULL;
-       tpl_wl_egl_buffer_t *wl_egl_buffer = NULL;
        int buffer_cnt = 0;
        int idx = 0;
 
@@ -3739,7 +3685,7 @@ _print_buffer_lists(tpl_wl_egl_surface_t *wl_egl_surface)
        node = __tpl_list_get_front_node(wl_egl_surface->buffers);
        do {
                if (!node) break;
-               wl_egl_buffer = (tpl_wl_egl_buffer_t *)__tpl_list_node_get_data(node);
+               tpl_wl_egl_buffer_t wl_egl_buffer(__tpl_list_node_get_data(node));
                TPL_INFO("[BUFFERS_INFO]",
                                 "[%d/%d] wl_egl_surface(%p), wl_egl_buffer(%p) tbm_surface(%p) bo(%d) | status(%s)",
                                 ++idx, buffer_cnt, wl_egl_surface, wl_egl_buffer,
@@ -3753,7 +3699,6 @@ static tpl_bool_t
 _check_buffer_validate(tpl_wl_egl_surface_t *wl_egl_surface, tbm_surface_h tbm_surface)
 {
        tpl_list_node_t *node = NULL;
-       tpl_wl_egl_buffer_t *wl_egl_buffer = NULL;
        tpl_bool_t ret = TPL_FALSE;
 
        /* silent return */
@@ -3764,7 +3709,7 @@ _check_buffer_validate(tpl_wl_egl_surface_t *wl_egl_surface, tbm_surface_h tbm_s
        node = __tpl_list_get_front_node(wl_egl_surface->buffers);
        do {
                if (!node) break;
-               wl_egl_buffer = (tpl_wl_egl_buffer_t *)__tpl_list_node_get_data(node);
+               tpl_wl_egl_buffer_t wl_egl_buffer(__tpl_list_node_get_data(node));
                if (wl_egl_buffer->tbm_surface == tbm_surface) {
                        ret = TPL_TRUE;
                        break;