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.
17 #include <Elementary.h>
19 #include <Ecore_Evas.h>
24 #include <dynamicbox_errno.h>
25 #include <dynamicbox_service.h>
27 #include "dynamicbox.h"
32 #define PUBLIC __attribute__((visibility("default")))
36 * Abstracted Data Type of Virtual Window
39 char *id; /*!< Identification */
40 struct dynamicbox_buffer *handle; /*!< Livebox buffer handle */
41 int is_hw; /*!< 1 if a buffer is created on the H/W accelerated place or 0 */
47 static inline Evas_Object *get_highlighted_object(Evas_Object *obj)
51 o = evas_object_name_find(evas_object_evas_get(obj), "_elm_access_disp");
54 ho = evas_object_data_get(o, "_elm_access_target");
60 * Every user event (mouse) on the buffer will be passed via this event callback
62 static int event_handler_cb(struct dynamicbox_buffer *handler, struct dynamicbox_buffer_event_data *event_info, void *data)
64 struct info *info = data;
65 Elm_Access_Action_Info action_info;
66 Elm_Access_Action_Type action_type;
68 Evas_Object *parent_elm;
72 /* Just ignore this event */
80 switch (event_info->type) {
81 case DBOX_BUFFER_EVENT_ENTER:
82 evas_event_feed_mouse_in(info->e, event_info->timestamp * 1000, NULL);
84 case DBOX_BUFFER_EVENT_LEAVE:
85 evas_event_feed_mouse_out(info->e, event_info->timestamp * 1000, NULL);
87 case DBOX_BUFFER_EVENT_DOWN:
90 * Calculate the event occurred X & Y on the buffer
92 evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, (event_info->timestamp - 0.001f) * 1000, NULL); /* + 0.1f just for fake event */
93 evas_event_feed_mouse_down(info->e, 1, EVAS_BUTTON_NONE, event_info->timestamp * 1000, NULL); /* + 0.2f just for fake event */
95 case DBOX_BUFFER_EVENT_MOVE:
98 * Calculate the event occurred X & Y on the buffer
100 evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, event_info->timestamp * 1000, NULL);
102 case DBOX_BUFFER_EVENT_UP:
103 evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, event_info->timestamp * 1000, NULL);
104 evas_event_feed_mouse_up(info->e, 1, EVAS_BUTTON_NONE, (event_info->timestamp + 0.001f) * 1000, NULL);
106 case DBOX_BUFFER_EVENT_ACCESS_HIGHLIGHT:
107 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
109 ret = DBOX_ACCESS_STATUS_ERROR;
112 memset(&action_info, 0, sizeof(action_info));
113 action_type = ELM_ACCESS_ACTION_HIGHLIGHT;
116 * Calculate the event occurred X & Y on the buffer
118 action_info.x = event_info->info.pointer.x;
119 action_info.y = event_info->info.pointer.y;
120 ret = elm_access_action(parent_elm, action_type, &action_info);
121 if (ret == EINA_TRUE) {
122 if (!get_highlighted_object(parent_elm)) {
123 LOGE("Highlighted object is not found\n");
124 ret = DBOX_ACCESS_STATUS_ERROR;
126 LOGD("Highlighted object is found\n");
127 ret = DBOX_ACCESS_STATUS_DONE;
130 LOGE("Action error\n");
131 ret = DBOX_ACCESS_STATUS_ERROR;
134 case DBOX_BUFFER_EVENT_ACCESS_HIGHLIGHT_NEXT:
135 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
137 ret = DBOX_ACCESS_STATUS_ERROR;
140 memset(&action_info, 0, sizeof(action_info));
141 action_type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
142 action_info.highlight_cycle = EINA_FALSE;
143 ret = elm_access_action(parent_elm, action_type, &action_info);
144 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_LAST : DBOX_ACCESS_STATUS_DONE;
146 case DBOX_BUFFER_EVENT_ACCESS_HIGHLIGHT_PREV:
147 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
149 ret = DBOX_ACCESS_STATUS_ERROR;
152 memset(&action_info, 0, sizeof(action_info));
153 action_type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
154 action_info.highlight_cycle = EINA_FALSE;
155 ret = elm_access_action(parent_elm, action_type, &action_info);
156 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_FIRST : DBOX_ACCESS_STATUS_DONE;
158 case DBOX_BUFFER_EVENT_ACCESS_ACTIVATE:
159 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
161 ret = DBOX_ACCESS_STATUS_ERROR;
164 memset(&action_info, 0, sizeof(action_info));
165 action_type = ELM_ACCESS_ACTION_ACTIVATE;
166 ret = elm_access_action(parent_elm, action_type, &action_info);
167 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
169 case DBOX_BUFFER_EVENT_ACCESS_ACTION_UP:
170 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
172 ret = DBOX_ACCESS_STATUS_ERROR;
175 memset(&action_info, 0, sizeof(action_info));
176 action_type = ELM_ACCESS_ACTION_UP;
177 ret = elm_access_action(parent_elm, action_type, &action_info);
178 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
180 case DBOX_BUFFER_EVENT_ACCESS_ACTION_DOWN:
181 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
183 ret = DBOX_ACCESS_STATUS_ERROR;
186 memset(&action_info, 0, sizeof(action_info));
187 action_type = ELM_ACCESS_ACTION_DOWN;
188 ret = elm_access_action(parent_elm, action_type, &action_info);
189 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
191 case DBOX_BUFFER_EVENT_ACCESS_SCROLL_UP:
192 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
194 ret = DBOX_ACCESS_STATUS_ERROR;
197 memset(&action_info, 0, sizeof(action_info));
198 action_type = ELM_ACCESS_ACTION_SCROLL;
199 action_info.x = event_info->info.pointer.x;
200 action_info.y = event_info->info.pointer.y;
201 action_info.mouse_type = 2;
202 ret = elm_access_action(parent_elm, action_type, &action_info);
203 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
205 case DBOX_BUFFER_EVENT_ACCESS_SCROLL_MOVE:
206 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
208 ret = DBOX_ACCESS_STATUS_ERROR;
211 memset(&action_info, 0, sizeof(action_info));
212 action_type = ELM_ACCESS_ACTION_SCROLL;
213 action_info.x = event_info->info.pointer.x;
214 action_info.y = event_info->info.pointer.y;
215 action_info.mouse_type = 1;
216 ret = elm_access_action(parent_elm, action_type, &action_info);
217 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
219 case DBOX_BUFFER_EVENT_ACCESS_SCROLL_DOWN:
220 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
222 ret = DBOX_ACCESS_STATUS_ERROR;
225 memset(&action_info, 0, sizeof(action_info));
226 action_type = ELM_ACCESS_ACTION_SCROLL;
227 action_info.x = event_info->info.pointer.x;
228 action_info.y = event_info->info.pointer.y;
229 action_info.mouse_type = 0;
230 ret = elm_access_action(parent_elm, action_type, &action_info);
231 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
233 case DBOX_BUFFER_EVENT_ACCESS_UNHIGHLIGHT:
234 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
236 ret = DBOX_ACCESS_STATUS_ERROR;
239 memset(&action_info, 0, sizeof(action_info));
240 action_type = ELM_ACCESS_ACTION_UNHIGHLIGHT;
241 ret = elm_access_action(parent_elm, action_type, &action_info);
242 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
244 case DBOX_BUFFER_EVENT_KEY_DOWN:
245 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
247 ret = DBOX_ACCESS_STATUS_ERROR;
251 ret = DBOX_KEY_STATUS_ERROR;
253 case DBOX_BUFFER_EVENT_KEY_UP:
254 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
256 ret = DBOX_ACCESS_STATUS_ERROR;
260 ret = DBOX_KEY_STATUS_ERROR;
262 case DBOX_BUFFER_EVENT_KEY_FOCUS_IN:
263 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
265 ret = DBOX_ACCESS_STATUS_ERROR;
269 ret = DBOX_KEY_STATUS_ERROR;
271 case DBOX_BUFFER_EVENT_KEY_FOCUS_OUT:
272 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
274 ret = DBOX_ACCESS_STATUS_ERROR;
278 ret = DBOX_KEY_STATUS_ERROR;
281 LOGD("Unhandled buffer event (%d)\n", event_info->type);
288 static void *alloc_fb(void *data, int size)
290 struct info *info = data;
295 if (info->ee == NULL) {
299 ecore_evas_geometry_get(info->ee, NULL, NULL, &width, &height);
303 * Acquire a buffer for canvas.
305 info->handle = dynamicbox_acquire_buffer(info->id, info->is_gbar,
307 event_handler_cb, info);
310 * If it supports the H/W accelerated buffer,
313 if (dynamicbox_support_hw_buffer(info->handle)) {
314 if (dynamicbox_create_hw_buffer(info->handle) == 0) {
315 buffer = dynamicbox_buffer_hw_buffer(info->handle);
317 LOGD("HW Accelerated buffer is created\n");
323 LOGE("Failed to allocate HW Accelerated buffer\n");
327 * Or use the buffer of a S/W backend.
329 buffer = dynamicbox_ref_buffer(info->handle);
330 LOGD("SW buffer is created\n");
335 static void free_fb(void *data, void *ptr)
337 struct info *info = data;
344 if (dynamicbox_destroy_hw_buffer(info->handle) == 0) {
345 LOGD("HW Accelerated buffer is destroyed\n");
350 dynamicbox_unref_buffer(ptr);
351 LOGD("SW buffer is destroyed\n");
353 dynamicbox_release_buffer(info->handle);
357 static void pre_render_cb(void *data, Evas *e, void *event_info)
359 struct info *info = data;
366 dynamicbox_buffer_pre_render(info->handle);
370 static void post_render_cb(void *data, Evas *e, void *event_info)
372 struct info *info = data;
379 dynamicbox_buffer_post_render(info->handle);
381 dynamicbox_sync_buffer(info->handle);
385 PUBLIC void *dynamicbox_get_evas_object(const char *id, int is_gbar)
391 ErrPrint("Invalid parameter\n");
395 info = calloc(1, sizeof(*info));
397 ErrPrint("Heap: %s\n", strerror(errno));
401 info->id = strdup(id);
403 ErrPrint("Heap: %s\n", strerror(errno));
408 info->is_gbar = is_gbar;
410 info->ee = ecore_evas_buffer_allocfunc_new(1, 1, alloc_fb, free_fb, info);
412 ErrPrint("Failed to create ecore_evas (%dx%d)\n", 1, 1);
418 pre_render_cb(info, NULL, NULL);
419 ecore_evas_alpha_set(info->ee, EINA_TRUE);
420 post_render_cb(info, NULL, NULL);
422 ecore_evas_data_set(info->ee, "dynamic,box,info", info);
424 ecore_evas_manual_render_set(info->ee, EINA_FALSE);
425 ecore_evas_resize(info->ee, 1, 1);
427 info->e = ecore_evas_get(info->ee);
429 ErrPrint("Failed to get evas\n");
430 ecore_evas_free(info->ee);
434 evas_event_callback_add(info->e, EVAS_CALLBACK_RENDER_POST, post_render_cb, info);
435 evas_event_callback_add(info->e, EVAS_CALLBACK_RENDER_PRE, pre_render_cb, info);
437 rect = evas_object_rectangle_add(info->e);
439 ErrPrint("Failed to create evas_object\n");
440 ecore_evas_free(info->ee);
444 evas_object_resize(rect, 1, 1);
445 evas_object_color_set(rect, 0, 0, 0, 0);