diff options
author | James Ross-Gowan <rossy@jrg.systems> | 2017-09-16 01:37:28 +1000 |
---|---|---|
committer | Niklas Haas <git@haasn.xyz> | 2017-09-21 15:01:17 +0200 |
commit | 75c0c06640da677477a0cfd08deee1d4e23a4361 (patch) | |
tree | 2053c8bf0097c3fc5142799cad67d49ecce981b1 /video/out/opengl/context_cocoa.c | |
parent | 65979986a923a8f08019b257c3fe72cd5e8ecf68 (diff) | |
download | mpv-75c0c06640da677477a0cfd08deee1d4e23a4361.tar.bz2 mpv-75c0c06640da677477a0cfd08deee1d4e23a4361.tar.xz |
vo_gpu: convert windows/osx hwdecs/contexts to new API
Diffstat (limited to 'video/out/opengl/context_cocoa.c')
-rw-r--r-- | video/out/opengl/context_cocoa.c | 70 |
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, }; |