1 /*****************************************************************************
2 * vout.m: MacOS X video output module
3 *****************************************************************************
4 * Copyright (C) 2001-2003 VideoLAN
5 * $Id: vout.m,v 1.82 2004/02/25 19:27:23 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( p_vout, p_pic, p_vout->output.i_chroma,
332 p_vout->output.i_width, p_vout->output.i_height,
333 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 unlockFocus];
354 /*****************************************************************************
355 * vout_End: terminate video thread output method
356 *****************************************************************************/
357 static void vout_End( vout_thread_t *p_vout )
361 if( !p_vout->p_sys->i_opengl )
363 QTDestroySequence( p_vout );
366 /* Free the direct buffers we allocated */
367 for( i_index = I_OUTPUTPICTURES; i_index; )
370 if( !p_vout->p_sys->i_opengl )
372 QTFreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );
376 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
381 /*****************************************************************************
382 * CloseVideo: destroy video thread output method
383 *****************************************************************************/
384 void E_(CloseVideo) ( vlc_object_t *p_this )
386 vout_thread_t * p_vout = (vout_thread_t *)p_this;
388 if( CoDestroyWindow( p_vout ) )
390 msg_Err( p_vout, "unable to destroy window" );
393 if( !p_vout->p_sys->i_opengl )
395 if ( p_vout->p_sys->p_fullscreen_state != NULL )
396 EndFullScreen ( p_vout->p_sys->p_fullscreen_state, NULL );
400 free( p_vout->p_sys->p_matrix );
401 DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
404 free( p_vout->p_sys );
407 /*****************************************************************************
408 * vout_Manage: handle events
409 *****************************************************************************
410 * This function should be called regularly by video output thread. It manages
411 * console events. It returns a non null value on error.
412 *****************************************************************************/
413 static int vout_Manage( vout_thread_t *p_vout )
415 if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
417 if( CoToggleFullscreen( p_vout ) )
422 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
425 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
427 if( !p_vout->p_sys->i_opengl )
429 QTScaleMatrix( p_vout );
430 SetDSequenceMatrix( p_vout->p_sys->i_seq,
431 p_vout->p_sys->p_matrix );
434 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
437 /* hide/show mouse cursor
438 * this code looks unnecessarily complicated, but is necessary like this.
439 * it has to deal with multiple monitors and therefore checks a lot */
440 if( !p_vout->p_sys->b_mouse_moved && p_vout->b_fullscreen )
442 if( mdate() - p_vout->p_sys->i_time_mouse_last_moved > 3000000 )
444 VLCHideMouse( p_vout, YES );
447 else if ( p_vout->p_sys->b_mouse_moved && p_vout->b_fullscreen )
449 VLCHideMouse( p_vout, NO );
452 /* disable screen saver */
453 UpdateSystemActivity( UsrActivity );
458 /*****************************************************************************
459 * vout_Display: displays previously rendered output
460 *****************************************************************************
461 * This function sends the currently rendered image to the display.
462 *****************************************************************************/
463 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
465 if( !p_vout->p_sys->i_opengl )
470 if( ( err = DecompressSequenceFrameS(
471 p_vout->p_sys->i_seq,
472 p_pic->p_sys->p_info,
473 p_pic->p_sys->i_size,
474 codecFlagUseImageBuffer, &flags, nil ) != noErr ) )
476 msg_Warn( p_vout, "DecompressSequenceFrameS failed: %d", err );
480 QDFlushPortBuffer( p_vout->p_sys->p_qdport, nil );
485 if( [p_vout->p_sys->o_glview lockFocusIfCanDraw] )
487 /* Texture gotta be reload before the buffer is filled
488 (thanks to gcc from arstechnica forums) */
489 [p_vout->p_sys->o_glview drawRect:
490 [p_vout->p_sys->o_glview bounds]];
491 [p_vout->p_sys->o_glview reloadTexture];
492 [p_vout->p_sys->o_glview unlockFocus];
497 /*****************************************************************************
498 * CoSendRequest: send request to interface thread
499 *****************************************************************************
500 * Returns 0 on success, 1 otherwise
501 *****************************************************************************/
502 static int CoSendRequest( vout_thread_t *p_vout, SEL sel )
506 intf_thread_t * p_intf;
508 VLCVout * o_vlv = [[VLCVout alloc] init];
510 if( ( i_ret = ExecuteOnMainThread( o_vlv, sel, (void *)p_vout ) ) )
512 msg_Err( p_vout, "SendRequest: no way to communicate with mt" );
517 /*This makes this function dependant of the presence of a macosx
518 interface. We do not check if this interface exists, since it has
519 already been done before.*/
521 p_intf = [NSApp getIntf];
523 val.b_bool = VLC_TRUE;
524 var_Create(p_intf,"intf-change",VLC_VAR_BOOL);
525 var_Set(p_intf, "intf-change",val);
530 /*****************************************************************************
531 * CoCreateWindow: create new window
532 *****************************************************************************
533 * Returns 0 on success, 1 otherwise
534 *****************************************************************************/
535 static int CoCreateWindow( vout_thread_t *p_vout )
537 if( CoSendRequest( p_vout, @selector(createWindow:) ) )
539 msg_Err( p_vout, "CoSendRequest (createWindow) failed" );
546 /*****************************************************************************
547 * CoDestroyWindow: destroy window
548 *****************************************************************************
549 * Returns 0 on success, 1 otherwise
550 *****************************************************************************/
551 static int CoDestroyWindow( vout_thread_t *p_vout )
554 VLCHideMouse( p_vout, NO );
556 if( CoSendRequest( p_vout, @selector(destroyWindow:) ) )
558 msg_Err( p_vout, "CoSendRequest (destroyWindow) failed" );
565 /*****************************************************************************
566 * CoToggleFullscreen: toggle fullscreen
567 *****************************************************************************
568 * Returns 0 on success, 1 otherwise
569 *****************************************************************************/
570 static int CoToggleFullscreen( vout_thread_t *p_vout )
572 if( p_vout->p_sys->i_opengl )
574 p_vout->b_fullscreen = !p_vout->b_fullscreen;
575 if( p_vout->b_fullscreen )
577 [p_vout->p_sys->o_glview goFullScreen];
581 [p_vout->p_sys->o_glview exitFullScreen];
586 QTDestroySequence( p_vout );
588 if( CoDestroyWindow( p_vout ) )
590 msg_Err( p_vout, "unable to destroy window" );
594 p_vout->b_fullscreen = !p_vout->b_fullscreen;
596 if( CoCreateWindow( p_vout ) )
598 msg_Err( p_vout, "unable to create window" );
602 SetPort( p_vout->p_sys->p_qdport );
603 QTScaleMatrix( p_vout );
605 if( QTCreateSequence( p_vout ) )
607 msg_Err( p_vout, "unable to create sequence" );
614 /*****************************************************************************
615 * VLCHideMouse: if b_hide then hide the cursor
616 *****************************************************************************/
617 static void VLCHideMouse ( vout_thread_t *p_vout, BOOL b_hide )
622 NSWindow *o_window = p_vout->p_sys->o_window;
623 NSView *o_contents = [o_window contentView];
625 s_rect = [o_contents bounds];
626 ml = [o_window convertScreenToBase:[NSEvent mouseLocation]];
627 ml = [o_contents convertPoint:ml fromView:nil];
628 b_inside = [o_contents mouse: ml inRect: s_rect];
630 if ( b_hide && b_inside )
632 /* only hide if mouse over VLCQTView */
633 [NSCursor setHiddenUntilMouseMoves: YES];
637 [NSCursor setHiddenUntilMouseMoves: NO];
639 p_vout->p_sys->b_mouse_moved = NO;
640 p_vout->p_sys->i_time_mouse_last_moved = mdate();
644 /*****************************************************************************
645 * QTScaleMatrix: scale matrix
646 *****************************************************************************/
647 static void QTScaleMatrix( vout_thread_t *p_vout )
650 unsigned int i_width, i_height;
651 Fixed factor_x, factor_y;
652 unsigned int i_offset_x = 0;
653 unsigned int i_offset_y = 0;
655 GetPortBounds( p_vout->p_sys->p_qdport, &s_rect );
657 i_width = s_rect.right - s_rect.left;
658 i_height = s_rect.bottom - s_rect.top;
660 if( i_height * p_vout->output.i_aspect < i_width * VOUT_ASPECT_FACTOR )
662 int i_adj_width = i_height * p_vout->output.i_aspect /
665 factor_x = FixDiv( Long2Fix( i_adj_width ),
666 Long2Fix( p_vout->output.i_width ) );
667 factor_y = FixDiv( Long2Fix( i_height ),
668 Long2Fix( p_vout->output.i_height ) );
670 i_offset_x = (i_width - i_adj_width) / 2;
674 int i_adj_height = i_width * VOUT_ASPECT_FACTOR /
675 p_vout->output.i_aspect;
677 factor_x = FixDiv( Long2Fix( i_width ),
678 Long2Fix( p_vout->output.i_width ) );
679 factor_y = FixDiv( Long2Fix( i_adj_height ),
680 Long2Fix( p_vout->output.i_height ) );
682 i_offset_y = (i_height - i_adj_height) / 2;
685 SetIdentityMatrix( p_vout->p_sys->p_matrix );
687 ScaleMatrix( p_vout->p_sys->p_matrix,
689 Long2Fix(0), Long2Fix(0) );
691 TranslateMatrix( p_vout->p_sys->p_matrix,
692 Long2Fix(i_offset_x),
693 Long2Fix(i_offset_y) );
697 /*****************************************************************************
698 * QTCreateSequence: create a new sequence
699 *****************************************************************************
700 * Returns 0 on success, 1 otherwise
701 *****************************************************************************/
702 static int QTCreateSequence( vout_thread_t *p_vout )
705 ImageDescriptionPtr p_descr;
707 HLock( (Handle)p_vout->p_sys->h_img_descr );
708 p_descr = *p_vout->p_sys->h_img_descr;
710 p_descr->idSize = sizeof(ImageDescription);
711 p_descr->cType = p_vout->p_sys->i_codec;
712 p_descr->version = 1;
713 p_descr->revisionLevel = 0;
714 p_descr->vendor = 'appl';
715 p_descr->width = p_vout->output.i_width;
716 p_descr->height = p_vout->output.i_height;
717 p_descr->hRes = Long2Fix(72);
718 p_descr->vRes = Long2Fix(72);
719 p_descr->spatialQuality = codecLosslessQuality;
720 p_descr->frameCount = 1;
721 p_descr->clutID = -1;
722 p_descr->dataSize = 0;
725 HUnlock( (Handle)p_vout->p_sys->h_img_descr );
727 if( ( err = DecompressSequenceBeginS(
728 &p_vout->p_sys->i_seq,
729 p_vout->p_sys->h_img_descr,
731 p_vout->p_sys->p_qdport,
733 p_vout->p_sys->p_matrix,
735 codecFlagUseImageBuffer,
736 codecLosslessQuality,
737 p_vout->p_sys->img_dc ) ) )
739 msg_Err( p_vout, "DecompressSequenceBeginS failed: %d", err );
746 /*****************************************************************************
747 * QTDestroySequence: destroy sequence
748 *****************************************************************************/
749 static void QTDestroySequence( vout_thread_t *p_vout )
751 CDSequenceEnd( p_vout->p_sys->i_seq );
754 /*****************************************************************************
755 * QTNewPicture: allocate a picture
756 *****************************************************************************
757 * Returns 0 on success, 1 otherwise
758 *****************************************************************************/
759 static int QTNewPicture( vout_thread_t *p_vout, picture_t *p_pic )
761 int i_width = p_vout->output.i_width;
762 int i_height = p_vout->output.i_height;
764 /* We know the chroma, allocate a buffer which will be used
765 * directly by the decoder */
766 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
768 if( p_pic->p_sys == NULL )
773 switch( p_vout->output.i_chroma )
775 case VLC_FOURCC('I','4','2','0'):
777 p_pic->p_sys->p_info = (void *)&p_pic->p_sys->pixmap_i420;
778 p_pic->p_sys->i_size = sizeof(PlanarPixmapInfoYUV420);
780 /* Allocate the memory buffer */
781 p_pic->p_data = vlc_memalign( &p_pic->p_data_orig,
782 16, i_width * i_height * 3 / 2 );
785 p_pic->Y_PIXELS = p_pic->p_data;
786 p_pic->p[Y_PLANE].i_lines = i_height;
787 p_pic->p[Y_PLANE].i_pitch = i_width;
788 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
789 p_pic->p[Y_PLANE].i_visible_pitch = i_width;
792 p_pic->U_PIXELS = p_pic->Y_PIXELS + i_height * i_width;
793 p_pic->p[U_PLANE].i_lines = i_height / 2;
794 p_pic->p[U_PLANE].i_pitch = i_width / 2;
795 p_pic->p[U_PLANE].i_pixel_pitch = 1;
796 p_pic->p[U_PLANE].i_visible_pitch = i_width / 2;
799 p_pic->V_PIXELS = p_pic->U_PIXELS + i_height * i_width / 4;
800 p_pic->p[V_PLANE].i_lines = i_height / 2;
801 p_pic->p[V_PLANE].i_pitch = i_width / 2;
802 p_pic->p[V_PLANE].i_pixel_pitch = 1;
803 p_pic->p[V_PLANE].i_visible_pitch = i_width / 2;
805 /* We allocated 3 planes */
808 #define P p_pic->p_sys->pixmap_i420
809 P.componentInfoY.offset = (void *)p_pic->Y_PIXELS
810 - p_pic->p_sys->p_info;
811 P.componentInfoCb.offset = (void *)p_pic->U_PIXELS
812 - p_pic->p_sys->p_info;
813 P.componentInfoCr.offset = (void *)p_pic->V_PIXELS
814 - p_pic->p_sys->p_info;
816 P.componentInfoY.rowBytes = i_width;
817 P.componentInfoCb.rowBytes = i_width / 2;
818 P.componentInfoCr.rowBytes = i_width / 2;
824 /* Unknown chroma, tell the guy to get lost */
825 free( p_pic->p_sys );
826 msg_Err( p_vout, "never heard of chroma 0x%.8x (%4.4s)",
827 p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma );
835 /*****************************************************************************
836 * QTFreePicture: destroy a picture allocated with QTNewPicture
837 *****************************************************************************/
838 static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
840 switch( p_vout->output.i_chroma )
842 case VLC_FOURCC('I','4','2','0'):
843 free( p_pic->p_data_orig );
847 free( p_pic->p_sys );
850 /*****************************************************************************
851 * VLCWindow implementation
852 *****************************************************************************/
853 @implementation VLCWindow
855 - (void)setVout:(vout_thread_t *)_p_vout
860 - (vout_thread_t *)getVout
865 - (void)scaleWindowWithFactor: (float)factor
868 int i_corrected_height, i_corrected_width;
870 NSPoint topleftscreen;
872 if ( !p_vout->b_fullscreen )
875 topleftbase.y = [self frame].size.height;
876 topleftscreen = [self convertBaseToScreen: topleftbase];
878 if( p_vout->output.i_height * p_vout->output.i_aspect >
879 p_vout->output.i_width * VOUT_ASPECT_FACTOR )
881 i_corrected_width = p_vout->output.i_height * p_vout->output.i_aspect /
883 newsize.width = (int) ( i_corrected_width * factor );
884 newsize.height = (int) ( p_vout->render.i_height * factor );
888 i_corrected_height = p_vout->output.i_width * VOUT_ASPECT_FACTOR /
889 p_vout->output.i_aspect;
890 newsize.width = (int) ( p_vout->render.i_width * factor );
891 newsize.height = (int) ( i_corrected_height * factor );
894 [self setContentSize: newsize];
896 [self setFrameTopLeftPoint: topleftscreen];
897 p_vout->i_changes |= VOUT_SIZE_CHANGE;
901 - (void)toggleFloatOnTop
903 if( config_GetInt( p_vout, "video-on-top" ) )
905 config_PutInt( p_vout, "video-on-top", 0 );
906 [p_vout->p_sys->o_window setLevel: NSNormalWindowLevel];
910 config_PutInt( p_vout, "video-on-top", 1 );
911 [p_vout->p_sys->o_window setLevel: NSStatusWindowLevel];
915 - (void)toggleFullscreen
917 config_PutInt(p_vout, "fullscreen", !p_vout->b_fullscreen);
918 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
923 return( p_vout->b_fullscreen );
926 - (BOOL)canBecomeKeyWindow
931 - (void)keyDown:(NSEvent *)o_event
935 unsigned int i_pressed_modifiers = 0;
938 i_pressed_modifiers = [o_event modifierFlags];
940 if( i_pressed_modifiers & NSShiftKeyMask )
941 val.i_int |= KEY_MODIFIER_SHIFT;
942 if( i_pressed_modifiers & NSControlKeyMask )
943 val.i_int |= KEY_MODIFIER_CTRL;
944 if( i_pressed_modifiers & NSAlternateKeyMask )
945 val.i_int |= KEY_MODIFIER_ALT;
946 if( i_pressed_modifiers & NSCommandKeyMask )
947 val.i_int |= KEY_MODIFIER_COMMAND;
949 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
953 /* Escape should always get you out of fullscreen */
954 if( key == (unichar) 0x1b )
956 if( [self isFullscreen] )
958 [self toggleFullscreen];
961 else if ( key == ' ' )
963 playlist_t *p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
965 if ( p_playlist != NULL )
967 playlist_Pause( p_playlist );
968 vlc_object_release( p_playlist);
973 val.i_int |= CocoaKeyToVLC( key );
974 var_Set( p_vout->p_vlc, "key-pressed", val );
979 [super keyDown: o_event];
985 NSMutableString * o_title;
986 playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
989 if( p_playlist == NULL )
994 vlc_mutex_lock( &p_playlist->object_lock );
995 o_title = [NSMutableString stringWithUTF8String:
996 p_playlist->pp_items[p_playlist->i_index]->psz_uri];
997 vlc_mutex_unlock( &p_playlist->object_lock );
999 vlc_object_release( p_playlist );
1001 if( o_title != nil )
1003 NSRange prefix_range = [o_title rangeOfString: @"file:"];
1004 if( prefix_range.location != NSNotFound )
1006 [o_title deleteCharactersInRange: prefix_range];
1009 [self setTitleWithRepresentedFilename: o_title];
1014 [NSString stringWithCString: VOUT_TITLE " (QuickTime)"]];
1018 /* This is actually the same as VLCControls::stop. */
1019 - (BOOL)windowShouldClose:(id)sender
1021 playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
1023 if( p_playlist == NULL )
1028 playlist_Stop( p_playlist );
1029 vlc_object_release( p_playlist );
1031 /* The window will be closed by the intf later. */
1037 /*****************************************************************************
1038 * VLCQTView implementation
1039 *****************************************************************************/
1040 @implementation VLCQTView
1042 - (void)drawRect:(NSRect)rect
1044 vout_thread_t * p_vout;
1045 id o_window = [self window];
1046 p_vout = (vout_thread_t *)[o_window getVout];
1048 [[NSColor blackColor] set];
1050 [super drawRect: rect];
1052 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1055 - (BOOL)acceptsFirstResponder
1060 - (BOOL)becomeFirstResponder
1062 vout_thread_t * p_vout;
1063 id o_window = [self window];
1064 p_vout = (vout_thread_t *)[o_window getVout];
1066 [o_window setAcceptsMouseMovedEvents: YES];
1070 - (BOOL)resignFirstResponder
1072 vout_thread_t * p_vout;
1073 id o_window = [self window];
1074 p_vout = (vout_thread_t *)[o_window getVout];
1076 [o_window setAcceptsMouseMovedEvents: NO];
1077 VLCHideMouse( p_vout, NO );
1081 - (void)mouseDown:(NSEvent *)o_event
1083 vout_thread_t * p_vout;
1084 id o_window = [self window];
1085 p_vout = (vout_thread_t *)[o_window getVout];
1088 switch( [o_event type] )
1090 case NSLeftMouseDown:
1092 var_Get( p_vout, "mouse-button-down", &val );
1094 var_Set( p_vout, "mouse-button-down", val );
1099 [super mouseDown: o_event];
1104 - (void)otherMouseDown:(NSEvent *)o_event
1106 /* This is not the the wheel button. you need to poll the
1107 * mouseWheel event for that. other is a third, forth or fifth button */
1108 vout_thread_t * p_vout;
1109 id o_window = [self window];
1110 p_vout = (vout_thread_t *)[o_window getVout];
1113 switch( [o_event type] )
1115 case NSOtherMouseDown:
1117 var_Get( p_vout, "mouse-button-down", &val );
1119 var_Set( p_vout, "mouse-button-down", val );
1124 [super mouseDown: o_event];
1129 - (void)rightMouseDown:(NSEvent *)o_event
1131 vout_thread_t * p_vout;
1132 id o_window = [self window];
1133 p_vout = (vout_thread_t *)[o_window getVout];
1136 switch( [o_event type] )
1138 case NSRightMouseDown:
1140 var_Get( p_vout, "mouse-button-down", &val );
1142 var_Set( p_vout, "mouse-button-down", val );
1147 [super mouseDown: o_event];
1152 - (void)mouseUp:(NSEvent *)o_event
1154 vout_thread_t * p_vout;
1155 id o_window = [self window];
1156 p_vout = (vout_thread_t *)[o_window getVout];
1159 switch( [o_event type] )
1164 b_val.b_bool = VLC_TRUE;
1165 var_Set( p_vout, "mouse-clicked", b_val );
1167 var_Get( p_vout, "mouse-button-down", &val );
1169 var_Set( p_vout, "mouse-button-down", val );
1174 [super mouseUp: o_event];
1179 - (void)otherMouseUp:(NSEvent *)o_event
1181 vout_thread_t * p_vout;
1182 id o_window = [self window];
1183 p_vout = (vout_thread_t *)[o_window getVout];
1186 switch( [o_event type] )
1188 case NSOtherMouseUp:
1190 var_Get( p_vout, "mouse-button-down", &val );
1192 var_Set( p_vout, "mouse-button-down", val );
1197 [super mouseUp: o_event];
1202 - (void)rightMouseUp:(NSEvent *)o_event
1204 vout_thread_t * p_vout;
1205 id o_window = [self window];
1206 p_vout = (vout_thread_t *)[o_window getVout];
1209 switch( [o_event type] )
1211 case NSRightMouseUp:
1213 var_Get( p_vout, "mouse-button-down", &val );
1215 var_Set( p_vout, "mouse-button-down", val );
1220 [super mouseUp: o_event];
1225 - (void)mouseDragged:(NSEvent *)o_event
1227 [self mouseMoved:o_event];
1230 - (void)otherMouseDragged:(NSEvent *)o_event
1232 [self mouseMoved:o_event];
1235 - (void)rightMouseDragged:(NSEvent *)o_event
1237 [self mouseMoved:o_event];
1240 - (void)mouseMoved:(NSEvent *)o_event
1246 vout_thread_t * p_vout;
1247 id o_window = [self window];
1248 p_vout = (vout_thread_t *)[o_window getVout];
1250 s_rect = [self bounds];
1251 ml = [self convertPoint: [o_event locationInWindow] fromView: nil];
1252 b_inside = [self mouse: ml inRect: s_rect];
1257 int i_width, i_height, i_x, i_y;
1259 vout_PlacePicture( p_vout, (unsigned int)s_rect.size.width,
1260 (unsigned int)s_rect.size.height,
1261 &i_x, &i_y, &i_width, &i_height );
1263 val.i_int = ( ((int)ml.x) - i_x ) *
1264 p_vout->render.i_width / i_width;
1265 var_Set( p_vout, "mouse-x", val );
1267 val.i_int = ( ((int)ml.y) - i_y ) *
1268 p_vout->render.i_height / i_height;
1269 var_Set( p_vout, "mouse-y", val );
1271 val.b_bool = VLC_TRUE;
1272 var_Set( p_vout, "mouse-moved", val );
1273 p_vout->p_sys->i_time_mouse_last_moved = mdate();
1274 p_vout->p_sys->b_mouse_moved = YES;
1277 [super mouseMoved: o_event];
1282 /*****************************************************************************
1283 * VLCGLView implementation
1284 *****************************************************************************/
1285 @implementation VLCGLView
1288 - (id) initWithFrame: (NSRect) frame vout: (vout_thread_t*) _p_vout
1293 NSOpenGLPixelFormatAttribute attribs[] =
1295 NSOpenGLPFAAccelerated,
1296 NSOpenGLPFANoRecovery,
1297 NSOpenGLPFADoubleBuffer,
1298 NSOpenGLPFAColorSize, 24,
1299 NSOpenGLPFAAlphaSize, 8,
1300 NSOpenGLPFADepthSize, 24,
1305 NSOpenGLPixelFormat * fmt = [[NSOpenGLPixelFormat alloc]
1306 initWithAttributes: attribs];
1310 msg_Warn( p_vout, "Cannot create NSOpenGLPixelFormat" );
1314 self = [super initWithFrame:frame pixelFormat: fmt];
1316 currentContext = [self openGLContext];
1317 [currentContext makeCurrentContext];
1318 [currentContext update];
1320 /* Black background */
1321 glClearColor( 0.0, 0.0, 0.0, 0.0 );
1323 /* Check if the user asked for useless visual effects */
1324 psz_effect = config_GetPsz( p_vout, "macosx-opengl-effect" );
1325 if( !strcmp( psz_effect, "none" ) )
1327 i_effect = OPENGL_EFFECT_NONE;
1329 else if( !strcmp( psz_effect, "cube" ) )
1331 i_effect = OPENGL_EFFECT_CUBE;
1333 glEnable( GL_DEPTH_TEST );
1335 else if( !strcmp( psz_effect, "transparent-cube" ) )
1337 i_effect = OPENGL_EFFECT_TRANSPARENT_CUBE;
1339 glDisable( GL_DEPTH_TEST );
1340 glEnable( GL_BLEND );
1341 glBlendFunc( GL_SRC_ALPHA, GL_ONE );
1345 msg_Warn( p_vout, "no valid opengl effect provided, using "
1347 i_effect = OPENGL_EFFECT_NONE;
1350 if( i_effect & ( OPENGL_EFFECT_CUBE |
1351 OPENGL_EFFECT_TRANSPARENT_CUBE ) )
1353 /* Set the perpective */
1354 glMatrixMode( GL_PROJECTION );
1356 glFrustum( -1.0, 1.0, -1.0, 1.0, 3.0, 20.0 );
1357 glMatrixMode( GL_MODELVIEW );
1359 glTranslatef( 0.0, 0.0, - 5.0 );
1369 [currentContext makeCurrentContext];
1371 NSRect bounds = [self bounds];
1373 glViewport( 0, 0, (GLint) bounds.size.width,
1374 (GLint) bounds.size.height );
1376 /* Quad size is set in order to preserve the aspect ratio */
1377 if( bounds.size.height * p_vout->render.i_aspect <
1378 bounds.size.width * VOUT_ASPECT_FACTOR )
1380 f_x = bounds.size.height * p_vout->render.i_aspect /
1381 VOUT_ASPECT_FACTOR / bounds.size.width;
1387 f_y = bounds.size.width * VOUT_ASPECT_FACTOR /
1388 p_vout->render.i_aspect / bounds.size.height;
1392 - (void) initTextures
1394 [currentContext makeCurrentContext];
1396 /* Create textures */
1397 glGenTextures( 1, &i_texture );
1399 glEnable( GL_TEXTURE_RECTANGLE_EXT );
1400 glEnable( GL_UNPACK_CLIENT_STORAGE_APPLE );
1402 glBindTexture( GL_TEXTURE_RECTANGLE_EXT, i_texture );
1404 /* Use VRAM texturing */
1405 glTexParameteri( GL_TEXTURE_RECTANGLE_EXT,
1406 GL_TEXTURE_STORAGE_HINT_APPLE, GL_STORAGE_CACHED_APPLE );
1408 /* Tell the driver not to make a copy of the texture but to use
1410 glPixelStorei( GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE );
1412 /* Linear interpolation */
1413 glTexParameteri( GL_TEXTURE_RECTANGLE_EXT,
1414 GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1415 glTexParameteri( GL_TEXTURE_RECTANGLE_EXT,
1416 GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1418 /* I have no idea what this exactly does, but it seems to be
1419 necessary for scaling */
1420 glTexParameteri( GL_TEXTURE_RECTANGLE_EXT,
1421 GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1422 glTexParameteri( GL_TEXTURE_RECTANGLE_EXT,
1423 GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1424 glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
1426 glTexImage2D( GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA,
1427 p_vout->output.i_width, p_vout->output.i_height, 0,
1428 GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE,
1429 PP_OUTPUTPICTURE[0]->p_data );
1434 - (void) reloadTexture
1436 [currentContext makeCurrentContext];
1438 glBindTexture( GL_TEXTURE_RECTANGLE_EXT, i_texture );
1440 /* glTexSubImage2D is faster than glTexImage2D
1441 http://developer.apple.com/samplecode/Sample_Code/Graphics_3D/
1442 TextureRange/MainOpenGLView.m.htm */
1443 glTexSubImage2D( GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0,
1444 p_vout->output.i_width, p_vout->output.i_height,
1445 GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE,
1446 PP_OUTPUTPICTURE[0]->p_data );
1449 - (void) goFullScreen
1451 NSOpenGLPixelFormatAttribute attribs[] =
1453 NSOpenGLPFAAccelerated,
1454 NSOpenGLPFANoRecovery,
1455 NSOpenGLPFADoubleBuffer,
1456 NSOpenGLPFAColorSize, 24,
1457 NSOpenGLPFAAlphaSize, 8,
1458 NSOpenGLPFADepthSize, 24,
1459 NSOpenGLPFAFullScreen,
1460 NSOpenGLPFAScreenMask,
1461 CGDisplayIDToOpenGLDisplayMask( kCGDirectMainDisplay ),
1465 NSOpenGLPixelFormat * fmt = [[NSOpenGLPixelFormat alloc]
1466 initWithAttributes: attribs];
1470 msg_Warn( p_vout, "Cannot create NSOpenGLPixelFormat" );
1474 fullScreenContext = [[NSOpenGLContext alloc]
1475 initWithFormat: fmt shareContext: [self openGLContext]];
1477 if( !fullScreenContext )
1479 msg_Warn( p_vout, "Failed to create new NSOpenGLContext" );
1483 currentContext = fullScreenContext;
1485 if( CGCaptureAllDisplays() != CGDisplayNoErr )
1487 msg_Warn( p_vout, "CGCaptureAllDisplays() failed" );
1491 [fullScreenContext setFullScreen];
1492 [fullScreenContext makeCurrentContext];
1493 unsigned width = CGDisplayPixelsWide( kCGDirectMainDisplay );
1494 unsigned height = CGDisplayPixelsHigh( kCGDirectMainDisplay );
1495 if( height * p_vout->output.i_aspect < width * VOUT_ASPECT_FACTOR )
1497 f_x = (float) height * p_vout->output.i_aspect /
1498 width / VOUT_ASPECT_FACTOR;
1504 f_y = (float) width * VOUT_ASPECT_FACTOR /
1505 p_vout->output.i_aspect / height;
1507 glViewport( 0, 0, width, height );
1508 [self initTextures];
1511 - (void) exitFullScreen
1513 [NSOpenGLContext clearCurrentContext];
1514 [fullScreenContext clearDrawable];
1515 [fullScreenContext release];
1516 CGReleaseAllDisplays();
1517 currentContext = [self openGLContext];
1523 glBegin( GL_QUADS );
1525 glTexCoord2f( 0.0, 0.0 );
1526 glVertex2f( - f_x, f_y );
1528 glTexCoord2f( 0.0, (float) p_vout->output.i_height );
1529 glVertex2f( - f_x, - f_y );
1531 glTexCoord2f( (float) p_vout->output.i_width,
1532 (float) p_vout->output.i_height );
1533 glVertex2f( f_x, - f_y );
1535 glTexCoord2f( (float) p_vout->output.i_width, 0.0 );
1536 glVertex2f( f_x, f_y );
1542 glBegin( GL_QUADS );
1544 glTexCoord2f( 0.0, 0.0 );
1545 glVertex3f( - 1.0, 1.0, 1.0 );
1546 glTexCoord2f( 0.0, (float) p_vout->output.i_height );
1547 glVertex3f( - 1.0, - 1.0, 1.0 );
1548 glTexCoord2f( (float) p_vout->output.i_width,
1549 (float) p_vout->output.i_height );
1550 glVertex3f( 1.0, - 1.0, 1.0 );
1551 glTexCoord2f( (float) p_vout->output.i_width, 0.0 );
1552 glVertex3f( 1.0, 1.0, 1.0 );
1555 glTexCoord2f( 0.0, 0.0 );
1556 glVertex3f( - 1.0, 1.0, - 1.0 );
1557 glTexCoord2f( 0.0, (float) p_vout->output.i_height );
1558 glVertex3f( - 1.0, - 1.0, - 1.0 );
1559 glTexCoord2f( (float) p_vout->output.i_width,
1560 (float) p_vout->output.i_height );
1561 glVertex3f( - 1.0, - 1.0, 1.0 );
1562 glTexCoord2f( (float) p_vout->output.i_width, 0.0 );
1563 glVertex3f( - 1.0, 1.0, 1.0 );
1566 glTexCoord2f( 0.0, 0.0 );
1567 glVertex3f( 1.0, 1.0, - 1.0 );
1568 glTexCoord2f( 0.0, (float) p_vout->output.i_height );
1569 glVertex3f( 1.0, - 1.0, - 1.0 );
1570 glTexCoord2f( (float) p_vout->output.i_width,
1571 (float) p_vout->output.i_height );
1572 glVertex3f( - 1.0, - 1.0, - 1.0 );
1573 glTexCoord2f( (float) p_vout->output.i_width, 0.0 );
1574 glVertex3f( - 1.0, 1.0, - 1.0 );
1577 glTexCoord2f( 0.0, 0.0 );
1578 glVertex3f( 1.0, 1.0, 1.0 );
1579 glTexCoord2f( 0.0, (float) p_vout->output.i_height );
1580 glVertex3f( 1.0, - 1.0, 1.0 );
1581 glTexCoord2f( (float) p_vout->output.i_width,
1582 (float) p_vout->output.i_height );
1583 glVertex3f( 1.0, - 1.0, - 1.0 );
1584 glTexCoord2f( (float) p_vout->output.i_width, 0.0 );
1585 glVertex3f( 1.0, 1.0, - 1.0 );
1588 glTexCoord2f( 0.0, 0.0 );
1589 glVertex3f( - 1.0, 1.0, - 1.0 );
1590 glTexCoord2f( 0.0, (float) p_vout->output.i_height );
1591 glVertex3f( - 1.0, 1.0, 1.0 );
1592 glTexCoord2f( (float) p_vout->output.i_width,
1593 (float) p_vout->output.i_height );
1594 glVertex3f( 1.0, 1.0, 1.0 );
1595 glTexCoord2f( (float) p_vout->output.i_width, 0.0 );
1596 glVertex3f( 1.0, 1.0, - 1.0 );
1599 glTexCoord2f( 0.0, 0.0 );
1600 glVertex3f( - 1.0, - 1.0, 1.0 );
1601 glTexCoord2f( 0.0, (float) p_vout->output.i_height );
1602 glVertex3f( - 1.0, - 1.0, - 1.0 );
1603 glTexCoord2f( (float) p_vout->output.i_width,
1604 (float) p_vout->output.i_height );
1605 glVertex3f( 1.0, - 1.0, - 1.0 );
1606 glTexCoord2f( (float) p_vout->output.i_width, 0.0 );
1607 glVertex3f( 1.0, - 1.0, 1.0 );
1611 - (void) drawRect: (NSRect) rect
1613 [currentContext makeCurrentContext];
1615 /* Swap buffers only during the vertical retrace of the monitor.
1616 http://developer.apple.com/documentation/GraphicsImaging/
1617 Conceptual/OpenGL/chap5/chapter_5_section_44.html */
1618 long params[] = { 1 };
1619 CGLSetParameter( CGLGetCurrentContext(), kCGLCPSwapInterval,
1622 /* Black background */
1623 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
1627 [currentContext flushBuffer];
1632 glBindTexture( GL_TEXTURE_RECTANGLE_EXT, i_texture );
1633 if( i_effect & ( OPENGL_EFFECT_CUBE |
1634 OPENGL_EFFECT_TRANSPARENT_CUBE ) )
1636 glRotatef( 1.0, 0.3, 0.5, 0.7 );
1644 /* Wait for the job to be done */
1645 [currentContext flushBuffer];
1650 /*****************************************************************************
1651 * VLCVout implementation
1652 *****************************************************************************/
1653 @implementation VLCVout
1655 - (void)createWindow:(NSValue *)o_value
1659 NSScreen * o_screen;
1660 vout_thread_t * p_vout;
1661 vlc_bool_t b_main_screen;
1663 p_vout = (vout_thread_t *)[o_value pointerValue];
1665 p_vout->p_sys->o_window = [VLCWindow alloc];
1666 [p_vout->p_sys->o_window setVout: p_vout];
1667 [p_vout->p_sys->o_window setReleasedWhenClosed: YES];
1669 if( var_Get( p_vout, "video-device", &val ) < 0 )
1671 o_screen = [NSScreen mainScreen];
1676 NSArray *o_screens = [NSScreen screens];
1677 unsigned int i_index = val.i_int;
1679 if( [o_screens count] < i_index )
1681 o_screen = [NSScreen mainScreen];
1687 o_screen = [o_screens objectAtIndex: i_index];
1688 config_PutInt( p_vout, "macosx-vdev", i_index );
1689 b_main_screen = (i_index == 0);
1693 if( p_vout->b_fullscreen && !p_vout->p_sys->i_opengl )
1695 NSRect screen_rect = [o_screen frame];
1696 screen_rect.origin.x = screen_rect.origin.y = 0;
1698 if ( b_main_screen && p_vout->p_sys->p_fullscreen_state == NULL )
1699 BeginFullScreen( &p_vout->p_sys->p_fullscreen_state, NULL, 0, 0,
1700 NULL, NULL, fullScreenAllowEvents );
1702 [p_vout->p_sys->o_window
1703 initWithContentRect: screen_rect
1704 styleMask: NSBorderlessWindowMask
1705 backing: NSBackingStoreBuffered
1706 defer: NO screen: o_screen];
1708 //[p_vout->p_sys->o_window setLevel: NSPopUpMenuWindowLevel - 1];
1709 p_vout->p_sys->b_mouse_moved = YES;
1710 p_vout->p_sys->i_time_mouse_last_moved = mdate();
1714 unsigned int i_stylemask = NSTitledWindowMask |
1715 NSMiniaturizableWindowMask |
1716 NSClosableWindowMask |
1717 NSResizableWindowMask;
1719 if( !p_vout->p_sys->i_opengl )
1721 if ( p_vout->p_sys->p_fullscreen_state != NULL )
1722 EndFullScreen ( p_vout->p_sys->p_fullscreen_state, NULL );
1723 p_vout->p_sys->p_fullscreen_state = NULL;
1726 [p_vout->p_sys->o_window
1727 initWithContentRect: p_vout->p_sys->s_rect
1728 styleMask: i_stylemask
1729 backing: NSBackingStoreBuffered
1730 defer: NO screen: o_screen];
1732 [p_vout->p_sys->o_window setAlphaValue: config_GetFloat( p_vout, "macosx-opaqueness" )];
1734 if( config_GetInt( p_vout, "video-on-top" ) )
1736 [p_vout->p_sys->o_window setLevel: NSStatusWindowLevel];
1739 if( !p_vout->p_sys->b_pos_saved )
1741 [p_vout->p_sys->o_window center];
1745 if( !p_vout->p_sys->i_opengl )
1747 o_view = [[VLCQTView alloc] init];
1748 /* FIXME: [o_view setMenu:] */
1749 [p_vout->p_sys->o_window setContentView: o_view];
1750 [o_view autorelease];
1753 p_vout->p_sys->p_qdport = [o_view qdPort];
1754 [o_view unlockFocus];
1758 #define o_glview p_vout->p_sys->o_glview
1759 o_glview = [[VLCGLView alloc] initWithFrame: p_vout->p_sys->s_rect vout: p_vout];
1760 [p_vout->p_sys->o_window setContentView: o_glview];
1761 [o_glview autorelease];
1765 [p_vout->p_sys->o_window updateTitle];
1766 [p_vout->p_sys->o_window makeKeyAndOrderFront: nil];
1770 - (void)destroyWindow:(NSValue *)o_value
1772 vout_thread_t * p_vout;
1774 p_vout = (vout_thread_t *)[o_value pointerValue];
1776 if( !p_vout->b_fullscreen )
1780 s_rect = [[p_vout->p_sys->o_window contentView] frame];
1781 p_vout->p_sys->s_rect.size = s_rect.size;
1783 s_rect = [p_vout->p_sys->o_window frame];
1784 p_vout->p_sys->s_rect.origin = s_rect.origin;
1786 p_vout->p_sys->b_pos_saved = YES;
1789 p_vout->p_sys->p_qdport = nil;
1790 [p_vout->p_sys->o_window close];
1791 p_vout->p_sys->o_window = nil;