2 * Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #define LOG_TAG "TIZEN_N_EFL_UTIL"
24 #include <sys/types.h>
28 #include <tbm_bufmgr.h>
29 #include <tbm_surface.h>
30 #include <tbm_surface_internal.h>
31 #include <Elementary.h>
32 #include <Ecore_Evas.h>
36 #include <X11/extensions/Xvlib.h>
37 #include <X11/extensions/Xvproto.h>
38 #include <X11/extensions/Xdamage.h>
42 #endif /* end of X11 */
45 #include <Ecore_Wayland.h>
46 #include <wayland-client.h>
47 #include <tizen-extension-client-protocol.h>
48 #include <screenshooter-client-protocol.h>
49 #endif /* end of WAYLAND */
51 /* callback handler index */
52 #define CBH_NOTI_LEV 0
53 #define CBH_SCR_MODE 1
56 typedef void (*Efl_Util_Cb)(Evas_Object *, int, void *);
58 typedef struct _Efl_Util_Callback_Info
63 } Efl_Util_Callback_Info;
66 typedef struct _Efl_Util_Wl_Surface_Lv_Info
68 void *surface; /* wl_surface */
70 Eina_Bool wait_for_done;
71 } Efl_Util_Wl_Surface_Lv_Info;
73 typedef struct _Efl_Util_Wl_Surface_Scr_Mode_Info
75 void *surface; /* wl_surface */
77 Eina_Bool wait_for_done;
78 } Efl_Util_Wl_Surface_Scr_Mode_Info;
80 typedef struct _Efl_Util_Wl_Output_Info
82 struct wl_output *output;
83 int offset_x, offset_y, width, height;
84 } Efl_Util_Wl_Output_Info;
87 typedef struct _Efl_Util_Data
90 /* x11 related stuffs */
94 Ecore_Event_Handler *handler; /* x11 client message handler */
97 #endif /* end of X11 */
100 /* wayland related stuffs */
104 struct wl_display *dpy;
108 struct tizen_policy *proto;
109 Eina_Hash *hash_noti_lv;
110 Eina_Hash *hash_scr_mode;
114 struct screenshooter *screenshooter;
115 struct tizen_buffer_pool *buffer_pool;
116 Eina_List *output_list;
119 #endif /* end of WAYLAND */
123 Eina_List *info_list; /* list of callback info */
124 unsigned int atom; /* x11 atom */
125 } cb_handler[CBH_MAX];
128 static Efl_Util_Data _eflutil =
136 #endif /* end of X11 */
141 { NULL, NULL, NULL }, /* tizen_policy protocol */
142 { NULL, NULL, NULL } /* screenshooter protocol */
144 #endif /* end of WAYLAND */
146 { NULL, 0 }, /* handler for notification level */
147 { NULL, 0 } /* handler for screen mode */
151 static Eina_Bool _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, void *data, int idx);
152 static Eina_Bool _cb_info_del_by_win(Evas_Object *win, int idx);
153 static Eina_List *_cb_info_list_get(int idx);
154 static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx);
156 static Efl_Util_Callback_Info *_cb_info_find_by_xwin(unsigned int xwin, int idx);
157 static Eina_Bool _cb_x11_client_msg(void *data, int type, void *event);
158 static Eina_Bool _x11_init(void);
159 #endif /* end of X11 */
161 static Eina_Bool _wl_init(void);
162 static void _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
163 static void _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name);
164 static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx);
165 static void _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t is_conformant);
166 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);
167 static void _cb_wl_tz_policy_notification_done(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, int32_t level, uint32_t state);
168 static void _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id);
169 static void _cb_wl_tz_policy_scr_mode_done(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t mode, uint32_t state);
171 static const struct wl_registry_listener _wl_reg_listener =
174 _cb_wl_reg_global_remove
177 struct tizen_policy_listener _wl_tz_policy_listener =
179 _cb_wl_tz_policy_conformant,
180 _cb_wl_tz_policy_conformant_area,
181 _cb_wl_tz_policy_notification_done,
182 _cb_wl_tz_policy_transient_for_done,
183 _cb_wl_tz_policy_scr_mode_done
185 #endif /* end of WAYLAND */
188 _cb_info_add(Evas_Object *win,
193 Efl_Util_Callback_Info *info;
195 info = _cb_info_find_by_win(win, idx);
198 _eflutil.cb_handler[idx].info_list
199 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
204 info = (Efl_Util_Callback_Info *)calloc(1, sizeof(Efl_Util_Callback_Info));
205 if (!info) return EINA_FALSE;
211 _eflutil.cb_handler[idx].info_list
212 = eina_list_append(_eflutil.cb_handler[idx].info_list,
216 if (!_eflutil.x11.handler)
217 _eflutil.x11.handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
220 #endif /* end of X11 */
226 _cb_info_del_by_win(Evas_Object *win,
229 Efl_Util_Callback_Info *info;
231 info = _cb_info_find_by_win(win, idx);
232 if (!info) return EINA_FALSE;
234 _eflutil.cb_handler[idx].info_list
235 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
240 unsigned int count = eina_list_count(_eflutil.cb_handler[idx].info_list);
241 if ((count == 0) && (_eflutil.x11.handler))
243 ecore_event_handler_del(_eflutil.x11.handler);
244 _eflutil.x11.handler = NULL;
252 _cb_info_list_get(int idx)
254 return _eflutil.cb_handler[idx].info_list;
257 static Efl_Util_Callback_Info *
258 _cb_info_find_by_win(Evas_Object *win,
262 Efl_Util_Callback_Info *info;
264 l = _cb_info_list_get(idx);
265 EINA_LIST_FOREACH(l, ll, info)
267 if (info->win == win) return info;
274 static Efl_Util_Callback_Info *
275 _cb_info_find_by_xwin(unsigned int xwin,
279 Efl_Util_Callback_Info *info;
282 l = _cb_info_list_get(idx);
283 EINA_LIST_FOREACH(l, ll, info)
285 xwin2 = elm_win_xwindow_get(info->win);
286 if (xwin == xwin2) return info;
293 _cb_x11_client_msg(void *data,
297 Ecore_X_Event_Client_Message *ev;
299 Efl_Util_Callback_Info *info;
302 if (!ev) return ECORE_CALLBACK_PASS_ON;
305 if (xwin == 0) return ECORE_CALLBACK_PASS_ON;
307 if (ev->message_type == _eflutil.cb_handler[CBH_NOTI_LEV].atom)
309 info = _cb_info_find_by_xwin(xwin, CBH_NOTI_LEV);
311 /* permission denied */
312 if ((ev->data.l[1] == 0) &&
317 EFL_UTIL_ERROR_PERMISSION_DENIED,
321 else if (ev->message_type == _eflutil.cb_handler[CBH_SCR_MODE].atom)
323 info = _cb_info_find_by_xwin(xwin, CBH_SCR_MODE);
325 /* permission denied */
326 if ((ev->data.l[1] == 0) &&
331 EFL_UTIL_ERROR_PERMISSION_DENIED,
335 return ECORE_CALLBACK_PASS_ON;
341 if (_eflutil.x11.init) return EINA_TRUE;
343 _eflutil.x11.dpy = ecore_x_display_get();
344 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.x11.dpy, EINA_FALSE);
346 _eflutil.x11.init = EINA_TRUE;
350 #endif /* end of X11 */
356 struct wl_registry *reg;
358 if (_eflutil.wl.init) return EINA_TRUE;
362 _eflutil.wl.dpy = ecore_wl_display_get();
363 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.dpy, EINA_FALSE);
365 reg = wl_display_get_registry(_eflutil.wl.dpy);
366 EINA_SAFETY_ON_NULL_RETURN_VAL(reg, EINA_FALSE);
368 wl_registry_add_listener(reg, &_wl_reg_listener, NULL);
370 _eflutil.wl.init = EINA_TRUE;
376 _cb_wl_output_geometry(void *data, struct wl_output *wl_output, int x, int y,
377 int physical_width, int physical_height, int subpixel,
378 const char *make, const char *model, int transform)
380 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
381 if (wl_output == output->output)
383 output->offset_x = x;
384 output->offset_y = y;
389 _cb_wl_output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
390 int width, int height, int refresh)
392 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
393 if (wl_output == output->output && (flags & WL_OUTPUT_MODE_CURRENT))
395 output->width = width;
396 output->height = height;
401 _cb_wl_output_done(void *data, struct wl_output *wl_output)
406 _cb_wl_output_scale(void *data, struct wl_output *wl_output, int32_t factor)
410 static const struct wl_output_listener output_listener =
412 _cb_wl_output_geometry,
419 _cb_wl_screenshot_done(void *data, struct screenshooter *screenshooter)
421 Eina_Bool *shot_done = (Eina_Bool*)data;
423 *shot_done = EINA_TRUE;
426 static const struct screenshooter_listener screenshooter_listener =
428 _cb_wl_screenshot_done
432 _cb_wl_reg_global(void *data,
433 struct wl_registry *reg,
435 const char *interface,
436 unsigned int version)
438 if (!strcmp(interface, "tizen_policy"))
440 struct tizen_policy *proto;
441 proto = wl_registry_bind(reg,
443 &tizen_policy_interface,
447 tizen_policy_add_listener(proto,
448 &_wl_tz_policy_listener,
451 _eflutil.wl.policy.hash_noti_lv = eina_hash_pointer_new(free);
452 _eflutil.wl.policy.hash_scr_mode = eina_hash_pointer_new(free);
453 _eflutil.wl.policy.proto = proto;
455 else if (strcmp(interface, "wl_output") == 0)
457 Efl_Util_Wl_Output_Info *output = calloc(1, sizeof(Efl_Util_Wl_Output_Info));
458 EINA_SAFETY_ON_NULL_RETURN(output);
460 _eflutil.wl.shot.output_list = eina_list_append(_eflutil.wl.shot.output_list, output);
462 output->output = wl_registry_bind(reg, name, &wl_output_interface, version);
463 wl_output_add_listener(output->output, &output_listener, output);
465 else if (strcmp(interface, "tizen_buffer_pool") == 0)
467 _eflutil.wl.shot.buffer_pool = wl_registry_bind(reg, name, &tizen_buffer_pool_interface, 1);
469 else if (strcmp(interface, "screenshooter") == 0)
471 _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version);
472 screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL);
477 _cb_wl_reg_global_remove(void *data,
478 struct wl_registry *reg,
481 _eflutil.wl.policy.proto = NULL;
482 eina_hash_free(_eflutil.wl.policy.hash_noti_lv);
483 eina_hash_free(_eflutil.wl.policy.hash_scr_mode);
486 static Efl_Util_Callback_Info *
487 _cb_info_find_by_wlsurf(void *wlsurf,
491 Efl_Util_Callback_Info *info;
492 Ecore_Wl_Window *wlwin2 = NULL;
493 void *wlsurf2 = NULL;
495 l = _cb_info_list_get(idx);
496 EINA_LIST_FOREACH(l, ll, info)
498 wlwin2 = elm_win_wl_window_get(info->win);
499 wlsurf2 = ecore_wl_window_surface_get(wlwin2);
500 if (wlsurf== wlsurf2) return info;
507 _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy,
508 struct wl_surface *surface, uint32_t is_conformant)
513 _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy,
514 struct wl_surface *surface, uint32_t conformant_part,
515 uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h)
520 _cb_wl_tz_policy_notification_done(void *data,
521 struct tizen_policy *tizen_policy,
522 struct wl_surface *surface,
526 Efl_Util_Wl_Surface_Lv_Info *lv_info;
527 Efl_Util_Callback_Info *cb_info;
529 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
532 lv_info->level = level;
533 lv_info->wait_for_done = EINA_FALSE;
536 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
538 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_NOTI_LEV);
539 if (!cb_info) return;
540 if (!cb_info->cb) return;
542 cb_info->cb(cb_info->win,
543 EFL_UTIL_ERROR_PERMISSION_DENIED,
548 _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id)
553 _cb_wl_tz_policy_scr_mode_done(void *data,
554 struct tizen_policy *tizen_policy,
555 struct wl_surface *surface,
560 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
561 Efl_Util_Callback_Info *cb_info;
563 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
566 scr_mode_info->mode = mode;
567 scr_mode_info->wait_for_done = EINA_FALSE;
570 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
572 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_SCR_MODE);
573 if (!cb_info) return;
574 if (!cb_info->cb) return;
576 cb_info->cb(cb_info->win,
577 EFL_UTIL_ERROR_PERMISSION_DENIED,
580 #endif /* end of WAYLAND */
583 efl_util_set_notification_window_level(Evas_Object *window,
584 efl_util_notification_level_e level)
588 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
589 EINA_SAFETY_ON_FALSE_RETURN_VAL((level >= EFL_UTIL_NOTIFICATION_LEVEL_1) &&
590 (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP),
591 EFL_UTIL_ERROR_INVALID_PARAMETER);
594 Ecore_X_Window_Type window_type;
598 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
600 xwin = elm_win_xwindow_get(window);
603 if (ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
605 // success to get window type
606 if (window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
608 // given EFL window's type is not notification type.
609 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
613 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
615 utilx_set_system_notification_level(_eflutil.x11.dpy,
618 return EFL_UTIL_ERROR_NONE;
620 #endif /* end of X11 */
624 Ecore_Wl_Window *wlwin;
625 struct wl_surface *surface;
626 Efl_Util_Wl_Surface_Lv_Info *lv_info;
629 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
631 type = elm_win_type_get(window);
632 EINA_SAFETY_ON_FALSE_RETURN_VAL((type == ELM_WIN_NOTIFICATION),
633 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
635 wlwin = elm_win_wl_window_get(window);
638 while (!_eflutil.wl.policy.proto)
639 wl_display_dispatch(_eflutil.wl.dpy);
641 surface = ecore_wl_window_surface_get(wlwin);
642 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
643 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
645 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
648 lv_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Lv_Info));
649 EINA_SAFETY_ON_NULL_RETURN_VAL(lv_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
651 lv_info->surface = surface;
652 lv_info->level = (int)level;
653 lv_info->wait_for_done = EINA_TRUE;
655 eina_hash_add(_eflutil.wl.policy.hash_noti_lv,
661 lv_info->level = (int)level;
662 lv_info->wait_for_done = EINA_TRUE;
665 tizen_policy_set_notification_level(_eflutil.wl.policy.proto,
666 surface, (int)level);
668 return EFL_UTIL_ERROR_NONE;
670 #endif /* end of WAYLAND */
672 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
676 efl_util_get_notification_window_level(Evas_Object *window,
677 efl_util_notification_level_e *level)
681 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
682 EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER);
685 Ecore_X_Window_Type window_type;
686 Utilx_Notification_Level utilx_level;
690 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
692 xwin = elm_win_xwindow_get(window);
695 if (ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
697 // success to get window type
698 if (window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
700 // given EFL window's type is not notification type.
701 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
704 utilx_level = utilx_get_system_notification_level(_eflutil.x11.dpy, xwin);
705 if (utilx_level == UTILX_NOTIFICATION_LEVEL_LOW)
706 *level = EFL_UTIL_NOTIFICATION_LEVEL_1;
707 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_NORMAL)
708 *level = EFL_UTIL_NOTIFICATION_LEVEL_2;
709 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_HIGH)
710 *level = EFL_UTIL_NOTIFICATION_LEVEL_3;
712 return EFL_UTIL_ERROR_INVALID_PARAMETER;
715 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
717 return EFL_UTIL_ERROR_NONE;
719 #endif /* end of X11 */
723 Ecore_Wl_Window *wlwin;
724 struct wl_surface *surface;
725 Efl_Util_Wl_Surface_Lv_Info *lv_info;
728 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
730 type = elm_win_type_get(window);
731 EINA_SAFETY_ON_FALSE_RETURN_VAL((type == ELM_WIN_NOTIFICATION),
732 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
734 wlwin = elm_win_wl_window_get(window);
737 while (!_eflutil.wl.policy.proto)
738 wl_display_dispatch(_eflutil.wl.dpy);
740 surface = ecore_wl_window_surface_get(wlwin);
741 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
742 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
744 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
747 if (lv_info->wait_for_done)
749 if (ecore_wl_window_shell_surface_get(wlwin) ||
750 ecore_wl_window_xdg_surface_get(wlwin))
752 while (lv_info->wait_for_done)
755 wl_display_dispatch(_eflutil.wl.dpy);
760 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
761 return EFL_UTIL_ERROR_INVALID_PARAMETER;
765 switch (lv_info->level)
767 case TIZEN_POLICY_LEVEL_1: *level = EFL_UTIL_NOTIFICATION_LEVEL_1; break;
768 case TIZEN_POLICY_LEVEL_2: *level = EFL_UTIL_NOTIFICATION_LEVEL_2; break;
769 case TIZEN_POLICY_LEVEL_3: *level = EFL_UTIL_NOTIFICATION_LEVEL_3; break;
770 case TIZEN_POLICY_LEVEL_NONE: *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE; break;
771 case TIZEN_POLICY_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break;
772 case TIZEN_POLICY_LEVEL_MEDIUM: *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM; break;
773 case TIZEN_POLICY_LEVEL_HIGH: *level = EFL_UTIL_NOTIFICATION_LEVEL_HIGH; break;
774 case TIZEN_POLICY_LEVEL_TOP: *level = EFL_UTIL_NOTIFICATION_LEVEL_TOP; break;
775 default: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
776 return EFL_UTIL_ERROR_INVALID_PARAMETER;
778 return EFL_UTIL_ERROR_NONE;
781 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
783 return EFL_UTIL_ERROR_NONE;
785 #endif /* end of WAYLAND */
786 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
790 efl_util_set_notification_window_level_error_cb(Evas_Object *window,
791 efl_util_notification_window_level_error_cb callback,
794 Eina_Bool ret = EINA_FALSE;
796 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
797 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
799 ret = _cb_info_add(window,
800 (Efl_Util_Cb)callback,
803 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
806 if (!_eflutil.cb_handler[CBH_NOTI_LEV].atom)
807 _eflutil.cb_handler[CBH_NOTI_LEV].atom = ecore_x_atom_get("_E_NOTIFICATION_LEVEL_ACCESS_RESULT");
808 #endif /* end of X11 */
810 return EFL_UTIL_ERROR_NONE;
814 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
816 Eina_Bool ret = EINA_FALSE;
818 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
820 ret = _cb_info_del_by_win(window, CBH_NOTI_LEV);
821 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
823 return EFL_UTIL_ERROR_NONE;
827 efl_util_set_window_opaque_state(Evas_Object *window,
832 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
833 EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)),
834 EFL_UTIL_ERROR_INVALID_PARAMETER);
838 Utilx_Opaque_State state;
842 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
844 xwin = elm_win_xwindow_get(window);
845 EINA_SAFETY_ON_FALSE_RETURN_VAL(xwin > 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
848 state = UTILX_OPAQUE_STATE_ON;
850 state = UTILX_OPAQUE_STATE_OFF;
852 ret = utilx_set_window_opaque_state(_eflutil.x11.dpy,
857 return EFL_UTIL_ERROR_INVALID_PARAMETER;
859 return EFL_UTIL_ERROR_NONE;
860 #endif /* end of X11 */
863 Ecore_Wl_Window *wlwin;
867 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
869 wlwin = elm_win_wl_window_get(window);
872 evas_object_geometry_get(window, &x, &y, &w, &h);
875 ecore_wl_window_opaque_region_set(wlwin, x, y, w, h);
877 ecore_wl_window_opaque_region_set(wlwin, 0, 0, 0, 0);
879 return EFL_UTIL_ERROR_NONE;
882 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
883 #endif /* end of WAYLAND */
887 efl_util_set_window_screen_mode(Evas_Object *window,
888 efl_util_screen_mode_e mode)
890 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
891 EINA_SAFETY_ON_FALSE_RETURN_VAL(((mode >= EFL_UTIL_SCREEN_MODE_DEFAULT) &&
892 (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)),
893 EFL_UTIL_ERROR_INVALID_PARAMETER);
900 e = evas_object_evas_get(window);
901 EINA_SAFETY_ON_NULL_RETURN_VAL(e, EFL_UTIL_ERROR_INVALID_PARAMETER);
903 ee = ecore_evas_ecore_evas_get(e);
904 EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EFL_UTIL_ERROR_INVALID_PARAMETER);
906 id = ecore_evas_aux_hint_id_get(ee, "wm.policy.win.lcd.lock");
907 if (mode == EFL_UTIL_SCREEN_MODE_ALWAYS_ON)
910 ecore_evas_aux_hint_add(ee, "wm.policy.win.lcd.lock", "1");
912 ecore_evas_aux_hint_val_set(ee, id, "1");
914 else if (mode == EFL_UTIL_SCREEN_MODE_DEFAULT)
917 ecore_evas_aux_hint_add(ee, "wm.policy.win.lcd.lock", "0");
919 ecore_evas_aux_hint_val_set(ee, id, "0");
922 return EFL_UTIL_ERROR_INVALID_PARAMETER;
924 return EFL_UTIL_ERROR_NONE;
925 #endif /* end of X11 */
928 Ecore_Wl_Window *wlwin;
929 struct wl_surface *surface;
930 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
934 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
936 wlwin = elm_win_wl_window_get(window);
939 while (!_eflutil.wl.policy.proto)
940 wl_display_dispatch(_eflutil.wl.dpy);
942 surface = ecore_wl_window_surface_get(wlwin);
943 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
944 EFL_UTIL_ERROR_INVALID_PARAMETER);
946 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
949 scr_mode_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Scr_Mode_Info));
950 EINA_SAFETY_ON_NULL_RETURN_VAL(scr_mode_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
952 scr_mode_info->surface = surface;
953 scr_mode_info->mode = (unsigned int)mode;
954 scr_mode_info->wait_for_done = EINA_TRUE;
956 eina_hash_add(_eflutil.wl.policy.hash_scr_mode,
962 scr_mode_info->mode = (unsigned int)mode;
963 scr_mode_info->wait_for_done = EINA_TRUE;
966 tizen_policy_set_window_screen_mode(_eflutil.wl.policy.proto,
967 surface, (unsigned int)mode);
969 return EFL_UTIL_ERROR_NONE;
972 return EFL_UTIL_ERROR_INVALID_PARAMETER;
973 #endif /* end of WAYLAND */
977 efl_util_get_window_screen_mode(Evas_Object *window,
978 efl_util_screen_mode_e *mode)
980 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
981 EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER);
989 e = evas_object_evas_get(window);
990 EINA_SAFETY_ON_NULL_RETURN_VAL(e, EFL_UTIL_ERROR_INVALID_PARAMETER);
992 ee = ecore_evas_ecore_evas_get(e);
993 EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EFL_UTIL_ERROR_INVALID_PARAMETER);
995 id = ecore_evas_aux_hint_id_get(ee, "wm.policy.win.lcd.lock");
996 EINA_SAFETY_ON_TRUE_RETURN_VAL((id == -1), EFL_UTIL_ERROR_INVALID_PARAMETER);
998 str = ecore_evas_aux_hint_val_get(ee, id);
999 EINA_SAFETY_ON_NULL_RETURN_VAL(str, EFL_UTIL_ERROR_INVALID_PARAMETER);
1001 if (strncmp(str, "1", strlen("1")) == 0)
1002 *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON;
1004 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1006 return EFL_UTIL_ERROR_NONE;
1007 #endif /* end of X11 */
1010 Ecore_Wl_Window *wlwin;
1011 struct wl_surface *surface;
1012 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
1016 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1018 wlwin = elm_win_wl_window_get(window);
1021 while (!_eflutil.wl.policy.proto)
1022 wl_display_dispatch(_eflutil.wl.dpy);
1024 surface = ecore_wl_window_surface_get(wlwin);
1025 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1026 EFL_UTIL_ERROR_INVALID_PARAMETER);
1028 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
1031 if (scr_mode_info->wait_for_done)
1033 while (scr_mode_info->wait_for_done)
1036 wl_display_dispatch(_eflutil.wl.dpy);
1040 switch (scr_mode_info->mode)
1042 case TIZEN_POLICY_MODE_DEFAULT: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT; break;
1043 case TIZEN_POLICY_MODE_ALWAYS_ON: *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON; break;
1044 default: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1045 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1047 return EFL_UTIL_ERROR_NONE;
1051 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1052 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1056 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1057 #endif /* end of WAYLAND */
1061 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
1062 efl_util_window_screen_mode_error_cb callback,
1065 Eina_Bool ret = EINA_FALSE;
1067 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1068 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
1070 ret = _cb_info_add(window,
1071 (Efl_Util_Cb)callback,
1074 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1077 if (!_eflutil.cb_handler[CBH_SCR_MODE].atom)
1078 _eflutil.cb_handler[CBH_SCR_MODE].atom = ecore_x_atom_get("_E_SCREEN_MODE_ACCESS_RESULT");
1079 #endif /* end of X11 */
1081 return EFL_UTIL_ERROR_NONE;
1085 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
1087 Eina_Bool ret = EINA_FALSE;
1089 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1091 ret = _cb_info_del_by_win(window, CBH_SCR_MODE);
1092 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1094 return EFL_UTIL_ERROR_NONE;
1098 efl_util_input_initialize_generator(efl_util_input_device_type_e dev_type)
1100 return EFL_UTIL_ERROR_NONE;
1104 efl_util_input_deinitialize_generator(void)
1110 efl_util_input_generate_key(const char *key_name,
1113 return EFL_UTIL_ERROR_NONE;
1117 efl_util_input_generate_touch(int idx,
1118 efl_util_input_touch_type_e touch_type,
1122 return EFL_UTIL_ERROR_NONE;
1125 struct _efl_util_screenshot_h
1131 Ecore_X_Display *dpy;
1132 int internal_display;
1147 int eventBase, errorBase;
1148 int dri2Major, dri2Minor;
1149 char *driver_name, *device_name;
1156 Eina_Bool shot_done;
1162 /* scrrenshot handle */
1163 static efl_util_screenshot_h g_screenshot;
1166 #define FOURCC(a,b,c,d) (((unsigned)d&0xff)<<24 | ((unsigned)c&0xff)<<16 | ((unsigned)b&0xff)<<8 | ((unsigned)a&0xff))
1167 #define FOURCC_RGB32 FOURCC('R','G','B','4')
1168 #define TIMEOUT_CAPTURE 3
1170 /* x error handling */
1171 static Bool g_efl_util_x_error_caught;
1174 _efl_util_screenshot_x_error_handle(Display *dpy, XErrorEvent *ev)
1176 if (!g_screenshot || (dpy != g_screenshot->dpy))
1179 g_efl_util_x_error_caught = True;
1185 _efl_util_screenshot_get_port(Display *dpy, unsigned int id, Window win)
1187 unsigned int ver, rev, req_base, evt_base, err_base;
1188 unsigned int adaptors;
1189 XvAdaptorInfo *ai = NULL;
1190 XvImageFormatValues *fo = NULL;
1194 if (XvQueryExtension(dpy, &ver, &rev, &req_base, &evt_base, &err_base) != Success)
1196 fprintf(stderr, "[screenshot] fail: no XV extension. \n");
1200 if (XvQueryAdaptors(dpy, win, &adaptors, &ai) != Success)
1202 fprintf(stderr, "[screenshot] fail: query adaptors. \n");
1206 EINA_SAFETY_ON_NULL_RETURN_VAL(ai, -1);
1208 for (i = 0; i < adaptors; i++)
1210 int support_format = False;
1212 if (!(ai[i].type & XvInputMask) ||
1213 !(ai[i].type & XvStillMask))
1218 fo = XvListImageFormats(dpy, p, &formats);
1219 for (j = 0; j < formats; j++)
1220 if (fo[j].id == (int)id)
1221 support_format = True;
1226 if (!support_format)
1229 for (; p < ai[i].base_id + ai[i].num_ports; p++)
1231 if (XvGrabPort(dpy, p, 0) == Success)
1233 XvFreeAdaptorInfo(ai);
1239 XvFreeAdaptorInfo(ai);
1246 static int _efl_util_screenshot_get_best_size(Display *dpy, int port, int width, int height, unsigned int *best_width, unsigned int *best_height)
1248 XErrorHandler old_handler = NULL;
1250 Atom atom_capture = XInternAtom(dpy, "_USER_WM_PORT_ATTRIBUTE_CAPTURE", False);
1252 g_efl_util_x_error_caught = False;
1253 old_handler = XSetErrorHandler(_efl_util_screenshot_x_error_handle);
1255 XvSetPortAttribute(dpy, port, atom_capture, 1);
1258 g_efl_util_x_error_caught = False;
1259 XSetErrorHandler(old_handler);
1261 XvQueryBestSize(dpy, port, 0, 0, 0, width, height, best_width, best_height);
1262 if (best_width <= 0 || best_height <= 0)
1269 API efl_util_screenshot_h efl_util_screenshot_initialize(int width, int height)
1272 efl_util_screenshot_h screenshot = NULL;
1274 int damage_err_base = 0;
1275 unsigned int best_width = 0;
1276 unsigned int best_height = 0;
1278 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1279 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1281 if (g_screenshot != NULL)
1283 if (g_screenshot->width != width || g_screenshot->height != height)
1285 // TODO: recreate pixmap and update information
1286 if (!_efl_util_screenshot_get_best_size(screenshot->dpy, screenshot->port, width, height, &best_width, &best_height))
1288 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1292 g_screenshot->width = width;
1293 g_screenshot->height = height;
1296 return g_screenshot;
1299 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1300 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1303 screenshot->dpy = ecore_x_display_get();
1304 if (!screenshot->dpy)
1306 screenshot->dpy = XOpenDisplay(0);
1307 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_init);
1309 /* for XCloseDisplay at denitialization */
1310 screenshot->internal_display = 1;
1314 screenshot->screen = DefaultScreen(screenshot->dpy);
1316 /* set root window */
1317 screenshot->root = DefaultRootWindow(screenshot->dpy);
1319 /* initialize capture adaptor */
1320 screenshot->port = _efl_util_screenshot_get_port(screenshot->dpy, FOURCC_RGB32, screenshot->root);
1321 EINA_SAFETY_ON_FALSE_GOTO(screenshot->port > 0, fail_init);
1323 /* get the best size */
1324 _efl_util_screenshot_get_best_size(screenshot->dpy, screenshot->port, width, height, &best_width, &best_height);
1325 EINA_SAFETY_ON_FALSE_GOTO(best_width > 0, fail_init);
1326 EINA_SAFETY_ON_FALSE_GOTO(best_height > 0, fail_init);
1328 /* set the width and the height */
1329 screenshot->width = best_width;
1330 screenshot->height = best_height;
1332 /* create a pixmap */
1333 depth = DefaultDepth(screenshot->dpy, screenshot->screen);
1334 screenshot->pixmap = XCreatePixmap(screenshot->dpy, screenshot->root, screenshot->width, screenshot->height, depth);
1335 EINA_SAFETY_ON_FALSE_GOTO(screenshot->pixmap > 0, fail_init);
1337 screenshot->gc = XCreateGC(screenshot->dpy, screenshot->pixmap, 0, 0);
1338 EINA_SAFETY_ON_NULL_GOTO(screenshot->gc, fail_init);
1340 XSetForeground(screenshot->dpy, screenshot->gc, 0xFF000000);
1341 XFillRectangle(screenshot->dpy, screenshot->pixmap, screenshot->gc, 0, 0, width, height);
1343 /* initialize damage */
1344 if (!XDamageQueryExtension(screenshot->dpy, &screenshot->damage_base, &damage_err_base))
1347 screenshot->damage = XDamageCreate(screenshot->dpy, screenshot->pixmap, XDamageReportNonEmpty);
1348 EINA_SAFETY_ON_FALSE_GOTO(screenshot->damage > 0, fail_init);
1350 /* initialize dri3 and dri2 */
1351 if (!DRI2QueryExtension(screenshot->dpy, &screenshot->eventBase, &screenshot->errorBase))
1353 fprintf(stderr, "[screenshot] fail: DRI2QueryExtention\n");
1357 if (!DRI2QueryVersion(screenshot->dpy, &screenshot->dri2Major, &screenshot->dri2Minor))
1359 fprintf(stderr, "[screenshot] fail: DRI2QueryVersion\n");
1363 if (!DRI2Connect(screenshot->dpy, screenshot->root, &screenshot->driver_name, &screenshot->device_name))
1365 fprintf(stderr, "[screenshot] fail: DRI2Connect\n");
1369 screenshot->drm_fd = open(screenshot->device_name, O_RDWR);
1370 EINA_SAFETY_ON_FALSE_GOTO(screenshot->drm_fd >= 0, fail_init);
1372 if (drmGetMagic(screenshot->drm_fd, &screenshot->magic))
1374 fprintf(stderr, "[screenshot] fail: drmGetMagic\n");
1378 if (!DRI2Authenticate(screenshot->dpy, screenshot->root, screenshot->magic))
1380 fprintf(stderr, "[screenshot] fail: DRI2Authenticate\n");
1384 if (!drmAuthMagic(screenshot->drm_fd, screenshot->magic))
1386 fprintf(stderr, "[screenshot] fail: drmAuthMagic\n");
1390 DRI2CreateDrawable(screenshot->dpy, screenshot->pixmap);
1393 screenshot->bufmgr = tbm_bufmgr_init(screenshot->drm_fd);
1394 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1396 XFlush(screenshot->dpy);
1398 g_screenshot = screenshot;
1399 set_last_result(EFL_UTIL_ERROR_NONE);
1401 return g_screenshot;
1405 efl_util_screenshot_h screenshot = NULL;
1407 if (!_eflutil.wl.shot.screenshooter)
1411 while (!_eflutil.wl.shot.screenshooter && ret != -1)
1412 ret = wl_display_dispatch(_eflutil.wl.dpy);
1413 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init);
1414 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.buffer_pool, fail_init);
1417 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1418 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1422 if (g_screenshot->width != width || g_screenshot->height != height)
1424 g_screenshot->width = width;
1425 g_screenshot->height = height;
1428 return g_screenshot;
1431 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1432 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1434 screenshot->width = width;
1435 screenshot->height = height;
1437 screenshot->bufmgr = tbm_bufmgr_init(-1);
1438 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1440 g_screenshot = screenshot;
1441 set_last_result(EFL_UTIL_ERROR_NONE);
1443 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
1445 return g_screenshot;
1449 efl_util_screenshot_deinitialize(screenshot);
1450 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1454 efl_util_screenshot_deinitialize(screenshot);
1455 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1459 efl_util_screenshot_deinitialize(screenshot);
1460 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1464 API int efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
1468 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1471 if (screenshot->bufmgr)
1472 tbm_bufmgr_deinit(screenshot->bufmgr);
1474 DRI2DestroyDrawable(screenshot->dpy, screenshot->pixmap);
1477 if (screenshot->drm_fd)
1478 close(screenshot->drm_fd);
1479 if (screenshot->driver_name)
1480 free(screenshot->driver_name);
1481 if (screenshot->device_name)
1482 free(screenshot->device_name);
1485 if (screenshot->port > 0 && screenshot->pixmap > 0)
1486 XvStopVideo(screenshot->dpy, screenshot->port, screenshot->pixmap);
1489 if (screenshot->damage)
1490 XDamageDestroy(screenshot->dpy, screenshot->damage);
1494 XFreeGC(screenshot->dpy, screenshot->gc);
1497 if (screenshot->pixmap > 0)
1498 XFreePixmap(screenshot->dpy, screenshot->pixmap);
1501 if (screenshot->port > 0)
1502 XvUngrabPort(screenshot->dpy, screenshot->port, 0);
1504 XSync(screenshot->dpy, False);
1507 if (screenshot->internal_display ==1 && screenshot->dpy)
1508 XCloseDisplay(screenshot->dpy);
1511 g_screenshot = NULL;
1513 return EFL_UTIL_ERROR_NONE;
1517 return EFL_UTIL_ERROR_NONE;
1519 if (screenshot->bufmgr)
1520 tbm_bufmgr_deinit(screenshot->bufmgr);
1523 g_screenshot = NULL;
1525 if (_eflutil.wl.shot.screenshooter)
1526 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, NULL);
1528 return EFL_UTIL_ERROR_NONE;
1533 API tbm_surface_h efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
1537 XErrorHandler old_handler = NULL;
1538 unsigned int attachment = DRI2BufferFrontLeft;
1540 DRI2Buffer *bufs = NULL;
1542 tbm_surface_h t_surface = NULL;
1545 tbm_surface_info_s surf_info;
1548 if (screenshot != g_screenshot)
1550 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1554 /* for flush other pending requests and pending events */
1555 XSync(screenshot->dpy, 0);
1557 g_efl_util_x_error_caught = False;
1558 old_handler = XSetErrorHandler(_efl_util_screenshot_x_error_handle);
1561 XvPutStill(screenshot->dpy, screenshot->port, screenshot->pixmap, screenshot->gc,
1562 0, 0, screenshot->width, screenshot->height,
1563 0, 0, screenshot->width, screenshot->height);
1565 XSync(screenshot->dpy, 0);
1567 if (g_efl_util_x_error_caught)
1569 g_efl_util_x_error_caught = False;
1570 XSetErrorHandler(old_handler);
1574 g_efl_util_x_error_caught = False;
1575 XSetErrorHandler(old_handler);
1577 if (XPending(screenshot->dpy))
1578 XNextEvent(screenshot->dpy, &ev);
1581 int fd = ConnectionNumber(screenshot->dpy);
1590 tv.tv_sec = TIMEOUT_CAPTURE;
1592 ret = select(fd + 1, &mask, 0, 0, &tv);
1594 fprintf(stderr, "[screenshot] fail: select.\n");
1596 fprintf(stderr, "[screenshot] fail: timeout(%d sec)!\n", TIMEOUT_CAPTURE);
1597 else if (XPending(screenshot->dpy))
1598 XNextEvent(screenshot->dpy, &ev);
1600 fprintf(stderr, "[screenshot] fail: not passed a event!\n");
1603 /* check if the capture is done by xserver and pixmap has got the captured image */
1604 if (ev.type == (screenshot->damage_base + XDamageNotify))
1606 XDamageNotifyEvent *damage_ev = (XDamageNotifyEvent *)&ev;
1607 if (damage_ev->drawable == screenshot->pixmap)
1609 /* Get DRI2 FrontLeft buffer of the pixmap */
1610 bufs = DRI2GetBuffers(screenshot->dpy, screenshot->pixmap, &buf_width, &buf_height, &attachment, 1, &nbufs);
1613 fprintf(stderr, "[screenshot] fail: DRI2GetBuffers\n");
1617 t_bo = tbm_bo_import(screenshot->bufmgr, bufs[0].name);
1620 fprintf(stderr, "[screenshot] fail: import tbm_bo!\n");
1624 surf_info.width = buf_width;
1625 surf_info.height = buf_height;
1626 surf_info.format = TBM_FORMAT_XRGB8888;
1628 surf_info.size = bufs->pitch * surf_info.height;
1629 surf_info.num_planes = 1;
1630 for (i = 0; i < surf_info.num_planes; i++)
1632 surf_info.planes[i].size = bufs->pitch * surf_info.height;
1633 surf_info.planes[i].stride = bufs->pitch;
1634 surf_info.planes[i].offset = 0;
1636 t_surface = tbm_surface_internal_create_with_bos(&surf_info, &t_bo, 1);
1639 fprintf(stderr, "[screenshot] fail: get tbm_surface!\n");
1646 XDamageSubtract(screenshot->dpy, screenshot->damage, None, None );
1648 set_last_result(EFL_UTIL_ERROR_NONE);
1653 XDamageSubtract(screenshot->dpy, screenshot->damage, None, None );
1663 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);
1670 tbm_surface_h t_surface = NULL;
1671 struct wl_buffer *buffer = NULL;
1672 tbm_surface_info_s info;
1673 Efl_Util_Wl_Output_Info *output;
1676 if (screenshot != g_screenshot)
1678 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1682 output = eina_list_nth(_eflutil.wl.shot.output_list, 0);
1685 fprintf(stderr, "[screenshot] fail: no output for screenshot\n");
1689 t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888);
1692 fprintf(stderr, "[screenshot] fail: tbm_surface_create\n");
1696 t_bo = tbm_surface_internal_get_bo(t_surface, 0);
1699 fprintf(stderr, "[screenshot] fail: no tbm_bo for screenshot\n");
1703 tbm_surface_get_info(t_surface, &info);
1706 tizen_buffer_pool_create_buffer(_eflutil.wl.shot.buffer_pool,
1707 tbm_bo_export(t_bo),
1708 info.width, info.height,
1709 info.planes[0].stride,
1710 TIZEN_BUFFER_POOL_FORMAT_XRGB8888);
1713 fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n");
1717 screenshooter_shoot(_eflutil.wl.shot.screenshooter, output->output, buffer);
1719 screenshot->shot_done = EINA_FALSE;
1720 while (!screenshot->shot_done && ret != -1)
1721 ret = wl_display_dispatch(_eflutil.wl.dpy);
1725 fprintf(stderr, "[screenshot] fail: screenshooter_shoot\n");
1729 wl_buffer_destroy(buffer);
1735 tbm_surface_destroy(t_surface);
1737 wl_buffer_destroy(buffer);
1739 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);