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_notification-client-protocol.h"
48 #include "tizen_window_screen-client-protocol.h"
49 #include "tizen-buffer-pool-client-protocol.h"
50 #include "screenshooter-client-protocol.h"
51 #endif /* end of WAYLAND */
53 /* callback handler index */
54 #define CBH_NOTI_LEV 0
55 #define CBH_SCR_MODE 1
58 typedef void (*Efl_Util_Cb)(Evas_Object *, int, void *);
60 typedef struct _Efl_Util_Callback_Info
65 } Efl_Util_Callback_Info;
68 typedef struct _Efl_Util_Wl_Surface_Lv_Info
70 void *surface; /* wl_surface */
72 Eina_Bool wait_for_done;
73 } Efl_Util_Wl_Surface_Lv_Info;
75 typedef struct _Efl_Util_Wl_Surface_Scr_Mode_Info
77 void *surface; /* wl_surface */
79 Eina_Bool wait_for_done;
80 } Efl_Util_Wl_Surface_Scr_Mode_Info;
82 typedef struct _Efl_Util_Wl_Output_Info
84 struct wl_output *output;
85 int offset_x, offset_y, width, height;
86 } Efl_Util_Wl_Output_Info;
89 typedef struct _Efl_Util_Data
92 /* x11 related stuffs */
96 Ecore_Event_Handler *handler; /* x11 client message handler */
99 #endif /* end of X11 */
102 /* wayland related stuffs */
106 struct wl_display *dpy;
109 struct tizen_notification *proto;
114 struct tizen_window_screen *proto;
119 struct screenshooter *screenshooter;
120 struct tizen_buffer_pool *buffer_pool;
121 Eina_List *output_list;
124 #endif /* end of WAYLAND */
128 Eina_List *info_list; /* list of callback info */
129 unsigned int atom; /* x11 atom */
130 } cb_handler[CBH_MAX];
133 static Efl_Util_Data _eflutil =
141 #endif /* end of X11 */
146 { NULL, NULL }, /* tizen_notification protocol */
147 { NULL, NULL }, /* tizen_window_screen protocol */
148 { NULL, NULL, NULL } /* screenshooter protocol */
150 #endif /* end of WAYLAND */
152 { NULL, 0 }, /* handler for notification level */
153 { NULL, 0 } /* handler for screen mode */
157 static Eina_Bool _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, void *data, int idx);
158 static Eina_Bool _cb_info_del_by_win(Evas_Object *win, int idx);
159 static Eina_List *_cb_info_list_get(int idx);
160 static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx);
162 static Efl_Util_Callback_Info *_cb_info_find_by_xwin(unsigned int xwin, int idx);
163 static Eina_Bool _cb_x11_client_msg(void *data, int type, void *event);
164 static Eina_Bool _x11_init(void);
165 #endif /* end of X11 */
167 static Eina_Bool _wl_init(void);
168 static void _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
169 static void _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name);
170 static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx);
171 static void _cb_wl_tz_noti_lv_done(void *data, struct tizen_notification *proto, struct wl_surface *surface, int32_t level, uint32_t state);
172 static void _cb_wl_tz_scr_mode_done(void *data, struct tizen_window_screen *proto, struct wl_surface *surface, uint32_t mode, uint32_t state);
174 static const struct wl_registry_listener _wl_reg_listener =
177 _cb_wl_reg_global_remove
180 struct tizen_notification_listener _wl_tz_noti_lv_listener =
182 _cb_wl_tz_noti_lv_done
185 struct tizen_window_screen_listener _wl_tz_scr_mode_listener =
187 _cb_wl_tz_scr_mode_done
189 #endif /* end of WAYLAND */
192 _cb_info_add(Evas_Object *win,
197 Efl_Util_Callback_Info *info;
199 info = _cb_info_find_by_win(win, idx);
202 _eflutil.cb_handler[idx].info_list
203 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
208 info = (Efl_Util_Callback_Info *)calloc(1, sizeof(Efl_Util_Callback_Info));
209 if (!info) return EINA_FALSE;
215 _eflutil.cb_handler[idx].info_list
216 = eina_list_append(_eflutil.cb_handler[idx].info_list,
220 if (!_eflutil.x11.handler)
221 _eflutil.x11.handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
224 #endif /* end of X11 */
230 _cb_info_del_by_win(Evas_Object *win,
233 Efl_Util_Callback_Info *info;
235 info = _cb_info_find_by_win(win, idx);
236 if (!info) return EINA_FALSE;
238 _eflutil.cb_handler[idx].info_list
239 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
244 unsigned int count = eina_list_count(_eflutil.cb_handler[idx].info_list);
245 if ((count == 0) && (_eflutil.x11.handler))
247 ecore_event_handler_del(_eflutil.x11.handler);
248 _eflutil.x11.handler = NULL;
256 _cb_info_list_get(int idx)
258 return _eflutil.cb_handler[idx].info_list;
261 static Efl_Util_Callback_Info *
262 _cb_info_find_by_win(Evas_Object *win,
266 Efl_Util_Callback_Info *info;
268 l = _cb_info_list_get(idx);
269 EINA_LIST_FOREACH(l, ll, info)
271 if (info->win == win) return info;
278 static Efl_Util_Callback_Info *
279 _cb_info_find_by_xwin(unsigned int xwin,
283 Efl_Util_Callback_Info *info;
286 l = _cb_info_list_get(idx);
287 EINA_LIST_FOREACH(l, ll, info)
289 xwin2 = elm_win_xwindow_get(info->win);
290 if (xwin == xwin2) return info;
297 _cb_x11_client_msg(void *data,
301 Ecore_X_Event_Client_Message *ev;
303 Efl_Util_Callback_Info *info;
306 if (!ev) return ECORE_CALLBACK_PASS_ON;
309 if (xwin == 0) return ECORE_CALLBACK_PASS_ON;
311 if (ev->message_type == _eflutil.cb_handler[CBH_NOTI_LEV].atom)
313 info = _cb_info_find_by_xwin(xwin, CBH_NOTI_LEV);
315 /* permission denied */
316 if ((ev->data.l[1] == 0) &&
321 EFL_UTIL_ERROR_PERMISSION_DENIED,
325 else if (ev->message_type == _eflutil.cb_handler[CBH_SCR_MODE].atom)
327 info = _cb_info_find_by_xwin(xwin, CBH_SCR_MODE);
329 /* permission denied */
330 if ((ev->data.l[1] == 0) &&
335 EFL_UTIL_ERROR_PERMISSION_DENIED,
339 return ECORE_CALLBACK_PASS_ON;
345 if (_eflutil.x11.init) return EINA_TRUE;
347 _eflutil.x11.dpy = ecore_x_display_get();
348 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.x11.dpy, EINA_FALSE);
350 _eflutil.x11.init = EINA_TRUE;
354 #endif /* end of X11 */
360 struct wl_registry *reg;
362 if (_eflutil.wl.init) return EINA_TRUE;
366 _eflutil.wl.dpy = ecore_wl_display_get();
367 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.dpy, EINA_FALSE);
369 reg = wl_display_get_registry(_eflutil.wl.dpy);
370 EINA_SAFETY_ON_NULL_RETURN_VAL(reg, EINA_FALSE);
372 wl_registry_add_listener(reg, &_wl_reg_listener, NULL);
374 _eflutil.wl.init = EINA_TRUE;
380 _cb_wl_output_geometry(void *data, struct wl_output *wl_output, int x, int y,
381 int physical_width, int physical_height, int subpixel,
382 const char *make, const char *model, int transform)
384 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
385 if (wl_output == output->output)
387 output->offset_x = x;
388 output->offset_y = y;
393 _cb_wl_output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
394 int width, int height, int refresh)
396 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
397 if (wl_output == output->output && (flags & WL_OUTPUT_MODE_CURRENT))
399 output->width = width;
400 output->height = height;
405 _cb_wl_output_done(void *data, struct wl_output *wl_output)
410 _cb_wl_output_scale(void *data, struct wl_output *wl_output, int32_t factor)
414 static const struct wl_output_listener output_listener =
416 _cb_wl_output_geometry,
423 _cb_wl_screenshot_done(void *data, struct screenshooter *screenshooter)
425 Eina_Bool *shot_done = (Eina_Bool*)data;
427 *shot_done = EINA_TRUE;
430 static const struct screenshooter_listener screenshooter_listener =
432 _cb_wl_screenshot_done
436 _cb_wl_reg_global(void *data,
437 struct wl_registry *reg,
439 const char *interface,
440 unsigned int version)
442 if (!strcmp(interface, "tizen_notification"))
444 struct tizen_notification *proto;
445 proto = wl_registry_bind(reg,
447 &tizen_notification_interface,
451 tizen_notification_add_listener(proto,
452 &_wl_tz_noti_lv_listener,
455 _eflutil.wl.noti_lv.hash = eina_hash_pointer_new(free);
456 _eflutil.wl.noti_lv.proto = proto;
458 else if (!strcmp(interface, "tizen_window_screen"))
460 struct tizen_window_screen *proto;
461 proto = wl_registry_bind(reg,
463 &tizen_window_screen_interface,
467 tizen_window_screen_add_listener(proto,
468 &_wl_tz_scr_mode_listener,
471 _eflutil.wl.scr_mode.hash = eina_hash_pointer_new(free);
472 _eflutil.wl.scr_mode.proto = proto;
474 else if (strcmp(interface, "wl_output") == 0)
476 Efl_Util_Wl_Output_Info *output = calloc(1, sizeof(Efl_Util_Wl_Output_Info));
477 EINA_SAFETY_ON_NULL_RETURN(output);
479 _eflutil.wl.shot.output_list = eina_list_append(_eflutil.wl.shot.output_list, output);
481 output->output = wl_registry_bind(reg, name, &wl_output_interface, version);
482 wl_output_add_listener(output->output, &output_listener, output);
484 else if (strcmp(interface, "tizen_buffer_pool") == 0)
486 _eflutil.wl.shot.buffer_pool = wl_registry_bind(reg, name, &tizen_buffer_pool_interface, 1);
488 else if (strcmp(interface, "screenshooter") == 0)
490 _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version);
491 screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL);
496 _cb_wl_reg_global_remove(void *data,
497 struct wl_registry *reg,
500 _eflutil.wl.noti_lv.proto = NULL;
501 eina_hash_free(_eflutil.wl.noti_lv.hash);
502 _eflutil.wl.scr_mode.proto = NULL;
503 eina_hash_free(_eflutil.wl.scr_mode.hash);
506 static Efl_Util_Callback_Info *
507 _cb_info_find_by_wlsurf(void *wlsurf,
511 Efl_Util_Callback_Info *info;
512 Ecore_Wl_Window *wlwin2 = NULL;
513 void *wlsurf2 = NULL;
515 l = _cb_info_list_get(idx);
516 EINA_LIST_FOREACH(l, ll, info)
518 wlwin2 = elm_win_wl_window_get(info->win);
519 wlsurf2 = ecore_wl_window_surface_get(wlwin2);
520 if (wlsurf== wlsurf2) return info;
527 _cb_wl_tz_noti_lv_done(void *data,
528 struct tizen_notification *proto,
529 struct wl_surface *surface,
533 Efl_Util_Wl_Surface_Lv_Info *lv_info;
534 Efl_Util_Callback_Info *cb_info;
536 lv_info = eina_hash_find(_eflutil.wl.noti_lv.hash, &surface);
539 lv_info->level = level;
540 lv_info->wait_for_done = EINA_FALSE;
543 if (state != TIZEN_NOTIFICATION_ERROR_STATE_PERMISSION_DENIED) return;
545 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_NOTI_LEV);
546 if (!cb_info) return;
547 if (!cb_info->cb) return;
549 cb_info->cb(cb_info->win,
550 EFL_UTIL_ERROR_PERMISSION_DENIED,
555 _cb_wl_tz_scr_mode_done(void *data,
556 struct tizen_window_screen *proto,
557 struct wl_surface *surface,
562 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
563 Efl_Util_Callback_Info *cb_info;
565 scr_mode_info = eina_hash_find(_eflutil.wl.scr_mode.hash, &surface);
568 scr_mode_info->mode = mode;
569 scr_mode_info->wait_for_done = EINA_FALSE;
572 if (state != TIZEN_WINDOW_SCREEN_ERROR_STATE_PERMISSION_DENIED) return;
574 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_SCR_MODE);
575 if (!cb_info) return;
576 if (!cb_info->cb) return;
578 cb_info->cb(cb_info->win,
579 EFL_UTIL_ERROR_PERMISSION_DENIED,
582 #endif /* end of WAYLAND */
585 efl_util_set_notification_window_level(Evas_Object *window,
586 efl_util_notification_level_e level)
590 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
591 EINA_SAFETY_ON_FALSE_RETURN_VAL((level >= EFL_UTIL_NOTIFICATION_LEVEL_1) &&
592 (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP),
593 EFL_UTIL_ERROR_INVALID_PARAMETER);
596 Ecore_X_Window_Type window_type;
600 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
602 xwin = elm_win_xwindow_get(window);
605 if (ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
607 // success to get window type
608 if (window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
610 // given EFL window's type is not notification type.
611 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
615 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
617 utilx_set_system_notification_level(_eflutil.x11.dpy,
620 return EFL_UTIL_ERROR_NONE;
622 #endif /* end of X11 */
626 Ecore_Wl_Window *wlwin;
627 struct wl_surface *surface;
628 Efl_Util_Wl_Surface_Lv_Info *lv_info;
631 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
633 type = elm_win_type_get(window);
634 EINA_SAFETY_ON_FALSE_RETURN_VAL((type == ELM_WIN_NOTIFICATION),
635 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
637 wlwin = elm_win_wl_window_get(window);
640 while (!_eflutil.wl.noti_lv.proto)
641 wl_display_dispatch(_eflutil.wl.dpy);
643 surface = ecore_wl_window_surface_get(wlwin);
644 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
645 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
647 lv_info = eina_hash_find(_eflutil.wl.noti_lv.hash, &surface);
650 lv_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Lv_Info));
651 EINA_SAFETY_ON_NULL_RETURN_VAL(lv_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
653 lv_info->surface = surface;
654 lv_info->level = (int)level;
655 lv_info->wait_for_done = EINA_TRUE;
657 eina_hash_add(_eflutil.wl.noti_lv.hash,
663 lv_info->level = (int)level;
664 lv_info->wait_for_done = EINA_TRUE;
667 tizen_notification_set_level(_eflutil.wl.noti_lv.proto,
671 return EFL_UTIL_ERROR_NONE;
673 #endif /* end of WAYLAND */
675 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
679 efl_util_get_notification_window_level(Evas_Object *window,
680 efl_util_notification_level_e *level)
684 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
685 EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER);
688 Ecore_X_Window_Type window_type;
689 Utilx_Notification_Level utilx_level;
693 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
695 xwin = elm_win_xwindow_get(window);
698 if (ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
700 // success to get window type
701 if (window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
703 // given EFL window's type is not notification type.
704 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
707 utilx_level = utilx_get_system_notification_level(_eflutil.x11.dpy, xwin);
708 if (utilx_level == UTILX_NOTIFICATION_LEVEL_LOW)
709 *level = EFL_UTIL_NOTIFICATION_LEVEL_1;
710 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_NORMAL)
711 *level = EFL_UTIL_NOTIFICATION_LEVEL_2;
712 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_HIGH)
713 *level = EFL_UTIL_NOTIFICATION_LEVEL_3;
715 return EFL_UTIL_ERROR_INVALID_PARAMETER;
718 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
720 return EFL_UTIL_ERROR_NONE;
722 #endif /* end of X11 */
726 Ecore_Wl_Window *wlwin;
727 struct wl_surface *surface;
728 Efl_Util_Wl_Surface_Lv_Info *lv_info;
731 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
733 type = elm_win_type_get(window);
734 EINA_SAFETY_ON_FALSE_RETURN_VAL((type == ELM_WIN_NOTIFICATION),
735 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
737 wlwin = elm_win_wl_window_get(window);
740 while (!_eflutil.wl.noti_lv.proto)
741 wl_display_dispatch(_eflutil.wl.dpy);
743 surface = ecore_wl_window_surface_get(wlwin);
744 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
745 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
747 lv_info = eina_hash_find(_eflutil.wl.noti_lv.hash, &surface);
750 if (lv_info->wait_for_done)
752 if (ecore_wl_window_shell_surface_get(wlwin) ||
753 ecore_wl_window_xdg_surface_get(wlwin))
755 while (lv_info->wait_for_done)
758 wl_display_dispatch(_eflutil.wl.dpy);
763 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
764 return EFL_UTIL_ERROR_INVALID_PARAMETER;
768 switch (lv_info->level)
770 case TIZEN_NOTIFICATION_LEVEL_1: *level = EFL_UTIL_NOTIFICATION_LEVEL_1; break;
771 case TIZEN_NOTIFICATION_LEVEL_2: *level = EFL_UTIL_NOTIFICATION_LEVEL_2; break;
772 case TIZEN_NOTIFICATION_LEVEL_3: *level = EFL_UTIL_NOTIFICATION_LEVEL_3; break;
773 case TIZEN_NOTIFICATION_LEVEL_NONE: *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE; break;
774 case TIZEN_NOTIFICATION_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break;
775 case TIZEN_NOTIFICATION_LEVEL_MEDIUM: *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM; break;
776 case TIZEN_NOTIFICATION_LEVEL_HIGH: *level = EFL_UTIL_NOTIFICATION_LEVEL_HIGH; break;
777 case TIZEN_NOTIFICATION_LEVEL_TOP: *level = EFL_UTIL_NOTIFICATION_LEVEL_TOP; break;
778 default: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
779 return EFL_UTIL_ERROR_INVALID_PARAMETER;
781 return EFL_UTIL_ERROR_NONE;
784 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
786 return EFL_UTIL_ERROR_NONE;
788 #endif /* end of WAYLAND */
789 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
793 efl_util_set_notification_window_level_error_cb(Evas_Object *window,
794 efl_util_notification_window_level_error_cb callback,
797 Eina_Bool ret = EINA_FALSE;
799 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
800 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
802 ret = _cb_info_add(window,
803 (Efl_Util_Cb)callback,
806 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
809 if (!_eflutil.cb_handler[CBH_NOTI_LEV].atom)
810 _eflutil.cb_handler[CBH_NOTI_LEV].atom = ecore_x_atom_get("_E_NOTIFICATION_LEVEL_ACCESS_RESULT");
811 #endif /* end of X11 */
813 return EFL_UTIL_ERROR_NONE;
817 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
819 Eina_Bool ret = EINA_FALSE;
821 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
823 ret = _cb_info_del_by_win(window, CBH_NOTI_LEV);
824 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
826 return EFL_UTIL_ERROR_NONE;
830 efl_util_set_window_opaque_state(Evas_Object *window,
835 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
836 EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)),
837 EFL_UTIL_ERROR_INVALID_PARAMETER);
841 Utilx_Opaque_State state;
845 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
847 xwin = elm_win_xwindow_get(window);
848 EINA_SAFETY_ON_FALSE_RETURN_VAL(xwin > 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
851 state = UTILX_OPAQUE_STATE_ON;
853 state = UTILX_OPAQUE_STATE_OFF;
855 ret = utilx_set_window_opaque_state(_eflutil.x11.dpy,
860 return EFL_UTIL_ERROR_INVALID_PARAMETER;
862 return EFL_UTIL_ERROR_NONE;
863 #endif /* end of X11 */
866 Ecore_Wl_Window *wlwin;
870 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
872 wlwin = elm_win_wl_window_get(window);
875 evas_object_geometry_get(window, &x, &y, &w, &h);
878 ecore_wl_window_opaque_region_set(wlwin, x, y, w, h);
880 ecore_wl_window_opaque_region_set(wlwin, 0, 0, 0, 0);
882 return EFL_UTIL_ERROR_NONE;
885 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
886 #endif /* end of WAYLAND */
890 efl_util_set_window_screen_mode(Evas_Object *window,
891 efl_util_screen_mode_e mode)
893 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
894 EINA_SAFETY_ON_FALSE_RETURN_VAL(((mode >= EFL_UTIL_SCREEN_MODE_DEFAULT) &&
895 (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)),
896 EFL_UTIL_ERROR_INVALID_PARAMETER);
903 e = evas_object_evas_get(window);
904 EINA_SAFETY_ON_NULL_RETURN_VAL(e, EFL_UTIL_ERROR_INVALID_PARAMETER);
906 ee = ecore_evas_ecore_evas_get(e);
907 EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EFL_UTIL_ERROR_INVALID_PARAMETER);
909 id = ecore_evas_aux_hint_id_get(ee, "wm.policy.win.lcd.lock");
910 if (mode == EFL_UTIL_SCREEN_MODE_ALWAYS_ON)
913 ecore_evas_aux_hint_add(ee, "wm.policy.win.lcd.lock", "1");
915 ecore_evas_aux_hint_val_set(ee, id, "1");
917 else if (mode == EFL_UTIL_SCREEN_MODE_DEFAULT)
920 ecore_evas_aux_hint_add(ee, "wm.policy.win.lcd.lock", "0");
922 ecore_evas_aux_hint_val_set(ee, id, "0");
925 return EFL_UTIL_ERROR_INVALID_PARAMETER;
927 return EFL_UTIL_ERROR_NONE;
928 #endif /* end of X11 */
931 Ecore_Wl_Window *wlwin;
932 struct wl_surface *surface;
933 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
937 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
939 wlwin = elm_win_wl_window_get(window);
942 while (!_eflutil.wl.scr_mode.proto)
943 wl_display_dispatch(_eflutil.wl.dpy);
945 surface = ecore_wl_window_surface_get(wlwin);
946 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
947 EFL_UTIL_ERROR_INVALID_PARAMETER);
949 scr_mode_info = eina_hash_find(_eflutil.wl.scr_mode.hash, &surface);
952 scr_mode_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Scr_Mode_Info));
953 EINA_SAFETY_ON_NULL_RETURN_VAL(scr_mode_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
955 scr_mode_info->surface = surface;
956 scr_mode_info->mode = (unsigned int)mode;
957 scr_mode_info->wait_for_done = EINA_TRUE;
959 eina_hash_add(_eflutil.wl.scr_mode.hash,
965 scr_mode_info->mode = (unsigned int)mode;
966 scr_mode_info->wait_for_done = EINA_TRUE;
969 tizen_window_screen_set_mode(_eflutil.wl.scr_mode.proto,
973 return EFL_UTIL_ERROR_NONE;
976 return EFL_UTIL_ERROR_INVALID_PARAMETER;
977 #endif /* end of WAYLAND */
981 efl_util_get_window_screen_mode(Evas_Object *window,
982 efl_util_screen_mode_e *mode)
984 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
985 EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER);
993 e = evas_object_evas_get(window);
994 EINA_SAFETY_ON_NULL_RETURN_VAL(e, EFL_UTIL_ERROR_INVALID_PARAMETER);
996 ee = ecore_evas_ecore_evas_get(e);
997 EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EFL_UTIL_ERROR_INVALID_PARAMETER);
999 id = ecore_evas_aux_hint_id_get(ee, "wm.policy.win.lcd.lock");
1000 EINA_SAFETY_ON_TRUE_RETURN_VAL((id == -1), EFL_UTIL_ERROR_INVALID_PARAMETER);
1002 str = ecore_evas_aux_hint_val_get(ee, id);
1003 EINA_SAFETY_ON_NULL_RETURN_VAL(str, EFL_UTIL_ERROR_INVALID_PARAMETER);
1005 if (strncmp(str, "1", strlen("1")) == 0)
1006 *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON;
1008 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1010 return EFL_UTIL_ERROR_NONE;
1011 #endif /* end of X11 */
1014 Ecore_Wl_Window *wlwin;
1015 struct wl_surface *surface;
1016 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
1020 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1022 wlwin = elm_win_wl_window_get(window);
1025 while (!_eflutil.wl.scr_mode.proto)
1026 wl_display_dispatch(_eflutil.wl.dpy);
1028 surface = ecore_wl_window_surface_get(wlwin);
1029 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1030 EFL_UTIL_ERROR_INVALID_PARAMETER);
1032 scr_mode_info = eina_hash_find(_eflutil.wl.scr_mode.hash, &surface);
1035 if (scr_mode_info->wait_for_done)
1037 while (scr_mode_info->wait_for_done)
1040 wl_display_dispatch(_eflutil.wl.dpy);
1044 switch (scr_mode_info->mode)
1046 case TIZEN_WINDOW_SCREEN_MODE_DEFAULT: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT; break;
1047 case TIZEN_WINDOW_SCREEN_MODE_ALWAYS_ON: *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON; break;
1048 default: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1049 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1051 return EFL_UTIL_ERROR_NONE;
1055 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1056 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1060 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1061 #endif /* end of WAYLAND */
1065 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
1066 efl_util_window_screen_mode_error_cb callback,
1069 Eina_Bool ret = EINA_FALSE;
1071 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1072 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
1074 ret = _cb_info_add(window,
1075 (Efl_Util_Cb)callback,
1078 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1081 if (!_eflutil.cb_handler[CBH_SCR_MODE].atom)
1082 _eflutil.cb_handler[CBH_SCR_MODE].atom = ecore_x_atom_get("_E_SCREEN_MODE_ACCESS_RESULT");
1083 #endif /* end of X11 */
1085 return EFL_UTIL_ERROR_NONE;
1089 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
1091 Eina_Bool ret = EINA_FALSE;
1093 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1095 ret = _cb_info_del_by_win(window, CBH_SCR_MODE);
1096 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1098 return EFL_UTIL_ERROR_NONE;
1102 efl_util_input_initialize_generator(efl_util_input_device_type_e dev_type)
1104 return EFL_UTIL_ERROR_NONE;
1108 efl_util_input_deinitialize_generator(void)
1114 efl_util_input_generate_key(const char *key_name,
1117 return EFL_UTIL_ERROR_NONE;
1121 efl_util_input_generate_touch(int idx,
1122 efl_util_input_touch_type_e touch_type,
1126 return EFL_UTIL_ERROR_NONE;
1129 struct _efl_util_screenshot_h
1135 Ecore_X_Display *dpy;
1136 int internal_display;
1151 int eventBase, errorBase;
1152 int dri2Major, dri2Minor;
1153 char *driver_name, *device_name;
1160 Eina_Bool shot_done;
1166 /* scrrenshot handle */
1167 static efl_util_screenshot_h g_screenshot;
1170 #define FOURCC(a,b,c,d) (((unsigned)d&0xff)<<24 | ((unsigned)c&0xff)<<16 | ((unsigned)b&0xff)<<8 | ((unsigned)a&0xff))
1171 #define FOURCC_RGB32 FOURCC('R','G','B','4')
1172 #define TIMEOUT_CAPTURE 3
1174 /* x error handling */
1175 static Bool g_efl_util_x_error_caught;
1178 _efl_util_screenshot_x_error_handle(Display *dpy, XErrorEvent *ev)
1180 if (!g_screenshot || (dpy != g_screenshot->dpy))
1183 g_efl_util_x_error_caught = True;
1189 _efl_util_screenshot_get_port(Display *dpy, unsigned int id, Window win)
1191 unsigned int ver, rev, req_base, evt_base, err_base;
1192 unsigned int adaptors;
1193 XvAdaptorInfo *ai = NULL;
1194 XvImageFormatValues *fo = NULL;
1198 if (XvQueryExtension(dpy, &ver, &rev, &req_base, &evt_base, &err_base) != Success)
1200 fprintf(stderr, "[screenshot] fail: no XV extension. \n");
1204 if (XvQueryAdaptors(dpy, win, &adaptors, &ai) != Success)
1206 fprintf(stderr, "[screenshot] fail: query adaptors. \n");
1210 EINA_SAFETY_ON_NULL_RETURN_VAL(ai, -1);
1212 for (i = 0; i < adaptors; i++)
1214 int support_format = False;
1216 if (!(ai[i].type & XvInputMask) ||
1217 !(ai[i].type & XvStillMask))
1222 fo = XvListImageFormats(dpy, p, &formats);
1223 for (j = 0; j < formats; j++)
1224 if (fo[j].id == (int)id)
1225 support_format = True;
1230 if (!support_format)
1233 for (; p < ai[i].base_id + ai[i].num_ports; p++)
1235 if (XvGrabPort(dpy, p, 0) == Success)
1237 XvFreeAdaptorInfo(ai);
1243 XvFreeAdaptorInfo(ai);
1250 static int _efl_util_screenshot_get_best_size(Display *dpy, int port, int width, int height, unsigned int *best_width, unsigned int *best_height)
1252 XErrorHandler old_handler = NULL;
1254 Atom atom_capture = XInternAtom(dpy, "_USER_WM_PORT_ATTRIBUTE_CAPTURE", False);
1256 g_efl_util_x_error_caught = False;
1257 old_handler = XSetErrorHandler(_efl_util_screenshot_x_error_handle);
1259 XvSetPortAttribute(dpy, port, atom_capture, 1);
1262 g_efl_util_x_error_caught = False;
1263 XSetErrorHandler(old_handler);
1265 XvQueryBestSize(dpy, port, 0, 0, 0, width, height, best_width, best_height);
1266 if (best_width <= 0 || best_height <= 0)
1273 API efl_util_screenshot_h efl_util_screenshot_initialize(int width, int height)
1276 efl_util_screenshot_h screenshot = NULL;
1278 int damage_err_base = 0;
1279 unsigned int best_width = 0;
1280 unsigned int best_height = 0;
1282 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1283 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1285 if (g_screenshot != NULL)
1287 if (g_screenshot->width != width || g_screenshot->height != height)
1289 // TODO: recreate pixmap and update information
1290 if (!_efl_util_screenshot_get_best_size(screenshot->dpy, screenshot->port, width, height, &best_width, &best_height))
1292 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1296 g_screenshot->width = width;
1297 g_screenshot->height = height;
1300 return g_screenshot;
1303 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1304 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1307 screenshot->dpy = ecore_x_display_get();
1308 if (!screenshot->dpy)
1310 screenshot->dpy = XOpenDisplay(0);
1311 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_init);
1313 /* for XCloseDisplay at denitialization */
1314 screenshot->internal_display = 1;
1318 screenshot->screen = DefaultScreen(screenshot->dpy);
1320 /* set root window */
1321 screenshot->root = DefaultRootWindow(screenshot->dpy);
1323 /* initialize capture adaptor */
1324 screenshot->port = _efl_util_screenshot_get_port(screenshot->dpy, FOURCC_RGB32, screenshot->root);
1325 EINA_SAFETY_ON_FALSE_GOTO(screenshot->port > 0, fail_init);
1327 /* get the best size */
1328 _efl_util_screenshot_get_best_size(screenshot->dpy, screenshot->port, width, height, &best_width, &best_height);
1329 EINA_SAFETY_ON_FALSE_GOTO(best_width > 0, fail_init);
1330 EINA_SAFETY_ON_FALSE_GOTO(best_height > 0, fail_init);
1332 /* set the width and the height */
1333 screenshot->width = best_width;
1334 screenshot->height = best_height;
1336 /* create a pixmap */
1337 depth = DefaultDepth(screenshot->dpy, screenshot->screen);
1338 screenshot->pixmap = XCreatePixmap(screenshot->dpy, screenshot->root, screenshot->width, screenshot->height, depth);
1339 EINA_SAFETY_ON_FALSE_GOTO(screenshot->pixmap > 0, fail_init);
1341 screenshot->gc = XCreateGC(screenshot->dpy, screenshot->pixmap, 0, 0);
1342 EINA_SAFETY_ON_NULL_GOTO(screenshot->gc, fail_init);
1344 XSetForeground(screenshot->dpy, screenshot->gc, 0xFF000000);
1345 XFillRectangle(screenshot->dpy, screenshot->pixmap, screenshot->gc, 0, 0, width, height);
1347 /* initialize damage */
1348 if (!XDamageQueryExtension(screenshot->dpy, &screenshot->damage_base, &damage_err_base))
1351 screenshot->damage = XDamageCreate(screenshot->dpy, screenshot->pixmap, XDamageReportNonEmpty);
1352 EINA_SAFETY_ON_FALSE_GOTO(screenshot->damage > 0, fail_init);
1354 /* initialize dri3 and dri2 */
1355 if (!DRI2QueryExtension(screenshot->dpy, &screenshot->eventBase, &screenshot->errorBase))
1357 fprintf(stderr, "[screenshot] fail: DRI2QueryExtention\n");
1361 if (!DRI2QueryVersion(screenshot->dpy, &screenshot->dri2Major, &screenshot->dri2Minor))
1363 fprintf(stderr, "[screenshot] fail: DRI2QueryVersion\n");
1367 if (!DRI2Connect(screenshot->dpy, screenshot->root, &screenshot->driver_name, &screenshot->device_name))
1369 fprintf(stderr, "[screenshot] fail: DRI2Connect\n");
1373 screenshot->drm_fd = open(screenshot->device_name, O_RDWR);
1374 EINA_SAFETY_ON_FALSE_GOTO(screenshot->drm_fd >= 0, fail_init);
1376 if (drmGetMagic(screenshot->drm_fd, &screenshot->magic))
1378 fprintf(stderr, "[screenshot] fail: drmGetMagic\n");
1382 if (!DRI2Authenticate(screenshot->dpy, screenshot->root, screenshot->magic))
1384 fprintf(stderr, "[screenshot] fail: DRI2Authenticate\n");
1388 if (!drmAuthMagic(screenshot->drm_fd, screenshot->magic))
1390 fprintf(stderr, "[screenshot] fail: drmAuthMagic\n");
1394 DRI2CreateDrawable(screenshot->dpy, screenshot->pixmap);
1397 screenshot->bufmgr = tbm_bufmgr_init(screenshot->drm_fd);
1398 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1400 XFlush(screenshot->dpy);
1402 g_screenshot = screenshot;
1403 set_last_result(EFL_UTIL_ERROR_NONE);
1405 return g_screenshot;
1409 efl_util_screenshot_h screenshot = NULL;
1411 if (!_eflutil.wl.shot.screenshooter)
1415 while (!_eflutil.wl.shot.screenshooter && ret != -1)
1416 ret = wl_display_dispatch(_eflutil.wl.dpy);
1417 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init);
1418 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.buffer_pool, fail_init);
1421 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1422 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1426 if (g_screenshot->width != width || g_screenshot->height != height)
1428 g_screenshot->width = width;
1429 g_screenshot->height = height;
1432 return g_screenshot;
1435 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1436 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1438 screenshot->width = width;
1439 screenshot->height = height;
1441 screenshot->bufmgr = tbm_bufmgr_init(-1);
1442 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1444 g_screenshot = screenshot;
1445 set_last_result(EFL_UTIL_ERROR_NONE);
1447 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
1449 return g_screenshot;
1453 efl_util_screenshot_deinitialize(screenshot);
1454 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1458 efl_util_screenshot_deinitialize(screenshot);
1459 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1463 efl_util_screenshot_deinitialize(screenshot);
1464 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1468 API int efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
1472 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1475 if (screenshot->bufmgr)
1476 tbm_bufmgr_deinit(screenshot->bufmgr);
1478 DRI2DestroyDrawable(screenshot->dpy, screenshot->pixmap);
1481 if (screenshot->drm_fd)
1482 close(screenshot->drm_fd);
1483 if (screenshot->driver_name)
1484 free(screenshot->driver_name);
1485 if (screenshot->device_name)
1486 free(screenshot->device_name);
1489 if (screenshot->port > 0 && screenshot->pixmap > 0)
1490 XvStopVideo(screenshot->dpy, screenshot->port, screenshot->pixmap);
1493 if (screenshot->damage)
1494 XDamageDestroy(screenshot->dpy, screenshot->damage);
1498 XFreeGC(screenshot->dpy, screenshot->gc);
1501 if (screenshot->pixmap > 0)
1502 XFreePixmap(screenshot->dpy, screenshot->pixmap);
1505 if (screenshot->port > 0)
1506 XvUngrabPort(screenshot->dpy, screenshot->port, 0);
1508 XSync(screenshot->dpy, False);
1511 if (screenshot->internal_display ==1 && screenshot->dpy)
1512 XCloseDisplay(screenshot->dpy);
1515 g_screenshot = NULL;
1517 return EFL_UTIL_ERROR_NONE;
1521 return EFL_UTIL_ERROR_NONE;
1523 if (screenshot->bufmgr)
1524 tbm_bufmgr_deinit(screenshot->bufmgr);
1527 g_screenshot = NULL;
1529 if (_eflutil.wl.shot.screenshooter)
1530 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, NULL);
1532 return EFL_UTIL_ERROR_NONE;
1537 API tbm_surface_h efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
1541 XErrorHandler old_handler = NULL;
1542 unsigned int attachment = DRI2BufferFrontLeft;
1544 DRI2Buffer *bufs = NULL;
1546 tbm_surface_h t_surface = NULL;
1549 tbm_surface_info_s surf_info;
1552 if (screenshot != g_screenshot)
1554 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1558 /* for flush other pending requests and pending events */
1559 XSync(screenshot->dpy, 0);
1561 g_efl_util_x_error_caught = False;
1562 old_handler = XSetErrorHandler(_efl_util_screenshot_x_error_handle);
1565 XvPutStill(screenshot->dpy, screenshot->port, screenshot->pixmap, screenshot->gc,
1566 0, 0, screenshot->width, screenshot->height,
1567 0, 0, screenshot->width, screenshot->height);
1569 XSync(screenshot->dpy, 0);
1571 if (g_efl_util_x_error_caught)
1573 g_efl_util_x_error_caught = False;
1574 XSetErrorHandler(old_handler);
1578 g_efl_util_x_error_caught = False;
1579 XSetErrorHandler(old_handler);
1581 if (XPending(screenshot->dpy))
1582 XNextEvent(screenshot->dpy, &ev);
1585 int fd = ConnectionNumber(screenshot->dpy);
1594 tv.tv_sec = TIMEOUT_CAPTURE;
1596 ret = select(fd + 1, &mask, 0, 0, &tv);
1598 fprintf(stderr, "[screenshot] fail: select.\n");
1600 fprintf(stderr, "[screenshot] fail: timeout(%d sec)!\n", TIMEOUT_CAPTURE);
1601 else if (XPending(screenshot->dpy))
1602 XNextEvent(screenshot->dpy, &ev);
1604 fprintf(stderr, "[screenshot] fail: not passed a event!\n");
1607 /* check if the capture is done by xserver and pixmap has got the captured image */
1608 if (ev.type == (screenshot->damage_base + XDamageNotify))
1610 XDamageNotifyEvent *damage_ev = (XDamageNotifyEvent *)&ev;
1611 if (damage_ev->drawable == screenshot->pixmap)
1613 /* Get DRI2 FrontLeft buffer of the pixmap */
1614 bufs = DRI2GetBuffers(screenshot->dpy, screenshot->pixmap, &buf_width, &buf_height, &attachment, 1, &nbufs);
1617 fprintf(stderr, "[screenshot] fail: DRI2GetBuffers\n");
1621 t_bo = tbm_bo_import(screenshot->bufmgr, bufs[0].name);
1624 fprintf(stderr, "[screenshot] fail: import tbm_bo!\n");
1628 surf_info.width = buf_width;
1629 surf_info.height = buf_height;
1630 surf_info.format = TBM_FORMAT_XRGB8888;
1632 surf_info.size = bufs->pitch * surf_info.height;
1633 surf_info.num_planes = 1;
1634 for (i = 0; i < surf_info.num_planes; i++)
1636 surf_info.planes[i].size = bufs->pitch * surf_info.height;
1637 surf_info.planes[i].stride = bufs->pitch;
1638 surf_info.planes[i].offset = 0;
1640 t_surface = tbm_surface_internal_create_with_bos(&surf_info, &t_bo, 1);
1643 fprintf(stderr, "[screenshot] fail: get tbm_surface!\n");
1650 XDamageSubtract(screenshot->dpy, screenshot->damage, None, None );
1652 set_last_result(EFL_UTIL_ERROR_NONE);
1657 XDamageSubtract(screenshot->dpy, screenshot->damage, None, None );
1667 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);
1674 tbm_surface_h t_surface = NULL;
1675 struct wl_buffer *buffer = NULL;
1676 tbm_surface_info_s info;
1677 Efl_Util_Wl_Output_Info *output;
1680 if (screenshot != g_screenshot)
1682 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1686 output = eina_list_nth(_eflutil.wl.shot.output_list, 0);
1689 fprintf(stderr, "[screenshot] fail: no output for screenshot\n");
1693 t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888);
1696 fprintf(stderr, "[screenshot] fail: tbm_surface_create\n");
1700 t_bo = tbm_surface_internal_get_bo(t_surface, 0);
1703 fprintf(stderr, "[screenshot] fail: no tbm_bo for screenshot\n");
1707 tbm_surface_get_info(t_surface, &info);
1710 tizen_buffer_pool_create_buffer(_eflutil.wl.shot.buffer_pool,
1711 tbm_bo_export(t_bo),
1712 info.width, info.height,
1713 info.planes[0].stride,
1714 TIZEN_BUFFER_POOL_FORMAT_XRGB8888);
1717 fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n");
1721 screenshooter_shoot(_eflutil.wl.shot.screenshooter, output->output, buffer);
1723 screenshot->shot_done = EINA_FALSE;
1724 while (!screenshot->shot_done && ret != -1)
1725 ret = wl_display_dispatch(_eflutil.wl.dpy);
1729 fprintf(stderr, "[screenshot] fail: screenshooter_shoot\n");
1733 wl_buffer_destroy(buffer);
1739 tbm_surface_destroy(t_surface);
1741 wl_buffer_destroy(buffer);
1743 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);