Remove Profile Build Dependency: do it at runtime / CAPI defragmentation
[platform/core/api/efl-util.git] / src / efl_util.c
index 112e625..170f0dc 100644 (file)
@@ -30,6 +30,7 @@
 #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
+#endif
+
+/* Determine Tizen profile at runtime */
+#include <system_info.h>
+typedef enum {
+   TIZEN_PROFILE_UNKNOWN = 0,
+   TIZEN_PROFILE_MOBILE = 0x1,
+   TIZEN_PROFILE_WEARABLE = 0x2,
+   TIZEN_PROFILE_TV = 0x4,
+   TIZEN_PROFILE_IVI = 0x8,
+   TIZEN_PROFILE_COMMON = 0x10,
+} tizen_profile_t;
+static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
+static tizen_profile_t _get_tizen_profile()
+{
+   char *profileName;
+   system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
+   switch (*profileName) {
+   case 'm':
+   case 'M':
+     profile = TIZEN_PROFILE_MOBILE;
+     break;
+   case 'w':
+   case 'W':
+     profile = TIZEN_PROFILE_WEARABLE;
+     break;
+   case 't':
+   case 'T':
+     profile = TIZEN_PROFILE_TV;
+     break;
+   case 'i':
+   case 'I':
+     profile = TIZEN_PROFILE_IVI;
+     break;
+   default: // common or unknown ==> ALL ARE COMMON.
+     profile = TIZEN_PROFILE_COMMON;
+   }
+   free(profileName);
+
+   return profile;
+}
+static inline tizen_profile_t get_tizen_profile()
+{
+   if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
+     return profile;
+   return _get_tizen_profile();
+}
+
+
+#define LOG_TAG "TIZEN_N_EFL_UTIL"
+
+
 /* callback handler index */
 #define CBH_NOTI_LEV 0
 #define CBH_SCR_MODE 1
@@ -98,9 +156,12 @@ typedef struct _Efl_Util_Data
       } policy;
       struct
       {
+         struct wl_event_queue *queue;
          struct screenshooter *screenshooter;
+         struct tizen_screenshooter *tz_screenshooter;
          struct wayland_tbm_client *tbm_client;
          Eina_List *output_list;
+         uint32_t noti;
       } shot;
       struct
       {
@@ -127,7 +188,7 @@ static Efl_Util_Data _eflutil =
       EINA_FALSE,
       NULL, NULL,
       { NULL, NULL, NULL }, /* tizen_policy protocol */
-      { NULL, NULL, NULL }, /* screenshooter protocol */
+      { NULL, NULL, NULL, NULL, NULL, 0 }, /* screenshooter protocol */
       { NULL, -1 } /* tizen_input_device_manager protocol */
    },
    {
@@ -143,6 +204,8 @@ static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx);
 static Eina_Bool               _wl_init(void);
 static void                    _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
 static void                    _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name);
+static void                    _cb_wl_reg_screenshooter_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
+static void                    _cb_wl_reg_screenshooter_global_remove(void *data, struct wl_registry *reg, unsigned int name);
 static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx);
 static void                    _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t is_conformant);
 static void                    _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t conformant_part, uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h);
@@ -152,6 +215,7 @@ static void                    _cb_wl_tz_policy_scr_mode_done(void *data, struct
 static void                    _cb_wl_tz_policy_iconify_state_changed(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, uint32_t iconified, uint32_t force);
 static void                    _cb_wl_tz_policy_supported_aux_hints(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, struct wl_array *hints, uint32_t num_hints);
 static void                    _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id);
+static void                    _cb_wl_tz_policy_aux_message(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, const char *key, const char *val, struct wl_array *options);
 
 static void                    _cb_wl_tz_display_policy_brightness_done(void *data, struct tizen_display_policy *tizen_display_policy, struct wl_surface *surface_resource, int32_t brightness, uint32_t state);
 
@@ -166,6 +230,12 @@ static const struct wl_registry_listener _wl_reg_listener =
    _cb_wl_reg_global_remove
 };
 
