summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorAkemi <der.richter@gmx.de>2018-06-06 17:04:40 +0200
committerJan Ekström <jeebjp@gmail.com>2018-06-12 01:51:01 +0300
commit5865086aa84cae5e5505698ccf115a53a1b6b4fa (patch)
tree416b5ce30ae4c4d35af4130aa1956757fb6252ff /osdep
parent20dffe0621b3e26674850ef0b46ba3e689931d87 (diff)
downloadmpv-5865086aa84cae5e5505698ccf115a53a1b6b4fa.tar.bz2
mpv-5865086aa84cae5e5505698ccf115a53a1b6b4fa.tar.xz
cocoa-cb: remove pre-allocation of window, view and layer
the pre-allocation was needed because the layer allocated a opengl context async itself and we couldn't influence that. so we had to start the core after the context was actually allocated. furthermore a window, view and layer hierarchy had to be created so the layer would create a context. now, instead of relying on the layer to create a context we do this manually and re-use that context later when the layer wants to create one async itself.
Diffstat (limited to 'osdep')
-rw-r--r--osdep/macOS_mpv_helper.swift7
-rw-r--r--osdep/macOS_swift_bridge.h1
-rw-r--r--osdep/macosx_application.h5
-rw-r--r--osdep/macosx_application.m70
-rw-r--r--osdep/macosx_application_objc.h2
5 files changed, 44 insertions, 41 deletions
diff --git a/osdep/macOS_mpv_helper.swift b/osdep/macOS_mpv_helper.swift
index b023c4f098..e1fb3cf6cb 100644
--- a/osdep/macOS_mpv_helper.swift
+++ b/osdep/macOS_mpv_helper.swift
@@ -21,6 +21,12 @@ import OpenGL.GL3
let glDummy: @convention(c) () -> Void = {}
+extension Bool {
+ init(_ num: Int32) {
+ self.init(num > 0)
+ }
+}
+
class MPVHelper: NSObject {
var mpvHandle: OpaquePointer?
@@ -28,6 +34,7 @@ class MPVHelper: NSObject {
var mpvLog: OpaquePointer?
var inputContext: OpaquePointer?
var mpctx: UnsafeMutablePointer<MPContext>?
+ var macOpts: macos_opts?
var fbo: GLint = 1
init(_ mpv: OpaquePointer) {
diff --git a/osdep/macOS_swift_bridge.h b/osdep/macOS_swift_bridge.h
index b0121d2a0f..4204b514d1 100644
--- a/osdep/macOS_swift_bridge.h
+++ b/osdep/macOS_swift_bridge.h
@@ -23,6 +23,7 @@
#include "video/out/libmpv.h"
#include "libmpv/render_gl.h"
+#include "options/m_config.h"
#include "player/core.h"
#include "input/input.h"
#include "video/out/win_state.h"
diff --git a/osdep/macosx_application.h b/osdep/macosx_application.h
index 96a861fa35..c04f479c5b 100644
--- a/osdep/macosx_application.h
+++ b/osdep/macosx_application.h
@@ -20,6 +20,11 @@
#include "osdep/macosx_menubar.h"
+struct macos_opts {
+ int macos_title_bar_style;
+ int macos_fs_animation_duration;
+};
+
// multithreaded wrapper for mpv_main
int cocoa_main(int argc, char *argv[]);
void cocoa_register_menu_item_action(MPMenuKey key, void* action);
diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m
index 4bc8eec0eb..66daa45909 100644
--- a/osdep/macosx_application.m
+++ b/osdep/macosx_application.m
@@ -40,11 +40,6 @@
#define MPV_PROTOCOL @"mpv://"
-struct macos_opts {
- int macos_title_bar_style;
- int macos_fs_animation_duration;
-};
-
#define OPT_BASE_STRUCT struct macos_opts
const struct m_sub_options macos_conf = {
.opts = (const struct m_option[]) {
@@ -66,13 +61,7 @@ const struct m_sub_options macos_conf = {
// running in libmpv mode, and cocoa_main() was never called.
static bool application_instantiated;
-struct playback_thread_ctx {
- int *argc;
- char ***argv;
-};
-
static pthread_t playback_thread_id;
-static struct playback_thread_ctx thread_ctx = {0};
@interface Application ()
{
@@ -92,18 +81,6 @@ static void terminate_cocoa_application(void)
[NSApp terminate:NSApp];
}
-static void *playback_thread(void *ctx_obj)
-{
- mpthread_set_name("playback core (OSX)");
- @autoreleasepool {
- struct playback_thread_ctx *ctx = (struct playback_thread_ctx*) ctx_obj;
- int r = mpv_main(*ctx->argc, *ctx->argv);
- terminate_cocoa_application();
- // normally never reached - unless the cocoa mainloop hasn't started yet
- exit(r);
- }
-}
-
@implementation Application
@synthesize menuBar = _menu_bar;
@synthesize openCount = _open_count;
@@ -141,12 +118,6 @@ static void *playback_thread(void *ctx_obj)
[super dealloc];
}
-- (void)initMPVCore
-{
- pthread_create(&playback_thread_id, NULL, playback_thread, &thread_ctx);
- [[EventsResponder sharedInstance] waitForInputContext];
-}
-
static const char macosx_icon[] =
#include "osdep/macosx_icon.inc"
;
@@ -187,9 +158,14 @@ static const char macosx_icon[] =
- (void)setMpvHandle:(struct mpv_handle *)ctx
{
- if (_cocoa_cb) {
- [_cocoa_cb setMpvHandle:ctx];
- }
+#if HAVE_MACOS_COCOA_CB
+ [NSApp setCocoaCB:[[CocoaCB alloc] init:ctx]];
+#endif
+}
+
+- (const struct m_sub_options *)getMacOSConf
+{
+ return &macos_conf;
}
- (void)queueCommand:(char *)cmd
@@ -255,6 +231,11 @@ static const char macosx_icon[] =
}
@end
+struct playback_thread_ctx {
+ int *argc;
+ char ***argv;
+};
+
static void cocoa_run_runloop(void)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@@ -262,6 +243,18 @@ static void cocoa_run_runloop(void)
[pool drain];
}
+static void *playback_thread(void *ctx_obj)
+{
+ mpthread_set_name("playback core (OSX)");
+ @autoreleasepool {
+ struct playback_thread_ctx *ctx = (struct playback_thread_ctx*) ctx_obj;
+ int r = mpv_main(*ctx->argc, *ctx->argv);
+ terminate_cocoa_application();
+ // normally never reached - unless the cocoa mainloop hasn't started yet
+ exit(r);
+ }
+}
+
void cocoa_register_menu_item_action(MPMenuKey key, void* action)
{
if (application_instantiated)
@@ -274,10 +267,6 @@ static void init_cocoa_application(bool regular)
[NSApp setDelegate:NSApp];
[NSApp setMenuBar:[[MenuBar alloc] init]];
-#if HAVE_MACOS_COCOA_CB
- [NSApp setCocoaCB:[[CocoaCB alloc] init]];
-#endif
-
// Will be set to Regular from cocoa_common during UI creation so that we
// don't create an icon when playing audio only files.
[NSApp setActivationPolicy: regular ?
@@ -339,8 +328,9 @@ int cocoa_main(int argc, char *argv[])
application_instantiated = true;
[[EventsResponder sharedInstance] setIsApplication:YES];
- thread_ctx.argc = &argc;
- thread_ctx.argv = &argv;
+ struct playback_thread_ctx ctx = {0};
+ ctx.argc = &argc;
+ ctx.argv = &argv;
if (bundle_started_from_finder(argv)) {
setup_bundle(&argc, argv);
@@ -353,8 +343,8 @@ int cocoa_main(int argc, char *argv[])
init_cocoa_application(false);
}
- if (![NSApp cocoaCB])
- [NSApp initMPVCore];
+ pthread_create(&playback_thread_id, NULL, playback_thread, &ctx);
+ [[EventsResponder sharedInstance] waitForInputContext];
cocoa_run_runloop();
// This should never be reached: cocoa_run_runloop blocks until the
diff --git a/osdep/macosx_application_objc.h b/osdep/macosx_application_objc.h
index 22e6f7e525..1685c99ba8 100644
--- a/osdep/macosx_application_objc.h
+++ b/osdep/macosx_application_objc.h
@@ -31,7 +31,7 @@ struct mpv_handle;
- (void)stopMPV:(char *)cmd;
- (void)openFiles:(NSArray *)filenames;
- (void)setMpvHandle:(struct mpv_handle *)ctx;
-- (void)initMPVCore;
+- (const struct m_sub_options *)getMacOSConf;
@property(nonatomic, retain) MenuBar *menuBar;
@property(nonatomic, assign) size_t openCount;