#include <tbm_surface_internal.h>
#include <Elementary.h>
#include <Ecore_Evas.h>
+#include <pthread.h>
#include <Ecore_Wayland.h>
#include <wayland-client.h>
#include <tizen-extension-client-protocol.h>
#include <screenshooter-client-protocol.h>
+#include <efl_util_screenshot_extension.h>
+
#include <dlog.h>
#ifdef LOG_TAG
#undef LOG_TAG
} policy;
struct
{
+ struct wl_event_queue *queue;
struct screenshooter *screenshooter;
struct tizen_screenshooter *tz_screenshooter;
struct wayland_tbm_client *tbm_client;
EINA_FALSE,
NULL, NULL,
{ NULL, NULL, NULL }, /* tizen_policy protocol */
- { NULL, NULL, NULL, NULL, 0 }, /* screenshooter protocol */
+ { NULL, NULL, NULL, NULL, NULL, 0 }, /* screenshooter protocol */
{ NULL, -1 } /* tizen_input_device_manager protocol */
},
{
static Eina_Bool
_wl_init(void)
{
+ struct wl_display *display_wrapper = NULL;
struct wl_registry *reg = NULL;
if (_eflutil.wl.init) return EINA_TRUE;
_eflutil.wl.dpy = ecore_wl_display_get();
EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.dpy, fail);
+ display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy);
+ EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail);
+
_eflutil.wl.queue = wl_display_create_queue(_eflutil.wl.dpy);
EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.queue, fail);
- reg = wl_display_get_registry(_eflutil.wl.dpy);
+ wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.queue);
+
+ reg = wl_display_get_registry(display_wrapper);
+ wl_proxy_wrapper_destroy(display_wrapper);
+ display_wrapper = NULL;
EINA_SAFETY_ON_NULL_GOTO(reg, fail);
- wl_proxy_set_queue((struct wl_proxy*)reg, _eflutil.wl.queue);
wl_registry_add_listener(reg, &_wl_reg_listener, NULL);
_eflutil.wl.init = EINA_TRUE;
return EINA_TRUE;
fail:
+ if (display_wrapper)
+ wl_proxy_wrapper_destroy(display_wrapper);
+
if (_eflutil.wl.queue)
{
wl_event_queue_destroy(_eflutil.wl.queue);
{
_eflutil.wl.shot.tz_screenshooter = wl_registry_bind(reg, name, &tizen_screenshooter_interface, version);
tizen_screenshooter_add_listener(_eflutil.wl.shot.tz_screenshooter, &tz_screenshooter_listener, NULL);
+
+ wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
}
}
{
int ret = EFL_UTIL_ERROR_NONE;
efl_util_inputgen_h inputgen_h = NULL;
+ unsigned int clas = 0x0;
if (!dev_type ||
dev_type & ~(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN
goto out;
}
+ if (dev_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN)
+ clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
+ if (dev_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD)
+ clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
+ if (dev_type & EFL_UTIL_INPUT_DEVTYPE_POINTER)
+ clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
+
while (!_eflutil.wl.devmgr.devicemgr)
wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
- tizen_input_device_manager_init_generator(_eflutil.wl.devmgr.devicemgr);
+ tizen_input_device_manager_init_generator(_eflutil.wl.devmgr.devicemgr, clas);
while (_eflutil.wl.devmgr.request_notified == -1)
wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h)
{
int ret = EFL_UTIL_ERROR_NONE;
+ unsigned int clas = 0x0;
EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN)
+ clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
+ if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD)
+ clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
+ if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER)
+ clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
+
free(inputgen_h);
inputgen_h = NULL;
EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
- tizen_input_device_manager_deinit_generator(_eflutil.wl.devmgr.devicemgr);
+ tizen_input_device_manager_deinit_generator(_eflutil.wl.devmgr.devicemgr, clas);
while (_eflutil.wl.devmgr.request_notified == -1)
wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
/* tbm bufmgr */
tbm_bufmgr bufmgr;
+
+ Eina_Bool auto_rotation;
};
/* 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)
{
- _wl_init();
+ 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);
display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy);
- EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail_init);
+ EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail_memory);
- wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.queue);
+ _eflutil.wl.shot.queue = wl_display_create_queue(_eflutil.wl.dpy);
+ EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.queue, fail_memory);
+
+ wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.shot.queue);
reg = wl_display_get_registry(display_wrapper);
+ wl_proxy_wrapper_destroy(display_wrapper);
+ display_wrapper = NULL;
EINA_SAFETY_ON_NULL_GOTO(reg, fail_init);
wl_registry_add_listener(reg, &_wl_reg_screenshooter_listener, NULL);
- ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
+ ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
EINA_SAFETY_ON_TRUE_GOTO(ret == -1, fail_init);
EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init);
EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tz_screenshooter, fail_init);
EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init);
}
- wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
- wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
-
if (_eflutil.wl.shot.noti == 0)
{
fprintf(stderr, "[screenshot] fail: privilege error\n"); /* LCOV_EXCL_LINE */
g_screenshot->height = height;
}
+ _screenshot_mutex_unlock();
+
return g_screenshot;
}
screenshot->width = width;
screenshot->height = height;
+ screenshot->auto_rotation = EINA_TRUE;
screenshot->bufmgr = wayland_tbm_client_get_bufmgr(_eflutil.wl.shot.tbm_client);
EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
+ _screenshot_mutex_unlock();
+
return g_screenshot;
fail_param:
wl_proxy_wrapper_destroy(display_wrapper);
set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
return NULL;
-/* LCOV_EXCL_STOP */
fail_init:
if (screenshot)
efl_util_screenshot_deinitialize(screenshot);
- if (display_wrapper)
- wl_proxy_wrapper_destroy(display_wrapper);
+ _screenshot_mutex_unlock();
set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
return NULL;
+/* LCOV_EXCL_STOP */
}
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;
+ if (_eflutil.wl.shot.queue)
+ {
+ wl_event_queue_destroy(_eflutil.wl.shot.queue);
+ _eflutil.wl.shot.queue = NULL;
+ }
+
if (_eflutil.wl.shot.screenshooter)
{
screenshooter_destroy(_eflutil.wl.shot.screenshooter);
_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;
}
screenshot->shot_done = EINA_FALSE;
while (!screenshot->shot_done && ret != -1)
- ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
+ ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
if (ret == -1)
{
/* reset shot_done for next screenshot */
screenshot->shot_done = EINA_FALSE;
+ set_last_result(EFL_UTIL_ERROR_NONE);
+
+ _screenshot_mutex_unlock();
+
return t_surface;
fail:
set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);
+ _screenshot_mutex_unlock();
+
return NULL;
}
+
+API int
+efl_util_screenshot_set_auto_rotation(efl_util_screenshot_h screenshot, int set)
+{
+ if (!screenshot || (screenshot != g_screenshot))
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+
+ if (!(set == 0 || set == 1))
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+
+ if (set)
+ g_screenshot->auto_rotation = EINA_TRUE;
+ else
+ g_screenshot->auto_rotation = EINA_FALSE;
+
+ tizen_screenshooter_set_oneshot_auto_rotation(_eflutil.wl.shot.tz_screenshooter, g_screenshot->auto_rotation);
+
+ return EFL_UTIL_ERROR_NONE;
+}
+
+API int
+efl_util_screenshot_get_auto_rotation(efl_util_screenshot_h screenshot, int *set)
+{
+ if (!screenshot || (screenshot != g_screenshot) || !set)
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+
+ *set = g_screenshot->auto_rotation;
+
+ return EFL_UTIL_ERROR_NONE;
+}