From f4071c4314d962133776b7a0e2b6a65100bf9eb3 Mon Sep 17 00:00:00 2001 From: Juyeon Lee Date: Mon, 16 May 2016 21:12:13 +0900 Subject: [PATCH] Removed WITH_X, WINT_WAYLAND configure and Make it Wayland only Change-Id: I657a26786810c70fe0918f97df135969047f55b5 --- CMakeLists.txt | 11 +- packaging/capi-ui-efl-util.spec | 21 -- src/efl_util.c | 779 +--------------------------------------- 3 files changed, 4 insertions(+), 807 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 299a3a0..aae7271 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,15 +19,8 @@ INCLUDE_DIRECTORIES(${INC_DIR}) # required dependencies SET(dependents "dlog elementary capi-base-common libdrm libtbm") -IF (WITH_X11) - ADD_DEFINITIONS("-DX11") - SET(dependents "${dependents} ecore-x utilX x11 xv libdri2 xext xdamage xtst") -ENDIF (WITH_X11) - -IF (WITH_WAYLAND) - ADD_DEFINITIONS("-DWAYLAND") - SET(dependents "${dependents} ecore-wayland wayland-client wayland-tbm-client screenshooter-client tizen-extension-client") -ENDIF (WITH_WAYLAND) +ADD_DEFINITIONS("-DWAYLAND") +SET(dependents "${dependents} ecore-wayland wayland-client wayland-tbm-client screenshooter-client tizen-extension-client") INCLUDE(FindPkgConfig) pkg_check_modules(${fw_name} REQUIRED ${dependents}) diff --git a/packaging/capi-ui-efl-util.spec b/packaging/capi-ui-efl-util.spec index 9eb45a9..0d0d9bc 100644 --- a/packaging/capi-ui-efl-util.spec +++ b/packaging/capi-ui-efl-util.spec @@ -1,5 +1,3 @@ -%bcond_with x -%bcond_with wayland Name: capi-ui-efl-util Summary: An EFL utility library in Tizen C API @@ -11,24 +9,11 @@ Source0: %{name}-%{version}.tar.gz Source1001: capi-ui-efl-util.manifest BuildRequires: cmake BuildRequires: pkgconfig(dlog) -%if %{with x} -BuildRequires: pkgconfig(x11) -BuildRequires: pkgconfig(utilX) -BuildRequires: pkgconfig(ecore-x) -BuildRequires: pkgconfig(xtst) -BuildRequires: pkgconfig(libdri2) -BuildRequires: pkgconfig(dri2proto) -BuildRequires: pkgconfig(xext) -BuildRequires: pkgconfig(xv) -BuildRequires: pkgconfig(xdamage) -%endif -%if %{with wayland} BuildRequires: pkgconfig(wayland-client) BuildRequires: pkgconfig(wayland-tbm-client) BuildRequires: pkgconfig(screenshooter-client) BuildRequires: pkgconfig(tizen-extension-client) BuildRequires: pkgconfig(ecore-wayland) -%endif BuildRequires: pkgconfig(elementary) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(libdrm) @@ -58,12 +43,6 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` %if "%{profile}" == "wearable" -DTIZEN_WEARABLE=YES \ %endif -%if %{with wayland} --DWITH_WAYLAND=TRUE -%endif -%if %{with x} --DWITH_X11=TRUE -%endif make %{?jobs:-j%jobs} diff --git a/src/efl_util.c b/src/efl_util.c index 5c3281d..324b099 100644 --- a/src/efl_util.c +++ b/src/efl_util.c @@ -31,23 +31,11 @@ #include #include -#if X11 -#include -#include -#include -#include -#include -#include -#include -#endif /* end of X11 */ - -#if WAYLAND #include #include #include #include #include -#endif /* end of WAYLAND */ /* callback handler index */ #define CBH_NOTI_LEV 0 @@ -63,7 +51,6 @@ typedef struct _Efl_Util_Callback_Info void *data; } Efl_Util_Callback_Info; -#if WAYLAND typedef struct _Efl_Util_Wl_Surface_Lv_Info { void *surface; /* wl_surface */ @@ -93,21 +80,9 @@ typedef struct _Efl_Util_Wl_Output_Info struct wl_output *output; int offset_x, offset_y, width, height; } Efl_Util_Wl_Output_Info; -#endif typedef struct _Efl_Util_Data { -#if X11 - /* x11 related stuffs */ - struct - { - Eina_Bool init; - Ecore_Event_Handler *handler; /* x11 client message handler */ - Ecore_X_Display *dpy; - } x11; -#endif /* end of X11 */ - -#if WAYLAND /* wayland related stuffs */ struct { @@ -138,7 +113,6 @@ typedef struct _Efl_Util_Data Eina_Hash *hash_brightness; } display_policy; } wl; -#endif /* end of WAYLAND */ struct { @@ -149,14 +123,6 @@ typedef struct _Efl_Util_Data static Efl_Util_Data _eflutil = { -#if X11 - { - EINA_FALSE, - NULL, - NULL - }, -#endif /* end of X11 */ -#if WAYLAND { EINA_FALSE, NULL, NULL, @@ -164,7 +130,6 @@ static Efl_Util_Data _eflutil = { NULL, NULL, NULL }, /* screenshooter protocol */ { NULL, -1 } /* tizen_input_device_manager protocol */ }, -#endif /* end of WAYLAND */ { { NULL, 0 }, /* handler for notification level */ { NULL, 0 } /* handler for screen mode */ @@ -175,12 +140,6 @@ static Eina_Bool _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, vo static Eina_Bool _cb_info_del_by_win(Evas_Object *win, int idx); static Eina_List *_cb_info_list_get(int idx); static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx); -#if X11 -static Efl_Util_Callback_Info *_cb_info_find_by_xwin(unsigned int xwin, int idx); -static Eina_Bool _cb_x11_client_msg(void *data, int type, void *event); -static Eina_Bool _x11_init(void); -#endif /* end of X11 */ -#if WAYLAND 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); @@ -231,7 +190,6 @@ struct tizen_display_policy_listener _wl_tz_display_policy_listener = { _cb_wl_tz_display_policy_brightness_done, }; -#endif /* end of WAYLAND */ static Eina_Bool _cb_info_add(Evas_Object *win, @@ -261,13 +219,6 @@ _cb_info_add(Evas_Object *win, = eina_list_append(_eflutil.cb_handler[idx].info_list, info); -#if X11 - if (!_eflutil.x11.handler) - _eflutil.x11.handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, - _cb_x11_client_msg, - NULL); -#endif /* end of X11 */ - return EINA_TRUE; } @@ -285,15 +236,6 @@ _cb_info_del_by_win(Evas_Object *win, info); free(info); -#if X11 - unsigned int count = eina_list_count(_eflutil.cb_handler[idx].info_list); - if ((count == 0) && (_eflutil.x11.handler)) - { - ecore_event_handler_del(_eflutil.x11.handler); - _eflutil.x11.handler = NULL; - } -#endif - return EINA_TRUE; } @@ -319,86 +261,6 @@ _cb_info_find_by_win(Evas_Object *win, return NULL; } -#if X11 -static Efl_Util_Callback_Info * -_cb_info_find_by_xwin(unsigned int xwin, - int idx) -{ - Eina_List *l, *ll; - Efl_Util_Callback_Info *info; - unsigned int xwin2; - - l = _cb_info_list_get(idx); - EINA_LIST_FOREACH(l, ll, info) - { - xwin2 = elm_win_xwindow_get(info->win); - if (xwin == xwin2) return info; - } - - return NULL; -} - -static Eina_Bool -_cb_x11_client_msg(void *data, - int type, - void *event) -{ - Ecore_X_Event_Client_Message *ev; - Ecore_X_Window xwin; - Efl_Util_Callback_Info *info; - - ev = event; - if (!ev) return ECORE_CALLBACK_PASS_ON; - - xwin = ev->win; - if (xwin == 0) return ECORE_CALLBACK_PASS_ON; - - if (ev->message_type == _eflutil.cb_handler[CBH_NOTI_LEV].atom) - { - info = _cb_info_find_by_xwin(xwin, CBH_NOTI_LEV); - - /* permission denied */ - if ((ev->data.l[1] == 0) && - (info) && - (info->cb)) - { - info->cb(info->win, - EFL_UTIL_ERROR_PERMISSION_DENIED, - info->data); - } - } - else if (ev->message_type == _eflutil.cb_handler[CBH_SCR_MODE].atom) - { - info = _cb_info_find_by_xwin(xwin, CBH_SCR_MODE); - - /* permission denied */ - if ((ev->data.l[1] == 0) && - (info) && - (info->cb)) - { - info->cb(info->win, - EFL_UTIL_ERROR_PERMISSION_DENIED, - info->data); - } - } - return ECORE_CALLBACK_PASS_ON; -} - -static Eina_Bool -_x11_init(void) -{ - if (_eflutil.x11.init) return EINA_TRUE; - - _eflutil.x11.dpy = ecore_x_display_get(); - EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.x11.dpy, EINA_FALSE); - - _eflutil.x11.init = EINA_TRUE; - - return EINA_TRUE; -} -#endif /* end of X11 */ - -#if WAYLAND static Eina_Bool _wl_init(void) { @@ -701,7 +563,6 @@ _cb_window_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, vo eina_hash_del(_eflutil.wl.policy.hash_noti_lv, &lv_info->surface, lv_info); } -#endif /* end of WAYLAND */ API int efl_util_set_notification_window_level(Evas_Object *window, @@ -714,38 +575,6 @@ efl_util_set_notification_window_level(Evas_Object *window, (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP), EFL_UTIL_ERROR_INVALID_PARAMETER); -#if X11 - Ecore_X_Window_Type window_type; - Ecore_X_Window xwin; - - res = _x11_init(); - EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER); - - xwin = elm_win_xwindow_get(window); - if (xwin) - { - if (ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE) - { - // success to get window type - if (window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION) - { - // given EFL window's type is not notification type. - return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE; - } - } - else - return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE; - - utilx_set_system_notification_level(_eflutil.x11.dpy, - xwin, - level); - return EFL_UTIL_ERROR_NONE; - } - - return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE; -#endif /* end of X11 */ - -#if WAYLAND Elm_Win_Type type; Ecore_Wl_Window *wlwin; struct wl_surface *surface; @@ -825,7 +654,6 @@ efl_util_set_notification_window_level(Evas_Object *window, } return EFL_UTIL_ERROR_NONE; -#endif /* end of WAYLAND */ } API int @@ -837,46 +665,6 @@ efl_util_get_notification_window_level(Evas_Object *window, EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER); EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER); -#if X11 - Ecore_X_Window_Type window_type; - Utilx_Notification_Level utilx_level; - Ecore_X_Window xwin; - - res = _x11_init(); - EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER); - - xwin = elm_win_xwindow_get(window); - if (xwin) - { - if (ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE) - { - // success to get window type - if (window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION) - { - // given EFL window's type is not notification type. - return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE; - } - - utilx_level = utilx_get_system_notification_level(_eflutil.x11.dpy, xwin); - if (utilx_level == UTILX_NOTIFICATION_LEVEL_LOW) - *level = EFL_UTIL_NOTIFICATION_LEVEL_1; - else if(utilx_level == UTILX_NOTIFICATION_LEVEL_NORMAL) - *level = EFL_UTIL_NOTIFICATION_LEVEL_2; - else if(utilx_level == UTILX_NOTIFICATION_LEVEL_HIGH) - *level = EFL_UTIL_NOTIFICATION_LEVEL_3; - else - return EFL_UTIL_ERROR_INVALID_PARAMETER; - } - else - return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE; - - return EFL_UTIL_ERROR_NONE; - } - - return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE; -#endif /* end of X11 */ - -#if WAYLAND Elm_Win_Type type; Ecore_Wl_Window *wlwin; struct wl_surface *surface; @@ -943,7 +731,6 @@ efl_util_get_notification_window_level(Evas_Object *window, *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; return EFL_UTIL_ERROR_NONE; -#endif /* end of WAYLAND */ } API int @@ -962,11 +749,6 @@ efl_util_set_notification_window_level_error_cb(Evas_Object *window, CBH_NOTI_LEV); if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY; -#if X11 - if (!_eflutil.cb_handler[CBH_NOTI_LEV].atom) - _eflutil.cb_handler[CBH_NOTI_LEV].atom = ecore_x_atom_get("_E_NOTIFICATION_LEVEL_ACCESS_RESULT"); -#endif /* end of X11 */ - return EFL_UTIL_ERROR_NONE; } @@ -993,33 +775,6 @@ efl_util_set_window_opaque_state(Evas_Object *window, EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)), EFL_UTIL_ERROR_INVALID_PARAMETER); -#if X11 - Ecore_X_Window xwin; - Utilx_Opaque_State state; - int ret; - - res = _x11_init(); - EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER); - - xwin = elm_win_xwindow_get(window); - EINA_SAFETY_ON_FALSE_RETURN_VAL(xwin > 0, EFL_UTIL_ERROR_INVALID_PARAMETER); - - if (opaque) - state = UTILX_OPAQUE_STATE_ON; - else - state = UTILX_OPAQUE_STATE_OFF; - - ret = utilx_set_window_opaque_state(_eflutil.x11.dpy, - xwin, - state); - - if (!ret) - return EFL_UTIL_ERROR_INVALID_PARAMETER; - else - return EFL_UTIL_ERROR_NONE; -#endif /* end of X11 */ - -#if WAYLAND Ecore_Wl_Window *wlwin; struct wl_surface *surface; @@ -1047,7 +802,6 @@ efl_util_set_window_opaque_state(Evas_Object *window, tizen_policy_set_opaque_state(_eflutil.wl.policy.proto, surface, opaque); return EFL_UTIL_ERROR_NONE; -#endif /* end of WAYLAND */ } API int @@ -1059,39 +813,6 @@ efl_util_set_window_screen_mode(Evas_Object *window, (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)), EFL_UTIL_ERROR_INVALID_PARAMETER); -#if X11 - Evas *e; - Ecore_Evas *ee; - int id; - - e = evas_object_evas_get(window); - EINA_SAFETY_ON_NULL_RETURN_VAL(e, EFL_UTIL_ERROR_INVALID_PARAMETER); - - ee = ecore_evas_ecore_evas_get(e); - EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EFL_UTIL_ERROR_INVALID_PARAMETER); - - id = ecore_evas_aux_hint_id_get(ee, "wm.policy.win.lcd.lock"); - if (mode == EFL_UTIL_SCREEN_MODE_ALWAYS_ON) - { - if (id == -1) - ecore_evas_aux_hint_add(ee, "wm.policy.win.lcd.lock", "1"); - else - ecore_evas_aux_hint_val_set(ee, id, "1"); - } - else if (mode == EFL_UTIL_SCREEN_MODE_DEFAULT) - { - if (id == -1) - ecore_evas_aux_hint_add(ee, "wm.policy.win.lcd.lock", "0"); - else - ecore_evas_aux_hint_val_set(ee, id, "0"); - } - else - return EFL_UTIL_ERROR_INVALID_PARAMETER; - - return EFL_UTIL_ERROR_NONE; -#endif /* end of X11 */ - -#if WAYLAND Ecore_Wl_Window *wlwin; struct wl_surface *surface; Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info; @@ -1161,7 +882,6 @@ efl_util_set_window_screen_mode(Evas_Object *window, } else return EFL_UTIL_ERROR_INVALID_PARAMETER; -#endif /* end of WAYLAND */ } API int @@ -1171,33 +891,6 @@ efl_util_get_window_screen_mode(Evas_Object *window, EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER); EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER); -#if X11 - Evas *e; - Ecore_Evas *ee; - const char *str; - int id; - - e = evas_object_evas_get(window); - EINA_SAFETY_ON_NULL_RETURN_VAL(e, EFL_UTIL_ERROR_INVALID_PARAMETER); - - ee = ecore_evas_ecore_evas_get(e); - EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EFL_UTIL_ERROR_INVALID_PARAMETER); - - id = ecore_evas_aux_hint_id_get(ee, "wm.policy.win.lcd.lock"); - EINA_SAFETY_ON_TRUE_RETURN_VAL((id == -1), EFL_UTIL_ERROR_INVALID_PARAMETER); - - str = ecore_evas_aux_hint_val_get(ee, id); - EINA_SAFETY_ON_NULL_RETURN_VAL(str, EFL_UTIL_ERROR_INVALID_PARAMETER); - - if (strncmp(str, "1", strlen("1")) == 0) - *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON; - else - *mode = EFL_UTIL_SCREEN_MODE_DEFAULT; - - return EFL_UTIL_ERROR_NONE; -#endif /* end of X11 */ - -#if WAYLAND Ecore_Wl_Window *wlwin; struct wl_surface *surface; Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info; @@ -1245,7 +938,6 @@ efl_util_get_window_screen_mode(Evas_Object *window, } else return EFL_UTIL_ERROR_INVALID_PARAMETER; -#endif /* end of WAYLAND */ } #ifndef TIZEN_WEARABLE @@ -1265,11 +957,6 @@ efl_util_set_window_screen_mode_error_cb(Evas_Object *window, CBH_SCR_MODE); if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY; -#if X11 - if (!_eflutil.cb_handler[CBH_SCR_MODE].atom) - _eflutil.cb_handler[CBH_SCR_MODE].atom = ecore_x_atom_get("_E_SCREEN_MODE_ACCESS_RESULT"); -#endif /* end of X11 */ - return EFL_UTIL_ERROR_NONE; } @@ -1412,7 +1099,6 @@ struct _efl_util_inputgen_h unsigned int init_type; }; -#if WAYLAND static void _cb_device_add(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, @@ -1449,7 +1135,6 @@ _cb_block_expired(void *data EINA_UNUSED, { ; } -#endif /* end of WAYLAND */ static efl_util_error_e _efl_util_input_convert_input_generator_error(int ret) @@ -1490,7 +1175,7 @@ efl_util_input_initialize_generator(efl_util_input_device_type_e dev_type) } inputgen_h->init_type |= dev_type; -#if WAYLAND + ret = _wl_init(); if (ret == (int)EINA_FALSE) { @@ -1512,7 +1197,6 @@ efl_util_input_initialize_generator(efl_util_input_device_type_e dev_type) set_last_result(ret); if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) goto out; -#endif return inputgen_h; @@ -1534,7 +1218,6 @@ efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h) free(inputgen_h); inputgen_h = NULL; -#if WAYLAND 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); @@ -1544,7 +1227,6 @@ efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h) ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified); _eflutil.wl.devmgr.request_notified = -1; -#endif return ret; } @@ -1559,7 +1241,6 @@ efl_util_input_generate_key(efl_util_inputgen_h inputgen_h, const char *key_name EINA_SAFETY_ON_FALSE_RETURN_VAL(pressed == 0 || pressed == 1, EFL_UTIL_ERROR_INVALID_PARAMETER); EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD, EFL_UTIL_ERROR_NO_SUCH_DEVICE); -#if WAYLAND EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER); tizen_input_device_manager_generate_key(_eflutil.wl.devmgr.devicemgr, key_name, pressed); @@ -1569,7 +1250,6 @@ efl_util_input_generate_key(efl_util_inputgen_h inputgen_h, const char *key_name ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified); _eflutil.wl.devmgr.request_notified = -1; -#endif return ret; } @@ -1579,16 +1259,13 @@ efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx, efl_util_input_touch_type_e touch_type, int x, int y) { int ret; -#if WAYLAND enum tizen_input_device_manager_pointer_event_type type; -#endif EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER); EINA_SAFETY_ON_FALSE_RETURN_VAL(idx >= 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_TOUCHSCREEN, EFL_UTIL_ERROR_NO_SUCH_DEVICE); -#if WAYLAND EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER); switch(touch_type) @@ -1613,7 +1290,6 @@ efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx, ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified); _eflutil.wl.devmgr.request_notified = -1; -#endif return ret; } @@ -1623,32 +1299,6 @@ struct _efl_util_screenshot_h int width; int height; -#if X11 - Ecore_X_Display *dpy; - int internal_display; - int screen; - Window root; - Pixmap pixmap; - GC gc; - Atom atom_capture; - - /* port */ - int port; - - /* damage */ - Damage damage; - int damage_base; - - /* dri2 */ - int eventBase, errorBase; - int dri2Major, dri2Minor; - char *driver_name, *device_name; - drm_magic_t magic; - - /* drm */ - int drm_fd; -#endif - Eina_Bool shot_done; /* tbm bufmgr */ @@ -1658,248 +1308,9 @@ struct _efl_util_screenshot_h /* scrrenshot handle */ static efl_util_screenshot_h g_screenshot; -#if X11 -#define FOURCC(a,b,c,d) (((unsigned)d&0xff)<<24 | ((unsigned)c&0xff)<<16 | ((unsigned)b&0xff)<<8 | ((unsigned)a&0xff)) -#define FOURCC_RGB32 FOURCC('R','G','B','4') -#define TIMEOUT_CAPTURE 3 - -/* x error handling */ -static Bool g_efl_util_x_error_caught; - -static int -_efl_util_screenshot_x_error_handle(Display *dpy, XErrorEvent *ev) -{ - if (!g_screenshot || (dpy != g_screenshot->dpy)) - return 0; - - g_efl_util_x_error_caught = True; - - return 0; -} - -static int -_efl_util_screenshot_get_port(Display *dpy, unsigned int id, Window win) -{ - unsigned int ver, rev, req_base, evt_base, err_base; - unsigned int adaptors; - XvAdaptorInfo *ai = NULL; - XvImageFormatValues *fo = NULL; - int formats; - int i, j, p; - - if (XvQueryExtension(dpy, &ver, &rev, &req_base, &evt_base, &err_base) != Success) - { - fprintf(stderr, "[screenshot] fail: no XV extension. \n"); - return -1; - } - - if (XvQueryAdaptors(dpy, win, &adaptors, &ai) != Success) - { - fprintf(stderr, "[screenshot] fail: query adaptors. \n"); - return -1; - } - - EINA_SAFETY_ON_NULL_RETURN_VAL(ai, -1); - - for (i = 0; i < adaptors; i++) - { - int support_format = False; - - if (!(ai[i].type & XvInputMask) || - !(ai[i].type & XvStillMask)) - continue; - - p = ai[i].base_id; - - fo = XvListImageFormats(dpy, p, &formats); - for (j = 0; j < formats; j++) - if (fo[j].id == (int)id) - support_format = True; - - if (fo) - XFree(fo); - - if (!support_format) - continue; - - for (; p < ai[i].base_id + ai[i].num_ports; p++) - { - if (XvGrabPort(dpy, p, 0) == Success) - { - XvFreeAdaptorInfo(ai); - return p; - } - } - } - - XvFreeAdaptorInfo(ai); - - XSync(dpy, False); - - return -1; -} - -static int -_efl_util_screenshot_get_best_size(Display *dpy, int port, int width, int height, unsigned int *best_width, unsigned int *best_height) -{ - XErrorHandler old_handler = NULL; - - Atom atom_capture = XInternAtom(dpy, "_USER_WM_PORT_ATTRIBUTE_CAPTURE", False); - - g_efl_util_x_error_caught = False; - old_handler = XSetErrorHandler(_efl_util_screenshot_x_error_handle); - - XvSetPortAttribute(dpy, port, atom_capture, 1); - XSync(dpy, False); - - g_efl_util_x_error_caught = False; - XSetErrorHandler(old_handler); - - XvQueryBestSize(dpy, port, 0, 0, 0, width, height, best_width, best_height); - if (best_width <= 0 || best_height <= 0) - return 0; - - return 1; -} -#endif - API efl_util_screenshot_h efl_util_screenshot_initialize(int width, int height) { -#if X11 - efl_util_screenshot_h screenshot = NULL; - int depth = 0; - int damage_err_base = 0; - unsigned int best_width = 0; - unsigned int best_height = 0; - - EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param); - EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param); - - if (g_screenshot != NULL) - { - if (g_screenshot->width != width || g_screenshot->height != height) - { - // TODO: recreate pixmap and update information - if (!_efl_util_screenshot_get_best_size(screenshot->dpy, screenshot->port, width, height, &best_width, &best_height)) - { - set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL); - return NULL; - } - - g_screenshot->width = width; - g_screenshot->height = height; - } - - return g_screenshot; - } - - screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h)); - EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory); - - /* set dpy */ - screenshot->dpy = ecore_x_display_get(); - if (!screenshot->dpy) - { - screenshot->dpy = XOpenDisplay(0); - EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_init); - - /* for XCloseDisplay at denitialization */ - screenshot->internal_display = 1; - } - - /* set screen */ - screenshot->screen = DefaultScreen(screenshot->dpy); - - /* set root window */ - screenshot->root = DefaultRootWindow(screenshot->dpy); - - /* initialize capture adaptor */ - screenshot->port = _efl_util_screenshot_get_port(screenshot->dpy, FOURCC_RGB32, screenshot->root); - EINA_SAFETY_ON_FALSE_GOTO(screenshot->port > 0, fail_init); - - /* get the best size */ - _efl_util_screenshot_get_best_size(screenshot->dpy, screenshot->port, width, height, &best_width, &best_height); - EINA_SAFETY_ON_FALSE_GOTO(best_width > 0, fail_init); - EINA_SAFETY_ON_FALSE_GOTO(best_height > 0, fail_init); - - /* set the width and the height */ - screenshot->width = best_width; - screenshot->height = best_height; - - /* create a pixmap */ - depth = DefaultDepth(screenshot->dpy, screenshot->screen); - screenshot->pixmap = XCreatePixmap(screenshot->dpy, screenshot->root, screenshot->width, screenshot->height, depth); - EINA_SAFETY_ON_FALSE_GOTO(screenshot->pixmap > 0, fail_init); - - screenshot->gc = XCreateGC(screenshot->dpy, screenshot->pixmap, 0, 0); - EINA_SAFETY_ON_NULL_GOTO(screenshot->gc, fail_init); - - XSetForeground(screenshot->dpy, screenshot->gc, 0xFF000000); - XFillRectangle(screenshot->dpy, screenshot->pixmap, screenshot->gc, 0, 0, width, height); - - /* initialize damage */ - if (!XDamageQueryExtension(screenshot->dpy, &screenshot->damage_base, &damage_err_base)) - goto fail_init; - - screenshot->damage = XDamageCreate(screenshot->dpy, screenshot->pixmap, XDamageReportNonEmpty); - EINA_SAFETY_ON_FALSE_GOTO(screenshot->damage > 0, fail_init); - - /* initialize dri3 and dri2 */ - if (!DRI2QueryExtension(screenshot->dpy, &screenshot->eventBase, &screenshot->errorBase)) - { - fprintf(stderr, "[screenshot] fail: DRI2QueryExtention\n"); - goto fail_init; - } - - if (!DRI2QueryVersion(screenshot->dpy, &screenshot->dri2Major, &screenshot->dri2Minor)) - { - fprintf(stderr, "[screenshot] fail: DRI2QueryVersion\n"); - goto fail_init; - } - - if (!DRI2Connect(screenshot->dpy, screenshot->root, &screenshot->driver_name, &screenshot->device_name)) - { - fprintf(stderr, "[screenshot] fail: DRI2Connect\n"); - goto fail_init; - } - - screenshot->drm_fd = open(screenshot->device_name, O_RDWR); - EINA_SAFETY_ON_FALSE_GOTO(screenshot->drm_fd >= 0, fail_init); - - if (drmGetMagic(screenshot->drm_fd, &screenshot->magic)) - { - fprintf(stderr, "[screenshot] fail: drmGetMagic\n"); - goto fail_init; - } - - if (!DRI2Authenticate(screenshot->dpy, screenshot->root, screenshot->magic)) - { - fprintf(stderr, "[screenshot] fail: DRI2Authenticate\n"); - goto fail_init; - } - - if (!drmAuthMagic(screenshot->drm_fd, screenshot->magic)) - { - fprintf(stderr, "[screenshot] fail: drmAuthMagic\n"); - goto fail_init; - } - - DRI2CreateDrawable(screenshot->dpy, screenshot->pixmap); - - /* tbm bufmgr */ - screenshot->bufmgr = tbm_bufmgr_init(screenshot->drm_fd); - EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init); - - XFlush(screenshot->dpy); - - g_screenshot = screenshot; - set_last_result(EFL_UTIL_ERROR_NONE); - - return g_screenshot; -#endif - -#if WAYLAND efl_util_screenshot_h screenshot = NULL; if (!_eflutil.wl.shot.screenshooter) @@ -1943,7 +1354,7 @@ efl_util_screenshot_initialize(int width, int height) screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done); return g_screenshot; -#endif + fail_param: if (screenshot) efl_util_screenshot_deinitialize(screenshot); @@ -1964,56 +1375,6 @@ fail_init: API int efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot) { -#if X11 - if (!screenshot) - return EFL_UTIL_ERROR_INVALID_PARAMETER; - - /* tbm bufmgr */ - if (screenshot->bufmgr) - tbm_bufmgr_deinit(screenshot->bufmgr); - - DRI2DestroyDrawable(screenshot->dpy, screenshot->pixmap); - - /* dri2 */ - if (screenshot->drm_fd) - close(screenshot->drm_fd); - if (screenshot->driver_name) - free(screenshot->driver_name); - if (screenshot->device_name) - free(screenshot->device_name); - - /* xv */ - if (screenshot->port > 0 && screenshot->pixmap > 0) - XvStopVideo(screenshot->dpy, screenshot->port, screenshot->pixmap); - - /* damage */ - if (screenshot->damage) - XDamageDestroy(screenshot->dpy, screenshot->damage); - - /* gc */ - if (screenshot->gc) - XFreeGC(screenshot->dpy, screenshot->gc); - - /* pixmap */ - if (screenshot->pixmap > 0) - XFreePixmap(screenshot->dpy, screenshot->pixmap); - - /* port */ - if (screenshot->port > 0) - XvUngrabPort(screenshot->dpy, screenshot->port, 0); - - XSync(screenshot->dpy, False); - - /* dpy */ - if (screenshot->internal_display ==1 && screenshot->dpy) - XCloseDisplay(screenshot->dpy); - - free(screenshot); - g_screenshot = NULL; - - return EFL_UTIL_ERROR_NONE; -#endif -#if WAYLAND if (!screenshot) return EFL_UTIL_ERROR_INVALID_PARAMETER; @@ -2024,147 +1385,12 @@ efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot) screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, NULL); return EFL_UTIL_ERROR_NONE; -#endif } API tbm_surface_h efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot) { -#if X11 - XEvent ev = {0,}; - XErrorHandler old_handler = NULL; - unsigned int attachment = DRI2BufferFrontLeft; - int nbufs = 0; - DRI2Buffer *bufs = NULL; - tbm_bo t_bo = NULL; - tbm_surface_h t_surface = NULL; - int buf_width = 0; - int buf_height = 0; - tbm_surface_info_s surf_info; - int i; - - if (screenshot != g_screenshot) - { - set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER); - return NULL; - } - - /* for flush other pending requests and pending events */ - XSync(screenshot->dpy, 0); - - g_efl_util_x_error_caught = False; - old_handler = XSetErrorHandler(_efl_util_screenshot_x_error_handle); - - /* dump here */ - XvPutStill(screenshot->dpy, screenshot->port, screenshot->pixmap, screenshot->gc, - 0, 0, screenshot->width, screenshot->height, - 0, 0, screenshot->width, screenshot->height); - - XSync(screenshot->dpy, 0); - - if (g_efl_util_x_error_caught) - { - g_efl_util_x_error_caught = False; - XSetErrorHandler(old_handler); - goto fail; - } - - g_efl_util_x_error_caught = False; - XSetErrorHandler(old_handler); - - if (XPending(screenshot->dpy)) - XNextEvent(screenshot->dpy, &ev); - else - { - int fd = ConnectionNumber(screenshot->dpy); - fd_set mask; - struct timeval tv; - int ret; - - FD_ZERO(&mask); - FD_SET(fd, &mask); - - tv.tv_usec = 0; - tv.tv_sec = TIMEOUT_CAPTURE; - - ret = select(fd + 1, &mask, 0, 0, &tv); - if (ret < 0) - fprintf(stderr, "[screenshot] fail: select.\n"); - else if (ret == 0) - fprintf(stderr, "[screenshot] fail: timeout(%d sec)!\n", TIMEOUT_CAPTURE); - else if (XPending(screenshot->dpy)) - XNextEvent(screenshot->dpy, &ev); - else - fprintf(stderr, "[screenshot] fail: not passed a event!\n"); - } - - /* check if the capture is done by xserver and pixmap has got the captured image */ - if (ev.type == (screenshot->damage_base + XDamageNotify)) - { - XDamageNotifyEvent *damage_ev = (XDamageNotifyEvent *)&ev; - if (damage_ev->drawable == screenshot->pixmap) - { - /* Get DRI2 FrontLeft buffer of the pixmap */ - bufs = DRI2GetBuffers(screenshot->dpy, screenshot->pixmap, &buf_width, &buf_height, &attachment, 1, &nbufs); - if (!bufs) - { - fprintf(stderr, "[screenshot] fail: DRI2GetBuffers\n"); - goto fail; - } - - t_bo = tbm_bo_import(screenshot->bufmgr, bufs[0].name); - if (!t_bo) - { - fprintf(stderr, "[screenshot] fail: import tbm_bo!\n"); - goto fail; - } - - surf_info.width = buf_width; - surf_info.height = buf_height; - surf_info.format = TBM_FORMAT_XRGB8888; - surf_info.bpp = 32; - surf_info.size = bufs->pitch * surf_info.height; - surf_info.num_planes = 1; - for (i = 0; i < surf_info.num_planes; i++) - { - surf_info.planes[i].size = bufs->pitch * surf_info.height; - surf_info.planes[i].stride = bufs->pitch; - surf_info.planes[i].offset = 0; - } - t_surface = tbm_surface_internal_create_with_bos(&surf_info, &t_bo, 1); - if (!t_surface) - { - fprintf(stderr, "[screenshot] fail: get tbm_surface!\n"); - goto fail; - } - - tbm_bo_unref(t_bo); - free(bufs); - - XDamageSubtract(screenshot->dpy, screenshot->damage, None, None ); - - set_last_result(EFL_UTIL_ERROR_NONE); - - return t_surface; - } - - XDamageSubtract(screenshot->dpy, screenshot->damage, None, None ); - } - -fail: - - if (t_bo) - tbm_bo_unref(t_bo); - if (bufs) - free(bufs); - - set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL); - - return NULL; -#endif - -#if WAYLAND tbm_surface_h t_surface = NULL; struct wl_buffer *buffer = NULL; Efl_Util_Wl_Output_Info *output; @@ -2225,5 +1451,4 @@ fail: set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL); return NULL; -#endif } -- 2.7.4