summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Aguirre <aguirre.nicolas@gmail.com>2011-11-02 18:31:31 +0000
committerNicolas Aguirre <aguirre.nicolas@gmail.com>2011-11-02 18:31:31 +0000
commit336c043d87dbcb92b72c2d988cdcb2f264ca52b6 (patch)
tree0358bc78c0dfc5271666631eb0db1595fd37179b
parent7045c20e5bd9990772dd2086646f351a9fec6130 (diff)
expedite: Add gl_cocoa support in expedite
SVN revision: 64654
-rw-r--r--configure.ac5
-rw-r--r--src/bin/Makefile.am7
-rw-r--r--src/bin/engine_gl_cocoa.h8
-rw-r--r--src/bin/engine_gl_cocoa.m231
-rw-r--r--src/bin/main.c3
-rw-r--r--src/bin/main.h3
6 files changed, 256 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 4d52f8e..8c715a2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -85,6 +85,10 @@ EXPEDITE_CHECK_ENGINE([fb], [Framebuffer], "yes")
85# DIRECTFB 85# DIRECTFB
86EXPEDITE_CHECK_ENGINE([directfb], [DirectFB], "yes") 86EXPEDITE_CHECK_ENGINE([directfb], [DirectFB], "yes")
87 87
88# GL Cocoa
89EXPEDITE_CHECK_ENGINE([opengl-cocoa], [OpenGL Cocoa], "yes", [gl_cocoa_libs="-framework Cocoa"])
90AC_SUBST(gl_cocoa_libs)
91
88# Software 16bit X11 92# Software 16bit X11
89EXPEDITE_CHECK_ENGINE([software-16-x11], [Software 16 bits X11], "yes") 93EXPEDITE_CHECK_ENGINE([software-16-x11], [Software 16 bits X11], "yes")
90 94
@@ -260,6 +264,7 @@ echo " Software DirectDraw..........: ${have_software_ddraw}"
260echo " Direct3D.....................: ${have_direct3d}" 264echo " Direct3D.....................: ${have_direct3d}"
261echo " Software SDL.................: ${have_software_sdl}" 265echo " Software SDL.................: ${have_software_sdl}"
262echo " Open GL SDL..................: ${have_opengl_sdl}" 266echo " Open GL SDL..................: ${have_opengl_sdl}"
267echo " Open GL Cocoa................: ${have_opengl_cocoa}"
263echo " FB...........................: ${have_fb}" 268echo " FB...........................: ${have_fb}"
264echo " DirectFB.....................: ${have_directfb}" 269echo " DirectFB.....................: ${have_directfb}"
265echo " Software X11 16 bits.........: ${have_software_16_x11}" 270echo " Software X11 16 bits.........: ${have_software_16_x11}"
diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am
index 20793b2..ba7cc04 100644
--- a/src/bin/Makefile.am
+++ b/src/bin/Makefile.am
@@ -144,7 +144,7 @@ proxy_text_random.c
144 144
145expedite_CFLAGS = @WIN32_CFLAGS@ 145expedite_CFLAGS = @WIN32_CFLAGS@
146expedite_CXXFLAGS = @EXPEDITE_CXXFLAGS@ 146expedite_CXXFLAGS = @EXPEDITE_CXXFLAGS@
147expedite_LDADD = @SDL_LIBS@ @x_libs@ @gdi_libs@ @ddraw_libs@ @ddraw_16_libs@ @d3d_libs@ @wince_16_libs@ @DIRECTFB_LIBS@ @XCB_LIBS@ @EVAS_LIBS@ @EINA_LIBS@ @EVIL_LIBS@ -lm 147expedite_LDADD = @SDL_LIBS@ @x_libs@ @gdi_libs@ @ddraw_libs@ @ddraw_16_libs@ @d3d_libs@ @wince_16_libs@ @DIRECTFB_LIBS@ @XCB_LIBS@ @EVAS_LIBS@ @EINA_LIBS@ @EVIL_LIBS@ @gl_cocoa_libs@ -lm
148expedite_LDFLAGS = @lt_enable_auto_import@ 148expedite_LDFLAGS = @lt_enable_auto_import@
149 149
150if BUILD_SOFTWARE_XLIB 150if BUILD_SOFTWARE_XLIB
@@ -207,6 +207,11 @@ expedite_SOURCES += \
207engine_directfb.c engine_directfb.h 207engine_directfb.c engine_directfb.h
208endif 208endif
209 209
210if BUILD_OPENGL_COCOA
211expedite_SOURCES += \
212engine_gl_cocoa.m engine_gl_cocoa.h
213endif
214
210if BUILD_SOFTWARE_16_X11 215if BUILD_SOFTWARE_16_X11
211expedite_SOURCES += \ 216expedite_SOURCES += \
212engine_software_16_x11.c engine_software_16_x11.h 217engine_software_16_x11.c engine_software_16_x11.h
diff --git a/src/bin/engine_gl_cocoa.h b/src/bin/engine_gl_cocoa.h
new file mode 100644
index 0000000..77430c9
--- /dev/null
+++ b/src/bin/engine_gl_cocoa.h
@@ -0,0 +1,8 @@
1#ifndef ENGINE_GL_COCOA_H
2#define ENGINE_GL_COCOA_H
3
4int engine_gl_cocoa_args(int argc, char **argv);
5void engine_gl_cocoa_loop(void);
6void engine_gl_cocoa_shutdown(void);
7
8#endif
diff --git a/src/bin/engine_gl_cocoa.m b/src/bin/engine_gl_cocoa.m
new file mode 100644
index 0000000..a6878d7
--- /dev/null
+++ b/src/bin/engine_gl_cocoa.m
@@ -0,0 +1,231 @@
1/* NOTE: If you're using Expedite for performance testing,
2 set "Disable Beam Synchronization" in GL_Cocoa Debug. */
3
4#include "main.h"
5
6#include <Cocoa/Cocoa.h>
7#include <Evas_Engine_GL_Cocoa.h>
8
9static NSView * evas_view;
10static NSWindow * main_window;
11
12
13int
14engine_gl_cocoa_args(int argc, char **argv)
15{
16 Evas_Engine_Info_GL_Cocoa *einfo;
17 int i;
18 int ok = 0;
19
20 /*
21 for (i = 1; i < argc; i++)
22 {
23 if ((!strcmp(argv[i], "-e")) && (i < (argc - 1)))
24 {
25 i++;
26 if (!strcmp(argv[i], "gl-cocoa")) ok = 1;
27 }
28 }
29 if (!ok) return 0;
30 */
31
32 evas_output_method_set(evas, evas_render_method_lookup("gl_cocoa"));
33 einfo = (Evas_Engine_Info_GL_Cocoa *)evas_engine_info_get(evas);
34 if (!einfo)
35 {
36 printf("Evas is a goat and can't run GL_COCOA ... or .... it's me the goat\n");
37 return 0;
38 }
39
40 // Set up the Cocoa runtime
41 [[NSAutoreleasePool alloc] init];
42 [NSApplication sharedApplication];
43
44 // Register ourselves as a full-fledged Cocoa app, instead of a NSUIElement.
45 // This gives benefits like window focus and a dock icon!
46 ProcessSerialNumber psn = { 0, kCurrentProcess };
47 TransformProcessType (&psn, kProcessTransformToForegroundApplication);
48
49 [NSApp finishLaunching];
50 // Create our main window, and embed an EvasGLView in it
51 main_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(20,500,win_w,win_h) styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask) backing:NSBackingStoreBuffered defer:NO screen:nil];
52 [main_window makeKeyAndOrderFront:NSApp];
53 [main_window setTitle:@"Expedite"];
54 [main_window makeMainWindow];
55 [main_window setAcceptsMouseMovedEvents:YES];
56 [NSApp activateIgnoringOtherApps:YES];
57
58 evas_output_size_set(evas, win_w, win_h);
59 evas_output_viewport_set(evas, 0, 0, win_w, win_h);
60
61 einfo->window = main_window;
62
63 //einfo->info.context = [evas_view context];
64 if (!evas_engine_info_set(evas, (Evas_Engine_Info *) einfo))
65 {
66 printf("Evas can not setup the informations of the GL_Cocoa Engine\n");
67 exit(-1);
68 }
69
70 evas_view = (NSView*)einfo->view;
71 [[main_window contentView] addSubview:evas_view];
72 [evas_view display];
73
74 evas_damage_rectangle_add(evas,0,0, win_w ,win_h);
75 return 1;
76}
77
78void
79engine_gl_cocoa_loop(void)
80{
81 NSDate *date = [NSDate dateWithTimeIntervalSinceNow:0.001];
82
83 NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask
84 untilDate:date
85 inMode:NSDefaultRunLoopMode
86 dequeue:YES];
87 [date release];
88
89 if (!event) return;
90
91 if([event type] == NSMouseMoved || [event type] == NSLeftMouseDragged || [event type] == NSRightMouseDragged)
92 {
93 evas_event_feed_mouse_move(evas, [event locationInWindow].x, [event locationInWindow].y, 0, NULL);
94
95 // Also notify on entering or leaving the window
96 NSPoint mouseLoc = [[event window] convertBaseToScreen:[event locationInWindow]];
97
98 if(NSPointInRect(mouseLoc, [[event window] frame]))
99 evas_event_feed_mouse_in(evas, 0, NULL);
100 else
101 evas_event_feed_mouse_out(evas, 0, NULL);
102
103 [NSApp sendEvent:event];
104 }
105 else if([event type] == NSLeftMouseDown)
106 {
107 evas_event_feed_mouse_move(evas, [event locationInWindow].x, [event locationInWindow].y, 0, NULL);
108 evas_event_feed_mouse_down(evas, 1, EVAS_BUTTON_NONE, 0, NULL);
109
110 [NSApp sendEvent:event];
111 }
112 else if([event type] == NSLeftMouseUp)
113 {
114 evas_event_feed_mouse_move(evas, [event locationInWindow].x, [event locationInWindow].y, 0, NULL);
115 evas_event_feed_mouse_up(evas, 1, EVAS_BUTTON_NONE, 0, NULL);
116
117 [NSApp sendEvent:event];
118 }
119 else if([event type] == NSRightMouseDown)
120 {
121 evas_event_feed_mouse_move(evas, [event locationInWindow].x, [event locationInWindow].y, 0, NULL);
122 evas_event_feed_mouse_down(evas, 3, EVAS_BUTTON_NONE, 0, NULL);
123 [NSApp sendEvent:event];
124 }
125 else if([event type] == NSRightMouseUp)
126 {
127 evas_event_feed_mouse_move(evas, [event locationInWindow].x, [event locationInWindow].y, 0, NULL);
128 evas_event_feed_mouse_up(evas, 3, EVAS_BUTTON_NONE, 0, NULL);
129 [NSApp sendEvent:event];
130 }
131 else if([event type] == NSKeyDown)
132 {
133 NSString * chars = [event charactersIgnoringModifiers];
134
135 switch([chars characterAtIndex:0])
136 {
137 case NSLeftArrowFunctionKey:
138 evas_event_feed_key_down(evas, "Left", "Left", NULL, NULL, 0, NULL);
139 break;
140 case NSRightArrowFunctionKey:
141 evas_event_feed_key_down(evas, "Right", "Right", NULL, NULL, 0, NULL);
142 break;
143 case NSEnterCharacter:
144 case NSCarriageReturnCharacter:
145 evas_event_feed_key_down(evas, "Return", "Return", NULL, NULL, 0, NULL);
146 break;
147 case 's':
148 case '\e':
149 evas_event_feed_key_down(evas, "Escape", "Escape", NULL, NULL, 0, NULL);
150 break;
151 case 'q':
152 evas_event_feed_key_down(evas, "q", "q", NULL, NULL, 0, NULL);
153 break;
154 }
155
156 [chars release];
157 }
158 else if([event type] == NSKeyUp)
159 {
160 NSString * chars = [event charactersIgnoringModifiers];
161
162 switch([chars characterAtIndex:0])
163 {
164 case NSLeftArrowFunctionKey:
165 evas_event_feed_key_up(evas, "Left", "Left", NULL, NULL, 0, NULL);
166 break;
167 case NSRightArrowFunctionKey:
168 evas_event_feed_key_up(evas, "Right", "Right", NULL, NULL, 0, NULL);
169 break;
170 case NSEnterCharacter:
171 case NSCarriageReturnCharacter:
172 evas_event_feed_key_up(evas, "Return", "Return", NULL, NULL, 0, NULL);
173 break;
174 case '\e':
175 evas_event_feed_key_up(evas, "Escape", "Escape", NULL, NULL, 0, NULL);
176 break;
177 case 'q':
178 if (evas_key_lock_is_set(evas_key_lock_get(evas), "Caps_Lock"))
179 evas_event_feed_key_up(evas, "Q", "Q", NULL, NULL, 0, NULL);
180 else
181 evas_event_feed_key_up(evas, "q", "q", NULL, NULL, 0, NULL);
182 break;
183 }
184
185 [chars release];
186 }
187 else if([event type] == NSFlagsChanged)
188 {
189 int flags = [event modifierFlags];
190
191 // Turn special key flags on
192 if(flags & NSShiftKeyMask)
193 evas_key_modifier_on(evas, "Shift");
194 else if(flags & NSControlKeyMask)
195 evas_key_modifier_on(evas, "Control");
196 else if(flags & NSAlternateKeyMask)
197 evas_key_modifier_on(evas, "Alt");
198 else if(flags & NSCommandKeyMask)
199 evas_key_modifier_on(evas, "Super");
200 else if(flags & NSAlphaShiftKeyMask)
201 {
202 if (evas_key_lock_is_set(evas_key_lock_get(evas), "Caps_Lock"))
203 evas_key_lock_off(evas, "Caps_Lock");
204 else
205 evas_key_lock_on(evas, "Caps_Lock");
206 }
207
208 // Turn special key flags off
209 if(!(flags & NSShiftKeyMask))
210 evas_key_modifier_off(evas, "Shift");
211 else if(!(flags & NSControlKeyMask))
212 evas_key_modifier_off(evas, "Control");
213 else if(!(flags & NSAlternateKeyMask))
214 evas_key_modifier_off(evas, "Alt");
215 else if(!(flags & NSCommandKeyMask))
216 evas_key_modifier_off(evas, "Super");
217 }
218 else
219 {
220 [NSApp sendEvent:event];
221 }
222
223 [event release];
224 [NSAutoreleasePool release];
225}
226
227void
228engine_gl_cocoa_shutdown(void)
229{
230 /* If someone knows what to do here... */
231}
diff --git a/src/bin/main.c b/src/bin/main.c
index ad63dc6..29c23d4 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -1171,6 +1171,9 @@ static const Expedite_Engine engines[] = {
1171#if HAVE_EVAS_DIRECTFB 1171#if HAVE_EVAS_DIRECTFB
1172 { "directfb",engine_directfb_args, engine_directfb_loop, engine_directfb_shutdown }, 1172 { "directfb",engine_directfb_args, engine_directfb_loop, engine_directfb_shutdown },
1173#endif 1173#endif
1174#if HAVE_EVAS_OPENGL_COCOA
1175 { "gl-cocoa", engine_gl_cocoa_args, engine_gl_cocoa_loop, engine_gl_cocoa_shutdown },
1176#endif
1174#if HAVE_EVAS_SOFTWARE_16_X11 1177#if HAVE_EVAS_SOFTWARE_16_X11
1175 { "x11-16",engine_software_16_x11_args, engine_software_16_x11_loop, engine_software_16_x11_shutdown }, 1178 { "x11-16",engine_software_16_x11_args, engine_software_16_x11_loop, engine_software_16_x11_shutdown },
1176#endif 1179#endif
diff --git a/src/bin/main.h b/src/bin/main.h
index fc78a7e..c0f1348 100644
--- a/src/bin/main.h
+++ b/src/bin/main.h
@@ -61,6 +61,9 @@
61#if HAVE_EVAS_DIRECTFB 61#if HAVE_EVAS_DIRECTFB
62#include "engine_directfb.h" 62#include "engine_directfb.h"
63#endif 63#endif
64#if HAVE_EVAS_OPENGL_COCOA
65#include "engine_gl_cocoa.h"
66#endif
64#if HAVE_EVAS_SOFTWARE_16_X11 67#if HAVE_EVAS_SOFTWARE_16_X11
65#include "engine_software_16_x11.h" 68#include "engine_software_16_x11.h"
66#endif 69#endif