From 60e4cca934eaa4713fdf693ac4afcacc43f7b632 Mon Sep 17 00:00:00 2001 From: Denis Bernard Date: Tue, 5 Nov 2019 13:07:36 +0100 Subject: [PATCH] app/internal/window: Do not re-create EGL surfaces when only resizing This prevents flickering when resizing the window on X11. Signed-off-by: Denis Bernard --- app/internal/window/egl.go | 57 ++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/app/internal/window/egl.go b/app/internal/window/egl.go index a8b7d9ed..3c54c086 100644 --- a/app/internal/window/egl.go +++ b/app/internal/window/egl.go @@ -134,38 +134,41 @@ func (c *context) MakeCurrent() error { if c.eglWin == win && width == c.width && height == c.height { return nil } - if win == nilEGLNativeWindowType { - if c.srgbFBO != nil { + c.width, c.height = width, height + // Do not re-create surfaces when only resizing. This prevents flickering when resizing on X11. + if c.eglWin != win { + if win == nilEGLNativeWindowType && c.srgbFBO != nil { c.srgbFBO.Release() c.srgbFBO = nil } - } - if c.eglSurf != nilEGLSurface { - // Make sure any in-flight GL commands are complete. - c.c.Finish() - eglMakeCurrent(c.eglCtx.disp, nilEGLSurface, nilEGLSurface, nilEGLContext) - eglDestroySurface(c.eglCtx.disp, c.eglSurf) - c.eglSurf = nilEGLSurface - } - c.width, c.height = width, height - c.eglWin = win - if c.eglWin == nilEGLNativeWindowType { + if c.eglSurf != nilEGLSurface { + // Make sure any in-flight GL commands are complete. + c.c.Finish() + eglMakeCurrent(c.eglCtx.disp, nilEGLSurface, nilEGLSurface, nilEGLContext) + eglDestroySurface(c.eglCtx.disp, c.eglSurf) + c.eglSurf = nilEGLSurface + } + c.eglWin = win + if c.eglWin == nilEGLNativeWindowType { + return nil + } + eglSurf, err := createSurfaceAndMakeCurrent(c.eglCtx, win) + c.eglSurf = eglSurf + if err != nil { + c.eglWin = nilEGLNativeWindowType + return err + } + // eglSwapInterval 1 leads to erratic frame rates and unnecessary blocking. + // We rely on platform specific frame rate limiting instead, except on Windows + // and X11 where eglSwapInterval is all there is. + if c.driver.needVSync() { + eglSwapInterval(c.eglCtx.disp, 1) + } else { + eglSwapInterval(c.eglCtx.disp, 0) + } + } else if c.eglWin == nilEGLNativeWindowType { return nil } - eglSurf, err := createSurfaceAndMakeCurrent(c.eglCtx, win) - c.eglSurf = eglSurf - if err != nil { - c.eglWin = nilEGLNativeWindowType - return err - } - // eglSwapInterval 1 leads to erratic frame rates and unnecessary blocking. - // We rely on platform specific frame rate limiting instead, except on Windows - // and X11 where eglSwapInterval is all there is. - if c.driver.needVSync() { - eglSwapInterval(c.eglCtx.disp, 1) - } else { - eglSwapInterval(c.eglCtx.disp, 0) - } if c.eglCtx.srgb { return nil }