forked from mpv-player/mpv
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(WIP) 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_ctx_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 Note: This is an in-progress commit. For a list of files that need to be ported to the new API, see the commented out build steps in wscript_build.py as well as the commented out backends in video/out/gpu/context.c
- Loading branch information
Showing
52 changed files
with
1,842 additions
and
1,722 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/* | ||
* 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 <stddef.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdbool.h> | ||
#include <math.h> | ||
#include <assert.h> | ||
|
||
#include "config.h" | ||
#include "common/common.h" | ||
#include "common/msg.h" | ||
#include "options/options.h" | ||
#include "options/m_option.h" | ||
#include "video/out/vo.h" | ||
|
||
#include "context.h" | ||
|
||
extern const struct ra_ctx_fns ra_ctx_glx; | ||
extern const struct ra_ctx_fns ra_ctx_glx_probe; | ||
extern const struct ra_ctx_fns ra_ctx_x11_egl; | ||
extern const struct ra_ctx_fns ra_ctx_drm_egl; | ||
extern const struct ra_ctx_fns ra_ctx_cocoa; | ||
extern const struct ra_ctx_fns ra_ctx_wayland_egl; | ||
extern const struct ra_ctx_fns ra_ctx_wgl; | ||
extern const struct ra_ctx_fns ra_ctx_angle; | ||
extern const struct ra_ctx_fns ra_ctx_dxinterop; | ||
extern const struct ra_ctx_fns ra_ctx_rpi; | ||
extern const struct ra_ctx_fns ra_ctx_mali; | ||
extern const struct ra_ctx_fns ra_ctx_vdpauglx; | ||
|
||
static const struct ra_ctx_fns *contexts[] = { | ||
// OpenGL contexts: | ||
/* | ||
#if HAVE_RPI | ||
&ra_ctx_rpi, | ||
#endif | ||
#if HAVE_GL_COCOA | ||
&ra_ctx_cocoa, | ||
#endif | ||
#if HAVE_EGL_ANGLE_WIN32 | ||
&ra_ctx_angle, | ||
#endif | ||
#if HAVE_GL_WIN32 | ||
&ra_ctx_wgl, | ||
#endif | ||
#if HAVE_GL_DXINTEROP | ||
&ra_ctx_dxinterop, | ||
#endif | ||
*/ | ||
#if HAVE_GL_X11 | ||
&ra_ctx_glx_probe, | ||
#endif | ||
#if HAVE_EGL_X11 | ||
&ra_ctx_x11_egl, | ||
#endif | ||
#if HAVE_GL_X11 | ||
&ra_ctx_glx, | ||
#endif | ||
#if HAVE_GL_WAYLAND | ||
&ra_ctx_wayland_egl, | ||
#endif | ||
#if HAVE_EGL_DRM | ||
&ra_ctx_drm_egl, | ||
#endif | ||
/* | ||
#if HAVE_MALI_FBDEV | ||
&ra_ctx_mali, | ||
#endif | ||
#if HAVE_VDPAU_GL_X11 | ||
&ra_ctx_vdpauglx, | ||
#endif | ||
*/ | ||
}; | ||
|
||
static const char *type_names[] = { | ||
[RA_API_OPENGL] = "opengl", | ||
}; | ||
|
||
int ra_ctx_validate_context(struct mp_log *log, const struct m_option *opt, | ||
struct bstr name, struct bstr param) | ||
{ | ||
if (bstr_equals0(param, "help")) { | ||
mp_info(log, "GPU contexts:\n"); | ||
mp_info(log, " auto (autodetect)\n"); | ||
for (int n = 0; n < MP_ARRAY_SIZE(contexts); n++) { | ||
mp_info(log, " %s (%s)\n", contexts[n]->name, | ||
type_names[contexts[n]->type]); | ||
} | ||
return M_OPT_EXIT; | ||
} | ||
|
||
if (bstr_equals0(param, "auto")) | ||
return 1; | ||
for (int i = 0; i < MP_ARRAY_SIZE(contexts); i++) { | ||
if (bstr_equals0(param, contexts[i]->name)) | ||
return 1; | ||
} | ||
|
||
return M_OPT_INVALID; | ||
} | ||
|
||
// Create a VO window and create a RA context on it. | ||
// vo_flags: passed to the backend's create window function | ||
struct ra_ctx *ra_ctx_create(struct vo *vo, enum ra_api_type type, | ||
const char *context_name, struct ra_ctx_opts opts) | ||
{ | ||
if (!context_name || strcmp(context_name, "auto") == 0) { | ||
MP_VERBOSE(vo, "Probing for best GPU context.\n"); | ||
opts.probing = true; | ||
} | ||
|
||
for (int i = 0; i < MP_ARRAY_SIZE(contexts); i++) { | ||
if (!opts.probing && strcmp(contexts[i]->name, context_name) != 0) | ||
continue; | ||
if (type && type != contexts[i]->type) | ||
continue; | ||
|
||
struct ra_ctx *ctx = talloc_ptrtype(NULL, ctx); | ||
*ctx = (struct ra_ctx) { | ||
.vo = vo, | ||
.global = vo->global, | ||
.log = vo->log, | ||
.opts = opts, | ||
.fns = contexts[i], | ||
}; | ||
|
||
MP_VERBOSE(ctx, "Initializing GPU context '%s'\n", ctx->fns->name); | ||
if (contexts[i]->init(ctx)) | ||
return ctx; | ||
|
||
talloc_free(ctx); | ||
} | ||
|
||
// If we've reached this point, then none of the contexts matched the name | ||
// requested, or the backend creation failed for all of them. | ||
MP_ERR(vo, "Failed initializing any suitable GPU context!\n"); | ||
return NULL; | ||
} | ||
|
||
void ra_ctx_destroy(struct ra_ctx **ctx) | ||
{ | ||
if (*ctx) | ||
(*ctx)->fns->uninit(*ctx); | ||
talloc_free(*ctx); | ||
*ctx = NULL; | ||
} |
Oops, something went wrong.