diff options
author | sfan5 <sfan5@live.de> | 2021-11-20 20:59:37 +0100 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2021-11-22 18:08:56 +0100 |
commit | d5d62c6a6459412c86bd8d09be248810364a2405 (patch) | |
tree | 9ee6ee69c48286b9acccf3957e2114b705c31b03 /video/out/gpu_next | |
parent | f32ea013dd41a1baa59c1cd696ed29ce21baca99 (diff) | |
download | mpv-d5d62c6a6459412c86bd8d09be248810364a2405.tar.bz2 mpv-d5d62c6a6459412c86bd8d09be248810364a2405.tar.xz |
vo_gpu_next: factor out context-specific code to gpu_next/context.c
This is done to avoid cluttering vo_gpu_next.c with more ifdeffery and context-specific code
when additional backends are added in the near future.
Eventually gpu_ctx is intended to take the place of ra_ctx to further separate gpu and gpu_next.
Diffstat (limited to 'video/out/gpu_next')
-rw-r--r-- | video/out/gpu_next/context.c | 80 | ||||
-rw-r--r-- | video/out/gpu_next/context.h | 41 |
2 files changed, 121 insertions, 0 deletions
diff --git a/video/out/gpu_next/context.c b/video/out/gpu_next/context.c new file mode 100644 index 0000000000..fdf308d7ef --- /dev/null +++ b/video/out/gpu_next/context.c @@ -0,0 +1,80 @@ +/* + * 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 <https://www.gnu.org/licenses/>. + */ + +#include <libplacebo/config.h> + +#include "context.h" +#include "config.h" +#include "common/common.h" +#include "options/m_config.h" +#include "video/out/placebo/utils.h" +#include "video/out/gpu/video.h" + +#if HAVE_VULKAN +#include "video/out/vulkan/context.h" +#endif + +struct priv { + char dummy; +}; + +struct gpu_ctx *gpu_ctx_create(struct vo *vo, struct gl_video_opts *gl_opts) +{ + struct gpu_ctx *ctx = talloc_zero(NULL, struct gpu_ctx); + ctx->log = vo->log; + ctx->priv = talloc_zero(ctx, struct priv); + + struct ra_ctx_opts *ctx_opts = mp_get_config_group(ctx, vo->global, &ra_ctx_conf); + ctx_opts->want_alpha = gl_opts->alpha_mode == ALPHA_YES; + ctx->ra_ctx = ra_ctx_create(vo, *ctx_opts); + if (!ctx->ra_ctx) + goto err_out; + +#if HAVE_VULKAN + struct mpvk_ctx *vkctx = ra_vk_ctx_get(ctx->ra_ctx); + if (vkctx) { + ctx->pllog = vkctx->ctx; + ctx->gpu = vkctx->gpu; + ctx->swapchain = vkctx->swapchain; + return ctx; + } +#endif + + // TODO: wrap GL contexts + +err_out: + gpu_ctx_destroy(&ctx); + return NULL; +} + +bool gpu_ctx_resize(struct gpu_ctx *ctx, int w, int h) +{ + // Not (yet) used + return true; +} + +void gpu_ctx_destroy(struct gpu_ctx **ctxp) +{ + struct gpu_ctx *ctx = *ctxp; + if (!ctx) + return; + + ra_ctx_destroy(&ctx->ra_ctx); + + talloc_free(ctx); + *ctxp = NULL; +} diff --git a/video/out/gpu_next/context.h b/video/out/gpu_next/context.h new file mode 100644 index 0000000000..2e2bc3cd29 --- /dev/null +++ b/video/out/gpu_next/context.h @@ -0,0 +1,41 @@ +/* + * 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 <https://www.gnu.org/licenses/>. + */ + +#pragma once + +#include <libplacebo/renderer.h> + +struct mp_log; +struct ra_ctx; +struct vo; +struct gl_video_opts; + +struct gpu_ctx { + struct mp_log *log; + + struct ra_ctx *ra_ctx; + + pl_log pllog; + pl_gpu gpu; + pl_swapchain swapchain; + + void *priv; +}; + +struct gpu_ctx *gpu_ctx_create(struct vo *vo, struct gl_video_opts *gl_opts); +bool gpu_ctx_resize(struct gpu_ctx *ctx, int w, int h); +void gpu_ctx_destroy(struct gpu_ctx **ctxp); |