6 #include <Ecore_Input.h>
7 #include <Ecore_Input_Evas.h>
8 #if defined(BUILD_ECORE_EVAS_SOFTWARE_SDL) || defined(BUILD_ECORE_EVAS_OPENGL_SDL)
9 # include <Ecore_Sdl.h>
10 # ifdef BUILD_ECORE_EVAS_SOFTWARE_SDL
11 # include <Evas_Engine_SDL.h>
13 # ifdef BUILD_ECORE_EVAS_OPENGL_SDL
14 # include <Evas_Engine_GL_SDL.h>
18 #include "ecore_evas_private.h"
19 #include "Ecore_Evas.h"
21 // fixme: 1 sdl window only at a time? seems wrong
23 #if defined(BUILD_ECORE_EVAS_SOFTWARE_SDL) || defined(BUILD_ECORE_EVAS_OPENGL_SDL)
25 /* static char *ecore_evas_default_display = "0"; */
26 /* static Ecore_List *ecore_evas_input_devices = NULL; */
28 static int _ecore_evas_init_count = 0;
30 static Ecore_Evas *sdl_ee = NULL;
31 static Ecore_Event_Handler *ecore_evas_event_handlers[4] = {
32 NULL, NULL, NULL, NULL
35 static const char *ecore_evas_sdl_default = "EFL SDL";
36 static int _ecore_evas_fps_debug = 0;
37 static Ecore_Poller *ecore_evas_event;
38 static Ecore_Evas *ecore_evases = NULL;
41 _ecore_evas_sdl_match(void)
47 _ecore_evas_sdl_event_got_focus(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
51 ee = _ecore_evas_sdl_match();
53 if (!ee) return ECORE_CALLBACK_PASS_ON;
57 return ECORE_CALLBACK_DONE;
61 _ecore_evas_sdl_event_lost_focus(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
65 ee = _ecore_evas_sdl_match();
67 if (!ee) return ECORE_CALLBACK_PASS_ON;
71 return ECORE_CALLBACK_DONE;
75 _ecore_evas_sdl_event_video_resize(void *data __UNUSED__, int type __UNUSED__, void *event)
77 Ecore_Sdl_Event_Video_Resize *e;
81 ee = _ecore_evas_sdl_match();
83 if (!ee) return ECORE_CALLBACK_PASS_ON; /* pass on event */
84 evas_output_size_set(ee->evas, e->w, e->h);
86 return ECORE_CALLBACK_DONE;
90 _ecore_evas_sdl_event_video_expose(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
96 ee = _ecore_evas_sdl_match();
98 if (!ee) return ECORE_CALLBACK_PASS_ON;
99 evas_output_size_get(ee->evas, &w, &h);
100 evas_damage_rectangle_add(ee->evas, 0, 0, w, h);
102 return ECORE_CALLBACK_DONE;
106 _ecore_evas_render(Ecore_Evas *ee)
110 updates = evas_render_updates(ee->evas);
113 evas_render_updates_free(updates);
114 _ecore_evas_idle_timeout_update(ee);
116 return updates ? 1 : 0;
120 _ecore_evas_sdl_render(Ecore_Evas *ee)
124 #ifdef BUILD_ECORE_EVAS_SOFTWARE_BUFFER
128 EINA_LIST_FOREACH(ee->sub_ecore_evas, ll, ee2)
130 if (ee2->func.fn_pre_render) ee2->func.fn_pre_render(ee2);
131 rend |= _ecore_evas_buffer_render(ee2);
132 if (ee2->func.fn_post_render) ee2->func.fn_post_render(ee2);
136 if (ee->func.fn_pre_render) ee->func.fn_pre_render(ee);
138 if (ee->prop.avoid_damage) rend = _ecore_evas_render(ee);
139 else if ((ee->visible) ||
140 ((ee->should_be_visible) && (ee->prop.fullscreen)) ||
141 ((ee->should_be_visible) && (ee->prop.override)))
142 rend |= _ecore_evas_render(ee);
144 evas_norender(ee->evas);
146 if (ee->func.fn_post_render) ee->func.fn_post_render(ee);
151 _ecore_evas_sdl_event(void *data __UNUSED__)
153 ecore_sdl_feed_events();
154 return ECORE_CALLBACK_RENEW;
158 _ecore_evas_sdl_init(int w __UNUSED__, int h __UNUSED__)
160 _ecore_evas_init_count++;
161 if (_ecore_evas_init_count > 1) return _ecore_evas_init_count;
164 if (getenv("ECORE_EVAS_FPS_DEBUG")) _ecore_evas_fps_debug = 1;
166 // this is pretty bad: poller? and set poll time? pol time is meant to be
167 // adjustable for things like polling battery state, or amoutn of spare
170 ecore_evas_event = ecore_poller_add(ECORE_POLLER_CORE, 1, _ecore_evas_sdl_event, NULL);
171 ecore_poller_poll_interval_set(ECORE_POLLER_CORE, 0.006);
173 if (_ecore_evas_fps_debug) _ecore_evas_fps_debug_init();
176 ecore_event_evas_init();
178 ecore_evas_event_handlers[0] = ecore_event_handler_add(ECORE_SDL_EVENT_GOT_FOCUS, _ecore_evas_sdl_event_got_focus, NULL);
179 ecore_evas_event_handlers[1] = ecore_event_handler_add(ECORE_SDL_EVENT_LOST_FOCUS, _ecore_evas_sdl_event_lost_focus, NULL);
180 ecore_evas_event_handlers[2] = ecore_event_handler_add(ECORE_SDL_EVENT_RESIZE, _ecore_evas_sdl_event_video_resize, NULL);
181 ecore_evas_event_handlers[3] = ecore_event_handler_add(ECORE_SDL_EVENT_EXPOSE, _ecore_evas_sdl_event_video_expose, NULL);
183 return _ecore_evas_init_count;
187 _ecore_evas_sdl_shutdown(void)
189 _ecore_evas_init_count--;
190 if (_ecore_evas_init_count == 0)
194 for (i = 0; i < sizeof (ecore_evas_event_handlers) / sizeof (Ecore_Event_Handler*); i++)
195 ecore_event_handler_del(ecore_evas_event_handlers[i]);
196 ecore_event_evas_shutdown();
197 ecore_poller_del(ecore_evas_event);
198 ecore_evas_event = NULL;
200 if (_ecore_evas_fps_debug) _ecore_evas_fps_debug_shutdown();
203 if (_ecore_evas_init_count < 0) _ecore_evas_init_count = 0;
204 return _ecore_evas_init_count;
208 _ecore_evas_sdl_free(Ecore_Evas *ee)
210 if (sdl_ee == ee) sdl_ee = NULL;
212 ecore_event_window_unregister(0);
213 _ecore_evas_sdl_shutdown();
214 ecore_sdl_shutdown();
218 _ecore_evas_resize(Ecore_Evas *ee, int w, int h)
220 if ((w == ee->w) && (h == ee->h)) return;
224 evas_output_size_set(ee->evas, ee->w, ee->h);
225 evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
226 evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h);
228 if (ee->func.fn_resize) ee->func.fn_resize(ee);
232 _ecore_evas_move_resize(Ecore_Evas *ee, int x __UNUSED__, int y __UNUSED__, int w, int h)
234 if ((w == ee->w) && (h == ee->h)) return;
238 evas_output_size_set(ee->evas, ee->w, ee->h);
239 evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
240 evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h);
242 if (ee->func.fn_resize) ee->func.fn_resize(ee);
246 _ecore_evas_object_cursor_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
252 ee->prop.cursor.object = NULL;
256 _ecore_evas_object_cursor_set(Ecore_Evas *ee, Evas_Object *obj, int layer, int hot_x, int hot_y)
260 if (ee->prop.cursor.object) evas_object_del(ee->prop.cursor.object);
264 ee->prop.cursor.object = NULL;
265 ee->prop.cursor.layer = 0;
266 ee->prop.cursor.hot.x = 0;
267 ee->prop.cursor.hot.y = 0;
271 ee->prop.cursor.object = obj;
272 ee->prop.cursor.layer = layer;
273 ee->prop.cursor.hot.x = hot_x;
274 ee->prop.cursor.hot.y = hot_y;
275 evas_pointer_output_xy_get(ee->evas, &x, &y);
276 evas_object_layer_set(ee->prop.cursor.object, ee->prop.cursor.layer);
277 evas_object_move(ee->prop.cursor.object,
278 x - ee->prop.cursor.hot.x,
279 y - ee->prop.cursor.hot.y);
280 evas_object_pass_events_set(ee->prop.cursor.object, 1);
281 if (evas_pointer_inside_get(ee->evas))
282 evas_object_show(ee->prop.cursor.object);
284 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, _ecore_evas_object_cursor_del, ee);
287 static Ecore_Evas_Engine_Func _ecore_sdl_engine_func =
289 _ecore_evas_sdl_free,
307 _ecore_evas_move_resize,
321 _ecore_evas_object_cursor_set,
340 _ecore_evas_internal_sdl_new(int rmethod, const char* name, int w, int h, int fullscreen, int hwsurface, int noframe, int alpha)
346 name = ecore_evas_sdl_default;
348 if (ecore_evases) return NULL;
350 ee = calloc(1, sizeof(Ecore_Evas));
351 if (!ee) return NULL;
353 ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS);
355 ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_sdl_engine_func;
358 if (name) ee->name = strdup(name);
369 ee->prop.focused = 1;
370 ee->prop.borderless = 1;
371 ee->prop.override = 1;
372 ee->prop.maximized = 1;
373 ee->prop.fullscreen = fullscreen;
374 ee->prop.withdrawn = 0;
379 ee->evas = evas_new();
380 evas_data_attach_set(ee->evas, ee);
381 evas_output_method_set(ee->evas, rmethod);
383 evas_output_size_set(ee->evas, w, h);
384 evas_output_viewport_set(ee->evas, 0, 0, w, h);
386 if (rmethod == evas_render_method_lookup("software_sdl"))
388 #ifdef BUILD_ECORE_EVAS_SOFTWARE_SDL
389 einfo = evas_engine_info_get(ee->evas);
392 ((Evas_Engine_Info_SDL *)einfo)->info.rotation = 0;
393 ((Evas_Engine_Info_SDL *)einfo)->info.fullscreen = fullscreen;
394 ((Evas_Engine_Info_SDL *)einfo)->info.hwsurface = hwsurface;
395 ((Evas_Engine_Info_SDL *)einfo)->info.noframe = noframe;
396 ((Evas_Engine_Info_SDL *)einfo)->info.alpha = alpha;
397 if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo))
399 ERR("evas_engine_info_set() for engine '%s' failed.", ee->driver);
404 else if (rmethod == evas_render_method_lookup("gl_sdl"))
406 #ifdef BUILD_ECORE_EVAS_OPENGL_SDL
407 einfo = evas_engine_info_get(ee->evas);
410 ((Evas_Engine_Info_GL_SDL *)einfo)->flags.fullscreen = fullscreen;
411 ((Evas_Engine_Info_GL_SDL *)einfo)->flags.noframe = noframe;
412 if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo))
414 ERR("evas_engine_info_set() for engine '%s' failed.", ee->driver);
420 if (!ecore_sdl_init(name))
423 if (ee->name) free(ee->name);
428 _ecore_evas_sdl_init(w, h);
430 ecore_event_window_register(0, ee, ee->evas,
431 (Ecore_Event_Mouse_Move_Cb)_ecore_evas_mouse_move_process,
432 (Ecore_Event_Multi_Move_Cb)_ecore_evas_mouse_multi_move_process,
433 (Ecore_Event_Multi_Down_Cb)_ecore_evas_mouse_multi_down_process,
434 (Ecore_Event_Multi_Up_Cb)_ecore_evas_mouse_multi_up_process);
436 SDL_ShowCursor(SDL_DISABLE);
438 ee->engine.func->fn_render = _ecore_evas_sdl_render;
439 _ecore_evas_register(ee);
443 evas_event_feed_mouse_in(ee->evas, (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff), NULL);
444 evas_focus_in(ee->evas);
450 #ifdef BUILD_ECORE_EVAS_SOFTWARE_SDL
452 ecore_evas_sdl_new(const char* name, int w, int h, int fullscreen, int hwsurface, int noframe, int alpha)
457 rmethod = evas_render_method_lookup("software_sdl");
458 if (!rmethod) return NULL;
460 ee = _ecore_evas_internal_sdl_new(rmethod, name, w, h, fullscreen, hwsurface, noframe, alpha);
466 ecore_evas_sdl_new(const char* name __UNUSED__, int w __UNUSED__, int h __UNUSED__, int fullscreen __UNUSED__, int hwsurface __UNUSED__, int noframe __UNUSED__, int alpha __UNUSED__)
473 #ifdef BUILD_ECORE_EVAS_SOFTWARE_SDL
475 ecore_evas_sdl16_new(const char* name, int w, int h, int fullscreen, int hwsurface, int noframe, int alpha)
480 rmethod = evas_render_method_lookup("software_16_sdl");
481 if (!rmethod) return NULL;
483 ee = _ecore_evas_internal_sdl_new(rmethod, name, w, h, fullscreen, hwsurface, noframe, alpha);
484 ee->driver = "software_16_sdl";
489 ecore_evas_sdl16_new(const char* name __UNUSED__, int w __UNUSED__, int h __UNUSED__, int fullscreen __UNUSED__, int hwsurface __UNUSED__, int noframe __UNUSED__, int alpha __UNUSED__)
496 #ifdef BUILD_ECORE_EVAS_OPENGL_SDL
498 ecore_evas_gl_sdl_new(const char* name, int w, int h, int fullscreen, int noframe)
503 rmethod = evas_render_method_lookup("gl_sdl");
504 if (!rmethod) return NULL;
506 ee = _ecore_evas_internal_sdl_new(rmethod, name, w, h, fullscreen, 0, noframe, 0);
507 ee->driver = "gl_sdl";
512 ecore_evas_gl_sdl_new(const char* name __UNUSED__, int w __UNUSED__, int h __UNUSED__, int fullscreen __UNUSED__, int noframe __UNUSED__)