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>
30 #include <dynamicbox_errno.h>
31 #include <dynamicbox_service.h>
32 #include <dynamicbox_conf.h>
33 #include <dynamicbox_buffer.h>
35 #include "dynamicbox.h"
40 #define PUBLIC __attribute__((visibility("default")))
41 #define DBOX_WIN_TAG "dynamic,box,win"
43 #define DBOX_DEFAULT_WIDTH 1
44 #define DBOX_DEFAULT_HEIGHT 1
45 #define GL_ENGINE "opengl_x11"
47 static struct static_info {
48 Ecore_Evas *(*alloc_canvas)(int w, int h, void *(*a)(void *data, int size), void (*f)(void *data, void *ptr), void *data);
49 Ecore_Evas *(*alloc_canvas_with_stride)(int w, int h, void *(*a)(void *data, int size, int *stride, int *bpp), void (*f)(void *data, void *ptr), void *data);
50 Ecore_Evas *(*alloc_canvas_with_pixmap)(const char *disp_name, Ecore_X_Window parent, int x, int y, int w, int h, Ecore_X_Pixmap (*alloc_cb)(void *data, Ecore_X_Window parent, int w, int h, int depth), void (*free_cb)(void *data, Ecore_X_Pixmap pixmap), void *data);
53 .alloc_canvas_with_stride = NULL,
54 .alloc_canvas_with_pixmap = NULL,
59 * Abstracted Data Type of Virtual Window
61 typedef struct virtual_window_info {
62 char *id; /**< Identification */
63 dynamicbox_buffer_h handle; /**< Livebox buffer handle */
65 VWIN_SW_BUF = 0x00, /**< S/W buffer */
66 VWIN_GEM = 0x01, /**< GEM buffer */
67 VWIN_PIXMAP = 0x02, /**< PIXMAP */
68 VWIN_ERROR = 0x03 /**< Unknown */
76 unsigned int *resource_array;
79 unsigned int front_resource_id;
84 static inline Evas_Object *get_highlighted_object(Evas_Object *obj)
88 o = evas_object_name_find(evas_object_evas_get(obj), "_elm_access_disp");
91 ho = evas_object_data_get(o, "_elm_access_target");
97 * Every user event (mouse) on the buffer will be passed via this event callback
99 static int event_handler_cb(dynamicbox_buffer_h handler, struct dynamicbox_buffer_event_data *event_info, void *data)
101 vwin_info_t info = data;
102 Elm_Access_Action_Info action_info;
103 Elm_Access_Action_Type action_type;
105 Evas_Object *parent_elm;
107 unsigned int flags = 0;
111 /* Just ignore this event */
115 if (DYNAMICBOX_CONF_USE_GETTIMEOFDAY) {
116 if (DYNAMICBOX_CONF_EVENT_FILTER > 0.0f && (info->pressed == 0 || event_info->type == DBOX_BUFFER_EVENT_MOVE)) {
119 if (gettimeofday(&tv, NULL) < 0) {
120 ErrPrint("gettimeofday: %s\n", strerror(errno));
122 timestamp = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
123 timestamp -= event_info->timestamp;
125 if (timestamp > DYNAMICBOX_CONF_EVENT_FILTER) {
126 DbgPrint("Dropped %lf\n", timestamp);
133 * If the device doesn't use the clock monotic time, we have to emulate it for EVAS
134 * Evas only use the monotic time for animating objects
136 timestamp = ecore_time_get() * 1000.0f;
138 if (DYNAMICBOX_CONF_EVENT_FILTER > 0.0f && (info->pressed == 0 || event_info->type == DBOX_BUFFER_EVENT_MOVE)) {
139 timestamp = ecore_time_get();
141 timestamp -= event_info->timestamp;
142 if (timestamp > DYNAMICBOX_CONF_EVENT_FILTER) {
143 DbgPrint("Dropped %lf\n", timestamp);
148 timestamp = event_info->timestamp * 1000.0f;
155 switch (event_info->type) {
156 case DBOX_BUFFER_EVENT_ON_HOLD:
157 flags = evas_event_default_flags_get(info->e);
158 flags |= EVAS_EVENT_FLAG_ON_HOLD;
159 evas_event_default_flags_set(info->e, flags);
161 case DBOX_BUFFER_EVENT_OFF_HOLD:
162 flags = evas_event_default_flags_get(info->e);
163 flags &= ~EVAS_EVENT_FLAG_ON_HOLD;
164 evas_event_default_flags_set(info->e, flags);
166 case DBOX_BUFFER_EVENT_ON_SCROLL:
167 flags = evas_event_default_flags_get(info->e);
168 flags |= EVAS_EVENT_FLAG_ON_SCROLL;
169 evas_event_default_flags_set(info->e, flags);
171 case DBOX_BUFFER_EVENT_OFF_SCROLL:
172 flags = evas_event_default_flags_get(info->e);
173 flags &= ~EVAS_EVENT_FLAG_ON_SCROLL;
174 evas_event_default_flags_set(info->e, flags);
176 case DBOX_BUFFER_EVENT_ENTER:
177 evas_event_feed_mouse_in(info->e, timestamp, NULL);
179 case DBOX_BUFFER_EVENT_LEAVE:
180 evas_event_feed_mouse_out(info->e, timestamp, NULL);
182 case DBOX_BUFFER_EVENT_DOWN:
185 * Before processing the DOWN event,
186 * Reset the evas event flags regarding ON_HOLD option.
187 * It can be re-enabled while processing down-move-up events.
189 flags = evas_event_default_flags_get(info->e);
190 flags &= ~EVAS_EVENT_FLAG_ON_SCROLL;
191 flags &= ~EVAS_EVENT_FLAG_ON_HOLD;
192 evas_event_default_flags_set(info->e, flags);
195 * Calculate the event occurred X & Y on the buffer
197 evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, timestamp, NULL);
198 evas_event_feed_mouse_down(info->e, 1, EVAS_BUTTON_NONE, timestamp, NULL); /* + 0.2f just for fake event */
201 case DBOX_BUFFER_EVENT_MOVE:
204 * Calculate the event occurred X & Y on the buffer
206 evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, timestamp, NULL);
208 case DBOX_BUFFER_EVENT_UP:
209 evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, timestamp, NULL);
210 evas_event_feed_mouse_up(info->e, 1, EVAS_BUTTON_NONE, timestamp, NULL);
214 * We have to keep the event flags, so we should not clear them from here.
215 * Sometimes, asynchronously callable Callbacks can refer the evas event flags after up event.
216 * so if we reset them from here, those kind of callbacks will fails to do their job properly.
219 case DBOX_BUFFER_EVENT_ACCESS_HIGHLIGHT:
220 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
222 ret = DBOX_ACCESS_STATUS_ERROR;
225 memset(&action_info, 0, sizeof(action_info));
226 action_type = ELM_ACCESS_ACTION_HIGHLIGHT;
229 * Calculate the event occurred X & Y on the buffer
231 action_info.x = event_info->info.access.x;
232 action_info.y = event_info->info.access.y;
233 ret = elm_access_action(parent_elm, action_type, &action_info);
234 if (ret == EINA_TRUE) {
235 if (!get_highlighted_object(parent_elm)) {
236 ErrPrint("Highlighted object is not found\n");
237 ret = DBOX_ACCESS_STATUS_ERROR;
239 DbgPrint("Highlighted object is found\n");
240 ret = DBOX_ACCESS_STATUS_DONE;
243 ErrPrint("Action error\n");
244 ret = DBOX_ACCESS_STATUS_ERROR;
247 case DBOX_BUFFER_EVENT_ACCESS_HIGHLIGHT_NEXT:
248 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
250 ret = DBOX_ACCESS_STATUS_ERROR;
253 memset(&action_info, 0, sizeof(action_info));
254 action_type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
255 action_info.highlight_cycle = EINA_FALSE;
256 ret = elm_access_action(parent_elm, action_type, &action_info);
257 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_LAST : DBOX_ACCESS_STATUS_DONE;
259 case DBOX_BUFFER_EVENT_ACCESS_HIGHLIGHT_PREV:
260 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
262 ret = DBOX_ACCESS_STATUS_ERROR;
265 memset(&action_info, 0, sizeof(action_info));
266 action_type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
267 action_info.highlight_cycle = EINA_FALSE;
268 ret = elm_access_action(parent_elm, action_type, &action_info);
269 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_FIRST : DBOX_ACCESS_STATUS_DONE;
271 case DBOX_BUFFER_EVENT_ACCESS_ACTIVATE:
272 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
274 ret = DBOX_ACCESS_STATUS_ERROR;
277 memset(&action_info, 0, sizeof(action_info));
278 action_type = ELM_ACCESS_ACTION_ACTIVATE;
279 ret = elm_access_action(parent_elm, action_type, &action_info);
280 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
282 case DBOX_BUFFER_EVENT_ACCESS_ACTION_UP:
283 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
285 ret = DBOX_ACCESS_STATUS_ERROR;
288 memset(&action_info, 0, sizeof(action_info));
289 action_type = ELM_ACCESS_ACTION_UP;
290 ret = elm_access_action(parent_elm, action_type, &action_info);
291 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
293 case DBOX_BUFFER_EVENT_ACCESS_ACTION_DOWN:
294 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
296 ret = DBOX_ACCESS_STATUS_ERROR;
299 memset(&action_info, 0, sizeof(action_info));
300 action_type = ELM_ACCESS_ACTION_DOWN;
301 ret = elm_access_action(parent_elm, action_type, &action_info);
302 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
304 case DBOX_BUFFER_EVENT_ACCESS_SCROLL_UP:
305 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
307 ret = DBOX_ACCESS_STATUS_ERROR;
310 memset(&action_info, 0, sizeof(action_info));
311 action_type = ELM_ACCESS_ACTION_SCROLL;
312 action_info.x = event_info->info.access.x;
313 action_info.y = event_info->info.access.y;
314 action_info.mouse_type = event_info->info.access.mouse_type;
315 ret = elm_access_action(parent_elm, action_type, &action_info);
316 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
318 case DBOX_BUFFER_EVENT_ACCESS_SCROLL_MOVE:
319 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
321 ret = DBOX_ACCESS_STATUS_ERROR;
324 memset(&action_info, 0, sizeof(action_info));
325 action_type = ELM_ACCESS_ACTION_SCROLL;
326 action_info.x = event_info->info.access.x;
327 action_info.y = event_info->info.access.y;
328 action_info.mouse_type = event_info->info.access.mouse_type;
329 ret = elm_access_action(parent_elm, action_type, &action_info);
330 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
332 case DBOX_BUFFER_EVENT_ACCESS_SCROLL_DOWN:
333 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
335 ret = DBOX_ACCESS_STATUS_ERROR;
338 memset(&action_info, 0, sizeof(action_info));
339 action_type = ELM_ACCESS_ACTION_SCROLL;
340 action_info.x = event_info->info.access.x;
341 action_info.y = event_info->info.access.y;
342 action_info.mouse_type = event_info->info.access.mouse_type;
343 ret = elm_access_action(parent_elm, action_type, &action_info);
344 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
346 case DBOX_BUFFER_EVENT_ACCESS_UNHIGHLIGHT:
347 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
349 ret = DBOX_ACCESS_STATUS_ERROR;
352 memset(&action_info, 0, sizeof(action_info));
353 action_type = ELM_ACCESS_ACTION_UNHIGHLIGHT;
354 ret = elm_access_action(parent_elm, action_type, &action_info);
355 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
357 case DBOX_BUFFER_EVENT_ACCESS_VALUE_CHANGE:
358 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
360 ret = DBOX_ACCESS_STATUS_ERROR;
363 memset(&action_info, 0, sizeof(action_info));
364 action_type = ELM_ACCESS_ACTION_VALUE_CHANGE;
365 action_info.x = event_info->info.access.x;
366 action_info.y = event_info->info.access.y;
367 action_info.mouse_type = event_info->info.access.mouse_type;
368 ret = elm_access_action(parent_elm, action_type, &action_info);
369 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
371 case DBOX_BUFFER_EVENT_ACCESS_MOUSE:
372 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
374 ret = DBOX_ACCESS_STATUS_ERROR;
377 memset(&action_info, 0, sizeof(action_info));
378 action_type = ELM_ACCESS_ACTION_MOUSE;
379 action_info.x = event_info->info.access.x;
380 action_info.y = event_info->info.access.y;
381 action_info.mouse_type = event_info->info.access.mouse_type;
382 ret = elm_access_action(parent_elm, action_type, &action_info);
383 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
385 case DBOX_BUFFER_EVENT_ACCESS_BACK:
386 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
388 ret = DBOX_ACCESS_STATUS_ERROR;
391 memset(&action_info, 0, sizeof(action_info));
392 action_type = ELM_ACCESS_ACTION_BACK;
393 action_info.x = event_info->info.access.x;
394 action_info.y = event_info->info.access.y;
395 action_info.mouse_type = event_info->info.access.mouse_type;
396 ret = elm_access_action(parent_elm, action_type, &action_info);
397 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
399 case DBOX_BUFFER_EVENT_ACCESS_OVER:
400 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
402 ret = DBOX_ACCESS_STATUS_ERROR;
405 memset(&action_info, 0, sizeof(action_info));
406 action_type = ELM_ACCESS_ACTION_OVER;
407 action_info.x = event_info->info.access.x;
408 action_info.y = event_info->info.access.y;
409 action_info.mouse_type = event_info->info.access.mouse_type;
410 ret = elm_access_action(parent_elm, action_type, &action_info);
411 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
413 case DBOX_BUFFER_EVENT_ACCESS_READ:
414 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
416 ret = DBOX_ACCESS_STATUS_ERROR;
419 memset(&action_info, 0, sizeof(action_info));
420 action_type = ELM_ACCESS_ACTION_READ;
421 action_info.x = event_info->info.access.x;
422 action_info.y = event_info->info.access.y;
423 action_info.mouse_type = event_info->info.access.mouse_type;
424 ret = elm_access_action(parent_elm, action_type, &action_info);
425 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
427 case DBOX_BUFFER_EVENT_ACCESS_ENABLE:
428 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
430 ret = DBOX_ACCESS_STATUS_ERROR;
433 memset(&action_info, 0, sizeof(action_info));
434 action_type = ELM_ACCESS_ACTION_ENABLE;
435 action_info.x = event_info->info.access.x;
436 action_info.y = event_info->info.access.y;
437 action_info.mouse_type = event_info->info.access.mouse_type;
438 ret = elm_access_action(parent_elm, action_type, &action_info);
439 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
441 case DBOX_BUFFER_EVENT_ACCESS_DISABLE:
442 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
444 ret = DBOX_ACCESS_STATUS_ERROR;
447 memset(&action_info, 0, sizeof(action_info));
448 action_type = ELM_ACCESS_ACTION_DISABLE;
449 action_info.x = event_info->info.access.x;
450 action_info.y = event_info->info.access.y;
451 action_info.mouse_type = event_info->info.access.mouse_type;
452 ret = elm_access_action(parent_elm, action_type, &action_info);
453 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
455 case DBOX_BUFFER_EVENT_KEY_DOWN:
456 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
458 ret = DBOX_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 = DBOX_KEY_STATUS_ERROR;
476 case DBOX_BUFFER_EVENT_KEY_UP:
477 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
479 ret = DBOX_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 = DBOX_KEY_STATUS_ERROR;
497 case DBOX_BUFFER_EVENT_KEY_FOCUS_IN:
498 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
500 ret = DBOX_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 = DBOX_KEY_STATUS_ERROR;
518 case DBOX_BUFFER_EVENT_KEY_FOCUS_OUT:
519 parent_elm = ecore_evas_data_get(info->ee, DBOX_WIN_TAG);
521 ret = DBOX_ACCESS_STATUS_ERROR;
525 key_symbol = XGetKeyboardMapping(ecore_x_display_get(), event_info->info.keycode, 1, &ret);
530 key_string = XKeysymToString(*key_symbol);
531 key_name = XKeysymToString(*key_symbol);
532 DbgPrint("Key symbol: %s, name: %s\n", key_string, key_name);
537 ret = DBOX_KEY_STATUS_ERROR;
540 DbgPrint("Unhandled buffer event (%d)\n", event_info->type);
549 * This callback can be called twice (or more) to get a several pixmaps
550 * Acquired pixmaps are used for double/tripple buffering for canvas
552 static Ecore_X_Pixmap alloc_pixmap_cb(void *data, Ecore_X_Window parent, int w, int h, int depth)
554 vwin_info_t info = data;
555 Ecore_X_Pixmap pixmap;
558 ErrPrint("Invalid handle\n");
564 DbgPrint("Size of ee is updated: %dx%d - %d (info: %p)\n", info->w, info->h, depth, info);
567 if (dynamicbox_resource_id(info->handle, DBOX_PRIMARY_BUFFER) == 0u) {
570 * Need to allocate a primary buffer
572 dynamicbox_acquire_buffer(info->handle, DBOX_PRIMARY_BUFFER, info->w, info->h, depth);
574 ErrPrint("Failed to get the buffer\n");
578 pixmap = (Ecore_X_Pixmap)dynamicbox_resource_id(info->handle, DBOX_PRIMARY_BUFFER);
579 } else if (DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT > 0) {
582 if (!info->resource_array) {
583 info->resource_array = calloc(DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT, sizeof(*info->resource_array));
584 if (!info->resource_array) {
585 ErrPrint("Out of memory: %s\n", strerror(errno));
591 for (idx = 0; idx < DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT; idx++) {
592 if (info->resource_array[idx] == 0u) {
597 if (idx == DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT) {
598 ErrPrint("Out of index: %d\n", idx);
603 if (dynamicbox_acquire_buffer(info->handle, idx, info->w, info->h, depth) < 0) {
604 ErrPrint("Failed to acquire a buffer for %d\n", idx);
608 info->resource_array[idx] = dynamicbox_resource_id(info->handle, idx);
609 if (info->resource_array[idx] == 0u) {
610 ErrPrint("Failed to allocate pixmap\n");
613 DbgPrint("Allocated index: %d/%d - %u\n", idx, DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT, info->resource_array[idx]);
614 pixmap = info->resource_array[idx];
618 * Acquire a buffer for canvas.
620 info->type = VWIN_PIXMAP;
621 info->resource_cnt += !!(unsigned int)pixmap;
625 static void free_pixmap_cb(void *data, Ecore_X_Pixmap pixmap)
627 vwin_info_t info = data;
633 if (info->type != VWIN_PIXMAP) {
634 ErrPrint("Impossible\n");
637 if (dynamicbox_resource_id(info->handle, DBOX_PRIMARY_BUFFER) == pixmap) {
638 if (dynamicbox_release_buffer(info->handle, DBOX_PRIMARY_BUFFER) < 0) {
639 DbgPrint("Failed to release buffer\n");
641 info->resource_cnt--;
645 for (idx = 0; idx < DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT; idx++) {
648 * Find a index to release it
650 if (info->resource_array[idx] == pixmap) {
651 if (dynamicbox_release_buffer(info->handle, idx) < 0) {
652 DbgPrint("Failed to release buffer\n");
654 info->resource_array[idx] = 0u;
655 info->resource_cnt--;
661 if (info->deleted && info->resource_cnt == 0) {
662 DbgPrint("Destroy buffer handle\n");
664 dynamicbox_destroy_buffer(info->handle);
665 free(info->resource_array);
671 static void *alloc_fb(void *data, int size)
673 vwin_info_t info = data;
677 ecore_evas_geometry_get(info->ee, NULL, NULL, &info->w, &info->h);
678 DbgPrint("Size of ee is updated: %dx%d (info: %p)\n", info->w, info->h, info);
682 ErrPrint("Failed to create a buffer\n");
686 if (dynamicbox_acquire_buffer(info->handle, DBOX_PRIMARY_BUFFER, info->w, info->h, sizeof(int)) < 0) {
687 ErrPrint("Failed to acquire buffer\n");
692 * If it supports the H/W accelerated buffer,
695 if (dynamicbox_support_hw_buffer(info->handle)) {
696 if (dynamicbox_create_hw_buffer(info->handle) == 0) {
697 buffer = dynamicbox_buffer_hw_buffer(info->handle);
699 DbgPrint("HW Accelerated buffer is created %p, (%dx%d)\n", info, info->w, info->h);
700 info->type = VWIN_GEM;
705 ErrPrint("Failed to allocate HW Accelerated buffer\n");
709 * Or use the buffer of a S/W backend.
711 buffer = dynamicbox_ref_buffer(info->handle);
712 DbgPrint("SW buffer is created (%dx%d)\n", info->w, info->h);
713 info->type = VWIN_SW_BUF;
717 static void *alloc_stride_fb(void *data, int size, int *stride, int *bpp)
721 buffer = alloc_fb(data, size);
723 vwin_info_t info = data;
727 _stride = dynamicbox_buffer_stride(info->handle);
729 _stride = info->w * *bpp;
734 DbgPrint("bpp: %d, stride: %d\n", *bpp, *stride);
740 static void free_fb(void *data, void *ptr)
742 vwin_info_t info = data;
748 if (info->type == VWIN_GEM) {
749 if (dynamicbox_destroy_hw_buffer(info->handle) == 0) {
750 DbgPrint("HW Accelerated buffer is destroyed\n");
752 } else if (info->type == VWIN_SW_BUF) {
753 DbgPrint("SW buffer is destroyed, %p\n", info);
754 dynamicbox_unref_buffer(ptr);
755 } else if (info->type == VWIN_PIXMAP) {
756 ErrPrint("Unable to reach to here\n");
759 if (dynamicbox_release_buffer(info->handle, DBOX_PRIMARY_BUFFER) < 0) {
760 ErrPrint("Failed to release buffer\n");
764 dynamicbox_destroy_buffer(info->handle);
765 free(info->resource_array);
771 static void pre_render_cb(void *data, Evas *e, void *event_info)
773 vwin_info_t info = data;
779 if (dynamicbox_conf_premultiplied_alpha()) {
783 ecore_evas_geometry_get(info->ee, NULL, NULL, &w, &h);
784 evas_damage_rectangle_add(e, 0, 0, w, h);
787 if (info->type == VWIN_GEM) {
788 dynamicbox_buffer_pre_render(info->handle);
789 } else if (info->type == VWIN_PIXMAP) {
791 * Only the pixmap type Ecore_Evas uses this variable
793 info->front_resource_id = ecore_evas_gl_x11_pixmap_get(info->ee);
794 } else if (info->type == VWIN_SW_BUF) {
799 static void post_render_cb(void *data, Evas *e, void *event_info)
801 vwin_info_t info = data;
807 if (dynamicbox_conf_premultiplied_alpha()) {
811 // Get a pointer of a buffer of the virtual canvas
812 canvas = (void *)ecore_evas_buffer_pixels_get(info->ee);
814 ErrPrint("Failed to get pixel canvas\n");
818 ecore_evas_geometry_get(info->ee, &x, &y, &w, &h);
819 evas_data_argb_unpremul(canvas, w * h);
822 if (info->type == VWIN_GEM) {
823 dynamicbox_buffer_post_render(info->handle);
824 } else if (info->type == VWIN_PIXMAP) {
827 for (idx = 0; idx < DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT; idx++) {
828 if (info->front_resource_id == info->resource_array[idx]) {
831 dynamicbox_send_updated_by_idx(info->handle, idx);
836 if (idx == DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT) {
837 /* Send updated event for PRIMARY BUFFER */
838 if (info->front_resource_id == dynamicbox_resource_id(info->handle, DBOX_PRIMARY_BUFFER)) {
839 dynamicbox_send_updated_by_idx(info->handle, DBOX_PRIMARY_BUFFER);
841 DbgPrint("Unable to send updated: %u (%u)\n", info->front_resource_id, dynamicbox_resource_id(info->handle, DBOX_PRIMARY_BUFFER));
844 } else if (info->type == VWIN_SW_BUF) {
845 dynamicbox_sync_buffer(info->handle);
849 static void ecore_evas_free_cb(Ecore_Evas *ee)
853 info = ecore_evas_data_get(ee, "dynamic,box,info");
855 DbgPrint("Info is not valid\n");
860 evas_event_callback_del(info->e, EVAS_CALLBACK_RENDER_POST, post_render_cb);
861 evas_event_callback_del(info->e, EVAS_CALLBACK_RENDER_PRE, pre_render_cb);
868 PUBLIC void *dynamicbox_get_evas_object(const char *id, int is_gbar)
873 int gl_is_turned_on = 0;
875 if (!s_info.alloc_canvas && !s_info.alloc_canvas_with_stride && !s_info.alloc_canvas_with_pixmap) {
876 s_info.alloc_canvas_with_pixmap = dlsym(RTLD_DEFAULT, "ecore_evas_gl_x11_pixmap_allocfunc_new");
877 if (!s_info.alloc_canvas_with_pixmap) {
878 DbgPrint("pixmap_allocfunc_new is not found\n");
881 s_info.alloc_canvas_with_stride = dlsym(RTLD_DEFAULT, "ecore_evas_buffer_allocfunc_with_stride_new");
882 if (!s_info.alloc_canvas_with_stride) {
883 DbgPrint("allocfunc_with_stirde_new is not found\n");
886 s_info.alloc_canvas = dlsym(RTLD_DEFAULT, "ecore_evas_buffer_allocfunc_new");
887 if (!s_info.alloc_canvas) {
888 ErrPrint("allocfunc_new is not found\n");
891 if (!s_info.alloc_canvas_with_stride && !s_info.alloc_canvas && !s_info.alloc_canvas_with_pixmap) {
892 ErrPrint("No way to allocate canvas\n");
898 ErrPrint("Invalid parameter\n");
902 info = calloc(1, sizeof(*info));
904 ErrPrint("Heap: %s\n", strerror(errno));
908 info->id = strdup(id);
910 ErrPrint("Heap: %s\n", strerror(errno));
915 info->is_gbar = is_gbar;
918 * Acquire a buffer for canvas.
920 info->handle = dynamicbox_create_buffer(info->id, info->is_gbar,
921 (dynamicbox_conf_auto_align() || !s_info.alloc_canvas_with_stride),
922 event_handler_cb, info);
925 ErrPrint("Failed to create a dynamicbox buffer\n");
932 * Size information must be initialized before call the ecore_evas_buffer_new.
934 info->w = DBOX_DEFAULT_WIDTH;
935 info->h = DBOX_DEFAULT_HEIGHT;
937 engine = elm_config_preferred_engine_get();
938 DbgPrint("Preferred engine: %s (%s)\n", engine, GL_ENGINE);
939 if (engine && !strcmp(engine, GL_ENGINE)) {
940 if (s_info.alloc_canvas_with_pixmap) {
941 info->ee = s_info.alloc_canvas_with_pixmap(NULL, 0u, 0, 0, info->w, info->h, alloc_pixmap_cb, free_pixmap_cb, info);
943 ErrPrint("Unable to create a ee for pixmap\n");
951 if (!dynamicbox_conf_auto_align() && s_info.alloc_canvas_with_stride) {
952 info->ee = s_info.alloc_canvas_with_stride(info->w, info->h, alloc_stride_fb, free_fb, info);
953 } else if (s_info.alloc_canvas) {
954 info->ee = s_info.alloc_canvas(info->w, info->h, alloc_fb, free_fb, info);
959 ErrPrint("Failed to create ecore_evas (%dx%d)\n", info->w, info->h);
960 dynamicbox_destroy_buffer(info->handle);
966 ecore_evas_data_set(info->ee, "dynamic,box,info", info);
970 * Free callback must be prepared before use the ecore_evas_free()
972 ecore_evas_callback_pre_free_set(info->ee, ecore_evas_free_cb);
974 info->e = ecore_evas_get(info->ee);
976 ErrPrint("Failed to get evas\n");
977 ecore_evas_free(info->ee);
981 if (!gl_is_turned_on) {
982 pre_render_cb(info, NULL, NULL);
983 ecore_evas_alpha_set(info->ee, EINA_TRUE);
984 post_render_cb(info, NULL, NULL);
986 DbgPrint("opengl-x11 engine should not turn on the alpha\n");
989 ecore_evas_manual_render_set(info->ee, EINA_FALSE);
990 ecore_evas_resize(info->ee, info->w, info->h);
992 evas_event_callback_add(info->e, EVAS_CALLBACK_RENDER_POST, post_render_cb, info);
993 evas_event_callback_add(info->e, EVAS_CALLBACK_RENDER_PRE, pre_render_cb, info);
995 rect = evas_object_rectangle_add(info->e);
997 ErrPrint("Failed to create evas_object\n");
998 ecore_evas_free(info->ee);
1002 evas_object_resize(rect, info->w, info->h);
1003 evas_object_color_set(rect, 0, 0, 0, 0);