6 #include "ecore_private.h"
7 #include <Ecore_Input.h>
9 #include "ecore_evas_private.h"
10 #include "Ecore_Evas.h"
12 #ifdef BUILD_ECORE_EVAS_SOFTWARE_BUFFER
13 static int _ecore_evas_init_count = 0;
16 _ecore_evas_buffer_init(void)
18 _ecore_evas_init_count++;
19 if (_ecore_evas_init_count > 1) return _ecore_evas_init_count;
20 return _ecore_evas_init_count;
24 _ecore_evas_buffer_free(Ecore_Evas *ee)
26 if (ee->engine.buffer.image)
30 ee2 = evas_object_data_get(ee->engine.buffer.image, "Ecore_Evas_Parent");
31 evas_object_del(ee->engine.buffer.image);
32 ee2->sub_ecore_evas = eina_list_remove(ee2->sub_ecore_evas, ee);
36 free(ee->engine.buffer.pixels);
38 _ecore_evas_buffer_shutdown();
42 _ecore_evas_resize(Ecore_Evas *ee, int w, int h)
44 Evas_Engine_Info_Buffer *einfo;
48 if ((w == ee->w) && (h == ee->h)) return;
51 evas_output_size_set(ee->evas, ee->w, ee->h);
52 evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
53 evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h);
55 if (ee->engine.buffer.image)
57 ee->engine.buffer.pixels = evas_object_image_data_get(ee->engine.buffer.image, 1);
61 if (ee->engine.buffer.pixels) free(ee->engine.buffer.pixels);
62 ee->engine.buffer.pixels = malloc(ee->w * ee->h * sizeof(int));
65 einfo = (Evas_Engine_Info_Buffer *)evas_engine_info_get(ee->evas);
68 einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_ARGB32;
69 einfo->info.dest_buffer = ee->engine.buffer.pixels;
70 einfo->info.dest_buffer_row_bytes = ee->w * sizeof(int);
71 einfo->info.use_color_key = 0;
72 einfo->info.alpha_threshold = 0;
73 einfo->info.func.new_update_region = NULL;
74 einfo->info.func.free_update_region = NULL;
75 evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
77 if (ee->func.fn_resize) ee->func.fn_resize(ee);
81 _ecore_evas_buffer_shutdown(void)
83 _ecore_evas_init_count--;
84 if (_ecore_evas_init_count == 0)
87 if (_ecore_evas_init_count < 0) _ecore_evas_init_count = 0;
88 return _ecore_evas_init_count;
92 _ecore_evas_buffer_render(Ecore_Evas *ee)
94 Eina_List *updates, *l, *ll;
98 EINA_LIST_FOREACH(ee->sub_ecore_evas, ll, ee2)
100 if (ee2->func.fn_pre_render) ee2->func.fn_pre_render(ee2);
101 rend |= _ecore_evas_buffer_render(ee2);
102 if (ee2->func.fn_post_render) ee2->func.fn_post_render(ee2);
104 if (ee->engine.buffer.image)
108 evas_object_image_size_get(ee->engine.buffer.image, &w, &h);
109 if ((w != ee->w) || (h != ee->h))
110 _ecore_evas_resize(ee, w, h);
112 updates = evas_render_updates(ee->evas);
113 if (ee->engine.buffer.image)
117 EINA_LIST_FOREACH(updates, l, r)
118 if (ee->engine.buffer.image)
119 evas_object_image_data_update_add(ee->engine.buffer.image,
120 r->x, r->y, r->w, r->h);
124 evas_render_updates_free(updates);
125 _ecore_evas_idle_timeout_update(ee);
128 return updates ? 1 : rend;
132 _ecore_evas_buffer_coord_translate(Ecore_Evas *ee, Evas_Coord *x, Evas_Coord *y)
134 Evas_Coord xx, yy, fx, fy, fw, fh;
136 evas_object_geometry_get(ee->engine.buffer.image, &xx, &yy, NULL, NULL);
137 evas_object_image_fill_get(ee->engine.buffer.image, &fx, &fy, &fw, &fh);
141 while (xx < 0) xx += fw;
142 while (xx > fw) xx -= fw;
143 *x = (ee->w * xx) / fw;
147 while (yy < 0) yy += fh;
148 while (yy > fh) yy -= fh;
149 *y = (ee->h * yy) / fh;
153 _ecore_evas_buffer_cb_mouse_in(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
156 Evas_Event_Mouse_In *ev;
160 evas_event_feed_mouse_in(ee->evas, ev->timestamp, NULL);
164 _ecore_evas_buffer_cb_mouse_out(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
167 Evas_Event_Mouse_Out *ev;
171 evas_event_feed_mouse_out(ee->evas, ev->timestamp, NULL);
175 _ecore_evas_buffer_cb_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
178 Evas_Event_Mouse_Down *ev;
182 evas_event_feed_mouse_down(ee->evas, ev->button, ev->flags, ev->timestamp, NULL);
186 _ecore_evas_buffer_cb_mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
189 Evas_Event_Mouse_Up *ev;
193 evas_event_feed_mouse_up(ee->evas, ev->button, ev->flags, ev->timestamp, NULL);
197 _ecore_evas_buffer_cb_mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
200 Evas_Event_Mouse_Move *ev;
205 x = ev->cur.canvas.x;
206 y = ev->cur.canvas.y;
207 _ecore_evas_buffer_coord_translate(ee, &x, &y);
208 _ecore_evas_mouse_move_process(ee, x, y, ev->timestamp);
212 _ecore_evas_buffer_cb_mouse_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
215 Evas_Event_Mouse_Wheel *ev;
219 evas_event_feed_mouse_wheel(ee->evas, ev->direction, ev->z, ev->timestamp, NULL);
223 _ecore_evas_buffer_cb_multi_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
226 Evas_Event_Multi_Down *ev;
233 _ecore_evas_buffer_coord_translate(ee, &x, &y);
234 evas_event_feed_multi_down(ee->evas, ev->device, x, y, ev->radius, ev->radius_x, ev->radius_y, ev->flags, ev->timestamp, NULL);
238 _ecore_evas_buffer_cb_multi_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
241 Evas_Event_Multi_Up *ev;
248 _ecore_evas_buffer_coord_translate(ee, &x, &y);
249 evas_event_feed_multi_up(ee->evas, ev->device, x, y, ev->radius, ev->radius_x, ev->radius_y, ev->flags, ev->timestamp, NULL);
253 _ecore_evas_buffer_cb_multi_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
256 Evas_Event_Multi_Move *ev;
261 x = ev->cur.canvas.x;
262 y = ev->cur.canvas.y;
263 _ecore_evas_buffer_coord_translate(ee, &x, &y);
264 evas_event_feed_multi_move(ee->evas, ev->device, x, y, ev->radius, ev->radius_x, ev->radius_y, ev->timestamp, NULL);
268 _ecore_evas_buffer_cb_free(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
273 if (ee->driver) _ecore_evas_free(ee);
277 _ecore_evas_buffer_cb_key_down(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
280 Evas_Event_Key_Down *ev;
284 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Shift"))
285 evas_key_modifier_on(e, "Shift");
287 evas_key_modifier_off(e, "Shift");
288 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Control"))
289 evas_key_modifier_on(e, "Control");
291 evas_key_modifier_off(e, "Control");
292 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Alt"))
293 evas_key_modifier_on(e, "Alt");
295 evas_key_modifier_off(e, "Alt");
296 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Meta"))
297 evas_key_modifier_on(e, "Meta");
299 evas_key_modifier_off(e, "Meta");
300 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Hyper"))
301 evas_key_modifier_on(e, "Hyper");
303 evas_key_modifier_off(e, "Hyper");
304 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Super"))
305 evas_key_modifier_on(e, "Super");
307 evas_key_modifier_off(e, "Super");
308 if (evas_key_lock_is_set(evas_key_lock_get(e), "Scroll_Lock"))
309 evas_key_lock_on(e, "Scroll_Lock");
311 evas_key_lock_off(e, "Scroll_Lock");
312 if (evas_key_lock_is_set(evas_key_lock_get(e), "Num_Lock"))
313 evas_key_lock_on(e, "Num_Lock");
315 evas_key_lock_off(e, "Num_Lock");
316 if (evas_key_lock_is_set(evas_key_lock_get(e), "Caps_Lock"))
317 evas_key_lock_on(e, "Caps_Lock");
319 evas_key_lock_off(e, "Caps_Lock");
320 evas_event_feed_key_down(ee->evas, ev->keyname, ev->key, ev->string, ev->compose, ev->timestamp, NULL);
324 _ecore_evas_buffer_cb_key_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
327 Evas_Event_Key_Up *ev;
331 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Shift"))
332 evas_key_modifier_on(e, "Shift");
334 evas_key_modifier_off(e, "Shift");
335 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Control"))
336 evas_key_modifier_on(e, "Control");
338 evas_key_modifier_off(e, "Control");
339 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Alt"))
340 evas_key_modifier_on(e, "Alt");
342 evas_key_modifier_off(e, "Alt");
343 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Meta"))
344 evas_key_modifier_on(e, "Meta");
346 evas_key_modifier_off(e, "Meta");
347 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Hyper"))
348 evas_key_modifier_on(e, "Hyper");
350 evas_key_modifier_off(e, "Hyper");
351 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Super"))
352 evas_key_modifier_on(e, "Super");
354 evas_key_modifier_off(e, "Super");
355 if (evas_key_lock_is_set(evas_key_lock_get(e), "Scroll_Lock"))
356 evas_key_lock_on(e, "Scroll_Lock");
358 evas_key_lock_off(e, "Scroll_Lock");
359 if (evas_key_lock_is_set(evas_key_lock_get(e), "Num_Lock"))
360 evas_key_lock_on(e, "Num_Lock");
362 evas_key_lock_off(e, "Num_Lock");
363 if (evas_key_lock_is_set(evas_key_lock_get(e), "Caps_Lock"))
364 evas_key_lock_on(e, "Caps_Lock");
366 evas_key_lock_off(e, "Caps_Lock");
367 evas_event_feed_key_up(ee->evas, ev->keyname, ev->key, ev->string, ev->compose, ev->timestamp, NULL);
371 _ecore_evas_buffer_cb_focus_in(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
376 ee->prop.focused = 1;
377 if (ee->func.fn_focus_in) ee->func.fn_focus_in(ee);
381 _ecore_evas_buffer_cb_focus_out(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
386 ee->prop.focused = 0;
387 if (ee->func.fn_focus_out) ee->func.fn_focus_out(ee);
391 _ecore_evas_buffer_cb_show(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
397 if (ee->func.fn_show) ee->func.fn_show(ee);
401 _ecore_evas_buffer_cb_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
407 if (ee->func.fn_hide) ee->func.fn_hide(ee);
410 static Ecore_Evas_Engine_Func _ecore_buffer_engine_func =
412 _ecore_evas_buffer_free,
465 * FIXME: To be fixed.
468 ecore_evas_buffer_new(int w, int h)
470 #ifdef BUILD_ECORE_EVAS_SOFTWARE_BUFFER
471 Evas_Engine_Info_Buffer *einfo;
475 rmethod = evas_render_method_lookup("buffer");
476 if (!rmethod) return NULL;
477 ee = calloc(1, sizeof(Ecore_Evas));
478 if (!ee) return NULL;
480 ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS);
482 _ecore_evas_buffer_init();
484 ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_buffer_engine_func;
486 ee->driver = "buffer";
498 ee->prop.focused = 1;
499 ee->prop.borderless = 1;
500 ee->prop.override = 1;
501 ee->prop.maximized = 1;
502 ee->prop.fullscreen = 0;
503 ee->prop.withdrawn = 0;
507 ee->evas = evas_new();
508 evas_data_attach_set(ee->evas, ee);
509 evas_output_method_set(ee->evas, rmethod);
510 evas_output_size_set(ee->evas, w, h);
511 evas_output_viewport_set(ee->evas, 0, 0, w, h);
513 ee->engine.buffer.pixels = malloc(w * h * sizeof(int));
515 einfo = (Evas_Engine_Info_Buffer *)evas_engine_info_get(ee->evas);
518 einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_ARGB32;
519 einfo->info.dest_buffer = ee->engine.buffer.pixels;
520 einfo->info.dest_buffer_row_bytes = ee->w * sizeof(int);
521 einfo->info.use_color_key = 0;
522 einfo->info.alpha_threshold = 0;
523 einfo->info.func.new_update_region = NULL;
524 einfo->info.func.free_update_region = NULL;
525 evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
527 evas_key_modifier_add(ee->evas, "Shift");
528 evas_key_modifier_add(ee->evas, "Control");
529 evas_key_modifier_add(ee->evas, "Alt");
530 evas_key_modifier_add(ee->evas, "Meta");
531 evas_key_modifier_add(ee->evas, "Hyper");
532 evas_key_modifier_add(ee->evas, "Super");
533 evas_key_lock_add(ee->evas, "Caps_Lock");
534 evas_key_lock_add(ee->evas, "Num_Lock");
535 evas_key_lock_add(ee->evas, "Scroll_Lock");
537 evas_event_feed_mouse_in(ee->evas, 0, NULL);
539 ee->engine.func->fn_render = _ecore_evas_buffer_render;
540 _ecore_evas_register(ee);
549 ecore_evas_buffer_pixels_get(Ecore_Evas *ee)
551 #ifdef BUILD_ECORE_EVAS_SOFTWARE_BUFFER
552 _ecore_evas_buffer_render(ee);
553 return ee->engine.buffer.pixels;
560 ecore_evas_object_image_new(Ecore_Evas *ee_target)
562 #ifdef BUILD_ECORE_EVAS_SOFTWARE_BUFFER
564 Evas_Engine_Info_Buffer *einfo;
569 rmethod = evas_render_method_lookup("buffer");
570 if (!rmethod) return NULL;
571 ee = calloc(1, sizeof(Ecore_Evas));
572 if (!ee) return NULL;
574 o = evas_object_image_add(ee_target->evas);
576 ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS);
578 _ecore_evas_buffer_init();
580 ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_buffer_engine_func;
582 ee->driver = "buffer";
594 ee->prop.focused = 0;
595 ee->prop.borderless = 1;
596 ee->prop.override = 1;
597 ee->prop.maximized = 0;
598 ee->prop.fullscreen = 0;
599 ee->prop.withdrawn = 0;
603 ee->evas = evas_new();
604 evas_data_attach_set(ee->evas, ee);
605 evas_output_method_set(ee->evas, rmethod);
606 evas_output_size_set(ee->evas, w, h);
607 evas_output_viewport_set(ee->evas, 0, 0, w, h);
609 ee->engine.buffer.image = o;
610 evas_object_data_set(ee->engine.buffer.image, "Ecore_Evas", ee);
611 evas_object_data_set(ee->engine.buffer.image, "Ecore_Evas_Parent", ee_target);
612 evas_object_image_size_set(o, ee->w, ee->h);
613 evas_object_image_alpha_set(o, 1);
614 ee->engine.buffer.pixels = evas_object_image_data_get(o, 1);
615 evas_object_image_data_set(o, ee->engine.buffer.pixels);
616 evas_object_event_callback_add(ee->engine.buffer.image,
617 EVAS_CALLBACK_MOUSE_IN,
618 _ecore_evas_buffer_cb_mouse_in, ee);
619 evas_object_event_callback_add(ee->engine.buffer.image,
620 EVAS_CALLBACK_MOUSE_OUT,
621 _ecore_evas_buffer_cb_mouse_out, ee);
622 evas_object_event_callback_add(ee->engine.buffer.image,
623 EVAS_CALLBACK_MOUSE_DOWN,
624 _ecore_evas_buffer_cb_mouse_down, ee);
625 evas_object_event_callback_add(ee->engine.buffer.image,
626 EVAS_CALLBACK_MOUSE_UP,
627 _ecore_evas_buffer_cb_mouse_up, ee);
628 evas_object_event_callback_add(ee->engine.buffer.image,
629 EVAS_CALLBACK_MOUSE_MOVE,
630 _ecore_evas_buffer_cb_mouse_move, ee);
631 evas_object_event_callback_add(ee->engine.buffer.image,
632 EVAS_CALLBACK_MOUSE_WHEEL,
633 _ecore_evas_buffer_cb_mouse_wheel, ee);
634 evas_object_event_callback_add(ee->engine.buffer.image,
635 EVAS_CALLBACK_MULTI_DOWN,
636 _ecore_evas_buffer_cb_multi_down, ee);
637 evas_object_event_callback_add(ee->engine.buffer.image,
638 EVAS_CALLBACK_MULTI_UP,
639 _ecore_evas_buffer_cb_multi_up, ee);
640 evas_object_event_callback_add(ee->engine.buffer.image,
641 EVAS_CALLBACK_MULTI_MOVE,
642 _ecore_evas_buffer_cb_multi_move, ee);
643 evas_object_event_callback_add(ee->engine.buffer.image,
645 _ecore_evas_buffer_cb_free, ee);
646 evas_object_event_callback_add(ee->engine.buffer.image,
647 EVAS_CALLBACK_KEY_DOWN,
648 _ecore_evas_buffer_cb_key_down, ee);
649 evas_object_event_callback_add(ee->engine.buffer.image,
650 EVAS_CALLBACK_KEY_UP,
651 _ecore_evas_buffer_cb_key_up, ee);
652 evas_object_event_callback_add(ee->engine.buffer.image,
653 EVAS_CALLBACK_FOCUS_IN,
654 _ecore_evas_buffer_cb_focus_in, ee);
655 evas_object_event_callback_add(ee->engine.buffer.image,
656 EVAS_CALLBACK_FOCUS_OUT,
657 _ecore_evas_buffer_cb_focus_out, ee);
658 evas_object_event_callback_add(ee->engine.buffer.image,
660 _ecore_evas_buffer_cb_show, ee);
661 evas_object_event_callback_add(ee->engine.buffer.image,
663 _ecore_evas_buffer_cb_hide, ee);
664 einfo = (Evas_Engine_Info_Buffer *)evas_engine_info_get(ee->evas);
667 einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_ARGB32;
668 einfo->info.dest_buffer = ee->engine.buffer.pixels;
669 einfo->info.dest_buffer_row_bytes = ee->w * sizeof(int);
670 einfo->info.use_color_key = 0;
671 einfo->info.alpha_threshold = 0;
672 einfo->info.func.new_update_region = NULL;
673 einfo->info.func.free_update_region = NULL;
674 evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
676 evas_key_modifier_add(ee->evas, "Shift");
677 evas_key_modifier_add(ee->evas, "Control");
678 evas_key_modifier_add(ee->evas, "Alt");
679 evas_key_modifier_add(ee->evas, "Meta");
680 evas_key_modifier_add(ee->evas, "Hyper");
681 evas_key_modifier_add(ee->evas, "Super");
682 evas_key_lock_add(ee->evas, "Caps_Lock");
683 evas_key_lock_add(ee->evas, "Num_Lock");
684 evas_key_lock_add(ee->evas, "Scroll_Lock");
686 ee_target->sub_ecore_evas = eina_list_append(ee_target->sub_ecore_evas, ee);
688 ee->engine.func->fn_render = _ecore_evas_buffer_render;