+static const struct wl_registry_listener _wl_reg_screenshooter_listener =
+{
+   _cb_wl_reg_screenshooter_global,
+   _cb_wl_reg_screenshooter_global_remove
+};
+
 struct tizen_policy_listener _wl_tz_policy_listener =
 {
    _cb_wl_tz_policy_conformant,
@@ -176,6 +246,7 @@ struct tizen_policy_listener _wl_tz_policy_listener =
    _cb_wl_tz_policy_iconify_state_changed,
    _cb_wl_tz_policy_supported_aux_hints,
    _cb_wl_tz_policy_allowed_aux_hint,
+   _cb_wl_tz_policy_aux_message,
 };
 
 struct tizen_input_device_manager_listener _wl_tz_devmgr_listener =
@@ -264,6 +335,7 @@ _cb_info_find_by_win(Evas_Object *win,
 static Eina_Bool
 _wl_init(void)
 {
+   struct wl_display *display_wrapper = NULL;
    struct wl_registry *reg = NULL;
 
    if (_eflutil.wl.init) return EINA_TRUE;
@@ -273,27 +345,34 @@ _wl_init(void)
    _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.queue = NULL;
      }
 
-   if (reg)
-     wl_registry_destroy(reg);
    ecore_wl_shutdown();
    return EINA_FALSE;
 }
@@ -355,6 +434,23 @@ static const struct screenshooter_listener screenshooter_listener =
 };
 
 static void
