Use normal refcounting for ISurfaceAllocator. (bug 1287232, r=billm)
authorDavid Anderson <danderson@mozilla.com>
Tue, 19 Jul 2016 16:59:30 -0700
changeset 345784 a46d84c52f89110162c4f292d646521bd6efc676
parent 345783 0fadabf932c25817f2b8f218532171b82ac96280
child 345785 4de50147d99cb9c51d11f0eaaac6663950f381ee
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1287232
milestone50.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
Use normal refcounting for ISurfaceAllocator. (bug 1287232, r=billm)
gfx/layers/AtomicRefCountedWithFinalize.h
gfx/layers/ipc/CompositableForwarder.h
gfx/layers/ipc/CompositableTransactionParent.h
gfx/layers/ipc/CompositorBridgeChild.cpp
gfx/layers/ipc/CompositorBridgeParent.cpp
gfx/layers/ipc/ISurfaceAllocator.h
gfx/layers/ipc/ImageBridgeChild.cpp
gfx/layers/ipc/ImageBridgeParent.cpp
gfx/layers/ipc/LayerTransactionParent.cpp
gfx/layers/ipc/LayerTransactionParent.h
gfx/layers/ipc/ShadowLayers.cpp
gfx/layers/ipc/TextureForwarder.cpp
gfx/layers/ipc/TextureForwarder.h
--- a/gfx/layers/AtomicRefCountedWithFinalize.h
+++ b/gfx/layers/AtomicRefCountedWithFinalize.h
@@ -31,41 +31,30 @@ class RefQueue;
 
 template<typename T>
 class AtomicRefCountedWithFinalize
 {
 protected:
     explicit AtomicRefCountedWithFinalize(const char* aName)
       : mRecycleCallback(nullptr)
       , mRefCount(0)
-      , mMessageLoopToPostDestructionTo(nullptr)
 #ifdef DEBUG
       , mSpew(false)
       , mManualAddRefs(0)
       , mManualReleases(0)
       , mName(aName)
 #endif
     {}
 
     ~AtomicRefCountedWithFinalize() {
       if (mRefCount >= 0) {
         gfxCriticalError() << "Deleting referenced object? " << mRefCount;
       }
     }
 
-    void SetMessageLoopToPostDestructionTo(MessageLoop* l) {
-      MOZ_ASSERT(NS_IsMainThread());
-      mMessageLoopToPostDestructionTo = l;
-    }
-
-    static void DestroyToBeCalledOnMainThread(T* ptr) {
-      MOZ_ASSERT(NS_IsMainThread());
-      delete ptr;
-    }
-
 public:
     // Mark user classes that are considered flawless.
     template<class U>
     friend class ::mozilla::StaticRefPtr;
 
     template<class U>
     friend struct mozilla::RefPtrTraits;
 
@@ -139,26 +128,17 @@ private:
           gfxCriticalError() << "About to release with valid callback";
           mRecycleCallback = nullptr;
         }
 
         MOZ_ASSERT(mManualAddRefs == mManualReleases);
 
         T* derived = static_cast<T*>(this);
         derived->Finalize();
-        if (MOZ_LIKELY(!mMessageLoopToPostDestructionTo)) {
-          delete derived;
-        } else {
-          if (MOZ_LIKELY(NS_IsMainThread())) {
-            delete derived;
-          } else {
-            mMessageLoopToPostDestructionTo->PostTask(
-              NewRunnableFunction(&DestroyToBeCalledOnMainThread, derived));
-          }
-        }
+        delete derived;
       } else if (1 == currCount && recycleCallback) {
         // There is nothing enforcing this in the code, except how the callers
         // are being careful to never let the reference count go down if there
         // is a callback.
         MOZ_ASSERT(!IsDead());
         T* derived = static_cast<T*>(this);
         recycleCallback(derived, mClosure);
       }
@@ -192,17 +172,16 @@ public:
     {
       return mRefCount < 0;
     }
 
 private:
     RecycleCallback mRecycleCallback;
     void *mClosure;
     Atomic<int> mRefCount;
