From 17b52cc4a9a8d044bbeb2696f507a361df370e4e Mon Sep 17 00:00:00 2001 From: Alexander Preisinger Date: Sat, 4 Jan 2014 16:43:58 +0100 Subject: 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. --- video/out/gl_wayland.c | 120 ++++++++++++++++++++------------------------- video/out/wayland_common.h | 20 ++++++++ 2 files changed, 73 insertions(+), 67 deletions(-) (limited to 'video') diff --git a/video/out/gl_wayland.c b/video/out/gl_wayland.c index 75f29632b0..e13314f531 100644 --- a/video/out/gl_wayland.c +++ b/video/out/gl_wayland.c @@ -16,27 +16,10 @@ * with mpv. If not, see . */ -#include -#include -#include - #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); +} + +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); - eglSwapBuffers(egl_ctx->egl.dpy, egl_ctx->egl_surface); + // NOTE: VO_EVENT_EXPOSE is never returned by the wayland backend + if (*events & VO_EVENT_RESIZE) + egl_resize(wl); - if (wl->window.events & VO_EVENT_RESIZE) - egl_resize(wl, egl_ctx); + 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; } diff --git a/video/out/wayland_common.h b/video/out/wayland_common.h index 01ff09fa43..ac5fc3cf39 100644 --- a/video/out/wayland_common.h +++ b/video/out/wayland_common.h @@ -27,6 +27,12 @@ #include "config.h" +#if HAVE_GL_WAYLAND +#include +#include +#include +#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; -- cgit v1.2.3