]> git.sesse.net Git - vlc/blob - modules/gui/minimal_macosx/voutagl.m
Make mouse-moved and mouse-clicked coordinates, remove mouse-x and -y
[vlc] / modules / gui / minimal_macosx / voutagl.m
1 /*****************************************************************************
2  * voutagl.c: MacOS X agl OpenGL provider (used by webbrowser.plugin)
3  *****************************************************************************
4  * Copyright (C) 2001-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Colin Delacroix <colin@zoy.org>
8  *          Florian G. Pflug <fgp@phlo.org>
9  *          Jon Lech Johansen <jon-vl@nanocrew.net>
10  *          Derk-Jan Hartman <hartman at videolan dot org>
11  *          Eric Petit <titer@m0k.org>
12  *          Benjamin Pracht <bigben at videolan dot org>
13  *          Damien Fouilleul <damienf at videolan dot org>
14  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 2 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
28  *****************************************************************************/
29
30 #include "intf.h"
31 #include "voutgl.h"
32 #include "voutagl.h"
33
34 /*****************************************************************************
35  * embedded AGL context implementation (not 64bit compatible)
36  *****************************************************************************/
37
38 #ifndef __x86_64__
39 static void aglSetViewport( vout_thread_t *p_vout, Rect viewBounds, Rect clipBounds );
40 static void aglReshape( vout_thread_t * p_vout );
41 static OSStatus WindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
42
43 int aglInit( vout_thread_t * p_vout )
44 {
45     vlc_value_t val;
46
47     Rect viewBounds;
48     Rect clipBounds;
49
50     static const GLint ATTRIBUTES[] = {
51         AGL_WINDOW,
52         AGL_RGBA,
53         AGL_NO_RECOVERY,
54         AGL_ACCELERATED,
55         AGL_DOUBLEBUFFER,
56         AGL_RED_SIZE,   8,
57         AGL_GREEN_SIZE, 8,
58         AGL_BLUE_SIZE,  8,
59         AGL_ALPHA_SIZE, 8,
60         AGL_DEPTH_SIZE, 24,
61         AGL_NONE };
62
63     AGLPixelFormat pixFormat;
64
65     p_vout->p_sys->b_embedded = true;
66
67     pixFormat = aglChoosePixelFormat(NULL, 0, ATTRIBUTES);
68     if( NULL == pixFormat )
69     {
70         msg_Err( p_vout, "No screen renderer available for required attributes." );
71         return VLC_EGENERIC;
72     }
73  
74     p_vout->p_sys->agl_ctx = aglCreateContext(pixFormat, NULL);
75     aglDestroyPixelFormat(pixFormat);
76     if( NULL == p_vout->p_sys->agl_ctx )
77     {
78         msg_Err( p_vout, "Cannot create AGL context." );
79         return VLC_EGENERIC;
80     }
81     else
82     {
83         // tell opengl not to sync buffer swap with vertical retrace (too inefficient)
84         GLint param = 0;
85         aglSetInteger(p_vout->p_sys->agl_ctx, AGL_SWAP_INTERVAL, &param);
86         aglEnable(p_vout->p_sys->agl_ctx, AGL_SWAP_INTERVAL);
87     }
88
89     var_Get( p_vout->p_libvlc, "drawable-agl", &val );
90     p_vout->p_sys->agl_drawable = (AGLDrawable)val.i_int;
91     aglSetDrawable(p_vout->p_sys->agl_ctx, p_vout->p_sys->agl_drawable);
92
93     var_Get( p_vout->p_libvlc, "drawable-view-top", &val );
94     viewBounds.top = val.i_int;
95     var_Get( p_vout->p_libvlc, "drawable-view-left", &val );
96     viewBounds.left = val.i_int;
97     var_Get( p_vout->p_libvlc, "drawable-view-bottom", &val );
98     viewBounds.bottom = val.i_int;
99     var_Get( p_vout->p_libvlc, "drawable-view-right", &val );
100     viewBounds.right = val.i_int;
101     var_Get( p_vout->p_libvlc, "drawable-clip-top", &val );
102     clipBounds.top = val.i_int;
103     var_Get( p_vout->p_libvlc, "drawable-clip-left", &val );
104     clipBounds.left = val.i_int;
105     var_Get( p_vout->p_libvlc, "drawable-clip-bottom", &val );
106     clipBounds.bottom = val.i_int;
107     var_Get( p_vout->p_libvlc, "drawable-clip-right", &val );
108     clipBounds.right = val.i_int;
109
110     p_vout->p_sys->b_clipped_out = (clipBounds.top == clipBounds.bottom)
111                                  || (clipBounds.left == clipBounds.right);
112     if( ! p_vout->p_sys->b_clipped_out )
113     {
114         aglLock(p_vout);
115         aglSetViewport(p_vout, viewBounds, clipBounds);
116         aglReshape(p_vout);
117         aglUnlock(p_vout);
118     }
119     p_vout->p_sys->clipBounds = clipBounds;
120     p_vout->p_sys->viewBounds = viewBounds;
121
122     return VLC_SUCCESS;
123 }
124
125 void aglEnd( vout_thread_t * p_vout )
126 {
127     aglSetCurrentContext(NULL);
128     if( p_vout->p_sys->theWindow )
129         DisposeWindow( p_vout->p_sys->theWindow );
130     aglDestroyContext(p_vout->p_sys->agl_ctx);
131 }
132
133 void aglReshape( vout_thread_t * p_vout )
134 {
135     unsigned int x, y;
136     unsigned int i_height = p_vout->p_sys->i_height;
137     unsigned int i_width  = p_vout->p_sys->i_width;
138
139     vout_PlacePicture(p_vout, i_width, i_height, &x, &y, &i_width, &i_height);
140
141     glViewport( p_vout->p_sys->i_offx + x, p_vout->p_sys->i_offy + y, i_width, i_height );
142
143     if( p_vout->p_sys->b_got_frame )
144     {
145         /* Ask the opengl module to redraw */
146         vout_thread_t * p_parent;
147         p_parent = (vout_thread_t *) p_vout->p_parent;
148         if( p_parent && p_parent->pf_display )
149         {
150             p_parent->pf_display( p_parent, NULL );
151         }
152     }
153     else
154     {
155         glClear( GL_COLOR_BUFFER_BIT );
156     }
157 }
158
159 /* private event class */
160 enum
161 {
162     kEventClassVLCPlugin = 'vlcp',
163 };
164 /* private event kinds */
165 enum
166 {
167     kEventVLCPluginShowFullscreen = 32768,
168     kEventVLCPluginHideFullscreen,
169 };
170
171 static void sendEventToMainThread(EventTargetRef target, UInt32 class, UInt32 kind)
172 {
173     EventRef myEvent;
174     if( noErr == CreateEvent(NULL, class, kind, 0, kEventAttributeNone, &myEvent) )
175     {
176         if( noErr == SetEventParameter(myEvent, kEventParamPostTarget, typeEventTargetRef, sizeof(EventTargetRef), &target) )
177         {
178             PostEventToQueue(GetMainEventQueue(), myEvent, kEventPriorityStandard);
179         }
180         ReleaseEvent(myEvent);
181     }
182 }
183
184 int aglManage( vout_thread_t * p_vout )
185 {
186     if( p_vout->i_changes & VOUT_ASPECT_CHANGE )
187     {
188         aglLock( p_vout );
189         aglReshape(p_vout);
190         aglUnlock( p_vout );
191         p_vout->i_changes &= ~VOUT_ASPECT_CHANGE;
192     }
193     if( p_vout->i_changes & VOUT_CROP_CHANGE )
194     {
195         aglLock( p_vout );
196         aglReshape(p_vout);
197         aglUnlock( p_vout );
198         p_vout->i_changes &= ~VOUT_CROP_CHANGE;
199     }
200     if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
201     {
202         aglSetDrawable(p_vout->p_sys->agl_ctx, NULL);
203         aglLock( p_vout );
204         if( p_vout->b_fullscreen )
205         {
206             /* Close the fullscreen window and resume normal drawing */
207             vlc_value_t val;
208             Rect viewBounds;
209             Rect clipBounds;
210
211             var_Get( p_vout->p_libvlc, "drawable-agl", &val );
212             p_vout->p_sys->agl_drawable = (AGLDrawable)val.i_int;
213             aglSetDrawable(p_vout->p_sys->agl_ctx, p_vout->p_sys->agl_drawable);
214
215             var_Get( p_vout->p_libvlc, "drawable-view-top", &val );
216             viewBounds.top = val.i_int;
217             var_Get( p_vout->p_libvlc, "drawable-view-left", &val );
218             viewBounds.left = val.i_int;
219             var_Get( p_vout->p_libvlc, "drawable-view-bottom", &val );
220             viewBounds.bottom = val.i_int;
221             var_Get( p_vout->p_libvlc, "drawable-view-right", &val );
222             viewBounds.right = val.i_int;
223             var_Get( p_vout->p_libvlc, "drawable-clip-top", &val );
224             clipBounds.top = val.i_int;
225             var_Get( p_vout->p_libvlc, "drawable-clip-left", &val );
226             clipBounds.left = val.i_int;
227             var_Get( p_vout->p_libvlc, "drawable-clip-bottom", &val );
228             clipBounds.bottom = val.i_int;
229             var_Get( p_vout->p_libvlc, "drawable-clip-right", &val );
230             clipBounds.right = val.i_int;
231
232             aglSetCurrentContext(p_vout->p_sys->agl_ctx);
233             aglSetViewport(p_vout, viewBounds, clipBounds);
234
235             /* Most Carbon APIs are not thread-safe, therefore delagate some GUI visibilty update to the main thread */
236             if( p_vout->p_sys->theWindow )
237                 sendEventToMainThread(GetWindowEventTarget(p_vout->p_sys->theWindow), kEventClassVLCPlugin, kEventVLCPluginHideFullscreen);
238         }
239         else
240         {
241             Rect deviceRect;
242  
243             GDHandle deviceHdl = GetMainDevice();
244             deviceRect = (*deviceHdl)->gdRect;
245  
246             if( !p_vout->p_sys->theWindow )
247             {
248                 /* Create a window */
249                 WindowAttributes    windowAttrs;
250
251                 windowAttrs = kWindowStandardDocumentAttributes
252                             | kWindowStandardHandlerAttribute
253                             | kWindowLiveResizeAttribute
254                             | kWindowNoShadowAttribute;
255  
256                 windowAttrs &= (~kWindowResizableAttribute);
257
258                 CreateNewWindow(kDocumentWindowClass, windowAttrs, &deviceRect, &p_vout->p_sys->theWindow);
259                 if( !p_vout->p_sys->winGroup )
260                 {
261                     CreateWindowGroup(0, &p_vout->p_sys->winGroup);
262                     SetWindowGroup(p_vout->p_sys->theWindow, p_vout->p_sys->winGroup);
263                     SetWindowGroupParent( p_vout->p_sys->winGroup, GetWindowGroupOfClass(kDocumentWindowClass) ) ;
264                 }
265  
266                 // Window title
267                 CFStringRef titleKey    = CFSTR("Fullscreen VLC media plugin");
268                 CFStringRef windowTitle = CFCopyLocalizedString(titleKey, NULL);
269                 SetWindowTitleWithCFString(p_vout->p_sys->theWindow, windowTitle);
270                 CFRelease(titleKey);
271                 CFRelease(windowTitle);
272  
273                 //Install event handler
274                 static const EventTypeSpec win_events[] = {
275                     { kEventClassMouse, kEventMouseDown },
276                     { kEventClassMouse, kEventMouseMoved },
277                     { kEventClassMouse, kEventMouseUp },
278                     { kEventClassWindow, kEventWindowClosed },
279                     { kEventClassWindow, kEventWindowBoundsChanged },
280                     { kEventClassCommand, kEventCommandProcess },
281                     { kEventClassVLCPlugin, kEventVLCPluginShowFullscreen },
282                     { kEventClassVLCPlugin, kEventVLCPluginHideFullscreen },
283                 };
284                 InstallWindowEventHandler (p_vout->p_sys->theWindow, NewEventHandlerUPP (WindowEventHandler), GetEventTypeCount(win_events), win_events, p_vout, NULL);
285             }
286             else
287             {
288                 /* just in case device resolution changed */
289                 SetWindowBounds(p_vout->p_sys->theWindow, kWindowContentRgn, &deviceRect);
290             }
291             glClear( GL_COLOR_BUFFER_BIT );
292             p_vout->p_sys->agl_drawable = (AGLDrawable)GetWindowPort(p_vout->p_sys->theWindow);
293             aglSetDrawable(p_vout->p_sys->agl_ctx, p_vout->p_sys->agl_drawable);
294             aglSetCurrentContext(p_vout->p_sys->agl_ctx);
295             aglSetViewport(p_vout, deviceRect, deviceRect);
296             //aglSetFullScreen(p_vout->p_sys->agl_ctx, device_width, device_height, 0, 0);
297
298             /* Most Carbon APIs are not thread-safe, therefore delagate some GUI visibilty update to the main thread */
299             sendEventToMainThread(GetWindowEventTarget(p_vout->p_sys->theWindow), kEventClassVLCPlugin, kEventVLCPluginShowFullscreen);
300         }
301         aglReshape(p_vout);
302         aglUnlock( p_vout );
303         p_vout->b_fullscreen = !p_vout->b_fullscreen;
304         p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
305     }
306     return VLC_SUCCESS;
307 }
308
309 int aglControl( vout_thread_t *p_vout, int i_query, va_list args )
310 {
311     switch( i_query )
312     {
313         case VOUT_SET_VIEWPORT:
314         {
315             Rect viewBounds, clipBounds;
316             viewBounds.top = va_arg( args, int);
317             viewBounds.left = va_arg( args, int);
318             viewBounds.bottom = va_arg( args, int);
319             viewBounds.right = va_arg( args, int);
320             clipBounds.top = va_arg( args, int);
321             clipBounds.left = va_arg( args, int);
322             clipBounds.bottom = va_arg( args, int);
323             clipBounds.right = va_arg( args, int);
324  
325             if( !p_vout->b_fullscreen )
326             {
327                 /*
328                 ** check that the clip rect is not empty, as this is used
329                 ** by Firefox to prevent a plugin from displaying during
330                 ** a scrolling event. In this case we just prevent buffers
331                 ** from being swapped and ignore clipping as this is less
332                 ** disruptive than a GL geometry change
333                 */
334
335                 p_vout->p_sys->b_clipped_out = (clipBounds.top == clipBounds.bottom)
336                                              || (clipBounds.left == clipBounds.right);
337                 if( ! p_vout->p_sys->b_clipped_out )
338                 {
339                     /* ignore consecutive viewport update with identical parameters */
340                     if( memcmp(&clipBounds, &(p_vout->p_sys->clipBounds), sizeof(clipBounds) )
341                      && memcmp(&viewBounds, &(p_vout->p_sys->viewBounds), sizeof(viewBounds)) )
342                     {
343                         aglLock( p_vout );
344                         aglSetViewport(p_vout, viewBounds, clipBounds);
345                         aglReshape( p_vout );
346                         aglUnlock( p_vout );
347                         p_vout->p_sys->clipBounds = clipBounds;
348                         p_vout->p_sys->viewBounds = viewBounds;
349                     }
350                 }
351             }
352             return VLC_SUCCESS;
353         }
354
355         case VOUT_REDRAW_RECT:
356         {
357             vout_thread_t * p_parent;
358             Rect areaBounds;
359
360             areaBounds.top = va_arg( args, int);
361             areaBounds.left = va_arg( args, int);
362             areaBounds.bottom = va_arg( args, int);
363             areaBounds.right = va_arg( args, int);
364
365             /* Ask the opengl module to redraw */
366             p_parent = (vout_thread_t *) p_vout->p_parent;
367             if( p_parent && p_parent->pf_display )
368             {
369                 p_parent->pf_display( p_parent, NULL );
370             }
371             return VLC_SUCCESS;
372         }
373
374         default:
375             return VLC_EGENERIC;
376     }
377 }
378
379 void aglSwap( vout_thread_t * p_vout )
380 {
381     if( ! p_vout->p_sys->b_clipped_out )
382     {
383         p_vout->p_sys->b_got_frame = true;
384         aglSwapBuffers(p_vout->p_sys->agl_ctx);
385     }
386     else
387     {
388         /* drop frame */
389         glFlush();
390     }
391 }
392
393 /* Enter this function with the p_vout locked */
394 static void aglSetViewport( vout_thread_t *p_vout, Rect viewBounds, Rect clipBounds )
395 {
396     // mozilla plugin provides coordinates based on port bounds
397     // however AGL coordinates are based on window structure region
398     // and are vertically flipped
399     GLint rect[4];
400     CGrafPtr port = (CGrafPtr)p_vout->p_sys->agl_drawable;
401     Rect winBounds, clientBounds;
402
403     GetWindowBounds(GetWindowFromPort(port),
404         kWindowStructureRgn, &winBounds);
405     GetWindowBounds(GetWindowFromPort(port),
406         kWindowContentRgn, &clientBounds);
407
408     /* update video clipping bounds in drawable */
409     rect[0] = (clientBounds.left-winBounds.left)
410             + clipBounds.left;                  // from window left edge
411     rect[1] = (winBounds.bottom-winBounds.top)
412             - (clientBounds.top-winBounds.top)
413             - clipBounds.bottom;                // from window bottom edge
414     rect[2] = clipBounds.right-clipBounds.left; // width
415     rect[3] = clipBounds.bottom-clipBounds.top; // height
416     aglSetInteger(p_vout->p_sys->agl_ctx, AGL_BUFFER_RECT, rect);
417     aglEnable(p_vout->p_sys->agl_ctx, AGL_BUFFER_RECT);
418
419     /* update video internal bounds in drawable */
420     p_vout->p_sys->i_width  = viewBounds.right-viewBounds.left;
421     p_vout->p_sys->i_height = viewBounds.bottom-viewBounds.top;
422     p_vout->p_sys->i_offx   = -clipBounds.left - viewBounds.left;
423     p_vout->p_sys->i_offy   = clipBounds.bottom + viewBounds.top
424                             - p_vout->p_sys->i_height;
425
426     aglUpdateContext(p_vout->p_sys->agl_ctx);
427 }
428
429 //default window event handler
430 static pascal OSStatus WindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
431 {
432     OSStatus result = noErr;
433     UInt32 class = GetEventClass (event);
434     UInt32 kind = GetEventKind (event);
435     vout_thread_t *p_vout = (vout_thread_t *)userData;
436
437     result = CallNextEventHandler(nextHandler, event);
438     if(class == kEventClassCommand)
439     {
440         HICommand theHICommand;
441         GetEventParameter( event, kEventParamDirectObject, typeHICommand, NULL, sizeof( HICommand ), NULL, &theHICommand );
442  
443         switch ( theHICommand.commandID )
444         {
445             default:
446                 result = eventNotHandledErr;
447         }
448     }
449     else if(class == kEventClassWindow)
450     {
451         WindowRef     window;
452         Rect          rectPort = {0,0,0,0};
453  
454         GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window);
455
456         if(window)
457         {
458             GetPortBounds(GetWindowPort(window), &rectPort);
459         }
460
461         switch (kind)
462         {
463             case kEventWindowClosed:
464             case kEventWindowZoomed:
465             case kEventWindowBoundsChanged:
466                 break;
467  
468             default:
469                 result = eventNotHandledErr;
470         }
471     }
472     else if(class == kEventClassMouse)
473     {
474         switch (kind)
475         {
476             case kEventMouseDown:
477             {
478                 UInt16     button;
479  
480                 GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(button), NULL, &button);
481                 switch (button)
482                 {
483                     case kEventMouseButtonPrimary:
484                     {
485                         vlc_value_t val;
486
487                         var_Get( p_vout, "mouse-button-down", &val );
488                         val.i_int |= 1;
489                         var_Set( p_vout, "mouse-button-down", val );
490                         break;
491                     }
492                     case kEventMouseButtonSecondary:
493                     {
494                         vlc_value_t val;
495
496                         var_Get( p_vout, "mouse-button-down", &val );
497                         val.i_int |= 2;
498                         var_Set( p_vout, "mouse-button-down", val );
499                         break;
500                     }
501                     case kEventMouseButtonTertiary:
502                     {
503                         vlc_value_t val;
504
505                         var_Get( p_vout, "mouse-button-down", &val );
506                         val.i_int |= 4;
507                         var_Set( p_vout, "mouse-button-down", val );
508                         break;
509                     }
510                     default:
511                         result = eventNotHandledErr;
512                 }
513                 break;
514             }
515
516             case kEventMouseUp:
517             {
518                 UInt16     button;
519  
520                 GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(button), NULL, &button);
521                 switch (button)
522                 {
523                     case kEventMouseButtonPrimary:
524                     {
525                         UInt32 clickCount = 0;
526                         GetEventParameter(event, kEventParamClickCount, typeUInt32, NULL, sizeof(clickCount), NULL, &clickCount);
527                         if( clickCount > 1 )
528                         {
529                             vlc_value_t val;
530
531                             val.b_bool = false;
532                             var_Set((vout_thread_t *) p_vout->p_parent, "fullscreen", val);
533                         }
534                         else
535                         {
536                             vlc_value_t val;
537                             int x, y;
538
539                             var_GetCoords( p_vout, "mouse-moved", &x, &y );
540                             var_SetCoords( p_vout, "mouse-clicked", x, y );
541
542                             var_Get( p_vout, "mouse-button-down", &val );
543                             val.i_int &= ~1;
544                             var_Set( p_vout, "mouse-button-down", val );
545                         }
546                         break;
547                     }
548                     case kEventMouseButtonSecondary:
549                     {
550                         vlc_value_t val;
551
552                         var_Get( p_vout, "mouse-button-down", &val );
553                         val.i_int &= ~2;
554                         var_Set( p_vout, "mouse-button-down", val );
555                         break;
556                     }
557                     case kEventMouseButtonTertiary:
558                     {
559                         vlc_value_t val;
560
561                         var_Get( p_vout, "mouse-button-down", &val );
562                         val.i_int &= ~2;
563                         var_Set( p_vout, "mouse-button-down", val );
564                         break;
565                     }
566                     default:
567                         result = eventNotHandledErr;
568                 }
569                 break;
570             }
571
572             case kEventMouseMoved:
573             {
574                 Point ml;
575                 vlc_value_t val;
576
577                 unsigned int i_x, i_y;
578                 unsigned int i_height = p_vout->p_sys->i_height;
579                 unsigned int i_width  = p_vout->p_sys->i_width;
580                 int x, y;
581
582                 vout_PlacePicture(p_vout, i_width, i_height, &i_x, &i_y, &i_width, &i_height);
583
584                 GetEventParameter(event, kEventParamWindowMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &ml);
585  
586                 x = (((int)ml.h) - i_x) * p_vout->render.i_width / i_width;
587                 y = (((int)ml.v) - i_y) * p_vout->render.i_height / i_height;
588                 var_SetCoords( p_vout, "mouse-moved", x, y );
589                 break;
590             }
591  
592             default:
593                 result = eventNotHandledErr;
594         }
595     }
596     else if(class == kEventClassTextInput)
597     {
598         switch (kind)
599         {
600             case kEventTextInputUnicodeForKeyEvent:
601             {
602                 break;
603             }
604             default:
605                 result = eventNotHandledErr;
606         }
607     }
608     else if(class == kEventClassVLCPlugin)
609     {
610         switch (kind)
611         {
612             case kEventVLCPluginShowFullscreen:
613                 ShowWindow (p_vout->p_sys->theWindow);
614                 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
615                 //CGDisplayHideCursor(kCGDirectMainDisplay);
616                 break;
617             case kEventVLCPluginHideFullscreen:
618                 HideWindow (p_vout->p_sys->theWindow);
619                 SetSystemUIMode( kUIModeNormal, 0);
620                 CGDisplayShowCursor(kCGDirectMainDisplay);
621                 break;
622             default:
623                 result = eventNotHandledErr;
624                 break;
625         }
626     }
627     return result;
628 }
629
630 int aglLock( vout_thread_t * p_vout )
631 {
632 #ifdef __ppc__
633     /*
634      * before 10.4, we set the AGL context as current and
635      * then we retrieve and use the matching CGL context
636      */
637     aglSetCurrentContext(p_vout->p_sys->agl_ctx);
638     return kCGLNoError != CGLLockContext( CGLGetCurrentContext() );
639 #else
640     /* since 10.4, this is the safe way to get the underlying CGL context */
641     CGLContextObj cglContext;
642     if( aglGetCGLContext(p_vout->p_sys->agl_ctx, (void**)&cglContext) )
643     {
644         if( kCGLNoError == CGLLockContext( cglContext ) )
645         {
646             aglSetCurrentContext(p_vout->p_sys->agl_ctx);
647             return 0;
648         }
649     }
650     return 1;
651 #endif
652 }
653
654 void aglUnlock( vout_thread_t * p_vout )
655 {
656 #ifdef __ppc__
657     /*
658      * before 10.4, we assume that the AGL context is current.
659      * therefore, we use the current CGL context
660      */
661     CGLUnlockContext( CGLGetCurrentContext() );
662 #else
663     /* since 10.4, this is the safe way to get the underlying CGL context */
664     CGLContextObj cglContext;
665     if( aglGetCGLContext(p_vout->p_sys->agl_ctx, (void**)&cglContext) )
666     {
667         CGLUnlockContext( cglContext );
668     }
669 #endif
670 }
671
672 #endif