2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
10 #include <Ecore_Input.h>
11 #include <Ecore_Input_Evas.h>
12 #if defined(BUILD_ECORE_EVAS_SOFTWARE_SDL) || defined(BUILD_ECORE_EVAS_OPENGL_SDL)
13 # include <Ecore_Sdl.h>
14 # ifdef BUILD_ECORE_EVAS_SOFTWARE_SDL
15 # include <Evas_Engine_SDL.h>
17 # ifdef BUILD_ECORE_EVAS_OPENGL_SDL
18 # include <Evas_Engine_GL_SDL.h>
22 #include "ecore_evas_private.h"
23 #include "Ecore_Evas.h"
25 // fixme: 1 sdl window only at a time? seems wrong
27 #if defined(BUILD_ECORE_EVAS_SOFTWARE_SDL) || defined(BUILD_ECORE_EVAS_OPENGL_SDL)
29 /* static char *ecore_evas_default_display = "0"; */
30 /* static Ecore_List *ecore_evas_input_devices = NULL; */
32 static int _ecore_evas_init_count = 0;
34 static Ecore_Evas *sdl_ee = NULL;
35 static Ecore_Event_Handler *ecore_evas_event_handlers[4] = {
36 NULL, NULL, NULL, NULL
39 static const char *ecore_evas_sdl_default = "EFL SDL";
40 static int _ecore_evas_fps_debug = 0;
41 static Ecore_Poller *ecore_evas_event;
42 static Ecore_Evas *ecore_evases = NULL;
45 _ecore_evas_sdl_match(void)
51 _ecore_evas_sdl_event_got_focus(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
55 ee = _ecore_evas_sdl_match();
65 _ecore_evas_sdl_event_lost_focus(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
69 ee = _ecore_evas_sdl_match();
79 _ecore_evas_sdl_event_video_resize(void *data __UNUSED__, int type __UNUSED__, void *event)
81 Ecore_Sdl_Event_Video_Resize *e;
85 ee = _ecore_evas_sdl_match();
87 if (!ee) return 1; /* pass on event */
88 evas_output_size_set(ee->evas, e->w, e->h);
94 _ecore_evas_sdl_event_video_expose(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
100 ee = _ecore_evas_sdl_match();
103 evas_output_size_get(ee->evas, &w, &h);
104 evas_damage_rectangle_add(ee->evas, 0, 0, w, h);
110 _ecore_evas_render(Ecore_Evas *ee)
114 updates = evas_render_updates(ee->evas);
117 evas_render_updates_free(updates);
118 _ecore_evas_idle_timeout_update(ee);
120 return updates ? 1 : 0;
124 _ecore_evas_sdl_render(Ecore_Evas *ee)
128 #ifdef BUILD_ECORE_EVAS_SOFTWARE_BUFFER
132 EINA_LIST_FOREACH(ee->sub_ecore_evas, ll, ee2)
134 if (ee2->func.fn_pre_render) ee2->func.fn_pre_render(ee2);
135 rend |= _ecore_evas_buffer_render(ee2);
136 if (ee2->func.fn_post_render) ee2->func.fn_post_render(ee2);
140 if (ee->func.fn_pre_render) ee->func.fn_pre_render(ee);
142 if (ee->prop.avoid_damage) rend = _ecore_evas_render(ee);
143 else if ((ee->visible) ||
144 ((ee->should_be_visible) && (ee->prop.fullscreen)) ||
145 ((ee->should_be_visible) && (ee->prop.override)))
146 rend |= _ecore_evas_render(ee);
148 evas_norender(ee->evas);
150 if (ee->func.fn_post_render) ee->func.fn_post_render(ee);
155 _ecore_evas_sdl_event(void *data __UNUSED__)
157 ecore_sdl_feed_events();
162 _ecore_evas_sdl_init(int w __UNUSED__, int h __UNUSED__)
164 _ecore_evas_init_count++;
165 if (_ecore_evas_init_count > 1) return _ecore_evas_init_count;
168 if (getenv("ECORE_EVAS_FPS_DEBUG")) _ecore_evas_fps_debug = 1;
170 // this is pretty bad: poller? and set poll time? pol time is meant to be
171 // adjustable for things like polling battery state, or amoutn of spare
174 ecore_evas_event = ecore_poller_add(ECORE_POLLER_CORE, 1, _ecore_evas_sdl_event, NULL);
175 ecore_poller_poll_interval_set(ECORE_POLLER_CORE, 0.006);
177 if (_ecore_evas_fps_debug) _ecore_evas_fps_debug_init();
180 ecore_event_evas_init();
182 ecore_evas_event_handlers[0] = ecore_event_handler_add(ECORE_SDL_EVENT_GOT_FOCUS, _ecore_evas_sdl_event_got_focus, NULL);
183 ecore_evas_event_handlers[1] = ecore_event_handler_add(ECORE_SDL_EVENT_LOST_FOCUS, _ecore_evas_sdl_event_lost_focus, NULL);
184 ecore_evas_event_handlers[2] = ecore_event_handler_add(ECORE_SDL_EVENT_RESIZE, _ecore_evas_sdl_event_video_resize, NULL);
185 ecore_evas_event_handlers[3] = ecore_event_handler_add(ECORE_SDL_EVENT_EXPOSE, _ecore_evas_sdl_event_video_expose, NULL);
187 return _ecore_evas_init_count;
191 _ecore_evas_sdl_shutdown(void)
193 _ecore_evas_init_count--;
194 if (_ecore_evas_init_count == 0)
198 for (i = 0; i < sizeof (ecore_evas_event_handlers) / sizeof (Ecore_Event_Handler*); i++)
199 ecore_event_handler_del(ecore_evas_event_handlers[i]);
200 ecore_event_evas_shutdown();
201 ecore_poller_del(ecore_evas_event);
202 ecore_evas_event = NULL;
204 if (_ecore_evas_fps_debug) _ecore_evas_fps_debug_shutdown();
207 if (_ecore_evas_init_count < 0) _ecore_evas_init_count = 0;
208 return _ecore_evas_init_count;
212 _ecore_evas_sdl_free(Ecore_Evas *ee)
214 if (sdl_ee == ee) sdl_ee = NULL;
216 ecore_event_window_unregister(0);
217 _ecore_evas_sdl_shutdown();
218 ecore_sdl_shutdown();
222 _ecore_evas_resize(Ecore_Evas *ee, int w, int h)
224 if ((w == ee->w) && (h == ee->h)) return;
228 evas_output_size_set(ee->evas, ee->w, ee->h);
229 evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
230 evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h);
232 if (ee->func.fn_resize) ee->func.fn_resize(ee);
236 _ecore_evas_move_resize(Ecore_Evas *ee, int x __UNUSED__, int y __UNUSED__, int w, int h)
238 if ((w == ee->w) && (h == ee->h)) return;
242 evas_output_size_set(ee->evas, ee->w, ee->h);
243 evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
244 evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h);
246 if (ee->func.fn_resize) ee->func.fn_resize(ee);
250 _ecore_evas_object_cursor_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
256 ee->prop.cursor.object = NULL;
260 _ecore_evas_object_cursor_set(Ecore_Evas *ee, Evas_Object *obj, int layer, int hot_x, int hot_y)
264 if (ee->prop.cursor.object) evas_object_del(ee->prop.cursor.object);
268 ee->prop.cursor.object = NULL;
269 ee->prop.cursor.layer = 0;
270 ee->prop.cursor.hot.x = 0;
271 ee->prop.cursor.hot.y = 0;
275 ee->prop.cursor.object = obj;
276 ee->prop.cursor.layer = layer;
277 ee->prop.cursor.hot.x = hot_x;
278 ee->prop.cursor.hot.y = hot_y;
279 evas_pointer_output_xy_get(ee->evas, &x, &y);
280 evas_object_layer_set(ee->prop.cursor.object, ee->prop.cursor.layer);
281 evas_object_move(ee->prop.cursor.object,
282 x - ee->prop.cursor.hot.x,
283 y - ee->prop.cursor.hot.y);
284 evas_object_pass_events_set(ee->prop.cursor.object, 1);
285 if (evas_pointer_inside_get(ee->evas))
286 evas_object_show(ee->prop.cursor.object);
288 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, _ecore_evas_object_cursor_del, ee);
291 static Ecore_Evas_Engine_Func _ecore_sdl_engine_func =
293 _ecore_evas_sdl_free,
311 _ecore_evas_move_resize,
325 _ecore_evas_object_cursor_set,
344 _ecore_evas_internal_sdl_new(int rmethod, const char* name, int w, int h, int fullscreen, int hwsurface, int noframe, int alpha)
350 name = ecore_evas_sdl_default;
352 if (ecore_evases) return NULL;
354 ee = calloc(1, sizeof(Ecore_Evas));
355 if (!ee) return NULL;
357 ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS);
359 ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_sdl_engine_func;
362 if (name) ee->name = strdup(name);
373 ee->prop.focused = 1;
374 ee->prop.borderless = 1;
375 ee->prop.override = 1;
376 ee->prop.maximized = 1;
377 ee->prop.fullscreen = fullscreen;
378 ee->prop.withdrawn = 0;
383 ee->evas = evas_new();
384 evas_data_attach_set(ee->evas, ee);
385 evas_output_method_set(ee->evas, rmethod);
387 evas_output_size_set(ee->evas, w, h);
388 evas_output_viewport_set(ee->evas, 0, 0, w, h);
390 if (rmethod == evas_render_method_lookup("software_sdl"))
392 #ifdef BUILD_ECORE_EVAS_SOFTWARE_SDL
393 einfo = evas_engine_info_get(ee->evas);
396 ((Evas_Engine_Info_SDL *)einfo)->info.rotation = 0;
397 ((Evas_Engine_Info_SDL *)einfo)->info.fullscreen = fullscreen;
398 ((Evas_Engine_Info_SDL *)einfo)->info.hwsurface = hwsurface;
399 ((Evas_Engine_Info_SDL *)einfo)->info.noframe = noframe;
400 ((Evas_Engine_Info_SDL *)einfo)->info.alpha = alpha;
401 evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
405 else if (rmethod == evas_render_method_lookup("gl_sdl"))
407 #ifdef BUILD_ECORE_EVAS_OPENGL_SDL
408 einfo = evas_engine_info_get(ee->evas);
411 ((Evas_Engine_Info_GL_SDL *)einfo)->flags.fullscreen = fullscreen;
412 ((Evas_Engine_Info_GL_SDL *)einfo)->flags.noframe = noframe;
413 evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
418 if (!ecore_sdl_init(name))
421 if (ee->name) free(ee->name);
426 _ecore_evas_sdl_init(w, h);
428 ecore_event_window_register(0, ee, ee->evas, (Ecore_Event_Mouse_Move_Cb) _ecore_evas_mouse_move_process);
430 SDL_ShowCursor(SDL_DISABLE);
432 ee->engine.func->fn_render = _ecore_evas_sdl_render;
433 _ecore_evas_register(ee);
437 evas_event_feed_mouse_in(ee->evas, (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff), NULL);
438 evas_focus_in(ee->evas);
444 #ifdef BUILD_ECORE_EVAS_SOFTWARE_SDL
446 ecore_evas_sdl_new(const char* name, int w, int h, int fullscreen, int hwsurface, int noframe, int alpha)
451 rmethod = evas_render_method_lookup("software_sdl");
452 if (!rmethod) return NULL;
454 ee = _ecore_evas_internal_sdl_new(rmethod, name, w, h, fullscreen, hwsurface, noframe, alpha);
460 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__)
467 #ifdef BUILD_ECORE_EVAS_SOFTWARE_SDL
469 ecore_evas_sdl16_new(const char* name, int w, int h, int fullscreen, int hwsurface, int noframe, int alpha)
474 rmethod = evas_render_method_lookup("software_16_sdl");
475 if (!rmethod) return NULL;
477 ee = _ecore_evas_internal_sdl_new(rmethod, name, w, h, fullscreen, hwsurface, noframe, alpha);
478 ee->driver = "software_16_sdl";
483 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__)
490 #ifdef BUILD_ECORE_EVAS_OPENGL_SDL
492 ecore_evas_gl_sdl_new(const char* name, int w, int h, int fullscreen, int noframe)
497 rmethod = evas_render_method_lookup("gl_sdl");
498 if (!rmethod) return NULL;
500 ee = _ecore_evas_internal_sdl_new(rmethod, name, w, h, fullscreen, 0, noframe, 0);
501 ee->driver = "gl_sdl";
506 ecore_evas_gl_sdl_new(const char* name __UNUSED__, int w __UNUSED__, int h __UNUSED__, int fullscreen __UNUSED__, int noframe __UNUSED__)