Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

video/wayland: use EGL_EXT_present_opaque when available #4646

Merged
merged 2 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions include/SDL_hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,17 @@ extern "C" {
*/
#define SDL_HINT_VIDEO_DOUBLE_BUFFER "SDL_VIDEO_DOUBLE_BUFFER"

/**
* \brief A variable controlling whether the EGL window is allowed to be
* composited as transparent, rather than opaque.
*
* Most window systems will always render windows opaque, even if the surface
* format has an alpha channel. This is not always true, however, so by default
* SDL will try to enforce opaque composition. To override this behavior, you
* can set this hint to "1".
*/
#define SDL_HINT_VIDEO_EGL_ALLOW_TRANSPARENCY "SDL_VIDEO_EGL_ALLOW_TRANSPARENCY"

/**
* \brief A variable controlling whether the graphics context is externally managed.
*
Expand Down
17 changes: 15 additions & 2 deletions src/video/SDL_egl.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
#endif
#endif /* EGL_KHR_create_context */

#ifndef EGL_EXT_present_opaque
#define EGL_EXT_present_opaque 1
#define EGL_PRESENT_OPAQUE_EXT 0x31DF
#endif /* EGL_EXT_present_opaque */

#if SDL_VIDEO_DRIVER_RPI
/* Raspbian places the OpenGL ES/EGL binaries in a non standard path */
#define DEFAULT_EGL ( vc4 ? "libEGL.so.1" : "libbrcmEGL.so" )
Expand Down Expand Up @@ -1182,8 +1187,8 @@ SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
EGLint format_wanted;
EGLint format_got;
#endif
/* max 2 values plus terminator. */
EGLint attribs[3];
/* max 2 key+value pairs, plus terminator. */
EGLint attribs[5];
int attr = 0;

EGLSurface * surface;
Expand Down Expand Up @@ -1216,6 +1221,14 @@ SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
}
}

#ifdef EGL_EXT_present_opaque
if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_EXT_present_opaque")) {
const SDL_bool allow_transparent = SDL_GetHintBoolean(SDL_HINT_VIDEO_EGL_ALLOW_TRANSPARENCY, SDL_FALSE);
attribs[attr++] = EGL_PRESENT_OPAQUE_EXT;
attribs[attr++] = allow_transparent ? EGL_FALSE : EGL_TRUE;
}
#endif

attribs[attr++] = EGL_NONE;

surface = _this->egl_data->eglCreateWindowSurface(
Expand Down