[MPlayer-cvslog] r35180 - in trunk: Makefile libvo/osx_objc_common.h libvo/osx_objc_common.m libvo/vo_corevideo.h libvo/vo_corevideo.m

reimar subversion at mplayerhq.hu
Thu Sep 13 21:20:47 CEST 2012


Author: reimar
Date: Thu Sep 13 21:20:47 2012
New Revision: 35180

Log:
Split out an objective-C common OS X layer, to be reused by -vo gl.

Added:
   trunk/libvo/osx_objc_common.h
      - copied, changed from r35177, trunk/libvo/vo_corevideo.h
   trunk/libvo/osx_objc_common.m
      - copied, changed from r35179, trunk/libvo/vo_corevideo.m
Modified:
   trunk/Makefile
   trunk/libvo/vo_corevideo.h
   trunk/libvo/vo_corevideo.m

Modified: trunk/Makefile
==============================================================================
--- trunk/Makefile	Thu Sep 13 21:15:37 2012	(r35179)
+++ trunk/Makefile	Thu Sep 13 21:20:47 2012	(r35180)
@@ -503,7 +503,7 @@ SRCS_MPLAYER-$(ARTS)         += libao2/a
 SRCS_MPLAYER-$(BL)           += libvo/vo_bl.c
 SRCS_MPLAYER-$(CACA)         += libvo/vo_caca.c
 SRCS_MPLAYER-$(COREAUDIO)    += libao2/ao_coreaudio.c
-SRCS_MPLAYER-$(COREVIDEO)    += libvo/vo_corevideo.m libvo/osx_common.c
+SRCS_MPLAYER-$(COREVIDEO)    += libvo/vo_corevideo.m libvo/osx_common.c libvo/osx_objc_common.m
 SRCS_MPLAYER-$(DART)         += libao2/ao_dart.c
 SRCS_MPLAYER-$(DGA)          += libvo/vo_dga.c
 SRCS_MPLAYER-$(DIRECT3D)     += libvo/vo_direct3d.c libvo/w32_common.c

Copied and modified: trunk/libvo/osx_objc_common.h (from r35177, trunk/libvo/vo_corevideo.h)
==============================================================================
--- trunk/libvo/vo_corevideo.h	Thu Sep 13 20:44:36 2012	(r35177, copy source)
+++ trunk/libvo/osx_objc_common.h	Thu Sep 13 21:20:47 2012	(r35180)
@@ -20,26 +20,12 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#ifndef MPLAYER_VO_COREVIDEO_H
-#define MPLAYER_VO_COREVIDEO_H
+#ifndef MPLAYER_OSX_OBJC_COMMON_H
+#define MPLAYER_OSX_OBJC_COMMON_H
 
 #import <Cocoa/Cocoa.h>
-#import <QuartzCore/QuartzCore.h>
-#import <Carbon/Carbon.h>
-
-// MPlayer OS X VO Protocol
- at protocol MPlayerOSXVOProto
-- (int) startWithWidth: (bycopy int)width
-            withHeight: (bycopy int)height
-             withBytes: (bycopy int)bytes
-            withAspect: (bycopy int)aspect;
-- (void) stop;
-- (void) render;
-- (void) toggleFullscreen;
-- (void) ontop;
- at end
 
- at interface MPlayerOpenGLView : NSOpenGLView
+ at interface MPCommonOpenGLView : NSOpenGLView
 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
 <NSWindowDelegate>
 #endif
@@ -47,17 +33,6 @@
 	//Cocoa
 	NSWindow *window;
 
-	//CoreVideo
-	CVPixelBufferRef frameBuffers[2];
-	CVOpenGLTextureCacheRef textureCache;
-	CVOpenGLTextureRef texture;
-	NSRect textureFrame;
-
-	GLfloat lowerLeft[2];
-	GLfloat lowerRight[2];
-	GLfloat upperRight[2];
-	GLfloat upperLeft[2];
-
 	BOOL mouseHide;
 
 	//menu command id
@@ -85,11 +60,6 @@
 //window & rendering
 - (void) preinit;
 - (void) config:(uint32_t)width:(uint32_t)height:(uint32_t)flags;
-- (void) prepareOpenGL;
-- (void) render;
-- (void) reshape;
-- (void) setCurrentTexture;
-- (void) drawRect: (NSRect *) bounds;
 
 //vo control
 - (void) fullscreen: (BOOL) animate;
@@ -112,6 +82,8 @@
 - (void) scrollWheel: (NSEvent *) theEvent;
 - (void) mouseEvent: (NSEvent *) theEvent;
 - (void) check_events;
+
+- (void) update_screen_info;
 @end
 
-#endif /* MPLAYER_VO_COREVIDEO_H */
+#endif /* MPLAYER_OSX_OBJC_COMMON_H */

Copied and modified: trunk/libvo/osx_objc_common.m (from r35179, trunk/libvo/vo_corevideo.m)
==============================================================================
--- trunk/libvo/vo_corevideo.m	Thu Sep 13 21:15:37 2012	(r35179, copy source)
+++ trunk/libvo/osx_objc_common.m	Thu Sep 13 21:20:47 2012	(r35180)
@@ -19,11 +19,8 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#import "vo_corevideo.h"
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/mman.h>
-#include <unistd.h>
+#import "osx_objc_common.h"
+#include <Carbon/Carbon.h>
 #include <CoreServices/CoreServices.h>
 //special workaround for Apple bug #6267445
 //(OSServices Power API disabled in OSServices.h for 64bit systems)
@@ -33,15 +30,10 @@
 
 //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 "sub/sub.h"
-#include "subopt-helper.h"
 
 #include "input/input.h"
 #include "input/mouse.h"
@@ -49,69 +41,64 @@
 #include "osdep/keycodes.h"
 #include "osx_common.h"
 
-//Cocoa
-static NSDistantObject *mplayerosxProxy;
-static id <MPlayerOSXVOProto> mplayerosxProto;
-static MPlayerOpenGLView *mpGLView;
-static NSAutoreleasePool *autoreleasepool;
-static OSType pixelFormat;
+static float winAlpha = 1;
 
-//shared memory
-static BOOL shared_buffer = false;
-#define DEFAULT_BUFFER_NAME "mplayerosx"
-static char *buffer_name;
+static BOOL isLeopardOrLater;
 
-//Screen
-static int screen_id = -1;
+static NSAutoreleasePool *autoreleasepool;
+static MPCommonOpenGLView *oglv;
 
