configure: Improve pkg-config tests for FFmpeg libraries
[mplayer.git] / libvo / vo_quartz.c
blob4aa3ac289b9382f6f6f68fd64c7855d87b955a72
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 /**
20 \author Nicolas Plourde <nicolasplourde@gmail.com>
22 Copyright (c) Nicolas Plourde - April 2004
24 YUV support Copyright (C) 2004 Romain Dolbeau <romain@dolbeau.org>
26 \brief MPlayer Mac OSX Quartz video out module.
28 \todo: -screen overlay output
29 -fit osd in black bar when available
30 -fix RGB32
31 -(add sugestion here)
34 //SYS
35 #include <stdio.h>
37 //OSX
38 #include <Carbon/Carbon.h>
39 #include <QuickTime/QuickTime.h>
41 //MPLAYER
42 #include "config.h"
43 #include "fastmemcpy.h"
44 #include "video_out.h"
45 #include "video_out_internal.h"
46 #include "aspect.h"
47 #include "mp_msg.h"
48 #include "m_option.h"
49 #include "mp_fifo.h"
50 #include "mpbswap.h"
51 #include "sub.h"
53 #include "input/input.h"
54 #include "input/mouse.h"
56 #include "vo_quartz.h"
58 static const vo_info_t info =
60 "Mac OSX (Quartz)",
61 "quartz",
62 "Nicolas Plourde <nicolasplourde@hotmail.com>, Romain Dolbeau <romain@dolbeau.org>",
66 const LIBVO_EXTERN(quartz)
68 static uint32_t image_depth;
69 static uint32_t image_format;
70 static uint32_t image_size;
71 static uint32_t image_buffer_size;
72 static char *image_data;
74 static ImageSequence seqId;
75 static CodecType image_qtcodec;
76 static PlanarPixmapInfoYUV420 *P = NULL;
77 static struct
79 ImageDescriptionHandle desc;
80 Handle extension_colr;
81 Handle extension_fiel;
82 Handle extension_clap;
83 Handle extension_pasp;
84 } yuv_qt_stuff;
85 static MatrixRecord matrix;
86 static int EnterMoviesDone = 0;
87 static int get_image_done = 0;
89 static int vo_quartz_fs; // we are in fullscreen
90 static float old_movie_aspect;
92 static int winLevel = 1;
93 int levelList[] =
95 kCGDesktopWindowLevelKey,
96 kCGNormalWindowLevelKey,
97 kCGScreenSaverWindowLevelKey
100 static int int_pause = 0;
101 static float winAlpha = 1;
102 static int mouseHide = FALSE;
104 static int device_id = 0;
106 static short fs_res_x = 0;
107 static short fs_res_y = 0;
109 static WindowRef theWindow = NULL;
110 static WindowGroupRef winGroup = NULL;
111 static CGRect bounds;
112 static CGDirectDisplayID displayId = 0;
113 static CFDictionaryRef originalMode = NULL;
115 static CGDataProviderRef dataProviderRef = NULL;
116 static CGImageRef image = NULL;
118 static Rect imgRect; // size of the original image (unscaled)
119 static Rect dstRect; // size of the displayed image (after scaling)
120 static Rect winRect; // size of the window containg the displayed image (include padding)
121 static Rect oldWinRect; // size of the window containg the displayed image (include padding) when NOT in FS mode
122 static CGRect displayRect; // size of the display device
123 static Rect oldWinBounds;
125 static MenuRef windMenu;
126 static MenuRef movMenu;
127 static MenuRef aspectMenu;
129 static int lastScreensaverUpdate = 0;
130 static int lastMouseHide = 0;
132 enum
134 kQuitCmd = 1,
135 kHalfScreenCmd = 2,
136 kNormalScreenCmd = 3,
137 kDoubleScreenCmd = 4,
138 kFullScreenCmd = 5,
139 kKeepAspectCmd = 6,
140 kAspectOrgCmd = 7,
141 kAspectFullCmd = 8,
142 kAspectWideCmd = 9,
143 kPanScanCmd = 10
146 #include "osdep/keycodes.h"
148 //PROTOTYPE/////////////////////////////////////////////////////////////////
149 static OSStatus KeyEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
150 static OSStatus MouseEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
151 static OSStatus WindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
152 void window_resized(void);
153 void window_ontop(void);
154 void window_fullscreen(void);
155 void window_panscan(void);
157 static inline int convert_key(UInt32 key, UInt32 charcode)
159 switch (key)
161 case QZ_IBOOK_ENTER:
162 case QZ_RETURN: return KEY_ENTER;
163 case QZ_ESCAPE: return KEY_ESC;
164 case QZ_BACKSPACE: return KEY_BACKSPACE;
165 case QZ_LALT: return KEY_BACKSPACE;
166 case QZ_LCTRL: return KEY_BACKSPACE;
167 case QZ_LSHIFT: return KEY_BACKSPACE;
168 case QZ_F1: return KEY_F + 1;
169 case QZ_F2: return KEY_F + 2;
170 case QZ_F3: return KEY_F + 3;
171 case QZ_F4: return KEY_F + 4;
172 case QZ_F5: return KEY_F + 5;
173 case QZ_F6: return KEY_F + 6;
174 case QZ_F7: return KEY_F + 7;
175 case QZ_F8: return KEY_F + 8;
176 case QZ_F9: return KEY_F + 9;
177 case QZ_F10: return KEY_F + 10;
178 case QZ_F11: return KEY_F + 11;
179 case QZ_F12: return KEY_F + 12;
180 case QZ_INSERT: return KEY_INSERT;
181 case QZ_DELETE: return KEY_DELETE;
182 case QZ_HOME: return KEY_HOME;
183 case QZ_END: return KEY_END;
184 case QZ_KP_PLUS: return '+';
185 case QZ_KP_MINUS: return '-';
186 case QZ_TAB: return KEY_TAB;
187 case QZ_PAGEUP: return KEY_PAGE_UP;
188 case QZ_PAGEDOWN: return KEY_PAGE_DOWN;
189 case QZ_UP: return KEY_UP;
190 case QZ_DOWN: return KEY_DOWN;
191 case QZ_LEFT: return KEY_LEFT;
192 case QZ_RIGHT: return KEY_RIGHT;
193 case QZ_KP_MULTIPLY: return '*';
194 case QZ_KP_DIVIDE: return '/';
195 case QZ_KP_ENTER: return KEY_KPENTER;
196 case QZ_KP_PERIOD: return KEY_KPDEC;
197 case QZ_KP0: return KEY_KP0;
198 case QZ_KP1: return KEY_KP1;
199 case QZ_KP2: return KEY_KP2;
200 case QZ_KP3: return KEY_KP3;
201 case QZ_KP4: return KEY_KP4;
202 case QZ_KP5: return KEY_KP5;
203 case QZ_KP6: return KEY_KP6;
204 case QZ_KP7: return KEY_KP7;
205 case QZ_KP8: return KEY_KP8;
206 case QZ_KP9: return KEY_KP9;
207 default: return charcode;
211 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride)
213 switch (image_format)
215 case IMGFMT_RGB32:
216 vo_draw_alpha_rgb32(w, h, src, srca, stride, image_data + 4 * (y0 * imgRect.right + x0), 4 * imgRect.right);
217 break;
218 case IMGFMT_YV12:
219 case IMGFMT_IYUV:
220 case IMGFMT_I420:
221 vo_draw_alpha_yv12(w, h, src, srca, stride, ((char *)P) + be2me_32(P->componentInfoY.offset) + x0 + y0 * imgRect.right, imgRect.right);
222 break;
223 case IMGFMT_UYVY:
224 vo_draw_alpha_uyvy(w, h, src, srca, stride, ((char *)P) + (x0 + y0 * imgRect.right) * 2, imgRect.right * 2);
225 break;
226 case IMGFMT_YUY2:
227 vo_draw_alpha_yuy2(w, h, src, srca, stride, ((char *)P) + (x0 + y0 * imgRect.right) * 2, imgRect.right * 2);
228 break;
232 //default keyboard event handler
233 static OSStatus KeyEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
235 OSStatus result = noErr;
236 UInt32 class = GetEventClass(event);
237 UInt32 kind = GetEventKind(event);
239 result = CallNextEventHandler(nextHandler, event);
241 if (class == kEventClassKeyboard)
243 char macCharCodes;
244 UInt32 macKeyCode;
245 UInt32 macKeyModifiers;
247 GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(macCharCodes), NULL, &macCharCodes);
248 GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(macKeyCode), NULL, &macKeyCode);
249 GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(macKeyModifiers), NULL, &macKeyModifiers);
251 if (macKeyModifiers != 256)
253 if (kind == kEventRawKeyRepeat || kind == kEventRawKeyDown)
255 int key = convert_key(macKeyCode, macCharCodes);
257 if (key != -1)
258 mplayer_put_key(key);
261 else if (macKeyModifiers == 256)
263 switch (macCharCodes)
265 case '[': SetWindowAlpha(theWindow, winAlpha -= 0.05); break;
266 case ']': SetWindowAlpha(theWindow, winAlpha += 0.05); break;
269 else
270 result = eventNotHandledErr;
273 return result;
276 //default mouse event handler
277 static OSStatus MouseEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
279 OSStatus result = noErr;
280 UInt32 class = GetEventClass(event);
281 UInt32 kind = GetEventKind(event);
283 result = CallNextEventHandler(nextHandler, event);
285 if (class == kEventClassMouse)
287 WindowPtr tmpWin;
288 Point mousePos;
289 Point winMousePos;
291 GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, 0, sizeof(Point), 0, &mousePos);
292 GetEventParameter(event, kEventParamWindowMouseLocation, typeQDPoint, 0, sizeof(Point), 0, &winMousePos);
294 switch (kind)
296 case kEventMouseMoved:
298 if (vo_quartz_fs)
300 CGDisplayShowCursor(displayId);
301 mouseHide = FALSE;
304 break;
306 case kEventMouseWheelMoved:
308 int wheel;
309 short part;
311 GetEventParameter(event, kEventParamMouseWheelDelta, typeSInt32, 0, sizeof(int), 0, &wheel);
313 part = FindWindow(mousePos, &tmpWin);
315 if (part == inContent)
317 if (wheel > 0)
318 mplayer_put_key(MOUSE_BTN3);
319 else
320 mplayer_put_key(MOUSE_BTN4);
323 break;
325 case kEventMouseDown:
326 case kEventMouseUp:
328 EventMouseButton button;
329 short part;
330 Rect bounds;
332 GetWindowPortBounds(theWindow, &bounds);
333 GetEventParameter(event, kEventParamMouseButton, typeMouseButton, 0, sizeof(EventMouseButton), 0, &button);
335 part = FindWindow(mousePos, &tmpWin);
336 if (kind == kEventMouseUp)
338 if (part != inContent)
339 break;
340 switch (button)
342 case kEventMouseButtonPrimary:
343 mplayer_put_key(MOUSE_BTN0);
344 break;
345 case kEventMouseButtonSecondary:
346 mplayer_put_key(MOUSE_BTN2);
347 break;
348 case kEventMouseButtonTertiary:
349 mplayer_put_key(MOUSE_BTN1);
350 break;
352 default:
353 result = eventNotHandledErr;
354 break;
356 break;
358 if ((winMousePos.h > (bounds.right - 15)) && (winMousePos.v > (bounds.bottom)))
360 if (!vo_quartz_fs)
362 Rect newSize;
364 ResizeWindow(theWindow, mousePos, NULL, &newSize);
367 else if (part == inMenuBar)
369 MenuSelect(mousePos);
370 HiliteMenu(0);
372 else if (part == inContent)
374 switch (button)
376 case kEventMouseButtonPrimary:
377 mplayer_put_key(MOUSE_BTN0 | MP_KEY_DOWN);
378 break;
379 case kEventMouseButtonSecondary:
380 mplayer_put_key(MOUSE_BTN2 | MP_KEY_DOWN);
381 break;
382 case kEventMouseButtonTertiary:
383 mplayer_put_key(MOUSE_BTN1 | MP_KEY_DOWN);
384 break;
386 default:
387 result = eventNotHandledErr;
388 break;
392 break;
394 case kEventMouseDragged:
395 break;
397 default:
398 result = eventNotHandledErr;
399 break;
403 return result;
406 //default window event handler
407 static OSStatus WindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
409 OSStatus result = noErr;
410 uint32_t d_width;
411 uint32_t d_height;
412 UInt32 class = GetEventClass(event);
413 UInt32 kind = GetEventKind(event);
415 result = CallNextEventHandler(nextHandler, event);
417 aspect(&d_width, &d_height, A_NOZOOM);
419 if (class == kEventClassCommand)
421 HICommand theHICommand;
423 GetEventParameter(event, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &theHICommand);
425 switch (theHICommand.commandID)
427 case kHICommandQuit:
428 mplayer_put_key(KEY_CLOSE_WIN);
429 break;
431 case kHalfScreenCmd:
432 if (vo_quartz_fs)
434 vo_fs = (!(vo_fs));
435 window_fullscreen();
438 SizeWindow(theWindow, (d_width / 2), ((d_width / movie_aspect) / 2), 1);
439 window_resized();
440 break;
442 case kNormalScreenCmd:
443 if (vo_quartz_fs)
445 vo_fs = (!(vo_fs));
446 window_fullscreen();
449 SizeWindow(theWindow, d_width, (d_width / movie_aspect), 1);
450 window_resized();
451 break;
453 case kDoubleScreenCmd:
454 if (vo_quartz_fs)
456 vo_fs = (!(vo_fs));
457 window_fullscreen();
460 SizeWindow(theWindow, (d_width * 2), ((d_width / movie_aspect) * 2), 1);
461 window_resized();
462 break;
464 case kFullScreenCmd:
465 vo_fs = (!(vo_fs));
466 window_fullscreen();
467 break;
469 case kKeepAspectCmd:
470 vo_keepaspect = (!(vo_keepaspect));
471 CheckMenuItem(aspectMenu, 1, vo_keepaspect);
472 window_resized();
473 break;
475 case kAspectOrgCmd:
476 movie_aspect = old_movie_aspect;
477 if (!vo_quartz_fs)
479 SizeWindow(theWindow, dstRect.right, (dstRect.right / movie_aspect), 1);
481 window_resized();
482 break;
484 case kAspectFullCmd:
485 movie_aspect = 4.0f / 3.0f;
486 if (!vo_quartz_fs)
488 SizeWindow(theWindow, dstRect.right, (dstRect.right / movie_aspect), 1);
490 window_resized();
491 break;
493 case kAspectWideCmd:
494 movie_aspect = 16.0f / 9.0f;
495 if (!vo_quartz_fs)
497 SizeWindow(theWindow, dstRect.right, (dstRect.right / movie_aspect), 1);
499 window_resized();
500 break;
502 case kPanScanCmd:
503 vo_panscan = (!(vo_panscan));
504 CheckMenuItem(aspectMenu, 2, vo_panscan);
505 window_panscan();
506 window_resized();
507 break;
509 default:
510 result = eventNotHandledErr;
511 break;
514 else if (class == kEventClassWindow)
516 WindowRef window;
517 Rect rectWindow = { 0, 0, 0, 0 };
519 GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window);
521 if (window)
523 GetWindowBounds(window, kWindowGlobalPortRgn, &rectWindow);
526 switch (kind)
528 case kEventWindowClosed:
529 theWindow = NULL;
530 mplayer_put_key(KEY_CLOSE_WIN);
531 break;
533 // resize window
534 case kEventWindowZoomed:
535 case kEventWindowBoundsChanged:
536 window_resized();
537 flip_page();
538 window_resized();
539 break;
541 default:
542 result = eventNotHandledErr;
543 break;
547 return result;
550 static void quartz_CreateWindow(uint32_t d_width, uint32_t d_height, WindowAttributes windowAttrs)
552 CFStringRef titleKey;
553 CFStringRef windowTitle;
554 OSStatus result;
556 MenuItemIndex index;
557 CFStringRef movMenuTitle;
558 CFStringRef aspMenuTitle;
560 const EventTypeSpec win_events[] = {
561 {kEventClassWindow, kEventWindowClosed},
562 {kEventClassWindow, kEventWindowBoundsChanged},
563 {kEventClassCommand, kEventCommandProcess}
566 const EventTypeSpec key_events[] = {
567 {kEventClassKeyboard, kEventRawKeyDown},
568 {kEventClassKeyboard, kEventRawKeyRepeat}
571 const EventTypeSpec mouse_events[] = {
572 {kEventClassMouse, kEventMouseMoved},
573 {kEventClassMouse, kEventMouseWheelMoved},
574 {kEventClassMouse, kEventMouseDown},
575 {kEventClassMouse, kEventMouseUp},
576 {kEventClassMouse, kEventMouseDragged}
579 SetRect(&winRect, 0, 0, d_width, d_height);
580 SetRect(&oldWinRect, 0, 0, d_width, d_height);
581 SetRect(&dstRect, 0, 0, d_width, d_height);
583 // Clear Menu Bar
584 ClearMenuBar();
586 // Create Window Menu
587 CreateStandardWindowMenu(0, &windMenu);
588 InsertMenu(windMenu, 0);
590 // Create Movie Menu
591 CreateNewMenu(1004, 0, &movMenu);
592 movMenuTitle = CFSTR("Movie");
593 SetMenuTitleWithCFString(movMenu, movMenuTitle);
595 AppendMenuItemTextWithCFString(movMenu, CFSTR("Half Size"), 0, kHalfScreenCmd, &index);
596 SetMenuItemCommandKey(movMenu, index, 0, '0');
598 AppendMenuItemTextWithCFString(movMenu, CFSTR("Normal Size"), 0, kNormalScreenCmd, &index);
599 SetMenuItemCommandKey(movMenu, index, 0, '1');
601 AppendMenuItemTextWithCFString(movMenu, CFSTR("Double Size"), 0, kDoubleScreenCmd, &index);
602 SetMenuItemCommandKey(movMenu, index, 0, '2');
604 AppendMenuItemTextWithCFString(movMenu, CFSTR("Full Size"), 0, kFullScreenCmd, &index);
605 SetMenuItemCommandKey(movMenu, index, 0, 'F');
607 AppendMenuItemTextWithCFString(movMenu, NULL, kMenuItemAttrSeparator, 0, &index);
609 AppendMenuItemTextWithCFString(movMenu, CFSTR("Aspect Ratio"), 0, 0, &index);
611 //// Create Aspect Ratio Sub Menu
612 CreateNewMenu(0, 0, &aspectMenu);
613 aspMenuTitle = CFSTR("Aspect Ratio");
614 SetMenuTitleWithCFString(aspectMenu, aspMenuTitle);
615 SetMenuItemHierarchicalMenu(movMenu, 6, aspectMenu);
617 AppendMenuItemTextWithCFString(aspectMenu, CFSTR("Keep"), 0, kKeepAspectCmd, &index);
618 CheckMenuItem(aspectMenu, 1, vo_keepaspect);
619 AppendMenuItemTextWithCFString(aspectMenu, CFSTR("Pan-Scan"), 0, kPanScanCmd, &index);
620 CheckMenuItem(aspectMenu, 2, vo_panscan);
621 AppendMenuItemTextWithCFString(aspectMenu, NULL, kMenuItemAttrSeparator, 0, &index);
622 AppendMenuItemTextWithCFString(aspectMenu, CFSTR("Original"), 0, kAspectOrgCmd, &index);
623 AppendMenuItemTextWithCFString(aspectMenu, CFSTR("4:3"), 0, kAspectFullCmd, &index);
624 AppendMenuItemTextWithCFString(aspectMenu, CFSTR("16:9"), 0, kAspectWideCmd, &index);
626 InsertMenu(movMenu, GetMenuID(windMenu)); //insert before Window menu
628 DrawMenuBar();
630 // create window
631 CreateNewWindow(kDocumentWindowClass, windowAttrs, &winRect, &theWindow);
633 CreateWindowGroup(0, &winGroup);
634 SetWindowGroup(theWindow, winGroup);
636 // Set window title
637 titleKey = CFSTR("MPlayer - The Movie Player");
638 windowTitle = CFCopyLocalizedString(titleKey, NULL);
639 result = SetWindowTitleWithCFString(theWindow, windowTitle);
640 CFRelease(titleKey);
641 CFRelease(windowTitle);
643 // Install event handler
644 InstallApplicationEventHandler(NewEventHandlerUPP(KeyEventHandler), GetEventTypeCount(key_events), key_events, NULL, NULL);
645 InstallApplicationEventHandler(NewEventHandlerUPP(MouseEventHandler), GetEventTypeCount(mouse_events), mouse_events, NULL, NULL);
646 InstallWindowEventHandler(theWindow, NewEventHandlerUPP(WindowEventHandler), GetEventTypeCount(win_events), win_events, theWindow, NULL);
649 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)
651 WindowAttributes windowAttrs;
652 OSErr qterr;
653 CGRect tmpBounds;
654 CGDisplayCount displayCount;
655 CGDirectDisplayID *displays;
657 // Get Main device info///////////////////////////////////////////////////
659 // Display IDs might not be consecutive, get the list of all devices up to # device_id
660 displayCount = device_id + 1;
661 displays = malloc(sizeof(CGDirectDisplayID) * displayCount);
662 if (kCGErrorSuccess != CGGetActiveDisplayList(displayCount, displays, &displayCount) || displayCount < device_id + 1) {
663 mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: Device ID %d do not exist, falling back to main device.\n", device_id);
664 displayId = kCGDirectMainDisplay;
665 device_id = 0;
667 else
669 displayId = displays[device_id];
671 free(displays);
673 displayRect = CGDisplayBounds(displayId);
675 monitor_aspect = (float)displayRect.size.width / (float)displayRect.size.height;
677 // misc mplayer setup/////////////////////////////////////////////////////
678 SetRect(&imgRect, 0, 0, width, height);
679 switch (image_format)
681 case IMGFMT_RGB32:
682 image_depth = 32;
683 break;
684 case IMGFMT_YV12:
685 case IMGFMT_IYUV:
686 case IMGFMT_I420:
687 case IMGFMT_UYVY:
688 case IMGFMT_YUY2:
689 image_depth = 16;
690 break;
692 image_size = ((imgRect.right * imgRect.bottom * image_depth) + 7) / 8;
694 vo_fs = flags & VOFLAG_FULLSCREEN;
696 // get movie aspect
697 panscan_init();
698 aspect_save_orig(width, height);
699 aspect_save_prescale(d_width, d_height);
700 aspect_save_screenres(displayRect.size.width, displayRect.size.height);
702 aspect(&d_width, &d_height, A_NOZOOM);
704 movie_aspect = (float)d_width / (float)d_height;
705 old_movie_aspect = movie_aspect;
707 if (image_data)
708 free(image_data);
710 image_data = malloc(image_size);
712 // Create player window//////////////////////////////////////////////////
713 windowAttrs = kWindowStandardDocumentAttributes
714 | kWindowStandardHandlerAttribute
715 | kWindowLiveResizeAttribute;
717 windowAttrs &= (~kWindowResizableAttribute);
719 if (theWindow == NULL)
721 CGContextRef context;
723 quartz_CreateWindow(d_width, d_height, windowAttrs);
725 if (theWindow == NULL)
727 mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: Couldn't create window !!!!!\n");
728 return -1;
730 tmpBounds = CGRectMake(0, 0, winRect.right, winRect.bottom);
731 QDBeginCGContext(GetWindowPort(theWindow), &context);
732 CGContextFillRect(context, tmpBounds);
733 QDEndCGContext(GetWindowPort(theWindow), &context);
735 else
737 HideWindow(theWindow);
738 ChangeWindowAttributes(theWindow, ~windowAttrs, windowAttrs);
739 SetRect(&winRect, 0, 0, d_width, d_height);
740 SetRect(&oldWinRect, 0, 0, d_width, d_height);
741 SizeWindow(theWindow, d_width, d_height, 1);
744 switch (image_format)
746 case IMGFMT_RGB32:
748 CGContextRef context;
750 QDBeginCGContext(GetWindowPort(theWindow), &context);
752 dataProviderRef = CGDataProviderCreateWithData(0, image_data, imgRect.right * imgRect.bottom * 4, 0);
754 image = CGImageCreate(imgRect.right,
755 imgRect.bottom,
757 image_depth,
758 ((imgRect.right * 32) + 7) / 8,
759 CGColorSpaceCreateDeviceRGB(),
760 kCGImageAlphaNoneSkipFirst,
761 dataProviderRef, 0, 1, kCGRenderingIntentDefault);
763 QDEndCGContext(GetWindowPort(theWindow), &context);
764 break;
767 case IMGFMT_YV12:
768 case IMGFMT_IYUV:
769 case IMGFMT_I420:
770 case IMGFMT_UYVY:
771 case IMGFMT_YUY2:
773 get_image_done = 0;
775 if (!EnterMoviesDone)
777 qterr = EnterMovies();
778 EnterMoviesDone = 1;
780 else
781 qterr = 0;
783 if (qterr)
785 mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: EnterMovies (%d)\n", qterr);
786 return -1;
790 SetIdentityMatrix(&matrix);
792 if ((d_width != width) || (d_height != height))
794 ScaleMatrix(&matrix, FixDiv(Long2Fix(d_width), Long2Fix(width)), FixDiv(Long2Fix(d_height), Long2Fix(height)), 0, 0);
797 yuv_qt_stuff.desc = (ImageDescriptionHandle) NewHandleClear(sizeof(ImageDescription));
799 yuv_qt_stuff.extension_colr = NewHandleClear(sizeof(NCLCColorInfoImageDescriptionExtension));
800 ((NCLCColorInfoImageDescriptionExtension *) (*yuv_qt_stuff.extension_colr))->colorParamType = kVideoColorInfoImageDescriptionExtensionType;
801 ((NCLCColorInfoImageDescriptionExtension *) (*yuv_qt_stuff.extension_colr))->primaries = 2;
802 ((NCLCColorInfoImageDescriptionExtension *) (*yuv_qt_stuff.extension_colr))->transferFunction = 2;
803 ((NCLCColorInfoImageDescriptionExtension *) (*yuv_qt_stuff.extension_colr))->matrix = 2;
805 yuv_qt_stuff.extension_fiel = NewHandleClear(sizeof(FieldInfoImageDescriptionExtension));
806 ((FieldInfoImageDescriptionExtension *) (*yuv_qt_stuff.extension_fiel))->fieldCount = 1;
807 ((FieldInfoImageDescriptionExtension *) (*yuv_qt_stuff.extension_fiel))->fieldOrderings = 0;
809 yuv_qt_stuff.extension_clap = NewHandleClear(sizeof(CleanApertureImageDescriptionExtension));
810 ((CleanApertureImageDescriptionExtension *) (*yuv_qt_stuff.extension_clap))->cleanApertureWidthN = imgRect.right;
811 ((CleanApertureImageDescriptionExtension *) (*yuv_qt_stuff.extension_clap))->cleanApertureWidthD = 1;
812 ((CleanApertureImageDescriptionExtension *) (*yuv_qt_stuff.extension_clap))->cleanApertureHeightN = imgRect.bottom;
813 ((CleanApertureImageDescriptionExtension *) (*yuv_qt_stuff.extension_clap))->cleanApertureHeightD = 1;
814 ((CleanApertureImageDescriptionExtension *) (*yuv_qt_stuff.extension_clap))->horizOffN = 0;
815 ((CleanApertureImageDescriptionExtension *) (*yuv_qt_stuff.extension_clap))->horizOffD = 1;
816 ((CleanApertureImageDescriptionExtension *) (*yuv_qt_stuff.extension_clap))->vertOffN = 0;
817 ((CleanApertureImageDescriptionExtension *) (*yuv_qt_stuff.extension_clap))->vertOffD = 1;
819 yuv_qt_stuff.extension_pasp = NewHandleClear(sizeof(PixelAspectRatioImageDescriptionExtension));
820 ((PixelAspectRatioImageDescriptionExtension *) (*yuv_qt_stuff.extension_pasp))->hSpacing = 1;
821 ((PixelAspectRatioImageDescriptionExtension *) (*yuv_qt_stuff.extension_pasp))->vSpacing = 1;
823 (*yuv_qt_stuff.desc)->idSize = sizeof(ImageDescription);
824 (*yuv_qt_stuff.desc)->cType = image_qtcodec;
825 (*yuv_qt_stuff.desc)->version = 2;
826 (*yuv_qt_stuff.desc)->revisionLevel = 0;
827 (*yuv_qt_stuff.desc)->vendor = 'mpla';
828 (*yuv_qt_stuff.desc)->width = imgRect.right;
829 (*yuv_qt_stuff.desc)->height = imgRect.bottom;
830 (*yuv_qt_stuff.desc)->hRes = Long2Fix(72);
831 (*yuv_qt_stuff.desc)->vRes = Long2Fix(72);
832 (*yuv_qt_stuff.desc)->temporalQuality = 0;
833 (*yuv_qt_stuff.desc)->spatialQuality = codecLosslessQuality;
834 (*yuv_qt_stuff.desc)->frameCount = 1;
835 (*yuv_qt_stuff.desc)->dataSize = 0;
836 (*yuv_qt_stuff.desc)->depth = 24;
837 (*yuv_qt_stuff.desc)->clutID = -1;
839 qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_colr, kColorInfoImageDescriptionExtension);
840 if (qterr)
842 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [colr] (%d)\n", qterr);
845 qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_fiel, kFieldInfoImageDescriptionExtension);
846 if (qterr)
848 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [fiel] (%d)\n", qterr);
851 qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_clap, kCleanApertureImageDescriptionExtension);
852 if (qterr)
854 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [clap] (%d)\n", qterr);
857 qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_pasp, kCleanApertureImageDescriptionExtension);
858 if (qterr)
860 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [pasp] (%d)\n", qterr);
862 if (P != NULL) { // second or subsequent movie
863 free(P);
865 P = calloc(sizeof(PlanarPixmapInfoYUV420) + image_size, 1);
866 switch (image_format)
868 case IMGFMT_YV12:
869 case IMGFMT_IYUV:
870 case IMGFMT_I420:
871 P->componentInfoY.offset = be2me_32(sizeof(PlanarPixmapInfoYUV420));
872 P->componentInfoCb.offset = be2me_32(be2me_32(P->componentInfoY.offset) + image_size / 2);
873 P->componentInfoCr.offset = be2me_32(be2me_32(P->componentInfoCb.offset) + image_size / 4);
874 P->componentInfoY.rowBytes = be2me_32(imgRect.right);
875 P->componentInfoCb.rowBytes = be2me_32(imgRect.right / 2);
876 P->componentInfoCr.rowBytes = be2me_32(imgRect.right / 2);
877 image_buffer_size = image_size + sizeof(PlanarPixmapInfoYUV420);
878 break;
879 case IMGFMT_UYVY:
880 case IMGFMT_YUY2:
881 image_buffer_size = image_size;
882 break;
885 qterr = DecompressSequenceBeginS(&seqId,
886 yuv_qt_stuff.desc,
887 (char *)P,
888 image_buffer_size,
889 GetWindowPort(theWindow),
890 NULL,
891 NULL,
892 ((d_width != width) || (d_height != height)) ?
893 &matrix : NULL,
894 srcCopy,
895 NULL,
897 codecLosslessQuality,
898 bestSpeedCodec);
900 if (qterr)
902 mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: DecompressSequenceBeginS (%d)\n", qterr);
903 return -1;
906 break;
909 // Show window
910 RepositionWindow(theWindow, NULL, kWindowCenterOnMainScreen);
911 ShowWindow(theWindow);
913 if (vo_fs)
914 window_fullscreen();
916 if (vo_ontop)
917 window_ontop();
919 if (vo_rootwin)
921 vo_fs = TRUE;
922 winLevel = 0;
923 SetWindowGroupLevel(winGroup, CGWindowLevelForKey(levelList[winLevel]));
924 window_fullscreen();
927 window_resized();
929 return 0;
932 static void check_events(void)
934 EventRef theEvent;
935 EventTargetRef theTarget;
936 OSStatus theErr;
938 // Get event
939 theTarget = GetEventDispatcherTarget();
940 theErr = ReceiveNextEvent(0, 0, kEventDurationNoWait, true, &theEvent);
941 if (theErr == noErr && theEvent != NULL)
943 SendEventToEventTarget(theEvent, theTarget);
944 ReleaseEvent(theEvent);
948 static void draw_osd(void)
950 vo_draw_text(imgRect.right, imgRect.bottom, draw_alpha);
953 static void flip_page(void)
955 int curTime;
957 if (theWindow == NULL)
958 return;
960 switch (image_format)
962 case IMGFMT_RGB32:
964 CGContextRef context;
966 QDBeginCGContext(GetWindowPort(theWindow), &context);
967 CGContextDrawImage(context, bounds, image);
968 QDEndCGContext(GetWindowPort(theWindow), &context);
970 break;
972 case IMGFMT_YV12:
973 case IMGFMT_IYUV:
974 case IMGFMT_I420:
975 case IMGFMT_UYVY:
976 case IMGFMT_YUY2:
977 if (EnterMoviesDone)
979 OSErr qterr;
980 CodecFlags flags = 0;
982 qterr = DecompressSequenceFrameWhen(seqId,
983 (char *)P,
984 image_buffer_size,
985 0, //codecFlagUseImageBuffer,
986 &flags,
987 NULL,
988 NULL);
989 if (qterr)
991 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: DecompressSequenceFrameWhen in flip_page (%d) flags:0x%08x\n", qterr, flags);
994 break;
997 if (!vo_quartz_fs)
999 CGContextRef context;
1001 QDBeginCGContext(GetWindowPort(theWindow), &context);
1002 // render resize box
1003 CGContextBeginPath(context);
1004 CGContextSetAllowsAntialiasing(context, false);
1005 //CGContextSaveGState(context);
1007 // line white
1008 CGContextSetRGBStrokeColor(context, 0.2, 0.2, 0.2, 0.5);
1009 CGContextMoveToPoint(context, winRect.right - 1, 1); CGContextAddLineToPoint(context, winRect.right - 1, 1);
1010 CGContextMoveToPoint(context, winRect.right - 1, 5); CGContextAddLineToPoint(context, winRect.right - 5, 1);
1011 CGContextMoveToPoint(context, winRect.right - 1, 9); CGContextAddLineToPoint(context, winRect.right - 9, 1);
1012 CGContextStrokePath(context);
1014 // line gray
1015 CGContextSetRGBStrokeColor(context, 0.4, 0.4, 0.4, 0.5);
1016 CGContextMoveToPoint(context, winRect.right - 1, 2); CGContextAddLineToPoint(context, winRect.right - 2, 1);
1017 CGContextMoveToPoint(context, winRect.right - 1, 6); CGContextAddLineToPoint(context, winRect.right - 6, 1);
1018 CGContextMoveToPoint(context, winRect.right - 1, 10); CGContextAddLineToPoint(context, winRect.right - 10, 1);
1019 CGContextStrokePath(context);
1021 // line black
1022 CGContextSetRGBStrokeColor(context, 0.6, 0.6, 0.6, 0.5);
1023 CGContextMoveToPoint(context, winRect.right - 1, 3); CGContextAddLineToPoint(context, winRect.right - 3, 1);
1024 CGContextMoveToPoint(context, winRect.right - 1, 7); CGContextAddLineToPoint(context, winRect.right - 7, 1);
1025 CGContextMoveToPoint(context, winRect.right - 1, 11); CGContextAddLineToPoint(context, winRect.right - 11, 1);
1026 CGContextStrokePath(context);
1028 // CGContextRestoreGState( context );
1029 CGContextFlush(context);
1030 QDEndCGContext(GetWindowPort(theWindow), &context);
1033 curTime = TickCount() / 60;
1035 // auto hide mouse cursor (and future on-screen control?)
1036 if (vo_quartz_fs && !mouseHide)
1038 if (((curTime - lastMouseHide) >= 5) || (lastMouseHide == 0))
1040 CGDisplayHideCursor(displayId);
1041 mouseHide = TRUE;
1042 lastMouseHide = curTime;
1045 // update activity every 30 seconds to prevent
1046 // screensaver from starting up.
1047 if (((curTime - lastScreensaverUpdate) >= 30) || (lastScreensaverUpdate == 0))
1049 UpdateSystemActivity(UsrActivity);
1050 lastScreensaverUpdate = curTime;
1054 static int draw_slice(uint8_t * src[], int stride[], int w, int h, int x, int y)
1056 switch (image_format)
1058 case IMGFMT_YV12:
1059 case IMGFMT_I420:
1060 memcpy_pic(((char *)P) + be2me_32(P->componentInfoY.offset) + x + imgRect.right * y, src[0], w, h, imgRect.right, stride[0]);
1061 x=x/2;y=y/2;w=w/2;h=h/2;
1063 memcpy_pic(((char *)P) + be2me_32(P->componentInfoCb.offset) + x + imgRect.right / 2 * y, src[1], w, h, imgRect.right / 2, stride[1]);
1064 memcpy_pic(((char *)P) + be2me_32(P->componentInfoCr.offset) + x + imgRect.right / 2 * y, src[2], w, h, imgRect.right / 2, stride[2]);
1065 return 0;
1067 case IMGFMT_IYUV:
1068 memcpy_pic(((char *)P) + be2me_32(P->componentInfoY.offset) + x + imgRect.right * y, src[0], w, h, imgRect.right, stride[0]);
1069 x=x/2;y=y/2;w=w/2;h=h/2;
1071 memcpy_pic(((char *)P) + be2me_32(P->componentInfoCr.offset) + x + imgRect.right / 2 * y, src[1], w, h, imgRect.right / 2, stride[1]);
1072 memcpy_pic(((char *)P) + be2me_32(P->componentInfoCb.offset) + x + imgRect.right / 2 * y, src[2], w, h, imgRect.right / 2, stride[2]);
1073 return 0;
1075 return -1;
1078 static int draw_frame(uint8_t * src[])
1080 switch (image_format)
1082 case IMGFMT_RGB32:
1083 fast_memcpy(image_data, src[0], image_size);
1084 return 0;
1086 case IMGFMT_UYVY:
1087 case IMGFMT_YUY2:
1088 memcpy_pic(((char *)P), src[0], imgRect.right * 2, imgRect.bottom, imgRect.right * 2, imgRect.right * 2);
1089 return 0;
1091 return -1;
1094 static int query_format(uint32_t format)
1096 image_format = format;
1097 image_qtcodec = 0;
1099 if (format == IMGFMT_RGB32)
1101 return VFCAP_CSP_SUPPORTED | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN;
1104 if ((format == IMGFMT_YV12) || (format == IMGFMT_IYUV) || (format == IMGFMT_I420))
1106 image_qtcodec = kMpegYUV420CodecType; //kYUV420CodecType ?;
1107 return VFCAP_CSP_SUPPORTED | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_ACCEPT_STRIDE;
1110 if (format == IMGFMT_YUY2)
1112 image_qtcodec = kComponentVideoUnsigned;
1113 return VFCAP_CSP_SUPPORTED | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN;
1116 if (format == IMGFMT_UYVY)
1118 image_qtcodec = k422YpCbCr8CodecType;
1119 return VFCAP_CSP_SUPPORTED | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN;
1122 return 0;
1125 static void uninit(void)
1127 OSErr qterr;
1129 switch (image_format)
1131 case IMGFMT_YV12:
1132 case IMGFMT_IYUV:
1133 case IMGFMT_I420:
1134 case IMGFMT_UYVY:
1135 case IMGFMT_YUY2:
1137 if (EnterMoviesDone)
1139 qterr = CDSequenceEnd(seqId);
1140 if (qterr)
1142 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: CDSequenceEnd (%d)\n", qterr);
1145 break;
1147 default:
1148 break;
1151 ShowMenuBar();
1154 static int preinit(const char *arg)
1156 int parse_err = 0;
1158 if(arg)
1160 char *parse_pos = (char *)&arg[0];
1162 while (parse_pos[0] && !parse_err)
1164 if (strncmp(parse_pos, "device_id=", 10) == 0)
1166 parse_pos = &parse_pos[10];
1167 device_id = strtol(parse_pos, &parse_pos, 0);
1169 if (strncmp(parse_pos, "fs_res=", 7) == 0)
1171 parse_pos = &parse_pos[7];
1172 fs_res_x = strtol(parse_pos, &parse_pos, 0);
1173 parse_pos = &parse_pos[1];
1174 fs_res_y = strtol(parse_pos, &parse_pos, 0);
1176 if (parse_pos[0] == ':')
1177 parse_pos = &parse_pos[1];
1178 else if (parse_pos[0])
1179 parse_err = 1;
1183 #if !defined (CONFIG_MACOSX_FINDER) || !defined (CONFIG_SDL)
1184 // this chunk of code is heavily based off SDL_macosx.m from SDL
1185 // the CPSEnableForegroundOperation that was here before is private and shouldn't be used
1186 // replaced by a call to the 10.3+ TransformProcessType
1188 ProcessSerialNumber myProc, frProc;
1189 Boolean sameProc;
1191 if (GetFrontProcess(&frProc) == noErr)
1193 if (GetCurrentProcess(&myProc) == noErr)
1195 if (SameProcess(&frProc, &myProc, &sameProc) == noErr && !sameProc)
1197 TransformProcessType(&myProc, kProcessTransformToForegroundApplication);
1199 SetFrontProcess(&myProc);
1203 #endif
1205 return 0;
1208 static uint32_t draw_yuv_image(mp_image_t * mpi)
1210 // ATM we're only called for planar IMGFMT
1211 // drawing is done directly in P
1212 // and displaying is in flip_page.
1213 return get_image_done ? VO_TRUE : VO_FALSE;
1216 static uint32_t get_yuv_image(mp_image_t * mpi)
1218 if (mpi->type != MP_IMGTYPE_EXPORT) return VO_FALSE;
1220 if (mpi->imgfmt != image_format) return VO_FALSE;
1222 if (mpi->flags & MP_IMGFLAG_PLANAR)
1224 if (mpi->num_planes != 3)
1226 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: only 3 planes allowed in get_yuv_image for planar (%d) \n", mpi->num_planes);
1227 return VO_FALSE;
1230 mpi->planes[0] = ((char *)P) + be2me_32(P->componentInfoY.offset);
1231 mpi->stride[0] = imgRect.right;
1232 mpi->width = imgRect.right;
1234 if (mpi->flags & MP_IMGFLAG_SWAPPED)
1236 // I420
1237 mpi->planes[1] = ((char *)P) + be2me_32(P->componentInfoCb.offset);
1238 mpi->planes[2] = ((char *)P) + be2me_32(P->componentInfoCr.offset);
1239 mpi->stride[1] = imgRect.right / 2;
1240 mpi->stride[2] = imgRect.right / 2;
1242 else
1244 // YV12
1245 mpi->planes[1] = ((char *)P) + be2me_32(P->componentInfoCr.offset);
1246 mpi->planes[2] = ((char *)P) + be2me_32(P->componentInfoCb.offset);
1247 mpi->stride[1] = imgRect.right / 2;
1248 mpi->stride[2] = imgRect.right / 2;
1251 mpi->flags |= MP_IMGFLAG_DIRECT;
1252 get_image_done = 1;
1253 return VO_TRUE;
1255 else
1257 // doesn't work yet
1258 if (mpi->num_planes != 1)
1260 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: only 1 plane allowed in get_yuv_image for packed (%d) \n", mpi->num_planes);
1261 return VO_FALSE;
1264 mpi->planes[0] = (char *)P;
1265 mpi->stride[0] = imgRect.right * 2;
1266 mpi->width = imgRect.right;
1267 mpi->flags |= MP_IMGFLAG_DIRECT;
1268 get_image_done = 1;
1269 return VO_TRUE;
1271 return VO_FALSE;
1274 static int control(uint32_t request, void *data)
1276 switch (request)
1278 case VOCTRL_PAUSE: return int_pause = 1;
1279 case VOCTRL_RESUME: return int_pause = 0;
1280 case VOCTRL_FULLSCREEN: vo_fs = (!(vo_fs)); window_fullscreen(); return VO_TRUE;
1281 case VOCTRL_ONTOP: vo_ontop = (!(vo_ontop)); window_ontop(); return VO_TRUE;
1282 case VOCTRL_QUERY_FORMAT: return query_format(*((uint32_t *) data));
1283 case VOCTRL_GET_PANSCAN: return VO_TRUE;
1284 case VOCTRL_SET_PANSCAN: window_panscan(); return VO_TRUE;
1286 case VOCTRL_GET_IMAGE:
1287 switch (image_format)
1289 case IMGFMT_YV12:
1290 case IMGFMT_IYUV:
1291 case IMGFMT_I420:
1292 case IMGFMT_UYVY:
1293 case IMGFMT_YUY2:
1294 return get_yuv_image(data);
1295 break;
1296 default:
1297 break;
1299 case VOCTRL_DRAW_IMAGE:
1300 switch (image_format)
1302 case IMGFMT_YV12:
1303 case IMGFMT_IYUV:
1304 case IMGFMT_I420:
1305 case IMGFMT_UYVY:
1306 case IMGFMT_YUY2:
1307 return draw_yuv_image(data);
1308 break;
1309 default:
1310 break;
1313 return VO_NOTIMPL;
1316 void window_resized(void)
1318 float aspectX;
1319 float aspectY;
1321 int padding = 0;
1323 uint32_t d_width;
1324 uint32_t d_height;
1326 CGRect tmpBounds;
1328 CGContextRef context;
1330 GetWindowPortBounds(theWindow, &winRect);
1332 if (vo_keepaspect)
1334 aspect(&d_width, &d_height, A_NOZOOM);
1335 d_height = ((float)d_width / movie_aspect);
1337 aspectX = (float)((float)winRect.right / (float)d_width);
1338 aspectY = (float)((float)(winRect.bottom) / (float)d_height);
1340 if ((d_height * aspectX) > (winRect.bottom))
1342 padding = (winRect.right - d_width * aspectY) / 2;
1343 SetRect(&dstRect, padding, 0, d_width * aspectY + padding, d_height * aspectY);
1345 else
1347 padding = ((winRect.bottom) - d_height * aspectX) / 2;
1348 SetRect(&dstRect, 0, padding, (d_width * aspectX), d_height * aspectX + padding);
1351 else
1353 SetRect(&dstRect, 0, 0, winRect.right, winRect.bottom);
1356 switch (image_format)
1358 case IMGFMT_RGB32:
1360 bounds = CGRectMake(dstRect.left, dstRect.top, dstRect.right - dstRect.left, dstRect.bottom - dstRect.top);
1361 break;
1363 case IMGFMT_YV12:
1364 case IMGFMT_IYUV:
1365 case IMGFMT_I420:
1366 case IMGFMT_UYVY:
1367 case IMGFMT_YUY2:
1369 long scale_X = FixDiv(Long2Fix(dstRect.right - dstRect.left), Long2Fix(imgRect.right));
1370 long scale_Y = FixDiv(Long2Fix(dstRect.bottom - dstRect.top), Long2Fix(imgRect.bottom));
1372 SetIdentityMatrix(&matrix);
1373 if (((dstRect.right - dstRect.left) != imgRect.right) || ((dstRect.bottom - dstRect.right) != imgRect.bottom))
1375 ScaleMatrix(&matrix, scale_X, scale_Y, 0, 0);
1377 if (padding > 0)
1379 TranslateMatrix(&matrix, Long2Fix(dstRect.left), Long2Fix(dstRect.top));
1383 SetDSequenceMatrix(seqId, &matrix);
1384 break;
1386 default:
1387 break;
1390 // Clear Background
1391 tmpBounds = CGRectMake(0, 0, winRect.right, winRect.bottom);
1392 QDBeginCGContext(GetWindowPort(theWindow), &context);
1393 CGContextFillRect(context, tmpBounds);
1394 QDEndCGContext(GetWindowPort(theWindow), &context);
1397 void window_ontop(void)
1399 if (!vo_quartz_fs)
1401 // Cycle between level
1402 winLevel++;
1403 if (winLevel > 2)
1404 winLevel = 1;
1406 SetWindowGroupLevel(winGroup, CGWindowLevelForKey(levelList[winLevel]));
1409 void window_fullscreen(void)
1411 // go fullscreen
1412 if (vo_fs)
1414 if (winLevel != 0)
1416 if (displayId == kCGDirectMainDisplay)
1418 SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);
1419 CGDisplayHideCursor(displayId);
1420 mouseHide = TRUE;
1423 if (fs_res_x != 0 || fs_res_y != 0)
1425 CFDictionaryRef mode;
1426 size_t desiredBitDepth = 32;
1427 boolean_t exactMatch;
1429 originalMode = CGDisplayCurrentMode(displayId);
1431 mode = CGDisplayBestModeForParameters(displayId, desiredBitDepth, fs_res_x, fs_res_y, &exactMatch);
1433 if (mode != NULL)
1435 if (!exactMatch)
1437 // Warn if the mode doesn't match exactly
1438 mp_msg(MSGT_VO, MSGL_WARN, "Quartz warning: did not get exact mode match (got %dx%d) \n", (int)CFDictionaryGetValue(mode, kCGDisplayWidth), (int)CFDictionaryGetValue(mode, kCGDisplayHeight));
1441 CGDisplayCapture(displayId);
1442 CGDisplaySwitchToMode(displayId, mode);
1444 else
1446 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: can't switch to fullscreen \n");
1449 // Get Main device info///////////////////////////////////////////////////
1450 displayRect = CGDisplayBounds(displayId);
1453 // save old window size
1454 if (!vo_quartz_fs)
1456 GetWindowPortBounds(theWindow, &oldWinRect);
1457 GetWindowBounds(theWindow, kWindowContentRgn, &oldWinBounds);
1459 // go fullscreen
1460 panscan_calc();
1461 ChangeWindowAttributes(theWindow, kWindowNoShadowAttribute, 0);
1462 MoveWindow(theWindow, displayRect.origin.x - (vo_panscan_x >> 1), displayRect.origin.y - (vo_panscan_y >> 1), 1);
1463 SizeWindow(theWindow, displayRect.size.width + vo_panscan_x, displayRect.size.height + vo_panscan_y, 1);
1465 vo_quartz_fs = 1;
1467 else //go back to windowed mode
1469 vo_quartz_fs = 0;
1470 if (originalMode != NULL)
1472 CGDisplaySwitchToMode(displayId, originalMode);
1473 CGDisplayRelease(displayId);
1475 // Get Main device info///////////////////////////////////////////////////
1476 displayRect = CGDisplayBounds(displayId);
1478 originalMode = NULL;
1480 SetSystemUIMode(kUIModeNormal, 0);
1482 // show mouse cursor
1483 CGDisplayShowCursor(displayId);
1484 mouseHide = FALSE;
1486 // revert window to previous setting
1487 ChangeWindowAttributes(theWindow, 0, kWindowNoShadowAttribute);
1488 SizeWindow(theWindow, oldWinRect.right, oldWinRect.bottom, 1);
1489 MoveWindow(theWindow, oldWinBounds.left, oldWinBounds.top, 1);
1491 window_resized();
1494 void window_panscan(void)
1496 panscan_calc();
1498 if (vo_panscan > 0)
1499 CheckMenuItem(aspectMenu, 2, 1);
1500 else
1501 CheckMenuItem(aspectMenu, 2, 0);
1503 if (vo_quartz_fs)
1505 MoveWindow(theWindow, displayRect.origin.x - (vo_panscan_x >> 1), displayRect.origin.y - (vo_panscan_y >> 1), 1);
1506 SizeWindow(theWindow, displayRect.size.width + vo_panscan_x, displayRect.size.height + vo_panscan_y, 1);