summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/context_cocoa.c
diff options
context:
space:
mode:
Diffstat (limited to 'video/out/opengl/context_cocoa.c')
-rw-r--r--video/out/opengl/context_cocoa.c70
1 files changed, 47 insertions, 23 deletions
diff --git a/video/out/opengl/context_cocoa.c b/video/out/opengl/context_cocoa.c
index cdf6faffcd..585c49f9a9 100644
--- a/video/out/opengl/context_cocoa.c
+++ b/video/out/opengl/context_cocoa.c
@@ -36,6 +36,7 @@ const struct m_sub_options cocoa_conf = {
};
struct priv {
+ GL gl;
CGLPixelFormatObj pix;
CGLContextObj ctx;
@@ -62,7 +63,7 @@ static void *cocoa_glgetaddr(const char *s)
return ret;
}
-static CGLError test_gl_version(struct MPGLContext *ctx, CGLOpenGLProfile ver)
+static CGLError test_gl_version(struct ra_ctx *ctx, CGLOpenGLProfile ver)
{
struct priv *p = ctx->priv;
@@ -107,9 +108,10 @@ error_out:
return err;
}
-static bool create_gl_context(struct MPGLContext *ctx, int vo_flags)
+static bool create_gl_context(struct ra_ctx *ctx)
{
struct priv *p = ctx->priv;
+ GL *gl = &p->gl;
CGLError err;
CGLOpenGLProfile gl_versions[] = {
@@ -132,60 +134,82 @@ static bool create_gl_context(struct MPGLContext *ctx, int vo_flags)
vo_cocoa_set_opengl_ctx(ctx->vo, p->ctx);
CGLSetCurrentContext(p->ctx);
- if (vo_flags & VOFLAG_ALPHA)
+ if (ctx->opts.want_alpha)
CGLSetParameter(p->ctx, kCGLCPSurfaceOpacity, &(GLint){0});
- mpgl_load_functions(ctx->gl, (void *)cocoa_glgetaddr, NULL, ctx->vo->log);
+ mpgl_load_functions(gl, (void *)cocoa_glgetaddr, NULL, ctx->vo->log);
+ gl->SwapInterval = set_swap_interval;
CGLReleasePixelFormat(p->pix);
return true;
}
-static void cocoa_uninit(MPGLContext *ctx)
+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 int cocoa_init(MPGLContext *ctx, int vo_flags)
+static void cocoa_swap_buffers(struct ra_ctx *ctx)
{
- struct priv *p = ctx->priv;
+ GL *gl = &p->gl;
+ vo_cocoa_swap_buffers(ctx->vo);
+ gl->Flush();
+}
+
+static bool cocoa_init(struct ra_ctx *ctx)
+{
+ struct priv *p = ctx->priv = talloc_zero(ctx, struct priv);
+ GL *gl = &p->gl;
p->opts = mp_get_config_group(ctx, ctx->global, &cocoa_conf);
vo_cocoa_init(ctx->vo);
- if (!create_gl_context(ctx, vo_flags))
- return -1;
+ if (!create_gl_context(ctx))
+ goto fail;
- ctx->gl->SwapInterval = set_swap_interval;
- return 0;
+ 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 int cocoa_reconfig(struct MPGLContext *ctx)
+static void resize(struct ra_ctx *ctx)
{
- vo_cocoa_config_window(ctx->vo);
- return 0;
+ ra_gl_ctx_resize(ctx->swapchain, ctx->vo->dwidth, ctx->vo->dheight, 0);
}
-static int cocoa_control(struct MPGLContext *ctx, int *events, int request,
- void *arg)
+static bool cocoa_reconfig(struct ra_ctx *ctx)
{
- return vo_cocoa_control(ctx->vo, events, request, arg);
+ vo_cocoa_config_window(ctx->vo);
+ resize(ctx);
+ return true;
}
-static void cocoa_swap_buffers(struct MPGLContext *ctx)
+static int cocoa_control(struct ra_ctx *ctx, int *events, int request,
+ void *arg)
{
- vo_cocoa_swap_buffers(ctx->vo);
- ctx->gl->Flush();
+ int ret = vo_cocoa_control(ctx->vo, events, request, arg);
+ if (*events & VO_EVENT_RESIZE)
+ resize(ctx);
+ return ret;
}
-const struct mpgl_driver mpgl_driver_cocoa = {
+const struct ra_ctx_fns ra_ctx_cocoa = {
+ .type = "opengl",
.name = "cocoa",
- .priv_size = sizeof(struct priv),
.init = cocoa_init,
.reconfig = cocoa_reconfig,
- .swap_buffers = cocoa_swap_buffers,
.control = cocoa_control,
.uninit = cocoa_uninit,
};