]> git.sesse.net Git - vlc/blob - modules/gui/minimal_macosx/voutagl.m
58f457f2de68ed87967be13b31fde5db04a21d55
[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
538                             var_SetBool( p_vout, "mouse-clicked", true );
539
540                             var_Get( p_vout, "mouse-button-down", &val );
541                             val.i_int &= ~1;
542                             var_Set( p_vout, "mouse-button-down", val );
543                         }
544                         break;
545                     }
546                     case kEventMouseButtonSecondary:
547                     {
548                         vlc_value_t val;
549
550                         var_Get( p_vout, "mouse-button-down", &val );
551                         val.i_int &= ~2;
552                         var_Set( p_vout, "mouse-button-down", val );
553                         break;
554                     }
555                     case kEventMouseButtonTertiary:
556                     {
557                         vlc_value_t val;
558
559                         var_Get( p_vout, "mouse-button-down", &val );
560                         val.i_int &= ~2;
561                         var_Set( p_vout, "mouse-button-down", val );
562                         break;
563                     }
564                     default:
565                         result = eventNotHandledErr;
566                 }
567                 break;
568             }
569
570             case kEventMouseMoved:
571             {
572                 Point ml;
573                 vlc_value_t val;
574
575                 unsigned int i_x, i_y;
576                 unsigned int i_height = p_vout->p_sys->i_height;
577                 unsigned int i_width  = p_vout->p_sys->i_width;
578
579                 vout_PlacePicture(p_vout, i_width, i_height, &i_x, &i_y, &i_width, &i_height);
580
581                 GetEventParameter(event, kEventParamWindowMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &ml);
582  
583                 val.i_int = ( ((int)ml.h) - i_x ) *
584                             p_vout->render.i_width / i_width;
585                 var_Set( p_vout, "mouse-x", val );
586
587                 val.i_int = ( ((int)ml.v) - i_y ) *
588                             p_vout->render.i_height / i_height;
589
590                 var_Set( p_vout, "mouse-y", val );
591                 var_TriggerCallback( p_vout, "mouse-moved" );
592                 break;
593             }
594  
595             default:
596                 result = eventNotHandledErr;
597         }
598     }
599     else if(class == kEventClassTextInput)
600     {
601         switch (kind)
602         {
603             case kEventTextInputUnicodeForKeyEvent:
604             {
605                 break;
606             }
607             default:
608                 result = eventNotHandledErr;
609         }
610     }
611     else if(class == kEventClassVLCPlugin)
612     {
613         switch (kind)
614         {
615             case kEventVLCPluginShowFullscreen:
616                 ShowWindow (p_vout->p_sys->theWindow);
617                 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
618                 //CGDisplayHideCursor(kCGDirectMainDisplay);
619                 break;
620             case kEventVLCPluginHideFullscreen:
621                 HideWindow (p_vout->p_sys->theWindow);
622                 SetSystemUIMode( kUIModeNormal, 0);
623                 CGDisplayShowCursor(kCGDirectMainDisplay);
624                 break;
625             default:
626                 result = eventNotHandledErr;
627                 break;
628         }
629     }
630     return result;
631 }
632
633 int aglLock( vout_thread_t * p_vout )
634 {
635 #ifdef __ppc__
636     /*
637      * before 10.4, we set the AGL context as current and
638      * then we retrieve and use the matching CGL context
639      */
640     aglSetCurrentContext(p_vout->p_sys->agl_ctx);
641     return kCGLNoError != CGLLockContext( CGLGetCurrentContext() );
642 #else
643     /* since 10.4, this is the safe way to get the underlying CGL context */
644     CGLContextObj cglContext;
645     if( aglGetCGLContext(p_vout->p_sys->agl_ctx, (void**)&cglContext) )
646     {
647         if( kCGLNoError == CGLLockContext( cglContext ) )
648         {
649             aglSetCurrentContext(p_vout->p_sys->agl_ctx);
650             return 0;
651         }
652     }
653     return 1;
654 #endif
655 }
656
657 void aglUnlock( vout_thread_t * p_vout )
658 {
659 #ifdef __ppc__
660     /*
661      * before 10.4, we assume that the AGL context is current.
662      * therefore, we use the current CGL context
663      */
664     CGLUnlockContext( CGLGetCurrentContext() );
665 #else
666     /* since 10.4, this is the safe way to get the underlying CGL context */
667     CGLContextObj cglContext;
668     if( aglGetCGLContext(p_vout->p_sys->agl_ctx, (void**)&cglContext) )
669     {
670         CGLUnlockContext( cglContext );
671     }
672 #endif
673 }
674
675 #endif