diff options
Diffstat (limited to 'libvo')
-rw-r--r-- | libvo/cocoa_common.h | 20 | ||||
-rw-r--r-- | libvo/cocoa_common.m | 128 | ||||
-rw-r--r-- | libvo/gl_common.c | 1 | ||||
-rw-r--r-- | libvo/video_out.c | 10 | ||||
-rw-r--r-- | libvo/video_out.h | 1 | ||||
-rw-r--r-- | libvo/vo_quartz.c | 1371 | ||||
-rw-r--r-- | libvo/vo_xv.c | 133 | ||||
-rw-r--r-- | libvo/x11_common.c | 17 | ||||
-rw-r--r-- | libvo/x11_common.h | 1 |
9 files changed, 165 insertions, 1517 deletions
diff --git a/libvo/cocoa_common.h b/libvo/cocoa_common.h index 1330caacc5..d47ac51500 100644 --- a/libvo/cocoa_common.h +++ b/libvo/cocoa_common.h @@ -1,3 +1,22 @@ +/* + * Cocoa OpenGL Backend + * + * This file is part of mplayer2. + * + * mplayer2 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * mplayer2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with mplayer2. If not, see <http://www.gnu.org/licenses/>. + */ + #ifndef MPLAYER_COCOA_COMMON_H #define MPLAYER_COCOA_COMMON_H @@ -16,6 +35,7 @@ int vo_cocoa_create_window(struct vo *vo, uint32_t d_width, void vo_cocoa_swap_buffers(void); int vo_cocoa_check_events(struct vo *vo); void vo_cocoa_fullscreen(struct vo *vo); +void vo_cocoa_ontop(struct vo *vo); // returns an int to conform to the gl extensions from other platforms int vo_cocoa_swap_interval(int enabled); diff --git a/libvo/cocoa_common.m b/libvo/cocoa_common.m index 4eccf1a320..e8ef278b1e 100644 --- a/libvo/cocoa_common.m +++ b/libvo/cocoa_common.m @@ -1,3 +1,22 @@ +/* + * Cocoa OpenGL Backend + * + * This file is part of mplayer2. + * + * mplayer2 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * mplayer2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with mplayer2. If not, see <http://www.gnu.org/licenses/>. + */ + #import <Cocoa/Cocoa.h> #import <OpenGL/OpenGL.h> #import <QuartzCore/QuartzCore.h> @@ -62,8 +81,15 @@ struct vo_cocoa_state { NSString *window_title; + NSInteger windowed_window_level; + NSInteger fullscreen_window_level; + int last_screensaver_update; + int display_cursor; + int cursor_timer; + int cursor_autohide_delay; + bool did_resize; bool out_fs_resize; }; @@ -74,8 +100,10 @@ struct vo *l_vo; // local function definitions struct vo_cocoa_state *vo_cocoa_init_state(void); +void vo_set_level(int ontop); void update_screen_info(void); void resize_window(struct vo *vo); +void vo_cocoa_display_cursor(int requested_state); void create_menu(void); bool is_lion_or_better(void); @@ -89,8 +117,10 @@ struct vo_cocoa_state *vo_cocoa_init_state(void) .previous_video_size = {0,0}, .windowed_mask = NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask, .fullscreen_mask = NSBorderlessWindowMask, + .fullscreen_window_level = NSNormalWindowLevel + 1, .windowed_frame = {{0,0},{0,0}}, .out_fs_resize = NO, + .display_cursor = 1, }; return s; } @@ -99,6 +129,7 @@ int vo_cocoa_init(struct vo *vo) { s = vo_cocoa_init_state(); s->pool = [[NSAutoreleasePool alloc] init]; + s->cursor_autohide_delay = vo->opts->cursor_autohide_delay; NSApplicationLoad(); NSApp = [NSApplication sharedApplication]; [NSApp setActivationPolicy: NSApplicationActivationPolicyRegular]; @@ -155,10 +186,30 @@ void resize_window(struct vo *vo) [s->glContext update]; } +void vo_set_level(int ontop) +{ + if (ontop) { + s->windowed_window_level = NSNormalWindowLevel + 1; + } else { + s->windowed_window_level = NSNormalWindowLevel; + } + + if (!vo_fs) + [s->window setLevel:s->windowed_window_level]; +} + +void vo_cocoa_ontop(struct vo *vo) +{ + struct MPOpts *opts = vo->opts; + opts->vo_ontop = !opts->vo_ontop; + vo_set_level(opts->vo_ontop); +} + int vo_cocoa_create_window(struct vo *vo, uint32_t d_width, uint32_t d_height, uint32_t flags, int gl3profile) { + struct MPOpts *opts = vo->opts; if (s->current_video_size.width > 0 || s->current_video_size.height > 0) s->previous_video_size = s->current_video_size; s->current_video_size = NSMakeSize(d_width, d_height); @@ -207,6 +258,8 @@ int vo_cocoa_create_window(struct vo *vo, uint32_t d_width, if (flags & VOFLAG_FULLSCREEN) vo_cocoa_fullscreen(vo); + + vo_set_level(opts->vo_ontop); } else { if (s->current_video_size.width != s->previous_video_size.width || s->current_video_size.height != s->previous_video_size.height) { @@ -238,18 +291,42 @@ void vo_cocoa_swap_buffers() [s->glContext flushBuffer]; } +void vo_cocoa_display_cursor(int requested_state) +{ + if (requested_state) { + if (!vo_fs || s->cursor_autohide_delay > -2) { + s->display_cursor = requested_state; + CGDisplayShowCursor(kCGDirectMainDisplay); + } + } else { + if (s->cursor_autohide_delay != -1) { + s->display_cursor = requested_state; + CGDisplayHideCursor(kCGDirectMainDisplay); + } + } +} + int vo_cocoa_check_events(struct vo *vo) { + NSEvent *event; + float curTime = TickCount()/60; + int msCurTime = (int) (curTime * 1000); + + // automatically hide mouse cursor + if (vo_fs && s->display_cursor && + (msCurTime - s->cursor_timer >= s->cursor_autohide_delay)) { + vo_cocoa_display_cursor(0); + s->cursor_timer = msCurTime; + } + //update activity every 30 seconds to prevent //screensaver from starting up. - int curTime = TickCount()/60; - if (curTime - s->last_screensaver_update >= 30 || s->last_screensaver_update == 0) + if ((int)curTime - s->last_screensaver_update >= 30 || s->last_screensaver_update == 0) { UpdateSystemActivity(UsrActivity); - s->last_screensaver_update = curTime; + s->last_screensaver_update = (int)curTime; } - NSEvent *event; event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSEventTrackingRunLoopMode dequeue:YES]; if (event == nil) @@ -333,14 +410,16 @@ bool is_lion_or_better(void) - (void) fullscreen { if (!vo_fs) { + update_screen_info(); [NSApp setPresentationOptions:NSApplicationPresentationHideDock|NSApplicationPresentationHideMenuBar]; s->windowed_frame = [self frame]; [self setHasShadow:NO]; [self setStyleMask:s->fullscreen_mask]; [self setFrame:s->screen_frame display:YES animate:NO]; - [self setLevel:NSNormalWindowLevel + 1]; - CGDisplayHideCursor(kCGDirectMainDisplay); + [self setLevel:s->fullscreen_window_level]; vo_fs = VO_TRUE; + vo_cocoa_display_cursor(0); + [self setMovableByWindowBackground: NO]; } else { [NSApp setPresentationOptions:NSApplicationPresentationDefault]; [self setHasShadow:YES]; @@ -352,9 +431,10 @@ bool is_lion_or_better(void) s->out_fs_resize = NO; } [self setContentAspectRatio:s->current_video_size]; - [self setLevel:NSNormalWindowLevel]; - CGDisplayShowCursor(kCGDirectMainDisplay); + [self setLevel:s->windowed_window_level]; vo_fs = VO_FALSE; + vo_cocoa_display_cursor(1); + [self setMovableByWindowBackground: YES]; } } @@ -372,6 +452,12 @@ bool is_lion_or_better(void) return NO; } +- (BOOL) isMovableByWindowBackground +{ + // this is only valid as a starting value. it will be rewritten in the -fullscreen method. + return !vo_fs; +} + - (void) handleQuitEvent:(NSAppleEventDescriptor*)e withReplyEvent:(NSAppleEventDescriptor*)r { mplayer_put_key(l_vo->key_fifo, KEY_CLOSE_WIN); @@ -400,6 +486,12 @@ bool is_lion_or_better(void) } } +- (void) mouseMoved: (NSEvent *) theEvent +{ + if (vo_fs) + vo_cocoa_display_cursor(1); +} + - (void) mouseDragged:(NSEvent *)theEvent { [self mouseEvent: theEvent]; @@ -445,23 +537,23 @@ bool is_lion_or_better(void) - (void) mouseEvent:(NSEvent *)theEvent { - if ( [theEvent buttonNumber] >= 0 && [theEvent buttonNumber] <= 9 ) - { + if ([theEvent buttonNumber] >= 0 && [theEvent buttonNumber] <= 9) { int buttonNumber = [theEvent buttonNumber]; // Fix to mplayer defined button order: left, middle, right - if (buttonNumber == 1) - buttonNumber = 2; - else if (buttonNumber == 2) - buttonNumber = 1; + if (buttonNumber == 1) buttonNumber = 2; + else if (buttonNumber == 2) buttonNumber = 1; switch ([theEvent type]) { case NSLeftMouseDown: - break; case NSRightMouseDown: case NSOtherMouseDown: mplayer_put_key(l_vo->key_fifo, (MOUSE_BTN0 + buttonNumber) | MP_KEY_DOWN); + // Looks like Cocoa doesn't create MouseUp events when we are + // doing the second click in a double click. Put in the key_fifo + // the key that would be put from the MouseUp handling code. + if([theEvent clickCount] == 2) + mplayer_put_key(l_vo->key_fifo, MOUSE_BTN0 + buttonNumber); break; case NSLeftMouseUp: - break; case NSRightMouseUp: case NSOtherMouseUp: mplayer_put_key(l_vo->key_fifo, MOUSE_BTN0 + buttonNumber); @@ -473,7 +565,7 @@ bool is_lion_or_better(void) - (void) applicationWillBecomeActive:(NSNotification *)aNotification { if (vo_fs) { - [s->window setLevel:NSNormalWindowLevel + 1]; + [s->window setLevel:s->fullscreen_window_level]; [NSApp setPresentationOptions:NSApplicationPresentationHideDock|NSApplicationPresentationHideMenuBar]; [s->window makeKeyAndOrderFront:nil]; [NSApp activateIgnoringOtherApps: YES]; @@ -483,7 +575,7 @@ bool is_lion_or_better(void) - (void) applicationWillResignActive:(NSNotification *)aNotification { if (vo_fs) { - [s->window setLevel:NSNormalWindowLevel]; + [s->window setLevel:s->windowed_window_level]; [NSApp setPresentationOptions:NSApplicationPresentationDefault]; } } diff --git a/libvo/gl_common.c b/libvo/gl_common.c index c5abc81e15..414e52dbd2 100644 --- a/libvo/gl_common.c +++ b/libvo/gl_common.c @@ -2447,6 +2447,7 @@ MPGLContext *init_mpglcontext(enum MPGLType type, struct vo *vo) ctx->check_events = cocoa_check_events; ctx->update_xinerama_info = cocoa_update_xinerama_info; ctx->fullscreen = cocoa_fullscreen; + ctx->ontop = vo_cocoa_ontop; ctx->vo_uninit = vo_cocoa_uninit; if (vo_cocoa_init(vo)) return ctx; diff --git a/libvo/video_out.c b/libvo/video_out.c index 094d5b1a12..540fedb132 100644 --- a/libvo/video_out.c +++ b/libvo/video_out.c @@ -118,7 +118,6 @@ extern struct vo_driver video_out_tdfx_vid; extern struct vo_driver video_out_xvr100; extern struct vo_driver video_out_tga; extern struct vo_driver video_out_corevideo; -extern struct vo_driver video_out_quartz; extern struct vo_driver video_out_pnm; extern struct vo_driver video_out_md5sum; @@ -140,12 +139,12 @@ const struct vo_driver *video_out_drivers[] = #ifdef CONFIG_KVA &video_out_kva, #endif +#ifdef CONFIG_GL_COCOA + &video_out_gl, +#endif #ifdef CONFIG_COREVIDEO &video_out_corevideo, #endif -#ifdef CONFIG_QUARTZ - &video_out_quartz, -#endif #ifdef CONFIG_XMGA &video_out_xmga, #endif @@ -183,7 +182,7 @@ const struct vo_driver *video_out_drivers[] = #ifdef CONFIG_SDL &video_out_sdl, #endif -#ifdef CONFIG_GL +#if (defined CONFIG_GL && !defined CONFIG_GL_COCOA) &video_out_gl, #endif #ifdef CONFIG_DGA @@ -378,6 +377,7 @@ void vo_seek_reset(struct vo *vo) { vo_control(vo, VOCTRL_RESET, NULL); vo->frame_loaded = false; + vo->hasframe = false; } void vo_destroy(struct vo *vo) diff --git a/libvo/video_out.h b/libvo/video_out.h index 554b97d207..3dd3ca8a8d 100644 --- a/libvo/video_out.h +++ b/libvo/video_out.h @@ -378,7 +378,6 @@ struct vo_rect { void calc_src_dst_rects(struct vo *vo, int src_width, int src_height, struct vo_rect *src, struct vo_rect *dst, struct vo_rect *borders, const struct vo_rect *crop); -struct input_ctx; void vo_mouse_movement(struct vo *vo, int posx, int posy); static inline int aspect_scaling(void) diff --git a/libvo/vo_quartz.c b/libvo/vo_quartz.c deleted file mode 100644 index 9098598aa8..0000000000 --- a/libvo/vo_quartz.c +++ /dev/null @@ -1,1371 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** - \author Nicolas Plourde <nicolasplourde@gmail.com> - - Copyright (c) Nicolas Plourde - April 2004 - - YUV support Copyright (C) 2004 Romain Dolbeau <romain@dolbeau.org> - - \brief MPlayer Mac OSX Quartz video out module. - - \todo: -screen overlay output - -fit osd in black bar when available - -fix RGB32 - -(add sugestion here) -*/ - -//SYS -#include <stdio.h> - -//OSX -#include <Carbon/Carbon.h> -#include <QuickTime/QuickTime.h> - -//MPLAYER -#include "config.h" -#include "fastmemcpy.h" -#include "video_out.h" -#include "video_out_internal.h" -#include "aspect.h" -#include "mp_msg.h" -#include "m_option.h" -#include "mp_fifo.h" -#include "mpbswap.h" -#include "sub/sub.h" - -#include "input/input.h" -#include "input/keycodes.h" - -#include "osx_common.h" - -static const vo_info_t info = -{ - "Mac OSX (Quartz)", - "quartz", - "Nicolas Plourde <nicolasplourde@hotmail.com>, Romain Dolbeau <romain@dolbeau.org>", - "" -}; - -const LIBVO_EXTERN(quartz) - -static uint32_t image_depth; -static uint32_t image_format; -static uint32_t image_size; -static uint32_t image_buffer_size; -static char *image_data; - -static ImageSequence seqId; -static CodecType image_qtcodec; -static PlanarPixmapInfoYUV420 *P = NULL; -static struct -{ - ImageDescriptionHandle desc; - Handle extension_colr; - Handle extension_fiel; - Handle extension_clap; - Handle extension_pasp; -} yuv_qt_stuff; -static MatrixRecord matrix; -static int EnterMoviesDone = 0; -static int get_image_done = 0; - -static int vo_quartz_fs; // we are in fullscreen - -static int winLevel = 1; -int levelList[] = -{ - kCGDesktopWindowLevelKey, - kCGNormalWindowLevelKey, - kCGScreenSaverWindowLevelKey -}; - -static int int_pause = 0; -static float winAlpha = 1; -static int mouseHide = FALSE; -static float winSizeMult = 1; - -static int device_id = 0; - -static short fs_res_x = 0; -static short fs_res_y = 0; - -static WindowRef theWindow = NULL; -static WindowGroupRef winGroup = NULL; -static CGRect bounds; -static CGDirectDisplayID displayId = 0; -static CFDictionaryRef originalMode = NULL; - -static CGDataProviderRef dataProviderRef = NULL; -static CGImageRef image = NULL; - -static Rect imgRect; // size of the original image (unscaled) -static Rect dstRect; // size of the displayed image (after scaling) -static Rect winRect; // size of the window containg the displayed image (include padding) -static Rect oldWinRect; // size of the window containg the displayed image (include padding) when NOT in FS mode -static Rect oldWinBounds; - -static MenuRef windMenu; -static MenuRef movMenu; -static MenuRef aspectMenu; - -static int lastScreensaverUpdate = 0; -static int lastMouseHide = 0; - -enum -{ - kHalfScreenCmd = 2, - kNormalScreenCmd = 3, - kDoubleScreenCmd = 4, - kFullScreenCmd = 5, - kKeepAspectCmd = 6, - kAspectOrgCmd = 7, - kAspectFullCmd = 8, - kAspectWideCmd = 9, - kPanScanCmd = 10 -}; - -//PROTOTYPE///////////////////////////////////////////////////////////////// -static OSStatus KeyEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData); -static OSStatus MouseEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData); -static OSStatus WindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData); -void window_resized(void); -void window_ontop(void); -void window_fullscreen(void); -void window_panscan(void); - -static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride) -{ - switch (image_format) - { - case IMGFMT_RGB32: - vo_draw_alpha_rgb32(w, h, src, srca, stride, image_data + 4 * (y0 * imgRect.right + x0), 4 * imgRect.right); - break; - case IMGFMT_YV12: - case IMGFMT_IYUV: - case IMGFMT_I420: - vo_draw_alpha_yv12(w, h, src, srca, stride, ((char *)P) + be2me_32(P->componentInfoY.offset) + x0 + y0 * imgRect.right, imgRect.right); - break; - case IMGFMT_UYVY: - vo_draw_alpha_uyvy(w, h, src, srca, stride, ((char *)P) + (x0 + y0 * imgRect.right) * 2, imgRect.right * 2); - break; - case IMGFMT_YUY2: - vo_draw_alpha_yuy2(w, h, src, srca, stride, ((char *)P) + (x0 + y0 * imgRect.right) * 2, imgRect.right * 2); - break; - } -} - -//default keyboard event handler -static OSStatus KeyEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData) -{ - OSStatus result = noErr; - UInt32 class = GetEventClass(event); - UInt32 kind = GetEventKind(event); - - result = CallNextEventHandler(nextHandler, event); - - if (class == kEventClassKeyboard) - { - char macCharCodes; - UInt32 macKeyCode; - UInt32 macKeyModifiers; - - GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(macCharCodes), NULL, &macCharCodes); - GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(macKeyCode), NULL, &macKeyCode); - GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(macKeyModifiers), NULL, &macKeyModifiers); - - if (macKeyModifiers != 256) - { - if (kind == kEventRawKeyRepeat || kind == kEventRawKeyDown) - { - int key = convert_key(macKeyCode, macCharCodes); - - if (key != -1) - mplayer_put_key(key); - } - } - else if (macKeyModifiers == 256) - { - switch (macCharCodes) - { - case '[': SetWindowAlpha(theWindow, winAlpha -= 0.05); break; - case ']': SetWindowAlpha(theWindow, winAlpha += 0.05); break; - } - } - else - result = eventNotHandledErr; - } - - return result; -} - -//default mouse event handler -static OSStatus MouseEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData) -{ - OSStatus result = noErr; - UInt32 class = GetEventClass(event); - UInt32 kind = GetEventKind(event); - - result = CallNextEventHandler(nextHandler, event); - - if (class == kEventClassMouse) - { - WindowPtr tmpWin; - Point mousePos; - Point winMousePos; - - GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, 0, sizeof(mousePos), 0, &mousePos); - GetEventParameter(event, kEventParamWindowMouseLocation, typeQDPoint, 0, sizeof(winMousePos), 0, &winMousePos); - - switch (kind) - { - case kEventMouseMoved: - { - if (vo_quartz_fs) - { - CGDisplayShowCursor(displayId); - mouseHide = FALSE; - } - } - break; - - case kEventMouseWheelMoved: - { - int wheel; - short part; - - GetEventParameter(event, kEventParamMouseWheelDelta, typeSInt32, 0, sizeof(wheel), 0, &wheel); - - part = FindWindow(mousePos, &tmpWin); - - if (part == inContent) - { - if (wheel > 0) - mplayer_put_key(MOUSE_BTN3); - else - mplayer_put_key(MOUSE_BTN4); - } - } - break; - - case kEventMouseDown: - case kEventMouseUp: - { - EventMouseButton button; - short part; - Rect bounds; - - GetWindowPortBounds(theWindow, &bounds); - GetEventParameter(event, kEventParamMouseButton, typeMouseButton, 0, sizeof(button), 0, &button); - - part = FindWindow(mousePos, &tmpWin); - if (kind == kEventMouseUp) - { - if (part != inContent) - break; - switch (button) - { - case kEventMouseButtonPrimary: - mplayer_put_key(MOUSE_BTN0); - break; - case kEventMouseButtonSecondary: - mplayer_put_key(MOUSE_BTN2); - break; - case kEventMouseButtonTertiary: - mplayer_put_key(MOUSE_BTN1); - break; - - default: - result = eventNotHandledErr; - break; - } - break; - } - if (winMousePos.h > bounds.right - 15 && winMousePos.v > bounds.bottom) - { - if (!vo_quartz_fs) - { - Rect newSize; - - ResizeWindow(theWindow, mousePos, NULL, &newSize); - } - } - else if (part == inMenuBar) - { - MenuSelect(mousePos); - HiliteMenu(0); - } - else if (part == inContent) - { - switch (button) - { - case kEventMouseButtonPrimary: - mplayer_put_key(MOUSE_BTN0 | MP_KEY_DOWN); - break; - case kEventMouseButtonSecondary: - mplayer_put_key(MOUSE_BTN2 | MP_KEY_DOWN); - break; - case kEventMouseButtonTertiary: - mplayer_put_key(MOUSE_BTN1 | MP_KEY_DOWN); - break; - - default: - result = eventNotHandledErr; - break; - } - } - } - break; - - case kEventMouseDragged: - break; - - default: - result = eventNotHandledErr; - break; - } - } - - return result; -} - -static void set_winSizeMult(float mult) -{ - int d_width, d_height; - aspect(&d_width, &d_height, A_NOZOOM); - - if (vo_quartz_fs) - { - vo_fs = !vo_fs; - window_fullscreen(); - } - - winSizeMult = mult; - SizeWindow(theWindow, d_width * mult, d_height * mult, 1); - window_resized(); -} - -//default window event handler -static OSStatus WindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData) -{ - OSStatus result = noErr; - UInt32 class = GetEventClass(event); - UInt32 kind = GetEventKind(event); - - result = CallNextEventHandler(nextHandler, event); - - if (class == kEventClassCommand) - { - HICommand theHICommand; - - GetEventParameter(event, kEventParamDirectObject, typeHICommand, NULL, sizeof(theHICommand), NULL, &theHICommand); - - switch (theHICommand.commandID) - { - case kHICommandQuit: - mplayer_put_key(KEY_CLOSE_WIN); - break; - - case kHalfScreenCmd: - set_winSizeMult(0.5); - break; - - case kNormalScreenCmd: - set_winSizeMult(1); - break; - - case kDoubleScreenCmd: - set_winSizeMult(2); - break; - - case kFullScreenCmd: - vo_fs = !vo_fs; - window_fullscreen(); - break; - - case kKeepAspectCmd: - vo_keepaspect = !vo_keepaspect; - CheckMenuItem(aspectMenu, 1, vo_keepaspect); - window_resized(); - break; - - case kAspectOrgCmd: - change_movie_aspect(-1); - break; - - case kAspectFullCmd: - change_movie_aspect(4.0 / 3.0); - break; - - case kAspectWideCmd: - change_movie_aspect(16.0 / 9.0); - break; - - case kPanScanCmd: - vo_panscan = !vo_panscan; - CheckMenuItem(aspectMenu, 2, vo_panscan); - window_panscan(); - window_resized(); - break; - - default: - result = eventNotHandledErr; - break; - } - } - else if (class == kEventClassWindow) - { - WindowRef window; - Rect rectWindow = { 0, 0, 0, 0 }; - - GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(window), NULL, &window); - - if (window) - { - GetWindowBounds(window, kWindowGlobalPortRgn, &rectWindow); - } - - switch (kind) - { - case kEventWindowClosed: - theWindow = NULL; - mplayer_put_key(KEY_CLOSE_WIN); - break; - - // resize window - case kEventWindowZoomed: - case kEventWindowBoundsChanged: - window_resized(); - flip_page(); - window_resized(); - break; - - default: - result = eventNotHandledErr; - break; - } - } - - return result; -} - -static void quartz_CreateWindow(uint32_t d_width, uint32_t d_height, WindowAttributes windowAttrs) -{ - CFStringRef titleKey; - CFStringRef windowTitle; - OSStatus result; - - MenuItemIndex index; - CFStringRef movMenuTitle; - CFStringRef aspMenuTitle; - - const EventTypeSpec win_events[] = { - {kEventClassWindow, kEventWindowClosed}, - {kEventClassWindow, kEventWindowBoundsChanged}, - {kEventClassCommand, kEventCommandProcess} - }; - - const EventTypeSpec key_events[] = { - {kEventClassKeyboard, kEventRawKeyDown}, - {kEventClassKeyboard, kEventRawKeyRepeat} - }; - - const EventTypeSpec mouse_events[] = { - {kEventClassMouse, kEventMouseMoved}, - {kEventClassMouse, kEventMouseWheelMoved}, - {kEventClassMouse, kEventMouseDown}, - {kEventClassMouse, kEventMouseUp}, - {kEventClassMouse, kEventMouseDragged} - }; - - SetRect(&winRect, 0, 0, d_width, d_height); - SetRect(&oldWinRect, 0, 0, d_width, d_height); - SetRect(&dstRect, 0, 0, d_width, d_height); - - // Clear Menu Bar - ClearMenuBar(); - - // Create Window Menu - CreateStandardWindowMenu(0, &windMenu); - InsertMenu(windMenu, 0); - - // Create Movie Menu - CreateNewMenu(1004, 0, &movMenu); - movMenuTitle = CFSTR("Movie"); - SetMenuTitleWithCFString(movMenu, movMenuTitle); - - AppendMenuItemTextWithCFString(movMenu, CFSTR("Half Size"), 0, kHalfScreenCmd, &index); - SetMenuItemCommandKey(movMenu, index, 0, '0'); - - AppendMenuItemTextWithCFString(movMenu, CFSTR("Normal Size"), 0, kNormalScreenCmd, &index); - SetMenuItemCommandKey(movMenu, index, 0, '1'); - - AppendMenuItemTextWithCFString(movMenu, CFSTR("Double Size"), 0, kDoubleScreenCmd, &index); - SetMenuItemCommandKey(movMenu, index, 0, '2'); - - AppendMenuItemTextWithCFString(movMenu, CFSTR("Full Size"), 0, kFullScreenCmd, &index); - SetMenuItemCommandKey(movMenu, index, 0, 'F'); - - AppendMenuItemTextWithCFString(movMenu, NULL, kMenuItemAttrSeparator, 0, &index); - - AppendMenuItemTextWithCFString(movMenu, CFSTR("Aspect Ratio"), 0, 0, &index); - - //// Create Aspect Ratio Sub Menu - CreateNewMenu(0, 0, &aspectMenu); - aspMenuTitle = CFSTR("Aspect Ratio"); - SetMenuTitleWithCFString(aspectMenu, aspMenuTitle); - SetMenuItemHierarchicalMenu(movMenu, 6, aspectMenu); - - AppendMenuItemTextWithCFString(aspectMenu, CFSTR("Keep"), 0, kKeepAspectCmd, &index); - CheckMenuItem(aspectMenu, 1, vo_keepaspect); - AppendMenuItemTextWithCFString(aspectMenu, CFSTR("Pan-Scan"), 0, kPanScanCmd, &index); - CheckMenuItem(aspectMenu, 2, vo_panscan); - AppendMenuItemTextWithCFString(aspectMenu, NULL, kMenuItemAttrSeparator, 0, &index); - AppendMenuItemTextWithCFString(aspectMenu, CFSTR("Original"), 0, kAspectOrgCmd, &index); - AppendMenuItemTextWithCFString(aspectMenu, CFSTR("4:3"), 0, kAspectFullCmd, &index); - AppendMenuItemTextWithCFString(aspectMenu, CFSTR("16:9"), 0, kAspectWideCmd, &index); - - InsertMenu(movMenu, GetMenuID(windMenu)); //insert before Window menu - - DrawMenuBar(); - - // create window - CreateNewWindow(kDocumentWindowClass, windowAttrs, &winRect, &theWindow); - - CreateWindowGroup(0, &winGroup); - SetWindowGroup(theWindow, winGroup); - - // Set window title - titleKey = CFSTR("MPlayer - The Movie Player"); - windowTitle = CFCopyLocalizedString(titleKey, NULL); - result = SetWindowTitleWithCFString(theWindow, windowTitle); - CFRelease(titleKey); - CFRelease(windowTitle); - - // Install event handler - InstallApplicationEventHandler(NewEventHandlerUPP(KeyEventHandler), GetEventTypeCount(key_events), key_events, NULL, NULL); - InstallApplicationEventHandler(NewEventHandlerUPP(MouseEventHandler), GetEventTypeCount(mouse_events), mouse_events, NULL, NULL); - InstallWindowEventHandler(theWindow, NewEventHandlerUPP(WindowEventHandler), GetEventTypeCount(win_events), win_events, theWindow, NULL); -} - -static void update_screen_info(void) -{ - CGRect displayRect; - CGDisplayCount displayCount; - CGDirectDisplayID *displays; - // Display IDs might not be consecutive, get the list of all devices up to # device_id - displayCount = device_id + 1; - displays = malloc(sizeof(*displays) * displayCount); - if (kCGErrorSuccess != CGGetActiveDisplayList(displayCount, displays, &displayCount) || displayCount < device_id + 1) { - mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: Device ID %d do not exist, falling back to main device.\n", device_id); - displayId = kCGDirectMainDisplay; - device_id = 0; - } - else - { - displayId = displays[device_id]; - } - free(displays); - - displayRect = CGDisplayBounds(displayId); - xinerama_x = displayRect.origin.x; - xinerama_y = displayRect.origin.y; - vo_screenwidth = displayRect.size.width; - vo_screenheight = displayRect.size.height; - aspect_save_screenres(vo_screenwidth, vo_screenheight); -} - -static void free_video_specific(void) -{ - if (seqId) CDSequenceEnd(seqId); - seqId = 0; - free(image_data); - image_data = NULL; - free(P); - P = NULL; - CGDataProviderRelease(dataProviderRef); - dataProviderRef = NULL; - CGImageRelease(image); - image = NULL; -} - -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) -{ - WindowAttributes windowAttrs; - OSErr qterr; - CGRect tmpBounds; - - free_video_specific(); - - vo_dwidth = d_width *= winSizeMult; - vo_dheight = d_height *= wi |