Add explanatory comments to the #endif part of multiple inclusion guards.
[mplayer/greg.git] / libvo / vo_quartz.c
blob240291bbf8fecb3571cc5a3d7977a9200159db1f
1 /*
2 vo_quartz.c
4 by Nicolas Plourde <nicolasplourde@gmail.com>
6 Copyright (c) Nicolas Plourde - April 2004
8 YUV support Copyright (C) 2004 Romain Dolbeau <romain@dolbeau.org>
10 MPlayer Mac OSX Quartz video out module.
12 todo: -screen overlay output
13 -fit osd in black bar when available
14 -fix RGB32
15 -(add sugestion here)
18 //SYS
19 #include <stdio.h>
21 //OSX
22 #include <Carbon/Carbon.h>
23 #include <QuickTime/QuickTime.h>
25 //MPLAYER
26 #include "config.h"
27 #include "fastmemcpy.h"
28 #include "video_out.h"
29 #include "video_out_internal.h"
30 #include "aspect.h"
31 #include "mp_msg.h"
32 #include "m_option.h"
33 #include "mp_fifo.h"
34 #include "mpbswap.h"
36 #include "input/input.h"
37 #include "input/mouse.h"
39 #include "vo_quartz.h"
41 static const vo_info_t info =
43 "Mac OSX (Quartz)",
44 "quartz",
45 "Nicolas Plourde <nicolasplourde@hotmail.com>, Romain Dolbeau <romain@dolbeau.org>",
49 const LIBVO_EXTERN(quartz)
51 static uint32_t image_depth;
52 static uint32_t image_format;
53 static uint32_t image_size;
54 static uint32_t image_buffer_size;
55 static char *image_data;
57 static ImageSequence seqId;
58 static CodecType image_qtcodec;
59 static PlanarPixmapInfoYUV420 *P = NULL;
60 static struct
62 ImageDescriptionHandle desc;
63 Handle extension_colr;
64 Handle extension_fiel;
65 Handle extension_clap;
66 Handle extension_pasp;
67 } yuv_qt_stuff;
68 static MatrixRecord matrix;
69 static int EnterMoviesDone = 0;
70 static int get_image_done = 0;
72 static int vo_quartz_fs; // we are in fullscreen
73 extern float monitor_aspect;
74 extern float movie_aspect;
75 static float old_movie_aspect;
77 static int winLevel = 1;
78 int levelList[] =
80 kCGDesktopWindowLevelKey,
81 kCGNormalWindowLevelKey,
82 kCGScreenSaverWindowLevelKey
85 static int int_pause = 0;
86 static float winAlpha = 1;
87 static int mouseHide = FALSE;
89 static int device_width;
90 static int device_height;
91 static int device_id;
93 static short fs_res_x=0;
94 static short fs_res_y=0;
96 static WindowRef theWindow = NULL;
97 static WindowGroupRef winGroup = NULL;
98 static CGContextRef context;
99 static CGRect bounds;
100 static GDHandle deviceHdl;
102 static CGDataProviderRef dataProviderRef;
103 static CGImageRef image;
105 static Rect imgRect; // size of the original image (unscaled)
106 static Rect dstRect; // size of the displayed image (after scaling)
107 static Rect winRect; // size of the window containg the displayed image (include padding)
108 static Rect oldWinRect; // size of the window containg the displayed image (include padding) when NOT in FS mode
109 static Rect deviceRect; // size of the display device
110 static Rect oldWinBounds;
112 static MenuRef windMenu;
113 static MenuRef movMenu;
114 static MenuRef aspectMenu;
116 enum
118 kQuitCmd = 1,
119 kHalfScreenCmd = 2,
120 kNormalScreenCmd = 3,
121 kDoubleScreenCmd = 4,
122 kFullScreenCmd = 5,
123 kKeepAspectCmd = 6,
124 kAspectOrgCmd = 7,
125 kAspectFullCmd = 8,
126 kAspectWideCmd = 9,
127 kPanScanCmd = 10
130 #include "osdep/keycodes.h"
132 extern void vo_draw_text(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride));
134 //PROTOTYPE/////////////////////////////////////////////////////////////////
135 static OSStatus KeyEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
136 static OSStatus MouseEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
137 static OSStatus WindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
138 void window_resized();
139 void window_ontop();
140 void window_fullscreen();
141 void window_panscan();
143 static inline int convert_key(UInt32 key, UInt32 charcode)
145 switch(key)
147 case QZ_IBOOK_ENTER:
148 case QZ_RETURN: return KEY_ENTER;
149 case QZ_ESCAPE: return KEY_ESC;
150 case QZ_BACKSPACE: return KEY_BACKSPACE;
151 case QZ_LALT: return KEY_BACKSPACE;
152 case QZ_LCTRL: return KEY_BACKSPACE;
153 case QZ_LSHIFT: return KEY_BACKSPACE;
154 case QZ_F1: return KEY_F+1;
155 case QZ_F2: return KEY_F+2;
156 case QZ_F3: return KEY_F+3;
157 case QZ_F4: return KEY_F+4;
158 case QZ_F5: return KEY_F+5;
159 case QZ_F6: return KEY_F+6;
160 case QZ_F7: return KEY_F+7;
161 case QZ_F8: return KEY_F+8;
162 case QZ_F9: return KEY_F+9;
163 case QZ_F10: return KEY_F+10;
164 case QZ_F11: return KEY_F+11;
165 case QZ_F12: return KEY_F+12;
166 case QZ_INSERT: return KEY_INSERT;
167 case QZ_DELETE: return KEY_DELETE;
168 case QZ_HOME: return KEY_HOME;
169 case QZ_END: return KEY_END;
170 case QZ_KP_PLUS: return '+';
171 case QZ_KP_MINUS: return '-';
172 case QZ_TAB: return KEY_TAB;
173 case QZ_PAGEUP: return KEY_PAGE_UP;
174 case QZ_PAGEDOWN: return KEY_PAGE_DOWN;
175 case QZ_UP: return KEY_UP;
176 case QZ_DOWN: return KEY_DOWN;
177 case QZ_LEFT: return KEY_LEFT;
178 case QZ_RIGHT: return KEY_RIGHT;
179 case QZ_KP_MULTIPLY: return '*';
180 case QZ_KP_DIVIDE: return '/';
181 case QZ_KP_ENTER: return KEY_KPENTER;
182 case QZ_KP_PERIOD: return KEY_KPDEC;
183 case QZ_KP0: return KEY_KP0;
184 case QZ_KP1: return KEY_KP1;
185 case QZ_KP2: return KEY_KP2;
186 case QZ_KP3: return KEY_KP3;
187 case QZ_KP4: return KEY_KP4;
188 case QZ_KP5: return KEY_KP5;
189 case QZ_KP6: return KEY_KP6;
190 case QZ_KP7: return KEY_KP7;
191 case QZ_KP8: return KEY_KP8;
192 case QZ_KP9: return KEY_KP9;
193 default: return charcode;
197 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride)
199 switch (image_format)
201 case IMGFMT_RGB32:
202 vo_draw_alpha_rgb32(w,h,src,srca,stride,image_data+4*(y0*imgRect.right+x0),4*imgRect.right);
203 break;
204 case IMGFMT_YV12:
205 case IMGFMT_IYUV:
206 case IMGFMT_I420:
207 vo_draw_alpha_yv12(w,h,src,srca,stride, ((char*)P) + be2me_32(P->componentInfoY.offset) + x0 + y0 * imgRect.right, imgRect.right);
208 break;
209 case IMGFMT_UYVY:
210 vo_draw_alpha_uyvy(w,h,src,srca,stride,((char*)P) + (x0 + y0 * imgRect.right) * 2,imgRect.right*2);
211 break;
212 case IMGFMT_YUY2:
213 vo_draw_alpha_yuy2(w,h,src,srca,stride,((char*)P) + (x0 + y0 * imgRect.right) * 2,imgRect.right*2);
214 break;
218 //default keyboard event handler
219 static OSStatus KeyEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
221 OSStatus result = noErr;
222 UInt32 class = GetEventClass (event);
223 UInt32 kind = GetEventKind (event);
225 result = CallNextEventHandler(nextHandler, event);
227 if(class == kEventClassKeyboard)
229 char macCharCodes;
230 UInt32 macKeyCode;
231 UInt32 macKeyModifiers;
233 GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(macCharCodes), NULL, &macCharCodes);
234 GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(macKeyCode), NULL, &macKeyCode);
235 GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(macKeyModifiers), NULL, &macKeyModifiers);
237 if(macKeyModifiers != 256)
239 if (kind == kEventRawKeyRepeat || kind == kEventRawKeyDown)
241 int key = convert_key(macKeyCode, macCharCodes);
242 if(key != -1)
243 mplayer_put_key(key);
246 else if(macKeyModifiers == 256)
248 switch(macCharCodes)
250 case '[': SetWindowAlpha(theWindow, winAlpha-=0.05); break;
251 case ']': SetWindowAlpha(theWindow, winAlpha+=0.05); break;
254 else
255 result = eventNotHandledErr;
258 return result;
261 //default mouse event handler
262 static OSStatus MouseEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
264 OSStatus result = noErr;
265 UInt32 class = GetEventClass (event);
266 UInt32 kind = GetEventKind (event);
268 result = CallNextEventHandler(nextHandler, event);
270 if(class == kEventClassMouse)
272 WindowPtr tmpWin;
273 Point mousePos;
274 Point winMousePos;
276 GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, 0, sizeof(Point), 0, &mousePos);
277 GetEventParameter(event, kEventParamWindowMouseLocation, typeQDPoint, 0, sizeof(Point), 0, &winMousePos);
279 switch (kind)
281 case kEventMouseMoved:
283 if(vo_quartz_fs)
285 CGDisplayShowCursor(kCGDirectMainDisplay);
286 mouseHide = FALSE;
289 break;
291 case kEventMouseWheelMoved:
293 int wheel;
294 short part;
296 GetEventParameter(event, kEventParamMouseWheelDelta, typeSInt32, 0, sizeof(int), 0, &wheel);
298 part = FindWindow(mousePos,&tmpWin);
300 if(part == inContent)
302 if(wheel > 0)
303 mplayer_put_key(MOUSE_BTN3);
304 else
305 mplayer_put_key(MOUSE_BTN4);
308 break;
310 case kEventMouseDown:
311 case kEventMouseUp:
313 EventMouseButton button;
314 short part;
315 Rect bounds;
317 GetWindowPortBounds(theWindow, &bounds);
318 GetEventParameter(event, kEventParamMouseButton, typeMouseButton, 0, sizeof(EventMouseButton), 0, &button);
320 part = FindWindow(mousePos,&tmpWin);
321 if(kind == kEventMouseUp)
323 if (part != inContent)
324 break;
325 switch(button)
327 case kEventMouseButtonPrimary:
328 mplayer_put_key(MOUSE_BTN0);
329 break;
330 case kEventMouseButtonSecondary:
331 mplayer_put_key(MOUSE_BTN2);
332 break;
333 case kEventMouseButtonTertiary:
334 mplayer_put_key(MOUSE_BTN1);
335 break;
337 default:result = eventNotHandledErr;break;
339 break;
341 if( (winMousePos.h > (bounds.right - 15)) && (winMousePos.v > (bounds.bottom)) )
343 if(!vo_quartz_fs)
345 GrowWindow(theWindow, mousePos, NULL);
348 else if(part == inMenuBar)
350 MenuSelect(mousePos);
351 HiliteMenu(0);
353 else if(part == inContent)
355 switch(button)
357 case kEventMouseButtonPrimary:
358 mplayer_put_key(MOUSE_BTN0 | MP_KEY_DOWN);
359 break;
360 case kEventMouseButtonSecondary:
361 mplayer_put_key(MOUSE_BTN2 | MP_KEY_DOWN);
362 break;
363 case kEventMouseButtonTertiary:
364 mplayer_put_key(MOUSE_BTN1 | MP_KEY_DOWN);
365 break;
367 default:result = eventNotHandledErr;break;
371 break;
373 case kEventMouseDragged:
374 break;
376 default:result = eventNotHandledErr;break;
380 return result;
383 //default window event handler
384 static OSStatus WindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
386 OSStatus result = noErr;
387 uint32_t d_width;
388 uint32_t d_height;
389 UInt32 class = GetEventClass (event);
390 UInt32 kind = GetEventKind (event);
392 result = CallNextEventHandler(nextHandler, event);
394 aspect(&d_width,&d_height,A_NOZOOM);
396 if(class == kEventClassCommand)
398 HICommand theHICommand;
399 GetEventParameter( event, kEventParamDirectObject, typeHICommand, NULL, sizeof( HICommand ), NULL, &theHICommand );
401 switch ( theHICommand.commandID )
403 case kHICommandQuit:
404 mplayer_put_key(KEY_CLOSE_WIN);
405 break;
407 case kHalfScreenCmd:
408 if(vo_quartz_fs)
410 vo_fs = (!(vo_fs)); window_fullscreen();
413 SizeWindow(theWindow, (d_width/2), ((d_width/movie_aspect)/2), 1);
414 window_resized();
415 break;
417 case kNormalScreenCmd:
418 if(vo_quartz_fs)
420 vo_fs = (!(vo_fs)); window_fullscreen();
423 SizeWindow(theWindow, d_width, (d_width/movie_aspect), 1);
424 window_resized();
425 break;
427 case kDoubleScreenCmd:
428 if(vo_quartz_fs)
430 vo_fs = (!(vo_fs)); window_fullscreen();
433 SizeWindow(theWindow, (d_width*2), ((d_width/movie_aspect)*2), 1);
434 window_resized();
435 break;
437 case kFullScreenCmd:
438 vo_fs = (!(vo_fs)); window_fullscreen();
439 break;
441 case kKeepAspectCmd:
442 vo_keepaspect = (!(vo_keepaspect));
443 CheckMenuItem (aspectMenu, 1, vo_keepaspect);
444 window_resized();
445 break;
447 case kAspectOrgCmd:
448 movie_aspect = old_movie_aspect;
449 if(!vo_quartz_fs)
451 SizeWindow(theWindow, dstRect.right, (dstRect.right/movie_aspect),1);
453 window_resized();
454 break;
456 case kAspectFullCmd:
457 movie_aspect = 4.0f/3.0f;
458 if(!vo_quartz_fs)
460 SizeWindow(theWindow, dstRect.right, (dstRect.right/movie_aspect),1);
462 window_resized();
463 break;
465 case kAspectWideCmd:
466 movie_aspect = 16.0f/9.0f;
467 if(!vo_quartz_fs)
469 SizeWindow(theWindow, dstRect.right, (dstRect.right/movie_aspect),1);
471 window_resized();
472 break;
474 case kPanScanCmd:
475 vo_panscan = (!(vo_panscan));
476 CheckMenuItem (aspectMenu, 2, vo_panscan);
477 window_panscan();
478 window_resized();
479 break;
481 default:
482 result = eventNotHandledErr;
483 break;
486 else if(class == kEventClassWindow)
488 WindowRef window;
489 Rect rectPort = {0,0,0,0};
491 GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window);
493 if(window)
495 GetPortBounds(GetWindowPort(window), &rectPort);
498 switch (kind)
500 case kEventWindowClosed:
501 theWindow = NULL;
502 mplayer_put_key(KEY_CLOSE_WIN);
503 break;
505 //resize window
506 case kEventWindowZoomed:
507 case kEventWindowBoundsChanged:
508 window_resized();
509 flip_page();
510 window_resized();
511 break;
513 default:
514 result = eventNotHandledErr;
515 break;
519 return result;
522 static void quartz_CreateWindow(uint32_t d_width, uint32_t d_height, WindowAttributes windowAttrs)
524 CFStringRef titleKey;
525 CFStringRef windowTitle;
526 OSStatus result;
528 MenuItemIndex index;
529 CFStringRef movMenuTitle;
530 CFStringRef aspMenuTitle;
532 const EventTypeSpec win_events[] = {
533 { kEventClassWindow, kEventWindowClosed },
534 { kEventClassWindow, kEventWindowBoundsChanged },
535 { kEventClassCommand, kEventCommandProcess }
538 const EventTypeSpec key_events[] = {
539 { kEventClassKeyboard, kEventRawKeyDown },
540 { kEventClassKeyboard, kEventRawKeyRepeat }
543 const EventTypeSpec mouse_events[] = {
544 { kEventClassMouse, kEventMouseMoved },
545 { kEventClassMouse, kEventMouseWheelMoved },
546 { kEventClassMouse, kEventMouseDown },
547 { kEventClassMouse, kEventMouseUp },
548 { kEventClassMouse, kEventMouseDragged }
551 SetRect(&winRect, 0, 0, d_width, d_height);
552 SetRect(&oldWinRect, 0, 0, d_width, d_height);
553 SetRect(&dstRect, 0, 0, d_width, d_height);
555 //Clear Menu Bar
556 ClearMenuBar();
558 //Create Window Menu
559 CreateStandardWindowMenu(0, &windMenu);
560 InsertMenu(windMenu, 0);
562 //Create Movie Menu
563 CreateNewMenu (1004, 0, &movMenu);
564 movMenuTitle = CFSTR("Movie");
565 SetMenuTitleWithCFString(movMenu, movMenuTitle);
567 AppendMenuItemTextWithCFString(movMenu, CFSTR("Half Size"), 0, kHalfScreenCmd, &index);
568 SetMenuItemCommandKey(movMenu, index, 0, '0');
570 AppendMenuItemTextWithCFString(movMenu, CFSTR("Normal Size"), 0, kNormalScreenCmd, &index);
571 SetMenuItemCommandKey(movMenu, index, 0, '1');
573 AppendMenuItemTextWithCFString(movMenu, CFSTR("Double Size"), 0, kDoubleScreenCmd, &index);
574 SetMenuItemCommandKey(movMenu, index, 0, '2');
576 AppendMenuItemTextWithCFString(movMenu, CFSTR("Full Size"), 0, kFullScreenCmd, &index);
577 SetMenuItemCommandKey(movMenu, index, 0, 'F');
579 AppendMenuItemTextWithCFString(movMenu, NULL, kMenuItemAttrSeparator, 0, &index);
581 AppendMenuItemTextWithCFString(movMenu, CFSTR("Aspect Ratio"), 0, 0, &index);
583 ////Create Aspect Ratio Sub Menu
584 CreateNewMenu (0, 0, &aspectMenu);
585 aspMenuTitle = CFSTR("Aspect Ratio");
586 SetMenuTitleWithCFString(aspectMenu, aspMenuTitle);
587 SetMenuItemHierarchicalMenu(movMenu, 6, aspectMenu);
589 AppendMenuItemTextWithCFString(aspectMenu, CFSTR("Keep"), 0, kKeepAspectCmd, &index);
590 CheckMenuItem (aspectMenu, 1, vo_keepaspect);
591 AppendMenuItemTextWithCFString(aspectMenu, CFSTR("Pan-Scan"), 0, kPanScanCmd, &index);
592 CheckMenuItem (aspectMenu, 2, vo_panscan);
593 AppendMenuItemTextWithCFString(aspectMenu, NULL, kMenuItemAttrSeparator, 0, &index);
594 AppendMenuItemTextWithCFString(aspectMenu, CFSTR("Original"), 0, kAspectOrgCmd, &index);
595 AppendMenuItemTextWithCFString(aspectMenu, CFSTR("4:3"), 0, kAspectFullCmd, &index);
596 AppendMenuItemTextWithCFString(aspectMenu, CFSTR("16:9"), 0, kAspectWideCmd, &index);
598 InsertMenu(movMenu, GetMenuID(windMenu)); //insert before Window menu
600 DrawMenuBar();
602 //create window
603 CreateNewWindow(kDocumentWindowClass, windowAttrs, &winRect, &theWindow);
605 CreateWindowGroup(0, &winGroup);
606 SetWindowGroup(theWindow, winGroup);
608 //Set window title
609 titleKey = CFSTR("MPlayer - The Movie Player");
610 windowTitle = CFCopyLocalizedString(titleKey, NULL);
611 result = SetWindowTitleWithCFString(theWindow, windowTitle);
612 CFRelease(titleKey);
613 CFRelease(windowTitle);
615 //Install event handler
616 InstallApplicationEventHandler (NewEventHandlerUPP (KeyEventHandler), GetEventTypeCount(key_events), key_events, NULL, NULL);
617 InstallApplicationEventHandler (NewEventHandlerUPP (MouseEventHandler), GetEventTypeCount(mouse_events), mouse_events, NULL, NULL);
618 InstallWindowEventHandler (theWindow, NewEventHandlerUPP (WindowEventHandler), GetEventTypeCount(win_events), win_events, theWindow, NULL);
621 static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
623 WindowAttributes windowAttrs;
624 OSErr qterr;
625 int i;
626 CGRect tmpBounds;
628 //Get Main device info///////////////////////////////////////////////////
631 deviceHdl = GetMainDevice();
633 for(i=0; i<device_id; i++)
635 deviceHdl = GetNextDevice(deviceHdl);
637 if(deviceHdl == NULL)
639 mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: Device ID %d do not exist, falling back to main device.\n", device_id);
640 deviceHdl = GetMainDevice();
641 device_id = 0;
642 break;
646 deviceRect = (*deviceHdl)->gdRect;
647 device_width = deviceRect.right-deviceRect.left;
648 device_height = deviceRect.bottom-deviceRect.top;
650 monitor_aspect = (float)device_width/(float)device_height;
652 //misc mplayer setup/////////////////////////////////////////////////////
653 SetRect(&imgRect, 0, 0, width, height);
654 switch (image_format)
656 case IMGFMT_RGB32:
657 image_depth = 32;
658 break;
659 case IMGFMT_YV12:
660 case IMGFMT_IYUV:
661 case IMGFMT_I420:
662 case IMGFMT_UYVY:
663 case IMGFMT_YUY2:
664 image_depth = 16;
665 break;
667 image_size = ((imgRect.right*imgRect.bottom*image_depth)+7)/8;
669 vo_fs = flags & VOFLAG_FULLSCREEN;
671 //get movie aspect
672 panscan_init();
673 aspect_save_orig(width,height);
674 aspect_save_prescale(d_width,d_height);
675 aspect_save_screenres(device_width, device_height);
677 aspect(&d_width,&d_height,A_NOZOOM);
679 movie_aspect = (float)d_width/(float)d_height;
680 old_movie_aspect = movie_aspect;
682 if(image_data)
683 free(image_data);
685 image_data = malloc(image_size);
687 //Create player window//////////////////////////////////////////////////
688 windowAttrs = kWindowStandardDocumentAttributes
689 | kWindowStandardHandlerAttribute
690 | kWindowLiveResizeAttribute;
692 windowAttrs &= (~kWindowResizableAttribute);
694 if (theWindow == NULL)
696 quartz_CreateWindow(d_width, d_height, windowAttrs);
698 if (theWindow == NULL)
700 mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: Couldn't create window !!!!!\n");
701 return -1;
703 tmpBounds = CGRectMake( 0, 0, winRect.right, winRect.bottom);
704 CreateCGContextForPort(GetWindowPort(theWindow),&context);
705 CGContextFillRect(context, tmpBounds);
707 else
709 HideWindow(theWindow);
710 ChangeWindowAttributes(theWindow, ~windowAttrs, windowAttrs);
711 SetRect(&winRect, 0, 0, d_width, d_height);
712 SetRect(&oldWinRect, 0, 0, d_width, d_height);
713 SizeWindow (theWindow, d_width, d_height, 1);
716 switch (image_format)
718 case IMGFMT_RGB32:
720 CreateCGContextForPort (GetWindowPort (theWindow), &context);
722 dataProviderRef = CGDataProviderCreateWithData (0, image_data, imgRect.right * imgRect.bottom * 4, 0);
724 image = CGImageCreate (imgRect.right,
725 imgRect.bottom,
727 image_depth,
728 ((imgRect.right*32)+7)/8,
729 CGColorSpaceCreateDeviceRGB(),
730 kCGImageAlphaNoneSkipFirst,
731 dataProviderRef, 0, 1, kCGRenderingIntentDefault);
732 break;
735 case IMGFMT_YV12:
736 case IMGFMT_IYUV:
737 case IMGFMT_I420:
738 case IMGFMT_UYVY:
739 case IMGFMT_YUY2:
741 get_image_done = 0;
743 if (!EnterMoviesDone)
745 qterr = EnterMovies();
746 EnterMoviesDone = 1;
748 else
749 qterr = 0;
751 if (qterr)
753 mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: EnterMovies (%d)\n", qterr);
754 return -1;
758 SetIdentityMatrix(&matrix);
760 if ((d_width != width) || (d_height != height))
762 ScaleMatrix(&matrix, FixDiv(Long2Fix(d_width),Long2Fix(width)), FixDiv(Long2Fix(d_height),Long2Fix(height)), 0, 0);
765 yuv_qt_stuff.desc = (ImageDescriptionHandle)NewHandleClear( sizeof(ImageDescription) );
767 yuv_qt_stuff.extension_colr = NewHandleClear(sizeof(NCLCColorInfoImageDescriptionExtension));
768 ((NCLCColorInfoImageDescriptionExtension*)(*yuv_qt_stuff.extension_colr))->colorParamType = kVideoColorInfoImageDescriptionExtensionType;
769 ((NCLCColorInfoImageDescriptionExtension*)(*yuv_qt_stuff.extension_colr))->primaries = 2;
770 ((NCLCColorInfoImageDescriptionExtension*)(*yuv_qt_stuff.extension_colr))->transferFunction = 2;
771 ((NCLCColorInfoImageDescriptionExtension*)(*yuv_qt_stuff.extension_colr))->matrix = 2;
773 yuv_qt_stuff.extension_fiel = NewHandleClear(sizeof(FieldInfoImageDescriptionExtension));
774 ((FieldInfoImageDescriptionExtension*)(*yuv_qt_stuff.extension_fiel))->fieldCount = 1;
775 ((FieldInfoImageDescriptionExtension*)(*yuv_qt_stuff.extension_fiel))->fieldOrderings = 0;
777 yuv_qt_stuff.extension_clap = NewHandleClear(sizeof(CleanApertureImageDescriptionExtension));
778 ((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->cleanApertureWidthN = imgRect.right;
779 ((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->cleanApertureWidthD = 1;
780 ((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->cleanApertureHeightN = imgRect.bottom;
781 ((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->cleanApertureHeightD = 1;
782 ((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->horizOffN = 0;
783 ((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->horizOffD = 1;
784 ((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->vertOffN = 0;
785 ((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->vertOffD = 1;
787 yuv_qt_stuff.extension_pasp = NewHandleClear(sizeof(PixelAspectRatioImageDescriptionExtension));
788 ((PixelAspectRatioImageDescriptionExtension*)(*yuv_qt_stuff.extension_pasp))->hSpacing = 1;
789 ((PixelAspectRatioImageDescriptionExtension*)(*yuv_qt_stuff.extension_pasp))->vSpacing = 1;
791 (*yuv_qt_stuff.desc)->idSize = sizeof(ImageDescription);
792 (*yuv_qt_stuff.desc)->cType = image_qtcodec;
793 (*yuv_qt_stuff.desc)->version = 2;
794 (*yuv_qt_stuff.desc)->revisionLevel = 0;
795 (*yuv_qt_stuff.desc)->vendor = 'mpla';
796 (*yuv_qt_stuff.desc)->width = imgRect.right;
797 (*yuv_qt_stuff.desc)->height = imgRect.bottom;
798 (*yuv_qt_stuff.desc)->hRes = Long2Fix(72);
799 (*yuv_qt_stuff.desc)->vRes = Long2Fix(72);
800 (*yuv_qt_stuff.desc)->temporalQuality = 0;
801 (*yuv_qt_stuff.desc)->spatialQuality = codecLosslessQuality;
802 (*yuv_qt_stuff.desc)->frameCount = 1;
803 (*yuv_qt_stuff.desc)->dataSize = 0;
804 (*yuv_qt_stuff.desc)->depth = 24;
805 (*yuv_qt_stuff.desc)->clutID = -1;
807 qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_colr, kColorInfoImageDescriptionExtension);
808 if (qterr)
810 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [colr] (%d)\n", qterr);
813 qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_fiel, kFieldInfoImageDescriptionExtension);
814 if (qterr)
816 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [fiel] (%d)\n", qterr);
819 qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_clap, kCleanApertureImageDescriptionExtension);
820 if (qterr)
822 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [clap] (%d)\n", qterr);
825 qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_pasp, kCleanApertureImageDescriptionExtension);
826 if (qterr)
828 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [pasp] (%d)\n", qterr);
830 if (P != NULL) { // second or subsequent movie
831 free(P);
833 P = calloc(sizeof(PlanarPixmapInfoYUV420) + image_size, 1);
834 switch (image_format)
836 case IMGFMT_YV12:
837 case IMGFMT_IYUV:
838 case IMGFMT_I420:
839 P->componentInfoY.offset = be2me_32(sizeof(PlanarPixmapInfoYUV420));
840 P->componentInfoCb.offset = be2me_32(be2me_32(P->componentInfoY.offset) + image_size / 2);
841 P->componentInfoCr.offset = be2me_32(be2me_32(P->componentInfoCb.offset) + image_size / 4);
842 P->componentInfoY.rowBytes = be2me_32(imgRect.right);
843 P->componentInfoCb.rowBytes = be2me_32(imgRect.right / 2);
844 P->componentInfoCr.rowBytes = be2me_32(imgRect.right / 2);
845 image_buffer_size = image_size + sizeof(PlanarPixmapInfoYUV420);
846 break;
847 case IMGFMT_UYVY:
848 case IMGFMT_YUY2:
849 image_buffer_size = image_size;
850 break;
853 qterr = DecompressSequenceBeginS(&seqId,
854 yuv_qt_stuff.desc,
855 (char *)P,
856 image_buffer_size,
857 GetWindowPort(theWindow),
858 NULL,
859 NULL,
860 ((d_width != width) || (d_height != height)) ?
861 &matrix : NULL,
862 srcCopy,
863 NULL,
865 codecLosslessQuality,
866 bestSpeedCodec);
868 if (qterr)
870 mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: DecompressSequenceBeginS (%d)\n", qterr);
871 return -1;
874 break;
877 //Show window
878 RepositionWindow(theWindow, NULL, kWindowCenterOnMainScreen);
879 ShowWindow (theWindow);
881 if(vo_fs)
882 window_fullscreen();
884 if(vo_ontop)
885 window_ontop();
887 if(vo_rootwin)
889 vo_fs = TRUE;
890 winLevel = 0;
891 SetWindowGroupLevel(winGroup, CGWindowLevelForKey(levelList[winLevel]));
892 window_fullscreen();
895 window_resized();
897 return 0;
900 static void check_events(void)
902 EventRef theEvent;
903 EventTargetRef theTarget;
904 OSStatus theErr;
906 //Get event
907 theTarget = GetEventDispatcherTarget();
908 theErr = ReceiveNextEvent(0, 0, kEventDurationNoWait,true, &theEvent);
909 if(theErr == noErr && theEvent != NULL)
911 SendEventToEventTarget (theEvent, theTarget);
912 ReleaseEvent(theEvent);
916 static void draw_osd(void)
918 vo_draw_text(imgRect.right,imgRect.bottom,draw_alpha);
921 static void flip_page(void)
923 int curTime;
924 static int lastTime = 0;
926 if(theWindow == NULL)
927 return;
929 switch (image_format)
931 case IMGFMT_RGB32:
933 CGContextDrawImage (context, bounds, image);
935 break;
937 case IMGFMT_YV12:
938 case IMGFMT_IYUV:
939 case IMGFMT_I420:
940 case IMGFMT_UYVY:
941 case IMGFMT_YUY2:
942 if (EnterMoviesDone)
944 OSErr qterr;
945 CodecFlags flags = 0;
946 qterr = DecompressSequenceFrameWhen(seqId,
947 (char *)P,
948 image_buffer_size,
949 0, //codecFlagUseImageBuffer,
950 &flags,
951 NULL,
952 NULL);
953 if (qterr)
955 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: DecompressSequenceFrameWhen in flip_page (%d) flags:0x%08x\n", qterr, flags);
958 break;
961 if(!vo_quartz_fs)
963 //render resize box
964 CGContextBeginPath(context);
965 CGContextSetAllowsAntialiasing(context, false);
966 //CGContextSaveGState(context);
968 //line white
969 CGContextSetRGBStrokeColor (context, 0.2, 0.2, 0.2, 0.5);
970 CGContextMoveToPoint( context, winRect.right-1, 1); CGContextAddLineToPoint( context, winRect.right-1, 1);
971 CGContextMoveToPoint( context, winRect.right-1, 5); CGContextAddLineToPoint( context, winRect.right-5, 1);
972 CGContextMoveToPoint( context, winRect.right-1, 9); CGContextAddLineToPoint( context, winRect.right-9, 1);
973 CGContextStrokePath( context );
975 //line gray
976 CGContextSetRGBStrokeColor (context, 0.4, 0.4, 0.4, 0.5);
977 CGContextMoveToPoint( context, winRect.right-1, 2); CGContextAddLineToPoint( context, winRect.right-2, 1);
978 CGContextMoveToPoint( context, winRect.right-1, 6); CGContextAddLineToPoint( context, winRect.right-6, 1);
979 CGContextMoveToPoint( context, winRect.right-1, 10); CGContextAddLineToPoint( context, winRect.right-10, 1);
980 CGContextStrokePath( context );
982 //line black
983 CGContextSetRGBStrokeColor (context, 0.6, 0.6, 0.6, 0.5);
984 CGContextMoveToPoint( context, winRect.right-1, 3); CGContextAddLineToPoint( context, winRect.right-3, 1);
985 CGContextMoveToPoint( context, winRect.right-1, 7); CGContextAddLineToPoint( context, winRect.right-7, 1);
986 CGContextMoveToPoint( context, winRect.right-1, 11); CGContextAddLineToPoint( context, winRect.right-11, 1);
987 CGContextStrokePath( context );
989 //CGContextRestoreGState( context );
990 CGContextFlush (context);
993 //auto hide mouse cursor and futur on-screen control?
994 if(vo_quartz_fs && !mouseHide)
996 int curTime = TickCount()/60;
997 static int lastTime = 0;
999 if( ((curTime - lastTime) >= 5) || (lastTime == 0) )
1001 CGDisplayHideCursor(kCGDirectMainDisplay);
1002 mouseHide = TRUE;
1003 lastTime = curTime;
1007 //update activity every 30 seconds to prevent
1008 //screensaver from starting up.
1009 curTime = TickCount()/60;
1011 if( ((curTime - lastTime) >= 30) || (lastTime == 0) )
1013 UpdateSystemActivity(UsrActivity);
1014 lastTime = curTime;
1018 static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
1020 switch (image_format)
1022 case IMGFMT_YV12:
1023 case IMGFMT_I420:
1024 memcpy_pic(((char*)P) + be2me_32(P->componentInfoY.offset) + x + imgRect.right * y, src[0], w, h, imgRect.right, stride[0]);
1025 x=x/2;y=y/2;w=w/2;h=h/2;
1027 memcpy_pic(((char*)P) + be2me_32(P->componentInfoCb.offset) + x + imgRect.right / 2 * y, src[1], w, h, imgRect.right / 2, stride[1]);
1028 memcpy_pic(((char*)P) + be2me_32(P->componentInfoCr.offset) + x + imgRect.right / 2 * y, src[2], w, h, imgRect.right / 2, stride[2]);
1029 return 0;
1031 case IMGFMT_IYUV:
1032 memcpy_pic(((char*)P) + be2me_32(P->componentInfoY.offset) + x + imgRect.right * y, src[0], w, h, imgRect.right, stride[0]);
1033 x=x/2;y=y/2;w=w/2;h=h/2;
1035 memcpy_pic(((char*)P) + be2me_32(P->componentInfoCr.offset) + x + imgRect.right / 2 * y, src[1], w, h, imgRect.right / 2, stride[1]);
1036 memcpy_pic(((char*)P) + be2me_32(P->componentInfoCb.offset) + x + imgRect.right / 2 * y, src[2], w, h, imgRect.right / 2, stride[2]);
1037 return 0;
1039 return -1;
1042 static int draw_frame(uint8_t *src[])
1044 switch (image_format)
1046 case IMGFMT_RGB32:
1047 fast_memcpy(image_data,src[0],image_size);
1048 return 0;
1050 case IMGFMT_UYVY:
1051 case IMGFMT_YUY2:
1052 memcpy_pic(((char*)P), src[0], imgRect.right * 2, imgRect.bottom, imgRect.right * 2, imgRect.right * 2);
1053 return 0;
1055 return -1;
1058 static int query_format(uint32_t format)
1060 image_format = format;
1061 image_qtcodec = 0;
1063 if (format == IMGFMT_RGB32)
1065 return VFCAP_CSP_SUPPORTED | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN;
1068 if ((format == IMGFMT_YV12) || (format == IMGFMT_IYUV) || (format == IMGFMT_I420))
1070 image_qtcodec = kMpegYUV420CodecType; //kYUV420CodecType ?;
1071 return VFCAP_CSP_SUPPORTED | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_ACCEPT_STRIDE;
1074 if (format == IMGFMT_YUY2)
1076 image_qtcodec = kComponentVideoUnsigned;
1077 return VFCAP_CSP_SUPPORTED | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN;
1080 if (format == IMGFMT_UYVY)
1082 image_qtcodec = k422YpCbCr8CodecType;
1083 return VFCAP_CSP_SUPPORTED | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN;
1086 return 0;
1089 static void uninit(void)
1091 OSErr qterr;
1093 switch (image_format)
1095 case IMGFMT_YV12:
1096 case IMGFMT_IYUV:
1097 case IMGFMT_I420:
1098 case IMGFMT_UYVY:
1099 case IMGFMT_YUY2:
1101 if (EnterMoviesDone)
1103 qterr = CDSequenceEnd(seqId);
1104 if (qterr)
1106 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: CDSequenceEnd (%d)\n", qterr);
1109 break;
1111 default:
1112 break;
1115 ShowMenuBar();
1118 static int preinit(const char *arg)
1120 int parse_err = 0;
1122 if(arg)
1124 char *parse_pos = (char *)&arg[0];
1125 while (parse_pos[0] && !parse_err)
1127 if (strncmp (parse_pos, "device_id=", 10) == 0)
1129 parse_pos = &parse_pos[10];
1130 device_id = strtol(parse_pos, &parse_pos, 0);
1132 if (strncmp (parse_pos, "fs_res=", 7) == 0)
1134 parse_pos = &parse_pos[7];
1135 fs_res_x = strtol(parse_pos, &parse_pos, 0);
1136 parse_pos = &parse_pos[1];
1137 fs_res_y = strtol(parse_pos, &parse_pos, 0);
1139 if (parse_pos[0] == ':') parse_pos = &parse_pos[1];
1140 else if (parse_pos[0]) parse_err = 1;
1144 #if !defined (MACOSX_FINDER_SUPPORT) || !defined (HAVE_SDL)
1145 //this chunk of code is heavily based off SDL_macosx.m from SDL
1146 //it uses an Apple private function to request foreground operation
1148 void CPSEnableForegroundOperation(ProcessSerialNumber* psn);
1149 ProcessSerialNumber myProc, frProc;
1150 Boolean sameProc;
1152 if (GetFrontProcess(&frProc) == noErr)
1154 if (GetCurrentProcess(&myProc) == noErr)
1156 if (SameProcess(&frProc, &myProc, &sameProc) == noErr && !sameProc)
1158 CPSEnableForegroundOperation(&myProc);
1160 SetFrontProcess(&myProc);
1164 #endif
1166 return 0;
1169 static uint32_t draw_yuv_image(mp_image_t *mpi)
1171 // ATM we're only called for planar IMGFMT
1172 // drawing is done directly in P
1173 // and displaying is in flip_page.
1174 return get_image_done ? VO_TRUE : VO_FALSE;
1177 static uint32_t get_yuv_image(mp_image_t *mpi)
1179 if(mpi->type!=MP_IMGTYPE_EXPORT) return VO_FALSE;
1181 if(mpi->imgfmt!=image_format) return VO_FALSE;
1183 if(mpi->flags&MP_IMGFLAG_PLANAR)
1185 if (mpi->num_planes != 3)
1187 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: only 3 planes allowed in get_yuv_image for planar (%d) \n", mpi->num_planes);
1188 return VO_FALSE;
1191 mpi->planes[0]=((char*)P) + be2me_32(P->componentInfoY.offset);
1192 mpi->stride[0]=imgRect.right;
1193 mpi->width=imgRect.right;
1195 if(mpi->flags&MP_IMGFLAG_SWAPPED)
1197 // I420
1198 mpi->planes[1]=((char*)P) + be2me_32(P->componentInfoCb.offset);
1199 mpi->planes[2]=((char*)P) + be2me_32(P->componentInfoCr.offset);
1200 mpi->stride[1]=imgRect.right/2;
1201 mpi->stride[2]=imgRect.right/2;
1203 else
1205 // YV12
1206 mpi->planes[1]=((char*)P) + be2me_32(P->componentInfoCr.offset);
1207 mpi->planes[2]=((char*)P) + be2me_32(P->componentInfoCb.offset);
1208 mpi->stride[1]=imgRect.right/2;
1209 mpi->stride[2]=imgRect.right/2;
1212 mpi->flags|=MP_IMGFLAG_DIRECT;
1213 get_image_done = 1;
1214 return VO_TRUE;
1216 else
1218 // doesn't work yet
1219 if (mpi->num_planes != 1)
1221 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: only 1 plane allowed in get_yuv_image for packed (%d) \n", mpi->num_planes);
1222 return VO_FALSE;
1225 mpi->planes[0] = (char*)P;
1226 mpi->stride[0] = imgRect.right * 2;
1227 mpi->width=imgRect.right;
1228 mpi->flags|=MP_IMGFLAG_DIRECT;
1229 get_image_done = 1;
1230 return VO_TRUE;
1232 return VO_FALSE;
1235 static int control(uint32_t request, void *data, ...)
1237 switch (request)
1239 case VOCTRL_PAUSE: return (int_pause=1);
1240 case VOCTRL_RESUME: return (int_pause=0);
1241 case VOCTRL_FULLSCREEN: vo_fs = (!(vo_fs)); window_fullscreen(); return VO_TRUE;
1242 case VOCTRL_ONTOP: vo_ontop = (!(vo_ontop)); window_ontop(); return VO_TRUE;
1243 case VOCTRL_QUERY_FORMAT: return query_format(*((uint32_t*)data));
1244 case VOCTRL_GET_PANSCAN: return VO_TRUE;
1245 case VOCTRL_SET_PANSCAN: window_panscan(); return VO_TRUE;
1247 case VOCTRL_GET_IMAGE:
1248 switch (image_format)
1250 case IMGFMT_YV12:
1251 case IMGFMT_IYUV:
1252 case IMGFMT_I420:
1253 case IMGFMT_UYVY:
1254 case IMGFMT_YUY2:
1255 return get_yuv_image(data);
1256 break;
1257 default:
1258 break;
1260 case VOCTRL_DRAW_IMAGE:
1261 switch (image_format)
1263 case IMGFMT_YV12:
1264 case IMGFMT_IYUV:
1265 case IMGFMT_I420:
1266 case IMGFMT_UYVY:
1267 case IMGFMT_YUY2:
1268 return draw_yuv_image(data);
1269 break;
1270 default:
1271 break;
1274 return VO_NOTIMPL;
1277 void window_resized()
1279 float aspectX;
1280 float aspectY;
1282 int padding = 0;
1284 uint32_t d_width;
1285 uint32_t d_height;
1287 CGRect tmpBounds;
1289 GetPortBounds( GetWindowPort(theWindow), &winRect );
1291 if(vo_keepaspect)
1293 aspect( &d_width, &d_height, A_NOZOOM);
1294 d_height = ((float)d_width/movie_aspect);
1296 aspectX = (float)((float)winRect.right/(float)d_width);
1297 aspectY = (float)((float)(winRect.bottom)/(float)d_height);
1299 if((d_height*aspectX)>(winRect.bottom))
1301 padding = (winRect.right - d_width*aspectY)/2;
1302 SetRect(&dstRect, padding, 0, d_width*aspectY+padding, d_height*aspectY);
1304 else
1306 padding = ((winRect.bottom) - d_height*aspectX)/2;
1307 SetRect(&dstRect, 0, padding, (d_width*aspectX), d_height*aspectX+padding);
1310 else
1312 SetRect(&dstRect, 0, 0, winRect.right, winRect.bottom);
1315 switch (image_format)
1317 case IMGFMT_RGB32:
1319 bounds = CGRectMake(dstRect.left, dstRect.top, dstRect.right-dstRect.left, dstRect.bottom-dstRect.top);
1320 CreateCGContextForPort (GetWindowPort (theWindow), &context);
1321 break;
1323 case IMGFMT_YV12:
1324 case IMGFMT_IYUV:
1325 case IMGFMT_I420:
1326 case IMGFMT_UYVY:
1327 case IMGFMT_YUY2:
1329 long scale_X = FixDiv(Long2Fix(dstRect.right - dstRect.left),Long2Fix(imgRect.right));
1330 long scale_Y = FixDiv(Long2Fix(dstRect.bottom - dstRect.top),Long2Fix(imgRect.bottom));
1332 SetIdentityMatrix(&matrix);
1333 if (((dstRect.right - dstRect.left) != imgRect.right) || ((dstRect.bottom - dstRect.right) != imgRect.bottom))
1335 ScaleMatrix(&matrix, scale_X, scale_Y, 0, 0);
1337 if (padding > 0)
1339 TranslateMatrix(&matrix, Long2Fix(dstRect.left), Long2Fix(dstRect.top));
1343 SetDSequenceMatrix(seqId, &matrix);
1344 break;
1346 default:
1347 break;
1350 //Clear Background
1351 tmpBounds = CGRectMake( 0, 0, winRect.right, winRect.bottom);
1352 CreateCGContextForPort(GetWindowPort(theWindow),&context);
1353 CGContextFillRect(context, tmpBounds);
1356 void window_ontop()
1358 if(!vo_quartz_fs)
1360 //Cycle between level
1361 winLevel++;
1362 if(winLevel>2)
1363 winLevel = 1;
1365 SetWindowGroupLevel(winGroup, CGWindowLevelForKey(levelList[winLevel]));
1368 void window_fullscreen()
1370 static Ptr restoreState = NULL;
1372 //go fullscreen
1373 if(vo_fs)
1375 if(winLevel != 0)
1377 if(device_id == 0)
1379 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
1380 CGDisplayHideCursor(kCGDirectMainDisplay);
1381 mouseHide = TRUE;
1384 if(fs_res_x != 0 || fs_res_y != 0)
1386 BeginFullScreen( &restoreState, deviceHdl, &fs_res_x, &fs_res_y, NULL, NULL, 0);
1388 //Get Main device info///////////////////////////////////////////////////
1389 deviceRect = (*deviceHdl)->gdRect;
1391 device_width = deviceRect.right;
1392 device_height = deviceRect.bottom;
1396 //save old window size
1397 if (!vo_quartz_fs)
1399 GetWindowPortBounds(theWindow, &oldWinRect);
1400 GetWindowBounds(theWindow, kWindowContentRgn, &oldWinBounds);
1403 //go fullscreen
1404 panscan_calc();
1405 ChangeWindowAttributes(theWindow, kWindowNoShadowAttribute, 0);
1406 MoveWindow(theWindow, deviceRect.left-(vo_panscan_x >> 1), deviceRect.top-(vo_panscan_y >> 1), 1);
1407 SizeWindow(theWindow, device_width+vo_panscan_x, device_height+vo_panscan_y,1);
1409 vo_quartz_fs = 1;
1411 else //go back to windowed mode
1413 vo_quartz_fs = 0;
1414 if(restoreState != NULL)
1416 EndFullScreen(restoreState, 0);
1418 //Get Main device info///////////////////////////////////////////////////
1419 deviceRect = (*deviceHdl)->gdRect;
1421 device_width = deviceRect.right;
1422 device_height = deviceRect.bottom;
1423 restoreState = NULL;
1425 SetSystemUIMode( kUIModeNormal, 0);
1427 //show mouse cursor
1428 CGDisplayShowCursor(kCGDirectMainDisplay);
1429 mouseHide = FALSE;
1431 //revert window to previous setting
1432 ChangeWindowAttributes(theWindow, 0, kWindowNoShadowAttribute);
1433 SizeWindow(theWindow, oldWinRect.right, oldWinRect.bottom,1);
1434 MoveWindow(theWindow, oldWinBounds.left, oldWinBounds.top, 1);
1436 window_resized();
1439 void window_panscan()
1441 panscan_calc();
1443 if(vo_panscan > 0)
1444 CheckMenuItem (aspectMenu, 2, 1);
1445 else
1446 CheckMenuItem (aspectMenu, 2, 0);
1448 if(vo_quartz_fs)
1450 MoveWindow(theWindow, deviceRect.left-(vo_panscan_x >> 1), deviceRect.top-(vo_panscan_y >> 1), 1);
1451 SizeWindow(theWindow, device_width+vo_panscan_x, device_height+vo_panscan_y,1);