Bug 1548499 - Set EGL context before call to eglSwapInterval. r=sotaro
authorKenny Levinsen <kl@kl.wtf>
Fri, 24 May 2019 06:06:12 +0000
changeset 475570 25ba16a5d7f8805c0058ea55e75040d6c927867a
parent 475569 d0646b8b69e78adfa6f7893b3c96884d0d717b9b
child 475571 df9cfc6d49a493986659a78123a0584bbd4e4f61
push id113210
push userdvarga@mozilla.com
push dateSat, 25 May 2019 21:41:26 +0000
treeherdermozilla-inbound@edbf8267dd4f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssotaro
bugs1548499
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1548499 - Set EGL context before call to eglSwapInterval. r=sotaro The EGL context must be set before the call to eglSwapInterval to ensure that it will operate on the correct context. Differential Revision: https://phabricator.services.mozilla.com/D30282
gfx/webrender_bindings/RenderCompositorEGL.cpp
--- a/gfx/webrender_bindings/RenderCompositorEGL.cpp
+++ b/gfx/webrender_bindings/RenderCompositorEGL.cpp
@@ -54,33 +54,42 @@ EGLSurface RenderCompositorEGL::CreateEG
 RenderCompositorEGL::RenderCompositorEGL(
     RefPtr<widget::CompositorWidget> aWidget)
     : RenderCompositor(std::move(aWidget)), mEGLSurface(EGL_NO_SURFACE) {}
 
 RenderCompositorEGL::~RenderCompositorEGL() { DestroyEGLSurface(); }
 
 bool RenderCompositorEGL::BeginFrame() {
 #ifdef MOZ_WAYLAND
-  if (mWidget->AsX11() &&
-      mWidget->AsX11()->WaylandRequestsUpdatingEGLSurface()) {
-    // Destroy EGLSurface if it exists.
+  bool newSurface =
+      mWidget->AsX11() && mWidget->AsX11()->WaylandRequestsUpdatingEGLSurface();
+  if (newSurface) {
+    // Destroy EGLSurface if it exists and create a new one. We will set the
+    // swap interval after MakeCurrent() has been called.
     DestroyEGLSurface();
     mEGLSurface = CreateEGLSurface();
-    if (mEGLSurface) {
-      const auto* egl = gl::GLLibraryEGL::Get();
-      // Make eglSwapBuffers() non-blocking on wayland
-      egl->fSwapInterval(gl::EGL_DISPLAY(), 0);
-    }
   }
 #endif
   if (!MakeCurrent()) {
     gfxCriticalNote << "Failed to make render context current, can't draw.";
     return false;
   }
 
+#ifdef MOZ_WAYLAND
+  if (newSurface) {
+    // We have a new EGL surface, which on wayland needs to be configured for
+    // non-blocking buffer swaps. We need MakeCurrent() to set our current EGL
+    // context before we call eglSwapInterval, which is why we do it here rather
+    // than where the surface was created.
+    const auto* egl = gl::GLLibraryEGL::Get();
+    // Make eglSwapBuffers() non-blocking on wayland.
+    egl->fSwapInterval(gl::EGL_DISPLAY(), 0);
+  }
+#endif
+
 #ifdef MOZ_WIDGET_ANDROID
   java::GeckoSurfaceTexture::DestroyUnused((int64_t)gl());
 #endif
 
   return true;
 }
 
 void RenderCompositorEGL::EndFrame() {