Move layers ID allocation to GPUProcessManager. (bug 1282348 part 3, r=mattwoodrow)
authorDavid Anderson <danderson@mozilla.com>
Sun, 17 Jul 2016 21:24:27 -0700
changeset 330399 f26200be9e80dcab281d843d4cc3ce70fe2fbc1a
parent 330398 31ee282cfbbde6f4f9a4302f3810f60823c8a7b4
child 330400 1276872114941b9cb7ab00bca24bd9c322191748
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1282348
milestone50.0a1
Move layers ID allocation to GPUProcessManager. (bug 1282348 part 3, r=mattwoodrow)
gfx/ipc/CompositorSession.cpp
gfx/ipc/CompositorSession.h
gfx/ipc/GPUProcessManager.cpp
gfx/ipc/GPUProcessManager.h
gfx/ipc/InProcessCompositorSession.cpp
gfx/ipc/InProcessCompositorSession.h
gfx/layers/ipc/CompositorBridgeChild.cpp
gfx/layers/ipc/CompositorBridgeChild.h
gfx/layers/ipc/CompositorBridgeParent.cpp
gfx/layers/ipc/CompositorBridgeParent.h
--- a/gfx/ipc/CompositorSession.cpp
+++ b/gfx/ipc/CompositorSession.cpp
@@ -9,20 +9,23 @@
 #include "mozilla/widget/PlatformWidgetTypes.h"
 #include "base/process_util.h"
 
 namespace mozilla {
 namespace layers {
 
 using namespace widget;
 
+
 CompositorSession::CompositorSession(CompositorWidgetDelegate* aDelegate,
-                                     CompositorBridgeChild* aChild)
+                                     CompositorBridgeChild* aChild,
+                                     const uint64_t& aRootLayerTreeId)
  : mCompositorWidgetDelegate(aDelegate),
-   mCompositorBridgeChild(aChild)
+   mCompositorBridgeChild(aChild),
+   mRootLayerTreeId(aRootLayerTreeId)
 {
 }
 
 CompositorSession::~CompositorSession()
 {
 }
 
 CompositorBridgeChild*
--- a/gfx/ipc/CompositorSession.h
+++ b/gfx/ipc/CompositorSession.h
@@ -43,38 +43,42 @@ public:
   virtual void Shutdown() = 0;
 
   // This returns a CompositorBridgeParent if the compositor resides in the same process.
   virtual CompositorBridgeParent* GetInProcessBridge() const = 0;
 
   // Set the GeckoContentController for the root of the layer tree.
   virtual void SetContentController(GeckoContentController* aController) = 0;
 
-  // Return the id of the root layer tree.
-  virtual uint64_t RootLayerTreeId() const = 0;
-
   // Return the Async Pan/Zoom Tree Manager for this compositor.
   virtual already_AddRefed<APZCTreeManager> GetAPZCTreeManager() const = 0;
 
   // Return the child end of the compositor IPC bridge.
   CompositorBridgeChild* GetCompositorBridgeChild();
 
   // Return the proxy for accessing the compositor's widget.
   CompositorWidgetDelegate* GetCompositorWidgetDelegate() {
     return mCompositorWidgetDelegate;
   }
 
+  // Return the id of the root layer tree.
+  uint64_t RootLayerTreeId() const {
+    return mRootLayerTreeId;
+  }
+
 protected:
   CompositorSession(CompositorWidgetDelegate* aDelegate,
-                    CompositorBridgeChild* aChild);
+                    CompositorBridgeChild* aChild,
+                    const uint64_t& aRootLayerTreeId);
   virtual ~CompositorSession();
 
 protected:
   CompositorWidgetDelegate* mCompositorWidgetDelegate;
   RefPtr<CompositorBridgeChild> mCompositorBridgeChild;
+  uint64_t mRootLayerTreeId;
 
 private:
   DISALLOW_COPY_AND_ASSIGN(CompositorSession);
 };
 
 } // namespace layers
 } // namespace mozilla
 