-    MessageLoop *mMessageLoopToPostDestructionTo;
 #ifdef DEBUG
 public:
     bool mSpew;
 private:
     Atomic<uint32_t> mManualAddRefs;
     Atomic<uint32_t> mManualReleases;
     const char* mName;
 #endif
--- a/gfx/layers/ipc/CompositableForwarder.h
+++ b/gfx/layers/ipc/CompositableForwarder.h
@@ -73,19 +73,18 @@ public:
  * ShadowLayerForwarder is an example of a CompositableForwarder (that can
  * additionally forward modifications of the Layer tree).
  * ImageBridgeChild is another CompositableForwarder.
  */
 class CompositableForwarder : public TextureForwarder
 {
 public:
 
-  CompositableForwarder(const char* aName)
-    : TextureForwarder(aName)
-    , mActiveResourceTracker(1000, "CompositableForwarder")
+  CompositableForwarder()
+    : mActiveResourceTracker(1000, "CompositableForwarder")
     , mSerial(++sSerialCounter)
   {}
 
   /**
    * Setup the IPDL actor for aCompositable to be part of layers
    * transactions.
    */
   virtual void Connect(CompositableClient* aCompositable,
--- a/gfx/layers/ipc/CompositableTransactionParent.h
+++ b/gfx/layers/ipc/CompositableTransactionParent.h
@@ -23,17 +23,17 @@ typedef std::vector<mozilla::layers::Edi
 
 // Since PCompositble has two potential manager protocols, we can't just call
 // the Manager() method usually generated when there's one manager protocol,
 // so both manager protocols implement this and we keep a reference to them
 // through this interface.
 class CompositableParentManager : public HostIPCAllocator
 {
 public:
-  CompositableParentManager(const char* aName) : HostIPCAllocator(aName) {}
+  CompositableParentManager() {}
 
   void DestroyActor(const OpDestroy& aOp);
 
   void UpdateFwdTransactionId(uint64_t aTransactionId)
   {
     MOZ_ASSERT(mFwdTransactionId < aTransactionId);
     mFwdTransactionId = aTransactionId;
   }
--- a/gfx/layers/ipc/CompositorBridgeChild.cpp
+++ b/gfx/layers/ipc/CompositorBridgeChild.cpp
@@ -43,26 +43,22 @@ using mozilla::Unused;
 namespace mozilla {
 namespace layers {
 
 static StaticRefPtr<CompositorBridgeChild> sCompositorBridge;
 
 Atomic<int32_t> CompositableForwarder::sSerialCounter(0);
 
 CompositorBridgeChild::CompositorBridgeChild(ClientLayerManager *aLayerManager)
-  : TextureForwarder("CompositorBridgeChild")
-  , mLayerManager(aLayerManager)
+  : mLayerManager(aLayerManager)
   , mCanSend(false)
   , mFwdTransactionId(0)
   , mMessageLoop(MessageLoop::current())
 {
   MOZ_ASSERT(NS_IsMainThread());
-
-  // Ensure destruction on the main thread
-  SetMessageLoopToPostDestructionTo(mMessageLoop);
 }
 
 CompositorBridgeChild::~CompositorBridgeChild()
 {
   if (mCanSend) {
     gfxCriticalError() << "CompositorBridgeChild was not deinitialized";
   }
 }
@@ -82,17 +78,16 @@ static void DeferredDestroyCompositor(Re
     sCompositorBridge = nullptr;
   }
 }
 
 void
 CompositorBridgeChild::Destroy()
 {
   // This must not be called from the destructor!
-  MOZ_ASSERT(!IsDead());
   mTexturesWaitingRecycled.Clear();
 
   if (!mCanSend) {
     return;
   }
 
   for (size_t i = 0; i < mTexturePools.Length(); i++) {
     mTexturePools[i]->Destroy();
--- a/gfx/layers/ipc/CompositorBridgeParent.cpp
+++ b/gfx/layers/ipc/CompositorBridgeParent.cpp
@@ -599,18 +599,17 @@ static inline MessageLoop*
 CompositorLoop()
 {
   return CompositorThreadHolder::Loop();
 }
 
 CompositorBridgeParent::CompositorBridgeParent(CSSToLayoutDeviceScale aScale,
                                                bool aUseExternalSurfaceSize,
                                                const gfx::IntSize& aSurfaceSize)
-  : CompositorBridgeParentIPCAllocator("CompositorBridgeParent")
-  , mWidget(nullptr)
+  : mWidget(nullptr)
   , mScale(aScale)
   , mIsTesting(false)
   , mPendingTransaction(0)
   , mPaused(false)
   , mUseExternalSurfaceSize(aUseExternalSurfaceSize)
   , mEGLSurfaceSize(aSurfaceSize)
   , mPauseCompositionMonitor("PauseCompositionMonitor")
   , mResumeCompositionMonitor("ResumeCompositionMonitor")
@@ -623,17 +622,16 @@ CompositorBridgeParent::CompositorBridge
 #if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
   , mLastPluginUpdateLayerTreeId(0)
   , mDeferPluginWindows(false)
   , mPluginWindowsHidden(false)
 #endif
 {
   // Always run destructor on the main thread
   MOZ_ASSERT(NS_IsMainThread());
-  SetMessageLoopToPostDestructionTo(MessageLoop::current());
 }
 
 void
 CompositorBridgeParent::InitSameProcess(widget::CompositorWidget* aWidget,
                                         const uint64_t& aLayerTreeId,
                                         bool aUseAPZ)
 {
   mWidget = aWidget;
@@ -699,18 +697,16 @@ uint64_t
 CompositorBridgeParent::RootLayerTreeId()
 {
   MOZ_ASSERT(mRootLayerTreeID);
   return mRootLayerTreeID;
 }
 
 CompositorBridgeParent::~CompositorBridgeParent()
 {
-  MOZ_ASSERT(NS_IsMainThread());
-
   InfallibleTArray<PTextureParent*> textures;
   ManagedPTextureParent(textures);
   // We expect all textures to be destroyed by now.
   MOZ_DIAGNOSTIC_ASSERT(textures.Length() == 0);
   for (unsigned int i = 0; i < textures.Length(); ++i) {
     RefPtr<TextureHost> tex = TextureHost::AsTextureHost(textures[i]);
     tex->DeallocateDeviceData();
   }
@@ -1964,23 +1960,20 @@ class CrossProcessCompositorBridgeParent
                                                  public ShadowLayersManager,
                                                  public CompositorBridgeParentIPCAllocator,
                                                  public ShmemAllocator
 {
   friend class CompositorBridgeParent;
 
 public:
   explicit CrossProcessCompositorBridgeParent()
-    : CompositorBridgeParentIPCAllocator("CrossProcessCompositorBridgeParent")
-    , mNotifyAfterRemotePaint(false)
+    : mNotifyAfterRemotePaint(false)
     , mDestroyCalled(false)
   {
     MOZ_ASSERT(NS_IsMainThread());
-    // Always run destructor on the main thread
-    SetMessageLoopToPostDestructionTo(MessageLoop::current());
   }
 
   void Bind(Endpoint<PCompositorBridgeParent>&& aEndpoint) {
     if (!aEndpoint.Bind(this, nullptr)) {
       return;
     }
     mSelfRef = this;
   }
@@ -2908,17 +2901,16 @@ void
 CrossProcessCompositorBridgeParent::DeferredDestroy()
 {
   mCompositorThreadHolder = nullptr;
   mSelfRef = nullptr;
 }
 
 CrossProcessCompositorBridgeParent::~CrossProcessCompositorBridgeParent()
 {
-  MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(XRE_GetIOMessageLoop());
   MOZ_ASSERT(IToplevelProtocol::GetTransport());
 }
 
 IToplevelProtocol*
 CrossProcessCompositorBridgeParent::CloneToplevel(
   const InfallibleTArray<mozilla::ipc::ProtocolFdMapping>& aFds,
   base::ProcessHandle aPeerProcess,
--- a/gfx/layers/ipc/ISurfaceAllocator.h
+++ b/gfx/layers/ipc/ISurfaceAllocator.h
@@ -11,17 +11,16 @@
 #include "gfxTypes.h"
 #include "mozilla/gfx/Point.h"          // for IntSize
 #include "mozilla/ipc/SharedMemory.h"   // for SharedMemory, etc
 #include "mozilla/RefPtr.h"
 #include "nsIMemoryReporter.h"          // for nsIMemoryReporter
 #include "mozilla/Atomics.h"            // for Atomic
 #include "mozilla/layers/LayersMessages.h" // for ShmemSection
 #include "LayersTypes.h"
-#include "mozilla/layers/AtomicRefCountedWithFinalize.h"
 
 /*
  * FIXME [bjacob] *** PURE CRAZYNESS WARNING ***
  * (I think that this doesn't apply anymore.)
  *
  * This #define is actually needed here, because subclasses of ISurfaceAllocator,
  * namely ShadowLayerForwarder, will or will not override AllocGrallocBuffer
  * depending on whether MOZ_HAVE_SURFACEDESCRIPTORGRALLOC is defined.
@@ -71,22 +70,23 @@ mozilla::ipc::SharedMemory::SharedMemory
  * An interface used to create and destroy surfaces that are shared with the
  * Compositor process (using shmem, or gralloc, or other platform specific memory)
  *
  * Most of the methods here correspond to methods that are implemented by IPDL
  * actors without a common polymorphic interface.
  * These methods should be only called in the ipdl implementor's thread, unless
  * specified otherwise in the implementing class.
  */
-class ISurfaceAllocator : public AtomicRefCountedWithFinalize<ISurfaceAllocator>
+class ISurfaceAllocator
 {
 public:
   MOZ_DECLARE_REFCOUNTED_TYPENAME(ISurfaceAllocator)
+  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ISurfaceAllocator)
 
-  ISurfaceAllocator(const char* aName) : AtomicRefCountedWithFinalize(aName) {}
+  ISurfaceAllocator() {}
 
   // down-casting
 
   virtual ShmemAllocator* AsShmemAllocator() { return nullptr; }
 
   virtual ShmemSectionAllocator* AsShmemSectionAllocator() { return nullptr; }
 
   virtual CompositableForwarder* AsCompositableForwarder() { return nullptr; }
@@ -109,42 +109,40 @@ public:
   virtual bool IsSameProcess() const = 0;
 
   virtual bool UsesImageBridge() const { return false; }
 
 protected:
   void Finalize() {}
 
   virtual ~ISurfaceAllocator() {}
-
-  friend class AtomicRefCountedWithFinalize<ISurfaceAllocator>;
 };
 
 /// Methods that are specific to the client/child side.
 class ClientIPCAllocator : public ISurfaceAllocator
 {
 public:
-  ClientIPCAllocator(const char* aName) : ISurfaceAllocator(aName) {}
+  ClientIPCAllocator() {}
 
   virtual ClientIPCAllocator* AsClientAllocator() override { return this; }
 
   virtual base::ProcessId GetParentPid() const = 0;
 
   virtual MessageLoop * GetMessageLoop() const = 0;
 
   virtual int32_t GetMaxTextureSize() const;
 
   virtual void CancelWaitForRecycle(uint64_t aTextureId) = 0;
 };
 
 /// Methods that are specific to the host/parent side.
 class HostIPCAllocator : public ISurfaceAllocator
 {
 public:
-  HostIPCAllocator(const char* aName) : ISurfaceAllocator(aName) {}
+  HostIPCAllocator() {}
 
   virtual HostIPCAllocator* AsHostIPCAllocator() override { return this; }
 
   /**
    * Get child side's process Id.
    */
   virtual base::ProcessId GetChildProcessId() = 0;
 
@@ -170,17 +168,17 @@ protected:
   std::vector<AsyncParentMessageData> mPendingAsyncMessage;
   bool mAboutToSendAsyncMessages = false;
 };
 
 /// Specific to the CompositorBridgeParent/CrossProcessCompositorBridgeParent.
 class CompositorBridgeParentIPCAllocator : public HostIPCAllocator
 {
 public:
-  CompositorBridgeParentIPCAllocator(const char* aName) : HostIPCAllocator(aName) {}
+  CompositorBridgeParentIPCAllocator() {}
   virtual void NotifyNotUsed(PTextureParent* aTexture, uint64_t aTransactionId) override;
 };
 
 /// An allocator can provide shared memory.
 ///
 /// The allocated shmems can be deallocated on either process, as long as they
 /// belong to the same channel.
 class ShmemAllocator
--- a/gfx/layers/ipc/ImageBridgeChild.cpp
+++ b/gfx/layers/ipc/ImageBridgeChild.cpp
@@ -489,33 +489,28 @@ static void CreateCanvasClientSync(Reent
 static void ConnectImageBridge(ImageBridgeChild * child, ImageBridgeParent * parent)
 {
   MessageLoop *parentMsgLoop = parent->GetMessageLoop();
   ipc::MessageChannel *parentChannel = parent->GetIPCChannel();
   child->Open(parentChannel, parentMsgLoop, mozilla::ipc::ChildSide);
 }
 
 ImageBridgeChild::ImageBridgeChild()
-  : CompositableForwarder("ImageBridgeChild")
-  , mShuttingDown(false)
+  : mShuttingDown(false)
   , mFwdTransactionId(0)
 #ifdef MOZ_WIDGET_GONK
   , mWaitingFenceHandleMutex("ImageBridgeChild::mWaitingFenceHandleMutex")
 #endif
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  // Always run destructor on the main thread
-  SetMessageLoopToPostDestructionTo(MessageLoop::current());
-
   mTxn = new CompositableTransaction();
 }
 ImageBridgeChild::~ImageBridgeChild()
 {
-  MOZ_ASSERT(NS_IsMainThread());
   delete mTxn;
 }
 
 void
 ImageBridgeChild::MarkShutDown()
 {
   MOZ_ASSERT(!mShuttingDown);
   mTexturesWaitingRecycled.Clear();
--- a/gfx/layers/ipc/ImageBridgeParent.cpp
+++ b/gfx/layers/ipc/ImageBridgeParent.cpp
@@ -46,40 +46,34 @@ std::map<base::ProcessId, ImageBridgePar
 
 MessageLoop* ImageBridgeParent::sMainLoop = nullptr;
 
 // defined in CompositorBridgeParent.cpp
 CompositorThreadHolder* GetCompositorThreadHolder();
 
 ImageBridgeParent::ImageBridgeParent(MessageLoop* aLoop,
                                      ProcessId aChildProcessId)
-  : CompositableParentManager("ImageBridgeParent")
-  , mMessageLoop(aLoop)
+  : mMessageLoop(aLoop)
   , mSetChildThreadPriority(false)
   , mClosed(false)
 {
   MOZ_ASSERT(NS_IsMainThread());
   sMainLoop = MessageLoop::current();
 
-  // top-level actors must be destroyed on the main thread.
-  SetMessageLoopToPostDestructionTo(sMainLoop);
-
   // creates the map only if it has not been created already, so it is safe
   // with several bridges
   CompositableMap::Create();
   sImageBridges[aChildProcessId] = this;
   SetOtherProcessId(aChildProcessId);
   // DeferredDestroy clears mSelfRef.
   mSelfRef = this;
 }
 
 ImageBridgeParent::~ImageBridgeParent()
 {
-  MOZ_ASSERT(NS_IsMainThread());
-
   nsTArray<PImageContainerParent*> parents;
   ManagedPImageContainerParent(parents);
   for (PImageContainerParent* p : parents) {
     delete p;
   }
 
   sImageBridges.erase(OtherPid());
 }
--- a/gfx/layers/ipc/LayerTransactionParent.cpp
+++ b/gfx/layers/ipc/LayerTransactionParent.cpp
@@ -141,18 +141,17 @@ ShadowChild(const OpRaiseToTopChild& op)
   return cast(op.childLayerParent());
 }
 
 //--------------------------------------------------
 // LayerTransactionParent
 LayerTransactionParent::LayerTransactionParent(LayerManagerComposite* aManager,
                                                ShadowLayersManager* aLayersManager,
                                                uint64_t aId)
-  : CompositableParentManager("LayerTransactionParent")
-  , mLayerManager(aManager)
+  : mLayerManager(aManager)
   , mShadowLayersManager(aLayersManager)
   , mId(aId)
   , mPendingTransaction(0)
   , mPendingCompositorUpdates(0)
   , mDestroyed(false)
   , mIPCOpen(false)
 {
 }
--- a/gfx/layers/ipc/LayerTransactionParent.h
+++ b/gfx/layers/ipc/LayerTransactionParent.h
@@ -165,22 +165,22 @@ protected:
 
   bool Attach(ShadowLayerParent* aLayerParent,
               CompositableHost* aCompositable,
               bool aIsAsyncVideo);
 
   void AddIPDLReference() {
     MOZ_ASSERT(mIPCOpen == false);
     mIPCOpen = true;
-    ADDREF_MANUALLY(this);
+    AddRef();
   }
   void ReleaseIPDLReference() {
     MOZ_ASSERT(mIPCOpen == true);
     mIPCOpen = false;
-    RELEASE_MANUALLY(this);
+    Release();
   }
   friend class CompositorBridgeParent;
   friend class CrossProcessCompositorBridgeParent;
   friend class layout::RenderFrameParent;
 
 private:
   RefPtr<LayerManagerComposite> mLayerManager;
   ShadowLayersManager* mShadowLayersManager;
--- a/gfx/layers/ipc/ShadowLayers.cpp
+++ b/gfx/layers/ipc/ShadowLayers.cpp
@@ -206,18 +206,17 @@ void
 CompositableForwarder::IdentifyTextureHost(const TextureFactoryIdentifier& aIdentifier)
 {
   mTextureFactoryIdentifier = aIdentifier;
 
   mSyncObject = SyncObject::CreateSyncObject(aIdentifier.mSyncHandle);
 }
 
 ShadowLayerForwarder::ShadowLayerForwarder(ClientLayerManager* aClientLayerManager)
- : CompositableForwarder("ShadowLayerForwarder")
- , mClientLayerManager(aClientLayerManager)
+ : mClientLayerManager(aClientLayerManager)
  , mMessageLoop(MessageLoop::current())
  , mDiagnosticTypes(DiagnosticTypes::NO_DIAGNOSTIC)
  , mIsFirstPaint(false)
  , mWindowOverlayChanged(false)
  , mPaintSyncId(0)
 {
   mTxn = new Transaction();
 }
--- a/gfx/layers/ipc/TextureForwarder.cpp
+++ b/gfx/layers/ipc/TextureForwarder.cpp
@@ -5,19 +5,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/layers/TextureForwarder.h"
 
 namespace mozilla {
 namespace layers {
 
-TextureForwarder::TextureForwarder(const char* aName)
-  : ClientIPCAllocator(aName)
-  , mSectionAllocator(nullptr)
+TextureForwarder::TextureForwarder()
+  : mSectionAllocator(nullptr)
 {
 }
 
 TextureForwarder::~TextureForwarder()
 {
   if (mSectionAllocator) {
     delete mSectionAllocator;
   }
--- a/gfx/layers/ipc/TextureForwarder.h
+++ b/gfx/layers/ipc/TextureForwarder.h
@@ -17,18 +17,17 @@
 #include "mozilla/gfx/Rect.h"
 
 namespace mozilla {
 namespace layers {
 
 class TextureForwarder : public ClientIPCAllocator
 {
 public:
-
-  TextureForwarder(const char* aName);
+  TextureForwarder();
 
   virtual ~TextureForwarder();
 
   /**
    * Create a TextureChild/Parent pair as as well as the TextureHost on the parent side.
    */
   virtual PTextureChild* CreateTexture(
     const SurfaceDescriptor& aSharedData,