screenshot: execute wayland_tbm_client_deinit when screenshot deinit
[platform/core/api/efl-util.git] / src / efl_util.c
index b5032bf..26c0482 100644 (file)
@@ -1812,11 +1812,20 @@ efl_util_screenshot_initialize(int width, int height)
    struct wl_registry *reg = NULL;
    int ret = 0;
 
-   EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
-   EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
+   if (width <= 0 || height <= 0)
+     {
+        set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
+        return NULL;
+     }
 
    _screenshot_mutex_lock();
 
+   if (!g_screenshot)
+     {
+        screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
+        EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
+     }
+
    if (!_eflutil.wl.shot.screenshooter)
      {
         ret = _wl_init();
@@ -1868,15 +1877,13 @@ efl_util_screenshot_initialize(int width, int height)
              g_screenshot->width = width;
              g_screenshot->height = height;
           }
+        set_last_result(EFL_UTIL_ERROR_NONE);
 
         _screenshot_mutex_unlock();
 
         return g_screenshot;
      }
 
-   screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
-   EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
-
    screenshot->width = width;
    screenshot->height = height;
    screenshot->auto_rotation = EINA_TRUE;
@@ -1893,21 +1900,22 @@ efl_util_screenshot_initialize(int width, int height)
 
    return g_screenshot;
 
-fail_param:
-   set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
-   return NULL;
-fail_memory:
 /* LCOV_EXCL_START */
+fail_memory:
    if (display_wrapper)
      wl_proxy_wrapper_destroy(display_wrapper);
    set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
+   _screenshot_mutex_unlock();
    return NULL;
+
 fail_init:
    if (reg)
      wl_registry_destroy(reg);
    if (screenshot)
-     efl_util_screenshot_deinitialize(screenshot);
-   _screenshot_mutex_unlock();
+     {
+        _screenshot_mutex_unlock();
+        efl_util_screenshot_deinitialize(screenshot);
+     }
    set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
    return NULL;
 /* LCOV_EXCL_STOP */
@@ -1928,6 +1936,12 @@ efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
    free(screenshot);
    g_screenshot = NULL;
 
+   if (_eflutil.wl.shot.tbm_client)
+     {
+        wayland_tbm_client_deinit(_eflutil.wl.shot.tbm_client);
+        _eflutil.wl.shot.tbm_client = NULL;
+     }
+
    if (_eflutil.wl.shot.screenshooter)
      {
         screenshooter_destroy(_eflutil.wl.shot.screenshooter);
@@ -2002,7 +2016,7 @@ efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
         goto fail;
      }
 
-   wl_buffer_destroy(buffer);
+   wayland_tbm_client_destroy_buffer(_eflutil.wl.shot.tbm_client, buffer);
 
    /* reset shot_done for next screenshot */
    screenshot->shot_done = EINA_FALSE;
@@ -2017,7 +2031,7 @@ fail:
    if (t_surface)
      tbm_surface_destroy(t_surface);
    if (buffer)
-     wl_buffer_destroy(buffer);
+     wayland_tbm_client_destroy_buffer(_eflutil.wl.shot.tbm_client, buffer);
 
    set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);