6 #include "ecore_private.h"
7 #include "Ecore_Input.h"
8 #include "Ecore_Input_Evas.h"
10 #ifdef BUILD_ECORE_EVAS_OPENGL_COCOA
11 #include <Ecore_Cocoa.h>
12 #include <Evas_Engine_GL_Cocoa.h>
15 #include "ecore_evas_private.h"
16 #include "Ecore_Evas.h"
19 #ifdef BUILD_ECORE_EVAS_OPENGL_COCOA
21 // FIXME: this engine has lots of problems. only 1 window at a time, drawRect looks wrong, doesnt handle resizes and more
23 static int _ecore_evas_init_count = 0;
24 static Ecore_Evas *ecore_evases = NULL;
25 static Ecore_Event_Handler *ecore_evas_event_handlers[4] = {
26 NULL, NULL, NULL, NULL
28 static Ecore_Idle_Enterer *ecore_evas_idle_enterer = NULL;
29 static Ecore_Poller *ecore_evas_event = NULL;
31 static const char *ecore_evas_cocoa_default = "EFL Cocoa";
35 _ecore_evas_cocoa_render(Ecore_Evas *ee)
38 Eina_List *updates = NULL;
44 EINA_LIST_FOREACH(ee->sub_ecore_evas, ll, ee2)
46 if (ee2->func.fn_pre_render) ee2->func.fn_pre_render(ee2);
47 if (ee2->engine.func->fn_render)
48 rend |= ee2->engine.func->fn_render(ee2);
49 if (ee2->func.fn_post_render) ee2->func.fn_post_render(ee2);
52 if (ee->func.fn_pre_render) ee->func.fn_pre_render(ee);
53 updates = evas_render_updates(ee->evas);
54 if (ee->prop.avoid_damage)
56 updates = evas_render_updates(ee->evas);
57 if (updates) evas_render_updates_free(updates);
59 else if ((ee->visible) ||
60 ((ee->should_be_visible) && (ee->prop.fullscreen)) ||
61 ((ee->should_be_visible) && (ee->prop.override)))
65 updates = evas_render_updates(ee->evas);
66 if (updates) evas_render_updates_free(updates);
70 updates = evas_render_updates(ee->evas);
71 if (updates) evas_render_updates_free(updates);
75 evas_norender(ee->evas);
76 if (updates) rend = 1;
77 if (ee->func.fn_post_render) ee->func.fn_post_render(ee);
81 static int frames = 0;
82 static double t0 = 0.0;
90 printf("FPS: %3.3f\n", (double)frames / td);
101 _ecore_evas_cocoa_match(void)
108 _ecore_evas_cocoa_event_got_focus(void *data __UNUSED__, int type __UNUSED__, void *event)
114 ee = _ecore_evas_cocoa_match();
116 if (!ee) return ECORE_CALLBACK_PASS_ON;
117 ee->prop.focused = 1;
118 evas_focus_in(ee->evas);
119 if (ee->func.fn_focus_in) ee->func.fn_focus_in(ee);
121 return ECORE_CALLBACK_PASS_ON;
125 _ecore_evas_cocoa_event_lost_focus(void *data __UNUSED__, int type __UNUSED__, void *event)
131 ee = _ecore_evas_cocoa_match();
133 if (!ee) return ECORE_CALLBACK_PASS_ON;
134 evas_focus_out(ee->evas);
135 ee->prop.focused = 0;
136 if (ee->func.fn_focus_out) ee->func.fn_focus_out(ee);
138 return ECORE_CALLBACK_PASS_ON;
142 _ecore_evas_cocoa_event_video_resize(void *data __UNUSED__, int type __UNUSED__, void *event)
144 /*Ecore_Cocoa_Event_Video_Resize *e;
148 ee = _ecore_evas_cocoa_match();
150 if (!ee) return 1; // pass on event
151 evas_output_size_set(ee->evas, e->w, e->h);
156 return ECORE_CALLBACK_PASS_ON;
160 _ecore_evas_cocoa_event_video_expose(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
168 ee = _ecore_evas_cocoa_match();
170 if (!ee) return ECORE_CALLBACK_PASS_ON;
171 evas_output_size_get(ee->evas, &w, &h);
172 evas_damage_rectangle_add(ee->evas, 0, 0, w, h);
174 return ECORE_CALLBACK_PASS_ON;
178 _ecore_evas_idle_enter(void *data __UNUSED__)
186 EINA_INLIST_FOREACH(ecore_evases, ee)
189 evas_render(ee->evas);
191 evas_norender(ee->evas);
198 _ecore_evas_cocoa_event(void *data)
200 // ecore_cocoa_feed_events();
208 _ecore_evas_cocoa_init(void)
211 _ecore_evas_init_count++;
212 if (_ecore_evas_init_count > 1)
213 return _ecore_evas_init_count;
215 ecore_evas_event_handlers[0] = ecore_event_handler_add(ECORE_COCOA_EVENT_GOT_FOCUS, _ecore_evas_cocoa_event_got_focus, NULL);
216 ecore_evas_event_handlers[1] = ecore_event_handler_add(ECORE_COCOA_EVENT_LOST_FOCUS, _ecore_evas_cocoa_event_lost_focus, NULL);
217 ecore_evas_event_handlers[2] = ecore_event_handler_add(ECORE_COCOA_EVENT_RESIZE, _ecore_evas_cocoa_event_video_resize, NULL);
218 ecore_evas_event_handlers[3] = ecore_event_handler_add(ECORE_COCOA_EVENT_EXPOSE, _ecore_evas_cocoa_event_video_expose, NULL);
220 ecore_event_evas_init();
221 return _ecore_evas_init_count;
225 _ecore_evas_cocoa_shutdown(void)
227 DBG("Cocoa SHutodwn");
228 _ecore_evas_init_count--;
229 if (_ecore_evas_init_count == 0)
233 while (ecore_evases) _ecore_evas_free(ecore_evases);
235 for (i = 0; i < sizeof (ecore_evas_event_handlers) / sizeof (Ecore_Event_Handler*); i++)
236 ecore_event_handler_del(ecore_evas_event_handlers[i]);
237 ecore_event_evas_shutdown();
238 ecore_idle_enterer_del(ecore_evas_idle_enterer);
239 ecore_evas_idle_enterer = NULL;
240 ecore_poller_del(ecore_evas_event);
241 ecore_evas_event = NULL;
243 ecore_event_evas_shutdown();
245 if (_ecore_evas_init_count < 0) _ecore_evas_init_count = 0;
246 return _ecore_evas_init_count;
250 _ecore_evas_cocoa_free(Ecore_Evas *ee)
253 ecore_evases = (Ecore_Evas *) eina_inlist_remove(EINA_INLIST_GET(ecore_evases), EINA_INLIST_GET(ee));
254 ecore_event_window_unregister(0);
255 _ecore_evas_cocoa_shutdown();
256 ecore_cocoa_shutdown();
260 _ecore_evas_resize(Ecore_Evas *ee, int w, int h)
263 if ((w == ee->w) && (h == ee->h)) return;
267 printf("Ecore_Evas Resize %d %d\n", w, h);
269 ecore_cocoa_window_resize(ee->prop.window, w, h);
271 evas_output_size_set(ee->evas, ee->w, ee->h);
272 evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
273 evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h);
275 if (ee->func.fn_resize) ee->func.fn_resize(ee);
279 _ecore_evas_move_resize(Ecore_Evas *ee, int x, int y, int w, int h)
282 if ((w == ee->w) && (h == ee->h)) return;
286 ecore_cocoa_window_move_resize(ee->prop.window, x, y, w, h);
288 evas_output_size_set(ee->evas, ee->w, ee->h);
289 evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
290 evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h);
292 if (ee->func.fn_resize) ee->func.fn_resize(ee);
297 _ecore_evas_show(Ecore_Evas *ee, int x, int y, int w, int h)
300 ee->should_be_visible = 1;
301 if (ee->prop.avoid_damage)
302 _ecore_evas_cocoa_render(ee);
304 ecore_cocoa_window_show(ee->prop.window);
305 evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h);
310 _ecore_evas_hide(Ecore_Evas *ee, int x, int y, int w, int h)
314 ecore_cocoa_window_hide(ee->prop.window);
315 ee->should_be_visible = 0;
319 _ecore_evas_title_set(Ecore_Evas *ee, const char *title)
321 INF("ecore evas title set");
323 if (ee->prop.title) free(ee->prop.title);
324 ee->prop.title = NULL;
325 if (title) ee->prop.title = strdup(title);
326 ecore_cocoa_window_title_set(ee->prop.window,
331 _ecore_evas_object_cursor_del(void *data, Evas *e, Evas_Object *obj, void *event_info)
339 ee->prop.cursor.object = NULL;
343 _ecore_evas_object_cursor_set(Ecore_Evas *ee, Evas_Object *obj, int layer, int hot_x, int hot_y)
347 if (ee->prop.cursor.object) evas_object_del(ee->prop.cursor.object);
351 ee->prop.cursor.object = NULL;
352 ee->prop.cursor.layer = 0;
353 ee->prop.cursor.hot.x = 0;
354 ee->prop.cursor.hot.y = 0;
358 ee->prop.cursor.object = obj;
359 ee->prop.cursor.layer = layer;
360 ee->prop.cursor.hot.x = hot_x;
361 ee->prop.cursor.hot.y = hot_y;
363 evas_pointer_output_xy_get(ee->evas, &x, &y);
364 evas_object_layer_set(ee->prop.cursor.object, ee->prop.cursor.layer);
365 evas_object_move(ee->prop.cursor.object,
366 x - ee->prop.cursor.hot.x,
367 y - ee->prop.cursor.hot.y);
369 evas_object_pass_events_set(ee->prop.cursor.object, 1);
371 if (evas_pointer_inside_get(ee->evas))
372 evas_object_show(ee->prop.cursor.object);
374 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, _ecore_evas_object_cursor_del, ee);
378 _ecore_evas_engine_cocoa_init(Ecore_Evas *ee)
380 Evas_Engine_Info_GL_Cocoa *einfo;
388 rmethod = evas_render_method_lookup(driver);
393 evas_output_method_set(ee->evas, rmethod);
395 einfo = (Evas_Engine_Info_GL_Cocoa *)evas_engine_info_get(ee->evas);
398 /* FIXME: REDRAW_DEBUG missing for now */
399 einfo->window = ee->prop.window;
400 //einfo->info.depth = ecore_win32_screen_depth_get();
401 //einfo->info.rotation = 0;
402 if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo))
404 ERR("evas_engine_info_set() for engine '%s' failed.", ee->driver);
407 ecore_cocoa_window_view_set(einfo->window, einfo->view);
411 ERR("evas_engine_info_set() init engine '%s' failed.", ee->driver);
418 static Ecore_Evas_Engine_Func _ecore_cocoa_engine_func =
420 _ecore_evas_cocoa_free,
438 _ecore_evas_move_resize,
446 _ecore_evas_title_set,
452 _ecore_evas_object_cursor_set,
466 NULL, // profiles_set
477 NULL // screen_dpi_get
482 ecore_evas_cocoa_new(Ecore_Cocoa_Window *parent, int x, int y, int w, int h)
484 #ifdef BUILD_ECORE_EVAS_OPENGL_COCOA
485 Evas_Engine_Info_GL_Cocoa *einfo;
491 if (!ecore_cocoa_init())
494 ee = calloc(1, sizeof(Ecore_Evas));
496 goto shutdown_ecore_cocoa;
498 ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS);
500 _ecore_evas_cocoa_init();
502 ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_cocoa_engine_func;
519 ee->prop.max.w = 32767;
520 ee->prop.max.h = 32767;
522 ee->prop.request_pos = 0;
526 printf("Create New Evas\n");
528 ee->evas = evas_new();
533 evas_data_attach_set(ee->evas, ee);
534 evas_output_method_set(ee->evas, rmethod);
535 evas_output_size_set(ee->evas, w, h);
536 evas_output_viewport_set(ee->evas, 0, 0, w, h);
538 printf("Create New Cocoa Window\n");
539 ee->prop.window = (Ecore_Cocoa_Window*)ecore_cocoa_window_new(x, y, w, h);
540 printf("Window Created %p\n", ee->prop.window);
541 if (!ee->prop.window)
543 _ecore_evas_cocoa_shutdown();
548 printf("Init Evas engine cocoa\n");
549 if (!_ecore_evas_engine_cocoa_init(ee))
551 _ecore_evas_cocoa_shutdown();
557 ee->engine.func->fn_render = _ecore_evas_cocoa_render;
558 _ecore_evas_register(ee);
559 ecore_event_window_register(0, ee, ee->evas, NULL, NULL, NULL, NULL);
561 evas_event_feed_mouse_in(ee->evas, (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff), NULL);
562 printf("Ecore Evas returned : %p\n", ee);
566 /* FIXME: free window here */
572 _ecore_evas_cocoa_shutdown();
574 shutdown_ecore_cocoa:
575 ecore_cocoa_shutdown();
579 ERR("Cocoa support in ecore-evas not enabled");
582 (void) x; (void) y; (void) w; (void) h;