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>
34 #include <Ecore_Wayland.h>
35 #include <wayland-client.h>
36 #include <wayland-tbm-client.h>
37 #include <tizen-extension-client-protocol.h>
38 #include <screenshooter-client-protocol.h>
40 /* callback handler index */
41 #define CBH_NOTI_LEV 0
42 #define CBH_SCR_MODE 1
45 typedef void (*Efl_Util_Cb)(Evas_Object *, int, void *);
47 typedef struct _Efl_Util_Callback_Info
52 } Efl_Util_Callback_Info;
54 typedef struct _Efl_Util_Wl_Surface_Lv_Info
56 void *surface; /* wl_surface */
58 Eina_Bool wait_for_done;
60 } Efl_Util_Wl_Surface_Lv_Info;
62 typedef struct _Efl_Util_Wl_Surface_Scr_Mode_Info
64 void *surface; /* wl_surface */
66 Eina_Bool wait_for_done;
68 } Efl_Util_Wl_Surface_Scr_Mode_Info;
70 typedef struct _Efl_Util_Wl_Surface_Brightness_Info
72 void *surface; /* wl_surface */
74 Eina_Bool wait_for_done;
76 } Efl_Util_Wl_Surface_Brightness_Info;
78 typedef struct _Efl_Util_Wl_Output_Info
80 struct wl_output *output;
81 int offset_x, offset_y, width, height;
82 } Efl_Util_Wl_Output_Info;
84 typedef struct _Efl_Util_Data
86 /* wayland related stuffs */
90 struct wl_display *dpy;
91 struct wl_event_queue *queue;
95 struct tizen_policy *proto;
96 Eina_Hash *hash_noti_lv;
97 Eina_Hash *hash_scr_mode;
101 struct screenshooter *screenshooter;
102 struct wayland_tbm_client *tbm_client;
103 Eina_List *output_list;
107 struct tizen_input_device_manager *devicemgr;
108 int request_notified;
112 struct tizen_display_policy *proto;
113 Eina_Hash *hash_brightness;
119 Eina_List *info_list; /* list of callback info */
120 unsigned int atom; /* x11 atom */
121 } cb_handler[CBH_MAX];
124 static Efl_Util_Data _eflutil =
129 { NULL, NULL, NULL }, /* tizen_policy protocol */
130 { NULL, NULL, NULL }, /* screenshooter protocol */
131 { NULL, -1 } /* tizen_input_device_manager protocol */
134 { NULL, 0 }, /* handler for notification level */
135 { NULL, 0 } /* handler for screen mode */
139 static Eina_Bool _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, void *data, int idx);
140 static Eina_Bool _cb_info_del_by_win(Evas_Object *win, int idx);
141 static Eina_List *_cb_info_list_get(int idx);
142 static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx);
143 static Eina_Bool _wl_init(void);
144 static void _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
145 static void _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name);
146 static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx);
147 static void _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t is_conformant);
148 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);
149 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);
150 static void _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id);
151 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);
152 static void _cb_wl_tz_policy_iconify_state_changed(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, uint32_t iconified, uint32_t force);
153 static void _cb_wl_tz_policy_supported_aux_hints(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, struct wl_array *hints, uint32_t num_hints);
154 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id);
155 static void _cb_wl_tz_policy_aux_message(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, const char *key, const char *val, struct wl_array *options);
157 static void _cb_wl_tz_display_policy_brightness_done(void *data, struct tizen_display_policy *tizen_display_policy, struct wl_surface *surface_resource, int32_t brightness, uint32_t state);
159 static void _cb_device_add(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t serial EINA_UNUSED, const char *identifier EINA_UNUSED, struct tizen_input_device *device EINA_UNUSED, struct wl_seat *seat EINA_UNUSED);
160 static void _cb_device_remove(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t serial EINA_UNUSED, const char *identifier EINA_UNUSED, struct tizen_input_device *device EINA_UNUSED, struct wl_seat *seat EINA_UNUSED);
161 static void _cb_error(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t errorcode);
162 static void _cb_block_expired(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED);
164 static const struct wl_registry_listener _wl_reg_listener =
167 _cb_wl_reg_global_remove
170 struct tizen_policy_listener _wl_tz_policy_listener =
172 _cb_wl_tz_policy_conformant,
173 _cb_wl_tz_policy_conformant_area,
174 _cb_wl_tz_policy_notification_done,
175 _cb_wl_tz_policy_transient_for_done,
176 _cb_wl_tz_policy_scr_mode_done,
177 _cb_wl_tz_policy_iconify_state_changed,
178 _cb_wl_tz_policy_supported_aux_hints,
179 _cb_wl_tz_policy_allowed_aux_hint,
180 _cb_wl_tz_policy_aux_message,
183 struct tizen_input_device_manager_listener _wl_tz_devmgr_listener =
191 struct tizen_display_policy_listener _wl_tz_display_policy_listener =
193 _cb_wl_tz_display_policy_brightness_done,
197 _cb_info_add(Evas_Object *win,
202 Efl_Util_Callback_Info *info;
204 info = _cb_info_find_by_win(win, idx);
207 _eflutil.cb_handler[idx].info_list
208 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
213 info = (Efl_Util_Callback_Info *)calloc(1, sizeof(Efl_Util_Callback_Info));
214 if (!info) return EINA_FALSE;
220 _eflutil.cb_handler[idx].info_list
221 = eina_list_append(_eflutil.cb_handler[idx].info_list,
228 _cb_info_del_by_win(Evas_Object *win,
231 Efl_Util_Callback_Info *info;
233 info = _cb_info_find_by_win(win, idx);
234 if (!info) return EINA_FALSE;
236 _eflutil.cb_handler[idx].info_list
237 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
245 _cb_info_list_get(int idx)
247 return _eflutil.cb_handler[idx].info_list;
250 static Efl_Util_Callback_Info *
251 _cb_info_find_by_win(Evas_Object *win,
255 Efl_Util_Callback_Info *info;
257 l = _cb_info_list_get(idx);
258 EINA_LIST_FOREACH(l, ll, info)
260 if (info->win == win) return info;
269 struct wl_registry *reg = NULL;
271 if (_eflutil.wl.init) return EINA_TRUE;
275 _eflutil.wl.dpy = ecore_wl_display_get();
276 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.dpy, fail);
278 _eflutil.wl.queue = wl_display_create_queue(_eflutil.wl.dpy);
279 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.queue, fail);
281 reg = wl_display_get_registry(_eflutil.wl.dpy);
282 EINA_SAFETY_ON_NULL_GOTO(reg, fail);
284 wl_proxy_set_queue((struct wl_proxy*)reg, _eflutil.wl.queue);
285 wl_registry_add_listener(reg, &_wl_reg_listener, NULL);
287 _eflutil.wl.init = EINA_TRUE;
291 if (_eflutil.wl.queue)
293 wl_event_queue_destroy(_eflutil.wl.queue);
294 _eflutil.wl.queue = NULL;
302 _cb_wl_output_geometry(void *data, struct wl_output *wl_output, int x, int y,
303 int physical_width, int physical_height, int subpixel,
304 const char *make, const char *model, int transform)
306 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
307 if (wl_output == output->output)
309 output->offset_x = x;
310 output->offset_y = y;
315 _cb_wl_output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
316 int width, int height, int refresh)
318 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
319 if (wl_output == output->output && (flags & WL_OUTPUT_MODE_CURRENT))
321 output->width = width;
322 output->height = height;
327 _cb_wl_output_done(void *data, struct wl_output *wl_output)
332 _cb_wl_output_scale(void *data, struct wl_output *wl_output, int32_t factor)
336 static const struct wl_output_listener output_listener =
338 _cb_wl_output_geometry,
345 _cb_wl_screenshot_done(void *data, struct screenshooter *screenshooter)
347 Eina_Bool *shot_done = (Eina_Bool*)data;
349 *shot_done = EINA_TRUE;
352 static const struct screenshooter_listener screenshooter_listener =
354 _cb_wl_screenshot_done
358 _cb_wl_reg_global(void *data,
359 struct wl_registry *reg,
361 const char *interface,
362 unsigned int version)
364 if (!strcmp(interface, "tizen_policy"))
366 struct tizen_policy *proto;
367 proto = wl_registry_bind(reg,
369 &tizen_policy_interface,
373 tizen_policy_add_listener(proto,
374 &_wl_tz_policy_listener,
377 _eflutil.wl.policy.hash_noti_lv = eina_hash_pointer_new(free);
378 _eflutil.wl.policy.hash_scr_mode = eina_hash_pointer_new(free);
379 _eflutil.wl.policy.proto = proto;
381 else if (strcmp(interface, "wl_output") == 0)
383 Efl_Util_Wl_Output_Info *output = calloc(1, sizeof(Efl_Util_Wl_Output_Info));
384 EINA_SAFETY_ON_NULL_RETURN(output);
386 _eflutil.wl.shot.output_list = eina_list_append(_eflutil.wl.shot.output_list, output);
388 output->output = wl_registry_bind(reg, name, &wl_output_interface, version);
389 wl_output_add_listener(output->output, &output_listener, output);
391 else if (strcmp(interface, "screenshooter") == 0)
393 _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version);
394 screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL);
396 else if (strcmp(interface, "tizen_input_device_manager") == 0)
398 _eflutil.wl.devmgr.devicemgr = wl_registry_bind(reg, name, &tizen_input_device_manager_interface, version);
399 tizen_input_device_manager_add_listener(_eflutil.wl.devmgr.devicemgr, &_wl_tz_devmgr_listener, NULL);
401 else if (!strcmp(interface, "tizen_display_policy"))
403 _eflutil.wl.display_policy.proto = wl_registry_bind(reg, name, &tizen_display_policy_interface, version);
404 if (!_eflutil.wl.display_policy.proto) return;
406 tizen_display_policy_add_listener(_eflutil.wl.display_policy.proto,
407 &_wl_tz_display_policy_listener,
410 _eflutil.wl.display_policy.hash_brightness = eina_hash_pointer_new(free);
414 /* LCOV_EXCL_START */
416 _cb_wl_reg_global_remove(void *data,
417 struct wl_registry *reg,
420 _eflutil.wl.policy.proto = NULL;
421 eina_hash_free(_eflutil.wl.policy.hash_noti_lv);
422 eina_hash_free(_eflutil.wl.policy.hash_scr_mode);
424 _eflutil.wl.display_policy.proto = NULL;
425 eina_hash_free(_eflutil.wl.display_policy.hash_brightness);
428 static Efl_Util_Callback_Info *
429 _cb_info_find_by_wlsurf(void *wlsurf,
433 Efl_Util_Callback_Info *info;
434 Ecore_Wl_Window *wlwin2 = NULL;
435 void *wlsurf2 = NULL;
437 l = _cb_info_list_get(idx);
438 EINA_LIST_FOREACH(l, ll, info)
440 wlwin2 = elm_win_wl_window_get(info->win);
441 wlsurf2 = ecore_wl_window_surface_get(wlwin2);
442 if (wlsurf== wlsurf2) return info;
449 _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy,
450 struct wl_surface *surface, uint32_t is_conformant)
455 _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy,
456 struct wl_surface *surface, uint32_t conformant_part,
457 uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h)
463 _cb_wl_tz_policy_notification_done(void *data,
464 struct tizen_policy *tizen_policy,
465 struct wl_surface *surface,
469 Efl_Util_Wl_Surface_Lv_Info *lv_info;
470 Efl_Util_Callback_Info *cb_info;
472 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
475 lv_info->level = level;
476 lv_info->wait_for_done = EINA_FALSE;
477 lv_info->state = state;
480 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
482 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_NOTI_LEV);
483 if (!cb_info) return;
484 if (!cb_info->cb) return;
486 cb_info->cb(cb_info->win,
487 EFL_UTIL_ERROR_PERMISSION_DENIED,
491 /* LCOV_EXCL_START */
493 _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id)
499 _cb_wl_tz_policy_scr_mode_done(void *data,
500 struct tizen_policy *tizen_policy,
501 struct wl_surface *surface,
506 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
507 Efl_Util_Callback_Info *cb_info;
509 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
512 scr_mode_info->mode = mode;
513 scr_mode_info->wait_for_done = EINA_FALSE;
514 scr_mode_info->state = state;
517 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
519 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_SCR_MODE);
520 if (!cb_info) return;
521 if (!cb_info->cb) return;
523 cb_info->cb(cb_info->win,
524 EFL_UTIL_ERROR_PERMISSION_DENIED,
528 /* LCOV_EXCL_START */
529 static void _cb_wl_tz_policy_iconify_state_changed(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, uint32_t iconified, uint32_t force)
533 static void _cb_wl_tz_policy_supported_aux_hints(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, struct wl_array *hints, uint32_t num_hints)
537 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id)
541 static void _cb_wl_tz_policy_aux_message(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, const char *key, const char *val, struct wl_array *options)
547 _cb_wl_tz_display_policy_brightness_done(void *data,
548 struct tizen_display_policy *tizen_display_policy,
549 struct wl_surface *surface,
553 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
555 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
558 brightness_info->brightness = brightness;
559 brightness_info->wait_for_done = EINA_FALSE;
560 brightness_info->state = state;
565 _cb_window_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
567 Efl_Util_Wl_Surface_Lv_Info *lv_info;
570 if (EINA_UNLIKELY(!lv_info))
573 eina_hash_del(_eflutil.wl.policy.hash_noti_lv, &lv_info->surface, lv_info);
577 efl_util_set_notification_window_level(Evas_Object *window,
578 efl_util_notification_level_e level)
582 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
583 EINA_SAFETY_ON_FALSE_RETURN_VAL((level >= EFL_UTIL_NOTIFICATION_LEVEL_NONE) &&
584 (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP),
585 EFL_UTIL_ERROR_INVALID_PARAMETER);
588 Ecore_Wl_Window *wlwin;
589 struct wl_surface *surface;
590 Efl_Util_Wl_Surface_Lv_Info *lv_info;
591 Ecore_Wl_Window_Type wl_type;
594 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
596 wlwin = elm_win_wl_window_get(window);
597 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
599 type = elm_win_type_get(window);
600 if (type != ELM_WIN_NOTIFICATION)
602 wl_type = ecore_wl_window_type_get(wlwin);
603 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
604 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
607 while (!_eflutil.wl.policy.proto)
608 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
610 surface = ecore_wl_window_surface_get(wlwin);
611 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
612 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
614 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
617 lv_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Lv_Info));
618 EINA_SAFETY_ON_NULL_RETURN_VAL(lv_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
620 lv_info->surface = surface;
621 lv_info->level = (int)level;
622 lv_info->wait_for_done = EINA_TRUE;
623 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
624 eina_hash_add(_eflutil.wl.policy.hash_noti_lv,
628 evas_object_event_callback_add(window, EVAS_CALLBACK_DEL,
629 _cb_window_del, lv_info);
633 lv_info->level = (int)level;
634 lv_info->wait_for_done = EINA_TRUE;
635 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
639 tizen_policy_set_notification_level(_eflutil.wl.policy.proto,
640 surface, (int)level);
642 if (lv_info->wait_for_done)
645 while (lv_info->wait_for_done && (count < 3))
648 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
652 if (lv_info->wait_for_done)
654 return EFL_UTIL_ERROR_INVALID_PARAMETER;
658 if (lv_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
660 return EFL_UTIL_ERROR_PERMISSION_DENIED;
665 return EFL_UTIL_ERROR_NONE;
669 efl_util_get_notification_window_level(Evas_Object *window,
670 efl_util_notification_level_e *level)
674 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
675 EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER);
678 Ecore_Wl_Window *wlwin;
679 struct wl_surface *surface;
680 Efl_Util_Wl_Surface_Lv_Info *lv_info;
681 Ecore_Wl_Window_Type wl_type;
684 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
686 wlwin = elm_win_wl_window_get(window);
687 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
689 type = elm_win_type_get(window);
690 if (type != ELM_WIN_NOTIFICATION)
692 wl_type = ecore_wl_window_type_get(wlwin);
693 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
694 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
697 while (!_eflutil.wl.policy.proto)
698 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
700 surface = ecore_wl_window_surface_get(wlwin);
701 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
702 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
704 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
707 if (lv_info->wait_for_done)
710 while ((lv_info->wait_for_done) && (count < 3))
713 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
717 if (lv_info->wait_for_done)
719 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
720 return EFL_UTIL_ERROR_INVALID_PARAMETER;
724 switch (lv_info->level)
726 case TIZEN_POLICY_LEVEL_1: *level = EFL_UTIL_NOTIFICATION_LEVEL_1; break;
727 case TIZEN_POLICY_LEVEL_2: *level = EFL_UTIL_NOTIFICATION_LEVEL_2; break;
728 case TIZEN_POLICY_LEVEL_3: *level = EFL_UTIL_NOTIFICATION_LEVEL_3; break;
729 case TIZEN_POLICY_LEVEL_NONE: *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE; break;
730 case TIZEN_POLICY_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break;
731 case TIZEN_POLICY_LEVEL_MEDIUM: *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM; break;
732 case TIZEN_POLICY_LEVEL_HIGH: *level = EFL_UTIL_NOTIFICATION_LEVEL_HIGH; break;
733 case TIZEN_POLICY_LEVEL_TOP: *level = EFL_UTIL_NOTIFICATION_LEVEL_TOP; break;
734 default: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
735 return EFL_UTIL_ERROR_INVALID_PARAMETER;
737 return EFL_UTIL_ERROR_NONE;
740 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
742 return EFL_UTIL_ERROR_NONE;
746 efl_util_set_notification_window_level_error_cb(Evas_Object *window,
747 efl_util_notification_window_level_error_cb callback,
750 Eina_Bool ret = EINA_FALSE;
752 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
753 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
755 ret = _cb_info_add(window,
756 (Efl_Util_Cb)callback,
759 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
761 return EFL_UTIL_ERROR_NONE;
765 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
767 Eina_Bool ret = EINA_FALSE;
769 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
771 ret = _cb_info_del_by_win(window, CBH_NOTI_LEV);
772 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
774 return EFL_UTIL_ERROR_NONE;
778 efl_util_set_window_opaque_state(Evas_Object *window,
783 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
784 EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)),
785 EFL_UTIL_ERROR_INVALID_PARAMETER);
787 Ecore_Wl_Window *wlwin;
788 struct wl_surface *surface;
790 if (!_eflutil.wl.policy.proto)
795 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
797 while (!_eflutil.wl.policy.proto && ret != -1)
798 ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
800 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
803 wlwin = elm_win_wl_window_get(window);
805 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
807 surface = ecore_wl_window_surface_get(wlwin);
809 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
811 tizen_policy_set_opaque_state(_eflutil.wl.policy.proto, surface, opaque);
813 return EFL_UTIL_ERROR_NONE;
817 efl_util_set_window_screen_mode(Evas_Object *window,
818 efl_util_screen_mode_e mode)
820 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
821 EINA_SAFETY_ON_FALSE_RETURN_VAL(((mode >= EFL_UTIL_SCREEN_MODE_DEFAULT) &&
822 (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)),
823 EFL_UTIL_ERROR_INVALID_PARAMETER);
825 Ecore_Wl_Window *wlwin;
826 struct wl_surface *surface;
827 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
831 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
833 wlwin = elm_win_wl_window_get(window);
836 while (!_eflutil.wl.policy.proto)
837 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
839 surface = ecore_wl_window_surface_get(wlwin);
840 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
841 EFL_UTIL_ERROR_INVALID_PARAMETER);
843 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
846 scr_mode_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Scr_Mode_Info));
847 EINA_SAFETY_ON_NULL_RETURN_VAL(scr_mode_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
849 scr_mode_info->surface = surface;
850 scr_mode_info->mode = (unsigned int)mode;
851 scr_mode_info->wait_for_done = EINA_TRUE;
852 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
854 eina_hash_add(_eflutil.wl.policy.hash_scr_mode,
860 scr_mode_info->mode = (unsigned int)mode;
861 scr_mode_info->wait_for_done = EINA_TRUE;
862 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
865 tizen_policy_set_window_screen_mode(_eflutil.wl.policy.proto,
866 surface, (unsigned int)mode);
867 if (scr_mode_info->wait_for_done)
870 while (scr_mode_info->wait_for_done && (count < 3))
873 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
877 if (scr_mode_info->wait_for_done)
879 return EFL_UTIL_ERROR_INVALID_PARAMETER;
883 if (scr_mode_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
885 return EFL_UTIL_ERROR_PERMISSION_DENIED;
890 return EFL_UTIL_ERROR_NONE;
893 return EFL_UTIL_ERROR_INVALID_PARAMETER;
897 efl_util_get_window_screen_mode(Evas_Object *window,
898 efl_util_screen_mode_e *mode)
900 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
901 EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER);
903 Ecore_Wl_Window *wlwin;
904 struct wl_surface *surface;
905 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
909 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
911 wlwin = elm_win_wl_window_get(window);
914 while (!_eflutil.wl.policy.proto)
915 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
917 surface = ecore_wl_window_surface_get(wlwin);
918 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
919 EFL_UTIL_ERROR_INVALID_PARAMETER);
921 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
924 if (scr_mode_info->wait_for_done)
926 while (scr_mode_info->wait_for_done)
929 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
933 switch (scr_mode_info->mode)
935 case TIZEN_POLICY_MODE_DEFAULT: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT; break;
936 case TIZEN_POLICY_MODE_ALWAYS_ON: *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON; break;
937 default: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
938 return EFL_UTIL_ERROR_INVALID_PARAMETER;
940 return EFL_UTIL_ERROR_NONE;
944 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
945 return EFL_UTIL_ERROR_INVALID_PARAMETER;
949 return EFL_UTIL_ERROR_INVALID_PARAMETER;
952 #ifndef TIZEN_WEARABLE
954 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
955 efl_util_window_screen_mode_error_cb callback,
958 Eina_Bool ret = EINA_FALSE;
960 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
961 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
963 ret = _cb_info_add(window,
964 (Efl_Util_Cb)callback,
967 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
969 return EFL_UTIL_ERROR_NONE;
973 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
975 Eina_Bool ret = EINA_FALSE;
977 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
979 ret = _cb_info_del_by_win(window, CBH_SCR_MODE);
980 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
982 return EFL_UTIL_ERROR_NONE;
987 efl_util_set_window_brightness(Evas_Object *window, int brightness)
989 Ecore_Wl_Window *wlwin;
990 struct wl_surface *surface;
991 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
994 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
995 EINA_SAFETY_ON_FALSE_RETURN_VAL(brightness <= 100, EFL_UTIL_ERROR_INVALID_PARAMETER);
998 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1000 wlwin = elm_win_wl_window_get(window);
1003 while (!_eflutil.wl.display_policy.proto)
1004 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1006 surface = ecore_wl_window_surface_get(wlwin);
1007 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1008 EFL_UTIL_ERROR_INVALID_PARAMETER);
1010 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1011 if (!brightness_info)
1013 brightness_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Brightness_Info));
1014 EINA_SAFETY_ON_NULL_RETURN_VAL(brightness_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
1016 brightness_info->surface = surface;
1017 brightness_info->brightness = brightness;
1018 brightness_info->wait_for_done = EINA_TRUE;
1019 brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1021 eina_hash_add(_eflutil.wl.display_policy.hash_brightness,
1027 brightness_info->brightness = brightness;
1028 brightness_info->wait_for_done = EINA_TRUE;
1029 brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1032 tizen_display_policy_set_window_brightness(_eflutil.wl.display_policy.proto,
1033 surface, brightness);
1034 if (brightness_info->wait_for_done)
1037 while (brightness_info->wait_for_done && (count < 3))
1040 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1044 if (brightness_info->wait_for_done)
1046 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1050 if (brightness_info->state == TIZEN_DISPLAY_POLICY_ERROR_STATE_PERMISSION_DENIED)
1052 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1056 return EFL_UTIL_ERROR_NONE;
1059 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1063 efl_util_get_window_brightness(Evas_Object *window, int *brightness)
1065 Ecore_Wl_Window *wlwin;
1066 struct wl_surface *surface;
1067 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1070 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1071 EINA_SAFETY_ON_NULL_RETURN_VAL(brightness, EFL_UTIL_ERROR_INVALID_PARAMETER);
1074 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1076 wlwin = elm_win_wl_window_get(window);
1077 if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1079 while (!_eflutil.wl.display_policy.proto)
1080 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1082 surface = ecore_wl_window_surface_get(wlwin);
1083 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1084 EFL_UTIL_ERROR_INVALID_PARAMETER);
1086 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1087 if (brightness_info)
1089 if (brightness_info->wait_for_done)
1091 while (brightness_info->wait_for_done)
1094 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1097 *brightness = brightness_info->brightness;
1102 return EFL_UTIL_ERROR_NONE;
1106 struct _efl_util_inputgen_h
1108 unsigned int init_type;
1112 _cb_device_add(void *data EINA_UNUSED,
1113 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1114 uint32_t serial EINA_UNUSED,
1115 const char *identifier EINA_UNUSED,
1116 struct tizen_input_device *device EINA_UNUSED,
1117 struct wl_seat *seat EINA_UNUSED)
1122 /* LCOV_EXCL_START */
1124 _cb_device_remove(void *data EINA_UNUSED,
1125 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1126 uint32_t serial EINA_UNUSED,
1127 const char *identifier EINA_UNUSED,
1128 struct tizen_input_device *device EINA_UNUSED,
1129 struct wl_seat *seat EINA_UNUSED)
1133 /* LCOV_EXCL_STOP */
1136 _cb_error(void *data EINA_UNUSED,
1137 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1140 _eflutil.wl.devmgr.request_notified = errorcode;
1143 /* LCOV_EXCL_START */
1145 _cb_block_expired(void *data EINA_UNUSED,
1146 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED)
1150 /* LCOV_EXCL_STOP */
1152 static efl_util_error_e
1153 _efl_util_input_convert_input_generator_error(int ret)
1157 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE:
1158 return EFL_UTIL_ERROR_NONE;
1159 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION:
1160 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1161 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES:
1162 return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1163 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER:
1164 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1166 return EFL_UTIL_ERROR_NONE;
1170 API efl_util_inputgen_h
1171 efl_util_input_initialize_generator(efl_util_input_device_type_e dev_type)
1173 int ret = EFL_UTIL_ERROR_NONE;
1174 efl_util_inputgen_h inputgen_h = NULL;
1176 if ((dev_type <= EFL_UTIL_INPUT_DEVTYPE_NONE) ||
1177 (dev_type >= EFL_UTIL_INPUT_DEVTYPE_MAX))
1179 set_last_result(EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1183 inputgen_h = (efl_util_inputgen_h)calloc(1, sizeof(struct _efl_util_inputgen_h));
1186 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1190 inputgen_h->init_type |= dev_type;
1193 if (ret == (int)EINA_FALSE)
1195 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1199 while (!_eflutil.wl.devmgr.devicemgr)
1200 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1202 tizen_input_device_manager_init_generator(_eflutil.wl.devmgr.devicemgr);
1204 while (_eflutil.wl.devmgr.request_notified == -1)
1205 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1207 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1208 _eflutil.wl.devmgr.request_notified = -1;
1210 set_last_result(ret);
1211 if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
1226 efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h)
1228 int ret = EFL_UTIL_ERROR_NONE;
1229 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1234 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1236 tizen_input_device_manager_deinit_generator(_eflutil.wl.devmgr.devicemgr);
1238 while (_eflutil.wl.devmgr.request_notified == -1)
1239 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1241 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1242 _eflutil.wl.devmgr.request_notified = -1;
1248 efl_util_input_generate_key(efl_util_inputgen_h inputgen_h, const char *key_name, int pressed)
1250 int ret = EFL_UTIL_ERROR_NONE;
1252 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1253 EINA_SAFETY_ON_NULL_RETURN_VAL(key_name, EFL_UTIL_ERROR_INVALID_PARAMETER);
1254 EINA_SAFETY_ON_FALSE_RETURN_VAL(pressed == 0 || pressed == 1, EFL_UTIL_ERROR_INVALID_PARAMETER);
1255 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1257 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1259 tizen_input_device_manager_generate_key(_eflutil.wl.devmgr.devicemgr, key_name, pressed);
1261 while (_eflutil.wl.devmgr.request_notified == -1)
1262 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1264 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1265 _eflutil.wl.devmgr.request_notified = -1;
1271 efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx,
1272 efl_util_input_touch_type_e touch_type, int x, int y)
1275 enum tizen_input_device_manager_pointer_event_type type;
1277 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1278 EINA_SAFETY_ON_FALSE_RETURN_VAL(idx >= 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1279 EINA_SAFETY_ON_FALSE_RETURN_VAL((x > 0 && y > 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1280 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1282 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1286 case EFL_UTIL_INPUT_TOUCH_BEGIN:
1287 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1289 case EFL_UTIL_INPUT_TOUCH_UPDATE:
1290 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1292 case EFL_UTIL_INPUT_TOUCH_END:
1293 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1296 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1299 tizen_input_device_manager_generate_touch(_eflutil.wl.devmgr.devicemgr, type, x, y, idx);
1301 while (_eflutil.wl.devmgr.request_notified == -1)
1302 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1304 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1305 _eflutil.wl.devmgr.request_notified = -1;
1310 struct _efl_util_screenshot_h
1315 Eina_Bool shot_done;
1321 /* scrrenshot handle */
1322 static efl_util_screenshot_h g_screenshot;
1324 API efl_util_screenshot_h
1325 efl_util_screenshot_initialize(int width, int height)
1327 efl_util_screenshot_h screenshot = NULL;
1329 if (!_eflutil.wl.shot.screenshooter)
1333 while (!_eflutil.wl.shot.screenshooter && ret != -1)
1334 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1335 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init);
1337 _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy);
1338 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init);
1341 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1342 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1346 if (g_screenshot->width != width || g_screenshot->height != height)
1348 g_screenshot->width = width;
1349 g_screenshot->height = height;
1352 return g_screenshot;
1355 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1356 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1358 screenshot->width = width;
1359 screenshot->height = height;
1361 screenshot->bufmgr = wayland_tbm_client_get_bufmgr(_eflutil.wl.shot.tbm_client);
1362 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1364 g_screenshot = screenshot;
1365 set_last_result(EFL_UTIL_ERROR_NONE);
1367 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
1369 return g_screenshot;
1372 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1375 /* LCOV_EXCL_START */
1376 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1378 /* LCOV_EXCL_STOP */
1381 efl_util_screenshot_deinitialize(screenshot);
1382 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1387 efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
1390 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1393 g_screenshot = NULL;
1395 if (_eflutil.wl.shot.screenshooter)
1396 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, NULL);
1398 return EFL_UTIL_ERROR_NONE;
1403 efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
1405 tbm_surface_h t_surface = NULL;
1406 struct wl_buffer *buffer = NULL;
1407 Efl_Util_Wl_Output_Info *output;
1410 if (screenshot != g_screenshot)
1412 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1416 output = eina_list_nth(_eflutil.wl.shot.output_list, 0);
1419 fprintf(stderr, "[screenshot] fail: no output for screenshot\n"); /* LCOV_EXCL_LINE */
1423 t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888);
1426 fprintf(stderr, "[screenshot] fail: tbm_surface_create\n"); /* LCOV_EXCL_LINE */
1430 buffer = wayland_tbm_client_create_buffer(_eflutil.wl.shot.tbm_client, t_surface);
1433 fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n"); /* LCOV_EXCL_LINE */
1437 screenshooter_shoot(_eflutil.wl.shot.screenshooter, output->output, buffer);
1439 screenshot->shot_done = EINA_FALSE;
1440 while (!screenshot->shot_done && ret != -1)
1441 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1445 fprintf(stderr, "[screenshot] fail: screenshooter_shoot\n"); /* LCOV_EXCL_LINE */
1449 wl_buffer_destroy(buffer);
1451 /* reset shot_done for next screenshot */
1452 screenshot->shot_done = EINA_FALSE;
1458 tbm_surface_destroy(t_surface);
1460 wl_buffer_destroy(buffer);
1462 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);