Index: libvo/vo_quartz.c =================================================================== RCS file: /cvsroot/mplayer/main/libvo/vo_quartz.c,v retrieving revision 1.6 diff -u -r1.6 vo_quartz.c --- libvo/vo_quartz.c 5 May 2004 02:38:35 -0000 1.6 +++ libvo/vo_quartz.c 5 May 2004 17:21:08 -0000 @@ -65,7 +65,7 @@ #ifdef QUARTZ_ENABLE_YUV static CodecType image_qtcodec; -static PlanarPixmapInfoYUV420 *P; +static PlanarPixmapInfoYUV420 *P = NULL; static struct { ImageSequence seqId; @@ -83,14 +83,15 @@ extern int vo_ontop; extern int vo_fs; - +// are we in fs mode or not ? +static int vo_quartz_fs = 0; int int_pause = 0; float winAlpha = 1; int device_width; int device_height; -WindowRef theWindow; +static WindowRef theWindow = NULL; GWorldPtr imgGWorld; @@ -284,12 +285,36 @@ return err; } +static void quartz_CreateWindow(uint32_t d_width, uint32_t d_height, WindowAttributes windowAttrs) { + CFStringRef titleKey; + CFStringRef windowTitle; + OSStatus result; + + SetRect(&winRect, 0, 0, d_width, d_height); + SetRect(&dstRect, 0, 0, d_width, d_height); + + CreateNewWindow(kDocumentWindowClass, windowAttrs, &winRect, &theWindow); + + //Set window title + titleKey = CFSTR("MPlayer"); + windowTitle = CFCopyLocalizedString(titleKey, NULL); + result = SetWindowTitleWithCFString(theWindow, windowTitle); + CFRelease(titleKey); + CFRelease(windowTitle); + + //Install event handler + const EventTypeSpec winEvents[] = { { kEventClassWindow, kEventWindowClosed }, { kEventClassWindow, kEventWindowBoundsChanged } }; + const EventTypeSpec keyEvents[] = { { kEventClassKeyboard, kEventRawKeyDown } }; + const EventTypeSpec mouseEvents[] = { { kEventClassMouse, kEventMouseDown } }; + + InstallWindowEventHandler (theWindow, NewEventHandlerUPP (MainWindowEventHandler), GetEventTypeCount(winEvents), winEvents, theWindow, NULL); + InstallWindowEventHandler (theWindow, NewEventHandlerUPP (MainKeyboardEventHandler), GetEventTypeCount(keyEvents), keyEvents, theWindow, NULL); + InstallApplicationEventHandler (NewEventHandlerUPP (MainMouseEventHandler), GetEventTypeCount(mouseEvents), mouseEvents, 0, NULL); +} + static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) { WindowAttributes windowAttrs; - CFStringRef titleKey; - CFStringRef windowTitle; - OSStatus result; GDHandle deviceHdl; Rect deviceRect; OSErr qterr; @@ -321,7 +346,7 @@ } image_size = ((image_width*image_height*image_depth)+7)/8; - vo_fs = flags & VOFLAG_FULLSCREEN; + vo_fs = (flags & VOFLAG_FULLSCREEN) ? 1 : 0; //get movie aspect aspect_save_orig(width,height); @@ -338,34 +363,32 @@ if (!(IMGFMT_IS_RGB(image_format))) { windowAttrs &= (~kWindowResizableAttribute); + if (EnterMoviesDone) { // restarting + qterr = CDSequenceEnd(yuv_qt_stuff.seqId); + if (qterr) { + mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: CDSequenceEnd (%d)\n", qterr); + } + } + } + + if (theWindow == NULL) { + quartz_CreateWindow(d_width, d_height, windowAttrs); + if (theWindow == NULL) { //oops + mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: Couldn't create window !!!!!\n"); + return -1; + } + } else { + HideWindow(theWindow); + ChangeWindowAttributes(theWindow, ~windowAttrs, windowAttrs); + SizeWindow (theWindow, d_width, d_height, 1); } - SetRect(&winRect, 0, 0, d_width, d_height); - SetRect(&dstRect, 0, 0, d_width, d_height); SetRect(&imgRect, 0, 0, image_width, image_height); - CreateNewWindow(kDocumentWindowClass, windowAttrs, &winRect, &theWindow); - - //Set window title - titleKey = CFSTR("MPlayer"); - windowTitle = CFCopyLocalizedString(titleKey, NULL); - result = SetWindowTitleWithCFString(theWindow, windowTitle); - CFRelease(titleKey); - CFRelease(windowTitle); - - //Install event handler - const EventTypeSpec winEvents[] = { { kEventClassWindow, kEventWindowClosed }, { kEventClassWindow, kEventWindowBoundsChanged } }; - const EventTypeSpec keyEvents[] = { { kEventClassKeyboard, kEventRawKeyDown } }; - const EventTypeSpec mouseEvents[] = { { kEventClassMouse, kEventMouseDown } }; - - InstallWindowEventHandler (theWindow, NewEventHandlerUPP (MainWindowEventHandler), GetEventTypeCount(winEvents), winEvents, theWindow, NULL); - InstallWindowEventHandler (theWindow, NewEventHandlerUPP (MainKeyboardEventHandler), GetEventTypeCount(keyEvents), keyEvents, theWindow, NULL); - InstallApplicationEventHandler (NewEventHandlerUPP (MainMouseEventHandler), GetEventTypeCount(mouseEvents), mouseEvents, 0, NULL); - #ifdef QUARTZ_ENABLE_YUV if (!(IMGFMT_IS_RGB(image_format))) { - if (!EnterMoviesDone) + if (!EnterMoviesDone) // only _once_ { qterr = EnterMovies(); EnterMoviesDone = 1; @@ -377,6 +400,7 @@ if (qterr) { mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: EnterMovies (%d)\n", qterr); + return -1; } { @@ -388,13 +412,13 @@ qterr = FindCodec(image_qtcodec, bestSpeedCodec, NULL, &mycodec); if (qterr) { - mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: FindCodec (%d)\n", qterr); + mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: FindCodec (%d)\n", qterr); } qterr = GetComponentInfo(mycodec, &cd2, h1, h2, NULL); if (qterr) { - mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: GetComponentInfo (%d)\n", qterr); + mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: GetComponentInfo (%d)\n", qterr); } memcpy(ch1, &((unsigned char*)(*h1))[1], ((unsigned char*)(*h1))[0]); @@ -418,7 +442,7 @@ if (qterr) { - mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: GetCodecInfo (%d)\n", qterr); + mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: GetCodecInfo (%d)\n", qterr); } mp_msg(MSGT_VO, MSGL_INFO, "Quartz: CodecInfo:\n\tname: %s\n\tvendor: %.4s\n\tversion/revision: %d/%d\n\tdecompressFlags: 0x%08x\n\tcompressFlags: 0x%08x\n\tformatFlags: 0x%08x\n", ch1, &ci.vendor, ci.version, ci.revisionLevel, ci.decompressFlags, ci.compressFlags, ci.formatFlags); } @@ -465,25 +489,25 @@ qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_colr, kColorInfoImageDescriptionExtension); if (qterr) { - mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: AddImageDescriptionExtension [colr] (%d)\n", qterr); + mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [colr] (%d)\n", qterr); } qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_fiel, kFieldInfoImageDescriptionExtension); if (qterr) { - mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: AddImageDescriptionExtension [fiel] (%d)\n", qterr); + mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [fiel] (%d)\n", qterr); } qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_clap, kCleanApertureImageDescriptionExtension); if (qterr) { - mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: AddImageDescriptionExtension [clap] (%d)\n", qterr); + mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [clap] (%d)\n", qterr); } qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_pasp, kCleanApertureImageDescriptionExtension); if (qterr) { - mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: AddImageDescriptionExtension [pasp] (%d)\n", qterr); + mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [pasp] (%d)\n", qterr); } SetPort(GetWindowPort(theWindow)); @@ -492,7 +516,9 @@ { ScaleMatrix(&yuv_qt_stuff.matrix, FixDiv(Long2Fix(d_width),Long2Fix(width)), FixDiv(Long2Fix(d_height),Long2Fix(height)), 0, 0); } - + if (P != NULL) { // second or subsequent movie + free(P); + } P = calloc(sizeof(PlanarPixmapInfoYUV420) + image_size, 1); switch (image_format) { @@ -536,6 +562,7 @@ if (qterr) { mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: DecompressSequenceBeginS (%d)\n", qterr); + return -1; } mp_msg(MSGT_VO, MSGL_INFO, "Quartz: DecompressSequenceBeginS done\n"); } @@ -545,6 +572,9 @@ RepositionWindow(theWindow, NULL, kWindowCascadeOnMainScreen); ShowWindow (theWindow); + if (vo_quartz_fs) // stay in full screen + vo_fs = 1; + if(vo_fs) window_fullscreen(); @@ -753,7 +783,7 @@ qterr = CDSequenceEnd(yuv_qt_stuff.seqId); if (qterr) { - mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: CDSequenceEnd (%d)\n", qterr); + mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: CDSequenceEnd (%d)\n", qterr); } } } @@ -841,7 +871,7 @@ { case VOCTRL_PAUSE: return (int_pause=1); case VOCTRL_RESUME: return (int_pause=0); - case VOCTRL_FULLSCREEN: window_fullscreen(); return VO_TRUE; + case VOCTRL_FULLSCREEN: vo_fs = 1 - vo_fs; window_fullscreen(); return VO_TRUE; case VOCTRL_ONTOP: window_ontop(); return VO_TRUE; case VOCTRL_QUERY_FORMAT: return query_format(*((uint32_t*)data)); #ifdef QUARTZ_ENABLE_YUV @@ -963,7 +993,7 @@ Rect deviceRect; //go fullscreen - if(!vo_fs) + if(vo_fs) { //BeginFullScreen( &restoreState,nil,&width,&height,nil,&black,nil); HideMenuBar(); @@ -988,7 +1018,7 @@ MoveWindow (theWindow, 0, 0, 1); SizeWindow(theWindow, device_width, device_height,1); - vo_fs = 1; + vo_quartz_fs = 1; } else //go back to windowed mode { @@ -1012,7 +1042,7 @@ SizeWindow(theWindow, oldRect.right, oldRect.bottom,1); RepositionWindow(theWindow, NULL, kWindowCascadeOnMainScreen); - vo_fs = 0; + vo_quartz_fs = 0; } window_resized();