--- a/gfx/ipc/GPUProcessManager.cpp
+++ b/gfx/ipc/GPUProcessManager.cpp
@@ -31,17 +31,18 @@ GPUProcessManager::Initialize()
 
 void
 GPUProcessManager::Shutdown()
 {
   sSingleton = nullptr;
 }
 
 GPUProcessManager::GPUProcessManager()
- : mProcess(nullptr),
+ : mNextLayerTreeId(0),
+   mProcess(nullptr),
    mGPUChild(nullptr)
 {
   mObserver = new Observer(this);
   nsContentUtils::RegisterShutdownObserver(mObserver);
 }
 
 GPUProcessManager::~GPUProcessManager()
 {
@@ -152,19 +153,22 @@ GPUProcessManager::DestroyProcess()
 RefPtr<CompositorSession>
 GPUProcessManager::CreateTopLevelCompositor(nsIWidget* aWidget,
                                             ClientLayerManager* aLayerManager,
                                             CSSToLayoutDeviceScale aScale,
                                             bool aUseAPZ,
                                             bool aUseExternalSurfaceSize,
                                             const gfx::IntSize& aSurfaceSize)
 {
+  uint64_t layerTreeId = AllocateLayerTreeId();
+
   return InProcessCompositorSession::Create(
     aWidget,
     aLayerManager,
+    layerTreeId,
     aScale,
     aUseAPZ,
     aUseExternalSurfaceSize,
     aSurfaceSize);
 }
 
 PCompositorBridgeParent*
 GPUProcessManager::CreateTabCompositorBridge(ipc::Transport* aTransport,
@@ -177,17 +181,18 @@ already_AddRefed<APZCTreeManager>
 GPUProcessManager::GetAPZCTreeManagerForLayers(uint64_t aLayersId)
 {
   return CompositorBridgeParent::GetAPZCTreeManager(aLayersId);
 }
 
 uint64_t
 GPUProcessManager::AllocateLayerTreeId()
 {
-  return CompositorBridgeParent::AllocateLayerTreeId();
+  MOZ_ASSERT(NS_IsMainThread());
+  return ++mNextLayerTreeId;
 }
 
 void
 GPUProcessManager::DeallocateLayerTreeId(uint64_t aLayersId)
 {
   CompositorBridgeParent::DeallocateLayerTreeId(aLayersId);
 }
 
--- a/gfx/ipc/GPUProcessManager.h
+++ b/gfx/ipc/GPUProcessManager.h
@@ -136,16 +136,17 @@ private:
     ~Observer() {}
 
     GPUProcessManager* mManager;
   };
   friend class Observer;
 
 private:
   RefPtr<Observer> mObserver;
+  uint64_t mNextLayerTreeId;
   GPUProcessHost* mProcess;
   GPUChild* mGPUChild;
 };
 
 } // namespace gfx
 } // namespace mozilla
 
 #endif // _include_mozilla_gfx_ipc_GPUProcessManager_h_
