diff options
author | Niklas Haas <git@haasn.xyz> | 2017-09-14 08:04:55 +0200 |
---|---|---|
committer | Niklas Haas <git@haasn.xyz> | 2017-09-21 15:00:55 +0200 |
commit | 65979986a923a8f08019b257c3fe72cd5e8ecf68 (patch) | |
tree | b8f4b8c17d583594aef0ca509064f8b2ff7128d4 /video/out/vo_opengl_cb.c | |
parent | 20f958c9775652c3213588c2a0824f5353276adc (diff) | |
download | mpv-65979986a923a8f08019b257c3fe72cd5e8ecf68.tar.bz2 mpv-65979986a923a8f08019b257c3fe72cd5e8ecf68.tar.xz |
vo_opengl: refactor into vo_gpu
This is done in several steps:
1. refactor MPGLContext -> struct ra_ctx
2. move GL-specific stuff in vo_opengl into opengl/context.c
3. generalize context creation to support other APIs, and add --gpu-api
4. rename all of the --opengl- options that are no longer opengl-specific
5. move all of the stuff from opengl/* that isn't GL-specific into gpu/
(note: opengl/gl_utils.h became opengl/utils.h)
6. rename vo_opengl to vo_gpu
7. to handle window screenshots, the short-term approach was to just add
it to ra_swchain_fns. Long term (and for vulkan) this has to be moved to
ra itself (and vo_gpu altered to compensate), but this was a stop-gap
measure to prevent this commit from getting too big
8. move ra->fns->flush to ra_gl_ctx instead
9. some other minor changes that I've probably already forgotten
Note: This is one half of a major refactor, the other half of which is
provided by rossy's following commit. This commit enables support for
all linux platforms, while his version enables support for all non-linux
platforms.
Note 2: vo_opengl_cb.c also re-uses ra_gl_ctx so it benefits from the
--opengl- options like --opengl-early-flush, --opengl-finish etc. Should
be a strict superset of the old functionality.
Disclaimer: Since I have no way of compiling mpv on all platforms, some
of these ports were done blindly. Specifically, the blind ports included
context_mali_fbdev.c and context_rpi.c. Since they're both based on
egl_helpers, the port should have gone smoothly without any major
changes required. But if somebody complains about a compile error on
those platforms (assuming anybody actually uses them), you know where to
complain.
Diffstat (limited to 'video/out/vo_opengl_cb.c')
-rw-r--r-- | video/out/vo_opengl_cb.c | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/video/out/vo_opengl_cb.c b/video/out/vo_opengl_cb.c index ea6aaa9048..7e95e8bd31 100644 --- a/video/out/vo_opengl_cb.c +++ b/video/out/vo_opengl_cb.c @@ -24,9 +24,10 @@ #include "common/global.h" #include "player/client.h" +#include "gpu/video.h" +#include "gpu/hwdec.h" #include "opengl/common.h" -#include "opengl/video.h" -#include "opengl/hwdec.h" +#include "opengl/context.h" #include "opengl/ra_gl.h" #include "libmpv/opengl_cb.h" @@ -86,7 +87,7 @@ struct mpv_opengl_cb_context { // application's OpenGL context is current - i.e. only while the // host application is calling certain mpv_opengl_cb_* APIs. GL *gl; - struct ra *ra; + struct ra_ctx *ra_ctx; struct gl_video *renderer; struct ra_hwdec *hwdec; struct m_config_cache *vo_opts_cache; @@ -171,16 +172,36 @@ int mpv_opengl_cb_init_gl(struct mpv_opengl_cb_context *ctx, const char *exts, return MPV_ERROR_UNSUPPORTED; } - ctx->ra = ra_create_gl(ctx->gl, ctx->log); - if (!ctx->ra) + // initialize a blank ra_ctx to reuse ra_gl_ctx + ctx->ra_ctx = talloc_zero(ctx, struct ra_ctx); + ctx->ra_ctx->log = ctx->log; + ctx->ra_ctx->global = ctx->global; + ctx->ra_ctx->opts = (struct ra_ctx_opts) { + .probing = false, + .allow_sw = true, + }; + + static const struct ra_swapchain_fns empty_swapchain_fns = {0}; + struct ra_gl_ctx_params gl_params = { + // vo_opengl_cb is essentially like a gigantic external swapchain where + // the user is in charge of presentation / swapping etc. But we don't + // actually need to provide any of these functions, since we can just + // not call them to begin with - so just set it to an empty object to + // signal to ra_gl_ctx that we don't care about its latency emulation + // functionality + .external_swapchain = &empty_swapchain_fns + }; + + ctx->gl->SwapInterval = NULL; // we shouldn't randomly change this, so lock it + if (!ra_gl_ctx_init(ctx->ra_ctx, ctx->gl, gl_params)) return MPV_ERROR_UNSUPPORTED; - ctx->renderer = gl_video_init(ctx->ra, ctx->log, ctx->global); + ctx->renderer = gl_video_init(ctx->ra_ctx->ra, ctx->log, ctx->global); m_config_cache_update(ctx->vo_opts_cache); ctx->hwdec_devs = hwdec_devices_create(); - ctx->hwdec = ra_hwdec_load(ctx->log, ctx->ra, ctx->global, + ctx->hwdec = ra_hwdec_load(ctx->log, ctx->ra_ctx->ra, ctx->global, ctx->hwdec_devs, ctx->vo_opts->gl_hwdec_interop); gl_video_set_hwdec(ctx->renderer, ctx->hwdec); @@ -221,7 +242,7 @@ int mpv_opengl_cb_uninit_gl(struct mpv_opengl_cb_context *ctx) ctx->hwdec = NULL; hwdec_devices_destroy(ctx->hwdec_devs); ctx->hwdec_devs = NULL; - ra_free(&ctx->ra); + ra_ctx_destroy(&ctx->ra_ctx); talloc_free(ctx->gl); ctx->gl = NULL; return 0; @@ -236,11 +257,6 @@ int mpv_opengl_cb_draw(mpv_opengl_cb_context *ctx, int fbo, int vp_w, int vp_h) return MPV_ERROR_UNSUPPORTED; } - struct fbodst target = { - .tex = ra_create_wrapped_fb(ctx->ra, fbo, vp_w, abs(vp_h)), - .flip = vp_h < 0, - }; - reset_gl_state(ctx->gl); pthread_mutex_lock(&ctx->lock); @@ -280,7 +296,7 @@ int mpv_opengl_cb_draw(mpv_opengl_cb_context *ctx, int fbo, int vp_w, int vp_h) mp_read_option_raw(ctx->global, "opengl-debug", &m_option_type_flag, &debug); ctx->gl->debug_context = debug; - ra_gl_set_debug(ctx->ra, debug); + ra_gl_set_debug(ctx->ra_ctx->ra, debug); if (gl_video_icc_auto_enabled(ctx->renderer)) MP_ERR(ctx, "icc-profile-auto is not available with opengl-cb\n"); } @@ -316,7 +332,14 @@ int mpv_opengl_cb_draw(mpv_opengl_cb_context *ctx, int fbo, int vp_w, int vp_h) pthread_mutex_unlock(&ctx->lock); MP_STATS(ctx, "glcb-render"); + struct ra_swapchain *sw = ctx->ra_ctx->swapchain; + ra_gl_ctx_resize(sw, vp_w, abs(vp_h), fbo); + struct fbodst target = { + .tex = ra_gl_ctx_start_frame(sw), + .flip = vp_h < 0, + }; gl_video_render_frame(ctx->renderer, frame, target); + ra_gl_ctx_submit_frame(sw, frame); reset_gl_state(ctx->gl); @@ -328,8 +351,6 @@ int mpv_opengl_cb_draw(mpv_opengl_cb_context *ctx, int fbo, int vp_w, int vp_h) pthread_cond_wait(&ctx->wakeup, &ctx->lock); pthread_mutex_unlock(&ctx->lock); - ra_tex_free(ctx->ra, &target.tex); - return 0; } |