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_OPENGL_SDL
11 # include <Evas_Engine_GL_SDL.h>
18 #if defined(BUILD_ECORE_EVAS_SOFTWARE_SDL) || defined(BUILD_ECORE_EVAS_OPENGL_SDL)
22 #include "ecore_evas_private.h"
23 #include "Ecore_Evas.h"
26 * SDL only handle one window at a time. That's by definition, there is nothing wrong here.
29 #if defined(BUILD_ECORE_EVAS_SOFTWARE_SDL) || defined(BUILD_ECORE_EVAS_OPENGL_SDL)
31 /* static char *ecore_evas_default_display = "0"; */
32 /* static Ecore_List *ecore_evas_input_devices = NULL; */
34 static int _ecore_evas_init_count = 0;
36 static Ecore_Evas *sdl_ee = NULL;
37 static Ecore_Event_Handler *ecore_evas_event_handlers[4] = {
38 NULL, NULL, NULL, NULL
41 static const char *ecore_evas_sdl_default = "EFL SDL";
42 static int _ecore_evas_fps_debug = 0;
43 static Ecore_Poller *ecore_evas_event;
46 _ecore_evas_sdl_match(void)
52 _ecore_evas_sdl_switch_buffer(void *data, void *dest __UNUSED__)
55 return ((SDL_Surface*)data)->pixels;
59 _ecore_evas_sdl_event_got_focus(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
63 ee = _ecore_evas_sdl_match();
65 if (!ee) return ECORE_CALLBACK_PASS_ON;
68 evas_focus_in(ee->evas);
69 if (ee->func.fn_focus_in) ee->func.fn_focus_in(ee);
70 return ECORE_CALLBACK_PASS_ON;
74 _ecore_evas_sdl_event_lost_focus(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
78 ee = _ecore_evas_sdl_match();
80 if (!ee) return ECORE_CALLBACK_PASS_ON;
83 evas_focus_out(ee->evas);
84 if (ee->func.fn_focus_out) ee->func.fn_focus_out(ee);
85 return ECORE_CALLBACK_PASS_ON;
89 _ecore_evas_sdl_event_video_resize(void *data __UNUSED__, int type __UNUSED__, void *event)
91 Ecore_Sdl_Event_Video_Resize *e;
96 ee = _ecore_evas_sdl_match();
98 if (!ee) return ECORE_CALLBACK_PASS_ON; /* pass on event */
100 rmethod = evas_output_method_get(ee->evas);
101 if (rmethod == evas_render_method_lookup("buffer"))
103 Evas_Engine_Info_Buffer *einfo;
105 einfo = (Evas_Engine_Info_Buffer *) evas_engine_info_get(ee->evas);
108 einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_RGB32;
109 einfo->info.switch_data = SDL_SetVideoMode(e->w, e->h, 32,
110 (ee->prop.hwsurface ? SDL_HWSURFACE : SDL_SWSURFACE)
111 | (ee->prop.fullscreen ? SDL_FULLSCREEN : 0)
112 | (ee->alpha ? SDL_SRCALPHA : 0)
114 if (!einfo->info.switch_data)
119 SDL_SetAlpha(einfo->info.switch_data, SDL_SRCALPHA, 0);
120 SDL_FillRect(einfo->info.switch_data, NULL, 0);
122 einfo->info.dest_buffer = ((SDL_Surface*)einfo->info.switch_data)->pixels;
123 einfo->info.dest_buffer_row_bytes = e->w * sizeof (int);
124 einfo->info.use_color_key = 0;
125 einfo->info.alpha_threshold = 0;
126 einfo->info.func.new_update_region = NULL;
127 einfo->info.func.free_update_region = NULL;
128 einfo->info.func.switch_buffer = _ecore_evas_sdl_switch_buffer;
129 if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *) einfo))
139 evas_output_size_set(ee->evas, e->w, e->h);
140 evas_output_viewport_set(ee->evas, 0, 0, e->w, e->h);
142 return ECORE_CALLBACK_PASS_ON;
146 _ecore_evas_sdl_event_video_expose(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
152 ee = _ecore_evas_sdl_match();
154 if (!ee) return ECORE_CALLBACK_PASS_ON;
155 evas_output_size_get(ee->evas, &w, &h);
156 evas_damage_rectangle_add(ee->evas, 0, 0, w, h);
158 return ECORE_CALLBACK_PASS_ON;
162 _ecore_evas_render(Ecore_Evas *ee)
166 updates = evas_render_updates(ee->evas);
169 evas_render_updates_free(updates);
170 _ecore_evas_idle_timeout_update(ee);
172 return updates ? 1 : 0;
176 _ecore_evas_sdl_render(Ecore_Evas *ee)
182 EINA_LIST_FOREACH(ee->sub_ecore_evas, ll, ee2)
184 if (ee2->func.fn_pre_render) ee2->func.fn_pre_render(ee2);
185 if (ee2->engine.func->fn_render)
186 rend |= ee2->engine.func->fn_render(ee2);
187 if (ee2->func.fn_post_render) ee2->func.fn_post_render(ee2);
190 if (ee->func.fn_pre_render) ee->func.fn_pre_render(ee);
192 if (ee->prop.avoid_damage) rend = _ecore_evas_render(ee);
193 else if ((ee->visible) ||
194 ((ee->should_be_visible) && (ee->prop.fullscreen)) ||
195 ((ee->should_be_visible) && (ee->prop.override)))
196 rend |= _ecore_evas_render(ee);
198 evas_norender(ee->evas);
200 if (ee->func.fn_post_render) ee->func.fn_post_render(ee);
205 _ecore_evas_sdl_event(void *data __UNUSED__)
207 ecore_sdl_feed_events();
208 return ECORE_CALLBACK_RENEW;
212 _ecore_evas_sdl_init(int w __UNUSED__, int h __UNUSED__)
214 _ecore_evas_init_count++;
215 if (_ecore_evas_init_count > 1) return _ecore_evas_init_count;
218 if (getenv("ECORE_EVAS_FPS_DEBUG")) _ecore_evas_fps_debug = 1;
220 // this is pretty bad: poller? and set poll time? pol time is meant to be
221 // adjustable for things like polling battery state, or amoutn of spare
224 ecore_evas_event = ecore_poller_add(ECORE_POLLER_CORE, 1, _ecore_evas_sdl_event, NULL);
225 ecore_poller_poll_interval_set(ECORE_POLLER_CORE, 0.006);
227 if (_ecore_evas_fps_debug) _ecore_evas_fps_debug_init();
230 ecore_event_evas_init();
232 ecore_evas_event_handlers[0] = ecore_event_handler_add(ECORE_SDL_EVENT_GOT_FOCUS, _ecore_evas_sdl_event_got_focus, NULL);
233 ecore_evas_event_handlers[1] = ecore_event_handler_add(ECORE_SDL_EVENT_LOST_FOCUS, _ecore_evas_sdl_event_lost_focus, NULL);
234 ecore_evas_event_handlers[2] = ecore_event_handler_add(ECORE_SDL_EVENT_RESIZE, _ecore_evas_sdl_event_video_resize, NULL);
235 ecore_evas_event_handlers[3] = ecore_event_handler_add(ECORE_SDL_EVENT_EXPOSE, _ecore_evas_sdl_event_video_expose, NULL);
237 return _ecore_evas_init_count;
241 _ecore_evas_sdl_shutdown(void)
243 _ecore_evas_init_count--;
244 if (_ecore_evas_init_count == 0)
248 for (i = 0; i < sizeof (ecore_evas_event_handlers) / sizeof (Ecore_Event_Handler*); i++)
249 ecore_event_handler_del(ecore_evas_event_handlers[i]);
250 ecore_event_evas_shutdown();
251 ecore_poller_del(ecore_evas_event);
252 ecore_evas_event = NULL;
254 if (_ecore_evas_fps_debug) _ecore_evas_fps_debug_shutdown();
257 if (_ecore_evas_init_count < 0) _ecore_evas_init_count = 0;
258 return _ecore_evas_init_count;
262 _ecore_evas_sdl_free(Ecore_Evas *ee)
264 if (sdl_ee == ee) sdl_ee = NULL;
266 ecore_event_window_unregister(0);
267 _ecore_evas_sdl_shutdown();
268 ecore_sdl_shutdown();
272 _ecore_evas_resize(Ecore_Evas *ee, int w, int h)
276 if ((w == ee->w) && (h == ee->h)) return;
280 rmethod = evas_output_method_get(ee->evas);
281 if (rmethod == evas_render_method_lookup("buffer"))
283 Evas_Engine_Info_Buffer *einfo;
285 einfo = (Evas_Engine_Info_Buffer *) evas_engine_info_get(ee->evas);
288 einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_RGB32;
289 einfo->info.switch_data = SDL_SetVideoMode(w, h, 32,
290 (ee->prop.hwsurface ? SDL_HWSURFACE : SDL_SWSURFACE)
291 | (ee->prop.fullscreen ? SDL_FULLSCREEN : 0)
292 | (ee->alpha ? SDL_SRCALPHA : 0)
294 if (!einfo->info.switch_data)
299 SDL_SetAlpha(einfo->info.switch_data, SDL_SRCALPHA, 0);
300 SDL_FillRect(einfo->info.switch_data, NULL, 0);
302 einfo->info.dest_buffer = ((SDL_Surface*)einfo->info.switch_data)->pixels;
303 einfo->info.dest_buffer_row_bytes = w * sizeof (int);
304 einfo->info.use_color_key = 0;
305 einfo->info.alpha_threshold = 0;
306 einfo->info.func.new_update_region = NULL;
307 einfo->info.func.free_update_region = NULL;
308 einfo->info.func.switch_buffer = _ecore_evas_sdl_switch_buffer;
309 if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *) einfo))
316 evas_output_size_set(ee->evas, ee->w, ee->h);
317 evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
318 evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h);
320 if (ee->func.fn_resize) ee->func.fn_resize(ee);
324 _ecore_evas_move_resize(Ecore_Evas *ee, int x __UNUSED__, int y __UNUSED__, int w, int h)
326 if ((w == ee->w) && (h == ee->h)) return;
330 evas_output_size_set(ee->evas, ee->w, ee->h);
331 evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
332 evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h);
334 if (ee->func.fn_resize) ee->func.fn_resize(ee);
338 _ecore_evas_show(Ecore_Evas *ee)
340 if (ee->prop.focused) return;
341 ee->prop.focused = 1;
342 evas_event_feed_mouse_in(ee->evas, (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff), NULL);
346 _ecore_evas_object_cursor_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
351 if (ee) ee->prop.cursor.object = NULL;
355 _ecore_evas_object_cursor_set(Ecore_Evas *ee, Evas_Object *obj, int layer, int hot_x, int hot_y)
359 if (ee->prop.cursor.object) evas_object_del(ee->prop.cursor.object);
363 ee->prop.cursor.object = NULL;
364 ee->prop.cursor.layer = 0;
365 ee->prop.cursor.hot.x = 0;
366 ee->prop.cursor.hot.y = 0;
370 ee->prop.cursor.object = obj;
371 ee->prop.cursor.layer = layer;
372 ee->prop.cursor.hot.x = hot_x;
373 ee->prop.cursor.hot.y = hot_y;
374 evas_pointer_output_xy_get(ee->evas, &x, &y);
375 evas_object_layer_set(ee->prop.cursor.object, ee->prop.cursor.layer);
376 evas_object_move(ee->prop.cursor.object,
377 x - ee->prop.cursor.hot.x,
378 y - ee->prop.cursor.hot.y);
379 evas_object_pass_events_set(ee->prop.cursor.object, 1);
380 if (evas_pointer_inside_get(ee->evas))
381 evas_object_show(ee->prop.cursor.object);
383 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, _ecore_evas_object_cursor_del, ee);
386 static Ecore_Evas_Engine_Func _ecore_sdl_engine_func =
388 _ecore_evas_sdl_free,
406 _ecore_evas_move_resize,
420 _ecore_evas_object_cursor_set,
434 NULL, // profiles_set
444 NULL, // screen_geometry_get
445 NULL // screen_dpi_get
449 _ecore_evas_internal_sdl_new(int rmethod, const char* name, int w, int h, int fullscreen, int hwsurface, int noframe, int alpha)
454 name = ecore_evas_sdl_default;
456 ee = calloc(1, sizeof(Ecore_Evas));
457 if (!ee) return NULL;
459 ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS);
461 ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_sdl_engine_func;
464 if (name) ee->name = strdup(name);
475 ee->prop.focused = 1;
476 ee->prop.borderless = 1;
477 ee->prop.override = 1;
478 ee->prop.maximized = 1;
479 ee->prop.fullscreen = fullscreen;
480 ee->prop.withdrawn = 0;
484 ee->prop.hwsurface = hwsurface;
487 ee->evas = evas_new();
488 evas_data_attach_set(ee->evas, ee);
489 evas_output_method_set(ee->evas, rmethod);
491 evas_output_size_set(ee->evas, w, h);
492 evas_output_viewport_set(ee->evas, 0, 0, w, h);
494 if (rmethod == evas_render_method_lookup("buffer"))
496 Evas_Engine_Info_Buffer *einfo;
498 einfo = (Evas_Engine_Info_Buffer *) evas_engine_info_get(ee->evas);
501 SDL_Init(SDL_INIT_NOPARACHUTE);
503 if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
505 ERR("SDL_Init failed with %s", SDL_GetError());
510 einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_RGB32;
511 einfo->info.switch_data = SDL_SetVideoMode(w, h, 32,
512 (hwsurface ? SDL_HWSURFACE : SDL_SWSURFACE)
513 | (fullscreen ? SDL_FULLSCREEN : 0)
514 | (noframe ? SDL_NOFRAME : 0)
515 | (alpha ? SDL_SRCALPHA : 0)
517 if (!einfo->info.switch_data)
519 ERR("SDL_SetVideoMode failed !");
524 SDL_SetAlpha(einfo->info.switch_data, SDL_SRCALPHA, 0);
525 SDL_FillRect(einfo->info.switch_data, NULL, 0);
527 einfo->info.dest_buffer = ((SDL_Surface*)einfo->info.switch_data)->pixels;
528 einfo->info.dest_buffer_row_bytes = w * sizeof (int);
529 einfo->info.use_color_key = 0;
530 einfo->info.alpha_threshold = 0;
531 einfo->info.func.new_update_region = NULL;
532 einfo->info.func.free_update_region = NULL;
533 einfo->info.func.switch_buffer = _ecore_evas_sdl_switch_buffer;
534 if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *) einfo))
536 ERR("evas_engine_info_set() for engine '%s' failed.", ee->driver);
543 ERR("evas_engine_info_set() init engine '%s' failed.", ee->driver);
548 else if (rmethod == evas_render_method_lookup("gl_sdl"))
550 #ifdef BUILD_ECORE_EVAS_OPENGL_SDL
551 Evas_Engine_Info_GL_SDL *einfo;
553 einfo = (Evas_Engine_Info_GL_SDL *) evas_engine_info_get(ee->evas);
556 einfo->flags.fullscreen = fullscreen;
557 einfo->flags.noframe = noframe;
558 if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo))
560 ERR("evas_engine_info_set() for engine '%s' failed.", ee->driver);
567 ERR("evas_engine_info_set() init engine '%s' failed.", ee->driver);
575 ERR("evas_engine_info_set() init engine '%s' failed.", ee->driver);
580 if (!ecore_sdl_init(name))
583 if (ee->name) free(ee->name);
588 _ecore_evas_sdl_init(w, h);
590 ecore_event_window_register(0, ee, ee->evas,
591 (Ecore_Event_Mouse_Move_Cb)_ecore_evas_mouse_move_process,
592 (Ecore_Event_Multi_Move_Cb)_ecore_evas_mouse_multi_move_process,
593 (Ecore_Event_Multi_Down_Cb)_ecore_evas_mouse_multi_down_process,
594 (Ecore_Event_Multi_Up_Cb)_ecore_evas_mouse_multi_up_process);
596 SDL_ShowCursor(SDL_ENABLE);
598 ee->engine.func->fn_render = _ecore_evas_sdl_render;
599 _ecore_evas_register(ee);
606 #ifdef BUILD_ECORE_EVAS_SOFTWARE_SDL
608 ecore_evas_sdl_new(const char* name, int w, int h, int fullscreen, int hwsurface, int noframe, int alpha)
613 rmethod = evas_render_method_lookup("buffer");
614 if (!rmethod) return NULL;
616 ee = _ecore_evas_internal_sdl_new(rmethod, name, w, h, fullscreen, hwsurface, noframe, alpha);
621 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__)
629 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__)
635 #ifdef BUILD_ECORE_EVAS_OPENGL_SDL
637 ecore_evas_gl_sdl_new(const char* name, int w, int h, int fullscreen, int noframe)
642 rmethod = evas_render_method_lookup("gl_sdl");
643 if (!rmethod) return NULL;
645 ee = _ecore_evas_internal_sdl_new(rmethod, name, w, h, fullscreen, 0, noframe, 0);
646 if (ee) ee->driver = "gl_sdl";
651 ecore_evas_gl_sdl_new(const char* name __UNUSED__, int w __UNUSED__, int h __UNUSED__, int fullscreen __UNUSED__, int noframe __UNUSED__)