2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
19 #include <Elementary.h>
21 #include <Ecore_Evas.h>
31 #include <widget_errno.h>
32 #include <widget_service.h>
33 #include <widget_service_internal.h>
34 #include <widget_conf.h>
35 #include <widget_buffer.h>
36 #include <widget_provider.h>
37 #include <widget_util.h>
40 #include "widget_internal.h"
46 #define PUBLIC __attribute__((visibility("default")))
47 #define WIDGET_WIN_TAG "dynamic,box,win"
48 #define WIN_INFO_TAG "dynamic,box,info"
50 #define WIDGET_DEFAULT_WIDTH 1
51 #define WIDGET_DEFAULT_HEIGHT 1
53 static inline Evas_Object *get_highlighted_object(Evas_Object *obj)
57 o = evas_object_name_find(evas_object_evas_get(obj), "_elm_access_disp");
60 ho = evas_object_data_get(o, "_elm_access_target");
64 static inline void apply_orientation(int degree, int *x, int *y, int width, int height, input_event_source_e source)
70 if (source == INPUT_EVENT_SOURCE_VIEWER) {
96 * This rotation formular is not work correctly.
97 * The pointer should be rotated by other way.
98 * This is not what we want.
102 *x = (double)_x * cos((double)_angle) - (double)_y * sin((double)_angle);
103 *y = (double)_x * sin((double)_angle) + (double)_y * cos((double)_angle);
110 * Every user event (mouse) on the buffer will be passed via this event callback
112 static int event_handler_cb(widget_buffer_h handler, struct widget_buffer_event_data *event_info, void *data)
114 vwin_info_t info = data;
115 Elm_Access_Action_Info action_info;
116 Elm_Access_Action_Type action_type;
118 Evas_Object *parent_elm;
120 unsigned int flags = 0;
123 if (!info || info->state != VWIN_INFO_CREATED || !info->handle) {
124 /* Just ignore this event */
128 if (WIDGET_CONF_USE_GETTIMEOFDAY) {
129 if (WIDGET_CONF_EVENT_FILTER > 0.0f && (info->pressed == 0 || event_info->type == WIDGET_BUFFER_EVENT_MOVE)) {
132 if (gettimeofday(&tv, NULL) < 0) {
133 ErrPrint("gettimeofday: %d\n", errno);
135 timestamp = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
136 timestamp -= event_info->timestamp;
138 if (timestamp > WIDGET_CONF_EVENT_FILTER) {
139 DbgPrint("Dropped %lf\n", timestamp);
146 * If the device doesn't use the clock monotic time, we have to emulate it for EVAS
147 * Evas only use the monotic time for animating objects
149 timestamp = ecore_time_get() * 1000.0f;
151 if (WIDGET_CONF_EVENT_FILTER > 0.0f && (info->pressed == 0 || event_info->type == WIDGET_BUFFER_EVENT_MOVE)) {
152 timestamp = ecore_time_get();
154 timestamp -= event_info->timestamp;
155 if (timestamp > WIDGET_CONF_EVENT_FILTER) {
156 DbgPrint("Dropped %lf\n", timestamp);
161 timestamp = event_info->timestamp * 1000.0f;
168 switch (event_info->type) {
169 case WIDGET_BUFFER_EVENT_ON_HOLD:
170 flags = evas_event_default_flags_get(info->e);
171 flags |= EVAS_EVENT_FLAG_ON_HOLD;
172 evas_event_default_flags_set(info->e, flags);
173 ErrPrint("ON_HOLD[%s] %dx%d - %lf\n", info->id, event_info->info.pointer.x, event_info->info.pointer.y, timestamp);
175 case WIDGET_BUFFER_EVENT_OFF_HOLD:
176 flags = evas_event_default_flags_get(info->e);
177 flags &= ~EVAS_EVENT_FLAG_ON_HOLD;
178 evas_event_default_flags_set(info->e, flags);
180 case WIDGET_BUFFER_EVENT_ON_SCROLL:
181 flags = evas_event_default_flags_get(info->e);
182 flags |= EVAS_EVENT_FLAG_ON_SCROLL;
183 evas_event_default_flags_set(info->e, flags);
185 case WIDGET_BUFFER_EVENT_OFF_SCROLL:
186 flags = evas_event_default_flags_get(info->e);
187 flags &= ~EVAS_EVENT_FLAG_ON_SCROLL;
188 evas_event_default_flags_set(info->e, flags);
190 case WIDGET_BUFFER_EVENT_ENTER:
191 evas_event_feed_mouse_in(info->e, timestamp, NULL);
193 case WIDGET_BUFFER_EVENT_LEAVE:
194 evas_event_feed_mouse_out(info->e, timestamp, NULL);
196 case WIDGET_BUFFER_EVENT_DOWN:
197 apply_orientation(info->orientation, &event_info->info.pointer.x, &event_info->info.pointer.y, info->w, info->h, event_info->info.pointer.source);
200 ErrPrint("MOUSE UP is not called\n");
201 ErrPrint("UP[%s] %dx%d - %lf\n", info->id, event_info->info.pointer.x, event_info->info.pointer.y, timestamp);
202 evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, timestamp, NULL);
203 evas_event_feed_mouse_up(info->e, 1, EVAS_BUTTON_NONE, timestamp, NULL);
208 * Before processing the DOWN event,
209 * Reset the evas event flags regarding ON_HOLD option.
210 * It can be re-enabled while processing down-move-up events.
212 flags = evas_event_default_flags_get(info->e);
213 flags &= ~EVAS_EVENT_FLAG_ON_SCROLL;
214 flags &= ~EVAS_EVENT_FLAG_ON_HOLD;
215 evas_event_default_flags_set(info->e, flags);
218 * Calculate the event occurred X & Y on the buffer
220 evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, timestamp, NULL);
221 evas_event_feed_mouse_down(info->e, 1, EVAS_BUTTON_NONE, timestamp, NULL); /* + 0.2f just for fake event */
223 ErrPrint("DOWN[%s] %dx%d - %lf\n", info->id, event_info->info.pointer.x, event_info->info.pointer.y, timestamp);
225 case WIDGET_BUFFER_EVENT_MOVE:
226 apply_orientation(info->orientation, &event_info->info.pointer.x, &event_info->info.pointer.y, info->w, info->h, event_info->info.pointer.source);
229 * Calculate the event occurred X & Y on the buffer
231 evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, timestamp, NULL);
233 case WIDGET_BUFFER_EVENT_UP:
234 apply_orientation(info->orientation, &event_info->info.pointer.x, &event_info->info.pointer.y, info->w, info->h, event_info->info.pointer.source);
235 evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, timestamp, NULL);
236 evas_event_feed_mouse_up(info->e, 1, EVAS_BUTTON_NONE, timestamp, NULL);
240 * We have to keep the event flags, so we should not clear them from here.
241 * Sometimes, asynchronously callable Callbacks can refer the evas event flags after up event.
242 * so if we reset them from here, those kind of callbacks will fails to do their job properly.
244 ErrPrint("UP[%s] %dx%d - %lf\n", info->id, event_info->info.pointer.x, event_info->info.pointer.y, timestamp);
246 case WIDGET_BUFFER_EVENT_ACCESS_HIGHLIGHT:
247 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
249 ret = WIDGET_ACCESS_STATUS_ERROR;
252 memset(&action_info, 0, sizeof(action_info));
253 action_type = 0; //ELM_ACCESS_ACTION_HIGHLIGHT;
256 * Calculate the event occurred X & Y on the buffer
258 action_info.x = event_info->info.access.x;
259 action_info.y = event_info->info.access.y;
260 ret = elm_access_action(parent_elm, action_type, &action_info);
261 if (ret == EINA_TRUE) {
262 if (!get_highlighted_object(parent_elm)) {
263 ErrPrint("Highlighted object is not found\n");
264 ret = WIDGET_ACCESS_STATUS_ERROR;
266 DbgPrint("Highlighted object is found\n");
267 ret = WIDGET_ACCESS_STATUS_DONE;
270 ErrPrint("Action error\n");
271 ret = WIDGET_ACCESS_STATUS_ERROR;
274 case WIDGET_BUFFER_EVENT_ACCESS_HIGHLIGHT_NEXT:
275 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
277 ret = WIDGET_ACCESS_STATUS_ERROR;
280 memset(&action_info, 0, sizeof(action_info));
281 action_type = 0; //ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
282 action_info.highlight_cycle = EINA_FALSE;
283 ret = elm_access_action(parent_elm, action_type, &action_info);
284 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_LAST : WIDGET_ACCESS_STATUS_DONE;
286 case WIDGET_BUFFER_EVENT_ACCESS_HIGHLIGHT_PREV:
287 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
289 ret = WIDGET_ACCESS_STATUS_ERROR;
292 memset(&action_info, 0, sizeof(action_info));
293 action_type = 0; //ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
294 action_info.highlight_cycle = EINA_FALSE;
295 ret = elm_access_action(parent_elm, action_type, &action_info);
296 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_FIRST : WIDGET_ACCESS_STATUS_DONE;
298 case WIDGET_BUFFER_EVENT_ACCESS_ACTIVATE:
299 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
301 ret = WIDGET_ACCESS_STATUS_ERROR;
304 memset(&action_info, 0, sizeof(action_info));
305 action_type = 0; //ELM_ACCESS_ACTION_ACTIVATE;
306 ret = elm_access_action(parent_elm, action_type, &action_info);
307 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
309 case WIDGET_BUFFER_EVENT_ACCESS_ACTION_UP:
310 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
312 ret = WIDGET_ACCESS_STATUS_ERROR;
315 memset(&action_info, 0, sizeof(action_info));
316 action_type = 0; //ELM_ACCESS_ACTION_UP;
317 ret = elm_access_action(parent_elm, action_type, &action_info);
318 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
320 case WIDGET_BUFFER_EVENT_ACCESS_ACTION_DOWN:
321 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
323 ret = WIDGET_ACCESS_STATUS_ERROR;
326 memset(&action_info, 0, sizeof(action_info));
327 action_type = 0; //ELM_ACCESS_ACTION_DOWN;
328 ret = elm_access_action(parent_elm, action_type, &action_info);
329 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
331 case WIDGET_BUFFER_EVENT_ACCESS_SCROLL_UP:
332 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
334 ret = WIDGET_ACCESS_STATUS_ERROR;
337 memset(&action_info, 0, sizeof(action_info));
338 action_type = 0; //ELM_ACCESS_ACTION_SCROLL;
339 action_info.x = event_info->info.access.x;
340 action_info.y = event_info->info.access.y;
341 action_info.mouse_type = event_info->info.access.mouse_type;
342 ret = elm_access_action(parent_elm, action_type, &action_info);
343 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
345 case WIDGET_BUFFER_EVENT_ACCESS_SCROLL_MOVE:
346 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
348 ret = WIDGET_ACCESS_STATUS_ERROR;
351 memset(&action_info, 0, sizeof(action_info));
352 action_type = 0; //ELM_ACCESS_ACTION_SCROLL;
353 action_info.x = event_info->info.access.x;
354 action_info.y = event_info->info.access.y;
355 action_info.mouse_type = event_info->info.access.mouse_type;
356 ret = elm_access_action(parent_elm, action_type, &action_info);
357 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
359 case WIDGET_BUFFER_EVENT_ACCESS_SCROLL_DOWN:
360 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
362 ret = WIDGET_ACCESS_STATUS_ERROR;
365 memset(&action_info, 0, sizeof(action_info));
366 action_type = 0; //ELM_ACCESS_ACTION_SCROLL;
367 action_info.x = event_info->info.access.x;
368 action_info.y = event_info->info.access.y;
369 action_info.mouse_type = event_info->info.access.mouse_type;
370 ret = elm_access_action(parent_elm, action_type, &action_info);
371 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
373 case WIDGET_BUFFER_EVENT_ACCESS_UNHIGHLIGHT:
374 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
376 ret = WIDGET_ACCESS_STATUS_ERROR;
379 memset(&action_info, 0, sizeof(action_info));
380 action_type = 0; //ELM_ACCESS_ACTION_UNHIGHLIGHT;
381 ret = elm_access_action(parent_elm, action_type, &action_info);
382 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
384 case WIDGET_BUFFER_EVENT_ACCESS_VALUE_CHANGE:
385 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
387 ret = WIDGET_ACCESS_STATUS_ERROR;
390 memset(&action_info, 0, sizeof(action_info));
391 action_type = 0; //ELM_ACCESS_ACTION_VALUE_CHANGE;
392 action_info.x = event_info->info.access.x;
393 action_info.y = event_info->info.access.y;
394 action_info.mouse_type = event_info->info.access.mouse_type;
395 ret = elm_access_action(parent_elm, action_type, &action_info);
396 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
398 case WIDGET_BUFFER_EVENT_ACCESS_MOUSE:
399 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
401 ret = WIDGET_ACCESS_STATUS_ERROR;
404 memset(&action_info, 0, sizeof(action_info));
405 action_type = 0; //ELM_ACCESS_ACTION_MOUSE;
406 action_info.x = event_info->info.access.x;
407 action_info.y = event_info->info.access.y;
408 action_info.mouse_type = event_info->info.access.mouse_type;
409 ret = elm_access_action(parent_elm, action_type, &action_info);
410 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
412 case WIDGET_BUFFER_EVENT_ACCESS_BACK:
413 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
415 ret = WIDGET_ACCESS_STATUS_ERROR;
418 memset(&action_info, 0, sizeof(action_info));
419 action_type = 0; //ELM_ACCESS_ACTION_BACK;
420 action_info.x = event_info->info.access.x;
421 action_info.y = event_info->info.access.y;
422 action_info.mouse_type = event_info->info.access.mouse_type;
423 ret = elm_access_action(parent_elm, action_type, &action_info);
424 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
426 case WIDGET_BUFFER_EVENT_ACCESS_OVER:
427 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
429 ret = WIDGET_ACCESS_STATUS_ERROR;
432 memset(&action_info, 0, sizeof(action_info));
433 action_type = 0; //ELM_ACCESS_ACTION_OVER;
434 action_info.x = event_info->info.access.x;
435 action_info.y = event_info->info.access.y;
436 action_info.mouse_type = event_info->info.access.mouse_type;
437 ret = elm_access_action(parent_elm, action_type, &action_info);
438 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
440 case WIDGET_BUFFER_EVENT_ACCESS_READ:
441 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
443 ret = WIDGET_ACCESS_STATUS_ERROR;
446 memset(&action_info, 0, sizeof(action_info));
447 action_type = 0; //ELM_ACCESS_ACTION_READ;
448 action_info.x = event_info->info.access.x;
449 action_info.y = event_info->info.access.y;
450 action_info.mouse_type = event_info->info.access.mouse_type;
451 ret = elm_access_action(parent_elm, action_type, &action_info);
452 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
454 case WIDGET_BUFFER_EVENT_ACCESS_ENABLE:
455 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
457 ret = WIDGET_ACCESS_STATUS_ERROR;
460 memset(&action_info, 0, sizeof(action_info));
461 action_type = 0; //ELM_ACCESS_ACTION_ENABLE;
462 action_info.x = event_info->info.access.x;
463 action_info.y = event_info->info.access.y;
464 action_info.mouse_type = event_info->info.access.mouse_type;
465 ret = elm_access_action(parent_elm, action_type, &action_info);
466 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
468 case WIDGET_BUFFER_EVENT_ACCESS_DISABLE:
469 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
471 ret = WIDGET_ACCESS_STATUS_ERROR;
474 memset(&action_info, 0, sizeof(action_info));
475 action_type = 0; //ELM_ACCESS_ACTION_DISABLE;
476 action_info.x = event_info->info.access.x;
477 action_info.y = event_info->info.access.y;
478 action_info.mouse_type = event_info->info.access.mouse_type;
479 ret = elm_access_action(parent_elm, action_type, &action_info);
480 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
482 case WIDGET_BUFFER_EVENT_KEY_DOWN:
483 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
485 ret = WIDGET_ACCESS_STATUS_ERROR;
489 key_symbol = XGetKeyboardMapping(ecore_x_display_get(), event_info->info.keycode, 1, &ret);
494 key_string = XKeysymToString(*key_symbol);
495 key_name = XKeysymToString(*key_symbol);
496 DbgPrint("Key symbol: %s, name: %s\n", key_string, key_name);
501 ret = WIDGET_KEY_STATUS_ERROR;
503 case WIDGET_BUFFER_EVENT_KEY_UP:
504 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
506 ret = WIDGET_ACCESS_STATUS_ERROR;
510 key_symbol = XGetKeyboardMapping(ecore_x_display_get(), event_info->info.keycode, 1, &ret);
515 key_string = XKeysymToString(*key_symbol);
516 key_name = XKeysymToString(*key_symbol);
517 DbgPrint("Key symbol: %s, name: %s\n", key_string, key_name);
522 ret = WIDGET_KEY_STATUS_ERROR;
524 case WIDGET_BUFFER_EVENT_KEY_FOCUS_IN:
525 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
527 ret = WIDGET_ACCESS_STATUS_ERROR;
531 key_symbol = XGetKeyboardMapping(ecore_x_display_get(), event_info->info.keycode, 1, &ret);
536 key_string = XKeysymToString(*key_symbol);
537 key_name = XKeysymToString(*key_symbol);
538 DbgPrint("Key symbol: %s, name: %s\n", key_string, key_name);
543 ret = WIDGET_KEY_STATUS_ERROR;
545 case WIDGET_BUFFER_EVENT_KEY_FOCUS_OUT:
546 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
548 ret = WIDGET_ACCESS_STATUS_ERROR;
552 key_symbol = XGetKeyboardMapping(ecore_x_display_get(), event_info->info.keycode, 1, &ret);
557 key_string = XKeysymToString(*key_symbol);
558 key_name = XKeysymToString(*key_symbol);
559 DbgPrint("Key symbol: %s, name: %s\n", key_string, key_name);
564 ret = WIDGET_KEY_STATUS_ERROR;
567 DbgPrint("Unhandled buffer event (%d)\n", event_info->type);
574 static void pre_render_cb(void *data, Evas *e, void *event_info)
576 vwin_info_t info = data;
578 if (!info || info->state != VWIN_INFO_CREATED || !info->handle) {
582 if (widget_conf_premultiplied_alpha()) {
586 ecore_evas_geometry_get(info->ee, NULL, NULL, &w, &h);
587 evas_damage_rectangle_add(e, 0, 0, w, h);
590 if (info->type == VWIN_GEM) {
591 widget_buffer_pre_render(info->handle);
592 } else if (info->type == VWIN_PIXMAP) {
594 * Only the pixmap type Ecore_Evas uses this variable
596 } else if (info->type == VWIN_SW_BUF) {
601 static void post_render_cb(void *data, Evas *e, void *event_info)
603 vwin_info_t info = data;
605 if (!info || info->state != VWIN_INFO_CREATED || !info->handle) {
609 if (widget_conf_premultiplied_alpha()) {
613 // Get a pointer of a buffer of the virtual canvas
614 canvas = (void *)ecore_evas_buffer_pixels_get(info->ee);
616 ErrPrint("Failed to get pixel canvas\n");
620 ecore_evas_geometry_get(info->ee, &x, &y, &w, &h);
621 evas_data_argb_unpremul(canvas, w * h);
624 if (info->type == VWIN_GEM) {
625 widget_buffer_post_render(info->handle);
626 } else if (info->type == VWIN_PIXMAP) {
628 unsigned int front_resource_id;
630 front_resource_id = ecore_evas_gl_x11_pixmap_get(info->ee);
632 for (idx = 0; idx < WIDGET_CONF_EXTRA_BUFFER_COUNT; idx++) {
633 if (front_resource_id == info->resource_array[idx]) {
636 widget_send_updated_by_idx(info->handle, idx);
641 if (idx == WIDGET_CONF_EXTRA_BUFFER_COUNT) {
642 /* Send updated event for PRIMARY BUFFER */
643 if (front_resource_id == widget_viewer_get_resource_id(info->handle, WIDGET_PRIMARY_BUFFER)) {
644 widget_send_updated_by_idx(info->handle, WIDGET_PRIMARY_BUFFER);
646 DbgPrint("Unable to send updated: %u (%u)\n", front_resource_id, widget_viewer_get_resource_id(info->handle, WIDGET_PRIMARY_BUFFER));
649 } else if (info->type == VWIN_SW_BUF) {
650 widget_viewer_sync_buffer(info->handle);
654 static int pre_orientation_cb(const char *id, void *data)
656 vwin_info_t info = data;
660 /* Try provider_app first */
661 if (!info || info->state != VWIN_INFO_CREATED || !id) {
662 return WIDGET_ERROR_INVALID_PARAMETER;
665 path = widget_util_uri_to_path(id);
666 if (path && strcmp(info->id, path)) {
668 DbgPrint("SKIP: Pre orientation event callback is called [%s], %s\n", id, info->id);
669 return WIDGET_ERROR_INVALID_PARAMETER;
672 DbgPrint("Pre orientation event callback is called [%s]\n", id);
673 orientation = widget_get_orientation(path);
674 if (orientation < 0) {
675 ErrPrint("Failed to get orientation: %X\n", orientation);
677 info->orientation = orientation;
680 return WIDGET_ERROR_NONE;
683 static int pre_destroy_cb(const char *id, void *data)
685 vwin_info_t info = data;
686 const char *path = NULL;
688 if (!info || info->state != VWIN_INFO_CREATED) {
689 return WIDGET_ERROR_INVALID_PARAMETER;
693 path = widget_util_uri_to_path(id);
695 if (path && strcmp(info->id, path)) {
697 DbgPrint("SKIP: Pre destroy event callback is called [%s], %s\n", id, info->id);
698 return WIDGET_ERROR_INVALID_PARAMETER;
702 DbgPrint("Pre destroy event callback is called [%s]\n", id);
705 DbgPrint("Toggle manual render mode to prevent from unwanted rendering");
706 ecore_evas_manual_render_set(info->ee, EINA_TRUE);
709 return WIDGET_ERROR_NONE;
712 static void ecore_evas_free_cb(Ecore_Evas *ee)
716 info = ecore_evas_data_get(ee, WIN_INFO_TAG);
718 DbgPrint("Info is not valid\n");
722 widget_del_pre_callback(WIDGET_PRE_DESTROY_CALLBACK, pre_destroy_cb, info);
725 evas_event_callback_del(info->e, EVAS_CALLBACK_RENDER_POST, post_render_cb);
726 evas_event_callback_del(info->e, EVAS_CALLBACK_RENDER_PRE, pre_render_cb);
733 #ifdef WIDGET_FEATURE_GBAR_SUPPORTED
734 PUBLIC Evas *widget_get_evas(const char *id, int is_gbar)
735 #else /* WIDGET_FEATURE_GBAR_SUPPORTED */
736 PUBLIC Evas *widget_get_evas(const char *id)
737 #endif /* WIDGET_FEATURE_GBAR_SUPPORTED */
744 * If the evas object is already created,
745 * this function should returns ERROR.
749 ErrPrint("Invalid parameter\n");
753 info = calloc(1, sizeof(*info));
755 ErrPrint("Heap: %d\n", errno);
759 info->state = VWIN_INFO_CREATED;
761 info->id = strdup(id);
763 ErrPrint("Heap: %d\n", errno);
764 info->state = VWIN_INFO_DESTROYED;
769 #ifdef WIDGET_FEATURE_GBAR_SUPPORTED
770 info->is_gbar = is_gbar;
773 #endif /* WIDGET_FEATURE_GBAR_SUPPORTED */
776 * Acquire a buffer for canvas.
778 info->handle = widget_create_buffer(info->id, info->is_gbar,
779 binder_widget_auto_align(),
780 event_handler_cb, info);
783 ErrPrint("Failed to create a widget buffer\n");
784 info->state = VWIN_INFO_DESTROYED;
791 * Size information must be initialized before call the ecore_evas_buffer_new.
793 info->w = WIDGET_DEFAULT_WIDTH;
794 info->h = WIDGET_DEFAULT_HEIGHT;
796 info->ee = binder_ecore_evas_new(info);
798 ErrPrint("Failed to create ecore_evas (%dx%d)\n", info->w, info->h);
799 widget_destroy_buffer(info->handle);
800 info->state = VWIN_INFO_DESTROYED;
806 ecore_evas_data_set(info->ee, WIN_INFO_TAG, info);
810 * Free callback must be prepared before use the ecore_evas_free()
812 ecore_evas_callback_pre_free_set(info->ee, ecore_evas_free_cb);
814 info->e = ecore_evas_get(info->ee);
816 ErrPrint("Failed to get evas\n");
817 ecore_evas_free(info->ee);
821 pre_render_cb(info, NULL, NULL);
822 ecore_evas_alpha_set(info->ee, EINA_TRUE);
823 post_render_cb(info, NULL, NULL);
825 ecore_evas_manual_render_set(info->ee, EINA_FALSE);
826 ecore_evas_resize(info->ee, info->w, info->h);
828 evas_event_callback_add(info->e, EVAS_CALLBACK_RENDER_POST, post_render_cb, info);
829 evas_event_callback_add(info->e, EVAS_CALLBACK_RENDER_PRE, pre_render_cb, info);
831 widget_add_pre_callback(WIDGET_PRE_DESTROY_CALLBACK, pre_destroy_cb, info);
832 widget_add_pre_callback(WIDGET_PRE_ORIENTATION_CALLBACK, pre_orientation_cb, info);
834 orientation = widget_get_orientation(info->id);
835 if (orientation < 0) {
836 ErrPrint("Failed to get orientation[%s]: %X\n", info->id, orientation);
838 info->orientation = orientation;