1 /*****************************************************************************
2 * vout.m: MacOS X video output module
3 *****************************************************************************
4 * Copyright (C) 2001-2003 VideoLAN
5 * $Id: vout.m,v 1.85 2004/02/28 13:53:35 titer Exp $
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 <thedj@users.sourceforge.net>
11 * Eric Petit <titer@m0k.org>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
26 *****************************************************************************/
28 /*****************************************************************************
30 *****************************************************************************/
31 #include <errno.h> /* ENOMEM */
32 #include <stdlib.h> /* free() */
33 #include <string.h> /* strerror() */
35 #include <QuickTime/QuickTime.h>
37 #include <OpenGL/OpenGL.h>
38 #include <OpenGL/gl.h>
39 #include <OpenGL/glext.h>
46 #define QT_MAX_DIRECTBUFFERS 10
47 #define VL_MAX_DISPLAYS 16
49 #define OPENGL_EFFECT_NONE 1
50 #define OPENGL_EFFECT_CUBE 2
51 #define OPENGL_EFFECT_TRANSPARENT_CUBE 4
58 /* When using I420 output */
59 PlanarPixmapInfoYUV420 pixmap_i420;
62 /*****************************************************************************
64 *****************************************************************************/
66 static int vout_Init ( vout_thread_t * );
67 static void vout_End ( vout_thread_t * );
68 static int vout_Manage ( vout_thread_t * );
69 static void vout_Display ( vout_thread_t *, picture_t * );
71 static int CoSendRequest ( vout_thread_t *, SEL );
72 static int CoCreateWindow ( vout_thread_t * );
73 static int CoDestroyWindow ( vout_thread_t * );
74 static int CoToggleFullscreen ( vout_thread_t * );
76 static void VLCHideMouse ( vout_thread_t *, BOOL );
78 static void QTScaleMatrix ( vout_thread_t * );
79 static int QTCreateSequence ( vout_thread_t * );
80 static void QTDestroySequence ( vout_thread_t * );
81 static int QTNewPicture ( vout_thread_t *, picture_t * );
82 static void QTFreePicture ( vout_thread_t *, picture_t * );
84 /*****************************************************************************
85 * OpenVideo: allocates MacOS X video thread output method
86 *****************************************************************************
87 * This function allocates and initializes a MacOS X vout method.
88 *****************************************************************************/
89 int E_(OpenVideo) ( vlc_object_t *p_this )
91 vout_thread_t * p_vout = (vout_thread_t *)p_this;
95 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
96 if( p_vout->p_sys == NULL )
98 msg_Err( p_vout, "out of memory" );
102 memset( p_vout->p_sys, 0, sizeof( vout_sys_t ) );
104 /* Wait for a MacOS X interface to appear. Timeout is 2 seconds. */
105 for( i_timeout = 20 ; i_timeout-- ; )
109 msleep( INTF_IDLE_SLEEP );
115 /* no MacOS X intf, unable to communicate with MT */
116 msg_Err( p_vout, "no MacOS X interface present" );
117 free( p_vout->p_sys );
121 if( [NSApp respondsToSelector: @selector(getIntf)] )
123 intf_thread_t * p_intf;
125 for( i_timeout = 10 ; i_timeout-- ; )
127 if( ( p_intf = [NSApp getIntf] ) == NULL )
129 msleep( INTF_IDLE_SLEEP );
135 msg_Err( p_vout, "MacOS X intf has getIntf, but is NULL" );
136 free( p_vout->p_sys );
141 p_vout->p_sys->b_mouse_moved = VLC_TRUE;
142 p_vout->p_sys->i_time_mouse_last_moved = mdate();
144 /* set window size */
145 p_vout->p_sys->s_rect.size.width = p_vout->i_window_width;
146 p_vout->p_sys->s_rect.size.height = p_vout->i_window_height;
148 /* Check if we should use QuickTime or OpenGL */
149 p_vout->p_sys->i_opengl = config_GetInt( p_vout, "macosx-opengl" );
151 if( !p_vout->p_sys->i_opengl )
153 /* Initialize QuickTime */
154 p_vout->p_sys->h_img_descr =
155 (ImageDescriptionHandle)NewHandleClear( sizeof(ImageDescription) );
156 p_vout->p_sys->p_matrix =
157 (MatrixRecordPtr)malloc( sizeof(MatrixRecord) );
158 p_vout->p_sys->p_fullscreen_state = NULL;
160 if( ( err = EnterMovies() ) != noErr )
162 msg_Err( p_vout, "EnterMovies failed: %d", err );
163 free( p_vout->p_sys->p_matrix );
164 DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
165 free( p_vout->p_sys );
169 /* Damn QT isn't thread safe. so keep a lock in the p_vlc object */
170 vlc_mutex_lock( &p_vout->p_vlc->quicktime_lock );
172 err = FindCodec( kYUV420CodecType, bestSpeedCodec,
173 nil, &p_vout->p_sys->img_dc );
175 vlc_mutex_unlock( &p_vout->p_vlc->quicktime_lock );
176 if( err == noErr && p_vout->p_sys->img_dc != 0 )
178 p_vout->output.i_chroma = VLC_FOURCC('I','4','2','0');
179 p_vout->p_sys->i_codec = kYUV420CodecType;
183 msg_Err( p_vout, "failed to find an appropriate codec" );
186 if( p_vout->p_sys->img_dc == 0 )
188 free( p_vout->p_sys->p_matrix );
189 DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
190 free( p_vout->p_sys );
195 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
196 NSArray * o_screens = [NSScreen screens];
197 if( [o_screens count] > 0 && var_Type( p_vout, "video-device" ) == 0 )
200 vlc_value_t val, text;
203 int i_option = config_GetInt( p_vout, "macosx-vdev" );
205 var_Create( p_vout, "video-device", VLC_VAR_INTEGER |
207 text.psz_string = _("Video device");
208 var_Change( p_vout, "video-device", VLC_VAR_SETTEXT, &text, NULL );
210 NSEnumerator * o_enumerator = [o_screens objectEnumerator];
212 while( (o_screen = [o_enumerator nextObject]) != NULL )
215 NSRect s_rect = [o_screen frame];
217 snprintf( psz_temp, sizeof(psz_temp)/sizeof(psz_temp[0])-1,
218 "%s %d (%dx%d)", _("Screen"), i,
219 (int)s_rect.size.width, (int)s_rect.size.height );
221 text.psz_string = psz_temp;
223 var_Change( p_vout, "video-device",
224 VLC_VAR_ADDCHOICE, &val, &text );
226 if( ( i - 1 ) == i_option )
228 var_Set( p_vout, "video-device", val );
233 var_AddCallback( p_vout, "video-device", vout_VarCallback,
236 val.b_bool = VLC_TRUE;
237 var_Set( p_vout, "intf-change", val );
241 if( CoCreateWindow( p_vout ) )
243 msg_Err( p_vout, "unable to create window" );
244 if( !p_vout->p_sys->i_opengl )
246 free( p_vout->p_sys->p_matrix );
247 DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
249 free( p_vout->p_sys );
253 p_vout->pf_init = vout_Init;
254 p_vout->pf_end = vout_End;
255 p_vout->pf_manage = vout_Manage;
256 p_vout->pf_render = NULL;
257 p_vout->pf_display = vout_Display;
262 /*****************************************************************************
263 * vout_Init: initialize video thread output method
264 *****************************************************************************/
265 static int vout_Init( vout_thread_t *p_vout )
270 I_OUTPUTPICTURES = 0;
272 /* Initialize the output structure; we already found a codec,
273 * and the corresponding chroma we will be using. Since we can
274 * arbitrary scale, stick to the coordinates and aspect. */
275 p_vout->output.i_width = p_vout->render.i_width;
276 p_vout->output.i_height = p_vout->render.i_height;
277 p_vout->output.i_aspect = p_vout->render.i_aspect;
279 if( !p_vout->p_sys->i_opengl )
281 SetPort( p_vout->p_sys->p_qdport );
282 QTScaleMatrix( p_vout );
284 if( QTCreateSequence( p_vout ) )
286 msg_Err( p_vout, "unable to create sequence" );
292 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
293 p_vout->output.i_rmask = 0xFF0000;
294 p_vout->output.i_gmask = 0x00FF00;
295 p_vout->output.i_bmask = 0x0000FF;
298 /* Try to initialize up to QT_MAX_DIRECTBUFFERS direct buffers */
299 while( I_OUTPUTPICTURES <
300 p_vout->p_sys->i_opengl ? 1 : QT_MAX_DIRECTBUFFERS )
304 /* Find an empty picture slot */
305 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
307 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
309 p_pic = p_vout->p_picture + i_index;
314 /* Allocate the picture */
320 if( !p_vout->p_sys->i_opengl )
322 if( QTNewPicture( p_vout, p_pic ) )
329 /* Nothing special to do, we just need a basic allocated
331 vout_AllocatePicture( VLC_OBJECT( p_vout ), p_pic,
332 p_vout->output.i_chroma, p_vout->output.i_width,
333 p_vout->output.i_height, p_vout->output.i_aspect );
336 p_pic->i_status = DESTROYED_PICTURE;
337 p_pic->i_type = DIRECT_PICTURE;
339 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
344 if( p_vout->p_sys->i_opengl )
346 [p_vout->p_sys->o_glview lockFocus];
347 [p_vout->p_sys->o_glview initTextures];
348 [p_vout->p_sys->o_glview reshape];
349 [p_vout->p_sys->o_glview unlockFocus];
355 /*****************************************************************************
356 * vout_End: terminate video thread output method
357 *****************************************************************************/
358 static void vout_End( vout_thread_t *p_vout )
362 if( !p_vout->p_sys->i_opengl )
364 QTDestroySequence( p_vout );
368 [p_vout->p_sys->o_glview cleanUp];
371 /* Free the direct buffers we allocated */
372 for( i_index = I_OUTPUTPICTURES; i_index; )
375 if( !p_vout->p_sys->i_opengl )
377 QTFreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );
381 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
386 /*****************************************************************************
387 * CloseVideo: destroy video thread output method
388 *****************************************************************************/
389 void E_(CloseVideo) ( vlc_object_t *p_this )
391 vout_thread_t * p_vout = (vout_thread_t *)p_this;
393 if( CoDestroyWindow( p_vout ) )
395 msg_Err( p_vout, "unable to destroy window" );
398 if( !p_vout->p_sys->i_opengl )
400 if ( p_vout->p_sys->p_fullscreen_state != NULL )
401 EndFullScreen ( p_vout->p_sys->p_fullscreen_state, NULL );
405 free( p_vout->p_sys->p_matrix );
406 DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
409 free( p_vout->p_sys );
412 /*****************************************************************************
413 * vout_Manage: handle events
414 *****************************************************************************
415 * This function should be called regularly by video output thread. It manages
416 * console events. It returns a non null value on error.
417 *****************************************************************************/
418 static int vout_Manage( vout_thread_t *p_vout )
420 if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
422 if( CoToggleFullscreen( p_vout ) )
427 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
430 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
432 if( !p_vout->p_sys->i_opengl )
434 QTScaleMatrix( p_vout );
435 SetDSequenceMatrix( p_vout->p_sys->i_seq,
436 p_vout->p_sys->p_matrix );
439 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
442 /* hide/show mouse cursor
443 * this code looks unnecessarily complicated, but is necessary like this.
444 * it has to deal with multiple monitors and therefore checks a lot */
445 if( !p_vout->p_sys->b_mouse_moved && p_vout->b_fullscreen )
447 if( mdate() - p_vout->p_sys->i_time_mouse_last_moved > 3000000 )
449 VLCHideMouse( p_vout, YES );
452 else if ( p_vout->p_sys->b_mouse_moved && p_vout->b_fullscreen )
454 VLCHideMouse( p_vout, NO );
457 /* disable screen saver */
458 UpdateSystemActivity( UsrActivity );
463 /*****************************************************************************
464 * vout_Display: displays previously rendered output
465 *****************************************************************************
466 * This function sends the currently rendered image to the display.
467 *****************************************************************************/
468 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
470 if( !p_vout->p_sys->i_opengl )
475 if( ( err = DecompressSequenceFrameS(
476 p_vout->p_sys->i_seq,
477 p_pic->p_sys->p_info,
478 p_pic->p_sys->i_size,
479 codecFlagUseImageBuffer, &flags, nil ) != noErr ) )
481 msg_Warn( p_vout, "DecompressSequenceFrameS failed: %d", err );
485 QDFlushPortBuffer( p_vout->p_sys->p_qdport, nil );
490 if( [p_vout->p_sys->o_glview lockFocusIfCanDraw] )
492 /* Texture gotta be reload before the buffer is filled
493 (thanks to gcc from arstechnica forums) */
494 [p_vout->p_sys->o_glview drawRect:
495 [p_vout->p_sys->o_glview bounds]];
496 [p_vout->p_sys->o_glview reloadTexture];
497 [p_vout->p_sys->o_glview unlockFocus];
502 /*****************************************************************************
503 * CoSendRequest: send request to interface thread
504 *****************************************************************************
505 * Returns 0 on success, 1 otherwise
506 *****************************************************************************/
507 static int CoSendRequest( vout_thread_t *p_vout, SEL sel )
511 intf_thread_t * p_intf;
513 VLCVout * o_vlv = [[VLCVout alloc] init];
515 if( ( i_ret = ExecuteOnMainThread( o_vlv, sel, (void *)p_vout ) ) )
517 msg_Err( p_vout, "SendRequest: no way to communicate with mt" );
522 /*This makes this function dependant of the presence of a macosx
523 interface. We do not check if this interface exists, since it has
524 already been done before.*/
526 p_intf = [NSApp getIntf];
528 val.b_bool = VLC_TRUE;
529 var_Create(p_intf,"intf-change",VLC_VAR_BOOL);
530 var_Set(p_intf, "intf-change",val);
535 /*****************************************************************************
536 * CoCreateWindow: create new window
537 *****************************************************************************
538 * Returns 0 on success, 1 otherwise
539 *****************************************************************************/
540 static int CoCreateWindow( vout_thread_t *p_vout )
542 if( CoSendRequest( p_vout, @selector(createWindow:) ) )
544 msg_Err( p_vout, "CoSendRequest (createWindow) failed" );
551 /*****************************************************************************
552 * CoDestroyWindow: destroy window
553 *****************************************************************************
554 * Returns 0 on success, 1 otherwise
555 *****************************************************************************/
556 static int CoDestroyWindow( vout_thread_t *p_vout )
559 VLCHideMouse( p_vout, NO );
561 if( CoSendRequest( p_vout, @selector(destroyWindow:) ) )
563 msg_Err( p_vout, "CoSendRequest (destroyWindow) failed" );
570 /*****************************************************************************
571 * CoToggleFullscreen: toggle fullscreen
572 *****************************************************************************
573 * Returns 0 on success, 1 otherwise
574 *****************************************************************************/
575 static int CoToggleFullscreen( vout_thread_t *p_vout )
577 if( p_vout->p_sys->i_opengl )
579 p_vout->b_fullscreen = !p_vout->b_fullscreen;
580 if( p_vout->b_fullscreen )
582 [p_vout->p_sys->o_glview goFullScreen];
586 [p_vout->p_sys->o_glview exitFullScreen];
591 QTDestroySequence( p_vout );
593 if( CoDestroyWindow( p_vout ) )
595 msg_Err( p_vout, "unable to destroy window" );
599 p_vout->b_fullscreen = !p_vout->b_fullscreen;
601 if( CoCreateWindow( p_vout ) )
603 msg_Err( p_vout, "unable to create window" );
607 SetPort( p_vout->p_sys->p_qdport );
608 QTScaleMatrix( p_vout );
610 if( QTCreateSequence( p_vout ) )
612 msg_Err( p_vout, "unable to create sequence" );
619 /*****************************************************************************
620 * VLCHideMouse: if b_hide then hide the cursor
621 *****************************************************************************/
622 static void VLCHideMouse ( vout_thread_t *p_vout, BOOL b_hide )
627 NSWindow *o_window = p_vout->p_sys->o_window;
628 NSView *o_contents = [o_window contentView];
630 s_rect = [o_contents bounds];
631 ml = [o_window convertScreenToBase:[NSEvent mouseLocation]];
632 ml = [o_contents convertPoint:ml fromView:nil];
633 b_inside = [o_contents mouse: ml inRect: s_rect];
635 if ( b_hide && b_inside )
637 /* only hide if mouse over VLCQTView */
638 [NSCursor setHiddenUntilMouseMoves: YES];
642 [NSCursor setHiddenUntilMouseMoves: NO];
644 p_vout->p_sys->b_mouse_moved = NO;
645 p_vout->p_sys->i_time_mouse_last_moved = mdate();
649 /*****************************************************************************
650 * QTScaleMatrix: scale matrix
651 *****************************************************************************/
652 static void QTScaleMatrix( vout_thread_t *p_vout )
655 unsigned int i_width, i_height;
656 Fixed factor_x, factor_y;
657 unsigned int i_offset_x = 0;
658 unsigned int i_offset_y = 0;
660 GetPortBounds( p_vout->p_sys->p_qdport, &s_rect );
662 i_width = s_rect.right - s_rect.left;
663 i_height = s_rect.bottom - s_rect.top;
665 if( config_GetInt( p_vout, "macosx-stretch" ) )
667 factor_x = FixDiv( Long2Fix( i_width ),
668 Long2Fix( p_vout->output.i_width ) );
669 factor_y = FixDiv( Long2Fix( i_height ),
670 Long2Fix( p_vout->output.i_height ) );
673 else if( i_height * p_vout->output.i_aspect < i_width * VOUT_ASPECT_FACTOR )
675 int i_adj_width = i_height * p_vout->output.i_aspect /
678 factor_x = FixDiv( Long2Fix( i_adj_width ),
679 Long2Fix( p_vout->output.i_width ) );
680 factor_y = FixDiv( Long2Fix( i_height ),
681 Long2Fix( p_vout->output.i_height ) );
683 i_offset_x = (i_width - i_adj_width) / 2;
687 int i_adj_height = i_width * VOUT_ASPECT_FACTOR /
688 p_vout->output.i_aspect;
690 factor_x = FixDiv( Long2Fix( i_width ),
691 Long2Fix( p_vout->output.i_width ) );
692 factor_y = FixDiv( Long2Fix( i_adj_height ),
693 Long2Fix( p_vout->output.i_height ) );
695 i_offset_y = (i_height - i_adj_height) / 2;
698 SetIdentityMatrix( p_vout->p_sys->p_matrix );
700 ScaleMatrix( p_vout->p_sys->p_matrix,
702 Long2Fix(0), Long2Fix(0) );
704 TranslateMatrix( p_vout->p_sys->p_matrix,
705 Long2Fix(i_offset_x), Long2Fix(i_offset_y) );
708 /*****************************************************************************
709 * QTCreateSequence: create a new sequence
710 *****************************************************************************
711 * Returns 0 on success, 1 otherwise
712 *****************************************************************************/
713 static int QTCreateSequence( vout_thread_t *p_vout )
716 ImageDescriptionPtr p_descr;
718 HLock( (Handle)p_vout->p_sys->h_img_descr );
719 p_descr = *p_vout->p_sys->h_img_descr;
721 p_descr->idSize = sizeof(ImageDescription);
722 p_descr->cType = p_vout->p_sys->i_codec;
723 p_descr->version = 1;
724 p_descr->revisionLevel = 0;
725 p_descr->vendor = 'appl';
726 p_descr->width = p_vout->output.i_width;
727 p_descr->height = p_vout->output.i_height;
728 p_descr->hRes = Long2Fix(72);
729 p_descr->vRes = Long2Fix(72);
730 p_descr->spatialQuality = codecLosslessQuality;
731 p_descr->frameCount = 1;
732 p_descr->clutID = -1;
733 p_descr->dataSize = 0;
736 HUnlock( (Handle)p_vout->p_sys->h_img_descr );
738 if( ( err = DecompressSequenceBeginS(
739 &p_vout->p_sys->i_seq,
740 p_vout->p_sys->h_img_descr,
742 p_vout->p_sys->p_qdport,
744 p_vout->p_sys->p_matrix,
746 codecFlagUseImageBuffer,
747 codecLosslessQuality,
748 p_vout->p_sys->img_dc ) ) )
750 msg_Err( p_vout, "DecompressSequenceBeginS failed: %d", err );
757 /*****************************************************************************
758 * QTDestroySequence: destroy sequence
759 *****************************************************************************/
760 static void QTDestroySequence( vout_thread_t *p_vout )
762 CDSequenceEnd( p_vout->p_sys->i_seq );
765 /*****************************************************************************
766 * QTNewPicture: allocate a picture
767 *****************************************************************************
768 * Returns 0 on success, 1 otherwise
769 *****************************************************************************/
770 static int QTNewPicture( vout_thread_t *p_vout, picture_t *p_pic )
772 int i_width = p_vout->output.i_width;
773 int i_height = p_vout->output.i_height;
775 /* We know the chroma, allocate a buffer which will be used
776 * directly by the decoder */
777 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
779 if( p_pic->p_sys == NULL )
784 switch( p_vout->output.i_chroma )
786 case VLC_FOURCC('I','4','2','0'):
788 p_pic->p_sys->p_info = (void *)&p_pic->p_sys->pixmap_i420;
789 p_pic->p_sys->i_size = sizeof(PlanarPixmapInfoYUV420);
791 /* Allocate the memory buffer */
792 p_pic->p_data = vlc_memalign( &p_pic->p_data_orig,
793 16, i_width * i_height * 3 / 2 );
796 p_pic->Y_PIXELS = p_pic->p_data;
797 p_pic->p[Y_PLANE].i_lines = i_height;
798 p_pic->p[Y_PLANE].i_pitch = i_width;
799 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
800 p_pic->p[Y_PLANE].i_visible_pitch = i_width;
803 p_pic->U_PIXELS = p_pic->Y_PIXELS + i_height * i_width;
804 p_pic->p[U_PLANE].i_lines = i_height / 2;
805 p_pic->p[U_PLANE].i_pitch = i_width / 2;
806 p_pic->p[U_PLANE].i_pixel_pitch = 1;
807 p_pic->p[U_PLANE].i_visible_pitch = i_width / 2;
810 p_pic->V_PIXELS = p_pic->U_PIXELS + i_height * i_width / 4;
811 p_pic->p[V_PLANE].i_lines = i_height / 2;
812 p_pic->p[V_PLANE].i_pitch = i_width / 2;
813 p_pic->p[V_PLANE].i_pixel_pitch = 1;
814 p_pic->p[V_PLANE].i_visible_pitch = i_width / 2;
816 /* We allocated 3 planes */
819 #define P p_pic->p_sys->pixmap_i420
820 P.componentInfoY.offset = (void *)p_pic->Y_PIXELS
821 - p_pic->p_sys->p_info;
822 P.componentInfoCb.offset = (void *)p_pic->U_PIXELS
823 - p_pic->p_sys->p_info;
824 P.componentInfoCr.offset = (void *)p_pic->V_PIXELS
825 - p_pic->p_sys->p_info;
827 P.componentInfoY.rowBytes = i_width;
828 P.componentInfoCb.rowBytes = i_width / 2;
829 P.componentInfoCr.rowBytes = i_width / 2;
835 /* Unknown chroma, tell the guy to get lost */
836 free( p_pic->p_sys );
837 msg_Err( p_vout, "never heard of chroma 0x%.8x (%4.4s)",
838 p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma );
846 /*****************************************************************************
847 * QTFreePicture: destroy a picture allocated with QTNewPicture
848 *****************************************************************************/
849 static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
851 switch( p_vout->output.i_chroma )
853 case VLC_FOURCC('I','4','2','0'):
854 free( p_pic->p_data_orig );
858 free( p_pic->p_sys );
861 /*****************************************************************************
862 * VLCWindow implementation
863 *****************************************************************************/
864 @implementation VLCWindow
866 - (void)setVout:(vout_thread_t *)_p_vout
871 - (vout_thread_t *)getVout
876 - (void)scaleWindowWithFactor: (float)factor
879 int i_corrected_height, i_corrected_width;
881 NSPoint topleftscreen;
883 if ( !p_vout->b_fullscreen )
886 topleftbase.y = [self frame].size.height;
887 topleftscreen = [self convertBaseToScreen: topleftbase];
889 if( p_vout->output.i_height * p_vout->output.i_aspect >
890 p_vout->output.i_width * VOUT_ASPECT_FACTOR )
892 i_corrected_width = p_vout->output.i_height * p_vout->output.i_aspect /
894 newsize.width = (int) ( i_corrected_width * factor );
895 newsize.height = (int) ( p_vout->render.i_height * factor );
899 i_corrected_height = p_vout->output.i_width * VOUT_ASPECT_FACTOR /
900 p_vout->output.i_aspect;
901 newsize.width = (int) ( p_vout->render.i_width * factor );
902 newsize.height = (int) ( i_corrected_height * factor );
905 [self setContentSize: newsize];
907 [self setFrameTopLeftPoint: topleftscreen];
908 p_vout->i_changes |= VOUT_SIZE_CHANGE;
912 - (void)toggleFloatOnTop
914 if( config_GetInt( p_vout, "video-on-top" ) )
916 config_PutInt( p_vout, "video-on-top", 0 );
917 [p_vout->p_sys->o_window setLevel: NSNormalWindowLevel];
921 config_PutInt( p_vout, "video-on-top", 1 );
922 [p_vout->p_sys->o_window setLevel: NSStatusWindowLevel];
926 - (void)toggleFullscreen
928 config_PutInt(p_vout, "fullscreen", !p_vout->b_fullscreen);
929 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
934 return( p_vout->b_fullscreen );
937 - (BOOL)canBecomeKeyWindow
942 - (void)keyDown:(NSEvent *)o_event
946 unsigned int i_pressed_modifiers = 0;
949 i_pressed_modifiers = [o_event modifierFlags];
951 if( i_pressed_modifiers & NSShiftKeyMask )
952 val.i_int |= KEY_MODIFIER_SHIFT;
953 if( i_pressed_modifiers & NSControlKeyMask )
954 val.i_int |= KEY_MODIFIER_CTRL;
955 if( i_pressed_modifiers & NSAlternateKeyMask )
956 val.i_int |= KEY_MODIFIER_ALT;
957 if( i_pressed_modifiers & NSCommandKeyMask )
958 val.i_int |= KEY_MODIFIER_COMMAND;
960 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
964 /* Escape should always get you out of fullscreen */
965 if( key == (unichar) 0x1b )
967 if( [self isFullscreen] )
969 [self toggleFullscreen];
972 else if ( key == ' ' )
974 playlist_t *p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
976 if ( p_playlist != NULL )
978 playlist_Pause( p_playlist );
979 vlc_object_release( p_playlist);
984 val.i_int |= CocoaKeyToVLC( key );
985 var_Set( p_vout->p_vlc, "key-pressed", val );
990 [super keyDown: o_event];
996 NSMutableString * o_title;
997 playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
1000 if( p_playlist == NULL )
1005 vlc_mutex_lock( &p_playlist->object_lock );
1006 o_title = [NSMutableString stringWithUTF8String:
1007 p_playlist->pp_items[p_playlist->i_index]->psz_uri];
1008 vlc_mutex_unlock( &p_playlist->object_lock );
1010 vlc_object_release( p_playlist );
1012 if( o_title != nil )
1014 NSRange prefix_range = [o_title rangeOfString: @"file:"];
1015 if( prefix_range.location != NSNotFound )
1017 [o_title deleteCharactersInRange: prefix_range];
1020 [self setTitleWithRepresentedFilename: o_title];
1025 [NSString stringWithCString: VOUT_TITLE " (QuickTime)"]];
1029 /* This is actually the same as VLCControls::stop. */
1030 - (BOOL)windowShouldClose:(id)sender
1032 playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
1034 if( p_playlist == NULL )
1039 playlist_Stop( p_playlist );
1040 vlc_object_release( p_playlist );
1042 /* The window will be closed by the intf later. */
1048 /*****************************************************************************
1049 * VLCQTView implementation
1050 *****************************************************************************/
1051 @implementation VLCQTView
1053 - (void)drawRect:(NSRect)rect
1055 vout_thread_t * p_vout;
1056 id o_window = [self window];
1057 p_vout = (vout_thread_t *)[o_window getVout];
1059 [[NSColor blackColor] set];
1061 [super drawRect: rect];
1063 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1066 - (BOOL)acceptsFirstResponder
1071 - (BOOL)becomeFirstResponder
1073 vout_thread_t * p_vout;
1074 id o_window = [self window];
1075 p_vout = (vout_thread_t *)[o_window getVout];
1077 [o_window setAcceptsMouseMovedEvents: YES];
1081 - (BOOL)resignFirstResponder
1083 vout_thread_t * p_vout;
1084 id o_window = [self window];
1085 p_vout = (vout_thread_t *)[o_window getVout];
1087 [o_window setAcceptsMouseMovedEvents: NO];
1088 VLCHideMouse( p_vout, NO );
1092 - (void)mouseDown:(NSEvent *)o_event
1094 vout_thread_t * p_vout;
1095 id o_window = [self window];
1096 p_vout = (vout_thread_t *)[o_window getVout];
1099 switch( [o_event type] )
1101 case NSLeftMouseDown:
1103 var_Get( p_vout, "mouse-button-down", &val );
1105 var_Set( p_vout, "mouse-button-down", val );
1110 [super mouseDown: o_event];
1115 - (void)otherMouseDown:(NSEvent *)o_event
1117 /* This is not the the wheel button. you need to poll the
1118 * mouseWheel event for that. other is a third, forth or fifth button */
1119 vout_thread_t * p_vout;
1120 id o_window = [self window];
1121 p_vout = (vout_thread_t *)[o_window getVout];
1124 switch( [o_event type] )
1126 case NSOtherMouseDown:
1128 var_Get( p_vout, "mouse-button-down", &val );
1130 var_Set( p_vout, "mouse-button-down", val );
1135 [super mouseDown: o_event];
1140 - (void)rightMouseDown:(NSEvent *)o_event
1142 vout_thread_t * p_vout;
1143 id o_window = [self window];
1144 p_vout = (vout_thread_t *)[o_window getVout];
1147 switch( [o_event type] )
1149 case NSRightMouseDown:
1151 var_Get( p_vout, "mouse-button-down", &val );
1153 var_Set( p_vout, "mouse-button-down", val );
1158 [super mouseDown: o_event];
1163 - (void)mouseUp:(NSEvent *)o_event
1165 vout_thread_t * p_vout;
1166 id o_window = [self window];
1167 p_vout = (vout_thread_t *)[o_window getVout];
1170 switch( [o_event type] )
1175 b_val.b_bool = VLC_TRUE;
1176 var_Set( p_vout, "mouse-clicked", b_val );
1178 var_Get( p_vout, "mouse-button-down", &val );
1180 var_Set( p_vout, "mouse-button-down", val );
1185 [super mouseUp: o_event];
1190 - (void)otherMouseUp:(NSEvent *)o_event
1192 vout_thread_t * p_vout;
1193 id o_window = [self window];
1194 p_vout = (vout_thread_t *)[o_window getVout];
1197 switch( [o_event type] )
1199 case NSOtherMouseUp:
1201 var_Get( p_vout, "mouse-button-down", &val );
1203 var_Set( p_vout, "mouse-button-down", val );
1208 [super mouseUp: o_event];
1213 - (void)rightMouseUp:(NSEvent *)o_event
1215 vout_thread_t * p_vout;
1216 id o_window = [self window];
1217 p_vout = (vout_thread_t *)[o_window getVout];
1220 switch( [o_event type] )
1222 case NSRightMouseUp:
1224 var_Get( p_vout, "mouse-button-down", &val );
1226 var_Set( p_vout, "mouse-button-down", val );
1231 [super mouseUp: o_event];
1236 - (void)mouseDragged:(NSEvent *)o_event
1238 [self mouseMoved:o_event];
1241 - (void)otherMouseDragged:(NSEvent *)o_event
1243 [self mouseMoved:o_event];
1246 - (void)rightMouseDragged:(NSEvent *)o_event
1248 [self mouseMoved:o_event];
1251 - (void)mouseMoved:(NSEvent *)o_event
1257 vout_thread_t * p_vout;
1258 id o_window = [self window];
1259 p_vout = (vout_thread_t *)[o_window getVout];
1261 s_rect = [self bounds];
1262 ml = [self convertPoint: [o_event locationInWindow] fromView: nil];
1263 b_inside = [self mouse: ml inRect: s_rect];
1268 int i_width, i_height, i_x, i_y;
1270 vout_PlacePicture( p_vout, (unsigned int)s_rect.size.width,
1271 (unsigned int)s_rect.size.height,
1272 &i_x, &i_y, &i_width, &i_height );
1274 val.i_int = ( ((int)ml.x) - i_x ) *
1275 p_vout->render.i_width / i_width;
1276 var_Set( p_vout, "mouse-x", val );
1278 val.i_int = ( ((int)ml.y) - i_y ) *
1279 p_vout->render.i_height / i_height;
1280 var_Set( p_vout, "mouse-y", val );
1282 val.b_bool = VLC_TRUE;
1283 var_Set( p_vout, "mouse-moved", val );
1284 p_vout->p_sys->i_time_mouse_last_moved = mdate();
1285 p_vout->p_sys->b_mouse_moved = YES;
1288 [super mouseMoved: o_event];
1293 /*****************************************************************************
1294 * VLCGLView implementation
1295 *****************************************************************************/
1296 @implementation VLCGLView
1299 - (id) initWithFrame: (NSRect) frame vout: (vout_thread_t*) _p_vout
1304 NSOpenGLPixelFormatAttribute attribs[] =
1306 NSOpenGLPFAAccelerated,
1307 NSOpenGLPFANoRecovery,
1308 NSOpenGLPFADoubleBuffer,
1309 NSOpenGLPFAColorSize, 24,
1310 NSOpenGLPFAAlphaSize, 8,
1311 NSOpenGLPFADepthSize, 24,
1316 NSOpenGLPixelFormat * fmt = [[NSOpenGLPixelFormat alloc]
1317 initWithAttributes: attribs];
1321 msg_Warn( p_vout, "Cannot create NSOpenGLPixelFormat" );
1325 self = [super initWithFrame:frame pixelFormat: fmt];
1327 currentContext = [self openGLContext];
1328 [currentContext makeCurrentContext];
1329 [currentContext update];
1331 /* Black background */
1332 glClearColor( 0.0, 0.0, 0.0, 0.0 );
1334 /* Check if the user asked for useless visual effects */
1335 psz_effect = config_GetPsz( p_vout, "macosx-opengl-effect" );
1336 if( !strcmp( psz_effect, "none" ) )
1338 i_effect = OPENGL_EFFECT_NONE;
1340 else if( !strcmp( psz_effect, "cube" ) )
1342 i_effect = OPENGL_EFFECT_CUBE;
1344 glEnable( GL_DEPTH_TEST );
1346 else if( !strcmp( psz_effect, "transparent-cube" ) )
1348 i_effect = OPENGL_EFFECT_TRANSPARENT_CUBE;
1350 glDisable( GL_DEPTH_TEST );
1351 glEnable( GL_BLEND );
1352 glBlendFunc( GL_SRC_ALPHA, GL_ONE );
1356 msg_Warn( p_vout, "no valid opengl effect provided, using "
1358 i_effect = OPENGL_EFFECT_NONE;
1361 if( i_effect & ( OPENGL_EFFECT_CUBE |
1362 OPENGL_EFFECT_TRANSPARENT_CUBE ) )
1364 /* Set the perpective */
1365 glMatrixMode( GL_PROJECTION );
1367 glFrustum( -1.0, 1.0, -1.0, 1.0, 3.0, 20.0 );
1368 glMatrixMode( GL_MODELVIEW );
1370 glTranslatef( 0.0, 0.0, - 5.0 );
1387 [currentContext makeCurrentContext];
1389 NSRect bounds = [self bounds];
1390 glViewport( 0, 0, (GLint) bounds.size.width,
1391 (GLint) bounds.size.height );
1393 /* Quad size is set in order to preserve the aspect ratio */
1394 if( config_GetInt( p_vout, "macosx-stretch" ) )
1399 else if( bounds.size.height * p_vout->output.i_aspect <
1400 bounds.size.width * VOUT_ASPECT_FACTOR )
1402 f_x = bounds.size.height * p_vout->output.i_aspect /
1403 VOUT_ASPECT_FACTOR / bounds.size.width;
1409 f_y = bounds.size.width * VOUT_ASPECT_FACTOR /
1410 p_vout->output.i_aspect / bounds.size.height;
1414 - (void) initTextures
1416 [currentContext makeCurrentContext];
1418 /* Free previous texture if any */
1421 glDeleteTextures( 1, &i_texture );
1424 /* Create textures */
1425 glGenTextures( 1, &i_texture );
1427 glEnable( GL_TEXTURE_RECTANGLE_EXT );
1428 glEnable( GL_UNPACK_CLIENT_STORAGE_APPLE );
1430 glBindTexture( GL_TEXTURE_RECTANGLE_EXT, i_texture );
1432 /* Use VRAM texturing */
1433 glTexParameteri( GL_TEXTURE_RECTANGLE_EXT,
1434 GL_TEXTURE_STORAGE_HINT_APPLE, GL_STORAGE_CACHED_APPLE );
1436 /* Tell the driver not to make a copy of the texture but to use
1438 glPixelStorei( GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE );
1440 /* Linear interpolation */
1441 glTexParameteri( GL_TEXTURE_RECTANGLE_EXT,
1442 GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1443 glTexParameteri( GL_TEXTURE_RECTANGLE_EXT,
1444 GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1446 /* I have no idea what this exactly does, but it seems to be
1447 necessary for scaling */
1448 glTexParameteri( GL_TEXTURE_RECTANGLE_EXT,
1449 GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1450 glTexParameteri( GL_TEXTURE_RECTANGLE_EXT,
1451 GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1452 glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
1454 glTexImage2D( GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA,
1455 p_vout->output.i_width, p_vout->output.i_height, 0,
1456 GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE,
1457 PP_OUTPUTPICTURE[0]->p_data );
1462 - (void) reloadTexture
1469 [currentContext makeCurrentContext];
1471 glBindTexture( GL_TEXTURE_RECTANGLE_EXT, i_texture );
1473 /* glTexSubImage2D is faster than glTexImage2D
1474 http://developer.apple.com/samplecode/Sample_Code/Graphics_3D/
1475 TextureRange/MainOpenGLView.m.htm */
1476 glTexSubImage2D( GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0,
1477 p_vout->output.i_width, p_vout->output.i_height,
1478 GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE,
1479 PP_OUTPUTPICTURE[0]->p_data );
1482 - (void) goFullScreen
1484 /* Create the new pixel format */
1485 NSOpenGLPixelFormatAttribute attribs[] =
1487 NSOpenGLPFAAccelerated,
1488 NSOpenGLPFANoRecovery,
1489 NSOpenGLPFADoubleBuffer,
1490 NSOpenGLPFAColorSize, 24,
1491 NSOpenGLPFAAlphaSize, 8,
1492 NSOpenGLPFADepthSize, 24,
1493 NSOpenGLPFAFullScreen,
1494 NSOpenGLPFAScreenMask,
1495 /* TODO handle macosxx-vdev */
1496 CGDisplayIDToOpenGLDisplayMask( kCGDirectMainDisplay ),
1499 NSOpenGLPixelFormat * fmt = [[NSOpenGLPixelFormat alloc]
1500 initWithAttributes: attribs];
1503 msg_Warn( p_vout, "Cannot create NSOpenGLPixelFormat" );
1507 /* Create the new OpenGL context */
1508 fullScreenContext = [[NSOpenGLContext alloc]
1509 initWithFormat: fmt shareContext: nil];
1510 if( !fullScreenContext )
1512 msg_Warn( p_vout, "Failed to create new NSOpenGLContext" );
1515 currentContext = fullScreenContext;
1517 /* Capture display, switch to fullscreen */
1518 if( CGCaptureAllDisplays() != CGDisplayNoErr )
1520 msg_Warn( p_vout, "CGCaptureAllDisplays() failed" );
1523 [fullScreenContext setFullScreen];
1524 [fullScreenContext makeCurrentContext];
1527 unsigned width = CGDisplayPixelsWide( kCGDirectMainDisplay );
1528 unsigned height = CGDisplayPixelsHigh( kCGDirectMainDisplay );
1529 if( config_GetInt( p_vout, "macosx-stretch" ) )
1534 else if( height * p_vout->output.i_aspect <
1535 width * VOUT_ASPECT_FACTOR )
1537 f_x = (float) height * p_vout->output.i_aspect /
1538 width / VOUT_ASPECT_FACTOR;
1544 f_y = (float) width * VOUT_ASPECT_FACTOR /
1545 p_vout->output.i_aspect / height;
1548 /* Update viewport, re-init textures */
1549 glViewport( 0, 0, width, height );
1550 [self initTextures];
1552 /* Redraw the last picture */
1553 [self setNeedsDisplay: YES];
1558 - (void) exitFullScreen
1560 /* Free current OpenGL context */
1561 [NSOpenGLContext clearCurrentContext];
1562 [fullScreenContext clearDrawable];
1563 [fullScreenContext release];
1564 CGReleaseAllDisplays();
1566 currentContext = [self openGLContext];
1567 [self initTextures];
1570 /* Redraw the last picture */
1571 [self setNeedsDisplay: YES];
1580 [self exitFullScreen];
1587 glBegin( GL_QUADS );
1589 glTexCoord2f( 0.0, 0.0 );
1590 glVertex2f( - f_x, f_y );
1592 glTexCoord2f( 0.0, (float) p_vout->output.i_height );
1593 glVertex2f( - f_x, - f_y );
1595 glTexCoord2f( (float) p_vout->output.i_width,
1596 (float) p_vout->output.i_height );
1597 glVertex2f( f_x, - f_y );
1599 glTexCoord2f( (float) p_vout->output.i_width, 0.0 );
1600 glVertex2f( f_x, f_y );
1606 glBegin( GL_QUADS );
1608 glTexCoord2f( 0.0, 0.0 );
1609 glVertex3f( - 1.0, 1.0, 1.0 );
1610 glTexCoord2f( 0.0, (float) p_vout->output.i_height );
1611 glVertex3f( - 1.0, - 1.0, 1.0 );
1612 glTexCoord2f( (float) p_vout->output.i_width,
1613 (float) p_vout->output.i_height );
1614 glVertex3f( 1.0, - 1.0, 1.0 );
1615 glTexCoord2f( (float) p_vout->output.i_width, 0.0 );
1616 glVertex3f( 1.0, 1.0, 1.0 );
1619 glTexCoord2f( 0.0, 0.0 );
1620 glVertex3f( - 1.0, 1.0, - 1.0 );
1621 glTexCoord2f( 0.0, (float) p_vout->output.i_height );
1622 glVertex3f( - 1.0, - 1.0, - 1.0 );
1623 glTexCoord2f( (float) p_vout->output.i_width,
1624 (float) p_vout->output.i_height );
1625 glVertex3f( - 1.0, - 1.0, 1.0 );
1626 glTexCoord2f( (float) p_vout->output.i_width, 0.0 );
1627 glVertex3f( - 1.0, 1.0, 1.0 );
1630 glTexCoord2f( 0.0, 0.0 );
1631 glVertex3f( 1.0, 1.0, - 1.0 );
1632 glTexCoord2f( 0.0, (float) p_vout->output.i_height );
1633 glVertex3f( 1.0, - 1.0, - 1.0 );
1634 glTexCoord2f( (float) p_vout->output.i_width,
1635 (float) p_vout->output.i_height );
1636 glVertex3f( - 1.0, - 1.0, - 1.0 );
1637 glTexCoord2f( (float) p_vout->output.i_width, 0.0 );
1638 glVertex3f( - 1.0, 1.0, - 1.0 );
1641 glTexCoord2f( 0.0, 0.0 );
1642 glVertex3f( 1.0, 1.0, 1.0 );
1643 glTexCoord2f( 0.0, (float) p_vout->output.i_height );
1644 glVertex3f( 1.0, - 1.0, 1.0 );
1645 glTexCoord2f( (float) p_vout->output.i_width,
1646 (float) p_vout->output.i_height );
1647 glVertex3f( 1.0, - 1.0, - 1.0 );
1648 glTexCoord2f( (float) p_vout->output.i_width, 0.0 );
1649 glVertex3f( 1.0, 1.0, - 1.0 );
1652 glTexCoord2f( 0.0, 0.0 );
1653 glVertex3f( - 1.0, 1.0, - 1.0 );
1654 glTexCoord2f( 0.0, (float) p_vout->output.i_height );
1655 glVertex3f( - 1.0, 1.0, 1.0 );
1656 glTexCoord2f( (float) p_vout->output.i_width,
1657 (float) p_vout->output.i_height );
1658 glVertex3f( 1.0, 1.0, 1.0 );
1659 glTexCoord2f( (float) p_vout->output.i_width, 0.0 );
1660 glVertex3f( 1.0, 1.0, - 1.0 );
1663 glTexCoord2f( 0.0, 0.0 );
1664 glVertex3f( - 1.0, - 1.0, 1.0 );
1665 glTexCoord2f( 0.0, (float) p_vout->output.i_height );
1666 glVertex3f( - 1.0, - 1.0, - 1.0 );
1667 glTexCoord2f( (float) p_vout->output.i_width,
1668 (float) p_vout->output.i_height );
1669 glVertex3f( 1.0, - 1.0, - 1.0 );
1670 glTexCoord2f( (float) p_vout->output.i_width, 0.0 );
1671 glVertex3f( 1.0, - 1.0, 1.0 );
1675 - (void) drawRect: (NSRect) rect
1677 [currentContext makeCurrentContext];
1679 /* Swap buffers only during the vertical retrace of the monitor.
1680 http://developer.apple.com/documentation/GraphicsImaging/
1681 Conceptual/OpenGL/chap5/chapter_5_section_44.html */
1682 long params[] = { 1 };
1683 CGLSetParameter( CGLGetCurrentContext(), kCGLCPSwapInterval,
1686 /* Black background */
1687 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
1691 [currentContext flushBuffer];
1696 glBindTexture( GL_TEXTURE_RECTANGLE_EXT, i_texture );
1697 if( i_effect & ( OPENGL_EFFECT_CUBE |
1698 OPENGL_EFFECT_TRANSPARENT_CUBE ) )
1700 glRotatef( 1.0, 0.3, 0.5, 0.7 );
1708 /* Wait for the job to be done */
1709 [currentContext flushBuffer];
1714 /*****************************************************************************
1715 * VLCVout implementation
1716 *****************************************************************************/
1717 @implementation VLCVout
1719 - (void)createWindow:(NSValue *)o_value
1723 NSScreen * o_screen;
1724 vout_thread_t * p_vout;
1725 vlc_bool_t b_main_screen;
1727 p_vout = (vout_thread_t *)[o_value pointerValue];
1729 p_vout->p_sys->o_window = [VLCWindow alloc];
1730 [p_vout->p_sys->o_window setVout: p_vout];
1731 [p_vout->p_sys->o_window setReleasedWhenClosed: YES];
1733 if( var_Get( p_vout, "video-device", &val ) < 0 )
1735 o_screen = [NSScreen mainScreen];
1740 NSArray *o_screens = [NSScreen screens];
1741 unsigned int i_index = val.i_int;
1743 if( [o_screens count] < i_index )
1745 o_screen = [NSScreen mainScreen];
1751 o_screen = [o_screens objectAtIndex: i_index];
1752 config_PutInt( p_vout, "macosx-vdev", i_index );
1753 b_main_screen = (i_index == 0);
1757 if( p_vout->b_fullscreen && !p_vout->p_sys->i_opengl )
1759 NSRect screen_rect = [o_screen frame];
1760 screen_rect.origin.x = screen_rect.origin.y = 0;
1762 if ( b_main_screen && p_vout->p_sys->p_fullscreen_state == NULL )
1763 BeginFullScreen( &p_vout->p_sys->p_fullscreen_state, NULL, 0, 0,
1764 NULL, NULL, fullScreenAllowEvents );
1766 [p_vout->p_sys->o_window
1767 initWithContentRect: screen_rect
1768 styleMask: NSBorderlessWindowMask
1769 backing: NSBackingStoreBuffered
1770 defer: NO screen: o_screen];
1772 //[p_vout->p_sys->o_window setLevel: NSPopUpMenuWindowLevel - 1];
1773 p_vout->p_sys->b_mouse_moved = YES;
1774 p_vout->p_sys->i_time_mouse_last_moved = mdate();
1778 unsigned int i_stylemask = NSTitledWindowMask |
1779 NSMiniaturizableWindowMask |
1780 NSClosableWindowMask |
1781 NSResizableWindowMask;
1783 if( !p_vout->p_sys->i_opengl )
1785 if ( p_vout->p_sys->p_fullscreen_state != NULL )
1786 EndFullScreen ( p_vout->p_sys->p_fullscreen_state, NULL );
1787 p_vout->p_sys->p_fullscreen_state = NULL;
1790 [p_vout->p_sys->o_window
1791 initWithContentRect: p_vout->p_sys->s_rect
1792 styleMask: i_stylemask
1793 backing: NSBackingStoreBuffered
1794 defer: NO screen: o_screen];
1796 [p_vout->p_sys->o_window setAlphaValue: config_GetFloat( p_vout, "macosx-opaqueness" )];
1798 if( config_GetInt( p_vout, "video-on-top" ) )
1800 [p_vout->p_sys->o_window setLevel: NSStatusWindowLevel];
1803 if( !p_vout->p_sys->b_pos_saved )
1805 [p_vout->p_sys->o_window center];
1809 if( !p_vout->p_sys->i_opengl )
1811 o_view = [[VLCQTView alloc] init];
1812 /* FIXME: [o_view setMenu:] */
1813 [p_vout->p_sys->o_window setContentView: o_view];
1814 [o_view autorelease];
1817 p_vout->p_sys->p_qdport = [o_view qdPort];
1818 [o_view unlockFocus];
1822 #define o_glview p_vout->p_sys->o_glview
1823 o_glview = [[VLCGLView alloc] initWithFrame: p_vout->p_sys->s_rect vout: p_vout];
1824 [p_vout->p_sys->o_window setContentView: o_glview];
1825 [o_glview autorelease];
1829 [p_vout->p_sys->o_window updateTitle];
1830 [p_vout->p_sys->o_window makeKeyAndOrderFront: nil];
1834 - (void)destroyWindow:(NSValue *)o_value
1836 vout_thread_t * p_vout;
1838 p_vout = (vout_thread_t *)[o_value pointerValue];
1840 if( !p_vout->b_fullscreen )
1844 s_rect = [[p_vout->p_sys->o_window contentView] frame];
1845 p_vout->p_sys->s_rect.size = s_rect.size;
1847 s_rect = [p_vout->p_sys->o_window frame];
1848 p_vout->p_sys->s_rect.origin = s_rect.origin;
1850 p_vout->p_sys->b_pos_saved = YES;
1853 p_vout->p_sys->p_qdport = nil;
1854 [p_vout->p_sys->o_window close];
1855 p_vout->p_sys->o_window = nil;