]> git.sesse.net Git - vlc/blob - modules/gui/minimal_macosx/voutagl.m
macosx: experimental 64bit support
[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             sendEventToMainThread(GetWindowEventTarget(p_vout->p_sys->theWindow), kEventClassVLCPlugin, kEventVLCPluginHideFullscreen);
237         }
238         else
239         {
240             Rect deviceRect;
241  
242             GDHandle deviceHdl = GetMainDevice();
243             deviceRect = (*deviceHdl)->gdRect;
244  
245             if( !p_vout->p_sys->theWindow )
246             {
247                 /* Create a window */
248                 WindowAttributes    windowAttrs;
249
250                 windowAttrs = kWindowStandardDocumentAttributes
251                             | kWindowStandardHandlerAttribute
252                             | kWindowLiveResizeAttribute
253                             | kWindowNoShadowAttribute;
254  
255                 windowAttrs &= (~kWindowResizableAttribute);
256
257                 CreateNewWindow(kDocumentWindowClass, windowAttrs, &deviceRect, &p_vout->p_sys->theWindow);
258                 if( !p_vout->p_sys->winGroup )
259                 {
260                     CreateWindowGroup(0, &p_vout->p_sys->winGroup);
261                     SetWindowGroup(p_vout->p_sys->theWindow, p_vout->p_sys->winGroup);
262                     SetWindowGroupParent( p_vout->p_sys->winGroup, GetWindowGroupOfClass(kDocumentWindowClass) ) ;
263                 }
264  
265                 // Window title
266                 CFStringRef titleKey    = CFSTR("Fullscreen VLC media plugin");
267                 CFStringRef windowTitle = CFCopyLocalizedString(titleKey, NULL);
268                 SetWindowTitleWithCFString(p_vout->p_sys->theWindow, windowTitle);
269                 CFRelease(titleKey);
270                 CFRelease(windowTitle);
271  
272                 //Install event handler
273                 static const EventTypeSpec win_events[] = {
274                     { kEventClassMouse, kEventMouseDown },
275                     { kEventClassMouse, kEventMouseMoved },
276                     { kEventClassMouse, kEventMouseUp },
277                     { kEventClassWindow, kEventWindowClosed },
278                     { kEventClassWindow, kEventWindowBoundsChanged },
279                     { kEventClassCommand, kEventCommandProcess },
280                     { kEventClassVLCPlugin, kEventVLCPluginShowFullscreen },
281                     { kEventClassVLCPlugin, kEventVLCPluginHideFullscreen },
282                 };
283                 InstallWindowEventHandler (p_vout->p_sys->theWindow, NewEventHandlerUPP (WindowEventHandler), GetEventTypeCount(win_events), win_events, p_vout, NULL);
284             }
285             else
286             {
287                 /* just in case device resolution changed */
288                 SetWindowBounds(p_vout->p_sys->theWindow, kWindowContentRgn, &deviceRect);
289             }
290             glClear( GL_COLOR_BUFFER_BIT );
291             p_vout->p_sys->agl_drawable = (AGLDrawable)GetWindowPort(p_vout->p_sys->theWindow);
292             aglSetDrawable(p_vout->p_sys->agl_ctx, p_vout->p_sys->agl_drawable);
293             aglSetCurrentContext(p_vout->p_sys->agl_ctx);
294             aglSetViewport(p_vout, deviceRect, deviceRect);
295             //aglSetFullScreen(p_vout->p_sys->agl_ctx, device_width, device_height, 0, 0);
296
297             /* Most Carbon APIs are not thread-safe, therefore delagate some GUI visibilty update to the main thread */
298             sendEventToMainThread(GetWindowEventTarget(p_vout->p_sys->theWindow), kEventClassVLCPlugin, kEventVLCPluginShowFullscreen);
299         }
300         aglReshape(p_vout);
301         aglUnlock( p_vout );
302         p_vout->b_fullscreen = !p_vout->b_fullscreen;
303         p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
304     }
305     return VLC_SUCCESS;
306 }
307
308 int aglControl( vout_thread_t *p_vout, int i_query, va_list args )
309 {
310     switch( i_query )
311     {
312         case VOUT_SET_VIEWPORT:
313         {
314             Rect viewBounds, clipBounds;
315             viewBounds.top = va_arg( args, int);
316             viewBounds.left = va_arg( args, int);
317             viewBounds.bottom = va_arg( args, int);
318             viewBounds.right = va_arg( args, int);
319             clipBounds.top = va_arg( args, int);
320             clipBounds.left = va_arg( args, int);
321             clipBounds.bottom = va_arg( args, int);
322             clipBounds.right = va_arg( args, int);
323  
324             if( !p_vout->b_fullscreen )
325             {
326                 /*
327                 ** check that the clip rect is not empty, as this is used
328                 ** by Firefox to prevent a plugin from displaying during
329                 ** a scrolling event. In this case we just prevent buffers
330                 ** from being swapped and ignore clipping as this is less
331                 ** disruptive than a GL geometry change
332                 */
333
334                 p_vout->p_sys->b_clipped_out = (clipBounds.top == clipBounds.bottom)
335                                              || (clipBounds.left == clipBounds.right);
336                 if( ! p_vout->p_sys->b_clipped_out )
337                 {
338                     /* ignore consecutive viewport update with identical parameters */
339                     if( memcmp(&clipBounds, &(p_vout->p_sys->clipBounds), sizeof(clipBounds) )
340                      && memcmp(&viewBounds, &(p_vout->p_sys->viewBounds), sizeof(viewBounds)) )
341                     {
342                         aglLock( p_vout );
343                         aglSetViewport(p_vout, viewBounds, clipBounds);
344                         aglReshape( p_vout );
345                         aglUnlock( p_vout );
346                         p_vout->p_sys->clipBounds = clipBounds;
347                         p_vout->p_sys->viewBounds = viewBounds;
348                     }
349                 }
350             }
351             return VLC_SUCCESS;
352         }
353
354         case VOUT_REDRAW_RECT:
355         {
356             vout_thread_t * p_parent;
357             Rect areaBounds;
358
359             areaBounds.top = va_arg( args, int);
360             areaBounds.left = va_arg( args, int);
361             areaBounds.bottom = va_arg( args, int);
362             areaBounds.right = va_arg( args, int);
363
364             /* Ask the opengl module to redraw */
365             p_parent = (vout_thread_t *) p_vout->p_parent;
366             if( p_parent && p_parent->pf_display )
367             {
368                 p_parent->pf_display( p_parent, NULL );
369             }
370             return VLC_SUCCESS;
371         }
372
373         default:
374             return VLC_EGENERIC;
375     }
376 }
377
378 void aglSwap( vout_thread_t * p_vout )
379 {
380     if( ! p_vout->p_sys->b_clipped_out )
381     {
382         p_vout->p_sys->b_got_frame = true;
383         aglSwapBuffers(p_vout->p_sys->agl_ctx);
384     }
385     else
386     {
387         /* drop frame */
388         glFlush();
389     }
390 }
391
392 /* Enter this function with the p_vout locked */
393 static void aglSetViewport( vout_thread_t *p_vout, Rect viewBounds, Rect clipBounds )
394 {
395     // mozilla plugin provides coordinates based on port bounds
396     // however AGL coordinates are based on window structure region
397     // and are vertically flipped
398     GLint rect[4];
399     CGrafPtr port = (CGrafPtr)p_vout->p_sys->agl_drawable;
400     Rect winBounds, clientBounds;
401
402     GetWindowBounds(GetWindowFromPort(port),
403         kWindowStructureRgn, &winBounds);
404     GetWindowBounds(GetWindowFromPort(port),
405         kWindowContentRgn, &clientBounds);
406
407     /* update video clipping bounds in drawable */
408     rect[0] = (clientBounds.left-winBounds.left)
409             + clipBounds.left;                  // from window left edge
410     rect[1] = (winBounds.bottom-winBounds.top)
411             - (clientBounds.top-winBounds.top)
412             - clipBounds.bottom;                // from window bottom edge
413     rect[2] = clipBounds.right-clipBounds.left; // width
414     rect[3] = clipBounds.bottom-clipBounds.top; // height
415     aglSetInteger(p_vout->p_sys->agl_ctx, AGL_BUFFER_RECT, rect);
416     aglEnable(p_vout->p_sys->agl_ctx, AGL_BUFFER_RECT);
417
418     /* update video internal bounds in drawable */
419     p_vout->p_sys->i_width  = viewBounds.right-viewBounds.left;
420     p_vout->p_sys->i_height = viewBounds.bottom-viewBounds.top;
421     p_vout->p_sys->i_offx   = -clipBounds.left - viewBounds.left;
422     p_vout->p_sys->i_offy   = clipBounds.bottom + viewBounds.top
423                             - p_vout->p_sys->i_height;
424
425     aglUpdateContext(p_vout->p_sys->agl_ctx);
426 }
427
428 //default window event handler
429 static pascal OSStatus WindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
430 {
431     OSStatus result = noErr;
432     UInt32 class = GetEventClass (event);
433     UInt32 kind = GetEventKind (event);
434     vout_thread_t *p_vout = (vout_thread_t *)userData;
435
436     result = CallNextEventHandler(nextHandler, event);
437     if(class == kEventClassCommand)
438     {
439         HICommand theHICommand;
440         GetEventParameter( event, kEventParamDirectObject, typeHICommand, NULL, sizeof( HICommand ), NULL, &theHICommand );
441  
442         switch ( theHICommand.commandID )
443         {
444             default:
445                 result = eventNotHandledErr;
446         }
447     }
448     else if(class == kEventClassWindow)
449     {
450         WindowRef     window;
451         Rect          rectPort = {0,0,0,0};
452  
453         GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window);
454
455         if(window)
456         {
457             GetPortBounds(GetWindowPort(window), &rectPort);
458         }
459
460         switch (kind)
461         {
462             case kEventWindowClosed:
463             case kEventWindowZoomed:
464             case kEventWindowBoundsChanged:
465                 break;
466  
467             default:
468                 result = eventNotHandledErr;
469         }
470     }
471     else if(class == kEventClassMouse)
472     {
473         switch (kind)
474         {
475             case kEventMouseDown:
476             {
477                 UInt16     button;
478  
479                 GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(button), NULL, &button);
480                 switch (button)
481                 {
482                     case kEventMouseButtonPrimary:
483                     {
484                         vlc_value_t val;
485
486                         var_Get( p_vout, "mouse-button-down", &val );
487                         val.i_int |= 1;
488                         var_Set( p_vout, "mouse-button-down", val );
489                         break;
490                     }
491                     case kEventMouseButtonSecondary:
492                     {
493                         vlc_value_t val;
494
495                         var_Get( p_vout, "mouse-button-down", &val );
496                         val.i_int |= 2;
497                         var_Set( p_vout, "mouse-button-down", val );
498                         break;
499                     }
500                     case kEventMouseButtonTertiary:
501                     {
502                         vlc_value_t val;
503
504                         var_Get( p_vout, "mouse-button-down", &val );
505                         val.i_int |= 4;
506                         var_Set( p_vout, "mouse-button-down", val );
507                         break;
508                     }
509                     default:
510                         result = eventNotHandledErr;
511                 }
512                 break;
513             }
514
515             case kEventMouseUp:
516             {
517                 UInt16     button;
518  
519                 GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(button), NULL, &button);
520                 switch (button)
521                 {
522                     case kEventMouseButtonPrimary:
523                     {
524                         UInt32 clickCount = 0;
525                         GetEventParameter(event, kEventParamClickCount, typeUInt32, NULL, sizeof(clickCount), NULL, &clickCount);
526                         if( clickCount > 1 )
527                         {
528                             vlc_value_t val;
529
530                             val.b_bool = false;
531                             var_Set((vout_thread_t *) p_vout->p_parent, "fullscreen", val);
532                         }
533                         else
534                         {
535                             vlc_value_t val;
536
537                             var_SetBool( p_vout, "mouse-clicked", true );
538
539                             var_Get( p_vout, "mouse-button-down", &val );
540                             val.i_int &= ~1;
541                             var_Set( p_vout, "mouse-button-down", val );
542                         }
543                         break;
544                     }
545                     case kEventMouseButtonSecondary:
546                     {
547                         vlc_value_t val;
548
549                         var_Get( p_vout, "mouse-button-down", &val );
550                         val.i_int &= ~2;
551                         var_Set( p_vout, "mouse-button-down", val );
552                         break;
553                     }
554                     case kEventMouseButtonTertiary:
555                     {
556                         vlc_value_t val;
557
558                         var_Get( p_vout, "mouse-button-down", &val );
559                         val.i_int &= ~2;
560                         var_Set( p_vout, "mouse-button-down", val );
561                         break;
562                     }
563                     default:
564                         result = eventNotHandledErr;
565                 }
566                 break;
567             }
568
569             case kEventMouseMoved:
570             {
571                 Point ml;
572                 vlc_value_t val;
573
574                 unsigned int i_x, i_y;
575                 unsigned int i_height = p_vout->p_sys->i_height;
576                 unsigned int i_width  = p_vout->p_sys->i_width;
577
578                 vout_PlacePicture(p_vout, i_width, i_height, &i_x, &i_y, &i_width, &i_height);
579
580                 GetEventParameter(event, kEventParamWindowMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &ml);
581  
582                 val.i_int = ( ((int)ml.h) - i_x ) *
583                             p_vout->render.i_width / i_width;
584                 var_Set( p_vout, "mouse-x", val );
585
586                 val.i_int = ( ((int)ml.v) - i_y ) *
587                             p_vout->render.i_height / i_height;
588
589                 var_Set( p_vout, "mouse-y", val );
590
591                 val.b_bool = true;
592                 var_Set( p_vout, "mouse-moved", val );
593
594                 break;
595             }
596  
597             default:
598                 result = eventNotHandledErr;
599         }
600     }
601     else if(class == kEventClassTextInput)
602     {
603         switch (kind)
604         {
605             case kEventTextInputUnicodeForKeyEvent:
606             {
607                 break;
608             }
609             default:
610                 result = eventNotHandledErr;
611         }
612     }
613     else if(class == kEventClassVLCPlugin)
614     {
615         switch (kind)
616         {
617             case kEventVLCPluginShowFullscreen:
618                 ShowWindow (p_vout->p_sys->theWindow);
619                 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
620                 //CGDisplayHideCursor(kCGDirectMainDisplay);
621                 break;
622             case kEventVLCPluginHideFullscreen:
623                 HideWindow (p_vout->p_sys->theWindow);
624                 SetSystemUIMode( kUIModeNormal, 0);
625                 CGDisplayShowCursor(kCGDirectMainDisplay);
626                 break;
627             default:
628                 result = eventNotHandledErr;
629                 break;
630         }
631     }
632     return result;
633 }
634
635 int aglLock( vout_thread_t * p_vout )
636 {
637 #ifdef __ppc__
638     /*
639      * before 10.4, we set the AGL context as current and
640      * then we retrieve and use the matching CGL context
641      */
642     aglSetCurrentContext(p_vout->p_sys->agl_ctx);
643     return kCGLNoError != CGLLockContext( CGLGetCurrentContext() );
644 #else
645     /* since 10.4, this is the safe way to get the underlying CGL context */
646     CGLContextObj cglContext;
647     if( aglGetCGLContext(p_vout->p_sys->agl_ctx, (void**)&cglContext) )
648     {
649         if( kCGLNoError == CGLLockContext( cglContext ) )
650         {
651             aglSetCurrentContext(p_vout->p_sys->agl_ctx);
652             return 0;
653         }
654     }
655     return 1;
656 #endif
657 }
658
659 void aglUnlock( vout_thread_t * p_vout )
660 {
661 #ifdef __ppc__
662     /*
663      * before 10.4, we assume that the AGL context is current.
664      * therefore, we use the current CGL context
665      */
666     CGLUnlockContext( CGLGetCurrentContext() );
667 #else
668     /* since 10.4, this is the safe way to get the underlying CGL context */
669     CGLContextObj cglContext;
670     if( aglGetCGLContext(p_vout->p_sys->agl_ctx, (void**)&cglContext) )
671     {
672         CGLUnlockContext( cglContext );
673     }
674 #endif
675 }
676
677 #endif