summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2024-02-25 23:59:11 +0100
committerder richter <der.richter@gmx.de>2024-02-27 14:01:38 +0100
commita7c4a113b82dc57641c08e1da5c3df9acb704be4 (patch)
tree7c2937343e2345a9050a320c868195c85f5ed437 /osdep
parent3dcc661de7e884e147965615749965df5f80a443 (diff)
downloadmpv-a7c4a113b82dc57641c08e1da5c3df9acb704be4.tar.bz2
mpv-a7c4a113b82dc57641c08e1da5c3df9acb704be4.tar.xz
cocoa-cb: remove pre-allocation and initialise only when used
cocoa-cb was always pre-allocated in the Application itself because libmpv needs to be set up before usage, an opengl context has to be set and because it was decided mac specific code should be kept out of libmpv. this means that a completely working libmpv and opengl renderer was set up even if it wasn't used. leading to unnecessary log message, resources being used or reserved on the system that might not be used, triggering of dedicated GPU unnecessarily and many other things. even if not optimal, this wasn't the biggest problem since we only had that one working vo on macOS. though now that we have a vulkan gpu(-next) backend on macOS that was made the default, we always have that dangling cocoa-cb instance, which is completely unnecessary. move the cocoa-cb initialisation into libmpv preinit function and only init cocoa-cb when we are a standalone App and cocoa-cb support is build into.
Diffstat (limited to 'osdep')
-rw-r--r--osdep/macosx_application.m6
-rw-r--r--osdep/macosx_application_objc.h2
-rw-r--r--osdep/macosx_events.h1
-rw-r--r--osdep/macosx_events.m24
4 files changed, 24 insertions, 9 deletions
diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m
index 1a1c6aefc0..c9ccd48033 100644
--- a/osdep/macosx_application.m
+++ b/osdep/macosx_application.m
@@ -183,10 +183,12 @@ static const char macosx_icon[] =
}
}
-- (void)setMpvHandle:(struct mpv_handle *)ctx
+- (void)initCocoaCb:(struct mpv_handle *)ctx
{
#if HAVE_MACOS_COCOA_CB
- [NSApp setCocoaCB:[[CocoaCB alloc] init:ctx]];
+ if (!_cocoa_cb) {
+ [NSApp setCocoaCB:[[CocoaCB alloc] init:ctx]];
+ }
#endif
}
diff --git a/osdep/macosx_application_objc.h b/osdep/macosx_application_objc.h
index fab968dba8..da8c73268b 100644
--- a/osdep/macosx_application_objc.h
+++ b/osdep/macosx_application_objc.h
@@ -30,7 +30,7 @@ struct mpv_handle;
- (void)queueCommand:(char *)cmd;
- (void)stopMPV:(char *)cmd;
- (void)openFiles:(NSArray *)filenames;
-- (void)setMpvHandle:(struct mpv_handle *)ctx;
+- (void)initCocoaCb:(struct mpv_handle *)ctx;
+ (const struct m_sub_options *)getMacOSConf;
+ (const struct m_sub_options *)getVoSubConf;
diff --git a/osdep/macosx_events.h b/osdep/macosx_events.h
index 9188c8bee2..79f2705a2e 100644
--- a/osdep/macosx_events.h
+++ b/osdep/macosx_events.h
@@ -32,5 +32,6 @@ void cocoa_uninit_media_keys(void);
void cocoa_set_input_context(struct input_ctx *input_context);
void cocoa_set_mpv_handle(struct mpv_handle *ctx);
+void cocoa_init_cocoa_cb(void);
#endif
diff --git a/osdep/macosx_events.m b/osdep/macosx_events.m
index 0b9c7e79f1..1b041cdb09 100644
--- a/osdep/macosx_events.m
+++ b/osdep/macosx_events.m
@@ -52,6 +52,7 @@
- (NSEvent *)handleKey:(NSEvent *)event;
- (BOOL)setMpvHandle:(struct mpv_handle *)ctx;
+- (void)initCocoaCb;
- (void)readEvents;
- (void)startMediaKeys;
- (void)stopMediaKeys;
@@ -166,6 +167,11 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx)
}
}
+void cocoa_init_cocoa_cb(void)
+{
+ [[EventsResponder sharedInstance] initCocoaCb];
+}
+
@implementation EventsResponder
@synthesize remoteCommandCenter = _remoteCommandCenter;
@@ -252,14 +258,20 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx)
- (BOOL)setMpvHandle:(struct mpv_handle *)ctx
{
if (_is_application) {
+ _ctx = ctx;
+ return YES;
+ }
+
+ mpv_destroy(ctx);
+ return NO;
+}
+
+- (void)initCocoaCb
+{
+ if (_is_application) {
dispatch_sync(dispatch_get_main_queue(), ^{
- _ctx = ctx;
- [NSApp setMpvHandle:ctx];
+ [NSApp initCocoaCb:_ctx];
});
- return YES;
- } else {
- mpv_destroy(ctx);
- return NO;
}
}