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);
108 static inline int processing_events(vwin_info_t info, widget_buffer_event_data_t event_info, double timestamp)
110 Elm_Access_Action_Info action_info;
111 Elm_Access_Action_Type action_type;
112 Evas_Object *parent_elm;
114 unsigned int flags = 0;
120 switch (event_info->type) {
121 case WIDGET_BUFFER_EVENT_ON_HOLD:
122 flags = evas_event_default_flags_get(info->e);
123 flags |= EVAS_EVENT_FLAG_ON_HOLD;
124 evas_event_default_flags_set(info->e, flags);
125 ErrPrint("ON_HOLD[%s] %dx%d - %lf\n", info->id, event_info->info.pointer.x, event_info->info.pointer.y, timestamp);
127 case WIDGET_BUFFER_EVENT_OFF_HOLD:
128 flags = evas_event_default_flags_get(info->e);
129 flags &= ~EVAS_EVENT_FLAG_ON_HOLD;
130 evas_event_default_flags_set(info->e, flags);
132 case WIDGET_BUFFER_EVENT_ON_SCROLL:
133 flags = evas_event_default_flags_get(info->e);
134 flags |= EVAS_EVENT_FLAG_ON_SCROLL;
135 evas_event_default_flags_set(info->e, flags);
137 case WIDGET_BUFFER_EVENT_OFF_SCROLL:
138 flags = evas_event_default_flags_get(info->e);
139 flags &= ~EVAS_EVENT_FLAG_ON_SCROLL;
140 evas_event_default_flags_set(info->e, flags);
142 case WIDGET_BUFFER_EVENT_ENTER:
143 evas_event_feed_mouse_in(info->e, timestamp, NULL);
145 case WIDGET_BUFFER_EVENT_LEAVE:
146 evas_event_feed_mouse_out(info->e, timestamp, NULL);
148 case WIDGET_BUFFER_EVENT_DOWN:
149 apply_orientation(info->orientation, &event_info->info.pointer.x, &event_info->info.pointer.y, info->w, info->h, event_info->info.pointer.source);
152 ErrPrint("MOUSE UP is not called\n");
153 ErrPrint("UP[%s] %dx%d - %lf\n", info->id, event_info->info.pointer.x, event_info->info.pointer.y, timestamp);
154 evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, timestamp, NULL);
155 evas_event_feed_mouse_up(info->e, 1, EVAS_BUTTON_NONE, timestamp, NULL);
160 * Before processing the DOWN event,
161 * Reset the evas event flags regarding ON_HOLD option.
162 * It can be re-enabled while processing down-move-up events.
164 flags = evas_event_default_flags_get(info->e);
165 flags &= ~EVAS_EVENT_FLAG_ON_SCROLL;
166 flags &= ~EVAS_EVENT_FLAG_ON_HOLD;
167 evas_event_default_flags_set(info->e, flags);
170 * Calculate the event occurred X & Y on the buffer
172 evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, timestamp, NULL);
173 evas_event_feed_mouse_down(info->e, 1, EVAS_BUTTON_NONE, timestamp, NULL); /* + 0.2f just for fake event */
175 ErrPrint("DOWN[%s] %dx%d - %lf\n", info->id, event_info->info.pointer.x, event_info->info.pointer.y, timestamp);
177 case WIDGET_BUFFER_EVENT_MOVE:
178 apply_orientation(info->orientation, &event_info->info.pointer.x, &event_info->info.pointer.y, info->w, info->h, event_info->info.pointer.source);
181 * Calculate the event occurred X & Y on the buffer
183 evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, timestamp, NULL);
185 case WIDGET_BUFFER_EVENT_UP:
186 apply_orientation(info->orientation, &event_info->info.pointer.x, &event_info->info.pointer.y, info->w, info->h, event_info->info.pointer.source);
187 evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, timestamp, NULL);
188 evas_event_feed_mouse_up(info->e, 1, EVAS_BUTTON_NONE, timestamp, NULL);
192 * We have to keep the event flags, so we should not clear them from here.
193 * Sometimes, asynchronously callable Callbacks can refer the evas event flags after up event.
194 * so if we reset them from here, those kind of callbacks will fails to do their job properly.
196 ErrPrint("UP[%s] %dx%d - %lf\n", info->id, event_info->info.pointer.x, event_info->info.pointer.y, timestamp);
198 case WIDGET_BUFFER_EVENT_ACCESS_HIGHLIGHT:
199 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
201 ret = WIDGET_ACCESS_STATUS_ERROR;
204 memset(&action_info, 0, sizeof(action_info));
205 action_type = 0; //ELM_ACCESS_ACTION_HIGHLIGHT;
208 * Calculate the event occurred X & Y on the buffer
210 action_info.x = event_info->info.access.x;
211 action_info.y = event_info->info.access.y;
212 ret = elm_access_action(parent_elm, action_type, &action_info);
213 if (ret == EINA_TRUE) {
214 if (!get_highlighted_object(parent_elm)) {
215 ErrPrint("Highlighted object is not found\n");
216 ret = WIDGET_ACCESS_STATUS_ERROR;
218 DbgPrint("Highlighted object is found\n");
219 ret = WIDGET_ACCESS_STATUS_DONE;
222 ErrPrint("Action error\n");
223 ret = WIDGET_ACCESS_STATUS_ERROR;
226 case WIDGET_BUFFER_EVENT_ACCESS_HIGHLIGHT_NEXT:
227 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
229 ret = WIDGET_ACCESS_STATUS_ERROR;
232 memset(&action_info, 0, sizeof(action_info));
233 action_type = 0; //ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
234 action_info.highlight_cycle = EINA_FALSE;
235 ret = elm_access_action(parent_elm, action_type, &action_info);
236 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_LAST : WIDGET_ACCESS_STATUS_DONE;
238 case WIDGET_BUFFER_EVENT_ACCESS_HIGHLIGHT_PREV:
239 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
241 ret = WIDGET_ACCESS_STATUS_ERROR;
244 memset(&action_info, 0, sizeof(action_info));
245 action_type = 0; //ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
246 action_info.highlight_cycle = EINA_FALSE;
247 ret = elm_access_action(parent_elm, action_type, &action_info);
248 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_FIRST : WIDGET_ACCESS_STATUS_DONE;
250 case WIDGET_BUFFER_EVENT_ACCESS_ACTIVATE:
251 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
253 ret = WIDGET_ACCESS_STATUS_ERROR;
256 memset(&action_info, 0, sizeof(action_info));
257 action_type = 0; //ELM_ACCESS_ACTION_ACTIVATE;
258 ret = elm_access_action(parent_elm, action_type, &action_info);
259 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
261 case WIDGET_BUFFER_EVENT_ACCESS_ACTION_UP:
262 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
264 ret = WIDGET_ACCESS_STATUS_ERROR;
267 memset(&action_info, 0, sizeof(action_info));
268 action_type = 0; //ELM_ACCESS_ACTION_UP;
269 ret = elm_access_action(parent_elm, action_type, &action_info);
270 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
272 case WIDGET_BUFFER_EVENT_ACCESS_ACTION_DOWN:
273 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
275 ret = WIDGET_ACCESS_STATUS_ERROR;
278 memset(&action_info, 0, sizeof(action_info));
279 action_type = 0; //ELM_ACCESS_ACTION_DOWN;
280 ret = elm_access_action(parent_elm, action_type, &action_info);
281 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
283 case WIDGET_BUFFER_EVENT_ACCESS_SCROLL_UP:
284 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
286 ret = WIDGET_ACCESS_STATUS_ERROR;
289 memset(&action_info, 0, sizeof(action_info));
290 action_type = 0; //ELM_ACCESS_ACTION_SCROLL;
291 action_info.x = event_info->info.access.x;
292 action_info.y = event_info->info.access.y;
293 action_info.mouse_type = event_info->info.access.mouse_type;
294 ret = elm_access_action(parent_elm, action_type, &action_info);
295 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
297 case WIDGET_BUFFER_EVENT_ACCESS_SCROLL_MOVE:
298 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
300 ret = WIDGET_ACCESS_STATUS_ERROR;
303 memset(&action_info, 0, sizeof(action_info));
304 action_type = 0; //ELM_ACCESS_ACTION_SCROLL;
305 action_info.x = event_info->info.access.x;
306 action_info.y = event_info->info.access.y;
307 action_info.mouse_type = event_info->info.access.mouse_type;
308 ret = elm_access_action(parent_elm, action_type, &action_info);
309 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
311 case WIDGET_BUFFER_EVENT_ACCESS_SCROLL_DOWN:
312 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
314 ret = WIDGET_ACCESS_STATUS_ERROR;
317 memset(&action_info, 0, sizeof(action_info));
318 action_type = 0; //ELM_ACCESS_ACTION_SCROLL;
319 action_info.x = event_info->info.access.x;
320 action_info.y = event_info->info.access.y;
321 action_info.mouse_type = event_info->info.access.mouse_type;
322 ret = elm_access_action(parent_elm, action_type, &action_info);
323 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
325 case WIDGET_BUFFER_EVENT_ACCESS_UNHIGHLIGHT:
326 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
328 ret = WIDGET_ACCESS_STATUS_ERROR;
331 memset(&action_info, 0, sizeof(action_info));
332 action_type = 0; //ELM_ACCESS_ACTION_UNHIGHLIGHT;
333 ret = elm_access_action(parent_elm, action_type, &action_info);
334 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
336 case WIDGET_BUFFER_EVENT_ACCESS_VALUE_CHANGE:
337 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
339 ret = WIDGET_ACCESS_STATUS_ERROR;
342 memset(&action_info, 0, sizeof(action_info));
343 action_type = 0; //ELM_ACCESS_ACTION_VALUE_CHANGE;
344 action_info.x = event_info->info.access.x;
345 action_info.y = event_info->info.access.y;
346 action_info.mouse_type = event_info->info.access.mouse_type;
347 ret = elm_access_action(parent_elm, action_type, &action_info);
348 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
350 case WIDGET_BUFFER_EVENT_ACCESS_MOUSE:
351 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
353 ret = WIDGET_ACCESS_STATUS_ERROR;
356 memset(&action_info, 0, sizeof(action_info));
357 action_type = 0; //ELM_ACCESS_ACTION_MOUSE;
358 action_info.x = event_info->info.access.x;
359 action_info.y = event_info->info.access.y;
360 action_info.mouse_type = event_info->info.access.mouse_type;
361 ret = elm_access_action(parent_elm, action_type, &action_info);
362 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
364 case WIDGET_BUFFER_EVENT_ACCESS_BACK:
365 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
367 ret = WIDGET_ACCESS_STATUS_ERROR;
370 memset(&action_info, 0, sizeof(action_info));
371 action_type = 0; //ELM_ACCESS_ACTION_BACK;
372 action_info.x = event_info->info.access.x;
373 action_info.y = event_info->info.access.y;
374 action_info.mouse_type = event_info->info.access.mouse_type;
375 ret = elm_access_action(parent_elm, action_type, &action_info);
376 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
378 case WIDGET_BUFFER_EVENT_ACCESS_OVER:
379 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
381 ret = WIDGET_ACCESS_STATUS_ERROR;
384 memset(&action_info, 0, sizeof(action_info));
385 action_type = 0; //ELM_ACCESS_ACTION_OVER;
386 action_info.x = event_info->info.access.x;
387 action_info.y = event_info->info.access.y;
388 action_info.mouse_type = event_info->info.access.mouse_type;
389 ret = elm_access_action(parent_elm, action_type, &action_info);
390 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
392 case WIDGET_BUFFER_EVENT_ACCESS_READ:
393 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
395 ret = WIDGET_ACCESS_STATUS_ERROR;
398 memset(&action_info, 0, sizeof(action_info));
399 action_type = 0; //ELM_ACCESS_ACTION_READ;
400 action_info.x = event_info->info.access.x;
401 action_info.y = event_info->info.access.y;
402 action_info.mouse_type = event_info->info.access.mouse_type;
403 ret = elm_access_action(parent_elm, action_type, &action_info);
404 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
406 case WIDGET_BUFFER_EVENT_ACCESS_ENABLE:
407 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
409 ret = WIDGET_ACCESS_STATUS_ERROR;
412 memset(&action_info, 0, sizeof(action_info));
413 action_type = 0; //ELM_ACCESS_ACTION_ENABLE;
414 action_info.x = event_info->info.access.x;
415 action_info.y = event_info->info.access.y;
416 action_info.mouse_type = event_info->info.access.mouse_type;
417 ret = elm_access_action(parent_elm, action_type, &action_info);
418 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
420 case WIDGET_BUFFER_EVENT_ACCESS_DISABLE:
421 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
423 ret = WIDGET_ACCESS_STATUS_ERROR;
426 memset(&action_info, 0, sizeof(action_info));
427 action_type = 0; //ELM_ACCESS_ACTION_DISABLE;
428 action_info.x = event_info->info.access.x;
429 action_info.y = event_info->info.access.y;
430 action_info.mouse_type = event_info->info.access.mouse_type;
431 ret = elm_access_action(parent_elm, action_type, &action_info);
432 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
434 case WIDGET_BUFFER_EVENT_KEY_DOWN:
435 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
437 ret = WIDGET_ACCESS_STATUS_ERROR;
441 key_symbol = XGetKeyboardMapping(ecore_x_display_get(), event_info->info.keycode, 1, &ret);
446 key_string = XKeysymToString(*key_symbol);
447 key_name = XKeysymToString(*key_symbol);
448 DbgPrint("Key symbol: %s, name: %s\n", key_string, key_name);
453 ret = WIDGET_KEY_STATUS_ERROR;
455 case WIDGET_BUFFER_EVENT_KEY_UP:
456 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
458 ret = WIDGET_ACCESS_STATUS_ERROR;
462 key_symbol = XGetKeyboardMapping(ecore_x_display_get(), event_info->info.keycode, 1, &ret);
467 key_string = XKeysymToString(*key_symbol);
468 key_name = XKeysymToString(*key_symbol);
469 DbgPrint("Key symbol: %s, name: %s\n", key_string, key_name);
474 ret = WIDGET_KEY_STATUS_ERROR;
476 case WIDGET_BUFFER_EVENT_KEY_FOCUS_IN:
477 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
479 ret = WIDGET_ACCESS_STATUS_ERROR;
483 key_symbol = XGetKeyboardMapping(ecore_x_display_get(), event_info->info.keycode, 1, &ret);
488 key_string = XKeysymToString(*key_symbol);
489 key_name = XKeysymToString(*key_symbol);
490 DbgPrint("Key symbol: %s, name: %s\n", key_string, key_name);
495 ret = WIDGET_KEY_STATUS_ERROR;
497 case WIDGET_BUFFER_EVENT_KEY_FOCUS_OUT:
498 parent_elm = ecore_evas_data_get(info->ee, WIDGET_WIN_TAG);
500 ret = WIDGET_ACCESS_STATUS_ERROR;
504 key_symbol = XGetKeyboardMapping(ecore_x_display_get(), event_info->info.keycode, 1, &ret);
509 key_string = XKeysymToString(*key_symbol);
510 key_name = XKeysymToString(*key_symbol);
511 DbgPrint("Key symbol: %s, name: %s\n", key_string, key_name);
516 ret = WIDGET_KEY_STATUS_ERROR;
519 DbgPrint("Unhandled buffer event (%d)\n", event_info->type);
525 static Eina_Bool pended_event_consumer_cb(void *data)
527 vwin_info_t info = data;
528 widget_buffer_event_data_t event_info;
530 event_info = eina_list_nth(info->pended_events_list, 0);
532 info->pended_events_consumer = NULL;
533 return ECORE_CALLBACK_CANCEL;
536 DbgPrint("Consuming delayed events\n");
537 (void)processing_events(info, event_info, event_info->timestamp);
539 info->pended_events_list = eina_list_remove(info->pended_events_list, event_info);
541 return ECORE_CALLBACK_RENEW;
546 * Every user event (mouse) on the buffer will be passed via this event callback
548 static int event_handler_cb(widget_buffer_h handler, widget_buffer_event_data_t event_info, void *data)
550 vwin_info_t info = data;
555 * If the feeds event is accessibility or key event,
556 * "return 0" will confusing the viewer,
557 * because it will waiting result of event processing to do handles state properly.
560 if (!info || info->state != VWIN_INFO_CREATED || !info->handle || info->deleted) {
561 /* Just ignore this event */
565 if (event_info->type == WIDGET_BUFFER_EVENT_FRAME_SKIP_CLEARED) {
567 * Increase the count_of_rendering only if it meets conditions.
568 * Or do not increase it to prevent from overflow problem.
569 * If we trying to increase the count_of_rendering variable, it could be overflowed.
570 * These conditions will prevents count_of_rendering from overflow issue.
572 if (info->pended_events_list && !info->pended_events_consumer) {
573 info->pended_events_consumer = ecore_timer_add(0.0001f, pended_event_consumer_cb, info);
574 if (info->pended_events_consumer) {
575 ErrPrint("Failed to create a pended event consumer\n");
582 if (WIDGET_CONF_USE_GETTIMEOFDAY) {
583 if (WIDGET_CONF_EVENT_FILTER > 0.0f && (info->pressed == 0 || event_info->type == WIDGET_BUFFER_EVENT_MOVE)) {
586 if (gettimeofday(&tv, NULL) < 0) {
587 ErrPrint("gettimeofday: %d\n", errno);
589 timestamp = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
590 timestamp -= event_info->timestamp;
592 if (timestamp > WIDGET_CONF_EVENT_FILTER) {
593 DbgPrint("Dropped %lf\n", timestamp);
600 * If the device doesn't use the clock monotic time, we have to emulate it for EVAS
601 * Evas only use the monotic time for animating objects
603 timestamp = ecore_time_get() * 1000.0f;
605 if (WIDGET_CONF_EVENT_FILTER > 0.0f && (info->pressed == 0 || event_info->type == WIDGET_BUFFER_EVENT_MOVE)) {
606 timestamp = ecore_time_get();
608 timestamp -= event_info->timestamp;
609 if (timestamp > WIDGET_CONF_EVENT_FILTER) {
610 DbgPrint("Dropped %lf\n", timestamp);
615 timestamp = event_info->timestamp * 1000.0f;
618 if ((info->w <= 1 && info->h <= 1) || widget_provider_buffer_frame_skip(info->handle) > 0 || info->pended_events_list) {
619 widget_buffer_event_data_t _ev_info;
620 _ev_info = malloc(sizeof(*_ev_info));
622 memcpy(_ev_info, event_info, sizeof(*_ev_info));
623 info->pended_events_list = eina_list_append(info->pended_events_list, _ev_info);
624 _ev_info->timestamp = timestamp;
627 * Push events to pending list,.
628 * Consuming it first.
630 DbgPrint("Canvas is not prepared. pending the events (%dx%d)\n", info->w, info->h);
633 ErrPrint("malloc: %d\n", errno);
637 return processing_events(info, event_info, timestamp);
640 static void pre_render_cb(void *data, Evas *e, void *event_info)
642 vwin_info_t info = data;
644 if (!info || info->state != VWIN_INFO_CREATED || !info->handle) {
648 if (widget_conf_premultiplied_alpha()) {
652 ecore_evas_geometry_get(info->ee, NULL, NULL, &w, &h);
653 evas_damage_rectangle_add(e, 0, 0, w, h);
656 if (info->type == VWIN_GEM) {
657 widget_buffer_pre_render(info->handle);
658 } else if (info->type == VWIN_PIXMAP) {
660 * Only the pixmap type Ecore_Evas uses this variable
662 } else if (info->type == VWIN_SW_BUF) {
667 static void post_render_cb(void *data, Evas *e, void *event_info)
669 vwin_info_t info = data;
671 if (!info || info->state != VWIN_INFO_CREATED || !info->handle) {
675 if (widget_conf_premultiplied_alpha()) {
679 // Get a pointer of a buffer of the virtual canvas
680 canvas = (void *)ecore_evas_buffer_pixels_get(info->ee);
682 ErrPrint("Failed to get pixel canvas\n");
686 ecore_evas_geometry_get(info->ee, &x, &y, &w, &h);
687 evas_data_argb_unpremul(canvas, w * h);
690 if (info->type == VWIN_GEM) {
691 widget_buffer_post_render(info->handle);
692 } else if (info->type == VWIN_PIXMAP) {
694 unsigned int front_resource_id;
696 front_resource_id = ecore_evas_gl_x11_pixmap_get(info->ee);
698 for (idx = 0; idx < WIDGET_CONF_EXTRA_BUFFER_COUNT; idx++) {
699 if (front_resource_id == info->resource_array[idx]) {
702 widget_send_updated_by_idx(info->handle, idx);
707 if (idx == WIDGET_CONF_EXTRA_BUFFER_COUNT) {
708 /* Send updated event for PRIMARY BUFFER */
709 if (front_resource_id == widget_viewer_get_resource_id(info->handle, WIDGET_PRIMARY_BUFFER)) {
710 widget_send_updated_by_idx(info->handle, WIDGET_PRIMARY_BUFFER);
712 DbgPrint("Unable to send updated: %u (%u)\n", front_resource_id, widget_viewer_get_resource_id(info->handle, WIDGET_PRIMARY_BUFFER));
715 } else if (info->type == VWIN_SW_BUF) {
716 widget_viewer_sync_buffer(info->handle);
720 static int pre_orientation_cb(const char *id, void *data)
722 vwin_info_t info = data;
726 /* Try provider_app first */
727 if (!info || info->state != VWIN_INFO_CREATED || !id || !info->id) {
728 return WIDGET_ERROR_INVALID_PARAMETER;
731 path = widget_util_uri_to_path(id);
732 if (path && strcmp(info->id, path)) {
734 DbgPrint("SKIP: Pre orientation event callback is called [%s], %s\n", id, info->id);
735 return WIDGET_ERROR_INVALID_PARAMETER;
738 DbgPrint("Pre orientation event callback is called [%s]\n", id);
739 orientation = widget_get_orientation(path);
740 if (orientation < 0) {
741 ErrPrint("Failed to get orientation: %X\n", orientation);
743 info->orientation = orientation;
746 return WIDGET_ERROR_NONE;
749 static int pre_destroy_cb(const char *id, void *data)
751 vwin_info_t info = data;
752 const char *path = NULL;
754 if (!info || info->state != VWIN_INFO_CREATED) {
755 return WIDGET_ERROR_INVALID_PARAMETER;
759 path = widget_util_uri_to_path(id);
761 if (path && strcmp(info->id, path)) {
763 DbgPrint("SKIP: Pre destroy event callback is called [%s], %s\n", id, info->id);
764 return WIDGET_ERROR_INVALID_PARAMETER;
768 DbgPrint("Pre destroy event callback is called [%s]\n", id);
771 DbgPrint("Toggle manual render mode to prevent from unwanted rendering");
772 ecore_evas_manual_render_set(info->ee, EINA_TRUE);
775 return WIDGET_ERROR_NONE;
778 static void ecore_evas_free_cb(Ecore_Evas *ee)
782 info = ecore_evas_data_get(ee, WIN_INFO_TAG);
784 DbgPrint("Info is not valid\n");
788 if (info->pended_events_consumer) {
789 widget_buffer_event_data_t event_info;
791 DbgPrint("Clearing pended event consumer\n");
792 ecore_timer_del(info->pended_events_consumer);
793 info->pended_events_consumer = NULL;
795 EINA_LIST_FREE(info->pended_events_list, event_info) {
800 widget_del_pre_callback(WIDGET_PRE_DESTROY_CALLBACK, pre_destroy_cb, info);
803 evas_event_callback_del(info->e, EVAS_CALLBACK_RENDER_POST, post_render_cb);
804 evas_event_callback_del(info->e, EVAS_CALLBACK_RENDER_PRE, pre_render_cb);
811 #ifdef WIDGET_FEATURE_GBAR_SUPPORTED
812 PUBLIC Evas *widget_get_evas(const char *id, int is_gbar)
813 #else /* WIDGET_FEATURE_GBAR_SUPPORTED */
814 PUBLIC Evas *widget_get_evas(const char *id)
815 #endif /* WIDGET_FEATURE_GBAR_SUPPORTED */
822 * If the evas object is already created,
823 * this function should returns ERROR.
827 ErrPrint("Invalid parameter\n");
831 info = calloc(1, sizeof(*info));
833 ErrPrint("Heap: %d\n", errno);
837 info->state = VWIN_INFO_CREATED;
839 info->id = strdup(id);
841 ErrPrint("Heap: %d\n", errno);
842 info->state = VWIN_INFO_DESTROYED;
847 #ifdef WIDGET_FEATURE_GBAR_SUPPORTED
848 info->is_gbar = is_gbar;
851 #endif /* WIDGET_FEATURE_GBAR_SUPPORTED */
854 * Acquire a buffer for canvas.
856 info->handle = widget_create_buffer(info->id, info->is_gbar,
857 binder_widget_auto_align(),
858 event_handler_cb, info);
861 ErrPrint("Failed to create a widget buffer\n");
862 info->state = VWIN_INFO_DESTROYED;
869 * Size information must be initialized before call the ecore_evas_buffer_new.
871 info->w = WIDGET_DEFAULT_WIDTH;
872 info->h = WIDGET_DEFAULT_HEIGHT;
874 info->ee = binder_ecore_evas_new(info);
876 ErrPrint("Failed to create ecore_evas (%dx%d)\n", info->w, info->h);
877 widget_destroy_buffer(info->handle);
878 info->state = VWIN_INFO_DESTROYED;
884 ecore_evas_data_set(info->ee, WIN_INFO_TAG, info);
888 * Free callback must be prepared before use the ecore_evas_free()
890 ecore_evas_callback_pre_free_set(info->ee, ecore_evas_free_cb);
892 info->e = ecore_evas_get(info->ee);
894 ErrPrint("Failed to get evas\n");
895 ecore_evas_free(info->ee);
899 pre_render_cb(info, NULL, NULL);
900 ecore_evas_alpha_set(info->ee, EINA_TRUE);
901 post_render_cb(info, NULL, NULL);
903 ecore_evas_manual_render_set(info->ee, EINA_FALSE);
904 ecore_evas_resize(info->ee, info->w, info->h);
906 evas_event_callback_add(info->e, EVAS_CALLBACK_RENDER_POST, post_render_cb, info);
907 evas_event_callback_add(info->e, EVAS_CALLBACK_RENDER_PRE, pre_render_cb, info);
909 widget_add_pre_callback(WIDGET_PRE_DESTROY_CALLBACK, pre_destroy_cb, info);
910 widget_add_pre_callback(WIDGET_PRE_ORIENTATION_CALLBACK, pre_orientation_cb, info);
912 orientation = widget_get_orientation(info->id);
913 if (orientation < 0) {
914 ErrPrint("Failed to get orientation[%s]: %X\n", info->id, orientation);
916 info->orientation = orientation;