summaryrefslogtreecommitdiffstats
path: root/libvo
diff options
context:
space:
mode:
authorUoti Urpala <uau@glyph.nonexistent.invalid>2009-09-04 19:49:35 +0300
committerUoti Urpala <uau@glyph.nonexistent.invalid>2009-09-04 19:49:35 +0300
commit0e1b7765be878491565cf5e471f22b15e106164c (patch)
tree422e500c289335182a2a64934dcabf10b95e32dc /libvo
parenta9618c1c6fe9424dfaeb1677348e0382d7252554 (diff)
parentdcfd043ea8d0c46929aad78596314d837c290d39 (diff)
downloadmpv-0e1b7765be878491565cf5e471f22b15e106164c.tar.bz2
mpv-0e1b7765be878491565cf5e471f22b15e106164c.tar.xz
Merge svn changes up to r29644
Diffstat (limited to 'libvo')
-rw-r--r--libvo/aspect.c52
-rw-r--r--libvo/aspect.h3
-rw-r--r--libvo/font_load_ft.c4
-rw-r--r--libvo/osx_common.c74
-rw-r--r--libvo/osx_common.h3
-rw-r--r--libvo/video_out.c6
-rw-r--r--libvo/video_out.h5
-rw-r--r--libvo/vo_corevideo.h4
-rw-r--r--libvo/vo_corevideo.m287
-rw-r--r--libvo/vo_gl.c21
-rw-r--r--libvo/vo_gl2.c36
-rw-r--r--libvo/vo_quartz.c308
-rw-r--r--libvo/vo_quartz.h152
-rw-r--r--libvo/vo_xv.c14
-rw-r--r--libvo/w32_common.c2
-rw-r--r--libvo/x11_common.c10
16 files changed, 363 insertions, 618 deletions
diff --git a/libvo/aspect.c b/libvo/aspect.c
index 6fa9905731..1b1e5857f3 100644
--- a/libvo/aspect.c
+++ b/libvo/aspect.c
@@ -87,11 +87,11 @@ void aspect_fit(struct vo *vo, int *srcw, int *srch, int fitw, int fith)
#ifdef ASPECT_DEBUG
printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat->prew,aspdat->preh);
#endif
- if(*srch>aspdat->scrh || *srch<aspdat->orgh){
+ if(*srch>fith || *srch<aspdat->orgh){
tmpw = (int)(((float)fith / (float)aspdat->preh * (float)aspdat->prew)
* ((float)aspdat->scrw / ((float)aspdat->scrh / (1.0/vo->monitor_aspect))));
tmpw+= tmpw%2; // round
- if(tmpw<=aspdat->scrw /*&& tmpw>=aspdat->orgw*/){
+ if(tmpw<=fitw /*&& tmpw>=aspdat->orgw*/){
*srch = fith;
*srcw = tmpw;
}else{
@@ -108,9 +108,23 @@ void aspect_fit(struct vo *vo, int *srcw, int *srch, int fitw, int fith)
#endif
}
-void aspect(struct vo *vo, int *srcw, int *srch, int zoom){
- int fitw = zoom ? vo->aspdat.scrw : vo->aspdat.prew;
- int fith = zoom ? vo->aspdat.scrh : vo->aspdat.preh;
+static void get_max_dims(struct vo *vo, int *w, int *h, int zoom)
+{
+ struct aspect_data *aspdat = &vo->aspdat;
+ *w = zoom ? aspdat->scrw : aspdat->prew;
+ *h = zoom ? aspdat->scrh : aspdat->preh;
+ if (zoom && WinID >= 0) zoom = A_WINZOOM;
+ if (zoom == A_WINZOOM) {
+ *w = vo->dwidth;
+ *h = vo->dheight;
+ }
+}
+
+void aspect(struct vo *vo, int *srcw, int *srch, int zoom)
+{
+ int fitw;
+ int fith;
+ get_max_dims(vo, &fitw, &fith, zoom);
if( !zoom && geometry_wh_changed ) {
#ifdef ASPECT_DEBUG
printf("aspect(0) no aspect forced!\n");
@@ -127,22 +141,38 @@ void panscan_init(struct vo *vo)
vo->panscan_amount = 0.0f;
}
-void panscan_calc(struct vo *vo)
+static void panscan_calc_internal(struct vo *vo, int zoom)
{
int fwidth,fheight;
int vo_panscan_area;
+ int max_w, max_h;
+ get_max_dims(vo, &max_w, &max_h, zoom);
struct MPOpts *opts = vo->opts;
if (opts->vo_panscanrange > 0) {
- aspect(vo, &fwidth, &fheight, A_ZOOM);
- vo_panscan_area = (vo->aspdat.scrh - fheight);
+ aspect(vo, &fwidth, &fheight, zoom);
+ vo_panscan_area = max_h - fheight;
if (!vo_panscan_area)
- vo_panscan_area = vo->aspdat.scrw - fwidth;
+ vo_panscan_area = max_w - fwidth;
vo_panscan_area *= opts->vo_panscanrange;
} else
- vo_panscan_area = -opts->vo_panscanrange * vo->aspdat.scrh;
+ vo_panscan_area = -opts->vo_panscanrange * max_h;
- vo->panscan_amount = vo_fs ? vo_panscan : 0;
+ vo->panscan_amount = vo_fs || zoom == A_WINZOOM ? vo_panscan : 0;
vo->panscan_x = vo_panscan_area * vo->panscan_amount * vo->aspdat.asp;
vo->panscan_y = vo_panscan_area * vo->panscan_amount;
}
+
+void panscan_calc(struct vo *vo)
+{
+ panscan_calc_internal(vo, A_ZOOM);
+}
+
+/**
+ * vos that set vo_dwidth and v_dheight correctly should call this to update
+ * vo_panscan_x and vo_panscan_y
+ */
+void panscan_calc_windowed(struct vo *vo)
+{
+ panscan_calc_internal(vo, A_WINZOOM);
+}
diff --git a/libvo/aspect.h b/libvo/aspect.h
index 89839e2c94..07f928a9ff 100644
--- a/libvo/aspect.h
+++ b/libvo/aspect.h
@@ -23,6 +23,7 @@
struct vo;
void panscan_init(struct vo *vo);
void panscan_calc(struct vo *vo);
+void panscan_calc_windowed(struct vo *vo);
void aspect_save_orig(struct vo *vo, int orgw, int orgh);
@@ -30,6 +31,7 @@ void aspect_save_prescale(struct vo *vo, int prew, int preh);
void aspect_save_screenres(struct vo *vo, int scrw, int scrh);
+#define A_WINZOOM 2 ///< zoom to fill window size
#define A_ZOOM 1
#define A_NOZOOM 0
@@ -45,6 +47,7 @@ void aspect_fit(struct vo *vo, int *srcw, int *srch, int fitw, int fith);
#define panscan_init() panscan_init(global_vo)
#define panscan_calc() panscan_calc(global_vo)
+#define panscan_calc_windowed() panscan_calc_windowed(global_vo)
#define aspect_save_orig(...) aspect_save_orig(global_vo, __VA_ARGS__)
#define aspect_save_prescale(...) aspect_save_prescale(global_vo, __VA_ARGS__)
#define aspect_save_screenres(...) aspect_save_screenres(global_vo, __VA_ARGS__)
diff --git a/libvo/font_load_ft.c b/libvo/font_load_ft.c
index f44c2c5796..ae2c6cc2ba 100644
--- a/libvo/font_load_ft.c
+++ b/libvo/font_load_ft.c
@@ -1157,10 +1157,8 @@ void load_font_ft(int width, int height, font_desc_t** fontp, const char *font_n
#ifdef CONFIG_FONTCONFIG
if (font_fontconfig > 0)
{
- if (!font_name)
- font_name = strdup("sans-serif");
FcInit();
- fc_pattern = FcNameParse(font_name);
+ fc_pattern = FcNameParse(font_name ? font_name : "sans-serif");
FcConfigSubstitute(0, fc_pattern, FcMatchPattern);
FcDefaultSubstitute(fc_pattern);
fc_pattern2 = fc_pattern;
diff --git a/libvo/osx_common.c b/libvo/osx_common.c
new file mode 100644
index 0000000000..642fa9e4da
--- /dev/null
+++ b/libvo/osx_common.c
@@ -0,0 +1,74 @@
+// only to get keycode definitions from HIToolbox/Events.h
+#include "config.h"
+
+#include <Carbon/Carbon.h>
+#include "osx_common.h"
+#include "video_out.h"
+#include "osdep/keycodes.h"
+#include "input/input.h"
+
+static const struct keymap keymap[] = {
+ // special keys
+ {0x34, KEY_ENTER}, // Enter key on some iBooks?
+ {kVK_Return, KEY_ENTER},
+ {kVK_Escape, KEY_ESC},
+ {kVK_Delete, KEY_BACKSPACE}, {kVK_Option, KEY_BACKSPACE}, {kVK_Control, KEY_BACKSPACE}, {kVK_Shift, KEY_BACKSPACE},
+ {kVK_Tab, KEY_TAB},
+
+ // cursor keys
+ {kVK_UpArrow, KEY_UP}, {kVK_DownArrow, KEY_DOWN}, {kVK_LeftArrow, KEY_LEFT}, {kVK_RightArrow, KEY_RIGHT},
+
+ // navigation block
+ {kVK_Help, KEY_INSERT}, {kVK_ForwardDelete, KEY_DELETE}, {kVK_Home, KEY_HOME},
+ {kVK_End, KEY_END}, {kVK_PageUp, KEY_PAGE_UP}, {kVK_PageUp, KEY_PAGE_DOWN},
+
+ // F-keys
+ {kVK_F1, KEY_F + 1}, {kVK_F2, KEY_F + 2}, {kVK_F3, KEY_F + 3}, {kVK_F4, KEY_F + 4},
+ {kVK_F5, KEY_F + 5}, {kVK_F6, KEY_F + 6}, {kVK_F7, KEY_F + 7}, {kVK_F8, KEY_F + 8},
+ {kVK_F9, KEY_F + 9}, {kVK_F10, KEY_F + 10}, {kVK_F11, KEY_F + 11}, {kVK_F12, KEY_F + 12},
+
+ // numpad
+ {kVK_ANSI_KeypadPlus, '+'}, {kVK_ANSI_KeypadMinus, '-'}, {kVK_ANSI_KeypadMultiply, '*'},
+ {kVK_ANSI_KeypadDivide, '/'}, {kVK_ANSI_KeypadEnter, KEY_KPENTER}, {kVK_ANSI_KeypadDecimal, KEY_KPDEC},
+ {kVK_ANSI_Keypad0, KEY_KP0}, {kVK_ANSI_Keypad1, KEY_KP1}, {kVK_ANSI_Keypad2, KEY_KP2}, {kVK_ANSI_Keypad3, KEY_KP3},
+ {kVK_ANSI_Keypad4, KEY_KP4}, {kVK_ANSI_Keypad5, KEY_KP5}, {kVK_ANSI_Keypad6, KEY_KP6}, {kVK_ANSI_Keypad7, KEY_KP7},
+ {kVK_ANSI_Keypad8, KEY_KP8}, {kVK_ANSI_Keypad9, KEY_KP9},
+
+ {0, 0}
+};
+
+int convert_key(unsigned key, unsigned charcode)
+{
+ int mpkey = lookup_keymap_table(keymap, key);
+ if (mpkey)
+ return mpkey;
+ return charcode;
+}
+
+static int our_aspect_change;
+static float old_movie_aspect;
+
+/**
+ * Sends MPlayer a command to change aspect to the requested value.
+ * @param new_aspect desired new aspect, < 0 means restore original.
+ */
+void change_movie_aspect(float new_aspect)
+{
+ char cmd_str[64];
+ if (new_aspect < 0)
+ new_aspect = old_movie_aspect;
+ our_aspect_change = 1;
+ snprintf(cmd_str, sizeof(cmd_str), "switch_ratio %f", new_aspect);
+ mp_input_queue_cmd(mp_input_parse_cmd(cmd_str));
+}
+
+/**
+ * Call in config to save the original movie aspect.
+ * This will ignore config calls caused by change_movie_aspect.
+ */
+void config_movie_aspect(float config_aspect)
+{
+ if (!our_aspect_change)
+ old_movie_aspect = config_aspect;
+ our_aspect_change = 0;
+}
diff --git a/libvo/osx_common.h b/libvo/osx_common.h
new file mode 100644
index 0000000000..ce598240c2
--- /dev/null
+++ b/libvo/osx_common.h
@@ -0,0 +1,3 @@
+int convert_key(unsigned key, unsigned charcode);
+void change_movie_aspect(float new_aspect);
+void config_movie_aspect(float config_aspect);
diff --git a/libvo/video_out.c b/libvo/video_out.c
index f81544fc93..01c04f3ca6 100644
--- a/libvo/video_out.c
+++ b/libvo/video_out.c
@@ -476,9 +476,9 @@ void calc_src_dst_rects(struct vo *vo, int src_width, int src_height,
if (borders) {
borders->left = 0; borders->top = 0;
}
- if (vo_fs) {
- aspect(vo, &scaled_width, &scaled_height, A_ZOOM);
- panscan_calc(vo);
+ if (aspect_scaling()) {
+ aspect(vo, &scaled_width, &scaled_height, A_WINZOOM);
+ panscan_calc_windowed(vo);
scaled_width += vo->panscan_x;
scaled_height += vo->panscan_y;
if (borders) {
diff --git a/libvo/video_out.h b/libvo/video_out.h
index 48b2eb295c..a55a2f87be 100644
--- a/libvo/video_out.h
+++ b/libvo/video_out.h
@@ -321,4 +321,9 @@ void calc_src_dst_rects(struct vo *vo, int src_width, int src_height,
struct vo_rect *src, struct vo_rect *dst,
struct vo_rect *borders, const struct vo_rect *crop);
+static inline int aspect_scaling(void)
+{
+ return vo_fs;
+}
+
#endif /* MPLAYER_VIDEO_OUT_H */
diff --git a/libvo/vo_corevideo.h b/libvo/vo_corevideo.h
index 559bb5f309..691ebe6537 100644
--- a/libvo/vo_corevideo.h
+++ b/libvo/vo_corevideo.h
@@ -40,7 +40,6 @@
{
//Cocoa
NSWindow *window;
- NSOpenGLContext *glContext;
NSEvent *event;
//CoreVideo
@@ -55,7 +54,6 @@
GLfloat upperLeft[2];
BOOL mouseHide;
- float winSizeMult;
//menu command id
NSMenuItem *kQuitCmd;
@@ -72,6 +70,8 @@
//timestamps for disabling screensaver and mouse hiding
int lastMouseHide;
int lastScreensaverUpdate;
+@public
+ float winSizeMult;
}
- (BOOL) acceptsFirstResponder;
diff --git a/libvo/vo_corevideo.m b/libvo/vo_corevideo.m
index 7967921467..9ed49a844d 100644
--- a/libvo/vo_corevideo.m
+++ b/libvo/vo_corevideo.m
@@ -47,7 +47,7 @@
#include "input/mouse.h"
#include "osdep/keycodes.h"
-#include "mp_fifo.h"
+#include "osx_common.h"
//Cocoa
NSDistantObject *mplayerosxProxy;
@@ -57,7 +57,6 @@ NSAutoreleasePool *autoreleasepool;
OSType pixelFormat;
//shared memory
-int shm_fd;
BOOL shared_buffer = false;
#define DEFAULT_BUFFER_NAME "mplayerosx"
static char *buffer_name;
@@ -84,7 +83,6 @@ static uint32_t image_format;
static int isFullscreen;
static int isOntop;
static int isRootwin;
-static float old_movie_aspect;
extern int enable_mouse_movements;
static float winAlpha = 1;
@@ -115,10 +113,8 @@ static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigne
}
}
-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)
+static void update_screen_info(void)
{
-
- //init screen
screen_array = [NSScreen screens];
if(screen_id < (int)[screen_array count])
{
@@ -130,9 +126,45 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_
screen_handle = [screen_array objectAtIndex:0];
screen_id = -1;
}
- screen_frame = [screen_handle frame];
+
+ screen_frame = ![mpGLView window] || screen_id >= 0 ? [screen_handle frame] : [[[mpGLView window] screen] 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);
+}
+
+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;
+ }
+}
+
+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();
+ config_movie_aspect((float)d_width/d_height);
+
+ vo_dwidth = d_width *= mpGLView->winSizeMult;
+ vo_dheight = d_height *= mpGLView->winSizeMult;
//misc mplayer setup
image_width = width;
@@ -157,18 +189,6 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_
image_datas[1] = malloc(image_width*image_height*image_bytes);
image_page = 0;
- 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
@@ -177,11 +197,10 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_
}
else
{
+ int shm_fd;
mp_msg(MSGT_VO, MSGL_INFO, "[vo_corevideo] writing output to a shared buffer "
"named \"%s\"\n",buffer_name);
- movie_aspect = (float)d_width/(float)d_height;
-
// create shared memory
shm_fd = shm_open(buffer_name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (shm_fd == -1)
@@ -196,12 +215,14 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_
{
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)
{
@@ -216,7 +237,7 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_
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)];
+ [mplayerosxProto startWithWidth: image_width withHeight: image_height withBytes: image_bytes withAspect:d_width*100/d_height];
}
else {
[mplayerosxProxy release];
@@ -297,24 +318,11 @@ static int query_format(uint32_t format)
static void uninit(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));
-
- }
-
SetSystemUIMode( kUIModeNormal, 0);
CGDisplayShowCursor(kCGDirectMainDisplay);
+ free_file_specific();
+
if(mpGLView)
{
NSAutoreleasePool *finalPool;
@@ -324,15 +332,6 @@ static void uninit(void)
[NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES];
[finalPool release];
}
- if (!shared_buffer)
- {
- free(image_datas[0]);
- if (vo_doublebuffering)
- free(image_datas[1]);
- image_datas[0] = NULL;
- image_datas[1] = NULL;
- image_data = NULL;
- }
if (buffer_name) free(buffer_name);
buffer_name = NULL;
@@ -426,6 +425,7 @@ static int control(uint32_t request, void *data)
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;
}
@@ -436,6 +436,10 @@ static int control(uint32_t request, void *data)
@implementation MPlayerOpenGLView
- (void) preinit
{
+ NSOpenGLContext *glContext;
+ GLint swapInterval = 1;
+ CVReturn error;
+
//init menu
[self initMenu];
@@ -453,6 +457,38 @@ static int control(uint32_t request, void *data)
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);
+}
+
+- (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
@@ -460,24 +496,15 @@ static int control(uint32_t request, void *data)
uint32_t d_width;
uint32_t d_height;
- GLint swapInterval = 1;
-
NSRect frame;
CVReturn error = kCVReturnSuccess;
//config window
- aspect((int *)&d_width, (int *)&d_height,A_NOZOOM);
+ d_width = vo_dwidth; d_height = vo_dheight;
frame = NSMakeRect(0, 0, d_width, d_height);
[window setContentSize: frame.size];
- //create OpenGL Context
- glContext = [[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:nil];
-
- [self setOpenGLContext:glContext];
- [glContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
- [glContext setView:self];
- [glContext makeCurrentContext];
-
+ [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);
@@ -487,10 +514,6 @@ static int control(uint32_t request, void *data)
mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create Pixel Double Buffer(%d)\n", error);
}
- 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);
-
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);
@@ -594,8 +617,8 @@ static int control(uint32_t request, void *data)
}
winSizeMult = 0.5;
- frame.size.width = (d_width*winSizeMult);
- frame.size.height = ((d_width/movie_aspect)*winSizeMult);
+ frame.size.width = d_width*winSizeMult;
+ frame.size.height = d_height*winSizeMult;
[window setContentSize: frame.size];
[self reshape];
}
@@ -607,7 +630,7 @@ static int control(uint32_t request, void *data)
winSizeMult = 1;
frame.size.width = d_width;
- frame.size.height = d_width/movie_aspect;
+ frame.size.height = d_height;
[window setContentSize: frame.size];
[self reshape];
}
@@ -619,7 +642,7 @@ static int control(uint32_t request, void *data)
winSizeMult = 2;
frame.size.width = d_width*winSizeMult;
- frame.size.height = (d_width/movie_aspect)*winSizeMult;
+ frame.size.height = d_height*winSizeMult;
[window setContentSize: frame.size];
[self reshape];
}
@@ -652,55 +675,13 @@ static int control(uint32_t request, void *data)
}
if(sender == kAspectOrgCmd)
- {
- movie_aspect = old_movie_aspect;
-
- 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];
- }
- }
+ change_movie_aspect(-1);
if(sender == kAspectFullCmd)
- {
- movie_aspect = 4.0f/3.0f;
-
- 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];
- }
- }
+ change_movie_aspect(4.0f/3.0f);
if(sender == kAspectWideCmd)
- {
- movie_aspect = 16.0f/9.0f;
-
- 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];
- }
- }
+ change_movie_aspect(16.0f/9.0f);
}
/*
@@ -722,11 +703,10 @@ static int control(uint32_t request, void *data)
{
uint32_t d_width;
uint32_t d_height;
- float aspectX;
- float aspectY;
- int padding = 0;
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);
@@ -738,29 +718,14 @@ static int control(uint32_t request, void *data)
//set texture frame
if(vo_keepaspect)
{
- aspect( (int *)&d_width, (int *)&d_height, A_NOZOOM);
- d_height = ((float)d_width/movie_aspect);
+ aspect( (int *)&d_width, (int *)&d_height, A_WINZOOM);
- 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;
- textureFrame = NSMakeRect(padding, 0, d_width*aspectY, d_height*aspectY);
- }
- else
- {
- padding = ((frame.size.height) - d_height*aspectX)/2;
- textureFrame = NSMakeRect(0, padding, d_width*aspectX, d_height*aspectX);
- }
+ textureFrame = NSMakeRect((vo_dwidth - d_width) / 2, (vo_dheight - d_height) / 2, d_width, d_height);
}
else
{
textureFrame = frame;
}
- vo_dwidth = textureFrame.size.width;
- vo_dheight = textureFrame.size.height;
}
/*
@@ -875,13 +840,7 @@ static int control(uint32_t request, void *data)
}
old_frame = [window frame]; //save main window size & position
- if(screen_id >= 0)
- screen_frame = [screen_handle frame];
- else {
- screen_frame = [[window screen] frame];
- vo_screenwidth = screen_frame.size.width;
- vo_screenheight = screen_frame.size.height;
- }
+ update_screen_info();
[window setFrame:screen_frame display:YES animate:animate]; //zoom-in window with nice useless sfx
old_view_frame = [self bounds];
@@ -992,58 +951,8 @@ static int control(uint32_t request, void *data)
*/
- (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;
- case 0x4C: key = KEY_KPENTER; break;
- 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;
- }
+ int key = convert_key([theEvent keyCode], *[[theEvent characters] UTF8String]);
+ if (key != -1)
mplayer_put_key(key);
}
diff --git a/libvo/vo_gl.c b/libvo/vo_gl.c
index 13ff34cd68..a97b524c56 100644
--- a/libvo/vo_gl.c
+++ b/libvo/vo_gl.c
@@ -159,18 +159,18 @@ static void resize(int x,int y){
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
ass_border_x = ass_border_y = 0;
- if (vo_fs && use_aspect) {
+ if (aspect_scaling() && use_aspect) {
int new_w, new_h;
GLdouble scale_x, scale_y;
- aspect(&new_w, &new_h, A_ZOOM);
- panscan_calc();
+ aspect(&new_w, &new_h, A_WINZOOM);
+ panscan_calc_windowed();
new_w += vo_panscan_x;
new_h += vo_panscan_y;
scale_x = (GLdouble)new_w / (GLdouble)x;
scale_y = (GLdouble)new_h / (GLdouble)y;
glScaled(scale_x, scale_y, 1);
- ass_border_x = (vo_screenwidth - new_w) / 2;
- ass_border_y = (vo_screenheight - new_h) / 2;
+ ass_border_x = (vo_dwidth - new_w) / 2;
+ ass_border_y = (vo_dheight - new_h) / 2;
}
glOrtho(0, image_width, image_height, 0, -1,1);
@@ -557,7 +557,8 @@ config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uin
glconfig:
if (vo_config_count)
uninitGl();
- setGlWindow(&gl_vinfo, &gl_context, vo_window);
+ if (setGlWindow(&gl_vinfo, &gl_context, vo_window) == SET_WINDOW_FAILED)
+ return -1;
initGl(vo_dwidth, vo_dheight);
return 0;
@@ -708,7 +709,7 @@ static void flip_page(void) {
if (vo_doublebuffering) {
if (use_glFinish) glFinish();
swapGlBuffers();
- if (vo_fs && use_aspect)
+ if (aspect_scaling() && use_aspect)
glClear(GL_COLOR_BUFFER_BIT);
} else {
do_render();
@@ -1131,14 +1132,12 @@ static int control(uint32_t request, void *data)
case VOCTRL_GET_EOSD_RES:
{
mp_eosd_res_t *r = data;
+ r->w = vo_dwidth; r->h = vo_dheight;
r->mt = r->mb = r->ml = r->mr = 0;
if (scaled_osd) {r->w = image_width; r->h = image_height;}
- else if (vo_fs) {
- r->w = vo_screenwidth; r->h = vo_screenheight;
+ else if (aspect_scaling()) {
r->ml = r->mr = ass_border_x;
r->mt = r->mb = ass_border_y;
- } else {
- r->w = vo_dwidth; r->h = vo_dheight;
}
}
return VO_TRUE;
diff --git a/libvo/vo_gl2.c b/libvo/vo_gl2.c
index 9e719e03c9..71361916f4 100644
--- a/libvo/vo_gl2.c
+++ b/libvo/vo_gl2.c
@@ -416,23 +416,23 @@ static void drawTextureDisplay (void)
}
-static void resize(int *x,int *y){
- mp_msg(MSGT_VO,MSGL_V,"[gl2] Resize: %dx%d\n",*x,*y);
- if( vo_fs ) {
+static void resize(int x,int y){
+ mp_msg(MSGT_VO,MSGL_V,"[gl2] Resize: %dx%d\n",x,y);
+ if(aspect_scaling()) {
glClear(GL_COLOR_BUFFER_BIT);
- aspect(x, y, A_ZOOM);
- panscan_calc();
- *x += vo_panscan_x;
- *y += vo_panscan_y;
- glViewport( (vo_screenwidth-*x)/2, (vo_screenheight-*y)/2, *x, *y);
+ aspect(&x, &y, A_WINZOOM);
+ panscan_calc_windowed();
+ x += vo_panscan_x;
+ y += vo_panscan_y;
+ glViewport( (vo_dwidth-x)/2, (vo_dheight-y)/2, x, y);
} else {
//aspect(x, y, A_NOZOOM);
if (WinID >= 0) {
- int top = 0, left = 0, w = *x, h = *y;
+ int top = 0, left = 0, w = x, h = y;
geometry(&top, &left, &w, &h, vo_screenwidth, vo_screenheight);
glViewport(top, left, w, h);
} else
- glViewport( 0, 0, *x, *y );
+ glViewport( 0, 0, x, y );
}
glMatrixMode(GL_PROJECTION);
@@ -468,9 +468,6 @@ static int config_w32(uint32_t width, uint32_t height, uint32_t d_width, uint32_
if (!vo_w32_config(d_width, d_height, flags))
return -1;
- if (vo_fs)
- aspect(&d_width, &d_height, A_ZOOM);
-
return 0;
}
@@ -590,7 +587,7 @@ static int initGl(uint32_t d_width, uint32_t d_height)
glValName(gl_bitmap_format), glValName(gl_bitmap_type),
rgb_sz, r_sz, g_sz, b_sz, a_sz, glValName(gl_internal_format));
- resize(&d_width, &d_height);
+ resize(d_width, d_height);
glClearColor( 0.0f,0.0f,0.0f,0.0f );
glClear( GL_COLOR_BUFFER_BIT );
@@ -619