-//image
-static unsigned char *image_data;
-// For double buffering
-static uint8_t image_page = 0;
-static unsigned char *image_datas[2];
+int vo_osx_init(void)
+{
+    autoreleasepool = [[NSAutoreleasePool alloc] init];
+    oglv = [[MPCommonOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) pixelFormat:[MPCommonOpenGLView defaultPixelFormat]];
+    [oglv autorelease];
+    [oglv display];
+    [oglv preinit];
+    return 1;
+}
 
-static uint32_t image_width;
-static uint32_t image_height;
-static uint32_t image_bytes;
-static uint32_t image_stride;
-static uint32_t image_format;
+void vo_osx_uninit(void)
+{
+    NSAutoreleasePool *finalPool;
+    oglv = nil;
+    [autoreleasepool release];
+    finalPool = [[NSAutoreleasePool alloc] init];
+    [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES];
+    [finalPool release];
+}
 
-static float winAlpha = 1;
+int vo_osx_config(uint32_t width, uint32_t height, uint32_t flags)
+{
+    [oglv config:width:height:flags];
+    return 1;
+}
 
-static BOOL isLeopardOrLater;
+void vo_osx_ontop(void)
+{
+    vo_ontop = !vo_ontop;
+    [oglv ontop];
+}
 
-static vo_info_t info =
+void vo_osx_fullscreen(void)
 {
-	"Mac OS X Core Video",
-	"corevideo",
-	"Nicolas Plourde <nicolas.plourde at gmail.com>",
-	""
-};
+    vo_fs = !vo_fs;
+    [oglv fullscreen:YES];
+}
 
-LIBVO_EXTERN(corevideo)
+int vo_osx_check_events(void)
+{
+    [oglv check_events];
+    return 0;
+}
 
-static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride)
+void vo_osx_update_xinerama_info(void)
 {
-	unsigned char *dst = image_data + image_bytes * (y0 * image_width + x0);
-	switch (image_format)
-	{
-		case IMGFMT_RGB24:
-			vo_draw_alpha_rgb24(w,h,src,srca,stride,dst,image_stride);
-			break;
-		case IMGFMT_ARGB:
-		case IMGFMT_BGRA:
-			vo_draw_alpha_rgb32(w,h,src,srca,stride,dst,image_stride);
-			break;
-		case IMGFMT_YUY2:
-			vo_draw_alpha_yuy2(w,h,src,srca,stride,dst,image_stride);
-			break;
-		case IMGFMT_UYVY:
-			vo_draw_alpha_uyvy(w,h,src,srca,stride,dst,image_stride);
-			break;
-	}
+    [oglv update_screen_info];
 }
 
-static void update_screen_info(void)
+ at implementation MPCommonOpenGLView
+- (void) update_screen_info
 {
 	int screen_id = xinerama_screen;
 	NSArray *screen_array = [NSScreen screens];
@@ -123,8 +110,8 @@ static void update_screen_info(void)
 		mp_msg(MSGT_VO, MSGL_INFO, "[vo_corevideo] Device ID %d does not exist, falling back to main device\n", screen_id);
 		screen_id = -1;
 	}
-	if (screen_id < 0 && [mpGLView window])
-		screen_handle = [[mpGLView window] screen];
+	if (screen_id < 0 && [self window])
+		screen_handle = [[self window] screen];
 	else
 		screen_handle = [screen_array objectAtIndex:(screen_id < 0 ? 0 : screen_id)];
 
@@ -136,316 +123,10 @@ static void update_screen_info(void)
 	aspect_save_screenres(vo_screenwidth, vo_screenheight);
 }
 
