summaryrefslogtreecommitdiffstats
path: root/video/out
diff options
context:
space:
mode:
Diffstat (limited to 'video/out')
-rw-r--r--video/out/bitmap_packer.c4
-rw-r--r--video/out/cocoa_common.h10
-rw-r--r--video/out/cocoa_common.m1047
-rw-r--r--video/out/dither.c239
-rw-r--r--video/out/dither.h2
-rw-r--r--video/out/gl_cocoa.c13
-rw-r--r--video/out/gl_common.c32
-rw-r--r--video/out/gl_common.h24
-rw-r--r--video/out/gl_lcms.c2
-rw-r--r--video/out/gl_osd.c54
-rw-r--r--video/out/gl_osd.h14
-rw-r--r--video/out/gl_video.c410
-rw-r--r--video/out/gl_video.h8
-rw-r--r--video/out/gl_video_shaders.glsl31
-rw-r--r--video/out/gl_w32.c5
-rw-r--r--video/out/gl_wayland.c99
-rw-r--r--video/out/gl_x11.c5
-rw-r--r--video/out/osx_common.h28
-rw-r--r--video/out/osx_common.m181
-rw-r--r--video/out/vo.c133
-rw-r--r--video/out/vo.h67
-rw-r--r--video/out/vo_caca.c20
-rw-r--r--video/out/vo_corevideo.m37
-rw-r--r--video/out/vo_direct3d.c43
-rw-r--r--video/out/vo_image.c9
-rw-r--r--video/out/vo_lavc.c80
-rw-r--r--video/out/vo_null.c5
-rw-r--r--video/out/vo_opengl.c218
-rw-r--r--video/out/vo_opengl_old.c54
-rw-r--r--video/out/vo_sdl.c66
-rw-r--r--video/out/vo_vdpau.c67
-rw-r--r--video/out/vo_x11.c38
-rw-r--r--video/out/vo_xv.c42
-rw-r--r--video/out/w32_common.c162
-rw-r--r--video/out/w32_common.h6
-rw-r--r--video/out/wayland_common.c432
-rw-r--r--video/out/wayland_common.h58
-rw-r--r--video/out/x11_common.c170
-rw-r--r--video/out/x11_common.h10
39 files changed, 1984 insertions, 1941 deletions
diff --git a/video/out/bitmap_packer.c b/video/out/bitmap_packer.c
index aae0703072..4fd6594a35 100644
--- a/video/out/bitmap_packer.c
+++ b/video/out/bitmap_packer.c
@@ -150,9 +150,9 @@ int packer_pack(struct bitmap_packer *packer)
xmax = FFMAX(0, xmax - packer->padding);
ymax = FFMAX(0, ymax - packer->padding);
if (xmax > packer->w)
- packer->w = 1 << av_log2(xmax - 1) + 1;
+ packer->w = 1 << (av_log2(xmax - 1) + 1);
if (ymax > packer->h)
- packer->h = 1 << av_log2(ymax - 1) + 1;
+ packer->h = 1 << (av_log2(ymax - 1) + 1);
while (1) {
int used_width = 0;
int y = pack_rectangles(in, packer->result, packer->count,
diff --git a/video/out/cocoa_common.h b/video/out/cocoa_common.h
index 3450ebd547..081c43d2ce 100644
--- a/video/out/cocoa_common.h
+++ b/video/out/cocoa_common.h
@@ -24,25 +24,25 @@
struct vo_cocoa_state;
-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);
-void vo_cocoa_update_xinerama_info(struct vo *vo);
-
int vo_cocoa_change_attributes(struct vo *vo);
int vo_cocoa_config_window(struct vo *vo, uint32_t d_width,
uint32_t d_height, uint32_t flags,
int gl3profile);
+void vo_cocoa_set_current_context(struct vo *vo, bool current);
void vo_cocoa_swap_buffers(struct vo *vo);
int vo_cocoa_check_events(struct vo *vo);
void vo_cocoa_fullscreen(struct vo *vo);
void vo_cocoa_ontop(struct vo *vo);
-void vo_cocoa_pause(struct vo *vo);
-void vo_cocoa_resume(struct vo *vo);
+int vo_cocoa_control(struct vo *vo, int *events, int request, void *arg);
+
+void vo_cocoa_register_resize_callback(struct vo *vo,
+ void (*cb)(struct vo *vo, int w, int h));
// returns an int to conform to the gl extensions from other platforms
int vo_cocoa_swap_interval(int enabled);
diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m
index 8e06e637a4..dc95e537a1 100644
--- a/video/out/cocoa_common.m
+++ b/video/out/cocoa_common.m
@@ -31,145 +31,89 @@
#include "vo.h"
#include "aspect.h"
-#include "core/mp_fifo.h"
#include "talloc.h"
-#include "core/input/input.h"
-#include "core/input/keycodes.h"
-#include "osx_common.h"
#include "core/mp_msg.h"
-#ifndef NSOpenGLPFAOpenGLProfile
-#define NSOpenGLPFAOpenGLProfile 99
-#endif
+#include "osdep/macosx_application.h"
+#include "osdep/macosx_events.h"
+#include "osdep/macosx_compat.h"
-#ifndef NSOpenGLProfileVersionLegacy
-#define NSOpenGLProfileVersionLegacy 0x1000
-#endif
-
-#ifndef NSOpenGLProfileVersion3_2Core
-#define NSOpenGLProfileVersion3_2Core 0x3200
-#endif
-
-#define NSLeftAlternateKeyMask (0x000020 | NSAlternateKeyMask)
-#define NSRightAlternateKeyMask (0x000040 | NSAlternateKeyMask)
-
-static bool LeftAltPressed(NSEvent *event)
-{
- return ([event modifierFlags] & NSLeftAlternateKeyMask) ==
- NSLeftAlternateKeyMask;
-}
-
-static bool RightAltPressed(NSEvent *event)
-{
- return ([event modifierFlags] & NSRightAlternateKeyMask) ==
- NSRightAlternateKeyMask;
-}
-
-// add methods not available on OSX versions prior to 10.7
-#ifndef MAC_OS_X_VERSION_10_7
-@interface NSView (IntroducedInLion)
-- (NSRect)convertRectToBacking:(NSRect)aRect;
-- (void)setWantsBestResolutionOpenGLSurface:(BOOL)aBool;
-@end
-@interface NSEvent (IntroducedInLion)
-- (BOOL)hasPreciseScrollingDeltas;
-@end
-#endif
-
-// add power management assertion not available on OSX versions prior to 10.7
-#ifndef kIOPMAssertionTypePreventUserIdleDisplaySleep
-#define kIOPMAssertionTypePreventUserIdleDisplaySleep \
- CFSTR("PreventUserIdleDisplaySleep")
-#endif
-
-@interface GLMPlayerWindow : NSWindow <NSWindowDelegate> {
- struct vo *_vo;
-}
-- (void)setVideoOutput:(struct vo *)vo;
+@interface GLMPlayerWindow : NSWindow <NSWindowDelegate>
- (BOOL)canBecomeKeyWindow;
- (BOOL)canBecomeMainWindow;
- (void)fullscreen;
-- (void)mouseEvent:(NSEvent *)theEvent;
- (void)mulSize:(float)multiplier;
- (int)titleHeight;
- (NSRect)clipFrame:(NSRect)frame withContentAspect:(NSSize) aspect;
- (void)setContentSize:(NSSize)newSize keepCentered:(BOOL)keepCentered;
+@property(nonatomic, assign) struct vo *videoOutput;
@end
@interface GLMPlayerOpenGLView : NSView
+@property(nonatomic, assign) struct vo *videoOutput;
+- (BOOL)containsCurrentMouseLocation;
+- (void)mouseEvent:(NSEvent *)theEvent;
+@property(nonatomic, assign, getter=hasMouseDown) BOOL mouseDown;
+@end
+
+@interface NSScreen (mpvadditions)
+- (BOOL)hasDock;
+- (BOOL)hasMenubar;
@end
struct vo_cocoa_state {
- NSAutoreleasePool *pool;
GLMPlayerWindow *window;
+ GLMPlayerOpenGLView *view;
NSOpenGLContext *glContext;
NSOpenGLPixelFormat *pixelFormat;
NSSize current_video_size;
NSSize previous_video_size;
- NSRect screen_frame;
- NSRect fsscreen_frame;
- NSScreen *screen_handle;
-
- NSInteger windowed_mask;
- NSInteger fullscreen_mask;
-
- NSRect windowed_frame;
-
- NSString *window_title;
+ NSScreen *current_screen;
+ NSScreen *fs_screen;
NSInteger window_level;
- int display_cursor;
- int cursor_timer;
- int vo_cursor_autohide_delay;
+ struct aspect_data aspdat;
bool did_resize;
+ bool did_async_resize;
bool out_fs_resize;
+ bool want_redraw;
IOPMAssertionID power_mgmt_assertion;
CGFloat accumulated_scroll;
-};
-static int _instances = 0;
-
-static void create_menu(void);
+ NSLock *lock;
+ bool enable_resize_redraw;
+ void (*resize_redraw)(struct vo *vo, int w, int h);
+};
static struct vo_cocoa_state *vo_cocoa_init_state(struct vo *vo)
{
struct vo_cocoa_state *s = talloc_ptrtype(vo, s);
*s = (struct vo_cocoa_state){
- .pool = [[NSAutoreleasePool alloc] init],
.did_resize = NO,
+ .did_async_resize = NO,
+ .want_redraw = NO,
.current_video_size = {0,0},
.previous_video_size = {0,0},
- .windowed_mask = NSTitledWindowMask|NSClosableWindowMask|
- NSMiniaturizableWindowMask|NSResizableWindowMask,
- .fullscreen_mask = NSBorderlessWindowMask,
- .windowed_frame = {{0,0},{0,0}},
.out_fs_resize = NO,
- .display_cursor = 1,
- .vo_cursor_autohide_delay = vo->opts->cursor_autohide_delay,
.power_mgmt_assertion = kIOPMNullAssertionID,
.accumulated_scroll = 0,
+ .lock = [[NSLock alloc] init],
+ .enable_resize_redraw = NO,
};
- if (!vo->opts->border) s->windowed_mask = NSBorderlessWindowMask;
return s;
}
-static bool supports_hidpi(NSView *view)
-{
- SEL hdpi_selector = @selector(setWantsBestResolutionOpenGLSurface:);
- return is_osx_version_at_least(10, 7, 0) && view &&
- [view respondsToSelector:hdpi_selector];
-}
-
-bool vo_cocoa_gui_running(void)
+static NSRect to_pixels(struct vo *vo, NSRect frame)
{
- return _instances > 0;
+ struct vo_cocoa_state *s = vo->cocoa;
+ return [s->view convertRectToBacking: frame];
}
void *vo_cocoa_glgetaddr(const char *s)
@@ -197,62 +141,59 @@ static void disable_power_management(struct vo *vo)
{
struct vo_cocoa_state *s = vo->cocoa;
if (s->power_mgmt_assertion) return;
-
- CFStringRef assertion_type = kIOPMAssertionTypeNoDisplaySleep;
- if (is_osx_version_at_least(10, 7, 0))
- assertion_type = kIOPMAssertionTypePreventUserIdleDisplaySleep;
-
- IOPMAssertionCreateWithName(assertion_type, kIOPMAssertionLevelOn,
- CFSTR("io.mpv.power_management"), &s->power_mgmt_assertion);
+ IOPMAssertionCreateWithName(
+ kIOPMAssertionTypePreventUserIdleDisplaySleep,
+ kIOPMAssertionLevelOn,
+ CFSTR("io.mpv.video_playing_back"),
+ &s->power_mgmt_assertion);
}
int vo_cocoa_init(struct vo *vo)
{
vo->cocoa = vo_cocoa_init_state(vo);
- vo->wakeup_period = 0.02;
- _instances++;
-
- NSApplicationLoad();
- NSApp = [NSApplication sharedApplication];
- [NSApp setActivationPolicy: NSApplicationActivationPolicyRegular];
- disable_power_management(vo);
return 1;
}
-void vo_cocoa_uninit(struct vo *vo)
+static void vo_cocoa_set_cursor_visibility(struct vo *vo, bool visible)
{
struct vo_cocoa_state *s = vo->cocoa;
- CGDisplayShowCursor(kCGDirectMainDisplay);
- enable_power_management(vo);
- [NSApp setPresentationOptions:NSApplicationPresentationDefault];
-
- [s->window release];
- s->window = nil;
- [s->glContext release];
- s->glContext = nil;
- [s->pool release];
- s->pool = nil;
- _instances--;
+ if (visible) {
+ // show cursor unconditionally
+ CGDisplayShowCursor(kCGDirectMainDisplay);
+ } else if (vo->opts->fs &&
+ [s->view containsCurrentMouseLocation] &&
+ ![s->view hasMouseDown]) {
+ // only hide cursor if in fullscreen and the video view contains the
+ // mouse location
+ CGDisplayHideCursor(kCGDirectMainDisplay);
+ }
}
-void vo_cocoa_pause(struct vo *vo)
+void vo_cocoa_uninit(struct vo *vo)
{
- enable_power_management(vo);
-}
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ struct vo_cocoa_state *s = vo->cocoa;
+ vo_cocoa_set_cursor_visibility(vo, true);
+ enable_power_management(vo);
+ [NSApp setPresentationOptions:NSApplicationPresentationDefault];
-void vo_cocoa_resume(struct vo *vo)
-{
- disable_power_management(vo);
+ if (vo->opts->fs)
+ [[s->view window] release];
+
+ [s->window release];
+ s->window = nil;
+ [s->glContext release];
+ s->glContext = nil;
+ });
}
-static int current_screen_has_dock_or_menubar(struct vo *vo)
+void vo_cocoa_register_resize_callback(struct vo *vo,
+ void (*cb)(struct vo *vo, int w, int h))
{
struct vo_cocoa_state *s = vo->cocoa;
- NSRect f = s->screen_frame;
- NSRect vf = [s->screen_handle visibleFrame];
- return f.size.height > vf.size.height || f.size.width > vf.size.width;
+ s->resize_redraw = cb;
}
static int get_screen_handle(int identifier, NSWindow *window, NSScreen **screen) {
@@ -281,46 +222,30 @@ static void update_screen_info(struct vo *vo)
{
struct vo_cocoa_state *s = vo->cocoa;
struct mp_vo_opts *opts = vo->opts;
- NSScreen *ws, *fss;
-
- get_screen_handle(opts->screen_id, s->window, &ws);
- s->screen_frame = [ws frame];
-
- get_screen_handle(opts->fsscreen_id, s->window, &fss);
- s->fsscreen_frame = [fss frame];
+ get_screen_handle(opts->screen_id, s->window, &s->current_screen);
+ get_screen_handle(opts->fsscreen_id, s->window, &s->fs_screen);
}
-void vo_cocoa_update_xinerama_info(struct vo *vo)
+static void vo_cocoa_update_screen_info(struct vo *vo)
{
struct vo_cocoa_state *s = vo->cocoa;
struct mp_vo_opts *opts = vo->opts;
update_screen_info(vo);
- aspect_save_screenres(vo, s->screen_frame.size.width,
- s->screen_frame.size.height);
- opts->screenwidth = s->screen_frame.size.width;
- opts->screenheight = s->screen_frame.size.height;
- vo->xinerama_x = s->screen_frame.origin.x;
- vo->xinerama_y = s->screen_frame.origin.y;
-}
-int vo_cocoa_change_attributes(struct vo *vo)
-{
- return 0;
+ NSRect r = [s->current_screen frame];
+
+ aspect_save_screenres(vo, r.size.width, r.size.height);
+ opts->screenwidth = r.size.width;
+ opts->screenheight = r.size.height;
+ vo->xinerama_x = r.origin.x;
+ vo->xinerama_y = r.origin.y;
}
static void resize_window(struct vo *vo)
{
struct vo_cocoa_state *s = vo->cocoa;
- NSView *view = [s->window contentView];
- NSRect frame;
-
- if (supports_hidpi(view)) {
- frame = [view convertRectToBacking: [view frame]];
- } else {
- frame = [view frame];
- }
-
+ NSRect frame = to_pixels(vo, [s->view frame]);
vo->dwidth = frame.size.width;
vo->dheight = frame.size.height;
[s->glContext update];
@@ -335,7 +260,8 @@ static void vo_set_level(struct vo *vo, int ontop)
s->window_level = NSNormalWindowLevel;
}
- [s->window setLevel:s->window_level];
+ [[s->view window] setLevel:s->window_level];
+ [s->window setLevel:s->window_level];
}
void vo_cocoa_ontop(struct vo *vo)
@@ -353,87 +279,145 @@ static void update_state_sizes(struct vo_cocoa_state *s,
s->current_video_size = NSMakeSize(d_width, d_height);
}
-static int create_window(struct vo *vo, uint32_t d_width, uint32_t d_height,
- uint32_t flags, int gl3profile)
+static void resize_window_from_stored_size(struct vo *vo)
+{
+ struct vo_cocoa_state *s = vo->cocoa;
+ [s->window setContentSize:s->current_video_size keepCentered:YES];
+ [s->window setContentAspectRatio:s->current_video_size];
+}
+
+static void create_window(struct vo *vo, uint32_t d_width, uint32_t d_height,
+ uint32_t flags)
{
struct vo_cocoa_state *s = vo->cocoa;
- const NSRect window_rect = NSMakeRect(vo->xinerama_x, vo->xinerama_y,
- d_width, d_height);
- const NSRect glview_rect = NSMakeRect(0, 0, 100, 100);
+ struct mp_vo_opts *opts = vo->opts;
+
+ const NSRect contentRect = NSMakeRect(0, 0, d_width, d_height);
+
+ int window_mask = 0;
+ if (opts->border) {
+ window_mask = NSTitledWindowMask|NSClosableWindowMask|
+ NSMiniaturizableWindowMask|NSResizableWindowMask;
+ } else {
+ window_mask = NSBorderlessWindowMask;
+ }
s->window =
- [[GLMPlayerWindow alloc] initWithContentRect:window_rect
- styleMask:s->windowed_mask
+ [[GLMPlayerWindow alloc] initWithContentRect:contentRect
+ styleMask:window_mask
backing:NSBackingStoreBuffered
defer:NO];
- GLMPlayerOpenGLView *glView =
- [[GLMPlayerOpenGLView alloc] initWithFrame:glview_rect];
+ s->view = [[GLMPlayerOpenGLView alloc] initWithFrame:contentRect];
+ [s->view setWantsBestResolutionOpenGLSurface:YES];
+
+ cocoa_register_menu_item_action(MPM_H_SIZE, @selector(halfSize));
+ cocoa_register_menu_item_action(MPM_N_SIZE, @selector(normalSize));
+ cocoa_register_menu_item_action(MPM_D_SIZE, @selector(doubleSize));
+ cocoa_register_menu_item_action(MPM_MINIMIZE, @selector(performMiniaturize:));
+ cocoa_register_menu_item_action(MPM_ZOOM, @selector(performZoom:));
+
+ [s->window setRestorable:NO];
+ [s->window setContentView:s->view];
+ [s->view release];
+ [s->window setAcceptsMouseMovedEvents:YES];
+ [s->glContext setView:s->view];
+ s->window.videoOutput = vo;
+ s->view.videoOutput = vo;
+
+ [s->window setDelegate:s->window];
+ [s->window makeMainWindow];
+
+ [s->window setFrameOrigin:NSMakePoint(vo->dx, vo->dy)];
+ [s->window makeKeyAndOrderFront:nil];
+ [NSApp activateIgnoringOtherApps:YES];
+
+ if (flags & VOFLAG_FULLSCREEN)
+ vo_cocoa_fullscreen(vo);
- // check for HiDPI support and enable it (available on 10.7 +)
- if (supports_hidpi(glView))
- [glView setWantsBestResolutionOpenGLSurface:YES];
+ vo_set_level(vo, opts->ontop);
- int i = 0;
- NSOpenGLPixelFormatAttribute attr[32];
- if (is_osx_version_at_least(10, 7, 0)) {
- attr[i++] = NSOpenGLPFAOpenGLProfile;
- if (gl3profile) {
- attr[i++] = NSOpenGLProfileVersion3_2Core;
- } else {
- attr[i++] = NSOpenGLProfileVersionLegacy;
- }
+ if (opts->native_fs) {
+ [s->window setCollectionBehavior:
+ NSWindowCollectionBehaviorFullScreenPrimary];
+ [NSApp setPresentationOptions:NSFullScreenWindowMask];
}
- attr[i++] = NSOpenGLPFADoubleBuffer; // double buffered
- attr[i] = (NSOpenGLPixelFormatAttribute)0;
+}
+
+static NSOpenGLPixelFormatAttribute get_nsopengl_profile(int gl3profile) {
+ if (gl3profile) {
+ return NSOpenGLProfileVersion3_2Core;
+ } else {
+ return NSOpenGLProfileVersionLegacy;
+ }
+}
+
+static int create_gl_context(struct vo *vo, int gl3profile)
+{
+ struct vo_cocoa_state *s = vo->cocoa;
+
+ NSOpenGLPixelFormatAttribute attr[] = {
+ NSOpenGLPFAOpenGLProfile,
+ get_nsopengl_profile(gl3profile),
+ NSOpenGLPFADoubleBuffer,
+ 0
+ };
s->pixelFormat =
[[[NSOpenGLPixelFormat alloc] initWithAttributes:attr] autorelease];
+
if (!s->pixelFormat) {
mp_msg(MSGT_VO, MSGL_ERR,
- "[cocoa] Invalid pixel format attribute "
- "(GL3 not supported?)\n");
+ "[cocoa] Trying to build invalid OpenGL pixel format\n");
return -1;
}
+
s->glContext =
[[NSOpenGLContext alloc] initWithFormat:s->pixelFormat
shareContext:nil];
- create_menu();
-
- [s->window setContentView:glView];
- [glView release];
- [s->window setAcceptsMouseMovedEvents:YES];
- [s->glContext setView:glView];
[s->glContext makeCurrentContext];
- [s->window setVideoOutput:vo];
-
- [NSApp setDelegate:s->window];
- [s->window setDelegate:s->window];
-
- [s->window setContentSize:s->current_video_size keepCentered:YES];
- [s->window setContentAspectRatio:s->current_video_size];
return 0;
}
+static void cocoa_set_window_title(struct vo *vo, const char *title)
+{
+ struct vo_cocoa_state *s = vo->cocoa;
+ [s->window setTitle: [NSString stringWithUTF8String:title]];
+}
+
static void update_window(struct vo *vo)
{
struct vo_cocoa_state *s = vo->cocoa;
- if (s->current_video_size.width != s->previous_video_size.width ||
- s->current_video_size.height != s->previous_video_size.height) {
+ if (!CGSizeEqualToSize(s->current_video_size, s->previous_video_size)) {
if (vo->opts->fs) {
// we will resize as soon as we get out of fullscreen
s->out_fs_resize = YES;
} else {
// only if we are not in fullscreen and the video size did
// change we resize the window and set a new aspect ratio
- [s->window setContentSize:s->current_video_size
- keepCentered:YES];
- [s->window setContentAspectRatio:s->current_video_size];
+ resize_window_from_stored_size(vo);
}
}
+
+ cocoa_set_window_title(vo, vo_get_window_title(vo));
+
+ resize_window(vo);
+}
+
+static void resize_redraw(struct vo *vo, int width, int height)
+{
+ struct vo_cocoa_state *s = vo->cocoa;
+ if (s->resize_redraw) {
+ vo_cocoa_set_current_context(vo, true);
+ [s->glContext update];
+ s->resize_redraw(vo, width, height);
+ [s->glContext flushBuffer];
+ s->did_async_resize = YES;
+ vo_cocoa_set_current_context(vo, false);
+ }
}
int vo_cocoa_config_window(struct vo *vo, uint32_t d_width,
@@ -441,116 +425,153 @@ int vo_cocoa_config_window(struct vo *vo, uint32_t d_width,
int gl3profile)
{
struct vo_cocoa_state *s = vo->cocoa;
- struct mp_vo_opts *opts = vo->opts;
-
- if (vo->config_count > 0) {
- NSPoint origin = [s->window frame].origin;
- vo->dx = origin.x;
- vo->dy = origin.y;
- }
-
- update_state_sizes(s, d_width, d_height);
-
- if (!(s->window || s->glContext)) {
- if (create_window(vo, d_width, d_height, flags, gl3profile) < 0)
- return -1;
- } else {
- update_window(vo);
- }
-
- [s->window setFrameOrigin:NSMakePoint(vo->dx, vo->dy)];
-
- if (flags & VOFLAG_HIDDEN) {
- [s->window orderOut:nil];
- } else {
- [s->window makeKeyAndOrderFront:nil];
- [NSApp activateIgnoringOtherApps:YES];
- }
-
- if (flags & VOFLAG_FULLSCREEN && !vo->opts->fs)
- vo_cocoa_fullscreen(vo);
-
- vo_set_level(vo, opts->ontop);
+ __block int ctxok = 0;
+ s->enable_resize_redraw = NO;
+
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ s->aspdat = vo->aspdat;
+ update_state_sizes(s, d_width, d_height);
+
+ if (flags & VOFLAG_HIDDEN) {
+ // This is certainly the first execution of vo_config_window and
+ // is called in order for an OpenGL based VO to perform detection
+ // of OpenGL extensions. On OSX to accomplish this task we are
+ // allowed only create a OpenGL context without attaching it to
+ // a drawable.
+ ctxok = create_gl_context(vo, gl3profile);
+ if (ctxok < 0) return;
+ } else if (!s->glContext || !s->window) {
+ // Either glContext+Window or Window alone are not created.
+ // Handle each of them independently. This is to handle correctly
+ // both VOs like vo_corevideo who skip the the OpenGL detection
+ // phase completly and generic OpenGL VOs who use VOFLAG_HIDDEN.
+ if (!s->glContext) {
+ ctxok = create_gl_context(vo, gl3profile);
+ if (ctxok < 0) return;
+ }
+
+ if (!s->window)
+ create_window(vo, d_width, d_height, flags);
+ }
- resize_window(vo);
+ if (s->window) {
+ // Everything is properly initialized
+ update_window(vo);
+ }
+ });
- if (s->window_title)
- [s->window_title release];
+ if (ctxok < 0)
+ return ctxok;
- s->window_title =
- [[NSString alloc] initWithUTF8String:vo_get_window_title(vo)];
- [s->window setTitle: s->window_title];
+ [vo->cocoa->glContext makeCurrentContext];
+ s->enable_resize_redraw = YES;
return 0;
}
-void vo_cocoa_swap_buffers(struct vo *vo)
+static bool resize_callback_registered(struct vo *vo)
{
struct vo_cocoa_state *s = vo->cocoa;
- [s->glContext flushBuffer];
+ return s->enable_resize_redraw && !!s->resize_redraw;
}
-static void vo_cocoa_display_cursor(struct vo *vo, int requested_state)
+void vo_cocoa_set_current_context(struct vo *vo, bool current)
{
struct vo_cocoa_state *s = vo->cocoa;
- if (requested_state) {
- if (!vo->opts->fs || s->vo_cursor_autohide_delay > -2) {
- s->display_cursor = requested_state;
- CGDisplayShowCursor(kCGDirectMainDisplay);
- }
+ if (current) {
+ [s->lock lock];
+ [s->glContext makeCurrentContext];
} else {
- if (s->vo_cursor_autohide_delay != -1) {
- s->display_cursor = requested_state;
- CGDisplayHideCursor(kCGDirectMainDisplay);
- }
+ [NSOpenGLContext clearCurrentContext];
+ [s->lock unlock];
}
}
-int vo_cocoa_check_events(struct vo *vo)
+void vo_cocoa_swap_buffers(struct vo *vo)
{
struct vo_cocoa_state *s = vo->cocoa;
-
- int ms_time = (int) ([[NSProcessInfo processInfo] systemUptime] * 1000);
-
- // automatically hide mouse cursor
- if (vo->opts->fs && s->display_cursor &&
- (ms_time - s->cursor_timer >= s->vo_cursor_autohide_delay)) {
- vo_cocoa_display_cursor(vo, 0);
- s->cursor_timer = ms_time;
+ if (s->did_async_resize && resize_callback_registered(vo)) {
+