wayland/egl: add egl_context to the wayland state

At the moment there are visual glitches when we resize the window. This happens
because in wayland there a special function for resizing EGL windows.

To prevent the glitches move the egl_context to the wayland state in
wayland_common.h and add a new control function to gl_wayland.c to wrap the
vo_wayland_control function to check for resize events.

With the new control wrapper the glitches are gone and the resizing is fluid.
This commit is contained in:
Alexander Preisinger 2014-01-04 16:43:58 +01:00
parent f5565f33c7
commit 17b52cc4a9
2 changed files with 73 additions and 67 deletions

View File

@ -16,27 +16,10 @@
* with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#include <wayland-egl.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include "wayland_common.h"
#include "gl_common.h"
struct egl_context {
EGLSurface egl_surface;
struct wl_egl_window *egl_window;
struct {
EGLDisplay dpy;
EGLContext ctx;
EGLConfig conf;
} egl;
};
static void egl_resize(struct vo_wayland_state *wl,
struct egl_context *ctx)
static void egl_resize(struct vo_wayland_state *wl)
{
int32_t x = wl->window.sh_x;
int32_t y = wl->window.sh_y;
@ -45,7 +28,7 @@ static void egl_resize(struct vo_wayland_state *wl,
// get the real size of the window
// this improves moving the window while resizing it
wl_egl_window_get_attached_size(ctx->egl_window,
wl_egl_window_get_attached_size(wl->egl_context.egl_window,
&wl->window.width,
&wl->window.height);
@ -60,7 +43,7 @@ static void egl_resize(struct vo_wayland_state *wl,
if (y != 0)
y = wl->window.height - height;
wl_egl_window_resize(ctx->egl_window, width, height, x, y);
wl_egl_window_resize(wl->egl_context.egl_window, width, height, x, y);
wl->window.width = width;
wl->window.height = height;
@ -74,7 +57,6 @@ static void egl_resize(struct vo_wayland_state *wl,
}
static bool egl_create_context(struct vo_wayland_state *wl,
struct egl_context *egl_ctx,
MPGLContext *ctx,
bool enable_alpha)
{
@ -83,7 +65,7 @@ static bool egl_create_context(struct vo_wayland_state *wl,
GL *gl = ctx->gl;
const char *eglstr = "";
if (!(egl_ctx->egl.dpy = eglGetDisplay(wl->display.display)))
if (!(wl->egl_context.egl.dpy = eglGetDisplay(wl->display.display)))
return false;
EGLint config_attribs[] = {
@ -98,7 +80,7 @@ static bool egl_create_context(struct vo_wayland_state *wl,
};
/* major and minor here returns the supported EGL version (e.g.: 1.4) */
if (eglInitialize(egl_ctx->egl.dpy, &major, &minor) != EGL_TRUE)
if (eglInitialize(wl->egl_context.egl.dpy, &major, &minor) != EGL_TRUE)
return false;
MP_VERBOSE(wl, "EGL version %d.%d\n", major, minor);
@ -112,30 +94,30 @@ static bool egl_create_context(struct vo_wayland_state *wl,
if (eglBindAPI(EGL_OPENGL_API) != EGL_TRUE)
return false;
eglChooseConfig(egl_ctx->egl.dpy, config_attribs,
&egl_ctx->egl.conf, 1, &n);
eglChooseConfig(wl->egl_context.egl.dpy, config_attribs,
&wl->egl_context.egl.conf, 1, &n);
egl_ctx->egl.ctx = eglCreateContext(egl_ctx->egl.dpy,
egl_ctx->egl.conf,
EGL_NO_CONTEXT,
context_attribs);
if (!egl_ctx->egl.ctx) {
wl->egl_context.egl.ctx = eglCreateContext(wl->egl_context.egl.dpy,
wl->egl_context.egl.conf,
EGL_NO_CONTEXT,
context_attribs);
if (!wl->egl_context.egl.ctx) {
/* fallback to any GL version */
MP_WARN(wl, "can't create context for requested OpenGL version: "
"fall back to any version available");
context_attribs[0] = EGL_NONE;
egl_ctx->egl.ctx = eglCreateContext(egl_ctx->egl.dpy,
egl_ctx->egl.conf,
EGL_NO_CONTEXT,
context_attribs);
wl->egl_context.egl.ctx = eglCreateContext(wl->egl_context.egl.dpy,
wl->egl_context.egl.conf,
EGL_NO_CONTEXT,
context_attribs);
if (!egl_ctx->egl.ctx)
if (!wl->egl_context.egl.ctx)
return false;
}
eglMakeCurrent(egl_ctx->egl.dpy, NULL, NULL, egl_ctx->egl.ctx);
eglMakeCurrent(wl->egl_context.egl.dpy, NULL, NULL, wl->egl_context.egl.ctx);
eglstr = eglQueryString(egl_ctx->egl.dpy, EGL_EXTENSIONS);
eglstr = eglQueryString(wl->egl_context.egl.dpy, EGL_EXTENSIONS);
mpgl_load_functions(gl, (void*(*)(const GLubyte*))eglGetProcAddress, eglstr,
wl->log);
@ -146,23 +128,22 @@ static bool egl_create_context(struct vo_wayland_state *wl,
}
static void egl_create_window(struct vo_wayland_state *wl,
struct egl_context *egl_ctx,
uint32_t width,
uint32_t height)
{
egl_ctx->egl_window = wl_egl_window_create(wl->window.surface,
wl->window.width,
wl->window.height);
wl->egl_context.egl_window = wl_egl_window_create(wl->window.surface,
wl->window.width,
wl->window.height);
egl_ctx->egl_surface = eglCreateWindowSurface(egl_ctx->egl.dpy,
egl_ctx->egl.conf,
egl_ctx->egl_window,
NULL);
wl->egl_context.egl_surface = eglCreateWindowSurface(wl->egl_context.egl.dpy,
wl->egl_context.egl.conf,
wl->egl_context.egl_window,
NULL);
eglMakeCurrent(egl_ctx->egl.dpy,
egl_ctx->egl_surface,
egl_ctx->egl_surface,
egl_ctx->egl.ctx);
eglMakeCurrent(wl->egl_context.egl.dpy,
wl->egl_context.egl_surface,
wl->egl_context.egl_surface,
wl->egl_context.egl.ctx);
wl_display_dispatch_pending(wl->display.display);
}
@ -172,7 +153,6 @@ static bool config_window_wayland(struct MPGLContext *ctx,
uint32_t d_height,
uint32_t flags)
{
struct egl_context * egl_ctx = ctx->priv;
struct vo_wayland_state * wl = ctx->vo->wayland;
bool enable_alpha = !!(flags & VOFLAG_ALPHA);
bool ret = false;
@ -180,23 +160,23 @@ static bool config_window_wayland(struct MPGLContext *ctx,
if (!vo_wayland_config(ctx->vo, d_width, d_height, flags))
return false;
if (!egl_ctx->egl.ctx) {
if (!wl->egl_context.egl.ctx) {
/* Create OpenGL context */
ret = egl_create_context(wl, egl_ctx, ctx, enable_alpha);
ret = egl_create_context(wl, ctx, enable_alpha);
/* If successfully created the context and we don't want to hide the
* window than also create the window immediately */
if (ret && !(VOFLAG_HIDDEN & flags))
egl_create_window(wl, egl_ctx, d_width, d_height);
egl_create_window(wl, d_width, d_height);
return ret;
}
else {
if (!egl_ctx->egl_window) {
if (!wl->egl_context.egl_window) {
/* If the context exists and the hidden flag is unset then
* create the window */
if (!(VOFLAG_HIDDEN & flags))
egl_create_window(wl, egl_ctx, d_width, d_height);
egl_create_window(wl, d_width, d_height);
}
return true;
}
@ -205,35 +185,41 @@ static bool config_window_wayland(struct MPGLContext *ctx,
static void releaseGlContext_wayland(MPGLContext *ctx)
{
GL *gl = ctx->gl;
struct egl_context * egl_ctx = ctx->priv;
struct vo_wayland_state *wl = ctx->vo->wayland;
gl->Finish();
eglMakeCurrent(egl_ctx->egl.dpy, NULL, NULL, EGL_NO_CONTEXT);
eglDestroyContext(egl_ctx->egl.dpy, egl_ctx->egl.ctx);
eglTerminate(egl_ctx->egl.dpy);
eglMakeCurrent(wl->egl_context.egl.dpy, NULL, NULL, EGL_NO_CONTEXT);
eglDestroyContext(wl->egl_context.egl.dpy, wl->egl_context.egl.ctx);
eglTerminate(wl->egl_context.egl.dpy);
eglReleaseThread();
wl_egl_window_destroy(egl_ctx->egl_window);
egl_ctx->egl.ctx = NULL;
wl_egl_window_destroy(wl->egl_context.egl_window);
wl->egl_context.egl.ctx = NULL;
}
static void swapGlBuffers_wayland(MPGLContext *ctx)
{
struct egl_context * egl_ctx = ctx->priv;
struct vo_wayland_state *wl = ctx->vo->wayland;
eglSwapBuffers(wl->egl_context.egl.dpy, wl->egl_context.egl_surface);
}
eglSwapBuffers(egl_ctx->egl.dpy, egl_ctx->egl_surface);
static int control(struct vo *vo, int *events, int request, void *data)
{
struct vo_wayland_state *wl = vo->wayland;
int r = vo_wayland_control(vo, events, request, data);
if (wl->window.events & VO_EVENT_RESIZE)
egl_resize(wl, egl_ctx);
// NOTE: VO_EVENT_EXPOSE is never returned by the wayland backend
if (*events & VO_EVENT_RESIZE)
egl_resize(wl);
return r;
}
void mpgl_set_backend_wayland(MPGLContext *ctx)
{
ctx->priv = talloc_zero(ctx, struct egl_context);
ctx->config_window = config_window_wayland;
ctx->releaseGlContext = releaseGlContext_wayland;
ctx->swapGlBuffers = swapGlBuffers_wayland;
ctx->vo_control = vo_wayland_control;
ctx->vo_control = control;
ctx->vo_init = vo_wayland_init;
ctx->vo_uninit = vo_wayland_uninit;
}

View File

@ -27,6 +27,12 @@
#include "config.h"
#if HAVE_GL_WAYLAND
#include <wayland-egl.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#endif
struct vo;
struct vo_wayland_output {
@ -43,6 +49,20 @@ struct vo_wayland_state {
struct vo *vo;
struct mp_log* log;
#if HAVE_GL_WAYLAND
struct {
EGLSurface egl_surface;
struct wl_egl_window *egl_window;
struct {
EGLDisplay dpy;
EGLContext ctx;
EGLConfig conf;
} egl;
} egl_context;
#endif
struct {
int fd;
struct wl_display *display;