summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/context_cocoa.c
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2023-11-10 14:34:29 +0100
committerder richter <der.richter@gmx.de>2023-11-10 14:54:37 +0100
commitfc4db187d0ac538cb5cd9fcd7120f4ee25df4690 (patch)
tree8de56871992d2d757d23874d888caf74345af438 /video/out/opengl/context_cocoa.c
parenta54cc02341fed3e1e2408a692aa4753718ee969f (diff)
downloadmpv-fc4db187d0ac538cb5cd9fcd7120f4ee25df4690.tar.bz2
mpv-fc4db187d0ac538cb5cd9fcd7120f4ee25df4690.tar.xz
cocoa: remove OpenGL cocoa backend
the OpenGL cocoa backend was deprecated in 0.29, it has lot of bugs, is completely unmaintained and can't properly playback anything anymore on the newest macOS. it is time to remove it.
Diffstat (limited to 'video/out/opengl/context_cocoa.c')
-rw-r--r--video/out/opengl/context_cocoa.c209
1 files changed, 0 insertions, 209 deletions
diff --git a/video/out/opengl/context_cocoa.c b/video/out/opengl/context_cocoa.c
deleted file mode 100644
index ec8ec27458..0000000000
--- a/video/out/opengl/context_cocoa.c
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * This file is part of mpv.
- *
- * mpv is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * mpv is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <OpenGL/OpenGL.h>
-#include <dlfcn.h>
-#include "options/m_config.h"
-#include "video/out/cocoa_common.h"
-#include "context.h"
-#include "osdep/macosx_application.h"
-
-struct priv {
- GL gl;
- void (GLAPIENTRY *Flush)(void);
- CGLPixelFormatObj pix;
- CGLContextObj ctx;
-
- struct macos_opts *macos_opts;
-};
-
-static int set_swap_interval(int enabled)
-{
- CGLContextObj ctx = CGLGetCurrentContext();
- CGLError err = CGLSetParameter(ctx, kCGLCPSwapInterval, &enabled);
- return (err == kCGLNoError) ? 0 : -1;
-}
-
-static void glFlushDummy(void) { }
-
-static void *cocoa_glgetaddr(const char *s)
-{
- void *ret = NULL;
- void *handle = dlopen(
- "/System/Library/Frameworks/OpenGL.framework/OpenGL",
- RTLD_LAZY | RTLD_LOCAL);
- if (!handle)
- return NULL;
- ret = dlsym(handle, s);
- dlclose(handle);
- return ret;
-}
-
-static CGLError test_gl_version(struct ra_ctx *ctx, CGLOpenGLProfile ver)
-{
- struct priv *p = ctx->priv;
-
- CGLPixelFormatAttribute attrs[] = {
- // let this array ordered by the inverse order of the most probably
- // rejected attribute to preserve the fallback code
- kCGLPFAOpenGLProfile,
- (CGLPixelFormatAttribute) ver,
- kCGLPFAAccelerated,
- kCGLPFAAllowOfflineRenderers,
- // keep this one last to apply the cocoa-force-dedicated-gpu option
- kCGLPFASupportsAutomaticGraphicsSwitching,
- 0
- };
-
- GLint npix;
- CGLError err;
- int supported_attribute = MP_ARRAY_SIZE(attrs)-1;
-
- if (p->macos_opts->macos_force_dedicated_gpu)
- attrs[--supported_attribute] = 0;
-
- err = CGLChoosePixelFormat(attrs, &p->pix, &npix);
- while (err == kCGLBadAttribute && supported_attribute > 3) {
- // kCGLPFASupportsAutomaticGraphicsSwitching is probably not
- // supported by the current hardware. Falling back to not using
- // it and disallowing Offline Renderers if further restrictions
- // apply
- attrs[--supported_attribute] = 0;
- err = CGLChoosePixelFormat(attrs, &p->pix, &npix);
- }
-
- if (err != kCGLNoError) {
- MP_ERR(ctx->vo, "error creating CGL pixel format: %s (%d)\n",
- CGLErrorString(err), err);
- goto error_out;
- }
-
- err = CGLCreateContext(p->pix, 0, &p->ctx);
-
-error_out:
- return err;
-}
-
-static bool create_gl_context(struct ra_ctx *ctx)
-{
- struct priv *p = ctx->priv;
- GL *gl = &p->gl;
- CGLError err;
-
- CGLOpenGLProfile gl_versions[] = {
- kCGLOGLPVersion_3_2_Core,
- kCGLOGLPVersion_Legacy,
- };
-
- for (int n = 0; n < MP_ARRAY_SIZE(gl_versions); n++) {
- err = test_gl_version(ctx, gl_versions[n]);
- if (err == kCGLNoError)
- break;
- }
-
- if (err != kCGLNoError) {
- MP_FATAL(ctx->vo, "error creating CGL context: %s (%d)\n",
- CGLErrorString(err), err);
- return false;
- }
-
- vo_cocoa_set_opengl_ctx(ctx->vo, p->ctx);
- CGLSetCurrentContext(p->ctx);
-
- if (ctx->opts.want_alpha)
- CGLSetParameter(p->ctx, kCGLCPSurfaceOpacity, &(GLint){0});
-
- mpgl_load_functions(gl, (void *)cocoa_glgetaddr, NULL, ctx->vo->log);
- gl->SwapInterval = set_swap_interval;
- p->Flush = gl->Flush;
- gl->Flush = glFlushDummy;
-
- CGLReleasePixelFormat(p->pix);
-
- return true;
-}
-
-static void cocoa_uninit(struct ra_ctx *ctx)
-{
- struct priv *p = ctx->priv;
- ra_gl_ctx_uninit(ctx);
- CGLReleaseContext(p->ctx);
- vo_cocoa_uninit(ctx->vo);
-}
-
-static void cocoa_swap_buffers(struct ra_ctx *ctx)
-{
- struct priv *p = ctx->priv;
- vo_cocoa_swap_buffers(ctx->vo);
- p->Flush();
-}
-
-static bool cocoa_init(struct ra_ctx *ctx)
-{
- struct priv *p = ctx->priv = talloc_zero(ctx, struct priv);
- GL *gl = &p->gl;
- p->macos_opts = mp_get_config_group(ctx, ctx->global, &macos_conf);
- vo_cocoa_init(ctx->vo);
-
- MP_WARN(ctx->vo, "opengl cocoa backend is deprecated, use vo=libmpv instead\n");
-
- if (!create_gl_context(ctx))
- goto fail;
-
- struct ra_gl_ctx_params params = {
- .swap_buffers = cocoa_swap_buffers,
- };
-
- if (!ra_gl_ctx_init(ctx, gl, params))
- goto fail;
-
- return true;
-
-fail:
- cocoa_uninit(ctx);
- return false;
-}
-
-static void resize(struct ra_ctx *ctx)
-{
- ra_gl_ctx_resize(ctx->swapchain, ctx->vo->dwidth, ctx->vo->dheight, 0);
-}
-
-static bool cocoa_reconfig(struct ra_ctx *ctx)
-{
- vo_cocoa_config_window(ctx->vo);
- resize(ctx);
- return true;
-}
-
-static int cocoa_control(struct ra_ctx *ctx, int *events, int request,
- void *arg)
-{
- int ret = vo_cocoa_control(ctx->vo, events, request, arg);
- if (*events & VO_EVENT_RESIZE)
- resize(ctx);
- return ret;
-}
-
-const struct ra_ctx_fns ra_ctx_cocoa = {
- .type = "opengl",
- .name = "cocoa",
- .init = cocoa_init,
- .reconfig = cocoa_reconfig,
- .control = cocoa_control,
- .uninit = cocoa_uninit,
-};