From bf7dca0235e8ade0ce27f29b0db38d8c22afd3ca Mon Sep 17 00:00:00 2001 From: captainigloo Date: Wed, 2 Nov 2011 19:20:09 +0000 Subject: [PATCH] ecore: Add ecore_cocoa and ecore_evas_cocoa engine support. Currently, event and main loop integration is not working, but you can create a new ecore_cocoa window and attach an evas inside. git-svn-id: http://svn.enlightenment.org/svn/e/trunk/ecore@64656 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- configure.ac | 14 +- src/lib/ecore_cocoa/Ecore_Cocoa.h | 10 +- src/lib/ecore_cocoa/ecore_cocoa.m | 5 +- src/lib/ecore_cocoa/ecore_cocoa_private.h | 2 - src/lib/ecore_cocoa/ecore_cocoa_window.m | 93 +++-- src/lib/ecore_evas/Ecore_Evas.h | 12 +- src/lib/ecore_evas/Makefile.am | 11 + src/lib/ecore_evas/ecore_evas.c | 12 +- src/lib/ecore_evas/ecore_evas_cocoa.c | 568 ++++++++++++++++++++++++++++++ src/lib/ecore_evas/ecore_evas_private.h | 5 + 10 files changed, 697 insertions(+), 35 deletions(-) create mode 100644 src/lib/ecore_evas/ecore_evas_cocoa.c diff --git a/configure.ac b/configure.ac index aefabb3..0ac4664 100644 --- a/configure.ac +++ b/configure.ac @@ -165,6 +165,7 @@ want_ecore_evas_opengl_glew="no" want_ecore_evas_software_16_ddraw="no" want_ecore_evas_software_sdl="no" want_ecore_evas_gl_sdl="no" +want_ecore_evas_gl_cocoa="no" want_ecore_evas_directfb="no" want_ecore_evas_fb="no" want_ecore_evas_software_16_wince="no" @@ -205,6 +206,7 @@ case "$host_os" in want_ecore_cocoa="yes" want_ecore_evas_software_sdl="yes" want_ecore_evas_gl_sdl="yes" + want_ecore_evas_gl_cocoa="yes" ;; *) want_curl="yes" @@ -226,6 +228,7 @@ case "$host_os" in want_ecore_evas_software_xcb="no" want_ecore_evas_software_sdl="yes" want_ecore_evas_gl_sdl="yes" + want_ecore_evas_gl_cocoa="no" want_ecore_evas_directfb="yes" want_ecore_evas_fb="yes" want_ecore_imf_xim="yes" @@ -1717,6 +1720,14 @@ ECORE_EVAS_CHECK_MODULE([opengl-sdl], [${have_ecore_sdl}], [requirements_ecore_evas="ecore-sdl >= 1.0.0 ${requirements_ecore_evas}"]) +# ecore_evas_cocoa + +ECORE_EVAS_CHECK_MODULE([opengl-cocoa], + [${want_ecore_evas_gl_cocoa}], + [OpenGL Cocoa], + [${have_ecore_cocoa}], + [requirements_ecore_evas="ecore-cocoa >= 1.0.0 ${requirements_ecore_evas}"]) + # ecore_evas_directfb ECORE_EVAS_CHECK_MODULE([directfb], @@ -1782,7 +1793,6 @@ ecore-directfb.pc ecore-evas.pc ecore-fb.pc ecore-file.pc -ecore-cocoa.pc ecore-imf.pc ecore-imf-evas.pc ecore-ipc.pc @@ -1791,6 +1801,7 @@ ecore-input.pc ecore-input-evas.pc ecore-win32.pc ecore-sdl.pc +ecore-cocoa.pc ecore-wince.pc ecore.pc doc/ecore.dox @@ -1959,6 +1970,7 @@ if test "x${have_ecore_evas}" = "xyes" ; then echo " OpenGL Glew................: $have_ecore_evas_opengl_glew" echo " Software SDL...............: $have_ecore_evas_software_sdl" echo " OpenGL SDL.................: $have_ecore_evas_opengl_sdl" + echo " OpenGL Cocoa...............: $have_ecore_evas_opengl_cocoa" echo " DirectFB...................: $have_ecore_evas_directfb" echo " Software Framebuffer.......: $have_ecore_evas_fb" echo " Software 8bit grayscale XCB: $have_ecore_evas_software_8_x11" diff --git a/src/lib/ecore_cocoa/Ecore_Cocoa.h b/src/lib/ecore_cocoa/Ecore_Cocoa.h index f90db7c..51c8ead 100644 --- a/src/lib/ecore_cocoa/Ecore_Cocoa.h +++ b/src/lib/ecore_cocoa/Ecore_Cocoa.h @@ -1,5 +1,5 @@ -#ifndef _ECORE_COCOA_H -#define _ECORE_COCOA_H +#ifndef __ECORE_COCOA_H__ +#define __ECORE_COCOA_H__ /* * DO NOT USE THIS HEADER. IT IS WORK IN PROGRESS. IT IS NOT FINAL AND @@ -46,7 +46,7 @@ struct _Ecore_Cocoa_Event_Video_Resize /* Core */ -EAPI int ecore_cocoa_init(const char *name); +EAPI int ecore_cocoa_init(void); EAPI int ecore_cocoa_shutdown(void); EAPI void ecore_cocoa_feed_events(void); @@ -136,6 +136,10 @@ EAPI void ecore_cocoa_window_iconified_set(Ecore_Cocoa_Window *window, EAPI void ecore_cocoa_window_borderless_set(Ecore_Cocoa_Window *window, int on); +EAPI void ecore_cocoa_window_view_set(Ecore_Cocoa_Window *window, + void *view); + + #ifdef __cplusplus } #endif diff --git a/src/lib/ecore_cocoa/ecore_cocoa.m b/src/lib/ecore_cocoa/ecore_cocoa.m index ad2e767..3f6023a 100644 --- a/src/lib/ecore_cocoa/ecore_cocoa.m +++ b/src/lib/ecore_cocoa/ecore_cocoa.m @@ -13,6 +13,7 @@ #include "Ecore_Cocoa.h" #include "Ecore_Cocoa_Keys.h" + EAPI int ECORE_COCOA_EVENT_GOT_FOCUS = 0; EAPI int ECORE_COCOA_EVENT_LOST_FOCUS = 0; EAPI int ECORE_COCOA_EVENT_RESIZE = 0; @@ -23,7 +24,7 @@ static int _ecore_cocoa_init_count = 0; static int old_flags; EAPI int -ecore_cocoa_init(const char *name __UNUSED__) +ecore_cocoa_init(void) { if (++_ecore_cocoa_init_count != 1) return _ecore_cocoa_init_count; @@ -31,6 +32,8 @@ ecore_cocoa_init(const char *name __UNUSED__) if (!ecore_event_init()) return --_ecore_cocoa_init_count; + NSApplicationLoad(); + ECORE_COCOA_EVENT_GOT_FOCUS = ecore_event_type_new(); ECORE_COCOA_EVENT_LOST_FOCUS = ecore_event_type_new(); ECORE_COCOA_EVENT_RESIZE = ecore_event_type_new(); diff --git a/src/lib/ecore_cocoa/ecore_cocoa_private.h b/src/lib/ecore_cocoa/ecore_cocoa_private.h index 05bdc1f..0b4cf31 100644 --- a/src/lib/ecore_cocoa/ecore_cocoa_private.h +++ b/src/lib/ecore_cocoa/ecore_cocoa_private.h @@ -1,11 +1,9 @@ #ifndef _ECORE_COCOA_PRIVATE_H #define _ECORE_COCOA_PRIVATE_H - struct _Ecore_Cocoa_Window { NSWindow *window; - unsigned int borderless : 1; }; diff --git a/src/lib/ecore_cocoa/ecore_cocoa_window.m b/src/lib/ecore_cocoa/ecore_cocoa_window.m index 751bde4..2091a69 100644 --- a/src/lib/ecore_cocoa/ecore_cocoa_window.m +++ b/src/lib/ecore_cocoa/ecore_cocoa_window.m @@ -5,6 +5,7 @@ #include #include "Ecore_Cocoa.h" +#include "ecore_cocoa_private.h" Ecore_Cocoa_Window * ecore_cocoa_window_new(int x, @@ -12,22 +13,29 @@ ecore_cocoa_window_new(int x, int width, int height) { - NSWindow *window; + Ecore_Cocoa_Window *w; - window = [[NSWindow alloc] - initWithContentRect:NSMakeRect(x, y, width, height) - styleMask:(NSTitledWindowMask | + NSWindow *window = [[NSWindow alloc] + initWithContentRect:NSMakeRect(x, y, width, height) + styleMask:(NSTitledWindowMask | NSClosableWindowMask | - NSResizableWindowMask | - NSMiniaturizableWindowMask) - backing:NSBackingStoreBuffered - defer:NO - screen:nil - ]; + NSResizableWindowMask | + NSMiniaturizableWindowMask) + backing:NSBackingStoreBuffered + defer:NO + screen:nil + ]; + if (!window) return NULL; - return window; + [window setBackgroundColor:[NSColor whiteColor]]; + + w = calloc(1, sizeof(Ecore_Cocoa_Window)); + w->window = window; + w->borderless = 0; + + return w; } void @@ -36,7 +44,8 @@ ecore_cocoa_window_free(Ecore_Cocoa_Window *window) if (!window) return; - [window release]; + [window->window release]; + free(window); } void @@ -44,8 +53,16 @@ ecore_cocoa_window_move(Ecore_Cocoa_Window *window, int x, int y) { + NSRect win_frame; + if (!window) return; + + win_frame = [window->window frame]; + win_frame.origin.x = x; + win_frame.origin.y = y; + + [window->window setFrame:win_frame display:YES]; } void @@ -56,7 +73,16 @@ ecore_cocoa_window_resize(Ecore_Cocoa_Window *window, if (!window) return; - [window setContentSize: NSMakeSize(width, height)]; + NSRect win_frame; + + if (!window) + return; + + win_frame = [window->window frame]; + win_frame.size.height = height; + win_frame.size.width = width; + + [window->window setFrame:win_frame display:YES]; } void @@ -68,6 +94,19 @@ ecore_cocoa_window_move_resize(Ecore_Cocoa_Window *window, { if (!window) return; + + NSRect win_frame; + + if (!window) + return; + + win_frame = [window->window frame]; + win_frame.size.height = height; + win_frame.size.width = width; + win_frame.origin.x = x; + win_frame.origin.y = y; + + [window->window setFrame:win_frame display:YES]; } void @@ -76,25 +115,28 @@ ecore_cocoa_window_title_set(Ecore_Cocoa_Window *window, const char *title) if (!window || !title) return; - [window setTitle:[NSString stringWithUTF8String:title]]; + [window->window setTitle:[NSString stringWithUTF8String:title]]; } void ecore_cocoa_window_show(Ecore_Cocoa_Window *window) { - if (!window || [window isVisible]) - return; + if (!window || [window->window isVisible]) + { + printf("Window(%p) is not visible\n", window->window); + return; + } - [window orderFront:NSApp]; + [window->window makeKeyAndOrderFront:NSApp]; } void ecore_cocoa_window_hide(Ecore_Cocoa_Window *window) { - if (!window || ![window isVisible]) + if (!window || ![window->window isVisible]) return; - [window orderOut:NSApp]; + [window->window orderOut:NSApp]; } void @@ -105,6 +147,17 @@ ecore_cocoa_window_borderless_set(Ecore_Cocoa_Window *window, return; if (on) - [window setContentBorderThickness:0.0 + [window->window setContentBorderThickness:0.0 forEdje:NSMinXEdge | NSMinYEdge | NSMaxXEdge | NSMaxYEdge]; } + +void +ecore_cocoa_window_view_set(Ecore_Cocoa_Window *window, + void *view) +{ + if (!window || !view) + return; + + [[window->window contentView] addSubview:view]; + +} diff --git a/src/lib/ecore_evas/Ecore_Evas.h b/src/lib/ecore_evas/Ecore_Evas.h index af0279a..acb0db5 100644 --- a/src/lib/ecore_evas/Ecore_Evas.h +++ b/src/lib/ecore_evas/Ecore_Evas.h @@ -93,7 +93,7 @@ typedef enum _Ecore_Evas_Engine_Type ECORE_EVAS_ENGINE_SOFTWARE_DDRAW, ECORE_EVAS_ENGINE_DIRECT3D, ECORE_EVAS_ENGINE_OPENGL_GLEW, - ECORE_EVAS_ENGINE_COCOA, + ECORE_EVAS_ENGINE_OPENGL_COCOA, ECORE_EVAS_ENGINE_SOFTWARE_SDL, ECORE_EVAS_ENGINE_DIRECTFB, ECORE_EVAS_ENGINE_SOFTWARE_FB, @@ -138,6 +138,10 @@ typedef struct _Ecore_Win32_Window Ecore_Win32_Window; typedef struct _Ecore_WinCE_Window Ecore_WinCE_Window; #endif +#ifndef __ECORE_COCOA_H__ +typedef struct _Ecore_Cocoa_Window Ecore_Cocoa_Window; +#endif + #ifndef _ECORE_EVAS_PRIVATE_H /* basic data types */ typedef struct _Ecore_Evas Ecore_Evas; @@ -943,7 +947,11 @@ EAPI Ecore_Evas *ecore_evas_software_wince_gdi_new(Ecore_WinCE_Window *paren EAPI Ecore_WinCE_Window *ecore_evas_software_wince_window_get(const Ecore_Evas *ee); -EAPI Ecore_Evas *ecore_evas_cocoa_new(const char* name, int w, int h); +EAPI Ecore_Evas *ecore_evas_cocoa_new(Ecore_Cocoa_Window *parent, + int x, + int y, + int w, + int h); /* generic manipulation calls */ /** diff --git a/src/lib/ecore_evas/Makefile.am b/src/lib/ecore_evas/Makefile.am index f0aaea9..c867d98 100644 --- a/src/lib/ecore_evas/Makefile.am +++ b/src/lib/ecore_evas/Makefile.am @@ -42,6 +42,14 @@ ECORE_SDL_LIB = ECORE_SDL_LIBADD = endif +if BUILD_ECORE_COCOA +ECORE_COCOA_INC = -I$(top_srcdir)/src/lib/ecore_cocoa +ECORE_COCOA_LIB = $(top_builddir)/src/lib/ecore_cocoa/libecore_cocoa.la +else +ECORE_COCOA_INC = +ECORE_COCOA_LIB = +endif + if BUILD_ECORE_WINCE ECORE_WINCE_INC = -I$(top_srcdir)/src/lib/ecore_wince ECORE_WINCE_LIB = $(top_builddir)/src/lib/ecore_wince/libecore_wince.la @@ -65,6 +73,7 @@ $(ECORE_FB_INC) \ $(ECORE_DIRECTFB_INC) \ $(ECORE_WIN32_INC) \ $(ECORE_SDL_INC) \ +$(ECORE_COCOA_INC) \ $(ECORE_WINCE_INC) \ @EVAS_CFLAGS@ \ @EINA_CFLAGS@ \ @@ -85,6 +94,7 @@ ecore_evas_buffer.c \ ecore_evas_directfb.c \ ecore_evas_win32.c \ ecore_evas_sdl.c \ +ecore_evas_cocoa.c \ ecore_evas_wince.c \ ecore_evas_ews.c @@ -95,6 +105,7 @@ $(ECORE_DIRECTFB_LIB) \ $(ECORE_WIN32_LIB) \ $(ECORE_SDL_LIB) \ $(ECORE_SDL_LIBADD) \ +$(ECORE_COCOA_LIB) \ $(ECORE_WINCE_LIB) \ $(top_builddir)/src/lib/ecore_input/libecore_input.la \ $(top_builddir)/src/lib/ecore_input_evas/libecore_input_evas.la \ diff --git a/src/lib/ecore_evas/ecore_evas.c b/src/lib/ecore_evas/ecore_evas.c index 4d13b1c..3cb656e 100644 --- a/src/lib/ecore_evas/ecore_evas.c +++ b/src/lib/ecore_evas/ecore_evas.c @@ -176,8 +176,8 @@ ecore_evas_engine_type_supported_get(Ecore_Evas_Engine_Type engine) #else return EINA_FALSE; #endif - case ECORE_EVAS_ENGINE_COCOA: -#ifdef BUILD_ECORE_EVAS_COCOA + case ECORE_EVAS_ENGINE_OPENGL_COCOA: +#ifdef BUILD_ECORE_EVAS_OPENGL_COCOA return EINA_TRUE; #else return EINA_FALSE; @@ -398,7 +398,7 @@ _ecore_evas_constructor_software_x11(int x, int y, int w, int h, const char *ext } #endif -#ifdef BUILD_ECORE_EVAS_COCOA +#ifdef BUILD_ECORE_EVAS_OPENGL_COCOA static Ecore_Evas * _ecore_evas_constructor_cocoa(int x, int y, int w, int h, const char *extra_options) { @@ -406,7 +406,7 @@ _ecore_evas_constructor_cocoa(int x, int y, int w, int h, const char *extra_opti Ecore_Evas *ee; _ecore_evas_parse_extra_options_str(extra_options, "name=", &name); - ee = ecore_evas_cocoa_new(name, w, h); + ee = ecore_evas_cocoa_new(NULL, x, y, w, h); free(name); if (ee) ecore_evas_move(ee, x, y); @@ -684,8 +684,8 @@ static const struct ecore_evas_engine _engines[] = { #endif /* Apple */ -#ifdef BUILD_ECORE_EVAS_COCOA - {"cocoa", _ecore_evas_constructor_cocoa}, +#ifdef BUILD_ECORE_EVAS_OPENGL_COCOA + {"opengl_cocoa", _ecore_evas_constructor_cocoa}, #endif /* Last chance to have a window */ diff --git a/src/lib/ecore_evas/ecore_evas_cocoa.c b/src/lib/ecore_evas/ecore_evas_cocoa.c new file mode 100644 index 0000000..af56879 --- /dev/null +++ b/src/lib/ecore_evas/ecore_evas_cocoa.c @@ -0,0 +1,568 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "Ecore.h" +#include "ecore_private.h" +#include "Ecore_Input.h" +#include "Ecore_Input_Evas.h" + +#ifdef BUILD_ECORE_EVAS_OPENGL_COCOA +#include +#endif + +#include + +#include "ecore_evas_private.h" +#include "Ecore_Evas.h" + + +#ifdef BUILD_ECORE_EVAS_OPENGL_COCOA + +// FIXME: this engine has lots of problems. only 1 window at a time, drawRect looks wrong, doesnt handle resizes and more + +static int _ecore_evas_init_count = 0; +static Ecore_Evas *ecore_evases = NULL; +static Ecore_Event_Handler *ecore_evas_event_handlers[4] = { + NULL, NULL, NULL, NULL +}; +static Ecore_Idle_Enterer *ecore_evas_idle_enterer = NULL; +static Ecore_Poller *ecore_evas_event = NULL; + +static const char *ecore_evas_cocoa_default = "EFL Cocoa"; + + +static int +_ecore_evas_cocoa_render(Ecore_Evas *ee) +{ + int rend = 0; + Eina_List *updates = NULL; + Eina_List *ll; + Ecore_Evas *ee2; + + DBG("Render"); + + EINA_LIST_FOREACH(ee->sub_ecore_evas, ll, ee2) + { + if (ee2->func.fn_pre_render) ee2->func.fn_pre_render(ee2); + if (ee2->engine.func->fn_render) + rend |= ee2->engine.func->fn_render(ee2); + if (ee2->func.fn_post_render) ee2->func.fn_post_render(ee2); + } + + if (ee->func.fn_pre_render) ee->func.fn_pre_render(ee); + updates = evas_render_updates(ee->evas); + if (ee->prop.avoid_damage) + { + updates = evas_render_updates(ee->evas); + if (updates) evas_render_updates_free(updates); + } + else if ((ee->visible) || + ((ee->should_be_visible) && (ee->prop.fullscreen)) || + ((ee->should_be_visible) && (ee->prop.override))) + { + if (ee->shaped) + { + updates = evas_render_updates(ee->evas); + if (updates) evas_render_updates_free(updates); + } + else + { + updates = evas_render_updates(ee->evas); + if (updates) evas_render_updates_free(updates); + } + } + else + evas_norender(ee->evas); + if (updates) rend = 1; + if (ee->func.fn_post_render) ee->func.fn_post_render(ee); + + if (rend) + { + static int frames = 0; + static double t0 = 0.0; + double t, td; + + t = ecore_time_get(); + frames++; + if ((t - t0) > 1.0) + { + td = t - t0; + printf("FPS: %3.3f\n", (double)frames / td); + frames = 0; + t0 = t; + } + } + + return rend; +} + + +static Ecore_Evas * +_ecore_evas_cocoa_match(void) +{ + DBG("Match"); + return ecore_evases; +} + +static int +_ecore_evas_cocoa_event_got_focus(void *data __UNUSED__, int type __UNUSED__, void *event) +{ + Ecore_Evas *ee; + + DBG("Got Focus"); + + ee = _ecore_evas_cocoa_match(); + + if (!ee) return 1; + ee->prop.focused = 1; + + return 0; +} + +static int +_ecore_evas_cocoa_event_lost_focus(void *data __UNUSED__, int type __UNUSED__, void *event) +{ + Ecore_Evas *ee; + + DBG("Lost Focus"); + + ee = _ecore_evas_cocoa_match(); + + if (!ee) return 1; + ee->prop.focused = 0; + + return 0; +} + +static int +_ecore_evas_cocoa_event_video_resize(void *data __UNUSED__, int type __UNUSED__, void *event) +{ + /*Ecore_Cocoa_Event_Video_Resize *e; + Ecore_Evas *ee; + + e = event; + ee = _ecore_evas_cocoa_match(); + + if (!ee) return 1; // pass on event + evas_output_size_set(ee->evas, e->w, e->h); + + return 0;*/ + + DBG("Video Resize"); + +} + +static int +_ecore_evas_cocoa_event_video_expose(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__) +{ + Ecore_Evas *ee; + int w; + int h; + + DBG("Video Expose"); + + ee = _ecore_evas_cocoa_match(); + + if (!ee) return 1; + evas_output_size_get(ee->evas, &w, &h); + evas_damage_rectangle_add(ee->evas, 0, 0, w, h); + + return 0; +} + +static int +_ecore_evas_idle_enter(void *data __UNUSED__) +{ + Ecore_Evas *ee; + double t1 = 0.; + double t2 = 0.; + + DBG("Idle enter"); + + EINA_INLIST_FOREACH(ecore_evases, ee) + { + if (ee->visible) + evas_render(ee->evas); + else + evas_norender(ee->evas); + } + + return 1; +} + +static int +_ecore_evas_cocoa_event(void *data) +{ + // ecore_cocoa_feed_events(); + + DBG("Cocoa Event"); + + return 1; +} + +static int +_ecore_evas_cocoa_init(void) +{ + DBG("Cocoa Init"); + _ecore_evas_init_count++; + if (_ecore_evas_init_count > 1) + return _ecore_evas_init_count; + + ecore_evas_event_handlers[0] = ecore_event_handler_add(ECORE_COCOA_EVENT_GOT_FOCUS, _ecore_evas_cocoa_event_got_focus, NULL); + ecore_evas_event_handlers[1] = ecore_event_handler_add(ECORE_COCOA_EVENT_LOST_FOCUS, _ecore_evas_cocoa_event_lost_focus, NULL); + ecore_evas_event_handlers[2] = ecore_event_handler_add(ECORE_COCOA_EVENT_RESIZE, _ecore_evas_cocoa_event_video_resize, NULL); + ecore_evas_event_handlers[3] = ecore_event_handler_add(ECORE_COCOA_EVENT_EXPOSE, _ecore_evas_cocoa_event_video_expose, NULL); + + ecore_event_evas_init(); + return _ecore_evas_init_count; +} + +static int +_ecore_evas_cocoa_shutdown(void) +{ + DBG("Cocoa SHutodwn"); + _ecore_evas_init_count--; + if (_ecore_evas_init_count == 0) + { + int i; + + while (ecore_evases) _ecore_evas_free(ecore_evases); + + for (i = 0; i < sizeof (ecore_evas_event_handlers) / sizeof (Ecore_Event_Handler*); i++) + ecore_event_handler_del(ecore_evas_event_handlers[i]); + ecore_event_evas_shutdown(); + ecore_idle_enterer_del(ecore_evas_idle_enterer); + ecore_evas_idle_enterer = NULL; + ecore_poller_del(ecore_evas_event); + ecore_evas_event = NULL; + + ecore_event_evas_shutdown(); + } + if (_ecore_evas_init_count < 0) _ecore_evas_init_count = 0; + return _ecore_evas_init_count; +} + +static void +_ecore_evas_cocoa_free(Ecore_Evas *ee) +{ + DBG("Cocoa Free"); + ecore_evases = (Ecore_Evas *) eina_inlist_remove(EINA_INLIST_GET(ecore_evases), EINA_INLIST_GET(ee)); + ecore_event_window_unregister(0); + _ecore_evas_cocoa_shutdown(); + ecore_cocoa_shutdown(); +} + +static void +_ecore_evas_resize(Ecore_Evas *ee, int w, int h) +{ + DBG("Resize"); + if ((w == ee->w) && (h == ee->h)) return; + ee->w = w; + ee->h = h; + + printf("Ecore_Evas Resize %d %d\n", w, h); + + ecore_cocoa_window_resize(ee->prop.window, w, h); + + evas_output_size_set(ee->evas, ee->w, ee->h); + evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h); + evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h); + + if (ee->func.fn_resize) ee->func.fn_resize(ee); +} + +static void +_ecore_evas_move_resize(Ecore_Evas *ee, int x, int y, int w, int h) +{ + DBG("Move Resize"); + if ((w == ee->w) && (h == ee->h)) return; + ee->w = w; + ee->h = h; + + ecore_cocoa_window_move_resize(ee->prop.window, x, y, w, h); + + evas_output_size_set(ee->evas, ee->w, ee->h); + evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h); + evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h); + + if (ee->func.fn_resize) ee->func.fn_resize(ee); +} + + +static void +_ecore_evas_show(Ecore_Evas *ee, int x, int y, int w, int h) +{ + DBG("Show"); + ee->should_be_visible = 1; + if (ee->prop.avoid_damage) + _ecore_evas_cocoa_render(ee); + + ecore_cocoa_window_show(ee->prop.window); + evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h); +} + + +static void +_ecore_evas_hide(Ecore_Evas *ee, int x, int y, int w, int h) +{ + DBG("Hide"); + + ecore_cocoa_window_hide(ee->prop.window); + ee->should_be_visible = 0; +} + +static void +_ecore_evas_title_set(Ecore_Evas *ee, const char *title) +{ + INF("ecore evas title set"); + + if (ee->prop.title) free(ee->prop.title); + ee->prop.title = NULL; + if (title) ee->prop.title = strdup(title); + ecore_cocoa_window_title_set(ee->prop.window, + ee->prop.title); +} + +static void +_ecore_evas_object_cursor_del(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + Ecore_Evas *ee; + + DBG("Cursor DEL"); + + ee = data; + if (ee) + ee->prop.cursor.object = NULL; +} + +static void +_ecore_evas_object_cursor_set(Ecore_Evas *ee, Evas_Object *obj, int layer, int hot_x, int hot_y) +{ + int x, y; + DBG("Cursor Set"); + if (ee->prop.cursor.object) evas_object_del(ee->prop.cursor.object); + + if (obj == NULL) + { + ee->prop.cursor.object = NULL; + ee->prop.cursor.layer = 0; + ee->prop.cursor.hot.x = 0; + ee->prop.cursor.hot.y = 0; + return; + } + + ee->prop.cursor.object = obj; + ee->prop.cursor.layer = layer; + ee->prop.cursor.hot.x = hot_x; + ee->prop.cursor.hot.y = hot_y; + + evas_pointer_output_xy_get(ee->evas, &x, &y); + evas_object_layer_set(ee->prop.cursor.object, ee->prop.cursor.layer); + evas_object_move(ee->prop.cursor.object, + x - ee->prop.cursor.hot.x, + y - ee->prop.cursor.hot.y); + + evas_object_pass_events_set(ee->prop.cursor.object, 1); + + if (evas_pointer_inside_get(ee->evas)) + evas_object_show(ee->prop.cursor.object); + + evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, _ecore_evas_object_cursor_del, ee); +} + +static int +_ecore_evas_engine_cocoa_init(Ecore_Evas *ee) +{ + Evas_Engine_Info_GL_Cocoa *einfo; + const char *driver; + int rmethod; + + DBG("Cocoa Init"); + + driver = "gl_cocoa"; + + rmethod = evas_render_method_lookup(driver); + if (!rmethod) + return 0; + + ee->driver = driver; + evas_output_method_set(ee->evas, rmethod); + + einfo = (Evas_Engine_Info_GL_Cocoa *)evas_engine_info_get(ee->evas); + if (einfo) + { + /* FIXME: REDRAW_DEBUG missing for now */ + einfo->window = ee->prop.window; + //einfo->info.depth = ecore_win32_screen_depth_get(); + //einfo->info.rotation = 0; + if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo)) + { + ERR("evas_engine_info_set() for engine '%s' failed.", ee->driver); + return 0; + } + ecore_cocoa_window_view_set(einfo->window, einfo->view); + } + else + { + ERR("evas_engine_info_set() init engine '%s' failed.", ee->driver); + return 0; + } + + return 1; +} + +static Ecore_Evas_Engine_Func _ecore_cocoa_engine_func = + { + _ecore_evas_cocoa_free, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, //move + NULL, + _ecore_evas_resize, + _ecore_evas_move_resize, + NULL, //rotation + NULL, //shaped + _ecore_evas_show, + _ecore_evas_hide, + NULL, //raise + NULL, //lower + NULL, //activate + _ecore_evas_title_set, + NULL, + NULL, + NULL, + NULL, + NULL, + _ecore_evas_object_cursor_set, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, //transparent + NULL, // render + NULL + }; +#endif + +EAPI Ecore_Evas * +ecore_evas_cocoa_new(Ecore_Cocoa_Window *parent, int x, int y, int w, int h) +{ +#ifdef BUILD_ECORE_EVAS_OPENGL_COCOA + Evas_Engine_Info_GL_Cocoa *einfo; + Ecore_Evas *ee; + int rmethod; + + DBG("Cocoa new"); + + if (!ecore_cocoa_init()) + return NULL; + + ee = calloc(1, sizeof(Ecore_Evas)); + if (!ee) + goto shutdown_ecore_cocoa; + + ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS); + + _ecore_evas_cocoa_init(); + + ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_cocoa_engine_func; + + if (w < 1) w = 1; + if (h < 1) h = 1; + ee->visible = 1; + ee->x = x; + ee->y = y; + ee->w = w; + ee->h = h; + ee->req.x = ee->x; + ee->req.y = ee->y; + ee->req.w = ee->w; + ee->req.h = ee->h; + + ee->semi_sync = 1; + + + ee->prop.max.w = 32767; + ee->prop.max.h = 32767; + ee->prop.layer = 4; + ee->prop.request_pos = 0; + ee->prop.sticky = 0; + ee->prop.window = 0; + + printf("Create New Evas\n"); + + ee->evas = evas_new(); + + if (!ee->evas) + goto free_name; + + evas_data_attach_set(ee->evas, ee); + evas_output_method_set(ee->evas, rmethod); + evas_output_size_set(ee->evas, w, h); + evas_output_viewport_set(ee->evas, 0, 0, w, h); + + printf("Create New Cocoa Window\n"); + ee->prop.window = (Ecore_Cocoa_Window*)ecore_cocoa_window_new(x, y, w, h); + printf("Window Created %p\n", ee->prop.window); + if (!ee->prop.window) + { + _ecore_evas_cocoa_shutdown(); + free(ee); + return NULL; + } + + printf("Init Evas engine cocoa\n"); + if (!_ecore_evas_engine_cocoa_init(ee)) + { + _ecore_evas_cocoa_shutdown(); + free(ee); + return NULL; + } + + + ee->engine.func->fn_render = _ecore_evas_cocoa_render; + _ecore_evas_register(ee); + ecore_event_window_register(0, ee, ee->evas, NULL, NULL, NULL, NULL); + + printf("Ecore Evas returned : %p\n", ee); + return ee; + + free_window: + /* FIXME: free window here */ + free_evas: + free(ee->evas); + free_name: + free(ee->name); + free_ee: + _ecore_evas_cocoa_shutdown(); + free(ee); + shutdown_ecore_cocoa: + ecore_cocoa_shutdown(); + + return NULL; +#else + ERR("OUTCH name='%s' size=%dx%d!", name ? name : "", w, h); + return NULL; +#endif +} diff --git a/src/lib/ecore_evas/ecore_evas_private.h b/src/lib/ecore_evas/ecore_evas_private.h index 39b63e5..2c20761 100644 --- a/src/lib/ecore_evas/ecore_evas_private.h +++ b/src/lib/ecore_evas/ecore_evas_private.h @@ -86,6 +86,11 @@ # include #endif +#ifdef BUILD_ECORE_EVAS_GL_COCOA +# include "Ecore_Cocoa.h" +# include +#endif + /** Log domain macros and variable **/ -- 2.7.4