+_cb_tz_screenshot_format(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t format)
+{
+}
+
+static void
+_cb_tz_screenshot_noti(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t noti)
+{
+   _eflutil.wl.shot.noti = noti;
+}
+
+static const struct tizen_screenshooter_listener tz_screenshooter_listener =
+{
+    _cb_tz_screenshot_format,
+    _cb_tz_screenshot_noti
+};
+
+static void
 _cb_wl_reg_global(void *data,
                   struct wl_registry *reg,
                   unsigned int name,
@@ -388,11 +484,6 @@ _cb_wl_reg_global(void *data,
         output->output = wl_registry_bind(reg, name, &wl_output_interface, version);
         wl_output_add_listener(output->output, &output_listener, output);
      }
-   else if (strcmp(interface, "screenshooter") == 0)
-     {
-        _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version);
-        screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL);
-     }
    else if (strcmp(interface, "tizen_input_device_manager") == 0)
      {
         _eflutil.wl.devmgr.devicemgr = wl_registry_bind(reg, name, &tizen_input_device_manager_interface, version);
@@ -424,6 +515,36 @@ _cb_wl_reg_global_remove(void *data,
    _eflutil.wl.display_policy.proto = NULL;
    eina_hash_free(_eflutil.wl.display_policy.hash_brightness);
 }
+/* LCOV_EXCL_STOP */
+
+static void
+_cb_wl_reg_screenshooter_global(void *data,
+                  struct wl_registry *reg,
+                  unsigned int name,
+                  const char *interface,
+                  unsigned int version)
+{
+   if (strcmp(interface, "screenshooter") == 0)
+     {
+        _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version);
+        screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL);
+     }
+   else if (strcmp(interface, "tizen_screenshooter") == 0)
+     {
+        _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);
+     }
+}
+
+/* LCOV_EXCL_START */
+static void
+_cb_wl_reg_screenshooter_global_remove(void *data,
+                         struct wl_registry *reg,
+                         unsigned int name)
+{
+}
 
 static Efl_Util_Callback_Info *
 _cb_info_find_by_wlsurf(void *wlsurf,
@@ -537,6 +658,10 @@ static void                    _cb_wl_tz_policy_supported_aux_hints(void *data,
 static void                    _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id)
 {
 }
+
+static void                    _cb_wl_tz_policy_aux_message(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, const char *key, const char *val, struct wl_array *options)
+{
+}
 /* LCOV_EXCL_STOP */
 
 static void
@@ -580,6 +705,22 @@ efl_util_set_notification_window_level(Evas_Object *window,
                                    (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP),
                                    EFL_UTIL_ERROR_INVALID_PARAMETER);
 
+   if (level == EFL_UTIL_NOTIFICATION_LEVEL_1)
+     {
+        dlog_print(DLOG_WARN, LOG_TAG,
+          "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_1 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT instead.");
+     }
+   else if (level == EFL_UTIL_NOTIFICATION_LEVEL_2)
+     {
+        dlog_print(DLOG_WARN, LOG_TAG,
+          "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_2 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM instead.");
+     }
+   else if (level == EFL_UTIL_NOTIFICATION_LEVEL_3)
+     {
+        dlog_print(DLOG_WARN, LOG_TAG,
+          "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_3 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_TOP instead.");
+     }
+
    Elm_Win_Type type;
    Ecore_Wl_Window *wlwin;
    struct wl_surface *surface;
@@ -743,6 +884,9 @@ efl_util_set_notification_window_level_error_cb(Evas_Object *window,
                                                 efl_util_notification_window_level_error_cb callback,
                                                 void *user_data)
 {
+   dlog_print(DLOG_WARN, LOG_TAG,
+     "DEPRECATION WARNING: efl_util_set_notification_window_level_error_cb() is deprecated and will be removed from next release. Use the return value of efl_util_set_notification_window_level() instead.");
+
    Eina_Bool ret = EINA_FALSE;
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
@@ -760,6 +904,9 @@ efl_util_set_notification_window_level_error_cb(Evas_Object *window,
 API int
 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
 {
+   dlog_print(DLOG_WARN, LOG_TAG,
+     "DEPRECATION WARNING: efl_util_unset_notification_window_level_error_cb() is deprecated and will be removed from next release. Use the return value of efl_util_set_notification_window_level() instead.");
+
    Eina_Bool ret = EINA_FALSE;
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
@@ -945,12 +1092,18 @@ efl_util_get_window_screen_mode(Evas_Object *window,
      return EFL_UTIL_ERROR_INVALID_PARAMETER;
 }
 
-#ifndef TIZEN_WEARABLE
 API int
 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
                                          efl_util_window_screen_mode_error_cb callback,
                                          void *user_data)
 {
+   /* Wearable device cannot use this. */
+   if (get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
+     return EFL_UTIL_ERROR_NO_SUCH_DEVICE;
+
+   dlog_print(DLOG_WARN, LOG_TAG,
+     "DEPRECATION WARNING: efl_util_set_window_screen_mode_error_cb() is deprecated and will be removed from next release. Use the return value of efl_util_set_window_screen_mode() instead.");
+
    Eina_Bool ret = EINA_FALSE;
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
@@ -968,6 +1121,13 @@ efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
 API int
 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
 {
+   /* Wearable device cannot use this. */
+   if (get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
+     return EFL_UTIL_ERROR_NO_SUCH_DEVICE;
+
+   dlog_print(DLOG_WARN, LOG_TAG,
+     "DEPRECATION WARNING: efl_util_unset_window_screen_mode_error_cb() is deprecated and will be removed from next release. Use the return value of efl_util_set_window_screen_mode() instead.");
+
    Eina_Bool ret = EINA_FALSE;
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
@@ -977,7 +1137,6 @@ efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
 
    return EFL_UTIL_ERROR_NONE;
 }
-#endif
 
 API int
 efl_util_set_window_brightness(Evas_Object *window, int brightness)
@@ -1164,13 +1323,16 @@ _efl_util_input_convert_input_generator_error(int ret)
 }
 
 API efl_util_inputgen_h
-efl_util_input_initialize_generator(efl_util_input_device_type_e dev_type)
+efl_util_input_initialize_generator(unsigned int dev_type)
 {
    int ret = EFL_UTIL_ERROR_NONE;
    efl_util_inputgen_h inputgen_h = NULL;
+   unsigned int clas = 0x0;
 
-   if ((dev_type <= EFL_UTIL_INPUT_DEVTYPE_NONE) ||
-       (dev_type >= EFL_UTIL_INPUT_DEVTYPE_MAX))
+   if (!dev_type ||
+        dev_type & ~(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN
+                    | EFL_UTIL_INPUT_DEVTYPE_KEYBOARD
+                    | EFL_UTIL_INPUT_DEVTYPE_POINTER))
      {
         set_last_result(EFL_UTIL_ERROR_NO_SUCH_DEVICE);
         goto out;
@@ -1192,10 +1354,17 @@ efl_util_input_initialize_generator(efl_util_input_device_type_e dev_type)
         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);
@@ -1222,14 +1391,22 @@ API int
 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);
@@ -1303,6 +1480,46 @@ efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx,
    return ret;
 }
 
+API int
+efl_util_input_generate_pointer(efl_util_inputgen_h inputgen_h, int buttons, efl_util_input_pointer_type_e pointer_type, int x, int y)
+{
+   int ret;
+   enum tizen_input_device_manager_pointer_event_type type;
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
+   EINA_SAFETY_ON_FALSE_RETURN_VAL(buttons > 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
+   EINA_SAFETY_ON_FALSE_RETURN_VAL((x >= 0 && y >= 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
+   EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
+
+   switch(pointer_type)
+     {
+        case EFL_UTIL_INPUT_POINTER_BUTTON_DOWN:
+           type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
+           break;
+        case EFL_UTIL_INPUT_POINTER_MOVE:
+           type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
+           break;
+        case EFL_UTIL_INPUT_POINTER_BUTTON_UP:
+           type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
+           break;
+        default:
+           return EFL_UTIL_ERROR_INVALID_PARAMETER;
+     }
+
+   tizen_input_device_manager_generate_pointer(_eflutil.wl.devmgr.devicemgr, type, x, y, buttons);
+
+   while (_eflutil.wl.devmgr.request_notified == -1)
+     wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
+
+   ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
+   _eflutil.wl.devmgr.request_notified = -1;
+
+   return ret;
+}
+
+
 struct _efl_util_screenshot_h
 {
    int width;
@@ -1312,30 +1529,117 @@ struct _efl_util_screenshot_h
 
    /* 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)
 {
    efl_util_screenshot_h screenshot = NULL;
+   struct wl_display *display_wrapper = NULL;
+   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);
+
+   _screenshot_mutex_lock();
 
    if (!_eflutil.wl.shot.screenshooter)
      {
-        int ret = 0;
-        _wl_init();
-        while (!_eflutil.wl.shot.screenshooter && ret != -1)
-          ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
+        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_memory);
+
+        _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.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);
 
-       _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy);
-       EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init);
+        _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy);
+        EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init);
      }
 
-   EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
-   EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
+   if (_eflutil.wl.shot.noti == 0)
+     {
+        fprintf(stderr, "[screenshot] fail: privilege error\n"); /* LCOV_EXCL_LINE */
+        goto fail_init;
+     }
 
    if (g_screenshot)
      {
@@ -1345,6 +1649,8 @@ efl_util_screenshot_initialize(int width, int height)
              g_screenshot->height = height;
           }
 
+        _screenshot_mutex_unlock();
+
         return g_screenshot;
      }
 
@@ -1353,6 +1659,7 @@ efl_util_screenshot_initialize(int width, int height)
 
    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);
@@ -1362,38 +1669,62 @@ efl_util_screenshot_initialize(int width, int height)
 
    screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
 
+   _screenshot_mutex_unlock();
+
    return g_screenshot;
 
 fail_param:
-   if (screenshot)
-     efl_util_screenshot_deinitialize(screenshot);
    set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
    return NULL;
 fail_memory:
 /* LCOV_EXCL_START */
-   if (screenshot)
-     efl_util_screenshot_deinitialize(screenshot);
+   if (display_wrapper)
+     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);
+   _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_set_user_data(_eflutil.wl.shot.screenshooter, NULL);
+     {
+        screenshooter_destroy(_eflutil.wl.shot.screenshooter);
+        _eflutil.wl.shot.screenshooter = NULL;
+     }
+   if (_eflutil.wl.shot.tz_screenshooter)
+     {
+        tizen_screenshooter_destroy(_eflutil.wl.shot.tz_screenshooter);
+        _eflutil.wl.shot.tz_screenshooter = NULL;
+     }
+
+   _screenshot_mutex_unlock();
+   _screenshot_mutex_destory();
 
    return EFL_UTIL_ERROR_NONE;
 }
@@ -1407,9 +1738,12 @@ efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
    Efl_Util_Wl_Output_Info *output;
    int ret = 0;
 
-   if (screenshot != g_screenshot)
+   _screenshot_mutex_lock();
+
+   if (!screenshot || (screenshot != g_screenshot))
      {
         set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
+        _screenshot_mutex_unlock();
         return NULL;
      }
 
@@ -1438,7 +1772,7 @@ efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
 
    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)
      {
@@ -1451,6 +1785,10 @@ efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
    /* 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:
@@ -1461,5 +1799,37 @@ 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;
+}