#include <tbm_surface_internal.h>
#include <Elementary.h>
#include <Ecore_Evas.h>
+#include <pthread.h>
#include <Ecore_Wayland.h>
#include <wayland-client.h>
/* scrrenshot handle */
static efl_util_screenshot_h g_screenshot;
+static Eina_Bool shot_mutex_init;
+static pthread_mutex_t shot_lock;
+
+static Eina_Bool
+_screenshot_mutex_init(void)
+{
+ if (shot_mutex_init)
+ return EINA_TRUE;
+
+ if (pthread_mutex_init(&shot_lock, NULL))
+ {
+ fprintf(stderr, "[screenshot] fail: mutex init"); /*LCOV_EXCL_LINE*/
+ return EINA_FALSE; /*LCOV_EXCL_LINE*/
+ }
+
+ shot_mutex_init = EINA_TRUE;
+
+ return EINA_TRUE;
+}
+
+static Eina_Bool
+_screenshot_mutex_destory(void)
+{
+ if (!shot_mutex_init)
+ return EINA_TRUE;
+
+ if (pthread_mutex_destroy(&shot_lock))
+ {
+ fprintf(stderr, "[screenshot] fail: mutex destory"); /*LCOV_EXCL_LINE*/
+ return EINA_FALSE; /*LCOV_EXCL_LINE*/
+ }
+
+ shot_mutex_init = EINA_FALSE;
+
+ return EINA_TRUE;
+}
+
+void
+_screenshot_mutex_lock(void)
+{
+ if (!_screenshot_mutex_init())
+ return;
+
+ pthread_mutex_lock(&shot_lock);
+}
+
+void
+_screenshot_mutex_unlock(void)
+{
+ pthread_mutex_unlock(&shot_lock);
+}
API efl_util_screenshot_h
efl_util_screenshot_initialize(int width, int height)
EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
+ _screenshot_mutex_lock();
+
if (!_eflutil.wl.shot.screenshooter)
{
ret = _wl_init();
if (ret == (int)EINA_FALSE)
{
set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
+ _screenshot_mutex_unlock();
return NULL;
}
wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
g_screenshot->height = height;
}
+ _screenshot_mutex_unlock();
+
return g_screenshot;
}
screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
+ _screenshot_mutex_unlock();
+
return g_screenshot;
fail_param:
fail_init:
if (screenshot)
efl_util_screenshot_deinitialize(screenshot);
+ _screenshot_mutex_unlock();
if (display_wrapper)
wl_proxy_wrapper_destroy(display_wrapper);
set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
API int
efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
{
+ _screenshot_mutex_lock();
+
if (!screenshot)
- return EFL_UTIL_ERROR_INVALID_PARAMETER;
+ {
+ _screenshot_mutex_unlock();
+ _screenshot_mutex_destory();
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+ }
free(screenshot);
g_screenshot = NULL;
_eflutil.wl.shot.tz_screenshooter = NULL;
}
+ _screenshot_mutex_unlock();
+ _screenshot_mutex_destory();
+
return EFL_UTIL_ERROR_NONE;
}
Efl_Util_Wl_Output_Info *output;
int ret = 0;
+ _screenshot_mutex_lock();
+
if (!screenshot || (screenshot != g_screenshot))
{
set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
+ _screenshot_mutex_unlock();
return NULL;
}
/* reset shot_done for next screenshot */
screenshot->shot_done = EINA_FALSE;
+ _screenshot_mutex_unlock();
+
return t_surface;
fail:
set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);
+ _screenshot_mutex_unlock();
+
return NULL;
}