2015-12-19 11:45:07 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
2016-01-19 17:36:34 +00:00
|
|
|
* 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.
|
2015-12-19 11:45:07 +00:00
|
|
|
*
|
|
|
|
* 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
|
2016-01-19 17:36:34 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2015-12-19 11:45:07 +00:00
|
|
|
*
|
2016-01-19 17:36:34 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2015-12-19 11:45:07 +00:00
|
|
|
*/
|
|
|
|
|
2017-04-06 12:50:19 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#if HAVE_LIBDL
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#endif
|
|
|
|
|
2016-09-13 13:38:51 +00:00
|
|
|
#include "common/common.h"
|
|
|
|
|
2015-12-19 11:45:07 +00:00
|
|
|
#include "egl_helpers.h"
|
|
|
|
#include "common.h"
|
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.
2017-09-14 06:04:55 +00:00
|
|
|
#include "utils.h"
|
2016-09-13 13:38:51 +00:00
|
|
|
#include "context.h"
|
|
|
|
|
2017-02-07 14:27:17 +00:00
|
|
|
#if HAVE_EGL_ANGLE
|
2017-02-04 08:16:02 +00:00
|
|
|
// On Windows, egl_helpers.c is only used by ANGLE, where the EGL functions may
|
|
|
|
// be loaded dynamically from ANGLE DLLs
|
|
|
|
#include "angle_dynamic.h"
|
|
|
|
#endif
|
|
|
|
|
2016-09-13 13:38:51 +00:00
|
|
|
// EGL 1.5
|
|
|
|
#ifndef EGL_CONTEXT_OPENGL_PROFILE_MASK
|
2016-09-14 08:05:00 +00:00
|
|
|
#define EGL_CONTEXT_MAJOR_VERSION 0x3098
|
|
|
|
#define EGL_CONTEXT_MINOR_VERSION 0x30FB
|
2016-09-13 13:38:51 +00:00
|
|
|
#define EGL_CONTEXT_OPENGL_PROFILE_MASK 0x30FD
|
|
|
|
#define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT 0x00000001
|
2016-09-14 08:05:00 +00:00
|
|
|
#define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE 0x31B1
|
2020-04-18 12:32:33 +00:00
|
|
|
typedef intptr_t EGLAttrib;
|
2016-09-13 13:38:51 +00:00
|
|
|
#endif
|
|
|
|
|
2021-10-20 16:36:59 +00:00
|
|
|
// Not every EGL provider (like RPI) has these.
|
|
|
|
#ifndef EGL_CONTEXT_FLAGS_KHR
|
|
|
|
#define EGL_CONTEXT_FLAGS_KHR EGL_NONE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR
|
|
|
|
#define EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR 0
|
|
|
|
#endif
|
|
|
|
|
2018-04-26 17:10:56 +00:00
|
|
|
struct mp_egl_config_attr {
|
|
|
|
int attrib;
|
|
|
|
const char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MP_EGL_ATTRIB(id) {id, # id}
|
|
|
|
|
|
|
|
static const struct mp_egl_config_attr mp_egl_attribs[] = {
|
|
|
|
MP_EGL_ATTRIB(EGL_CONFIG_ID),
|
|
|
|
MP_EGL_ATTRIB(EGL_RED_SIZE),
|
|
|
|
MP_EGL_ATTRIB(EGL_GREEN_SIZE),
|
|
|
|
MP_EGL_ATTRIB(EGL_BLUE_SIZE),
|
|
|
|
MP_EGL_ATTRIB(EGL_ALPHA_SIZE),
|
|
|
|
MP_EGL_ATTRIB(EGL_COLOR_BUFFER_TYPE),
|
|
|
|
MP_EGL_ATTRIB(EGL_CONFIG_CAVEAT),
|
|
|
|
MP_EGL_ATTRIB(EGL_CONFORMANT),
|
2020-08-27 09:28:39 +00:00
|
|
|
MP_EGL_ATTRIB(EGL_NATIVE_VISUAL_ID),
|
2018-04-26 17:10:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void dump_egl_config(struct mp_log *log, int msgl, EGLDisplay display,
|
|
|
|
EGLConfig config)
|
|
|
|
{
|
|
|
|
for (int n = 0; n < MP_ARRAY_SIZE(mp_egl_attribs); n++) {
|
|
|
|
const char *name = mp_egl_attribs[n].name;
|
|
|
|
EGLint v = -1;
|
|
|
|
if (eglGetConfigAttrib(display, config, mp_egl_attribs[n].attrib, &v)) {
|
2020-08-27 09:28:39 +00:00
|
|
|
mp_msg(log, msgl, " %s=0x%x\n", name, v);
|
2018-04-26 17:10:56 +00:00
|
|
|
} else {
|
|
|
|
mp_msg(log, msgl, " %s=<error>\n", name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
egl_helpers: fix create_context fallback behavior
The EGL stuff is really complicated because of historical reasons
(tl;dr: blame EGL). There was one edge case with EGL context creation
that lead to incorrect behavior. EGL_KHR_create_context was created with
EGL 1.4 (which mpv does support) but it is still possible for an EGL 1.4
device to not implement this extension. That means that none of the EGL
attrs that pass a specific opengl version work. So for this obscure
case, there is a fallback context creation at the very end which simply
creates an EGLContext without passing any special attrs.
This has another problem however. mpv has a hard requirement on at least
desktop opengl 2.1 or opengl ES 2.0 to function (we're not asking for
much here). Since the fallback EGL context creation has no version
checking, it is entirely possible to create an EGL context with a
desktop opengl version under 2.1. As you get further along in the code,
the user will encounter the hard opengl version check and then error
out. However, we're supposed to also actually check if GLES works
(that's what the opengl-es=auto option is for) so this is a bug.
The fix is to do a bit of code duplication and make a mpgl_check_version
specifically for if we hit the edge case of needing to create an EGL
context without the EGL_KHR_create_context extension. Grab the version
with the function pointer, check if it's under 210, if so destroy the
EGL context and set it to NULL. After that, if the user has set
opengl-es to auto, mpv will try GLES next. If it is set to no, then mpv
will simply fail as desired. Fixes #5915.
Sidenote: the ra_gl_ctx_test_version originally testing 140 doesn't make
any sense. Passing the version number in that function only does
something if the user has set opengl-restrict. What we need to do is to
pass the version of the created context to that function. If the version
is higher than the opengl-restrict option, then make this a failure.
2021-07-24 01:08:05 +00:00
|
|
|
static void *mpegl_get_proc_address(void *ctx, const char *name)
|
|
|
|
{
|
|
|
|
void *p = eglGetProcAddress(name);
|
|
|
|
#if defined(__GLIBC__) && HAVE_LIBDL
|
|
|
|
// Some crappy ARM/Linux things do not provide EGL 1.5, so above call does
|
|
|
|
// not necessarily return function pointers for core functions. Try to get
|
|
|
|
// them from a loaded GLES lib. As POSIX leaves RTLD_DEFAULT "reserved",
|
|
|
|
// use it only with glibc.
|
|
|
|
if (!p)
|
|
|
|
p = dlsym(RTLD_DEFAULT, name);
|
|
|
|
#endif
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
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.
2017-09-14 06:04:55 +00:00
|
|
|
static bool create_context(struct ra_ctx *ctx, EGLDisplay display,
|
2021-10-03 12:14:03 +00:00
|
|
|
bool es, struct mpegl_cb cb,
|
2016-09-13 13:38:51 +00:00
|
|
|
EGLContext *out_context, EGLConfig *out_config)
|
|
|
|
{
|
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.
2017-09-14 06:04:55 +00:00
|
|
|
int msgl = ctx->opts.probing ? MSGL_V : MSGL_FATAL;
|
|
|
|
|
|
|
|
EGLenum api;
|
|
|
|
EGLint rend;
|
|
|
|
const char *name;
|
|
|
|
|
2021-10-03 12:14:03 +00:00
|
|
|
if (!es) {
|
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.
2017-09-14 06:04:55 +00:00
|
|
|
api = EGL_OPENGL_API;
|
|
|
|
rend = EGL_OPENGL_BIT;
|
|
|
|
name = "Desktop OpenGL";
|
2021-10-03 12:14:03 +00:00
|
|
|
} else {
|
2016-09-14 08:05:00 +00:00
|
|
|
api = EGL_OPENGL_ES_API;
|
2021-11-10 15:17:10 +00:00
|
|
|
rend = EGL_OPENGL_ES2_BIT;
|
2021-10-03 12:14:03 +00:00
|
|
|
name = "GLES 2.x +";
|
2016-09-14 08:05:00 +00:00
|
|
|
}
|
|
|
|
|
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.
2017-09-14 06:04:55 +00:00
|
|
|
MP_VERBOSE(ctx, "Trying to create %s context.\n", name);
|
2016-09-14 08:05:00 +00:00
|
|
|
|
|
|
|
if (!eglBindAPI(api)) {
|
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.
2017-09-14 06:04:55 +00:00
|
|
|
MP_VERBOSE(ctx, "Could not bind API!\n");
|
2016-09-13 13:38:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLint attributes[] = {
|
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
2018-04-26 19:48:57 +00:00
|
|
|
EGL_RED_SIZE, 8,
|
|
|
|
EGL_GREEN_SIZE, 8,
|
|
|
|
EGL_BLUE_SIZE, 8,
|
2020-10-14 20:38:55 +00:00
|
|
|
EGL_ALPHA_SIZE, ctx->opts.want_alpha ? 1 : 0,
|
2016-09-14 08:05:00 +00:00
|
|
|
EGL_RENDERABLE_TYPE, rend,
|
2016-09-13 13:38:51 +00:00
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
2016-12-31 12:55:44 +00:00
|
|
|
EGLint num_configs;
|
|
|
|
if (!eglChooseConfig(display, attributes, NULL, 0, &num_configs))
|
|
|
|
num_configs = 0;
|
2016-09-13 13:38:51 +00:00
|
|
|
|
2016-12-31 12:55:44 +00:00
|
|
|
EGLConfig *configs = talloc_array(NULL, EGLConfig, num_configs);
|
|
|
|
if (!eglChooseConfig(display, attributes, configs, num_configs, &num_configs))
|
|
|
|
num_configs = 0;
|
2016-12-30 18:52:47 +00:00
|
|
|
|
2016-12-31 12:55:44 +00:00
|
|
|
if (!num_configs) {
|
|
|
|
talloc_free(configs);
|
2018-04-09 19:32:46 +00:00
|
|
|
MP_MSG(ctx, msgl, "Could not choose EGLConfig for %s!\n", name);
|
2016-09-13 13:38:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-26 17:10:56 +00:00
|
|
|
for (int n = 0; n < num_configs; n++)
|
|
|
|
dump_egl_config(ctx->log, MSGL_TRACE, display, configs[n]);
|
|
|
|
|
2016-12-30 18:52:47 +00:00
|
|
|
int chosen = 0;
|
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.
2017-09-14 06:04:55 +00:00
|
|
|
if (cb.refine_config)
|
|
|
|
chosen = cb.refine_config(cb.user_data, configs, num_configs);
|
2018-02-18 22:51:10 +00:00
|
|
|
if (chosen < 0) {
|
|
|
|
talloc_free(configs);
|
2018-04-09 19:32:46 +00:00
|
|
|
MP_MSG(ctx, msgl, "Could not refine EGLConfig for %s!\n", name);
|
2018-02-18 22:51:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-12-30 18:52:47 +00:00
|
|
|
EGLConfig config = configs[chosen];
|
|
|
|
|
|
|
|
talloc_free(configs);
|
|
|
|
|
2018-04-26 17:10:56 +00:00
|
|
|
MP_DBG(ctx, "Chosen EGLConfig:\n");
|
|
|
|
dump_egl_config(ctx->log, MSGL_DEBUG, display, config);
|
|
|
|
|
2021-10-02 21:38:12 +00:00
|
|
|
int ctx_flags = ctx->opts.debug ? EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR : 0;
|
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.
2017-09-14 06:04:55 +00:00
|
|
|
EGLContext *egl_ctx = NULL;
|
2016-09-14 08:05:00 +00:00
|
|
|
|
2021-10-02 20:30:10 +00:00
|
|
|
if (!es) {
|
2021-10-02 16:44:34 +00:00
|
|
|
for (int n = 0; mpgl_min_required_gl_versions[n]; n++) {
|
|
|
|
int ver = mpgl_min_required_gl_versions[n];
|
2016-09-14 08:05:00 +00:00
|
|
|
|
|
|
|
EGLint attrs[] = {
|
|
|
|
EGL_CONTEXT_MAJOR_VERSION, MPGL_VER_GET_MAJOR(ver),
|
|
|
|
EGL_CONTEXT_MINOR_VERSION, MPGL_VER_GET_MINOR(ver),
|
|
|
|
EGL_CONTEXT_OPENGL_PROFILE_MASK,
|
|
|
|
ver >= 320 ? EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT : 0,
|
2021-10-02 21:38:12 +00:00
|
|
|
EGL_CONTEXT_FLAGS_KHR, ctx_flags,
|
2016-09-14 08:05:00 +00:00
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
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.
2017-09-14 06:04:55 +00:00
|
|
|
egl_ctx = eglCreateContext(display, config, EGL_NO_CONTEXT, attrs);
|
|
|
|
if (egl_ctx)
|
2016-09-14 08:05:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-10-02 20:30:10 +00:00
|
|
|
}
|
|
|
|
if (!egl_ctx) {
|
|
|
|
// Fallback for EGL 1.4 without EGL_KHR_create_context or GLES
|
2021-10-02 21:38:12 +00:00
|
|
|
// Add the context flags only for GLES - GL has been attempted above
|
2021-10-02 20:30:10 +00:00
|
|
|
EGLint attrs[] = {
|
|
|
|
EGL_CONTEXT_CLIENT_VERSION, 2,
|
2021-10-02 21:38:12 +00:00
|
|
|
es ? EGL_CONTEXT_FLAGS_KHR : EGL_NONE, ctx_flags,
|
2021-10-02 20:30:10 +00:00
|
|
|
EGL_NONE
|
|
|
|
};
|
2016-09-14 08:05:00 +00:00
|
|
|
|
2021-10-02 20:30:10 +00:00
|
|
|
egl_ctx = eglCreateContext(display, config, EGL_NO_CONTEXT, attrs);
|
2016-09-13 13:38:51 +00:00
|
|
|
}
|
|
|
|
|
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.
2017-09-14 06:04:55 +00:00
|
|
|
if (!egl_ctx) {
|
2018-04-09 19:32:46 +00:00
|
|
|
MP_MSG(ctx, msgl, "Could not create EGL context for %s!\n", name);
|
2016-09-13 13:38:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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.
2017-09-14 06:04:55 +00:00
|
|
|
*out_context = egl_ctx;
|
2016-09-13 13:38:51 +00:00
|
|
|
*out_config = config;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-14 08:38:37 +00:00
|
|
|
#define STR_OR_ERR(s) ((s) ? (s) : "(error)")
|
|
|
|
|
2016-09-13 13:38:51 +00:00
|
|
|
// Create a context and return it and the config it was created with. If it
|
|
|
|
// returns false, the out_* pointers are set to NULL.
|
|
|
|
// vo_flags is a combination of VOFLAG_* values.
|
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.
2017-09-14 06:04:55 +00:00
|
|
|
bool mpegl_create_context(struct ra_ctx *ctx, EGLDisplay display,
|
2016-09-13 13:38:51 +00:00
|
|
|
EGLContext *out_context, EGLConfig *out_config)
|
|
|
|
{
|
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.
2017-09-14 06:04:55 +00:00
|
|
|
return mpegl_create_context_cb(ctx, display, (struct mpegl_cb){0},
|
|
|
|
out_context, out_config);
|
2016-12-30 18:24:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a context and return it and the config it was created with. If it
|
|
|
|
// returns false, the out_* pointers are set to NULL.
|
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.
2017-09-14 06:04:55 +00:00
|
|
|
bool mpegl_create_context_cb(struct ra_ctx *ctx, EGLDisplay display,
|
|
|
|
struct mpegl_cb cb, EGLContext *out_context,
|
|
|
|
EGLConfig *out_config)
|
2016-12-30 18:24:34 +00:00
|
|
|
{
|
2016-09-13 13:38:51 +00:00
|
|
|
*out_context = NULL;
|
|
|
|
*out_config = NULL;
|
|
|
|
|
2016-09-14 08:38:37 +00:00
|
|
|
const char *version = eglQueryString(display, EGL_VERSION);
|
|
|
|
const char *vendor = eglQueryString(display, EGL_VENDOR);
|
|
|
|
const char *apis = eglQueryString(display, EGL_CLIENT_APIS);
|
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.
2017-09-14 06:04:55 +00:00
|
|
|
MP_VERBOSE(ctx, "EGL_VERSION=%s\nEGL_VENDOR=%s\nEGL_CLIENT_APIS=%s\n",
|
2016-09-14 08:38:37 +00:00
|
|
|
STR_OR_ERR(version), STR_OR_ERR(vendor), STR_OR_ERR(apis));
|
|
|
|
|
2021-10-02 20:22:46 +00:00
|
|
|
enum gles_mode mode = ra_gl_ctx_get_glesmode(ctx);
|
|
|
|
|
|
|
|
if ((mode == GLES_NO || mode == GLES_AUTO) &&
|
|
|
|
create_context(ctx, display, false, cb, out_context, out_config))
|
2021-10-03 12:14:03 +00:00
|
|
|
return true;
|
2021-10-02 20:22:46 +00:00
|
|
|
|
|
|
|
if ((mode == GLES_YES || mode == GLES_AUTO) &&
|
|
|
|
create_context(ctx, display, true, cb, out_context, out_config))
|
2021-10-03 12:14:03 +00:00
|
|
|
return true;
|
2016-09-13 13:38:51 +00:00
|
|
|
|
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.
2017-09-14 06:04:55 +00:00
|
|
|
int msgl = ctx->opts.probing ? MSGL_V : MSGL_ERR;
|
|
|
|
MP_MSG(ctx, msgl, "Could not create a GL context.\n");
|
2016-09-13 13:38:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-12-19 11:45:07 +00:00
|
|
|
|
2017-12-27 08:52:55 +00:00
|
|
|
static int GLAPIENTRY swap_interval(int interval)
|
|
|
|
{
|
|
|
|
EGLDisplay display = eglGetCurrentDisplay();
|
|
|
|
if (!display)
|
|
|
|
return 1;
|
|
|
|
return !eglSwapInterval(display, interval);
|
|
|
|
}
|
|
|
|
|
2017-04-06 12:50:19 +00:00
|
|
|
// Load gl version and function pointers into *gl.
|
|
|
|
// Expects a current EGL context set.
|
|
|
|
void mpegl_load_functions(struct GL *gl, struct mp_log *log)
|
|
|
|
{
|
|
|
|
const char *egl_exts = "";
|
|
|
|
EGLDisplay display = eglGetCurrentDisplay();
|
|
|
|
if (display != EGL_NO_DISPLAY)
|
|
|
|
egl_exts = eglQueryString(display, EGL_EXTENSIONS);
|
|
|
|
|
|
|
|
mpgl_load_functions2(gl, mpegl_get_proc_address, NULL, egl_exts, log);
|
2017-12-27 08:52:55 +00:00
|
|
|
if (!gl->SwapInterval)
|
|
|
|
gl->SwapInterval = swap_interval;
|
2017-04-06 12:50:19 +00:00
|
|
|
}
|
vo_gpu: opengl: make it work with EGL 1.4
This tries to deal with the crazy EGL situation. The summary is:
- using eglGetDisplay() with multiple windowing platforms doesn't really
work, but Mesa had an awful hack for it
- this hack can be disabled at build time, and some distros sometimes
accidentally or intentionally do so
- Mesa will probably eventually disable it by default
- we switched to eglGetPlatformDisplay(), but this requires EGL 1.5
- the very regrettable graphics company (also known as Nvidia) ships
drivers (for old hardware I think) that are EGL 1.4 only
- that means even though we "require" EGL 1.5 and link against it, the
runtime EGL may be 1.4
- trying to run mpv there crashes in the dynamic linker
- so we have to go through some more awful compatibility hacks
This commit tries to do it "properly", but using EGL 1.4 as base. The
plaform selection mechanism is a messy extension there, which got
elevated to core API in 1.5 (but OF COURSE in incompatible ways).
I'm not sure whether the EGL 1.5 code path (by parsing the EGL_VERSION)
is really needed, but if you ask me, it feels slightly saner not to rely
on an EGL 1.4 kludge forever. But maybe this is just an instance of
self-harm, since they will most likely never drop or not provide this
API.
Also, unlike before, we actually check the extension string for the
individual platform extensions, because who knows, some EGL
implementations might curse us if we pass unknown platform parameters.
(But actually, the more I think about this, the more bullshit it is.)
X11 and Wayland were the only ones trying to call eglGetPlatformDisplay,
so they're the only ones which are adjusted in this commit.
Unfortunately, correct function of this commit is unconfirmed. It's
possible that it crashes with the old drivers mentioned above.
Why didn't they solve it like this:
struct native_display {
int platform_type;
void *native_display;
};
Could have kept eglGetDisplay() without all the obnoxious extension BS.
2019-11-30 19:48:30 +00:00
|
|
|
|
|
|
|
// This is similar to eglGetPlatformDisplay(platform, native_display, NULL),
|
|
|
|
// except that it 1. may use eglGetPlatformDisplayEXT, 2. checks for the
|
|
|
|
// platform client extension platform_ext_name, and 3. does not support passing
|
|
|
|
// an attrib list, because the type for that parameter is different in the EXT
|
|
|
|
// and standard functions (EGL can't not fuck up, no matter what).
|
|
|
|
// platform: e.g. EGL_PLATFORM_X11_KHR
|
|
|
|
// platform_ext_name: e.g. "EGL_KHR_platform_x11"
|
|
|
|
// native_display: e.g. X11 Display*
|
|
|
|
// Returns EGL_NO_DISPLAY on failure.
|
|
|
|
// Warning: the EGL version can be different at runtime depending on the chosen
|
|
|
|
// platform, so this might return a display corresponding to some older EGL
|
|
|
|
// version (often 1.4).
|
|
|
|
// Often, there are two extension variants of a platform (KHR and EXT). If you
|
|
|
|
// need to check both, call this function twice. (Why do they define them twice?
|
|
|
|
// They're crazy.)
|
|
|
|
EGLDisplay mpegl_get_display(EGLenum platform, const char *platform_ext_name,
|
|
|
|
void *native_display)
|
|
|
|
{
|
|
|
|
// EGL is awful. Designed as ultra-portable library, it fails at dealing
|
|
|
|
// with slightly more complex environment than its short-sighted design
|
|
|
|
// could deal with. So they invented an awful, awful kludge that modifies
|
|
|
|
// EGL standard behavior, the EGL_EXT_client_extensions extension. EGL 1.4
|
|
|
|
// normally is to return NULL when querying EGL_EXTENSIONS on EGL_NO_DISPLAY,
|
|
|
|
// however, with that extension, it'll return the set of "client extensions",
|
|
|
|
// which may include EGL_EXT_platform_base.
|
|
|
|
|
|
|
|
// Prerequisite: check the platform extension.
|
|
|
|
// If this is either EGL 1.5, or 1.4 with EGL_EXT_client_extensions, then
|
|
|
|
// this must return a valid extension string.
|
|
|
|
const char *exts = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
|
|
|
|
if (!exts || !gl_check_extension(exts, platform_ext_name))
|
|
|
|
return EGL_NO_DISPLAY;
|
|
|
|
|
|
|
|
// Before we go through the EGL 1.4 BS, try if we can use native EGL 1.5
|
|
|
|
// It appears that EGL 1.4 is specified to _require_ an initialized display
|
|
|
|
// for EGL_VERSION, while EGL 1.5 is _required_ to return the EGL version.
|
|
|
|
const char *ver = eglQueryString(EGL_NO_DISPLAY, EGL_VERSION);
|
|
|
|
// Of course we have to go through the excruciating pain of parsing a
|
|
|
|
// version string, since EGL provides no other way without a display. In
|
|
|
|
// theory version!=NULL is already proof enough that it's 1.5, but be
|
|
|
|
// extra defensive, since this should have been true for EGL_EXTENSIONS as
|
|
|
|
// well, but then they added an extension that modified standard behavior.
|
|
|
|
int ma = 0, mi = 0;
|
|
|
|
if (ver && sscanf(ver, "%d.%d", &ma, &mi) == 2 && (ma > 1 || mi >= 5)) {
|
|
|
|
// This is EGL 1.5. It must support querying standard functions through
|
|
|
|
// eglGetProcAddress(). Note that on EGL 1.4, even if the function is
|
|
|
|
// unknown, it could return non-NULL anyway (because EGL is crazy).
|
|
|
|
EGLDisplay (EGLAPIENTRYP GetPlatformDisplay)
|
|
|
|
(EGLenum, void *, const EGLAttrib *) =
|
|
|
|
(void *)eglGetProcAddress("eglGetPlatformDisplay");
|
|
|
|
// (It should be impossible to be NULL, but uh.)
|
|
|
|
if (GetPlatformDisplay)
|
|
|
|
return GetPlatformDisplay(platform, native_display, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// (It should be impossible to be missing, but uh.)
|
|
|
|
if (!gl_check_extension(exts, "EGL_EXT_client_extensions"))
|
|
|
|
return EGL_NO_DISPLAY;
|
|
|
|
|
|
|
|
EGLDisplay (EGLAPIENTRYP GetPlatformDisplayEXT)(EGLenum, void*, const EGLint*)
|
|
|
|
= (void *)eglGetProcAddress("eglGetPlatformDisplayEXT");
|
|
|
|
|
|
|
|
// (It should be impossible to be NULL, but uh.)
|
|
|
|
if (GetPlatformDisplayEXT)
|
|
|
|
return GetPlatformDisplayEXT(platform, native_display, NULL);
|
|
|
|
|
|
|
|
return EGL_NO_DISPLAY;
|
|
|
|
}
|