-static void free_file_specific(void)
-{
-	if(shared_buffer)
-	{
-		[mplayerosxProto stop];
-		mplayerosxProto = nil;
-		[mplayerosxProxy release];
-		mplayerosxProxy = nil;
-
-		if (munmap(image_data, image_height*image_stride) == -1)
-			mp_msg(MSGT_VO, MSGL_FATAL, "[vo_corevideo] uninit: munmap failed. Error: %s\n", strerror(errno));
-
-		if (shm_unlink(buffer_name) == -1)
-			mp_msg(MSGT_VO, MSGL_FATAL, "[vo_corevideo] uninit: shm_unlink failed. Error: %s\n", strerror(errno));
-    } else {
-        free(image_datas[0]);
-        free(image_datas[1]);
-        image_datas[0] = NULL;
-        image_datas[1] = NULL;
-        image_data = 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)
-{
-	free_file_specific();
-
-	//misc mplayer setup
-	image_width = width;
-	image_height = height;
-	switch (image_format)
-	{
-		case IMGFMT_RGB24:
-			image_bytes = 3;
-			break;
-		case IMGFMT_ARGB:
-		case IMGFMT_BGRA:
-			image_bytes = 4;
-			break;
-		case IMGFMT_YUY2:
-		case IMGFMT_UYVY:
-			image_bytes = 2;
-			break;
-	}
-	// should be aligned, but that would break the shared buffer
-	image_stride = image_width * image_bytes;
-
-	if(!shared_buffer)
-	{
-		image_data = malloc(image_height*image_stride);
-		image_datas[0] = image_data;
-		if (vo_doublebuffering)
-			image_datas[1] = malloc(image_height*image_stride);
-		image_page = 0;
-
-		//config OpenGL View
-		[mpGLView config:d_width:d_height:flags];
-		[mpGLView reshape];
-		[[mpGLView window] setTitle:[NSString stringWithCString:vo_wintitle ? vo_wintitle : title]];
-	}
-	else
-	{
-		int shm_fd;
-		mp_msg(MSGT_VO, MSGL_INFO, "[vo_corevideo] writing output to a shared buffer "
-				"named \"%s\"\n",buffer_name);
-
-		// create shared memory
-		shm_fd = shm_open(buffer_name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
-		if (shm_fd == -1)
-		{
-			mp_msg(MSGT_VO, MSGL_FATAL,
-				   "[vo_corevideo] failed to open shared memory. Error: %s\n", strerror(errno));
-			return 1;
-		}
-
-
-		if (ftruncate(shm_fd, image_height*image_stride) == -1)
-		{
-			mp_msg(MSGT_VO, MSGL_FATAL,
-				   "[vo_corevideo] failed to size shared memory, possibly already in use. Error: %s\n", strerror(errno));
-			close(shm_fd);
-			shm_unlink(buffer_name);
-			return 1;
-		}
-
-		image_data = mmap(NULL, image_height*image_stride,
-					PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
-		close(shm_fd);
-
-		if (image_data == MAP_FAILED)
-		{
-			mp_msg(MSGT_VO, MSGL_FATAL,
-				   "[vo_corevideo] failed to map shared memory. Error: %s\n", strerror(errno));
-			shm_unlink(buffer_name);
-			return 1;
-		}
-
-		//connect to mplayerosx
-		mplayerosxProxy=[NSConnection rootProxyForConnectionWithRegisteredName:[NSString stringWithCString:buffer_name] host:nil];
-		if ([mplayerosxProxy conformsToProtocol:@protocol(MPlayerOSXVOProto)]) {
-			[mplayerosxProxy setProtocolForProxy:@protocol(MPlayerOSXVOProto)];
-			mplayerosxProto = (id <MPlayerOSXVOProto>)mplayerosxProxy;
-			[mplayerosxProto startWithWidth: image_width withHeight: image_height withBytes: image_bytes withAspect:d_width*100/d_height];
-		}
-		else {
-			[mplayerosxProxy release];
-			mplayerosxProxy = nil;
-			mplayerosxProto = nil;
-		}
-	}
-	return 0;
-}
-
-static void check_events(void)
-{
-	if (mpGLView)
-		[mpGLView check_events];
-}
-
-static void draw_osd(void)
-{
-	vo_draw_text(image_width, image_height, draw_alpha);
-}
-
-static void flip_page(void)
-{
-	if(shared_buffer) {
-		NSAutoreleasePool *pool = [NSAutoreleasePool new];
-		[mplayerosxProto render];
-		[pool release];
-	} else {
-		[mpGLView setCurrentTexture];
-		[mpGLView render];
-		if (vo_doublebuffering) {
-			image_page = 1 - image_page;
-			image_data = image_datas[image_page];
-		}
-	}
-}
-
-static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
-{
-	return 0;
-}
-
-
-static int draw_frame(uint8_t *src[])
-{
-	return 0;
-}
-
-static uint32_t draw_image(mp_image_t *mpi)
-{
-	if (!(mpi->flags & MP_IMGFLAG_DIRECT))
-	memcpy_pic(image_data, mpi->planes[0], image_width*image_bytes, image_height, image_stride, mpi->stride[0]);
-
-	return 0;
-}
-
-static int query_format(uint32_t format)
-{
-    const int supportflags = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN;
-	image_format = format;
-
-    switch(format)
-	{
-		case IMGFMT_YUY2:
-			pixelFormat = kYUVSPixelFormat;
-			return supportflags;
-
-		case IMGFMT_UYVY:
-			pixelFormat = k2vuyPixelFormat;
-			return supportflags;
-
-		case IMGFMT_RGB24:
-			pixelFormat = k24RGBPixelFormat;
-			return supportflags;
-
-		case IMGFMT_ARGB:
-			pixelFormat = k32ARGBPixelFormat;
-			return supportflags;
-
-		case IMGFMT_BGRA:
-			pixelFormat = k32BGRAPixelFormat;
-			return supportflags;
-    }
-    return 0;
-}
-
-static int get_image(mp_image_t *mpi)
-{
-    if (!(mpi->flags & (MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_ACCEPT_WIDTH)) ||
-            (mpi->type != MP_IMGTYPE_TEMP && mpi->type != MP_IMGTYPE_STATIC))
-        return VO_FALSE;
-
-	// mpi should not be planar format here
-	mpi->planes[0] = image_data;
-	mpi->stride[0] = image_stride;
-	mpi->flags |=  MP_IMGFLAG_DIRECT;
-	mpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK;
-	return VO_TRUE;
-}
-
-static void uninit(void)
-{
-    SetSystemUIMode( kUIModeNormal, 0);
-    CGDisplayShowCursor(kCGDirectMainDisplay);
-
-    free_file_specific();
-
-    if(mpGLView)
-    {
-        NSAutoreleasePool *finalPool;
-        mpGLView = nil;
-        [autoreleasepool release];
-        finalPool = [[NSAutoreleasePool alloc] init];
-        [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES];
-        [finalPool release];
-    }
-
-    free(buffer_name);
-    buffer_name = NULL;
-}
-
-static const opt_t subopts[] = {
-{"device_id",     OPT_ARG_INT,  &screen_id,     NULL},
-{"shared_buffer", OPT_ARG_BOOL, &shared_buffer, NULL},
-{"buffer_name",   OPT_ARG_MSTRZ,&buffer_name,   NULL},
-{NULL}
-};
-
-static int preinit(const char *arg)
-{
-
-	// set defaults
-	screen_id = -1;
-	shared_buffer = false;
-	buffer_name = NULL;
-
-	if (subopt_parse(arg, subopts) != 0) {
-		mp_msg(MSGT_VO, MSGL_FATAL,
-				"\n-vo corevideo command line help:\n"
-				"Example: mplayer -vo corevideo:device_id=1:shared_buffer:buffer_name=mybuff\n"
-				"\nOptions:\n"
-				"  device_id=<0-...>\n"
-				"    DEPRECATED, use -xineramascreen instead.\n"
-				"    Set screen device ID for fullscreen.\n"
-				"  shared_buffer\n"
-				"    Write output to a shared memory buffer instead of displaying it.\n"
-				"  buffer_name=<name>\n"
-				"    Name of the shared buffer created with shm_open() as well as\n"
-				"    the name of the NSConnection MPlayer will try to open.\n"
-				"    Setting buffer_name implicitly enables shared_buffer.\n"
-				"\n" );
-		return -1;
-	}
-
-	autoreleasepool = [[NSAutoreleasePool alloc] init];
-
-	if (screen_id != -1)
-		xinerama_screen = screen_id;
-
-	if (!buffer_name)
-		buffer_name = strdup(DEFAULT_BUFFER_NAME);
-	else
-		shared_buffer = true;
-
-	if(!shared_buffer)
-	{
-		if(!mpGLView)
-		{
-			mpGLView = [[MPlayerOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) pixelFormat:[MPlayerOpenGLView defaultPixelFormat]];
-			[mpGLView autorelease];
-		}
-		[mpGLView display];
-		[mpGLView preinit];
-	}
-
-    return 0;
-}
-
-static int control(uint32_t request, void *data)
-{
-	switch (request)
-	{
-		case VOCTRL_DRAW_IMAGE: return draw_image(data);
-		case VOCTRL_PAUSE:
-		case VOCTRL_RESUME:
-			return VO_TRUE;
-		case VOCTRL_QUERY_FORMAT: return query_format(*(uint32_t*)data);
-		case VOCTRL_GET_IMAGE: return get_image(data);
-		case VOCTRL_ONTOP: vo_ontop = !vo_ontop; if(!shared_buffer){ [mpGLView ontop]; } else { [mplayerosxProto ontop]; } return VO_TRUE;
-		case VOCTRL_ROOTWIN: vo_rootwin = !vo_rootwin; [mpGLView rootwin]; return VO_TRUE;
-		case VOCTRL_FULLSCREEN: vo_fs = !vo_fs; if(!shared_buffer){ [mpGLView fullscreen: NO]; } else { [mplayerosxProto toggleFullscreen]; } return VO_TRUE;
-		case VOCTRL_GET_PANSCAN: return VO_TRUE;
-		case VOCTRL_SET_PANSCAN: panscan_calc(); return VO_TRUE;
-		case VOCTRL_UPDATE_SCREENINFO: update_screen_info(); return VO_TRUE;
-	}
-	return VO_NOTIMPL;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// NSOpenGLView Subclass
-//////////////////////////////////////////////////////////////////////////
- at implementation MPlayerOpenGLView
 - (void) preinit
 {
 	NSOpenGLContext *glContext;
 	GLint swapInterval = 1;
-	CVReturn error;
 
 	NSApplicationLoad();
 	NSApp = [NSApplication sharedApplication];
@@ -488,35 +169,16 @@ static int control(uint32_t request, voi
 	[glContext setView:self];
 	[glContext makeCurrentContext];
 	[glContext release];
-
-	error = CVOpenGLTextureCacheCreate(NULL, 0, [glContext CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache);
-	if(error != kCVReturnSuccess)
-		mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture Cache(%d)\n", error);
-}
-
-- (void) releaseVideoSpecific
-{
-	CVPixelBufferRelease(frameBuffers[0]);
-	frameBuffers[0] = NULL;
-	CVPixelBufferRelease(frameBuffers[1]);
-	frameBuffers[1] = NULL;
-	CVOpenGLTextureRelease(texture);
-	texture = NULL;
 }
 
 - (void) dealloc
 {
-	[self releaseVideoSpecific];
-	CVOpenGLTextureCacheRelease(textureCache);
-	textureCache = NULL;
 	[self setOpenGLContext:nil];
 	[super dealloc];
 }
 
 - (void) config:(uint32_t)width:(uint32_t)height:(uint32_t)flags
 {
-	CVReturn error = kCVReturnSuccess;
-
 	config_movie_aspect((float)width/height);
 
 	vo_dwidth  = width  *= self->winSizeMult;
@@ -530,25 +192,11 @@ static int control(uint32_t request, voi
 	// being placed strangely off-center since vo_dx/vo_dy calculation is
 	// not aware of it.
 	// Also flip vo_dy since the screen origin is in the bottom left on OSX.
-	update_screen_info();
+	[self update_screen_info];
 	[window setFrameTopLeftPoint:NSMakePoint(
 		vo_dx,
 		2*xinerama_y + vo_screenheight - vo_dy)];
 
-	[self releaseVideoSpecific];
-	error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[0], image_stride, NULL, NULL, NULL, &frameBuffers[0]);
-	if(error != kCVReturnSuccess)
-		mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create Pixel Buffer(%d)\n", error);
-	if (vo_doublebuffering) {
-		error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[1], image_stride, NULL, NULL, NULL, &frameBuffers[1]);
-		if(error != kCVReturnSuccess)
-			mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create Pixel Double Buffer(%d)\n", error);
-	}
-
-	error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture);
-	if(error != kCVReturnSuccess)
-		mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture(%d)\n", error);
-
 	vo_fs = flags & VOFLAG_FULLSCREEN;
 
 	[self rootwin];
@@ -558,8 +206,9 @@ static int control(uint32_t request, voi
 
 	[self ontop];
 
-	//show window
-	[window makeKeyAndOrderFront:self];
+	if (!(flags & VOFLAG_HIDDEN))
+		//show window
+		[window makeKeyAndOrderFront:self];
 }
 
 /*
@@ -703,117 +352,6 @@ static int control(uint32_t request, voi
 }
 
 /*
-	Setup OpenGL
-*/
-- (void)prepareOpenGL
-{
-	glEnable(GL_BLEND);
-	glDisable(GL_DEPTH_TEST);
-	glDepthMask(GL_FALSE);
-	glDisable(GL_CULL_FACE);
-	[self reshape];
-}
-
-/*
-	reshape OpenGL viewport
-*/
-- (void)reshape
-{
-	int d_width, d_height;
-
-	NSRect frame = [self frame];
-	vo_dwidth  = frame.size.width;
-	vo_dheight = frame.size.height;
-
-	glViewport(0, 0, frame.size.width, frame.size.height);
-	glMatrixMode(GL_PROJECTION);
-	glLoadIdentity();
-	glOrtho(0, frame.size.width, frame.size.height, 0, -1.0, 1.0);
-	glMatrixMode(GL_MODELVIEW);
-	glLoadIdentity();
-
-	//set texture frame
-	if(vo_keepaspect)
-	{
-		aspect(&d_width, &d_height, A_WINZOOM);
-
-		textureFrame = NSMakeRect((vo_dwidth - d_width) / 2, (vo_dheight - d_height) / 2, d_width, d_height);
-	}
-	else
-	{
-		textureFrame = frame;
-	}
-}
-
-/*
-	Render frame
-*/
-- (void) render
-{
-	glClear(GL_COLOR_BUFFER_BIT);
-
-	glEnable(CVOpenGLTextureGetTarget(texture));
-	glBindTexture(CVOpenGLTextureGetTarget(texture), CVOpenGLTextureGetName(texture));
-
-	glColor3f(1,1,1);
-	glBegin(GL_QUADS);
-	glTexCoord2f(upperLeft[0], upperLeft[1]); glVertex2i(	textureFrame.origin.x-(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1));
-	glTexCoord2f(lowerLeft[0], lowerLeft[1]); glVertex2i(textureFrame.origin.x-(vo_panscan_x >> 1), NSMaxY(textureFrame)+(vo_panscan_y >> 1));
-	glTexCoord2f(lowerRight[0], lowerRight[1]); glVertex2i(NSMaxX(textureFrame)+(vo_panscan_x >> 1), NSMaxY(textureFrame)+(vo_panscan_y >> 1));
-	glTexCoord2f(upperRight[0], upperRight[1]); glVertex2i(NSMaxX(textureFrame)+(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1));
-	glEnd();
-	glDisable(CVOpenGLTextureGetTarget(texture));
-
-	//render resize box
-	if(!vo_fs)
-	{
-		NSRect frame = [self frame];
-
-		glBegin(GL_LINES);
-		glColor4f(0.2, 0.2, 0.2, 0.5);
-		glVertex2i(frame.size.width-1, frame.size.height-1); glVertex2i(frame.size.width-1, frame.size.height-1);
-		glVertex2i(frame.size.width-1, frame.size.height-5); glVertex2i(frame.size.width-5, frame.size.height-1);
-		glVertex2i(frame.size.width-1, frame.size.height-9); glVertex2i(frame.size.width-9, frame.size.height-1);
-
-		glColor4f(0.4, 0.4, 0.4, 0.5);
-		glVertex2i(frame.size.width-1, frame.size.height-2); glVertex2i(frame.size.width-2, frame.size.height-1);
-		glVertex2i(frame.size.width-1, frame.size.height-6); glVertex2i(frame.size.width-6, frame.size.height-1);
-		glVertex2i(frame.size.width-1, frame.size.height-10); glVertex2i(frame.size.width-10, frame.size.height-1);
-
-		glColor4f(0.6, 0.6, 0.6, 0.5);
-		glVertex2i(frame.size.width-1, frame.size.height-3); glVertex2i(frame.size.width-3, frame.size.height-1);
-		glVertex2i(frame.size.width-1, frame.size.height-7); glVertex2i(frame.size.width-7, frame.size.height-1);
-		glVertex2i(frame.size.width-1, frame.size.height-11); glVertex2i(frame.size.width-11, frame.size.height-1);
-		glEnd();
-	}
-
-	glFlush();
-}
-
-/*
-	Create OpenGL texture from current frame & set texco
-*/
-- (void) setCurrentTexture
-{
-	CVReturn error = kCVReturnSuccess;
-
-	CVOpenGLTextureRelease(texture);
-	error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture);
-	if(error != kCVReturnSuccess)
-		mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture(%d)\n", error);
-
-    CVOpenGLTextureGetCleanTexCoords(texture, lowerLeft, lowerRight, upperRight, upperLeft);
-}
-
-/*
-	redraw win rect
-*/
-- (void) drawRect: (NSRect *) bounds
-{
-	[self render];
-}
-
-/*
 	Toggle Fullscreen
 */
 - (void) fullscreen: (BOOL) animate
@@ -834,7 +372,7 @@ static int control(uint32_t request, voi
 		}
 
 		old_frame = [window frame];	//save main window size & position
-		update_screen_info();
+		[self update_screen_info];
 
 		[window setFrame:NSMakeRect(xinerama_x, xinerama_y, vo_screenwidth, vo_screenheight) display:YES animate:animate]; //zoom-in window with nice useless sfx
 		old_view_frame = [self bounds];

Modified: trunk/libvo/vo_corevideo.h
==============================================================================
--- trunk/libvo/vo_corevideo.h	Thu Sep 13 21:15:37 2012	(r35179)
+++ trunk/libvo/vo_corevideo.h	Thu Sep 13 21:20:47 2012	(r35180)
@@ -26,6 +26,7 @@
 #import <Cocoa/Cocoa.h>
 #import <QuartzCore/QuartzCore.h>
 #import <Carbon/Carbon.h>
+#import "osx_objc_common.h"
 
 // MPlayer OS X VO Protocol
 @protocol MPlayerOSXVOProto
@@ -39,14 +40,8 @@
 - (void) ontop;
 @end
 
- at interface MPlayerOpenGLView : NSOpenGLView
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
-<NSWindowDelegate>
-#endif
+ at interface MPlayerOpenGLView : MPCommonOpenGLView
 {
-	//Cocoa
-	NSWindow *window;
-
 	//CoreVideo
 	CVPixelBufferRef frameBuffers[2];
 	CVOpenGLTextureCacheRef textureCache;
@@ -57,31 +52,8 @@
 	GLfloat lowerRight[2];
 	GLfloat upperRight[2];
 	GLfloat upperLeft[2];
-
-	BOOL mouseHide;
-
-	//menu command id
-	NSMenuItem *kHalfScreenCmd;
-	NSMenuItem *kNormalScreenCmd;
-	NSMenuItem *kDoubleScreenCmd;
-	NSMenuItem *kFullScreenCmd;
-	NSMenuItem *kKeepAspectCmd;
-	NSMenuItem *kAspectOrgCmd;
-	NSMenuItem *kAspectFullCmd;
-	NSMenuItem *kAspectWideCmd;
-	NSMenuItem *kPanScanCmd;
-
-	//timestamps for disabling screensaver and mouse hiding
-	int lastMouseHide;
-	int lastScreensaverUpdate;
- at public
-	float winSizeMult;
 }
 
-- (BOOL) acceptsFirstResponder;
-- (BOOL) becomeFirstResponder;
-- (BOOL) resignFirstResponder;
-
 //window & rendering
 - (void) preinit;
 - (void) config:(uint32_t)width:(uint32_t)height:(uint32_t)flags;
@@ -91,27 +63,6 @@
 - (void) setCurrentTexture;
 - (void) drawRect: (NSRect *) bounds;
 
-//vo control
-- (void) fullscreen: (BOOL) animate;
-- (void) ontop;
-- (void) rootwin;
-
-//menu
-- (void) initMenu;
-- (void) menuAction:(id)sender;
-
-//event
-- (void) keyDown: (NSEvent *) theEvent;
-- (void) mouseMoved: (NSEvent *) theEvent;
-- (void) mouseDown: (NSEvent *) theEvent;
-- (void) mouseUp: (NSEvent *) theEvent;
-- (void) rightMouseDown: (NSEvent *) theEvent;
-- (void) rightMouseUp: (NSEvent *) theEvent;
-- (void) otherMouseDown: (NSEvent *) theEvent;
-- (void) otherMouseUp: (NSEvent *) theEvent;
-- (void) scrollWheel: (NSEvent *) theEvent;
-- (void) mouseEvent: (NSEvent *) theEvent;
-- (void) check_events;
 @end
 
 #endif /* MPLAYER_VO_COREVIDEO_H */

Modified: trunk/libvo/vo_corevideo.m
==============================================================================
--- trunk/libvo/vo_corevideo.m	Thu Sep 13 21:15:37 2012	(r35179)
+++ trunk/libvo/vo_corevideo.m	Thu Sep 13 21:20:47 2012	(r35180)
@@ -76,10 +76,6 @@ static uint32_t image_bytes;
 static uint32_t image_stride;
 static uint32_t image_format;
 
-static float winAlpha = 1;
-
-static BOOL isLeopardOrLater;
-
 static vo_info_t info =
 {
 	"Mac OS X Core Video",
@@ -111,31 +107,6 @@ static void draw_alpha(int x0, int y0, i
 	}
 }
 
-static void update_screen_info(void)
-{
-	int screen_id = xinerama_screen;
-	NSArray *screen_array = [NSScreen screens];
-	NSScreen *screen_handle;
-	NSRect screen_frame;
-
-	if(screen_id >= (int)[screen_array count])
-	{
-		mp_msg(MSGT_VO, MSGL_INFO, "[vo_corevideo] Device ID %d does not exist, falling back to main device\n", screen_id);
-		screen_id = -1;
-	}
-	if (screen_id < 0 && [mpGLView window])
-		screen_handle = [[mpGLView window] screen];
-	else
-		screen_handle = [screen_array objectAtIndex:(screen_id < 0 ? 0 : screen_id)];
-
-	screen_frame = [screen_handle frame];
-	vo_screenwidth = screen_frame.size.width;
-	vo_screenheight = screen_frame.size.height;
-	xinerama_x = screen_frame.origin.x;
-	xinerama_y = screen_frame.origin.y;
-	aspect_save_screenres(vo_screenwidth, vo_screenheight);
-}
-
 static void free_file_specific(void)
 {
 	if(shared_buffer)
@@ -432,7 +403,7 @@ static int control(uint32_t request, voi
 		case VOCTRL_FULLSCREEN: vo_fs = !vo_fs; if(!shared_buffer){ [mpGLView fullscreen: NO]; } else { [mplayerosxProto toggleFullscreen]; } return VO_TRUE;
 		case VOCTRL_GET_PANSCAN: return VO_TRUE;
 		case VOCTRL_SET_PANSCAN: panscan_calc(); return VO_TRUE;
-		case VOCTRL_UPDATE_SCREENINFO: update_screen_info(); return VO_TRUE;
+		case VOCTRL_UPDATE_SCREENINFO: [mpGLView update_screen_info]; return VO_TRUE;
 	}
 	return VO_NOTIMPL;
 }
@@ -443,53 +414,11 @@ static int control(uint32_t request, voi
 @implementation MPlayerOpenGLView
 - (void) preinit
 {
-	NSOpenGLContext *glContext;
-	GLint swapInterval = 1;
 	CVReturn error;
 
-	NSApplicationLoad();
-	NSApp = [NSApplication sharedApplication];
-	isLeopardOrLater = floor(NSAppKitVersionNumber) > 824;
-
-	osx_foreground_hack();
-
-	// Install an event handler so the Quit menu entry works
-	// The proper way using NSApp setDelegate: and
-	// applicationShouldTerminate: does not work,
-	// probably NSApplication never installs its handler.
-	[[NSAppleEventManager sharedAppleEventManager]
-		setEventHandler:self
-		andSelector:@selector(handleQuitEvent:withReplyEvent:)
-		forEventClass:kCoreEventClass
-		andEventID:kAEQuitApplication];
-
-	//init menu
-	[self initMenu];
-
-	//create window
-	window = [[NSWindow alloc]	initWithContentRect:NSMakeRect(0, 0, 100, 100)
-								styleMask:NSTitledWindowMask|NSTexturedBackgroundWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask
-								backing:NSBackingStoreBuffered defer:NO];
-
-	[window autorelease];
-	[window setDelegate:self];
-	[window setContentView:self];
-	[window setInitialFirstResponder:self];
-	[window setAcceptsMouseMovedEvents:YES];
-	[window setTitle:@"MPlayer - The Movie Player"];
-
-	winSizeMult = 1;
-
-	//create OpenGL Context
-	glContext = [[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:nil];
-
-	[self setOpenGLContext:glContext];
-	[glContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
-	[glContext setView:self];
-	[glContext makeCurrentContext];
-	[glContext release];
+	[super preinit];
 
-	error = CVOpenGLTextureCacheCreate(NULL, 0, [glContext CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache);
+	error = CVOpenGLTextureCacheCreate(NULL, 0, [[self openGLContext] CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache);
 	if(error != kCVReturnSuccess)
 		mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture Cache(%d)\n", error);
 }
@@ -509,7 +438,6 @@ static int control(uint32_t request, voi
 	[self releaseVideoSpecific];
 	CVOpenGLTextureCacheRelease(textureCache);
 	textureCache = NULL;
-	[self setOpenGLContext:nil];
 	[super dealloc];
 }
 
@@ -517,23 +445,7 @@ static int control(uint32_t request, voi
 {
 	CVReturn error = kCVReturnSuccess;
 
-	config_movie_aspect((float)width/height);
-
-	vo_dwidth  = width  *= self->winSizeMult;
-	vo_dheight = height *= self->winSizeMult;
-
-	//config window
-	[window setContentSize:NSMakeSize(vo_dwidth, vo_dheight)];
-
-	// Do not use visibleFrame - taking the menu bar and dock into account
-	// would be nicer in principle, but currently only results in the window
-	// being placed strangely off-center since vo_dx/vo_dy calculation is
-	// not aware of it.
-	// Also flip vo_dy since the screen origin is in the bottom left on OSX.
-	update_screen_info();
-	[window setFrameTopLeftPoint:NSMakePoint(
-		vo_dx,
-		2*xinerama_y + vo_screenheight - vo_dy)];
+	[super config:width:height:flags];
 
 	[self releaseVideoSpecific];
 	error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[0], image_stride, NULL, NULL, NULL, &frameBuffers[0]);
@@ -548,158 +460,6 @@ static int control(uint32_t request, voi
 	error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture);
 	if(error != kCVReturnSuccess)
 		mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture(%d)\n", error);
-
-	vo_fs = flags & VOFLAG_FULLSCREEN;
-
-	[self rootwin];
-
-	if(vo_fs)
-		[self fullscreen: NO];
-
-	[self ontop];
-
-	//show window
-	[window makeKeyAndOrderFront:self];
-}
-
-/*
-	Init Menu
-*/
-- (void)initMenu
-{
-	NSMenu *mainMenu = [[NSMenu alloc] init];
-	NSMenu *menu, *aspectMenu;
-	NSMenuItem *menuItem;
-
-	menu = [[NSMenu alloc] init];
-	menuItem = [[NSMenuItem alloc] init];
-	[menuItem setSubmenu:menu];
-	[mainMenu addItem:menuItem];
-	// Note: setAppleMenu seems to be unnecessary from 10.6 on,
-	// but is needed for all earlier versions or the menu is
-	// messed up.
-	// Round-about way with performSelector used to avoid compiler
-	// warnings.
-	[NSApp performSelector:@selector(setAppleMenu:) withObject:menu];
-
-//Create Movie Menu
-	menu = [[NSMenu alloc] initWithTitle:@"Movie"];
-	menuItem = [[NSMenuItem alloc] initWithTitle:@"Half Size" action:@selector(menuAction:) keyEquivalent:@"0"]; [menu addItem:menuItem];
-	kHalfScreenCmd = menuItem;
-	menuItem = [[NSMenuItem alloc] initWithTitle:@"Normal Size" action:@selector(menuAction:) keyEquivalent:@"1"]; [menu addItem:menuItem];
-	kNormalScreenCmd = menuItem;
-	menuItem = [[NSMenuItem alloc] initWithTitle:@"Double Size" action:@selector(menuAction:) keyEquivalent:@"2"]; [menu addItem:menuItem];
-	kDoubleScreenCmd = menuItem;
-	menuItem = [[NSMenuItem alloc] initWithTitle:@"Full Size" action:@selector(menuAction:) keyEquivalent:@"f"]; [menu addItem:menuItem];
-	kFullScreenCmd = menuItem;
-	menuItem = [NSMenuItem separatorItem]; [menu addItem:menuItem];
-
-	aspectMenu = [[NSMenu alloc] initWithTitle:@"Aspect Ratio"];
-	menuItem = [[NSMenuItem alloc] initWithTitle:@"Keep" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem];
-	if(vo_keepaspect) [menuItem setState:NSOnState];
-	kKeepAspectCmd = menuItem;
-	menuItem = [[NSMenuItem alloc] initWithTitle:@"Pan-Scan" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem];
-	if(vo_panscan) [menuItem setState:NSOnState];
-	kPanScanCmd = menuItem;
-	menuItem = [NSMenuItem separatorItem]; [aspectMenu addItem:menuItem];
-	menuItem = [[NSMenuItem alloc] initWithTitle:@"Original" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem];
-	kAspectOrgCmd = menuItem;
-	menuItem = [[NSMenuItem alloc] initWithTitle:@"4:3" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem];
-	kAspectFullCmd = menuItem;
-	menuItem = [[NSMenuItem alloc] initWithTitle:@"16:9" action:@selector(menuAction:) keyEquivalent:@""];	[aspectMenu addItem:menuItem];
-	kAspectWideCmd = menuItem;
-	menuItem = [[NSMenuItem alloc] initWithTitle:@"Aspect Ratio" action:nil keyEquivalent:@""];
-	[menuItem setSubmenu:aspectMenu];
-	[menu addItem:menuItem];
-	[aspectMenu release];
-
-	//Add to menubar
-	menuItem = [[NSMenuItem alloc] initWithTitle:@"Movie" action:nil keyEquivalent:@""];
-	[menuItem setSubmenu:menu];
-	[mainMenu addItem:menuItem];
-
-//Create Window Menu
-	menu = [[NSMenu alloc] initWithTitle:@"Window"];
-
-	menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; [menu addItem:menuItem];
-	menuItem = [[NSMenuItem alloc] initWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""]; [menu addItem:menuItem];
-
-	//Add to menubar
-	menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
-	[menuItem setSubmenu:menu];
-	[mainMenu addItem:menuItem];
-	[NSApp setWindowsMenu:menu];
-	[NSApp setMainMenu:mainMenu];
-
-	[menu release];
-	[menuItem release];
-}
-
-- (void)set_winSizeMult:(float)mult
-{
-    NSRect frame;
-    int d_width, d_height;
-    aspect(&d_width, &d_height, A_NOZOOM);
-
-    if (vo_fs) {
-        vo_fs = !vo_fs;
-        [self fullscreen:NO];
-    }
-
-    winSizeMult = mult;
-    frame.size.width  = d_width  * mult;
-    frame.size.height = d_height * mult;
-    [window setContentSize: frame.size];
-    [self reshape];
-}
-
-/*
-	Menu Action
- */
-- (void)menuAction:(id)sender
-{
-	if(sender == kHalfScreenCmd)
-		[self set_winSizeMult: 0.5];
-	if(sender == kNormalScreenCmd)
-		[self set_winSizeMult: 1];
-	if(sender == kDoubleScreenCmd)
-		[self set_winSizeMult: 2];
-	if(sender == kFullScreenCmd)
-	{
-		vo_fs = !vo_fs;
-		[self fullscreen:NO];
-	}
-
-	if(sender == kKeepAspectCmd)
-	{
-		vo_keepaspect = !vo_keepaspect;
-		if(vo_keepaspect)
-			[kKeepAspectCmd setState:NSOnState];
-		else
-			[kKeepAspectCmd setState:NSOffState];
-
-		[self reshape];
-	}
-
-	if(sender == kPanScanCmd)
-	{
-		vo_panscan = !vo_panscan;
-		if(vo_panscan)
-			[kPanScanCmd setState:NSOnState];
-		else
-			[kPanScanCmd setState:NSOffState];
-
-		panscan_calc();
-	}
-
-	if(sender == kAspectOrgCmd)
-		change_movie_aspect(-1);
-
-	if(sender == kAspectFullCmd)
-		change_movie_aspect(4.0f/3.0f);
-
-	if(sender == kAspectWideCmd)
-		change_movie_aspect(16.0f/9.0f);
 }
 
 /*
@@ -812,260 +572,4 @@ static int control(uint32_t request, voi
 {
 	[self render];
 }
-
-/*
-	Toggle Fullscreen
-*/
-- (void) fullscreen: (BOOL) animate
-{
-	static NSRect old_frame;
-	static NSRect old_view_frame;
-
-	panscan_calc();
-
-	//go fullscreen
-	if(vo_fs)
-	{
-		if(!vo_rootwin)
-		{
-			SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
-			CGDisplayHideCursor(kCGDirectMainDisplay);
-			mouseHide = YES;
-		}
-
-		old_frame = [window frame];	//save main window size & position
-		update_screen_info();
-
-		[window setFrame:NSMakeRect(xinerama_x, xinerama_y, vo_screenwidth, vo_screenheight) display:YES animate:animate]; //zoom-in window with nice useless sfx
-		old_view_frame = [self bounds];
-
-		[self setFrame:NSMakeRect(0, 0, vo_screenwidth, vo_screenheight)];
-		[self setNeedsDisplay:YES];
-		[window setHasShadow:NO];
-	}
-	else
-	{
-		SetSystemUIMode( kUIModeNormal, 0);
-
-		CGDisplayShowCursor(kCGDirectMainDisplay);
-		mouseHide = NO;
-
-		//revert window to previous setting
-		[self setFrame:old_view_frame];
-		[self setNeedsDisplay:YES];
-		[window setHasShadow:YES];
-		[window setFrame:old_frame display:YES animate:animate];//zoom-out window with nice useless sfx
-	}
-}
-
-/*
-	Toggle ontop
-*/
-- (void) ontop
-{
-	if(vo_ontop)
-	{
-		[window setLevel:NSScreenSaverWindowLevel];
-	}
-	else
-	{
-		[window setLevel:NSNormalWindowLevel];
-	}
-}
-
-/*
-	Toggle rootwin
- */
-- (void) rootwin
-{
-	if(vo_rootwin)
-	{
-		[window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey)];
-		[window orderBack:self];
-	}
-	else
-	{
-		[window setLevel:NSNormalWindowLevel];
-	}
-}
-
-/*
-	Check event for new event
-*/
-- (void) check_events
-{
-	NSEvent *event;
-	int curTime = TickCount()/60;
-
-	//automatically hide mouse cursor (and future on-screen control?)
-	if(vo_fs && !mouseHide && !vo_rootwin)
-	{
-		if(curTime - lastMouseHide >= 5 || lastMouseHide == 0)
-		{
-			CGDisplayHideCursor(kCGDirectMainDisplay);
-			mouseHide = TRUE;
-			lastMouseHide = curTime;
-		}
-	}
-
-	//update activity every 30 seconds to prevent
-	//screensaver from starting up.
-	if(curTime - lastScreensaverUpdate >= 30 || lastScreensaverUpdate == 0)
-	{
-		UpdateSystemActivity(UsrActivity);
-		lastScreensaverUpdate = curTime;
-	}
-
-	event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSEventTrackingRunLoopMode dequeue:YES];
-	if (event == nil)
-		return;
-	[NSApp sendEvent:event];
-	// Without SDL's bootstrap code (include SDL.h in mplayer.c),
-	// on Leopard, we have trouble to get the play window automatically focused
-	// when the app is actived. The Following code fix this problem.
-#ifndef CONFIG_SDL
-	if (isLeopardOrLater && [event type] == NSAppKitDefined
-			&& [event subtype] == NSApplicationActivatedEventType) {
-		[window makeMainWindow];
-		[window makeKeyAndOrderFront:self];
-	}
-#endif
-}
-
-/*
-	From NSView, respond to key equivalents.
-*/
-- (BOOL)performKeyEquivalent:(NSEvent *)theEvent
-{
-	switch([theEvent keyCode])
-	{
-		case 0x21: [window setAlphaValue: winAlpha-=0.05]; return YES;
-		case 0x1e: [window setAlphaValue: winAlpha+=0.05]; return YES;
-	}
-	return NO;
-}
-
-/*
-	Process key event
-*/
-- (void) keyDown: (NSEvent *) theEvent
-{
-	int key = convert_key([theEvent keyCode], *[[theEvent characters] UTF8String]);
-	if (key != -1)
-	mplayer_put_key(key);
-}
-
-/*
-	Process mouse button event
-*/
-- (void) mouseMoved: (NSEvent *) theEvent
-{
-	if(vo_fs && !vo_rootwin)
-	{
-		CGDisplayShowCursor(kCGDirectMainDisplay);
-		mouseHide = NO;
-	}
-	if (enable_mouse_movements && !vo_rootwin) {
-		NSPoint p =[self convertPoint:[theEvent locationInWindow] fromView:nil];
-		if ([self mouse:p inRect:[self frame]]) {
-			vo_mouse_movement(p.x, [self frame].size.height - p.y);
-		}
-	}
-}
-
-- (void) mouseDown: (NSEvent *) theEvent
-{
-	[self mouseEvent: theEvent];
-}
-
-- (void) mouseUp: (NSEvent *) theEvent
-{
-	[self mouseEvent: theEvent];
-}
-
-- (void) rightMouseDown: (NSEvent *) theEvent
-{
-	[self mouseEvent: theEvent];
-}
-
-- (void) rightMouseUp: (NSEvent *) theEvent
-{
-	[self mouseEvent: theEvent];
-}
-
-- (void) otherMouseDown: (NSEvent *) theEvent
-{
-	[self mouseEvent: theEvent];
-}
-
-- (void) otherMouseUp: (NSEvent *) theEvent
-{
-	[self mouseEvent: theEvent];
-}
-
-- (void) scrollWheel: (NSEvent *) theEvent
-{
-	if([theEvent deltaY] > 0)
-		mplayer_put_key(MOUSE_BTN3);
-	else
-		mplayer_put_key(MOUSE_BTN4);
-}
-
-- (void) mouseEvent: (NSEvent *) theEvent
-{
-	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;
-		switch([theEvent type])
-		{
-			case NSLeftMouseDown:
-			case NSRightMouseDown:
-			case NSOtherMouseDown:
-				mplayer_put_key((MOUSE_BTN0 + buttonNumber) | MP_KEY_DOWN);
-				break;
-			case NSLeftMouseUp:
-			case NSRightMouseUp:
-			case NSOtherMouseUp:
-				mplayer_put_key(MOUSE_BTN0 + buttonNumber);
-				break;
-		}
-	}
-}
-
-/*
-	NSResponder
-*/
-- (BOOL) acceptsFirstResponder
-{
-	return YES;
-}
-
-- (BOOL) becomeFirstResponder
-{
-	return YES;
-}
-
-- (BOOL) resignFirstResponder
-{
-	return YES;
-}
-
-- (BOOL)windowShouldClose:(id)sender
-{
-	mplayer_put_key(KEY_CLOSE_WIN);
-	// We have to wait for MPlayer to handle this,
-	// otherwise we are in trouble if the
-	// KEY_CLOSE_WIN handler is disabled
-	return NO;
-}
-
-- (void)handleQuitEvent:(NSAppleEventDescriptor*)e withReplyEvent:(NSAppleEventDescriptor*)r
-{
-	mplayer_put_key(KEY_CLOSE_WIN);
-}
 @end


More information about the MPlayer-cvslog mailing list