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 return _ecore_evas_init_count;
23 _ecore_evas_buffer_free(Ecore_Evas *ee)
25 if (ee->engine.buffer.image)
29 ee2 = evas_object_data_get(ee->engine.buffer.image, "Ecore_Evas_Parent");
30 evas_object_del(ee->engine.buffer.image);
31 ee2->sub_ecore_evas = eina_list_remove(ee2->sub_ecore_evas, ee);
35 ee->engine.buffer.free_func(ee->engine.buffer.data,
36 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)
62 ee->engine.buffer.free_func(ee->engine.buffer.data,
63 ee->engine.buffer.pixels);
64 ee->engine.buffer.pixels =
65 ee->engine.buffer.alloc_func(ee->engine.buffer.data,
66 ee->w * ee->h * sizeof(int));
69 einfo = (Evas_Engine_Info_Buffer *)evas_engine_info_get(ee->evas);
72 einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_ARGB32;
73 einfo->info.dest_buffer = ee->engine.buffer.pixels;
74 einfo->info.dest_buffer_row_bytes = ee->w * sizeof(int);
75 einfo->info.use_color_key = 0;
76 einfo->info.alpha_threshold = 0;
77 einfo->info.func.new_update_region = NULL;
78 einfo->info.func.free_update_region = NULL;
79 evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
81 if (ee->func.fn_resize) ee->func.fn_resize(ee);
85 _ecore_evas_buffer_shutdown(void)
87 _ecore_evas_init_count--;
88 if (_ecore_evas_init_count == 0)
91 if (_ecore_evas_init_count < 0) _ecore_evas_init_count = 0;
92 return _ecore_evas_init_count;
96 _ecore_evas_buffer_render(Ecore_Evas *ee)
98 Eina_List *updates, *l, *ll;
102 EINA_LIST_FOREACH(ee->sub_ecore_evas, ll, ee2)
104 if (ee2->func.fn_pre_render) ee2->func.fn_pre_render(ee2);
105 rend |= _ecore_evas_buffer_render(ee2);
106 if (ee2->func.fn_post_render) ee2->func.fn_post_render(ee2);
108 if (ee->engine.buffer.image)
112 evas_object_image_size_get(ee->engine.buffer.image, &w, &h);
113 if ((w != ee->w) || (h != ee->h))
114 _ecore_evas_resize(ee, w, h);
116 updates = evas_render_updates(ee->evas);
117 if (ee->engine.buffer.image)
121 EINA_LIST_FOREACH(updates, l, r)
122 evas_object_image_data_update_add(ee->engine.buffer.image,
123 r->x, r->y, r->w, r->h);
127 evas_render_updates_free(updates);
128 _ecore_evas_idle_timeout_update(ee);
131 return updates ? 1 : rend;
135 _ecore_evas_buffer_coord_translate(Ecore_Evas *ee, Evas_Coord *x, Evas_Coord *y)
137 Evas_Coord xx, yy, fx, fy, fw, fh;
139 evas_object_geometry_get(ee->engine.buffer.image, &xx, &yy, NULL, NULL);
140 evas_object_image_fill_get(ee->engine.buffer.image, &fx, &fy, &fw, &fh);
144 while (xx < 0) xx += fw;
145 while (xx > fw) xx -= fw;
146 *x = (ee->w * xx) / fw;
150 while (yy < 0) yy += fh;
151 while (yy > fh) yy -= fh;
152 *y = (ee->h * yy) / fh;
156 _ecore_evas_buffer_cb_mouse_in(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
159 Evas_Event_Mouse_In *ev;
163 evas_event_feed_mouse_in(ee->evas, ev->timestamp, NULL);
167 _ecore_evas_buffer_cb_mouse_out(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
170 Evas_Event_Mouse_Out *ev;
174 evas_event_feed_mouse_out(ee->evas, ev->timestamp, NULL);
178 _ecore_evas_buffer_cb_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
181 Evas_Event_Mouse_Down *ev;
185 evas_event_feed_mouse_down(ee->evas, ev->button, ev->flags, ev->timestamp, NULL);
189 _ecore_evas_buffer_cb_mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
192 Evas_Event_Mouse_Up *ev;
196 evas_event_feed_mouse_up(ee->evas, ev->button, ev->flags, ev->timestamp, NULL);
200 _ecore_evas_buffer_cb_mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
203 Evas_Event_Mouse_Move *ev;
208 x = ev->cur.canvas.x;
209 y = ev->cur.canvas.y;
210 _ecore_evas_buffer_coord_translate(ee, &x, &y);
211 _ecore_evas_mouse_move_process(ee, x, y, ev->timestamp);
215 _ecore_evas_buffer_cb_mouse_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
218 Evas_Event_Mouse_Wheel *ev;
222 evas_event_feed_mouse_wheel(ee->evas, ev->direction, ev->z, ev->timestamp, NULL);
226 _ecore_evas_buffer_cb_multi_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
229 Evas_Event_Multi_Down *ev;
230 Evas_Coord x, y, xx, yy;
239 _ecore_evas_buffer_coord_translate(ee, &x, &y);
240 xf = (ev->canvas.xsub - (double)xx) + (double)x;
241 yf = (ev->canvas.ysub - (double)yy) + (double)y;
242 evas_event_feed_multi_down(ee->evas, ev->device, x, y, ev->radius, ev->radius_x, ev->radius_y, ev->pressure, ev->angle, xf, yf, ev->flags, ev->timestamp, NULL);
246 _ecore_evas_buffer_cb_multi_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
249 Evas_Event_Multi_Up *ev;
250 Evas_Coord x, y, xx, yy;
259 _ecore_evas_buffer_coord_translate(ee, &x, &y);
260 xf = (ev->canvas.xsub - (double)xx) + (double)x;
261 yf = (ev->canvas.ysub - (double)yy) + (double)y;
262 evas_event_feed_multi_up(ee->evas, ev->device, x, y, ev->radius, ev->radius_x, ev->radius_y, ev->pressure, ev->angle, xf, yf, ev->flags, ev->timestamp, NULL);
266 _ecore_evas_buffer_cb_multi_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
269 Evas_Event_Multi_Move *ev;
270 Evas_Coord x, y, xx, yy;
275 x = ev->cur.canvas.x;
276 y = ev->cur.canvas.y;
279 _ecore_evas_buffer_coord_translate(ee, &x, &y);
280 xf = (ev->cur.canvas.xsub - (double)xx) + (double)x;
281 yf = (ev->cur.canvas.ysub - (double)yy) + (double)y;
282 evas_event_feed_multi_move(ee->evas, ev->device, x, y, ev->radius, ev->radius_x, ev->radius_y, ev->pressure, ev->angle, xf, yf, ev->timestamp, NULL);
286 _ecore_evas_buffer_cb_free(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
291 if (ee->driver) _ecore_evas_free(ee);
295 _ecore_evas_buffer_cb_key_down(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
298 Evas_Event_Key_Down *ev;
302 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Shift"))
303 evas_key_modifier_on(e, "Shift");
305 evas_key_modifier_off(e, "Shift");
306 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Control"))
307 evas_key_modifier_on(e, "Control");
309 evas_key_modifier_off(e, "Control");
310 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Alt"))
311 evas_key_modifier_on(e, "Alt");
313 evas_key_modifier_off(e, "Alt");
314 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Meta"))
315 evas_key_modifier_on(e, "Meta");
317 evas_key_modifier_off(e, "Meta");
318 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Hyper"))
319 evas_key_modifier_on(e, "Hyper");
321 evas_key_modifier_off(e, "Hyper");
322 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Super"))
323 evas_key_modifier_on(e, "Super");
325 evas_key_modifier_off(e, "Super");
326 if (evas_key_lock_is_set(evas_key_lock_get(e), "Scroll_Lock"))
327 evas_key_lock_on(e, "Scroll_Lock");
329 evas_key_lock_off(e, "Scroll_Lock");
330 if (evas_key_lock_is_set(evas_key_lock_get(e), "Num_Lock"))
331 evas_key_lock_on(e, "Num_Lock");
333 evas_key_lock_off(e, "Num_Lock");
334 if (evas_key_lock_is_set(evas_key_lock_get(e), "Caps_Lock"))
335 evas_key_lock_on(e, "Caps_Lock");
337 evas_key_lock_off(e, "Caps_Lock");
338 evas_event_feed_key_down(ee->evas, ev->keyname, ev->key, ev->string, ev->compose, ev->timestamp, NULL);
342 _ecore_evas_buffer_cb_key_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
345 Evas_Event_Key_Up *ev;
349 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Shift"))
350 evas_key_modifier_on(e, "Shift");
352 evas_key_modifier_off(e, "Shift");
353 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Control"))
354 evas_key_modifier_on(e, "Control");
356 evas_key_modifier_off(e, "Control");
357 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Alt"))
358 evas_key_modifier_on(e, "Alt");
360 evas_key_modifier_off(e, "Alt");
361 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Meta"))
362 evas_key_modifier_on(e, "Meta");
364 evas_key_modifier_off(e, "Meta");
365 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Hyper"))
366 evas_key_modifier_on(e, "Hyper");
368 evas_key_modifier_off(e, "Hyper");
369 if (evas_key_modifier_is_set(evas_key_modifier_get(e), "Super"))
370 evas_key_modifier_on(e, "Super");
372 evas_key_modifier_off(e, "Super");
373 if (evas_key_lock_is_set(evas_key_lock_get(e), "Scroll_Lock"))
374 evas_key_lock_on(e, "Scroll_Lock");
376 evas_key_lock_off(e, "Scroll_Lock");
377 if (evas_key_lock_is_set(evas_key_lock_get(e), "Num_Lock"))
378 evas_key_lock_on(e, "Num_Lock");
380 evas_key_lock_off(e, "Num_Lock");
381 if (evas_key_lock_is_set(evas_key_lock_get(e), "Caps_Lock"))
382 evas_key_lock_on(e, "Caps_Lock");
384 evas_key_lock_off(e, "Caps_Lock");
385 evas_event_feed_key_up(ee->evas, ev->keyname, ev->key, ev->string, ev->compose, ev->timestamp, NULL);
389 _ecore_evas_buffer_cb_focus_in(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
394 ee->prop.focused = 1;
395 evas_focus_in(ee->evas);
396 if (ee->func.fn_focus_in) ee->func.fn_focus_in(ee);
400 _ecore_evas_buffer_cb_focus_out(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
405 ee->prop.focused = 0;
406 evas_focus_out(ee->evas);
407 if (ee->func.fn_focus_out) ee->func.fn_focus_out(ee);
411 _ecore_evas_buffer_cb_show(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
417 if (ee->func.fn_show) ee->func.fn_show(ee);
421 _ecore_evas_buffer_cb_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
427 if (ee->func.fn_hide) ee->func.fn_hide(ee);
430 static Ecore_Evas_Engine_Func _ecore_buffer_engine_func =
432 _ecore_evas_buffer_free,
484 _ecore_evas_buffer_pix_alloc(void *data __UNUSED__, int size)
490 _ecore_evas_buffer_pix_free(void *data __UNUSED__, void *pix)
498 * FIXME: To be fixed.
501 ecore_evas_buffer_new(int w, int h)
503 return ecore_evas_buffer_allocfunc_new
504 (w, h, _ecore_evas_buffer_pix_alloc, _ecore_evas_buffer_pix_free, NULL);
508 ecore_evas_buffer_allocfunc_new(int w, int h, void *(*alloc_func) (void *data, int size), void (*free_func) (void *data, void *pix), const void *data)
510 #ifdef BUILD_ECORE_EVAS_SOFTWARE_BUFFER
511 Evas_Engine_Info_Buffer *einfo;
515 if ((!alloc_func) || (!free_func)) return NULL;
516 rmethod = evas_render_method_lookup("buffer");
517 if (!rmethod) return NULL;
518 ee = calloc(1, sizeof(Ecore_Evas));
519 if (!ee) return NULL;
521 ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS);
523 _ecore_evas_buffer_init();
525 ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_buffer_engine_func;
526 ee->engine.buffer.alloc_func = alloc_func;
527 ee->engine.buffer.free_func = free_func;
528 ee->engine.buffer.data = (void *)data;
530 ee->driver = "buffer";
542 ee->prop.focused = 1;
543 ee->prop.borderless = 1;
544 ee->prop.override = 1;
545 ee->prop.maximized = 1;
546 ee->prop.fullscreen = 0;
547 ee->prop.withdrawn = 0;
551 ee->evas = evas_new();
552 evas_data_attach_set(ee->evas, ee);
553 evas_output_method_set(ee->evas, rmethod);
554 evas_output_size_set(ee->evas, w, h);
555 evas_output_viewport_set(ee->evas, 0, 0, w, h);
557 ee->engine.buffer.pixels =
558 ee->engine.buffer.alloc_func
559 (ee->engine.buffer.data, w * h * sizeof(int));
561 einfo = (Evas_Engine_Info_Buffer *)evas_engine_info_get(ee->evas);
564 einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_ARGB32;
565 einfo->info.dest_buffer = ee->engine.buffer.pixels;
566 einfo->info.dest_buffer_row_bytes = ee->w * sizeof(int);
567 einfo->info.use_color_key = 0;
568 einfo->info.alpha_threshold = 0;
569 einfo->info.func.new_update_region = NULL;
570 einfo->info.func.free_update_region = NULL;
571 evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
573 evas_key_modifier_add(ee->evas, "Shift");
574 evas_key_modifier_add(ee->evas, "Control");
575 evas_key_modifier_add(ee->evas, "Alt");
576 evas_key_modifier_add(ee->evas, "Meta");
577 evas_key_modifier_add(ee->evas, "Hyper");
578 evas_key_modifier_add(ee->evas, "Super");
579 evas_key_lock_add(ee->evas, "Caps_Lock");
580 evas_key_lock_add(ee->evas, "Num_Lock");
581 evas_key_lock_add(ee->evas, "Scroll_Lock");
583 evas_event_feed_mouse_in(ee->evas, 0, NULL);
585 ee->engine.func->fn_render = _ecore_evas_buffer_render;
586 _ecore_evas_register(ee);
595 ecore_evas_buffer_pixels_get(Ecore_Evas *ee)
597 #ifdef BUILD_ECORE_EVAS_SOFTWARE_BUFFER
598 _ecore_evas_buffer_render(ee);
599 return ee->engine.buffer.pixels;
606 ecore_evas_object_image_new(Ecore_Evas *ee_target)
608 #ifdef BUILD_ECORE_EVAS_SOFTWARE_BUFFER
610 Evas_Engine_Info_Buffer *einfo;
615 rmethod = evas_render_method_lookup("buffer");
616 if (!rmethod) return NULL;
617 ee = calloc(1, sizeof(Ecore_Evas));
618 if (!ee) return NULL;
620 o = evas_object_image_add(ee_target->evas);
622 ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS);
624 _ecore_evas_buffer_init();
626 ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_buffer_engine_func;
628 ee->driver = "buffer";
640 ee->prop.focused = 0;
641 ee->prop.borderless = 1;
642 ee->prop.override = 1;
643 ee->prop.maximized = 0;
644 ee->prop.fullscreen = 0;
645 ee->prop.withdrawn = 0;
649 ee->evas = evas_new();
650 evas_data_attach_set(ee->evas, ee);
651 evas_output_method_set(ee->evas, rmethod);
652 evas_output_size_set(ee->evas, w, h);
653 evas_output_viewport_set(ee->evas, 0, 0, w, h);
655 ee->engine.buffer.image = o;
656 evas_object_data_set(ee->engine.buffer.image, "Ecore_Evas", ee);
657 evas_object_data_set(ee->engine.buffer.image, "Ecore_Evas_Parent", ee_target);
658 evas_object_image_size_set(o, ee->w, ee->h);
659 evas_object_image_alpha_set(o, 1);
660 ee->engine.buffer.pixels = evas_object_image_data_get(o, 1);
661 evas_object_image_data_set(o, ee->engine.buffer.pixels);
662 evas_object_event_callback_add(ee->engine.buffer.image,
663 EVAS_CALLBACK_MOUSE_IN,
664 _ecore_evas_buffer_cb_mouse_in, ee);
665 evas_object_event_callback_add(ee->engine.buffer.image,
666 EVAS_CALLBACK_MOUSE_OUT,
667 _ecore_evas_buffer_cb_mouse_out, ee);
668 evas_object_event_callback_add(ee->engine.buffer.image,
669 EVAS_CALLBACK_MOUSE_DOWN,
670 _ecore_evas_buffer_cb_mouse_down, ee);
671 evas_object_event_callback_add(ee->engine.buffer.image,
672 EVAS_CALLBACK_MOUSE_UP,
673 _ecore_evas_buffer_cb_mouse_up, ee);
674 evas_object_event_callback_add(ee->engine.buffer.image,
675 EVAS_CALLBACK_MOUSE_MOVE,
676 _ecore_evas_buffer_cb_mouse_move, ee);
677 evas_object_event_callback_add(ee->engine.buffer.image,
678 EVAS_CALLBACK_MOUSE_WHEEL,
679 _ecore_evas_buffer_cb_mouse_wheel, ee);
680 evas_object_event_callback_add(ee->engine.buffer.image,
681 EVAS_CALLBACK_MULTI_DOWN,
682 _ecore_evas_buffer_cb_multi_down, ee);
683 evas_object_event_callback_add(ee->engine.buffer.image,
684 EVAS_CALLBACK_MULTI_UP,
685 _ecore_evas_buffer_cb_multi_up, ee);
686 evas_object_event_callback_add(ee->engine.buffer.image,
687 EVAS_CALLBACK_MULTI_MOVE,
688 _ecore_evas_buffer_cb_multi_move, ee);
689 evas_object_event_callback_add(ee->engine.buffer.image,
691 _ecore_evas_buffer_cb_free, ee);
692 evas_object_event_callback_add(ee->engine.buffer.image,
693 EVAS_CALLBACK_KEY_DOWN,
694 _ecore_evas_buffer_cb_key_down, ee);
695 evas_object_event_callback_add(ee->engine.buffer.image,
696 EVAS_CALLBACK_KEY_UP,
697 _ecore_evas_buffer_cb_key_up, ee);
698 evas_object_event_callback_add(ee->engine.buffer.image,
699 EVAS_CALLBACK_FOCUS_IN,
700 _ecore_evas_buffer_cb_focus_in, ee);
701 evas_object_event_callback_add(ee->engine.buffer.image,
702 EVAS_CALLBACK_FOCUS_OUT,
703 _ecore_evas_buffer_cb_focus_out, ee);
704 evas_object_event_callback_add(ee->engine.buffer.image,
706 _ecore_evas_buffer_cb_show, ee);
707 evas_object_event_callback_add(ee->engine.buffer.image,
709 _ecore_evas_buffer_cb_hide, ee);
710 einfo = (Evas_Engine_Info_Buffer *)evas_engine_info_get(ee->evas);
713 einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_ARGB32;
714 einfo->info.dest_buffer = ee->engine.buffer.pixels;
715 einfo->info.dest_buffer_row_bytes = ee->w * sizeof(int);
716 einfo->info.use_color_key = 0;
717 einfo->info.alpha_threshold = 0;
718 einfo->info.func.new_update_region = NULL;
719 einfo->info.func.free_update_region = NULL;
720 evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
722 evas_key_modifier_add(ee->evas, "Shift");
723 evas_key_modifier_add(ee->evas, "Control");
724 evas_key_modifier_add(ee->evas, "Alt");
725 evas_key_modifier_add(ee->evas, "Meta");
726 evas_key_modifier_add(ee->evas, "Hyper");
727 evas_key_modifier_add(ee->evas, "Super");
728 evas_key_lock_add(ee->evas, "Caps_Lock");
729 evas_key_lock_add(ee->evas, "Num_Lock");
730 evas_key_lock_add(ee->evas, "Scroll_Lock");
732 ee_target->sub_ecore_evas = eina_list_append(ee_target->sub_ecore_evas, ee);
734 ee->engine.func->fn_render = _ecore_evas_buffer_render;