--- a/gfx/ipc/InProcessCompositorSession.cpp
+++ b/gfx/ipc/InProcessCompositorSession.cpp
@@ -7,63 +7,58 @@
 #include "InProcessCompositorSession.h"
 
 namespace mozilla {
 namespace layers {
 
 InProcessCompositorSession::InProcessCompositorSession(widget::CompositorWidget* aWidget,
                                                        CompositorBridgeChild* aChild,
                                                        CompositorBridgeParent* aParent)
- : CompositorSession(aWidget->AsDelegate(), aChild),
+ : CompositorSession(aWidget->AsDelegate(), aChild, aParent->RootLayerTreeId()),
    mCompositorBridgeParent(aParent),
    mCompositorWidget(aWidget)
 {
 }
 
 /* static */ RefPtr<InProcessCompositorSession>
 InProcessCompositorSession::Create(nsIWidget* aWidget,
                                    ClientLayerManager* aLayerManager,
+                                   const uint64_t& aRootLayerTreeId,
                                    CSSToLayoutDeviceScale aScale,
                                    bool aUseAPZ,
                                    bool aUseExternalSurfaceSize,
                                    const gfx::IntSize& aSurfaceSize)
 {
   CompositorWidgetInitData initData;
   aWidget->GetCompositorWidgetInitData(&initData);
 
   RefPtr<CompositorWidget> widget = CompositorWidget::CreateLocal(initData, aWidget);
   RefPtr<CompositorBridgeChild> child = new CompositorBridgeChild(aLayerManager);
   RefPtr<CompositorBridgeParent> parent =
-    child->InitSameProcess(widget, aScale, aUseAPZ, aUseExternalSurfaceSize, aSurfaceSize);
+    child->InitSameProcess(widget, aRootLayerTreeId, aScale, aUseAPZ, aUseExternalSurfaceSize, aSurfaceSize);
 
   return new InProcessCompositorSession(widget, child, parent);
 }
 
 CompositorBridgeParent*
 InProcessCompositorSession::GetInProcessBridge() const
 {
   return mCompositorBridgeParent;
 }
 
 void
 InProcessCompositorSession::SetContentController(GeckoContentController* aController)
 {
-  mCompositorBridgeParent->SetControllerForLayerTree(RootLayerTreeId(), aController);
-}
-
-uint64_t
-InProcessCompositorSession::RootLayerTreeId() const
-{
-  return mCompositorBridgeParent->RootLayerTreeId();
+  mCompositorBridgeParent->SetControllerForLayerTree(mRootLayerTreeId, aController);
 }
 
 already_AddRefed<APZCTreeManager>
 InProcessCompositorSession::GetAPZCTreeManager() const
 {
-  return mCompositorBridgeParent->GetAPZCTreeManager(RootLayerTreeId());
+  return mCompositorBridgeParent->GetAPZCTreeManager(mRootLayerTreeId);
 }
 
 void
 InProcessCompositorSession::Shutdown()
 {
   // Destroy will synchronously wait for the parent to acknowledge shutdown,
   // at which point CBP will defer a Release on the compositor thread. We
   // can safely release our reference now, and let the destructor run on either
--- a/gfx/ipc/InProcessCompositorSession.h
+++ b/gfx/ipc/InProcessCompositorSession.h
@@ -16,24 +16,24 @@ namespace layers {
 // A CompositorSession where both the child and parent CompositorBridge reside
 // in the same process.
 class InProcessCompositorSession final : public CompositorSession
 {
 public:
   static RefPtr<InProcessCompositorSession> Create(
     nsIWidget* aWidget,
     ClientLayerManager* aLayerManager,
+    const uint64_t& aRootLayerTreeId,
     CSSToLayoutDeviceScale aScale,
     bool aUseAPZ,
     bool aUseExternalSurfaceSize,
     const gfx::IntSize& aSurfaceSize);
 
   CompositorBridgeParent* GetInProcessBridge() const override;
   void SetContentController(GeckoContentController* aController) override;
-  uint64_t RootLayerTreeId() const override;
   already_AddRefed<APZCTreeManager> GetAPZCTreeManager() const override;
   void Shutdown() override;
 
 private:
   InProcessCompositorSession(widget::CompositorWidget* aWidget,
                              CompositorBridgeChild* aChild,
                              CompositorBridgeParent* aParent);
 
--- a/gfx/layers/ipc/CompositorBridgeChild.cpp
+++ b/gfx/layers/ipc/CompositorBridgeChild.cpp
@@ -186,30 +186,31 @@ CompositorBridgeChild::Create(Transport*
   sCompositorBridge->SendGetTileSize(&width, &height);
   gfxPlatform::GetPlatform()->SetTileSize(width, height);
 
   return sCompositorBridge;
 }
 
 CompositorBridgeParent*
 CompositorBridgeChild::InitSameProcess(widget::CompositorWidget* aWidget,
+                                       const uint64_t& aLayerTreeId,
                                        CSSToLayoutDeviceScale aScale,
                                        bool aUseAPZ,
                                        bool aUseExternalSurface,
                                        const gfx::IntSize& aSurfaceSize)
 {
   mCompositorBridgeParent =
     new CompositorBridgeParent(aScale, aUseExternalSurface, aSurfaceSize);
 
   mCanSend = Open(mCompositorBridgeParent->GetIPCChannel(),
                   CompositorThreadHolder::Loop(),
                   ipc::ChildSide);
   MOZ_RELEASE_ASSERT(mCanSend);
 
-  mCompositorBridgeParent->InitSameProcess(aWidget, aUseAPZ);
+  mCompositorBridgeParent->InitSameProcess(aWidget, aLayerTreeId, aUseAPZ);
   return mCompositorBridgeParent;
 }
 
 /*static*/ CompositorBridgeChild*
 CompositorBridgeChild::Get()
 {
   // This is only expected to be used in child processes.
   MOZ_ASSERT(!XRE_IsParentProcess());
--- a/gfx/layers/ipc/CompositorBridgeChild.h
+++ b/gfx/layers/ipc/CompositorBridgeChild.h
@@ -67,16 +67,17 @@ public:
   Create(Transport* aTransport, ProcessId aOtherProcess);
 
   /**
    * Initialize the CompositorBridgeChild, create CompositorBridgeParent, and
    * open a same-process connection.
    */
   CompositorBridgeParent* InitSameProcess(
     widget::CompositorWidget* aWidget,
+    const uint64_t& aLayerTreeId,
     CSSToLayoutDeviceScale aScale,
     bool aUseAPZ,
     bool aUseExternalSurface,
     const gfx::IntSize& aSurfaceSize);
 
   static CompositorBridgeChild* Get();
 
   static bool ChildProcessHasCompositorBridge();
--- a/gfx/layers/ipc/CompositorBridgeParent.cpp
+++ b/gfx/layers/ipc/CompositorBridgeParent.cpp
@@ -596,33 +596,36 @@ CompositorBridgeParent::CompositorBridge
   , mIsTesting(false)
   , mPendingTransaction(0)
   , mPaused(false)
   , mUseExternalSurfaceSize(aUseExternalSurfaceSize)
   , mEGLSurfaceSize(aSurfaceSize)
   , mPauseCompositionMonitor("PauseCompositionMonitor")
   , mResumeCompositionMonitor("ResumeCompositionMonitor")
   , mResetCompositorMonitor("ResetCompositorMonitor")
-  , mRootLayerTreeID(AllocateLayerTreeId())
+  , mRootLayerTreeID(0)
   , mOverrideComposeReadiness(false)
   , mForceCompositionTask(nullptr)
   , mCompositorThreadHolder(CompositorThreadHolder::GetSingleton())
   , mCompositorScheduler(nullptr)
 #if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
   , mLastPluginUpdateLayerTreeId(0)
   , mDeferPluginWindows(false)
   , mPluginWindowsHidden(false)
 #endif
 {
 }
 
 void
-CompositorBridgeParent::InitSameProcess(widget::CompositorWidget* aWidget, bool aUseAPZ)
+CompositorBridgeParent::InitSameProcess(widget::CompositorWidget* aWidget,
+                                        const uint64_t& aLayerTreeId,
+                                        bool aUseAPZ)
 {
   mWidget = aWidget;
+  mRootLayerTreeID = aLayerTreeId;
   if (aUseAPZ) {
     mApzcTreeManager = new APZCTreeManager();
   }
 
   // IPDL initialization. mSelfRef is cleared in DeferredDestroy.
   SetOtherProcessId(base::GetCurrentProcId());
   mSelfRef = this;
 
@@ -657,16 +660,17 @@ CompositorBridgeParent::Initialize()
 
   mCompositorScheduler = new CompositorVsyncScheduler(this, mWidget);
   LayerScope::SetPixelScale(mScale.scale);
 }
 
 uint64_t
 CompositorBridgeParent::RootLayerTreeId()
 {
+  MOZ_ASSERT(mRootLayerTreeID);
   return mRootLayerTreeID;
 }
 
 CompositorBridgeParent::~CompositorBridgeParent()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   InfallibleTArray<PTextureParent*> textures;
@@ -1675,25 +1679,16 @@ CompositorBridgeParent::RecvAdoptChild(c
   // potential deadlock between that lock and sIndirectLayerTreesLock we
   // release sIndirectLayerTreesLock first before calling ChildAdopted.
   if (mApzcTreeManager && controller) {
     controller->ChildAdopted();
   }
   return true;
 }
 
-/*static*/ uint64_t
-CompositorBridgeParent::AllocateLayerTreeId()
-{
-  MOZ_ASSERT(CompositorLoop());
-  MOZ_ASSERT(NS_IsMainThread());
-  static uint64_t ids = 0;
-  return ++ids;
-}
-
 static void
 EraseLayerState(uint64_t aId)
 {
   MonitorAutoLock lock(*sIndirectLayerTreesLock);
 
   auto iter = sIndirectLayerTrees.find(aId);
   if (iter != sIndirectLayerTrees.end()) {
     CompositorBridgeParent* parent = iter->second.mParent;
--- a/gfx/layers/ipc/CompositorBridgeParent.h
+++ b/gfx/layers/ipc/CompositorBridgeParent.h
@@ -214,17 +214,19 @@ class CompositorBridgeParent final : pub
 public:
   explicit CompositorBridgeParent(CSSToLayoutDeviceScale aScale,
                                   bool aUseExternalSurfaceSize,
                                   const gfx::IntSize& aSurfaceSize);
 
   // Must only be called by CompositorBridgeChild. After invoking this, the
   // IPC channel is active and RecvWillStop/ActorDestroy must be called to
   // free the compositor.
-  void InitSameProcess(widget::CompositorWidget* aWidget, bool aUseAPZ);
+  void InitSameProcess(widget::CompositorWidget* aWidget,
+                       const uint64_t& aLayerTreeId,
+                       bool aUseAPZ);
 
   virtual bool RecvGetFrameUniformity(FrameUniformityData* aOutData) override;
   virtual bool RecvRequestOverfill() override;
   virtual bool RecvWillClose() override;
   virtual bool RecvPause() override;
   virtual bool RecvResume() override;
   virtual bool RecvNotifyHidden(const uint64_t& id) override { return true; }
   virtual bool RecvNotifyVisible(const uint64_t& id) override { return true; }
@@ -489,23 +491,16 @@ private:
 
   /**
    * This returns a reference to the APZCTreeManager to which
    * pan/zoom-related events can be sent.
    */
   static already_AddRefed<APZCTreeManager> GetAPZCTreeManager(uint64_t aLayersId);
 
   /**
-   * Allocate an ID that can be used to refer to a layer tree and
-   * associated resources that live only on the compositor thread.
-   *
-   * Must run on the content main thread.
-   */
-  static uint64_t AllocateLayerTreeId();
-  /**
    * Release compositor-thread resources referred to by |aID|.
    *
    * Must run on the content main thread.
    */
   static void DeallocateLayerTreeId(uint64_t aId);
 
   static void RequestNotifyLayerTreeReady(uint64_t aLayersId, CompositorUpdateObserver* aObserver);
   static void RequestNotifyLayerTreeCleared(uint64_t aLayersId, CompositorUpdateObserver* aObserver);
@@ -607,17 +602,17 @@ protected:
   bool mUseExternalSurfaceSize;
   gfx::IntSize mEGLSurfaceSize;
 
   mozilla::Monitor mPauseCompositionMonitor;
   mozilla::Monitor mResumeCompositionMonitor;
   mozilla::Monitor mResetCompositorMonitor;
 
   uint64_t mCompositorID;
-  const uint64_t mRootLayerTreeID;
+  uint64_t mRootLayerTreeID;
 
   bool mOverrideComposeReadiness;
   RefPtr<CancelableRunnable> mForceCompositionTask;
 
   RefPtr<APZCTreeManager> mApzcTreeManager;
 
   RefPtr<CompositorThreadHolder> mCompositorThreadHolder;
   RefPtr<CompositorVsyncScheduler> mCompositorScheduler;