From 5865086aa84cae5e5505698ccf115a53a1b6b4fa Mon Sep 17 00:00:00 2001 From: Akemi Date: Wed, 6 Jun 2018 17:04:40 +0200 Subject: 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. --- osdep/macosx_application.m | 70 ++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 40 deletions(-) (limited to 'osdep/macosx_application.m') 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 -- cgit v1.2.3