2005-04-29 11:05:16 +00:00
|
|
|
/*
|
|
|
|
vo_macosx.m
|
|
|
|
by Nicolas Plourde <nicolasplourde@gmail.com>
|
|
|
|
|
|
|
|
MPlayer Mac OSX video out module.
|
|
|
|
Copyright (c) Nicolas Plourde - 2005
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "vo_macosx.h"
|
2005-09-04 12:58:16 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/shm.h>
|
2005-04-29 11:05:16 +00:00
|
|
|
|
|
|
|
//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 "input/input.h"
|
|
|
|
#include "input/mouse.h"
|
|
|
|
|
|
|
|
#include "osdep/keycodes.h"
|
|
|
|
|
|
|
|
//Cocoa
|
2007-11-28 00:01:35 +00:00
|
|
|
NSDistantObject *mplayerosxProxy;
|
|
|
|
id <MPlayerOSXVOProto> mplayerosxProto;
|
2005-06-02 14:10:52 +00:00
|
|
|
MPlayerOpenGLView *mpGLView;
|
2005-04-29 11:05:16 +00:00
|
|
|
NSAutoreleasePool *autoreleasepool;
|
|
|
|
OSType pixelFormat;
|
|
|
|
|
2005-09-04 12:58:16 +00:00
|
|
|
//shared memory
|
|
|
|
int shm_id;
|
|
|
|
struct shmid_ds shm_desc;
|
|
|
|
BOOL shared_buffer = false;
|
|
|
|
|
2005-06-15 16:54:43 +00:00
|
|
|
//Screen
|
|
|
|
int screen_id;
|
|
|
|
BOOL screen_force;
|
|
|
|
NSRect screen_frame;
|
|
|
|
NSScreen *screen_handle;
|
|
|
|
NSArray *screen_array;
|
2005-04-29 11:05:16 +00:00
|
|
|
|
|
|
|
//image
|
|
|
|
unsigned char *image_data;
|
2007-11-30 04:20:38 +00:00
|
|
|
// For double buffering
|
|
|
|
static uint8_t image_page = 0;
|
|
|
|
static unsigned char *image_datas[2];
|
|
|
|
|
2005-04-29 11:05:16 +00:00
|
|
|
static uint32_t image_width;
|
|
|
|
static uint32_t image_height;
|
|
|
|
static uint32_t image_depth;
|
|
|
|
static uint32_t image_bytes;
|
|
|
|
static uint32_t image_format;
|
|
|
|
|
|
|
|
//vo
|
|
|
|
static int isFullscreen;
|
2005-05-02 01:48:37 +00:00
|
|
|
static int isOntop;
|
2005-05-02 18:05:59 +00:00
|
|
|
static int isRootwin;
|
2005-04-29 11:05:16 +00:00
|
|
|
extern float monitor_aspect;
|
|
|
|
extern float movie_aspect;
|
|
|
|
static float old_movie_aspect;
|
2007-12-20 12:00:44 +00:00
|
|
|
extern int enable_mouse_movements;
|
2005-04-29 11:05:16 +00:00
|
|
|
|
2005-06-16 00:26:47 +00:00
|
|
|
static float winAlpha = 1;
|
2005-04-29 11:05:16 +00:00
|
|
|
static int int_pause = 0;
|
|
|
|
|
2007-11-30 00:03:01 +00:00
|
|
|
static BOOL isLeopardOrLater;
|
|
|
|
|
2005-04-29 11:05:16 +00:00
|
|
|
static vo_info_t info =
|
|
|
|
{
|
|
|
|
"Mac OSX Core Video",
|
|
|
|
"macosx",
|
|
|
|
"Nicolas Plourde <nicolas.plourde@gmail.com>",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
LIBVO_EXTERN(macosx)
|
|
|
|
|
|
|
|
extern void mplayer_put_key(int code);
|
|
|
|
extern void vo_draw_text(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride));
|
|
|
|
|
|
|
|
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*image_width+x0),4*image_width);
|
|
|
|
break;
|
|
|
|
case IMGFMT_YUY2:
|
|
|
|
vo_draw_alpha_yuy2(w,h,src,srca,stride,image_data + (x0 + y0 * image_width) * 2,image_width*2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
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)
|
2005-04-29 11:05:16 +00:00
|
|
|
{
|
2005-09-04 12:58:16 +00:00
|
|
|
|
2005-06-15 16:54:43 +00:00
|
|
|
//init screen
|
|
|
|
screen_array = [NSScreen screens];
|
|
|
|
if(screen_id < [screen_array count])
|
2005-04-29 11:05:16 +00:00
|
|
|
{
|
2005-06-15 16:54:43 +00:00
|
|
|
screen_handle = [screen_array objectAtIndex:screen_id];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_VO, MSGL_FATAL, "Get device error: Device ID %d do not exist, falling back to main device.\n", screen_id);
|
|
|
|
screen_handle = [screen_array objectAtIndex:0];
|
|
|
|
screen_id = 0;
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
2005-06-15 16:54:43 +00:00
|
|
|
screen_frame = [screen_handle frame];
|
2007-12-17 15:49:54 +00:00
|
|
|
vo_screenwidth = screen_frame.size.width;
|
|
|
|
vo_screenheight = screen_frame.size.height;
|
2005-09-04 12:58:16 +00:00
|
|
|
|
2005-04-29 11:05:16 +00:00
|
|
|
//misc mplayer setup
|
|
|
|
image_width = width;
|
|
|
|
image_height = height;
|
|
|
|
switch (image_format)
|
|
|
|
{
|
|
|
|
case IMGFMT_BGR32:
|
|
|
|
case IMGFMT_RGB32:
|
|
|
|
image_depth = 32;
|
|
|
|
break;
|
2005-09-04 12:58:16 +00:00
|
|
|
case IMGFMT_YUY2:
|
2005-04-29 11:05:16 +00:00
|
|
|
image_depth = 16;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
image_bytes = (image_depth + 7) / 8;
|
2005-06-15 14:48:33 +00:00
|
|
|
|
2005-09-04 12:58:16 +00:00
|
|
|
if(!shared_buffer)
|
|
|
|
{
|
2007-11-23 13:22:21 +00:00
|
|
|
image_data = malloc(image_width*image_height*image_bytes);
|
2007-11-30 04:20:38 +00:00
|
|
|
image_datas[0] = image_data;
|
|
|
|
if (vo_doublebuffering)
|
|
|
|
image_datas[1] = malloc(image_width*image_height*image_bytes);
|
|
|
|
image_page = 0;
|
2007-11-23 13:22:21 +00:00
|
|
|
|
2005-09-04 12:58:16 +00:00
|
|
|
monitor_aspect = (float)screen_frame.size.width/(float)screen_frame.size.height;
|
|
|
|
|
|
|
|
//set aspect
|
|
|
|
panscan_init();
|
|
|
|
aspect_save_orig(width,height);
|
|
|
|
aspect_save_prescale(d_width,d_height);
|
|
|
|
aspect_save_screenres(screen_frame.size.width, screen_frame.size.height);
|
|
|
|
aspect((int *)&d_width,(int *)&d_height,A_NOZOOM);
|
|
|
|
|
|
|
|
movie_aspect = (float)d_width/(float)d_height;
|
|
|
|
old_movie_aspect = movie_aspect;
|
|
|
|
|
|
|
|
vo_fs = flags & VOFLAG_FULLSCREEN;
|
|
|
|
|
|
|
|
//config OpenGL View
|
|
|
|
[mpGLView config];
|
|
|
|
[mpGLView reshape];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
movie_aspect = (float)d_width/(float)d_height;
|
|
|
|
|
|
|
|
shm_id = shmget(9849, image_width*image_height*image_bytes, IPC_CREAT | 0666);
|
|
|
|
if (shm_id == -1)
|
|
|
|
{
|
|
|
|
perror("vo_mplayer shmget: ");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
image_data = shmat(shm_id, NULL, 0);
|
|
|
|
if (!image_data)
|
|
|
|
{
|
|
|
|
perror("vo_mplayer shmat: ");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//connnect to mplayerosx
|
|
|
|
mplayerosxProxy=[NSConnection rootProxyForConnectionWithRegisteredName:@"mplayerosx" host:nil];
|
2007-11-28 00:01:35 +00:00
|
|
|
if ([mplayerosxProxy conformsToProtocol:@protocol(MPlayerOSXVOProto)]) {
|
|
|
|
[mplayerosxProxy setProtocolForProxy:@protocol(MPlayerOSXVOProto)];
|
|
|
|
mplayerosxProto = (id <MPlayerOSXVOProto>)mplayerosxProxy;
|
|
|
|
[mplayerosxProto startWithWidth: image_width withHeight: image_height withBytes: image_bytes withAspect:(int)(movie_aspect*100)];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
[mplayerosxProxy release];
|
|
|
|
mplayerosxProxy = nil;
|
|
|
|
mplayerosxProto = nil;
|
|
|
|
}
|
2005-09-04 12:58:16 +00:00
|
|
|
}
|
2005-04-29 11:05:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_events(void)
|
|
|
|
{
|
2005-06-02 14:10:52 +00:00
|
|
|
[mpGLView check_events];
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_osd(void)
|
|
|
|
{
|
|
|
|
vo_draw_text(image_width, image_height, draw_alpha);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void flip_page(void)
|
|
|
|
{
|
2005-09-04 12:58:16 +00:00
|
|
|
if(shared_buffer)
|
2007-11-28 00:01:35 +00:00
|
|
|
[mplayerosxProto render];
|
2007-11-23 04:49:10 +00:00
|
|
|
else {
|
|
|
|
[mpGLView setCurrentTexture];
|
2005-09-04 12:58:16 +00:00
|
|
|
[mpGLView render];
|
2007-11-30 04:20:38 +00:00
|
|
|
if (vo_doublebuffering) {
|
|
|
|
image_page = 1 - image_page;
|
|
|
|
image_data = image_datas[image_page];
|
|
|
|
}
|
2007-11-23 04:49:10 +00:00
|
|
|
}
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
|
2005-04-29 11:05:16 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int draw_frame(uint8_t *src[])
|
2005-04-29 11:05:16 +00:00
|
|
|
{
|
|
|
|
switch (image_format)
|
|
|
|
{
|
|
|
|
case IMGFMT_BGR32:
|
|
|
|
case IMGFMT_RGB32:
|
2007-06-05 14:27:54 +00:00
|
|
|
fast_memcpy(image_data, src[0], image_width*image_height*image_bytes);
|
2005-04-29 11:05:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IMGFMT_YUY2:
|
|
|
|
memcpy_pic(image_data, src[0], image_width * 2, image_height, image_width * 2, image_width * 2);
|
|
|
|
break;
|
|
|
|
}
|
2005-09-04 12:58:16 +00:00
|
|
|
|
2005-04-29 11:05:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int query_format(uint32_t format)
|
2005-04-29 11:05:16 +00:00
|
|
|
{
|
|
|
|
image_format = format;
|
|
|
|
|
|
|
|
switch(format)
|
|
|
|
{
|
|
|
|
case IMGFMT_YUY2:
|
|
|
|
pixelFormat = kYUVSPixelFormat;
|
|
|
|
return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN;
|
|
|
|
|
|
|
|
case IMGFMT_RGB32:
|
|
|
|
case IMGFMT_BGR32:
|
|
|
|
pixelFormat = k32ARGBPixelFormat;
|
|
|
|
return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uninit(void)
|
|
|
|
{
|
2005-09-04 12:58:16 +00:00
|
|
|
if(shared_buffer)
|
|
|
|
{
|
2007-11-28 00:01:35 +00:00
|
|
|
[mplayerosxProto stop];
|
|
|
|
mplayerosxProto = nil;
|
|
|
|
[mplayerosxProxy release];
|
|
|
|
mplayerosxProxy = nil;
|
2005-09-04 12:58:16 +00:00
|
|
|
|
|
|
|
if (shmdt(image_data) == -1)
|
|
|
|
mp_msg(MSGT_VO, MSGL_FATAL, "uninit: shmdt failed\n");
|
|
|
|
|
|
|
|
if (shmctl(shm_id, IPC_RMID, &shm_desc) == -1)
|
|
|
|
mp_msg(MSGT_VO, MSGL_FATAL, "uninit: shmctl failed\n");
|
|
|
|
}
|
|
|
|
|
2006-12-10 01:38:54 +00:00
|
|
|
SetSystemUIMode( kUIModeNormal, 0);
|
|
|
|
CGDisplayShowCursor(kCGDirectMainDisplay);
|
|
|
|
|
|
|
|
if(mpGLView)
|
|
|
|
{
|
2007-11-26 02:57:02 +00:00
|
|
|
NSAutoreleasePool *finalPool;
|
2007-10-13 12:17:37 +00:00
|
|
|
mpGLView = nil;
|
2006-12-10 01:38:54 +00:00
|
|
|
[autoreleasepool release];
|
2007-11-26 02:57:02 +00:00
|
|
|
finalPool = [[NSAutoreleasePool alloc] init];
|
2007-11-19 12:01:30 +00:00
|
|
|
[NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES];
|
|
|
|
[finalPool release];
|
2006-12-10 01:38:54 +00:00
|
|
|
}
|
2007-11-23 13:46:38 +00:00
|
|
|
if (!shared_buffer)
|
|
|
|
{
|
2007-11-30 04:20:38 +00:00
|
|
|
free(image_datas[0]);
|
|
|
|
if (vo_doublebuffering)
|
|
|
|
free(image_datas[1]);
|
|
|
|
image_datas[0] = NULL;
|
|
|
|
image_datas[1] = NULL;
|
2007-11-23 13:46:38 +00:00
|
|
|
image_data = NULL;
|
|
|
|
}
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int preinit(const char *arg)
|
2005-04-29 11:05:16 +00:00
|
|
|
{
|
|
|
|
int parse_err = 0;
|
|
|
|
|
2005-06-15 16:54:43 +00:00
|
|
|
if(arg)
|
|
|
|
{
|
|
|
|
char *parse_pos = (char *)&arg[0];
|
|
|
|
while (parse_pos[0] && !parse_err)
|
|
|
|
{
|
|
|
|
if (strncmp (parse_pos, "device_id=", 10) == 0)
|
|
|
|
{
|
|
|
|
parse_pos = &parse_pos[10];
|
|
|
|
screen_id = strtol(parse_pos, &parse_pos, 0);
|
|
|
|
screen_force = YES;
|
2005-09-04 12:58:16 +00:00
|
|
|
}
|
|
|
|
if (strncmp (parse_pos, "shared_buffer", 13) == 0)
|
|
|
|
{
|
|
|
|
parse_pos = &parse_pos[13];
|
|
|
|
shared_buffer = YES;
|
2005-06-15 16:54:43 +00:00
|
|
|
}
|
|
|
|
if (parse_pos[0] == ':') parse_pos = &parse_pos[1];
|
|
|
|
else if (parse_pos[0]) parse_err = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-16 16:41:44 +00:00
|
|
|
NSApplicationLoad();
|
2005-04-29 11:05:16 +00:00
|
|
|
autoreleasepool = [[NSAutoreleasePool alloc] init];
|
2005-06-16 16:41:44 +00:00
|
|
|
NSApp = [NSApplication sharedApplication];
|
2007-11-30 00:03:01 +00:00
|
|
|
isLeopardOrLater = floor(NSAppKitVersionNumber) > 824;
|
2005-06-15 14:48:33 +00:00
|
|
|
|
2005-09-04 12:58:16 +00:00
|
|
|
if(!shared_buffer)
|
2005-07-28 22:19:34 +00:00
|
|
|
{
|
2006-01-11 02:45:17 +00:00
|
|
|
#if !defined (MACOSX_FINDER_SUPPORT) || !defined (HAVE_SDL)
|
|
|
|
//this chunk of code is heavily based off SDL_macosx.m from SDL
|
|
|
|
//it uses an Apple private function to request foreground operation
|
|
|
|
void CPSEnableForegroundOperation(ProcessSerialNumber* psn);
|
|
|
|
ProcessSerialNumber myProc, frProc;
|
|
|
|
Boolean sameProc;
|
|
|
|
|
|
|
|
if (GetFrontProcess(&frProc) == noErr)
|
|
|
|
{
|
|
|
|
if (GetCurrentProcess(&myProc) == noErr)
|
|
|
|
{
|
|
|
|
if (SameProcess(&frProc, &myProc, &sameProc) == noErr && !sameProc)
|
|
|
|
{
|
|
|
|
CPSEnableForegroundOperation(&myProc);
|
|
|
|
}
|
|
|
|
SetFrontProcess(&myProc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-09-04 12:58:16 +00:00
|
|
|
if(!mpGLView)
|
|
|
|
{
|
|
|
|
mpGLView = [[MPlayerOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) pixelFormat:[MPlayerOpenGLView defaultPixelFormat]];
|
|
|
|
[mpGLView autorelease];
|
|
|
|
}
|
2005-07-28 22:19:34 +00:00
|
|
|
|
2005-09-04 12:58:16 +00:00
|
|
|
[mpGLView display];
|
|
|
|
[mpGLView preinit];
|
|
|
|
}
|
2005-06-15 14:48:33 +00:00
|
|
|
|
2005-04-29 11:05:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int control(uint32_t request, void *data, ...)
|
2005-04-29 11:05:16 +00:00
|
|
|
{
|
|
|
|
switch (request)
|
|
|
|
{
|
2008-05-16 08:33:27 +00:00
|
|
|
case VOCTRL_PAUSE: return int_pause = 1;
|
|
|
|
case VOCTRL_RESUME: return int_pause = 0;
|
2005-04-29 11:05:16 +00:00
|
|
|
case VOCTRL_QUERY_FORMAT: return query_format(*((uint32_t*)data));
|
2007-11-28 00:01:35 +00:00
|
|
|
case VOCTRL_ONTOP: vo_ontop = (!(vo_ontop)); if(!shared_buffer){ [mpGLView ontop]; } else { [mplayerosxProto ontop]; } return VO_TRUE;
|
2005-06-02 14:10:52 +00:00
|
|
|
case VOCTRL_ROOTWIN: vo_rootwin = (!(vo_rootwin)); [mpGLView rootwin]; return VO_TRUE;
|
2007-11-28 00:01:35 +00:00
|
|
|
case VOCTRL_FULLSCREEN: vo_fs = (!(vo_fs)); if(!shared_buffer){ [mpGLView fullscreen: NO]; } else { [mplayerosxProto toggleFullscreen]; } return VO_TRUE;
|
2005-04-29 11:05:16 +00:00
|
|
|
case VOCTRL_GET_PANSCAN: return VO_TRUE;
|
2005-06-02 14:10:52 +00:00
|
|
|
case VOCTRL_SET_PANSCAN: [mpGLView panscan]; return VO_TRUE;
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
|
|
|
return VO_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// NSOpenGLView Subclass
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2005-06-02 14:10:52 +00:00
|
|
|
@implementation MPlayerOpenGLView
|
2007-08-18 10:30:15 +00:00
|
|
|
- (void) preinit
|
2005-04-29 11:05:16 +00:00
|
|
|
{
|
2005-05-25 23:38:59 +00:00
|
|
|
//init menu
|
|
|
|
[self initMenu];
|
|
|
|
|
2005-04-29 11:05:16 +00:00
|
|
|
//create window
|
2005-06-17 16:45:24 +00:00
|
|
|
window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
|
2005-04-29 11:05:16 +00:00
|
|
|
styleMask:NSTitledWindowMask|NSTexturedBackgroundWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask
|
2005-06-05 14:57:36 +00:00
|
|
|
backing:NSBackingStoreBuffered defer:NO];
|
2005-04-29 11:05:16 +00:00
|
|
|
|
2005-07-28 22:19:34 +00:00
|
|
|
[window autorelease];
|
2005-06-15 14:48:33 +00:00
|
|
|
[window setDelegate:mpGLView];
|
|
|
|
[window setContentView:mpGLView];
|
|
|
|
[window setInitialFirstResponder:mpGLView];
|
2005-04-29 11:05:16 +00:00
|
|
|
[window setAcceptsMouseMovedEvents:YES];
|
|
|
|
[window setTitle:@"MPlayer - The Movie Player"];
|
2005-06-15 14:48:33 +00:00
|
|
|
|
|
|
|
isFullscreen = 0;
|
2005-06-29 21:54:48 +00:00
|
|
|
winSizeMult = 1;
|
2005-06-15 14:48:33 +00:00
|
|
|
}
|
|
|
|
|
2007-08-18 10:30:15 +00:00
|
|
|
- (void) config
|
2005-06-15 14:48:33 +00:00
|
|
|
{
|
|
|
|
uint32_t d_width;
|
|
|
|
uint32_t d_height;
|
|
|
|
|
2007-11-26 03:06:16 +00:00
|
|
|
GLint swapInterval = 1;
|
2005-06-15 14:48:33 +00:00
|
|
|
|
|
|
|
NSRect frame;
|
|
|
|
CVReturn error = kCVReturnSuccess;
|
|
|
|
|
2005-06-15 16:54:43 +00:00
|
|
|
//config window
|
2005-06-15 14:48:33 +00:00
|
|
|
aspect((int *)&d_width, (int *)&d_height,A_NOZOOM);
|
|
|
|
frame = NSMakeRect(0, 0, d_width, d_height);
|
|
|
|
[window setContentSize: frame.size];
|
|
|
|
|
|
|
|
//create OpenGL Context
|
|
|
|
glContext = [[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:nil];
|
2005-06-05 14:57:36 +00:00
|
|
|
|
2005-04-29 11:05:16 +00:00
|
|
|
[self setOpenGLContext:glContext];
|
2005-06-05 14:57:36 +00:00
|
|
|
[glContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
|
2005-04-29 11:05:16 +00:00
|
|
|
[glContext setView:self];
|
|
|
|
[glContext makeCurrentContext];
|
|
|
|
|
2007-11-30 04:20:38 +00:00
|
|
|
error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[0], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[0]);
|
2005-04-29 11:05:16 +00:00
|
|
|
if(error != kCVReturnSuccess)
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR,"Failed to create Pixel Buffer(%d)\n", error);
|
2007-11-30 04:20:38 +00:00
|
|
|
if (vo_doublebuffering) {
|
|
|
|
error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[1], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[1]);
|
|
|
|
if(error != kCVReturnSuccess)
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR,"Failed to create Pixel Double Buffer(%d)\n", error);
|
|
|
|
}
|
2005-04-29 11:05:16 +00:00
|
|
|
|
|
|
|
error = CVOpenGLTextureCacheCreate(NULL, 0, [glContext CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache);
|
|
|
|
if(error != kCVReturnSuccess)
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture Cache(%d)\n", error);
|
|
|
|
|
2007-11-30 04:20:38 +00:00
|
|
|
error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture);
|
2005-04-29 11:05:16 +00:00
|
|
|
if(error != kCVReturnSuccess)
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture(%d)\n", error);
|
|
|
|
|
2005-06-15 16:54:43 +00:00
|
|
|
//show window
|
|
|
|
[window center];
|
|
|
|
[window makeKeyAndOrderFront:mpGLView];
|
|
|
|
|
2005-06-15 14:48:33 +00:00
|
|
|
if(vo_rootwin)
|
|
|
|
[mpGLView rootwin];
|
|
|
|
|
|
|
|
if(vo_fs)
|
|
|
|
[mpGLView fullscreen: NO];
|
2005-06-05 20:21:34 +00:00
|
|
|
|
2005-06-15 14:48:33 +00:00
|
|
|
if(vo_ontop)
|
|
|
|
[mpGLView ontop];
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
|
|
|
|
2005-05-25 23:38:59 +00:00
|
|
|
/*
|
|
|
|
Init Menu
|
|
|
|
*/
|
|
|
|
- (void)initMenu
|
|
|
|
{
|
2006-12-01 14:58:11 +00:00
|
|
|
NSMenu *menu, *aspectMenu;
|
2005-05-25 23:38:59 +00:00
|
|
|
NSMenuItem *menuItem;
|
|
|
|
|
|
|
|
[NSApp setMainMenu:[[NSMenu alloc] init]];
|
|
|
|
|
|
|
|
//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;
|
2005-07-03 14:28:51 +00:00
|
|
|
menuItem = (NSMenuItem *)[NSMenuItem separatorItem]; [menu addItem:menuItem];
|
2005-05-25 23:38:59 +00:00
|
|
|
|
|
|
|
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;
|
2005-07-03 14:28:51 +00:00
|
|
|
menuItem = (NSMenuItem *)[NSMenuItem separatorItem]; [aspectMenu addItem:menuItem];
|
2005-05-25 23:38:59 +00:00
|
|
|
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];
|
|
|
|
[[NSApp 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];
|
|
|
|
[[NSApp mainMenu] addItem:menuItem];
|
|
|
|
[NSApp setWindowsMenu:menu];
|
|
|
|
|
|
|
|
[menu release];
|
|
|
|
[menuItem release];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Menu Action
|
|
|
|
*/
|
|
|
|
- (void)menuAction:(id)sender
|
|
|
|
{
|
|
|
|
uint32_t d_width;
|
|
|
|
uint32_t d_height;
|
|
|
|
NSRect frame;
|
|
|
|
|
|
|
|
aspect((int *)&d_width, (int *)&d_height,A_NOZOOM);
|
2005-06-16 00:26:47 +00:00
|
|
|
|
|
|
|
if(sender == kQuitCmd)
|
|
|
|
{
|
|
|
|
mplayer_put_key(KEY_ESC);
|
|
|
|
}
|
2005-05-25 23:38:59 +00:00
|
|
|
|
|
|
|
if(sender == kHalfScreenCmd)
|
|
|
|
{
|
|
|
|
if(isFullscreen) {
|
2006-12-09 23:57:28 +00:00
|
|
|
vo_fs = (!(vo_fs)); [self fullscreen:NO];
|
2005-05-25 23:38:59 +00:00
|
|
|
}
|
|
|
|
|
2005-06-29 21:54:48 +00:00
|
|
|
winSizeMult = 0.5;
|
|
|
|
frame.size.width = (d_width*winSizeMult);
|
|
|
|
frame.size.height = ((d_width/movie_aspect)*winSizeMult);
|
2005-05-25 23:38:59 +00:00
|
|
|
[window setContentSize: frame.size];
|
|
|
|
[self reshape];
|
|
|
|
}
|
|
|
|
if(sender == kNormalScreenCmd)
|
|
|
|
{
|
|
|
|
if(isFullscreen) {
|
2006-12-09 23:57:28 +00:00
|
|
|
vo_fs = (!(vo_fs)); [self fullscreen:NO];
|
2005-05-25 23:38:59 +00:00
|
|
|
}
|
|
|
|
|
2005-06-29 21:54:48 +00:00
|
|
|
winSizeMult = 1;
|
2005-05-25 23:38:59 +00:00
|
|
|
frame.size.width = d_width;
|
|
|
|
frame.size.height = d_width/movie_aspect;
|
|
|
|
[window setContentSize: frame.size];
|
|
|
|
[self reshape];
|
|
|
|
}
|
|
|
|
if(sender == kDoubleScreenCmd)
|
|
|
|
{
|
|
|
|
if(isFullscreen) {
|
2006-12-09 23:57:28 +00:00
|
|
|
vo_fs = (!(vo_fs)); [self fullscreen:NO];
|
2005-05-25 23:38:59 +00:00
|
|
|
}
|
|
|
|
|
2005-06-29 21:54:48 +00:00
|
|
|
winSizeMult = 2;
|
|
|
|
frame.size.width = d_width*winSizeMult;
|
|
|
|
frame.size.height = (d_width/movie_aspect)*winSizeMult;
|
2005-05-25 23:38:59 +00:00
|
|
|
[window setContentSize: frame.size];
|
|
|
|
[self reshape];
|
|
|
|
}
|
|
|
|
if(sender == kFullScreenCmd)
|
|
|
|
{
|
|
|
|
vo_fs = (!(vo_fs));
|
2006-12-09 23:57:28 +00:00
|
|
|
[self fullscreen:NO];
|
2005-05-25 23:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(sender == kKeepAspectCmd)
|
|
|
|
{
|
|
|
|
vo_keepaspect = (!(vo_keepaspect));
|
|
|
|
if(vo_keepaspect)
|
|
|
|
[kKeepAspectCmd setState:NSOnState];
|
|
|
|
else
|
|
|
|
[kKeepAspectCmd setState:NSOffState];
|
2005-07-03 14:28:51 +00:00
|
|
|
|
|
|
|
[self reshape];
|
2005-05-25 23:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(sender == kPanScanCmd)
|
|
|
|
{
|
|
|
|
vo_panscan = (!(vo_panscan));
|
|
|
|
if(vo_panscan)
|
|
|
|
[kPanScanCmd setState:NSOnState];
|
|
|
|
else
|
|
|
|
[kPanScanCmd setState:NSOffState];
|
2005-07-03 12:24:48 +00:00
|
|
|
|
|
|
|
[self panscan];
|
2005-05-25 23:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(sender == kAspectOrgCmd)
|
|
|
|
{
|
|
|
|
movie_aspect = old_movie_aspect;
|
2005-07-03 12:24:48 +00:00
|
|
|
|
|
|
|
if(isFullscreen)
|
|
|
|
{
|
|
|
|
[self reshape];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
frame.size.width = d_width*winSizeMult;
|
|
|
|
frame.size.height = (d_width/movie_aspect)*winSizeMult;
|
|
|
|
[window setContentSize: frame.size];
|
|
|
|
[self reshape];
|
|
|
|
}
|
2005-05-25 23:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(sender == kAspectFullCmd)
|
|
|
|
{
|
|
|
|
movie_aspect = 4.0f/3.0f;
|
2005-07-01 17:24:31 +00:00
|
|
|
|
|
|
|
if(isFullscreen)
|
|
|
|
{
|
|
|
|
[self reshape];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
frame.size.width = d_width*winSizeMult;
|
|
|
|
frame.size.height = (d_width/movie_aspect)*winSizeMult;
|
|
|
|
[window setContentSize: frame.size];
|
|
|
|
[self reshape];
|
|
|
|
}
|
2005-05-25 23:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(sender == kAspectWideCmd)
|
|
|
|
{
|
|
|
|
movie_aspect = 16.0f/9.0f;
|
2005-07-01 17:24:31 +00:00
|
|
|
|
|
|
|
if(isFullscreen)
|
|
|
|
{
|
|
|
|
[self reshape];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
frame.size.width = d_width*winSizeMult;
|
|
|
|
frame.size.height = (d_width/movie_aspect)*winSizeMult;
|
|
|
|
[window setContentSize: frame.size];
|
|
|
|
[self reshape];
|
|
|
|
}
|
2005-05-25 23:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-29 11:05:16 +00:00
|
|
|
/*
|
|
|
|
Setup OpenGL
|
|
|
|
*/
|
|
|
|
- (void)prepareOpenGL
|
|
|
|
{
|
2005-05-04 12:00:54 +00:00
|
|
|
glEnable(GL_BLEND);
|
2005-04-29 11:05:16 +00:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
[self reshape];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
reshape OpenGL viewport
|
|
|
|
*/
|
|
|
|
- (void)reshape
|
|
|
|
{
|
|
|
|
uint32_t d_width;
|
|
|
|
uint32_t d_height;
|
|
|
|
float aspectX;
|
|
|
|
float aspectY;
|
|
|
|
int padding = 0;
|
|
|
|
|
|
|
|
NSRect frame = [self frame];
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2005-06-15 21:49:50 +00:00
|
|
|
//set texture frame
|
2005-04-29 11:05:16 +00:00
|
|
|
if(vo_keepaspect)
|
|
|
|
{
|
2005-05-25 23:44:55 +00:00
|
|
|
aspect( (int *)&d_width, (int *)&d_height, A_NOZOOM);
|
2005-04-29 11:05:16 +00:00
|
|
|
d_height = ((float)d_width/movie_aspect);
|
|
|
|
|
|
|
|
aspectX = (float)((float)frame.size.width/(float)d_width);
|
|
|
|
aspectY = (float)((float)(frame.size.height)/(float)d_height);
|
|
|
|
|
|
|
|
if((d_height*aspectX)>(frame.size.height))
|
|
|
|
{
|
|
|
|
padding = (frame.size.width - d_width*aspectY)/2;
|
2007-12-18 16:37:36 +00:00
|
|
|
textureFrame = NSMakeRect(padding, 0, d_width*aspectY, d_height*aspectY);
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
padding = ((frame.size.height) - d_height*aspectX)/2;
|
2007-12-18 16:37:36 +00:00
|
|
|
textureFrame = NSMakeRect(0, padding, d_width*aspectX, d_height*aspectX);
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-15 21:49:50 +00:00
|
|
|
textureFrame = frame;
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
2007-12-20 12:00:44 +00:00
|
|
|
vo_dwidth = textureFrame.size.width;
|
|
|
|
vo_dheight = textureFrame.size.height;
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Render frame
|
|
|
|
*/
|
|
|
|
- (void) render
|
|
|
|
{
|
2006-12-01 14:58:11 +00:00
|
|
|
int curTime;
|
2007-11-06 12:40:04 +00:00
|
|
|
static int lastTime = 0;
|
2006-12-01 14:58:11 +00:00
|
|
|
|
2005-04-29 11:05:16 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
glEnable(CVOpenGLTextureGetTarget(texture));
|
|
|
|
glBindTexture(CVOpenGLTextureGetTarget(texture), CVOpenGLTextureGetName(texture));
|
|
|
|
|
|
|
|
glColor3f(1,1,1);
|
|
|
|
glBegin(GL_QUADS);
|
2005-06-15 21:49:50 +00:00
|
|
|
glTexCoord2f(upperLeft[0], upperLeft[1]); glVertex2i( textureFrame.origin.x-(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1));
|
2007-12-18 16:37:36 +00:00
|
|
|
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));
|
2005-04-29 11:05:16 +00:00
|
|
|
glEnd();
|
2005-05-04 12:00:54 +00:00
|
|
|
glDisable(CVOpenGLTextureGetTarget(texture));
|
|
|
|
|
|
|
|
//render resize box
|
|
|
|
if(!isFullscreen)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
2005-04-29 11:05:16 +00:00
|
|
|
|
|
|
|
glFlush();
|
|
|
|
|
|
|
|
//auto hide mouse cursor and futur on-screen control?
|
2005-05-02 18:05:59 +00:00
|
|
|
if(isFullscreen && !mouseHide && !isRootwin)
|
2005-04-29 11:05:16 +00:00
|
|
|
{
|
2006-04-08 16:16:48 +00:00
|
|
|
int curTime = TickCount()/60;
|
|
|
|
static int lastTime = 0;
|
2005-04-29 11:05:16 +00:00
|
|
|
|
|
|
|
if( ((curTime - lastTime) >= 5) || (lastTime == 0) )
|
|
|
|
{
|
2006-04-08 16:16:48 +00:00
|
|
|
CGDisplayHideCursor(kCGDirectMainDisplay);
|
2005-04-29 11:05:16 +00:00
|
|
|
mouseHide = YES;
|
|
|
|
lastTime = curTime;
|
|
|
|
}
|
|
|
|
}
|
2006-02-07 01:36:32 +00:00
|
|
|
|
2006-03-04 12:37:44 +00:00
|
|
|
//update activity every 30 seconds to prevent
|
2006-02-07 01:36:32 +00:00
|
|
|
//screensaver from starting up.
|
2006-12-01 14:58:11 +00:00
|
|
|
curTime = TickCount()/60;
|
2006-04-08 16:16:48 +00:00
|
|
|
|
|
|
|
if( ((curTime - lastTime) >= 30) || (lastTime == 0) )
|
2006-02-07 01:36:32 +00:00
|
|
|
{
|
|
|
|
UpdateSystemActivity(UsrActivity);
|
|
|
|
lastTime = curTime;
|
|
|
|
}
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Create OpenGL texture from current frame & set texco
|
|
|
|
*/
|
|
|
|
- (void) setCurrentTexture
|
|
|
|
{
|
|
|
|
CVReturn error = kCVReturnSuccess;
|
|
|
|
|
2007-11-30 04:20:38 +00:00
|
|
|
error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture);
|
2005-04-29 11:05:16 +00:00
|
|
|
if(error != kCVReturnSuccess)
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR,"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
|
|
|
|
{
|
|
|
|
static NSRect old_frame;
|
|
|
|
static NSRect old_view_frame;
|
2005-06-15 16:54:43 +00:00
|
|
|
|
2005-05-26 16:33:28 +00:00
|
|
|
panscan_calc();
|
|
|
|
|
2005-04-29 11:05:16 +00:00
|
|
|
//go fullscreen
|
|
|
|
if(vo_fs)
|
|
|
|
{
|
2005-05-02 18:05:59 +00:00
|
|
|
if(!isRootwin)
|
|
|
|
{
|
2005-07-01 17:24:31 +00:00
|
|
|
SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
|
2006-04-08 16:16:48 +00:00
|
|
|
CGDisplayHideCursor(kCGDirectMainDisplay);
|
2005-05-02 18:05:59 +00:00
|
|
|
mouseHide = YES;
|
|
|
|
}
|
2005-04-29 11:05:16 +00:00
|
|
|
|
|
|
|
old_frame = [window frame]; //save main window size & position
|
2007-12-17 15:45:37 +00:00
|
|
|
if(screen_force)
|
|
|
|
screen_frame = [screen_handle frame];
|
2007-12-17 15:49:54 +00:00
|
|
|
else {
|
2007-12-17 15:45:37 +00:00
|
|
|
screen_frame = [[window screen] frame];
|
2007-12-17 15:49:54 +00:00
|
|
|
vo_screenwidth = screen_frame.size.width;
|
|
|
|
vo_screenheight = screen_frame.size.height;
|
|
|
|
}
|
2007-12-17 15:45:37 +00:00
|
|
|
|
2005-06-15 16:54:43 +00:00
|
|
|
[window setFrame:screen_frame display:YES animate:animate]; //zoom-in window with nice useless sfx
|
2005-04-29 11:05:16 +00:00
|
|
|
old_view_frame = [self bounds];
|
|
|
|
|
|
|
|
//fix origin for multi screen setup
|
2005-06-15 16:54:43 +00:00
|
|
|
screen_frame.origin.x = 0;
|
|
|
|
screen_frame.origin.y = 0;
|
|
|
|
[self setFrame:screen_frame];
|
2005-04-29 11:05:16 +00:00
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
[window setHasShadow:NO];
|
|
|
|
isFullscreen = 1;
|
|
|
|
}
|
|
|
|
else
|
2005-07-01 17:24:31 +00:00
|
|
|
{
|
2005-07-03 12:24:48 +00:00
|
|
|
SetSystemUIMode( kUIModeNormal, 0);
|
2005-07-01 17:24:31 +00:00
|
|
|
|
2005-04-29 11:05:16 +00:00
|
|
|
isFullscreen = 0;
|
2006-04-08 16:16:48 +00:00
|
|
|
CGDisplayShowCursor(kCGDirectMainDisplay);
|
2005-04-29 11:05:16 +00:00
|
|
|
mouseHide = NO;
|
|
|
|
|
|
|
|
//revert window to previous setting
|
|
|
|
[self setFrame:old_view_frame];
|
|
|
|
[self setNeedsDisplay:YES];
|
2005-07-24 15:16:27 +00:00
|
|
|
[window setHasShadow:YES];
|
2005-04-29 11:05:16 +00:00
|
|
|
[window setFrame:old_frame display:YES animate:animate];//zoom-out window with nice useless sfx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Toggle ontop
|
|
|
|
*/
|
|
|
|
- (void) ontop
|
|
|
|
{
|
2005-05-02 01:48:37 +00:00
|
|
|
if(vo_ontop)
|
|
|
|
{
|
|
|
|
[window setLevel:NSScreenSaverWindowLevel];
|
|
|
|
isOntop = YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[window setLevel:NSNormalWindowLevel];
|
|
|
|
isOntop = NO;
|
|
|
|
}
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Toggle panscan
|
|
|
|
*/
|
|
|
|
- (void) panscan
|
|
|
|
{
|
2005-05-02 21:17:27 +00:00
|
|
|
panscan_calc();
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
|
|
|
|
2005-05-02 18:05:59 +00:00
|
|
|
/*
|
|
|
|
Toggle rootwin
|
|
|
|
*/
|
|
|
|
- (void) rootwin
|
|
|
|
{
|
|
|
|
if(vo_rootwin)
|
|
|
|
{
|
|
|
|
[window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey)];
|
|
|
|
[window orderBack:self];
|
|
|
|
isRootwin = YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[window setLevel:NSNormalWindowLevel];
|
|
|
|
isRootwin = NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-29 11:05:16 +00:00
|
|
|
/*
|
|
|
|
Check event for new event
|
|
|
|
*/
|
|
|
|
- (void) check_events
|
|
|
|
{
|
|
|
|
event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:0.0001] inMode:NSEventTrackingRunLoopMode dequeue:YES];
|
2007-11-29 23:32:08 +00:00
|
|
|
if (event == nil)
|
|
|
|
return;
|
2005-04-29 11:05:16 +00:00
|
|
|
[NSApp sendEvent:event];
|
2007-11-30 00:03:01 +00:00
|
|
|
// Without SDL's bootstrap code (include SDL.h in mplayer.c),
|
|
|
|
// on Leopard, we got trouble to get the play window auto focused
|
|
|
|
// when app is actived. Following code fix this problem.
|
|
|
|
#ifndef HAVE_SDL
|
|
|
|
if (isLeopardOrLater && [event type] == NSAppKitDefined
|
|
|
|
&& [event subtype] == NSApplicationActivatedEventType) {
|
|
|
|
[window makeMainWindow];
|
|
|
|
[window makeKeyAndOrderFront:mpGLView];
|
|
|
|
}
|
|
|
|
#endif
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
|
|
|
|
2005-06-16 00:26:47 +00:00
|
|
|
/*
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-04-29 11:05:16 +00:00
|
|
|
/*
|
|
|
|
Process key event
|
|
|
|
*/
|
|
|
|
- (void) keyDown: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
unsigned int key;
|
|
|
|
|
|
|
|
switch([theEvent keyCode])
|
|
|
|
{
|
|
|
|
case 0x34:
|
|
|
|
case 0x24: key = KEY_ENTER; break;
|
|
|
|
case 0x35: key = KEY_ESC; break;
|
|
|
|
case 0x33: key = KEY_BACKSPACE; break;
|
|
|
|
case 0x3A: key = KEY_BACKSPACE; break;
|
|
|
|
case 0x3B: key = KEY_BACKSPACE; break;
|
|
|
|
case 0x38: key = KEY_BACKSPACE; break;
|
|
|
|
case 0x7A: key = KEY_F+1; break;
|
|
|
|
case 0x78: key = KEY_F+2; break;
|
|
|
|
case 0x63: key = KEY_F+3; break;
|
|
|
|
case 0x76: key = KEY_F+4; break;
|
|
|
|
case 0x60: key = KEY_F+5; break;
|
|
|
|
case 0x61: key = KEY_F+6; break;
|
|
|
|
case 0x62: key = KEY_F+7; break;
|
|
|
|
case 0x64: key = KEY_F+8; break;
|
|
|
|
case 0x65: key = KEY_F+9; break;
|
|
|
|
case 0x6D: key = KEY_F+10; break;
|
|
|
|
case 0x67: key = KEY_F+11; break;
|
|
|
|
case 0x6F: key = KEY_F+12; break;
|
|
|
|
case 0x72: key = KEY_INSERT; break;
|
|
|
|
case 0x75: key = KEY_DELETE; break;
|
|
|
|
case 0x73: key = KEY_HOME; break;
|
|
|
|
case 0x77: key = KEY_END; break;
|
|
|
|
case 0x45: key = '+'; break;
|
|
|
|
case 0x4E: key = '-'; break;
|
|
|
|
case 0x30: key = KEY_TAB; break;
|
|
|
|
case 0x74: key = KEY_PAGE_UP; break;
|
|
|
|
case 0x79: key = KEY_PAGE_DOWN; break;
|
|
|
|
case 0x7B: key = KEY_LEFT; break;
|
|
|
|
case 0x7C: key = KEY_RIGHT; break;
|
|
|
|
case 0x7D: key = KEY_DOWN; break;
|
|
|
|
case 0x7E: key = KEY_UP; break;
|
|
|
|
case 0x43: key = '*'; break;
|
|
|
|
case 0x4B: key = '/'; break;
|
2007-08-23 17:45:54 +00:00
|
|
|
case 0x4C: key = KEY_KPENTER; break;
|
2005-04-29 11:05:16 +00:00
|
|
|
case 0x41: key = KEY_KPDEC; break;
|
|
|
|
case 0x52: key = KEY_KP0; break;
|
|
|
|
case 0x53: key = KEY_KP1; break;
|
|
|
|
case 0x54: key = KEY_KP2; break;
|
|
|
|
case 0x55: key = KEY_KP3; break;
|
|
|
|
case 0x56: key = KEY_KP4; break;
|
|
|
|
case 0x57: key = KEY_KP5; break;
|
|
|
|
case 0x58: key = KEY_KP6; break;
|
|
|
|
case 0x59: key = KEY_KP7; break;
|
|
|
|
case 0x5B: key = KEY_KP8; break;
|
|
|
|
case 0x5C: key = KEY_KP9; break;
|
|
|
|
default: key = *[[theEvent characters] UTF8String]; break;
|
|
|
|
}
|
|
|
|
mplayer_put_key(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Process mouse button event
|
|
|
|
*/
|
|
|
|
- (void) mouseMoved: (NSEvent *) theEvent
|
|
|
|
{
|
2005-05-02 18:05:59 +00:00
|
|
|
if(isFullscreen && !isRootwin)
|
2005-04-29 11:05:16 +00:00
|
|
|
{
|
2006-04-08 16:16:48 +00:00
|
|
|
CGDisplayShowCursor(kCGDirectMainDisplay);
|
2005-04-29 11:05:16 +00:00
|
|
|
mouseHide = NO;
|
|
|
|
}
|
2007-12-22 14:55:26 +00:00
|
|
|
if (enable_mouse_movements && !isRootwin) {
|
2007-12-20 12:00:44 +00:00
|
|
|
NSPoint p =[self convertPoint:[theEvent locationInWindow] fromView:nil];
|
|
|
|
if ([self mouse:p inRect:textureFrame]) {
|
|
|
|
char cmdstr[40];
|
|
|
|
snprintf(cmdstr, sizeof(cmdstr), "set_mouse_pos %i %i",
|
|
|
|
(int)(vo_fs ? p.x : (p.x - textureFrame.origin.x)),
|
|
|
|
(int)(vo_fs ? [self frame].size.height - p.y: (NSMaxY(textureFrame) - p.y)));
|
|
|
|
mp_input_queue_cmd(mp_input_parse_cmd(cmdstr));
|
|
|
|
}
|
|
|
|
}
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mouseDown: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
[self mouseEvent: theEvent];
|
|
|
|
}
|
|
|
|
|
2007-08-18 22:46:29 +00:00
|
|
|
- (void) mouseUp: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
[self mouseEvent: theEvent];
|
|
|
|
}
|
|
|
|
|
2005-04-29 11:05:16 +00:00
|
|
|
- (void) rightMouseDown: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
[self mouseEvent: theEvent];
|
|
|
|
}
|
|
|
|
|
2007-08-18 22:46:29 +00:00
|
|
|
- (void) rightMouseUp: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
[self mouseEvent: theEvent];
|
|
|
|
}
|
|
|
|
|
2005-04-29 11:05:16 +00:00
|
|
|
- (void) otherMouseDown: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
[self mouseEvent: theEvent];
|
|
|
|
}
|
|
|
|
|
2007-08-18 22:46:29 +00:00
|
|
|
- (void) otherMouseUp: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
[self mouseEvent: theEvent];
|
|
|
|
}
|
|
|
|
|
2005-04-29 11:05:16 +00:00
|
|
|
- (void) scrollWheel: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
if([theEvent deltaY] > 0)
|
|
|
|
mplayer_put_key(MOUSE_BTN3);
|
|
|
|
else
|
|
|
|
mplayer_put_key(MOUSE_BTN4);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mouseEvent: (NSEvent *) theEvent
|
|
|
|
{
|
2007-08-18 22:46:29 +00:00
|
|
|
if ( [theEvent buttonNumber] >= 0 && [theEvent buttonNumber] <= 9 )
|
|
|
|
{
|
2007-12-18 14:48:30 +00:00
|
|
|
int buttonNumber = [theEvent buttonNumber];
|
|
|
|
// Fix to mplayer defined button order: left, middle, right
|
|
|
|
if (buttonNumber == 1)
|
|
|
|
buttonNumber = 2;
|
2007-12-18 14:58:14 +00:00
|
|
|
else if (buttonNumber == 2)
|
|
|
|
buttonNumber = 1;
|
2007-08-18 22:46:29 +00:00
|
|
|
switch([theEvent type])
|
|
|
|
{
|
|
|
|
case NSLeftMouseDown:
|
|
|
|
case NSRightMouseDown:
|
|
|
|
case NSOtherMouseDown:
|
2007-12-18 14:48:30 +00:00
|
|
|
mplayer_put_key((MOUSE_BTN0 + buttonNumber) | MP_KEY_DOWN);
|
2007-08-18 22:46:29 +00:00
|
|
|
break;
|
|
|
|
case NSLeftMouseUp:
|
|
|
|
case NSRightMouseUp:
|
|
|
|
case NSOtherMouseUp:
|
2007-12-18 14:48:30 +00:00
|
|
|
mplayer_put_key(MOUSE_BTN0 + buttonNumber);
|
2007-08-18 22:46:29 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
NSResponder
|
|
|
|
*/
|
|
|
|
- (BOOL) acceptsFirstResponder
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) becomeFirstResponder
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) resignFirstResponder
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
2005-05-02 14:40:16 +00:00
|
|
|
|
|
|
|
- (void)windowWillClose:(NSNotification *)aNotification
|
|
|
|
{
|
2006-12-10 01:38:54 +00:00
|
|
|
mpGLView = NULL;
|
2005-05-02 14:40:16 +00:00
|
|
|
mplayer_put_key(KEY_ESC);
|
|
|
|
}
|
|
|
|
@end
|