diff options
author | wm4 <wm4@mplayer2.org> | 2012-04-29 07:16:09 +0200 |
---|---|---|
committer | wm4 <wm4@mplayer2.org> | 2012-04-29 10:01:28 +0200 |
commit | 97ac824124fc5cdfbd9ac74156b79c098bce09c6 (patch) | |
tree | 2c924403e2fb619ec57ee0933cd12d32ef1bb62a /libvo | |
parent | 87f4cafe9c0881743d1117c2e8cd7e3376e33302 (diff) | |
parent | f64a4e9931428de0f308f6ed0a0144edb8ce9619 (diff) | |
download | mpv-97ac824124fc5cdfbd9ac74156b79c098bce09c6.tar.bz2 mpv-97ac824124fc5cdfbd9ac74156b79c098bce09c6.tar.xz |
Merge remote-tracking branch 'origin/master'
Conflicts:
bstr.c
bstr.h
libvo/cocoa_common.m
libvo/gl_common.c
libvo/video_out.c
mplayer.c
screenshot.c
sub/subassconvert.c
Merge of cocoa_common.m done by pigoz.
Picking my version of screenshot.c. The fix in commit aadf1002f8a will
be redone in a follow-up commit, as the original commit causes too many
conflicts with the work done locally in this branch, and other work in
progress.
Diffstat (limited to 'libvo')
-rw-r--r-- | libvo/cocoa_common.h | 6 | ||||
-rw-r--r-- | libvo/cocoa_common.m | 47 | ||||
-rw-r--r-- | libvo/gl_common.c | 5 | ||||
-rw-r--r-- | libvo/gl_common.h | 1 | ||||
-rw-r--r-- | libvo/video_out.c | 4 | ||||
-rw-r--r-- | libvo/vo_corevideo.h | 87 | ||||
-rw-r--r-- | libvo/vo_corevideo.m | 1317 | ||||
-rw-r--r-- | libvo/vo_sharedbuffer.h | 37 | ||||
-rw-r--r-- | libvo/vo_sharedbuffer.m | 277 |
9 files changed, 723 insertions, 1058 deletions
diff --git a/libvo/cocoa_common.h b/libvo/cocoa_common.h index d47ac51500..1a2ec7bd75 100644 --- a/libvo/cocoa_common.h +++ b/libvo/cocoa_common.h @@ -22,6 +22,9 @@ #include "video_out.h" +bool vo_cocoa_gui_running(void); +void *vo_cocoa_glgetaddr(const char *s); + int vo_cocoa_init(struct vo *vo); void vo_cocoa_uninit(struct vo *vo); @@ -40,4 +43,7 @@ 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); +void *vo_cocoa_cgl_context(void); +void *vo_cocoa_cgl_pixel_format(void); + #endif /* MPLAYER_COCOA_COMMON_H */ diff --git a/libvo/cocoa_common.m b/libvo/cocoa_common.m index e8ef278b1e..66f4cd3937 100644 --- a/libvo/cocoa_common.m +++ b/libvo/cocoa_common.m @@ -21,6 +21,8 @@ #import <OpenGL/OpenGL.h> #import <QuartzCore/QuartzCore.h> #import <CoreServices/CoreServices.h> // for CGDisplayHideCursor and Gestalt +#include <dlfcn.h> + #include "cocoa_common.h" #include "options.h" @@ -66,6 +68,7 @@ struct vo_cocoa_state { NSAutoreleasePool *pool; GLMPlayerWindow *window; NSOpenGLContext *glContext; + NSOpenGLPixelFormat *pixelFormat; NSSize current_video_size; NSSize previous_video_size; @@ -125,6 +128,24 @@ struct vo_cocoa_state *vo_cocoa_init_state(void) return s; } +bool vo_cocoa_gui_running(void) +{ + return !!s; +} + +void *vo_cocoa_glgetaddr(const char *s) +{ + void *ret = NULL; + void *handle = dlopen( + "/System/Library/Frameworks/OpenGL.framework/OpenGL", + RTLD_LAZY | RTLD_LOCAL); + if (!handle) + return NULL; + ret = dlsym(handle, s); + dlclose(handle); + return ret; +} + int vo_cocoa_init(struct vo *vo) { s = vo_cocoa_init_state(); @@ -140,6 +161,8 @@ int vo_cocoa_init(struct vo *vo) void vo_cocoa_uninit(struct vo *vo) { CGDisplayShowCursor(kCGDirectMainDisplay); + [NSApp setPresentationOptions:NSApplicationPresentationDefault]; + [s->window release]; s->window = nil; [s->glContext release]; @@ -148,6 +171,7 @@ void vo_cocoa_uninit(struct vo *vo) s->pool = nil; talloc_free(s); + s = nil; } void update_screen_info(void) @@ -232,8 +256,8 @@ int vo_cocoa_create_window(struct vo *vo, uint32_t d_width, attr[i++] = (NSOpenGLPixelFormatAttribute)16; // 16 bit depth buffer attr[i] = (NSOpenGLPixelFormatAttribute)0; - NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr]; - s->glContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil]; + s->pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attr] autorelease]; + s->glContext = [[NSOpenGLContext alloc] initWithFormat:s->pixelFormat shareContext:nil]; create_menu(); @@ -365,6 +389,16 @@ int vo_cocoa_swap_interval(int enabled) return 0; } +void *vo_cocoa_cgl_context(void) +{ + return [s->glContext CGLContextObj]; +} + +void *vo_cocoa_cgl_pixel_format(void) +{ + return [s->pixelFormat CGLPixelFormatObj]; +} + void create_menu() { NSMenu *menu; @@ -565,18 +599,19 @@ bool is_lion_or_better(void) - (void) applicationWillBecomeActive:(NSNotification *)aNotification { if (vo_fs) { + [s->window makeKeyAndOrderFront:s->window]; [s->window setLevel:s->fullscreen_window_level]; - [NSApp setPresentationOptions:NSApplicationPresentationHideDock|NSApplicationPresentationHideMenuBar]; - [s->window makeKeyAndOrderFront:nil]; - [NSApp activateIgnoringOtherApps: YES]; + [NSApp setPresentationOptions:NSApplicationPresentationHideDock| + NSApplicationPresentationHideMenuBar]; } } - (void) applicationWillResignActive:(NSNotification *)aNotification { if (vo_fs) { - [s->window setLevel:s->windowed_window_level]; [NSApp setPresentationOptions:NSApplicationPresentationDefault]; + [s->window setLevel:s->windowed_window_level]; + [s->window orderBack:s->window]; } } diff --git a/libvo/gl_common.c b/libvo/gl_common.c index 9a8de977b2..cd618b443c 100644 --- a/libvo/gl_common.c +++ b/libvo/gl_common.c @@ -330,6 +330,7 @@ static const extfunc_desc_t extfuncs[] = { DEF_FUNC_DESC(Color4ub), DEF_FUNC_DESC(Color4f), DEF_FUNC_DESC(TexCoord2f), + DEF_FUNC_DESC(TexCoord2fv), DEF_FUNC_DESC(Vertex2f), DEF_FUNC_DESC(VertexPointer), DEF_FUNC_DESC(ColorPointer), @@ -1725,14 +1726,14 @@ static int create_window_cocoa_gl3(struct MPGLContext *ctx, int gl_flags, uint32_t d_height, uint32_t flags) { int rv = vo_cocoa_create_window(ctx->vo, d_width, d_height, flags, 1); - getFunctions(ctx->gl, (void *)getdladdr, NULL, true); + getFunctions(ctx->gl, (void *)vo_cocoa_glgetaddr, NULL, true); return rv; } static int setGlWindow_cocoa(MPGLContext *ctx) { vo_cocoa_change_attributes(ctx->vo); - getFunctions(ctx->gl, (void *)getdladdr, NULL, false); + getFunctions(ctx->gl, (void *)vo_cocoa_glgetaddr, NULL, false); if (!ctx->gl->SwapInterval) ctx->gl->SwapInterval = vo_cocoa_swap_interval; return SET_WINDOW_OK; diff --git a/libvo/gl_common.h b/libvo/gl_common.h index 8091886b1f..f0e5912dd9 100644 --- a/libvo/gl_common.h +++ b/libvo/gl_common.h @@ -260,6 +260,7 @@ struct GL { void (GLAPIENTRY *TexParameterf)(GLenum, GLenum, GLfloat); void (GLAPIENTRY *TexParameterfv)(GLenum, GLenum, const GLfloat *); void (GLAPIENTRY *TexCoord2f)(GLfloat, GLfloat); + void (GLAPIENTRY *TexCoord2fv)(const GLfloat *); void (GLAPIENTRY *Vertex2f)(GLfloat, GLfloat); void (GLAPIENTRY *GetIntegerv)(GLenum, GLint *); void (GLAPIENTRY *GetBooleanv)(GLenum, GLboolean *); diff --git a/libvo/video_out.c b/libvo/video_out.c index 9b06794c61..aea62ce0ab 100644 --- a/libvo/video_out.c +++ b/libvo/video_out.c @@ -118,6 +118,7 @@ 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_sharedbuffer; extern struct vo_driver video_out_pnm; extern struct vo_driver video_out_md5sum; @@ -221,6 +222,9 @@ const struct vo_driver *video_out_drivers[] = #endif &video_out_null, // should not be auto-selected +#ifdef CONFIG_SHAREDBUFFER + &video_out_sharedbuffer, +#endif #ifdef CONFIG_DIRECTFB // vo directfb can call exit() if initialization fails &video_out_directfb, diff --git a/libvo/vo_corevideo.h b/libvo/vo_corevideo.h index 926399053f..cfb86621bc 100644 --- a/libvo/vo_corevideo.h +++ b/libvo/vo_corevideo.h @@ -23,93 +23,6 @@ #ifndef MPLAYER_VO_COREVIDEO_H #define MPLAYER_VO_COREVIDEO_H -#import <Cocoa/Cocoa.h> #import <QuartzCore/QuartzCore.h> -#import <Carbon/Carbon.h> - -// MPlayer OS X VO Protocol -@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; -@end - -@interface MPlayerOpenGLView : NSOpenGLView -{ - //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 - 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; -@public - float winSizeMult; -} - -- (BOOL) acceptsFirstResponder; -- (BOOL) becomeFirstResponder; -- (BOOL) resignFirstResponder; - -//window & rendering -- (void) preinit; -- (void) config; -- (void) prepareOpenGL; -- (void) render; -- (void) reshape; -- (void) setCurrentTexture; -- (void) drawRect: (NSRect *) bounds; - -//vo control -- (void) fullscreen: (BOOL) animate; -- (void) ontop; -- (void) panscan; -- (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 */ diff --git a/libvo/vo_corevideo.m b/libvo/vo_corevideo.m index e937460636..57e93a9326 100644 --- a/libvo/vo_corevideo.m +++ b/libvo/vo_corevideo.m @@ -20,1057 +20,448 @@ */ #import "vo_corevideo.h" -#include <sys/types.h> -#include <sys/ipc.h> -#include <sys/mman.h> -#include <unistd.h> -#include <CoreServices/CoreServices.h> -//special workaround for Apple bug #6267445 -//(OSServices Power API disabled in OSServices.h for 64bit systems) -#ifndef __POWER__ -#include <CoreServices/../Frameworks/OSServices.framework/Headers/Power.h> -#endif - -//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/keycodes.h" -#include "osx_common.h" - -//Cocoa -NSDistantObject *mplayerosxProxy; -id <MPlayerOSXVOProto> mplayerosxProto; -MPlayerOpenGLView *mpGLView; -NSAutoreleasePool *autoreleasepool; -OSType pixelFormat; - -//shared memory -BOOL shared_buffer = false; -#define DEFAULT_BUFFER_NAME "mplayerosx" -static char *buffer_name; - -//Screen -int screen_id = -1; -NSRect screen_frame; -NSScreen *screen_handle; -NSArray *screen_array; - -//image -unsigned char *image_data; -// For double buffering -static uint8_t image_page = 0; -static unsigned char *image_datas[2]; - -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; -static int isOntop; -static int isRootwin; - -static float winAlpha = 1; -static int int_pause = 0; - -static BOOL isLeopardOrLater; - -#define NSLeftAlternateKeyMask (0x000020 | NSAlternateKeyMask) -#define NSRightAlternateKeyMask (0x000040 | NSAlternateKeyMask) - -static vo_info_t info = -{ - "Mac OS X Core Video", - "corevideo", - "Nicolas Plourde <nicolas.plourde@gmail.com>", - "" + +// mplayer includes +#import "fastmemcpy.h" +#import "talloc.h" +#import "video_out.h" +#import "aspect.h" +#import "sub/font_load.h" +#import "sub/sub.h" +#import "subopt-helper.h" + +#import "csputils.h" +#import "libmpcodecs/vfcap.h" +#import "libmpcodecs/mp_image.h" +#import "osd.h" + +#import "gl_common.h" +#import "cocoa_common.h" + +struct quad { + GLfloat lowerLeft[2]; + GLfloat lowerRight[2]; + GLfloat upperRight[2]; + GLfloat upperLeft[2]; }; -LIBVO_EXTERN(corevideo) +#define CV_VERTICES_PER_QUAD 6 +#define CV_MAX_OSD_PARTS 20 -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_RGB24: - vo_draw_alpha_rgb24(w,h,src,srca,stride,image_data+3*(y0*image_width+x0),3*image_width); - break; - case IMGFMT_ARGB: - case IMGFMT_BGRA: - 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; - } -} +struct osd_p { + GLuint tex[CV_MAX_OSD_PARTS]; + NSRect tex_rect[CV_MAX_OSD_PARTS]; + int tex_cnt; +}; -static void update_screen_info(void) -{ - if (screen_id == -1 && xinerama_screen > -1) - screen_id = xinerama_screen; - - screen_array = [NSScreen screens]; - 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 = xinerama_y = 0; - aspect_save_screenres(vo_screenwidth, vo_screenheight); -} +struct priv { + MPGLContext *mpglctx; + OSType pixelFormat; + unsigned int image_width; + unsigned int image_height; + struct mp_csp_details colorspace; -static void free_file_specific(void) -{ - if(shared_buffer) - { - [mplayerosxProto stop]; - mplayerosxProto = nil; - [mplayerosxProxy release]; - mplayerosxProxy = nil; - - if (munmap(image_data, image_width*image_height*image_bytes) == -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]); - if (vo_doublebuffering) - free(image_datas[1]); - image_datas[0] = NULL; - image_datas[1] = NULL; - image_data = NULL; - } -} + CVPixelBufferRef pixelBuffer; + CVOpenGLTextureCacheRef textureCache; + CVOpenGLTextureRef texture; + struct quad *quad; -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_depth = 24; - break; - case IMGFMT_ARGB: - case IMGFMT_BGRA: - image_depth = 32; - break; - case IMGFMT_YUY2: - image_depth = 16; - break; - } - image_bytes = (image_depth + 7) / 8; - - if(!shared_buffer) - { - config_movie_aspect((float)d_width/d_height); - - vo_dwidth = d_width *= mpGLView->winSizeMult; - vo_dheight = d_height *= mpGLView->winSizeMult; - - image_data = malloc(image_width*image_height*image_bytes); - image_datas[0] = image_data; - if (vo_doublebuffering) - image_datas[1] = malloc(image_width*image_height*image_bytes); - image_page = 0; - - vo_fs = flags & VOFLAG_FULLSCREEN; - - //config OpenGL View - [mpGLView config]; - [mpGLView reshape]; - } - 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_width*image_height*image_bytes) == -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_width*image_height*image_bytes, - 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; -} + struct osd_p *osd; +}; -static void check_events(void) -{ - if (mpGLView) - [mpGLView check_events]; -} +static struct priv *p; -static void draw_osd(void) +static void resize(struct vo *vo, int width, int height) { - vo_draw_text(image_width, image_height, draw_alpha); -} + GL *gl = p->mpglctx->gl; + p->image_width = width; + p->image_height = height; -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]; - } - } -} + mp_msg(MSGT_VO, MSGL_V, "[vo_corevideo] New OpenGL Viewport (0, 0, %d, " + "%d)\n", p->image_width, p->image_height); -static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) -{ - return 0; -} + gl->Viewport(0, 0, p->image_width, p->image_height); + gl->MatrixMode(GL_PROJECTION); + gl->LoadIdentity(); + if (aspect_scaling()) { + int new_w, new_h; + GLdouble scale_x, scale_y; -static int draw_frame(uint8_t *src[]) -{ - return 0; -} + aspect(vo, &new_w, &new_h, A_WINZOOM); + panscan_calc_windowed(vo); + new_w += vo->panscan_x; + new_h += vo->panscan_y; + scale_x = (GLdouble)new_w / (GLdouble)p->image_width; + scale_y = (GLdouble)new_h / (GLdouble)p->image_height; + gl->Scaled(scale_x, scale_y, 1); + } -static uint32_t draw_image(mp_image_t *mpi) -{ - memcpy_pic(image_data, mpi->planes[0], image_width*image_bytes, image_height, image_width*image_bytes, mpi->stride[0]); + gl->Ortho(0, p->image_width, p->image_height, 0, -1.0, 1.0); + gl->MatrixMode(GL_MODELVIEW); + gl->LoadIdentity(); - return 0; -} + force_load_font = 1; + vo_osd_changed(OSDTYPE_OSD); -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_RGB24: - pixelFormat = k24RGBPixelFormat; - return supportflags; - - case IMGFMT_ARGB: - pixelFormat = k32ARGBPixelFormat; - return supportflags; - - case IMGFMT_BGRA: - pixelFormat = k32BGRAPixelFormat; - return supportflags; - } - return 0; + gl->Clear(GL_COLOR_BUFFER_BIT); + vo->want_redraw = true; } -static void uninit(void) +static int init_gl(struct vo *vo, uint32_t d_width, uint32_t d_height) { - SetSystemUIMode( kUIModeNormal, 0); - CGDisplayShowCursor(kCGDirectMainDisplay); + GL *gl = p->mpglctx->gl; - free_file_specific(); + const char *vendor = gl->GetString(GL_VENDOR); + const char *version = gl->GetString(GL_VERSION); + const char *renderer = gl->GetString(GL_RENDERER); - if(mpGLView) - { - NSAutoreleasePool *finalPool; - mpGLView = nil; - [autoreleasepool release]; - finalPool = [[NSAutoreleasePool alloc] init]; - [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES]; - [finalPool release]; - } + mp_msg(MSGT_VO, MSGL_V, "[vo_corevideo] Running on OpenGL '%s' by '%s'," + " version '%s'\n", renderer, vendor, version); - free(buffer_name); - buffer_name = NULL; -} + gl->Disable(GL_BLEND); + gl->Disable(GL_DEPTH_TEST); + gl->DepthMask(GL_FALSE); + gl->Disable(GL_CULL_FACE); + gl->Enable(GL_TEXTURE_2D); + gl->DrawBuffer(GL_BACK); + gl->TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); -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} -}; + resize(vo, d_width, d_height); -static int preinit(const char *arg) -{ + gl->ClearColor(0.0f, 0.0f, 0.0f, 0.0f); + gl->Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + if (gl->SwapInterval) + gl->SwapInterval(1); + return 1; +} - // 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" - " 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 (!buffer_name) - buffer_name = strdup(DEFAULT_BUFFER_NAME); - else - shared_buffer = true; - - if(!shared_buffer) - { - NSApplicationLoad(); - NSApp = [NSApplication sharedApplication]; - isLeopardOrLater = floor(NSAppKitVersionNumber) > 824; - - osx_foreground_hack(); - - if(!mpGLView) - { - mpGLView = [[MPlayerOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) pixelFormat:[MPlayerOpenGLView defaultPixelFormat]]; - [mpGLView autorelease]; - } - // 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:mpGLView - andSelector:@selector(handleQuitEvent:withReplyEvent:) - forEventClass:kCoreEventClass - andEventID:kAEQuitApplication]; - - [mpGLView display]; - [mpGLView preinit]; - } +static void release_cv_entities(void) { + CVPixelBufferRelease(p->pixelBuffer); + p->pixelBuffer = NULL; + CVOpenGLTextureRelease(p->texture); + p->texture = NULL; + CVOpenGLTextureCacheRelease(p->textureCache); + p->textureCache = NULL; - return 0; } -static int control(uint32_t request, void *data) +static int config(struct vo *vo, uint32_t width, uint32_t height, + uint32_t d_width, uint32_t d_height, uint32_t flags, + uint32_t format) { - switch (request) - { - case VOCTRL_DRAW_IMAGE: return draw_image(data); - case VOCTRL_PAUSE: return int_pause = 1; - case VOCTRL_RESUME: return int_pause = 0; - case VOCTRL_QUERY_FORMAT: return query_format(*(uint32_t*)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: [mpGLView panscan]; return VO_TRUE; - case VOCTRL_UPDATE_SCREENINFO: update_screen_info(); return VO_TRUE; - } - return VO_NOTIMPL; -} + release_cv_entities(); + p->image_width = width; + p->image_height = height; -////////////////////////////////////////////////////////////////////////// -// NSOpenGLView Subclass -////////////////////////////////////////////////////////////////////////// -@implementation MPlayerOpenGLView -- (void) preinit -{ - NSOpenGLContext *glContext; - GLint swapInterval = 1; - CVReturn error; - - //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:mpGLView]; - [window setContentView:mpGLView]; - [window setInitialFirstResponder:mpGLView]; - [window setAcceptsMouseMovedEvents:YES]; - [window setTitle:@"MPlayer - The Movie Player"]; - - isFullscreen = 0; - 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]; - - 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); -} + if (p->mpglctx->create_window(p->mpglctx, d_width, d_height, flags) < 0) + return -1; + if (p->mpglctx->setGlWindow(p->mpglctx) == SET_WINDOW_FAILED) + return -1; -- (void) releaseVideoSpecific -{ - CVPixelBufferRelease(frameBuffers[0]); - frameBuffers[0] = NULL; - CVPixelBufferRelease(frameBuffers[1]); - frameBuffers[1] = NULL; - CVOpenGLTextureRelease(texture); - texture = NULL; -} + init_gl(vo, vo->dwidth, vo->dheight); -- (void) dealloc -{ - [self releaseVideoSpecific]; - CVOpenGLTextureCacheRelease(textureCache); - textureCache = NULL; - [self setOpenGLContext:nil]; - [super dealloc]; + return 0; } -- (void) config +static void check_events(struct vo *vo) { - NSRect visibleFrame; - CVReturn error = kCVReturnSuccess; - - //config window - [window setContentSize:NSMakeSize(vo_dwidth, vo_dheight)]; - - // Use visibleFrame to position the window taking the menu bar and dock into account. - // Also flip vo_dy since the screen origin is in the bottom left on OSX. - update_screen_info(); - visibleFrame = [screen_handle visibleFrame]; - [window setFrameTopLeftPoint:NSMakePoint( - visibleFrame.origin.x + vo_dx, - visibleFrame.origin.y + visibleFrame.size.height - vo_dy)]; - - [self releaseVideoSpecific]; - error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[0], image_width*image_bytes, 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_width*image_bytes, 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); - - //show window - [window makeKeyAndOrderFront:mpGLView]; - - if(vo_rootwin) - [mpGLView rootwin]; - - if(vo_fs) - [mpGLView fullscreen: NO]; - - if(vo_ontop) - [mpGLView ontop]; + int e = p->mpglctx->check_events(vo); + if (e & VO_EVENT_RESIZE) + resize(vo, vo->dwidth, vo->dheight); } -/* - Init Menu -*/ -- (void)initMenu +static void create_osd_texture(void *ctx, int x0, int y0, int w, int h, + unsigned char *src, unsigned char *srca, + int stride) { - NSMenu *menu, *aspectMenu; - NSMenuItem *menuItem; - - menu = [[NSMenu new] autorelease]; - menuItem = [[NSMenuItem new] autorelease]; - [menu addItem: menuItem]; - [NSApp setMainMenu: 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]; |