path: root/player
diff options
authorAkemi <>2018-02-12 12:28:19 +0100
committerKevin Mitchell <>2018-02-12 04:49:15 -0800
commitc5e4538bc4b63f02bf89f62aa25a37b9eb0c0316 (patch)
tree443f47ce1d584bb5fbf4fa30918e7c17cb800016 /player
parent235eb60671c899d55b1174043940763b250fa3b8 (diff)
cocoa-cb: initial implementation via opengl-cb API
this is meant to replace the old and not properly working vo_gpu/opengl cocoa backend in the future. the problems are various shortcomings of Apple's opengl implementation and buggy behaviour in certain circumstances that couldn't be properly worked around. there are also certain regressions on newer macOS versions from 10.11 onwards. - awful opengl performance with a none layer backed context - huge amount of dropped frames with an early context flush - flickering of system elements like the dock or volume indicator - double buffering not properly working with a none layer backed context - bad performance in fullscreen because of system optimisations all the problems were caused by using a normal opengl context, that seems somewhat abandoned by apple, and are fixed by using a layer backed opengl context instead. problems that couldn't be fixed could be properly worked around. this has all features our old backend has sans the wid embedding, the possibility to disable the automatic GPU switching and taking screenshots of the window content. the first was deemed unnecessary by me for now, since i just use the libmpv API that others can use anyway. second is technically not possible atm because we have to pre-allocate our opengl context at a time the config isn't read yet, so we can't get the needed property. third one is a bit tricky because of deadlocking and it needed to be in sync, hopefully i can work around that in the future. this also has at least one additional feature or eye-candy. a properly working fullscreen animation with the native fs. also since this is a direct port of the old backend of the parts that could be used, though with adaptions and improvements, this looks a lot cleaner and easier to understand. some credit goes to @pigoz for the initial swift build support which i could improve upon. Fixes: #5478, #5393, #5152, #5151, #4615, #4476, #3978, #3746, #3739, #2392, #2217
Diffstat (limited to 'player')
2 files changed, 31 insertions, 3 deletions
diff --git a/player/client.c b/player/client.c
index 618dbc4165..1df7e659d8 100644
--- a/player/client.c
+++ b/player/client.c
@@ -1726,6 +1726,17 @@ int mpv_opengl_cb_uninit_gl(mpv_opengl_cb_context *ctx)
+void mp_client_set_control_callback(struct mpv_opengl_cb_context *ctx,
+ mpv_opengl_cb_control_fn callback,
+ void *callback_ctx)
+void mp_client_set_icc_profile(struct mpv_opengl_cb_context *ctx, bstr icc_data)
+void mp_client_set_ambient_lux(struct mpv_opengl_cb_context *ctx, int lux)
int mpv_opengl_cb_render(mpv_opengl_cb_context *ctx, int fbo, int vp[4])
@@ -1733,22 +1744,29 @@ int mpv_opengl_cb_render(mpv_opengl_cb_context *ctx, int fbo, int vp[4])
return mpv_opengl_cb_draw(ctx, fbo, vp[2], vp[3]);
-void *mpv_get_sub_api(mpv_handle *ctx, mpv_sub_api sub_api)
+void *mp_get_sub_api2(mpv_handle *ctx, mpv_sub_api sub_api, bool lock)
if (!ctx->mpctx->initialized)
return NULL;
void *res = NULL;
- lock_core(ctx);
+ if (lock)
+ lock_core(ctx);
switch (sub_api) {
res = opengl_cb_get_context(ctx);
- unlock_core(ctx);
+ if (lock)
+ unlock_core(ctx);
return res;
+void *mpv_get_sub_api(mpv_handle *ctx, mpv_sub_api sub_api)
+ return mp_get_sub_api2(ctx, sub_api, true);
struct mp_custom_protocol {
char *protocol;
void *user_data;
diff --git a/player/client.h b/player/client.h
index 67b287b67f..042934cde3 100644
--- a/player/client.h
+++ b/player/client.h
@@ -6,6 +6,7 @@
#include "libmpv/client.h"
#include "libmpv/stream_cb.h"
+#include "misc/bstr.h"
struct MPContext;
struct mpv_handle;
@@ -34,6 +35,7 @@ struct mpv_handle *mp_new_client(struct mp_client_api *clients, const char *name
struct mp_log *mp_client_get_log(struct mpv_handle *ctx);
struct MPContext *mp_client_get_core(struct mpv_handle *ctx);
struct MPContext *mp_client_api_get_core(struct mp_client_api *api);
+void *mp_get_sub_api2(mpv_handle *ctx, mpv_sub_api sub_api, bool lock);
// m_option.c
void *node_get_alloc(struct mpv_node *node);
@@ -49,4 +51,12 @@ void kill_video(struct mp_client_api *client_api);
bool mp_streamcb_lookup(struct mpv_global *g, const char *protocol,
void **out_user_data, mpv_stream_cb_open_ro_fn *out_fn);
+typedef int (*mpv_opengl_cb_control_fn)(void *cb_ctx, int *events, uint32_t request, void *data);
+void mp_client_set_control_callback(struct mpv_opengl_cb_context *ctx,
+ mpv_opengl_cb_control_fn callback,
+ void *callback_ctx);
+void mp_client_set_icc_profile(struct mpv_opengl_cb_context *ctx, bstr icc_data);
+void mp_client_set_ambient_lux(struct mpv_opengl_cb_context *ctx, int lux);