Bug 1711214 - Some cleanups in NativeLayerWayland and SurfacePoolWayland, r=aosmond
authorRobert Mader <robert.mader@posteo.de>
Mon, 17 May 2021 12:20:19 +0000
changeset 579762 99a8ee75c63dc69b47e614c2c23527d9888d48b7
parent 579761 265d1b80d9d629315babb708548b2e428cd15b50
child 579763 5db410a50b08d7c65410207b442e0fdeac83e2a2
push id38468
push userapavel@mozilla.com
push dateMon, 17 May 2021 21:26:00 +0000
treeherdermozilla-central@50c8711162bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaosmond
bugs1711214
milestone90.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 1711214 - Some cleanups in NativeLayerWayland and SurfacePoolWayland, r=aosmond To make the code nicer to read. No functional changes intended. Depends on D115139 Differential Revision: https://phabricator.services.mozilla.com/D115145
gfx/layers/NativeLayerWayland.cpp
gfx/layers/NativeLayerWayland.h
gfx/layers/SurfacePoolWayland.cpp
gfx/layers/SurfacePoolWayland.h
--- a/gfx/layers/NativeLayerWayland.cpp
+++ b/gfx/layers/NativeLayerWayland.cpp
@@ -11,21 +11,16 @@
 #include "GLContextEGL.h"
 #include "GLContextProvider.h"
 #include "mozilla/layers/SurfacePoolWayland.h"
 #include "mozilla/StaticPrefs_widget.h"
 #include "mozilla/webrender/RenderThread.h"
 
 namespace mozilla::layers {
 
-using gfx::IntPoint;
-using gfx::IntRect;
-using gfx::IntRegion;
-using gfx::IntSize;
-using gfx::Matrix4x4;
 using gfx::Point;
 using gfx::Rect;
 using gfx::Size;
 using gl::GLContextEGL;
 
 /* static */
 already_AddRefed<NativeLayerRootWayland>
 NativeLayerRootWayland::CreateForMozContainer(MozContainer* aContainer) {
@@ -388,18 +383,17 @@ void NativeLayerWayland::SetTransform(co
   MutexAutoLock lock(mMutex);
   MOZ_ASSERT(aTransform.IsRectilinear());
 
   if (aTransform != mTransform) {
     mTransform = aTransform;
   }
 }
 
-void NativeLayerWayland::SetSamplingFilter(
-    gfx::SamplingFilter aSamplingFilter) {
+void NativeLayerWayland::SetSamplingFilter(SamplingFilter aSamplingFilter) {
   MutexAutoLock lock(mMutex);
 
   if (aSamplingFilter != mSamplingFilter) {
     mSamplingFilter = aSamplingFilter;
   }
 }
 
 Matrix4x4 NativeLayerWayland::GetTransform() {
@@ -420,50 +414,49 @@ void NativeLayerWayland::SetBackingScale
   }
 }
 
 bool NativeLayerWayland::IsOpaque() {
   MutexAutoLock lock(mMutex);
   return mIsOpaque;
 }
 
-void NativeLayerWayland::SetClipRect(const Maybe<gfx::IntRect>& aClipRect) {
+void NativeLayerWayland::SetClipRect(const Maybe<IntRect>& aClipRect) {
   MutexAutoLock lock(mMutex);
 
   if (aClipRect != mClipRect) {
     mClipRect = aClipRect;
   }
 }
 
-Maybe<gfx::IntRect> NativeLayerWayland::ClipRect() {
+Maybe<IntRect> NativeLayerWayland::ClipRect() {
   MutexAutoLock lock(mMutex);
   return mClipRect;
 }
 
-gfx::IntRect NativeLayerWayland::CurrentSurfaceDisplayRect() {
+IntRect NativeLayerWayland::CurrentSurfaceDisplayRect() {
   MutexAutoLock lock(mMutex);
   return mDisplayRect;
 }
 
-RefPtr<gfx::DrawTarget> NativeLayerWayland::NextSurfaceAsDrawTarget(
+RefPtr<DrawTarget> NativeLayerWayland::NextSurfaceAsDrawTarget(
     const IntRect& aDisplayRect, const IntRegion& aUpdateRegion,
-    gfx::BackendType aBackendType) {
+    BackendType aBackendType) {
   MOZ_ASSERT(false);
   return nullptr;
 }
 
 Maybe<GLuint> NativeLayerWayland::NextSurfaceAsFramebuffer(
     const IntRect& aDisplayRect, const IntRegion& aUpdateRegion,
     bool aNeedsDepth) {
   MutexAutoLock lock(mMutex);
 
   mValidRect = IntRect(aDisplayRect);
   mDirtyRegion = IntRegion(aUpdateRegion);
 
-  MOZ_ASSERT(!mSize.IsEmpty());
   if (!mNativeSurface) {
     mNativeSurface = mSurfacePoolHandle->ObtainSurfaceFromPool(mSize);
   }
   GLContextEGL* gl = GLContextEGL::Cast(mSurfacePoolHandle->gl());
 
   gl->SetEGLSurfaceOverride(mNativeSurface->GetEGLSurface());
   gl->MakeCurrent();
 
--- a/gfx/layers/NativeLayerWayland.h
+++ b/gfx/layers/NativeLayerWayland.h
@@ -13,32 +13,35 @@
 
 #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"
 
-namespace mozilla {
+namespace mozilla::layers {
 
-namespace gl {
-class GLContextEGL;
-}  // namespace gl
-
-namespace layers {
+using gfx::BackendType;
+using gfx::DrawTarget;
+using gfx::IntPoint;
+using gfx::IntRect;
+using gfx::IntRegion;
+using gfx::IntSize;
+using gfx::Matrix4x4;
+using gfx::SamplingFilter;
 
 class NativeLayerRootWayland : public NativeLayerRoot {
  public:
   static already_AddRefed<NativeLayerRootWayland> CreateForMozContainer(
       MozContainer* aContainer);
 
   // Overridden methods
   already_AddRefed<NativeLayer> CreateLayer(
-      const gfx::IntSize& aSize, bool aIsOpaque,
+      const IntSize& aSize, bool aIsOpaque,
       SurfacePoolHandle* aSurfacePoolHandle) override;
   void AppendLayer(NativeLayer* aLayer) override;
   void RemoveLayer(NativeLayer* aLayer) override;
   void SetLayers(const nsTArray<RefPtr<NativeLayer>>& aLayers) override;
   UniquePtr<NativeLayerRootSnapshotter> CreateSnapshotter() override;
   bool CommitToScreen() override;
 
   // When the compositor is paused the wl_surface of the MozContainer will
@@ -71,65 +74,64 @@ class NativeLayerRootWayland : public Na
   RefPtr<widget::WaylandShmBuffer> mShmBuffer;
 };
 
 class NativeLayerWayland : public NativeLayer {
  public:
   virtual NativeLayerWayland* AsNativeLayerWayland() override { return this; }
 
   // Overridden methods
-  gfx::IntSize GetSize() override;
-  void SetPosition(const gfx::IntPoint& aPosition) override;
-  gfx::IntPoint GetPosition() override;
-  void SetTransform(const gfx::Matrix4x4& aTransform) override;
-  gfx::Matrix4x4 GetTransform() override;
-  gfx::IntRect GetRect() override;
-  void SetSamplingFilter(gfx::SamplingFilter aSamplingFilter) override;
-  RefPtr<gfx::DrawTarget> NextSurfaceAsDrawTarget(
-      const gfx::IntRect& aDisplayRect, const gfx::IntRegion& aUpdateRegion,
-      gfx::BackendType aBackendType) override;
-  Maybe<GLuint> NextSurfaceAsFramebuffer(const gfx::IntRect& aDisplayRect,
-                                         const gfx::IntRegion& aUpdateRegion,
+  IntSize GetSize() override;
+  void SetPosition(const IntPoint& aPosition) override;
+  IntPoint GetPosition() override;
+  void SetTransform(const Matrix4x4& aTransform) override;
+  Matrix4x4 GetTransform() override;
+  IntRect GetRect() override;
+  void SetSamplingFilter(SamplingFilter aSamplingFilter) override;
+  RefPtr<DrawTarget> NextSurfaceAsDrawTarget(const IntRect& aDisplayRect,
+                                             const IntRegion& aUpdateRegion,
+                                             BackendType aBackendType) override;
+  Maybe<GLuint> NextSurfaceAsFramebuffer(const IntRect& aDisplayRect,
+                                         const IntRegion& aUpdateRegion,
                                          bool aNeedsDepth) override;
   void NotifySurfaceReady() override;
   void DiscardBackbuffers() override;
   bool IsOpaque() override;
-  void SetClipRect(const Maybe<gfx::IntRect>& aClipRect) override;
-  Maybe<gfx::IntRect> ClipRect() override;
-  gfx::IntRect CurrentSurfaceDisplayRect() override;
+  void SetClipRect(const Maybe<IntRect>& aClipRect) override;
+  Maybe<IntRect> ClipRect() override;
+  IntRect CurrentSurfaceDisplayRect() override;
   void SetSurfaceIsFlipped(bool aIsFlipped) override;
   bool SurfaceIsFlipped() override;
 
   void AttachExternalImage(wr::RenderTextureHost* aExternalImage) override;
 
   void SetBackingScale(float aBackingScale);
 
  protected:
   friend class NativeLayerRootWayland;
 
-  NativeLayerWayland(const gfx::IntSize& aSize, bool aIsOpaque,
+  NativeLayerWayland(const IntSize& aSize, bool aIsOpaque,
                      SurfacePoolHandleWayland* aSurfacePoolHandle);
   explicit NativeLayerWayland(bool aIsOpaque);
   ~NativeLayerWayland() override;
 
   Mutex mMutex;
 
   RefPtr<SurfacePoolHandleWayland> mSurfacePoolHandle;
-  gfx::IntPoint mPosition;
-  gfx::Matrix4x4 mTransform;
-  gfx::IntRect mDisplayRect;
-  gfx::IntRect mValidRect;
-  gfx::IntRegion mDirtyRegion;
-  gfx::IntSize mSize;
-  Maybe<gfx::IntRect> mClipRect;
-  gfx::SamplingFilter mSamplingFilter = gfx::SamplingFilter::POINT;
+  IntPoint mPosition;
+  Matrix4x4 mTransform;
+  IntRect mDisplayRect;
+  IntRect mValidRect;
+  IntRegion mDirtyRegion;
+  IntSize mSize;
+  Maybe<IntRect> mClipRect;
+  SamplingFilter mSamplingFilter = SamplingFilter::POINT;
   float mBackingScale = 1.0f;
   bool mSurfaceIsFlipped = false;
   const bool mIsOpaque = false;
   bool mIsShown = false;
 
   RefPtr<NativeSurfaceWayland> mNativeSurface;
 };
 
-}  // namespace layers
-}  // namespace mozilla
+}  // namespace mozilla::layers
 
 #endif  // mozilla_layers_NativeLayerWayland_h
--- a/gfx/layers/SurfacePoolWayland.cpp
+++ b/gfx/layers/SurfacePoolWayland.cpp
@@ -4,21 +4,19 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/layers/SurfacePoolWayland.h"
 
 #include "GLContextEGL.h"
 
 namespace mozilla::layers {
 
-using gl::GLContext;
 using gl::GLContextEGL;
 
-NativeSurfaceWayland::NativeSurfaceWayland(const gfx::IntSize& aSize,
-                                           GLContext* aGL)
+NativeSurfaceWayland::NativeSurfaceWayland(const IntSize& aSize, GLContext* aGL)
     : mGL(aGL) {
   wl_compositor* compositor = widget::WaylandDisplayGet()->GetCompositor();
   mWlSurface = wl_compositor_create_surface(compositor);
 
   wl_region* region = wl_compositor_create_region(compositor);
   wl_surface_set_input_region(mWlSurface, region);
   wl_region_destroy(region);
 
@@ -55,22 +53,22 @@ RefPtr<SurfacePoolHandle> SurfacePoolWay
 
 void SurfacePoolWayland::DestroyGLResourcesForContext(GLContext* aGL) {
   // Assume a single shared GL context for now
   MOZ_ASSERT(mInUseEntries.empty());
   mAvailableEntries.Clear();
 }
 
 bool SurfacePoolWayland::CanRecycleSurfaceForRequest(
-    const SurfacePoolEntry& aEntry, const gfx::IntSize& aSize, GLContext* aGL) {
+    const SurfacePoolEntry& aEntry, const IntSize& aSize, GLContext* aGL) {
   return aEntry.mSize == aSize;
 }
 
 RefPtr<NativeSurfaceWayland> SurfacePoolWayland::ObtainSurfaceFromPool(
-    const gfx::IntSize& aSize, GLContext* aGL) {
+    const IntSize& aSize, GLContext* aGL) {
   auto iterToRecycle =
       std::find_if(mAvailableEntries.begin(), mAvailableEntries.end(),
                    [&](const SurfacePoolEntry& aEntry) {
                      return CanRecycleSurfaceForRequest(aEntry, aSize, aGL);
                    });
   if (iterToRecycle != mAvailableEntries.end()) {
     RefPtr<NativeSurfaceWayland> surface = iterToRecycle->mNativeSurface;
     mInUseEntries.insert({surface.get(), std::move(*iterToRecycle)});
@@ -107,17 +105,17 @@ SurfacePoolHandleWayland::SurfacePoolHan
     RefPtr<SurfacePoolWayland> aPool, GLContext* aGL)
     : mPool(std::move(aPool)), mGL(aGL) {}
 
 void SurfacePoolHandleWayland::OnBeginFrame() {}
 
 void SurfacePoolHandleWayland::OnEndFrame() { mPool->EnforcePoolSizeLimit(); }
 
 RefPtr<NativeSurfaceWayland> SurfacePoolHandleWayland::ObtainSurfaceFromPool(
-    const gfx::IntSize& aSize) {
+    const IntSize& aSize) {
   return mPool->ObtainSurfaceFromPool(aSize, mGL);
 }
 
 void SurfacePoolHandleWayland::ReturnSurfaceToPool(
     const RefPtr<NativeSurfaceWayland>& aSurface) {
   mPool->ReturnSurfaceToPool(aSurface);
 }
 
--- a/gfx/layers/SurfacePoolWayland.h
+++ b/gfx/layers/SurfacePoolWayland.h
@@ -6,67 +6,67 @@
 #ifndef mozilla_layers_SurfacePoolWayland_h
 #define mozilla_layers_SurfacePoolWayland_h
 
 #include <wayland-egl.h>
 
 #include "mozilla/layers/SurfacePool.h"
 #include "mozilla/widget/nsWaylandDisplay.h"
 
-namespace mozilla {
+namespace mozilla::layers {
 
-namespace layers {
+using gfx::IntSize;
+using gl::GLContext;
 
 class NativeSurfaceWayland {
  public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(NativeSurfaceWayland);
 
   EGLSurface GetEGLSurface() { return mEGLSurface; }
 
   struct wl_surface* mWlSurface = nullptr;
   struct wl_subsurface* mWlSubsurface = nullptr;
   struct wp_viewport* mViewport = nullptr;
 
  private:
   friend class SurfacePoolWayland;
-  NativeSurfaceWayland(const gfx::IntSize& aSize, gl::GLContext* aGL);
+  NativeSurfaceWayland(const IntSize& aSize, GLContext* aGL);
   ~NativeSurfaceWayland();
 
-  gl::GLContext* mGL = nullptr;
+  GLContext* mGL = nullptr;
   struct wl_egl_window* mEGLWindow = nullptr;
   EGLSurface mEGLSurface = nullptr;
 };
 
 class SurfacePoolWayland final : public SurfacePool {
  public:
   // Get a handle for a new window. aGL can be nullptr.
-  RefPtr<SurfacePoolHandle> GetHandleForGL(gl::GLContext* aGL) override;
+  RefPtr<SurfacePoolHandle> GetHandleForGL(GLContext* aGL) override;
 
   // Destroy all GL resources associated with aGL managed by this pool.
-  void DestroyGLResourcesForContext(gl::GLContext* aGL) override;
+  void DestroyGLResourcesForContext(GLContext* aGL) override;
 
  private:
   friend class SurfacePoolHandleWayland;
   friend RefPtr<SurfacePool> SurfacePool::Create(size_t aPoolSizeLimit);
 
   explicit SurfacePoolWayland(size_t aPoolSizeLimit);
 
-  RefPtr<NativeSurfaceWayland> ObtainSurfaceFromPool(const gfx::IntSize& aSize,
-                                                     gl::GLContext* aGL);
+  RefPtr<NativeSurfaceWayland> ObtainSurfaceFromPool(const IntSize& aSize,
+                                                     GLContext* aGL);
   void ReturnSurfaceToPool(const RefPtr<NativeSurfaceWayland>& aSurface);
   void EnforcePoolSizeLimit();
 
   struct SurfacePoolEntry {
-    gfx::IntSize mSize;
+    IntSize mSize;
     RefPtr<NativeSurfaceWayland> mNativeSurface;  // non-null
   };
 
   bool CanRecycleSurfaceForRequest(const SurfacePoolEntry& aEntry,
-                                   const gfx::IntSize& aSize,
-                                   gl::GLContext* aGL);
+                                   const IntSize& aSize, GLContext* aGL);
 
   // Stores the entries for surfaces that are in use by NativeLayerWayland, i.e.
   // an entry is inside mInUseEntries between calls to ObtainSurfaceFromPool()
   // and ReturnSurfaceToPool().
   std::unordered_map<NativeSurfaceWayland*, SurfacePoolEntry> mInUseEntries;
 
   // Stores entries which are no longer in use by NativeLayerWayland but are
   // still in use by the window server, i.e. for which
@@ -86,29 +86,27 @@ class SurfacePoolWayland final : public 
 // A surface pool handle that is stored on NativeLayerWayland and keeps the
 // SurfacePool alive.
 class SurfacePoolHandleWayland final : public SurfacePoolHandle {
  public:
   SurfacePoolHandleWayland* AsSurfacePoolHandleWayland() override {
     return this;
   }
 
-  RefPtr<NativeSurfaceWayland> ObtainSurfaceFromPool(const gfx::IntSize& aSize);
+  RefPtr<NativeSurfaceWayland> ObtainSurfaceFromPool(const IntSize& aSize);
   void ReturnSurfaceToPool(const RefPtr<NativeSurfaceWayland>& aSurface);
   const auto& gl() { return mGL; }
 
   RefPtr<SurfacePool> Pool() override { return mPool; }
   void OnBeginFrame() override;
   void OnEndFrame() override;
 
  private:
   friend class SurfacePoolWayland;
-  SurfacePoolHandleWayland(RefPtr<SurfacePoolWayland> aPool,
-                           gl::GLContext* aGL);
+  SurfacePoolHandleWayland(RefPtr<SurfacePoolWayland> aPool, GLContext* aGL);
 
   const RefPtr<SurfacePoolWayland> mPool;
-  const RefPtr<gl::GLContext> mGL;
+  const RefPtr<GLContext> mGL;
 };
 
-}  // namespace layers
-}  // namespace mozilla
+}  // namespace mozilla::layers
 
 #endif