Bug 1594950 - Remove unused SurfaceRegistry API. r=jrmuizel
authorMarkus Stange <mstange@themasta.com>
Wed, 13 Nov 2019 18:33:24 +0000
changeset 501817 25c597f8703fb05ceb531889a0a478bdebfd78fb
parent 501816 4391cb16bb0b291b02a1fc42a7295c564d76d9ec
child 501818 a65a260a14fe1950e0b061b12c62e55cea49df4a
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1594950
milestone72.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 1594950 - Remove unused SurfaceRegistry API. r=jrmuizel Differential Revision: https://phabricator.services.mozilla.com/D51758
gfx/layers/NativeLayerCA.h
gfx/layers/NativeLayerCA.mm
--- a/gfx/layers/NativeLayerCA.h
+++ b/gfx/layers/NativeLayerCA.h
@@ -29,27 +29,16 @@ namespace mozilla {
 
 namespace gl {
 class GLContextCGL;
 class MozFramebuffer;
 }  // namespace gl
 
 namespace layers {
 
-class IOSurfaceRegistry {
- public:
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(IOSurfaceRegistry)
-
-  virtual void RegisterSurface(CFTypeRefPtr<IOSurfaceRef> aSurface) = 0;
-  virtual void UnregisterSurface(CFTypeRefPtr<IOSurfaceRef> aSurface) = 0;
-
- protected:
-  virtual ~IOSurfaceRegistry() {}
-};
-
 // NativeLayerRootCA is the CoreAnimation implementation of the NativeLayerRoot
 // interface. A NativeLayerRootCA is created by the widget around an existing
 // CALayer with a call to CreateForCALayer.
 // All methods can be called from any thread, there is internal locking.
 // All effects from mutating methods are buffered locally and don't modify the
 // underlying CoreAnimation layers until ApplyChanges() is called. This ensures
 // that the modifications can be limited to run within a CoreAnimation
 // transaction, and on a thread of the caller's choosing.
@@ -86,23 +75,16 @@ class NativeLayerRootCA : public NativeL
 // All calls to mutating methods are buffered, and don't take effect on the
 // underlying CoreAnimation layers until ApplyChanges() is called.
 // The two most important methods are NextSurface and NotifySurfaceReady:
 // NextSurface takes an available surface from the swap chain or creates a new
 // surface if necessary. This surface can then be drawn to. Once drawing is
 // finished, NotifySurfaceReady marks the surface as ready. This surface is
 // committed to the layer during the next call to ApplyChanges().
 // The swap chain keeps track of invalid areas within the surfaces.
-//
-// Creation and destruction of IOSurface objects is broadcast to an optional
-// "surface registry" so that associated objects such as framebuffer objects
-// don't need to be recreated on every frame: Instead, the surface registry can
-// maintain one object per IOSurface in this layer's swap chain, and those
-// objects will be reused in different frames as the layer cycles through the
-// surfaces in its swap chain.
 class NativeLayerCA : public NativeLayer {
  public:
   virtual NativeLayerCA* AsNativeLayerCA() override { return this; }
 
   // Overridden methods
   gfx::IntSize GetSize() override;
   void SetPosition(const gfx::IntPoint& aPosition) override;
   gfx::IntPoint GetPosition() override;
@@ -117,34 +99,16 @@ class NativeLayerCA : public NativeLayer
   gfx::IntRegion CurrentSurfaceInvalidRegion() override;
   void NotifySurfaceReady() override;
   bool IsOpaque() override;
   void SetClipRect(const Maybe<gfx::IntRect>& aClipRect) override;
   Maybe<gfx::IntRect> ClipRect() override;
   void SetSurfaceIsFlipped(bool aIsFlipped) override;
   bool SurfaceIsFlipped() override;
 
-  // Consumers may provide an object that implements the IOSurfaceRegistry
-  // interface.
-  // The registry's methods, Register/UnregisterSurface, will be called
-  // synchronously during calls to NextSurface(), SetSurfaceRegistry(), and the
-  // NativeLayer destructor, on the thread that those things happen to run on.
-  // If this layer already owns surfaces when SetSurfaceRegistry gets called
-  // with a non-null surface registry, those surfaces will immediately
-  // (synchronously) be registered with that registry. If the current surface
-  // registry is unset (via a call to SetSurfaceRegistry with a different value,
-  // such as null), and the NativeLayer still owns surfaces, then those surfaces
-  // will immediately be unregistered.
-  // Since NativeLayer objects are reference counted and can be used from
-  // different threads, it is recommended to call SetSurfaceRegistry(nullptr)
-  // before destroying the NativeLayer so that the UnregisterSurface calls
-  // happen at a deterministic time and on the right thread.
-  void SetSurfaceRegistry(RefPtr<IOSurfaceRegistry> aSurfaceRegistry);
-  RefPtr<IOSurfaceRegistry> GetSurfaceRegistry();
-
  protected:
   friend class NativeLayerRootCA;
 
   NativeLayerCA(const gfx::IntSize& aSize, bool aIsOpaque);
   ~NativeLayerCA() override;
 
   // Returns an IOSurface that can be drawn to. The size of the IOSurface will
   // be the same as the size of this layer.
@@ -176,18 +140,16 @@ class NativeLayerCA : public NativeLayer
   };
 
   std::vector<SurfaceWithInvalidRegion> RemoveExcessUnusedSurfaces(
       const MutexAutoLock&);
 
   // Controls access to all fields of this class.
   Mutex mMutex;
 
-  RefPtr<IOSurfaceRegistry> mSurfaceRegistry;  // can be null
-
   // Each IOSurface is initially created inside NextSurface.
   // The surface stays alive until the recycling mechanism in NextSurface
   // determines it is no longer needed (because the swap chain has grown too
   // long) or until the layer is destroyed. During the surface's lifetime, it
   // will continuously move through the fields mInProgressSurface,
   // mReadySurface, and back to front through the mSurfaces queue:
   //
   //  mSurfaces.front()
--- a/gfx/layers/NativeLayerCA.mm
+++ b/gfx/layers/NativeLayerCA.mm
@@ -134,67 +134,31 @@ void NativeLayerRootCA::SetBackingScale(
     layer->SetBackingScale(aBackingScale);
   }
 }
 
 NativeLayerCA::NativeLayerCA(const IntSize& aSize, bool aIsOpaque)
     : mMutex("NativeLayerCA"), mSize(aSize), mIsOpaque(aIsOpaque) {}
 
 NativeLayerCA::~NativeLayerCA() {
-  SetSurfaceRegistry(nullptr);  // or maybe MOZ_RELEASE_ASSERT(!mSurfaceRegistry) would be better?
-
   if (mInProgressLockedIOSurface) {
     mInProgressLockedIOSurface->Unlock(false);
     mInProgressLockedIOSurface = nullptr;
   }
   if (mInProgressSurface) {
     IOSurfaceDecrementUseCount(mInProgressSurface->mSurface.get());
   }
   if (mReadySurface) {
     IOSurfaceDecrementUseCount(mReadySurface->mSurface.get());
   }
 
   [mContentCALayer release];
   [mWrappingCALayer release];
 }
 
-void NativeLayerCA::SetSurfaceRegistry(RefPtr<IOSurfaceRegistry> aSurfaceRegistry) {
-  MutexAutoLock lock(mMutex);
-
-  if (mSurfaceRegistry) {
-    for (auto surf : mSurfaces) {
-      mSurfaceRegistry->UnregisterSurface(surf.mSurface);
-    }
-    if (mInProgressSurface) {
-      mSurfaceRegistry->UnregisterSurface(mInProgressSurface->mSurface);
-    }
-    if (mReadySurface) {
-      mSurfaceRegistry->UnregisterSurface(mReadySurface->mSurface);
-    }
-  }
-  mSurfaceRegistry = aSurfaceRegistry;
-  if (mSurfaceRegistry) {
-    for (auto surf : mSurfaces) {
-      mSurfaceRegistry->RegisterSurface(surf.mSurface);
-    }
-    if (mInProgressSurface) {
-      mSurfaceRegistry->RegisterSurface(mInProgressSurface->mSurface);
-    }
-    if (mReadySurface) {
-      mSurfaceRegistry->RegisterSurface(mReadySurface->mSurface);
-    }
-  }
-}
-
-RefPtr<IOSurfaceRegistry> NativeLayerCA::GetSurfaceRegistry() {
-  MutexAutoLock lock(mMutex);
-
-  return mSurfaceRegistry;
-}
-
 void NativeLayerCA::SetSurfaceIsFlipped(bool aIsFlipped) {
   MutexAutoLock lock(mMutex);
 
   if (aIsFlipped != mSurfaceIsFlipped) {
     mSurfaceIsFlipped = aIsFlipped;
     mMutatedSurfaceIsFlipped = true;
   }
 }
@@ -310,27 +274,21 @@ CFTypeRefPtr<IOSurfaceRef> NativeLayerCA
           (__bridge NSString*)kIOSurfaceHeight : @(mSize.height),
           (__bridge NSString*)kIOSurfacePixelFormat : @(kCVPixelFormatType_32BGRA),
           (__bridge NSString*)kIOSurfaceBytesPerElement : @(4),
         }));
     if (!newSurf) {
       NSLog(@"NextSurface returning nullptr because IOSurfaceCreate failed to create the surface.");
       return nullptr;
     }
-    if (mSurfaceRegistry) {
-      mSurfaceRegistry->RegisterSurface(newSurf);
-    }
     surf = Some(SurfaceWithInvalidRegion{newSurf, IntRect({}, mSize)});
   }
 
   // Delete all other unused surfaces.
   for (auto unusedSurf : unusedSurfaces) {
-    if (mSurfaceRegistry) {
-      mSurfaceRegistry->UnregisterSurface(unusedSurf.mSurface);
-    }
     mFramebuffers.erase(unusedSurf.mSurface);
   }
   unusedSurfaces.clear();
 
   MOZ_RELEASE_ASSERT(surf);
   mInProgressSurface = std::move(surf);
   IOSurfaceIncrementUseCount(mInProgressSurface->mSurface.get());
   return mInProgressSurface->mSurface;