diff --git a/gfx/layers/NativeLayerWayland.cpp b/gfx/layers/NativeLayerWayland.cpp index 293f744c3b9c..d942371fbd2c 100644 --- a/gfx/layers/NativeLayerWayland.cpp +++ b/gfx/layers/NativeLayerWayland.cpp @@ -40,41 +40,17 @@ NativeLayerRootWayland::NativeLayerRootWayland(MozContainer* aContainer) void NativeLayerRootWayland::EnsureSurfaceInitialized() { MutexAutoLock lock(mMutex); - if (mInitialized) { + if (mShmBuffer) { return; } - mEGLWindow = moz_container_wayland_get_egl_window(mContainer, 1); - if (!mEGLWindow) { - return; - } + mShmBuffer = widget::WaylandShmBuffer::Create(widget::WaylandDisplayGet(), + LayoutDeviceIntSize(1, 1)); + mShmBuffer->Clear(); - moz_container_wayland_egl_window_set_size(mContainer, 1, 1); - wp_viewport* viewporter = moz_container_wayland_get_viewport(mContainer); - wp_viewport_set_source(viewporter, wl_fixed_from_int(0), wl_fixed_from_int(0), - wl_fixed_from_int(1), wl_fixed_from_int(1)); - wp_viewport_set_destination(viewporter, 1, 1); - - // TODO: use shm-buffer instead of GL - GLContextEGL* gl = GLContextEGL::Cast(wr::RenderThread::Get()->SingletonGL()); - auto egl = gl->mEgl; - - mEGLSurface = egl->fCreateWindowSurface(gl->mConfig, mEGLWindow, nullptr); - MOZ_ASSERT(mEGLSurface != EGL_NO_SURFACE); - - gl->SetEGLSurfaceOverride(mEGLSurface); - gl->MakeCurrent(); - - gl->fClearColor(0.f, 0.f, 0.f, 0.f); - gl->fClear(LOCAL_GL_COLOR_BUFFER_BIT); - - egl->fSwapInterval(0); - egl->fSwapBuffers(mEGLSurface); - - gl->SetEGLSurfaceOverride(nullptr); - gl->MakeCurrent(); - - mInitialized = true; + wl_surface* wlSurface = moz_container_wayland_surface_lock(mContainer); + mShmBuffer->AttachAndCommit(wlSurface); + moz_container_wayland_surface_unlock(mContainer, &wlSurface); } already_AddRefed NativeLayerRootWayland::CreateLayer( @@ -320,9 +296,7 @@ bool NativeLayerRootWayland::CommitToScreen() { } } - if (mInitialized) { - wl_surface_commit(wlSurface); - } + wl_surface_commit(wlSurface); moz_container_wayland_surface_unlock(mContainer, &wlSurface); } @@ -337,12 +311,7 @@ void NativeLayerRootWayland::PauseCompositor() { UnmapLayer(layer); } - GLContextEGL* gl = GLContextEGL::Cast(wr::RenderThread::Get()->SingletonGL()); - auto egl = gl->mEgl; - egl->fDestroySurface(mEGLSurface); - mEGLSurface = nullptr; - mEGLWindow = nullptr; - mInitialized = false; + mShmBuffer = nullptr; } bool NativeLayerRootWayland::ResumeCompositor() { return true; } diff --git a/gfx/layers/NativeLayerWayland.h b/gfx/layers/NativeLayerWayland.h index c38124bd06e5..f97014e95905 100644 --- a/gfx/layers/NativeLayerWayland.h +++ b/gfx/layers/NativeLayerWayland.h @@ -14,6 +14,7 @@ #include "mozilla/layers/NativeLayer.h" #include "mozilla/layers/SurfacePoolWayland.h" #include "mozilla/widget/MozContainerWayland.h" +#include "mozilla/widget/WaylandShmBuffer.h" #include "nsRegion.h" #include "nsISupportsImpl.h" @@ -67,10 +68,7 @@ class NativeLayerRootWayland : public NativeLayerRoot { nsTArray> mSublayers; float mBackingScale = 1.0f; MozContainer* mContainer = nullptr; - bool mInitialized = false; - wl_egl_window* mEGLWindow = nullptr; - EGLSurface mEGLSurface = nullptr; - struct wp_viewport* mViewport = nullptr; + RefPtr mShmBuffer; }; class NativeLayerWayland : public NativeLayer { diff --git a/widget/gtk/moz.build b/widget/gtk/moz.build index f9ef6bd0770b..3369efa4e5b5 100644 --- a/widget/gtk/moz.build +++ b/widget/gtk/moz.build @@ -95,6 +95,7 @@ if CONFIG["MOZ_WAYLAND"]: "DMABufSurface.h", "MozContainerWayland.h", "nsWaylandDisplay.h", + "WaylandShmBuffer.h", ] if CONFIG["MOZ_X11"]: