Don't expose CompositorVsyncDispatcher from CompositorWidget. (bug 1285625 part 2, r=mchang)
authorDavid Anderson <danderson@mozilla.com>
Tue, 19 Jul 2016 11:56:07 -0700
changeset 330805 522249786c4c5cd027df51e2369f74366ea3374f
parent 330804 de2f89a5b4c3f821c37b230ef99dffa0b7325474
child 330806 3fdb8ca3e6ffbd310daf342eb8febb1c17938dd0
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)
reviewersmchang
bugs1285625
milestone50.0a1
Don't expose CompositorVsyncDispatcher from CompositorWidget. (bug 1285625 part 2, r=mchang)
gfx/layers/ipc/CompositorBridgeParent.cpp
gfx/layers/ipc/CompositorBridgeParent.h
widget/CompositorWidget.h
widget/InProcessCompositorWidget.cpp
widget/InProcessCompositorWidget.h
widget/windows/WinCompositorWidget.cpp
widget/windows/WinCompositorWidget.h
--- a/gfx/layers/ipc/CompositorBridgeParent.cpp
+++ b/gfx/layers/ipc/CompositorBridgeParent.cpp
@@ -251,17 +251,17 @@ CompositorVsyncScheduler::Observer::Dest
 
 CompositorVsyncScheduler::CompositorVsyncScheduler(CompositorBridgeParent* aCompositorBridgeParent,
                                                    widget::CompositorWidget* aWidget)
   : mCompositorBridgeParent(aCompositorBridgeParent)
   , mLastCompose(TimeStamp::Now())
   , mIsObservingVsync(false)
   , mNeedsComposite(0)
   , mVsyncNotificationsSkipped(0)
-  , mCompositorVsyncDispatcher(aWidget->GetCompositorVsyncDispatcher())
+  , mWidget(aWidget)
   , mCurrentCompositeTaskMonitor("CurrentCompositeTaskMonitor")
   , mCurrentCompositeTask(nullptr)
   , mSetNeedsCompositeMonitor("SetNeedsCompositeMonitor")
   , mSetNeedsCompositeTask(nullptr)
 #ifdef MOZ_WIDGET_GONK
 #if ANDROID_VERSION >= 19
   , mDisplayEnabled(false)
   , mSetDisplayMonitor("SetDisplayMonitor")
@@ -534,25 +534,25 @@ CompositorVsyncScheduler::NeedsComposite
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
   return mNeedsComposite;
 }
 
 void
 CompositorVsyncScheduler::ObserveVsync()
 {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
-  mCompositorVsyncDispatcher->SetCompositorVsyncObserver(mVsyncObserver);
+  mWidget->ObserveVsync(mVsyncObserver);
   mIsObservingVsync = true;
 }
 
 void
 CompositorVsyncScheduler::UnobserveVsync()
 {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
-  mCompositorVsyncDispatcher->SetCompositorVsyncObserver(nullptr);
+  mWidget->ObserveVsync(nullptr);
   mIsObservingVsync = false;
 }
 
 void
 CompositorVsyncScheduler::DispatchTouchEvents(TimeStamp aVsyncTimestamp)
 {
 #ifdef MOZ_WIDGET_GONK
   GeckoTouchDispatcher::GetInstance()->NotifyVsync(aVsyncTimestamp);
@@ -717,17 +717,16 @@ void
 CompositorBridgeParent::ForceIsFirstPaint()
 {
   mCompositionManager->ForceIsFirstPaint();
 }
 
 void
 CompositorBridgeParent::StopAndClearResources()
 {
-  CancelCurrentCompositeTask();
   if (mForceCompositionTask) {
     mForceCompositionTask->Cancel();
     mForceCompositionTask = nullptr;
   }
 
   mPaused = true;
 
   // Ensure that the layer manager is destroyed before CompositorBridgeChild.
@@ -744,16 +743,22 @@ CompositorBridgeParent::StopAndClearReso
   }
 
   if (mCompositor) {
     mCompositor->DetachWidget();
     mCompositor->Destroy();
     mCompositor = nullptr;
   }
 
+  // This must be destroyed now since it accesses the widget.
+  if (mCompositorScheduler) {
+    mCompositorScheduler->Destroy();
+    mCompositorScheduler = nullptr;
+  }
+
   // After this point, it is no longer legal to access the widget.
   mWidget = nullptr;
 }
 
 bool
 CompositorBridgeParent::RecvWillClose()
 {
   StopAndClearResources();
@@ -917,18 +922,16 @@ CompositorBridgeParent::ActorDestroy(Act
 
   mCompositionManager = nullptr;
 
   if (mApzcTreeManager) {
     mApzcTreeManager->ClearTree();
     mApzcTreeManager = nullptr;
   }
 
-  mCompositorScheduler->Destroy();
-
   { // scope lock
     MonitorAutoLock lock(*sIndirectLayerTreesLock);
     sIndirectLayerTrees.erase(mRootLayerTreeID);
   }
 
   // There are chances that the ref count reaches zero on the main thread shortly
   // after this function returns while some ipdl code still needs to run on
   // this thread.
--- a/gfx/layers/ipc/CompositorBridgeParent.h
+++ b/gfx/layers/ipc/CompositorBridgeParent.h
@@ -167,17 +167,17 @@ private:
 #ifdef COMPOSITOR_PERFORMANCE_WARNING
   TimeStamp mExpectedComposeStartTime;
 #endif
 
   bool mAsapScheduling;
   bool mIsObservingVsync;
   uint32_t mNeedsComposite;
   int32_t mVsyncNotificationsSkipped;
-  RefPtr<CompositorVsyncDispatcher> mCompositorVsyncDispatcher;
+  widget::CompositorWidget* mWidget;
   RefPtr<CompositorVsyncScheduler::Observer> mVsyncObserver;
 
   mozilla::Monitor mCurrentCompositeTaskMonitor;
   RefPtr<CancelableRunnable> mCurrentCompositeTask;
 
   mozilla::Monitor mSetNeedsCompositeMonitor;
   RefPtr<CancelableRunnable> mSetNeedsCompositeTask;
 
--- a/widget/CompositorWidget.h
+++ b/widget/CompositorWidget.h
@@ -10,17 +10,17 @@
 #include "Units.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/layers/LayersTypes.h"
 
 class nsIWidget;
 class nsBaseWidget;
 
 namespace mozilla {
-class CompositorVsyncDispatcher;
+class VsyncObserver;
 namespace layers {
 class Compositor;
 class LayerManagerComposite;
 class Compositor;
 class Composer2D;
 } // namespace layers
 namespace gfx {
 class DrawTarget;
@@ -218,19 +218,19 @@ public:
    * Ensure end of composition to back buffer.
    *
    * Called by BasicCompositor on the compositor thread for OMTC drawing
    * after each composition to back buffer.
    */
   virtual already_AddRefed<gfx::SourceSurface> EndBackBufferDrawing();
 
   /**
-   * Return a compositor vsync dispatcher for this widget.
+   * Observer or unobserve vsync.
    */
-  virtual already_AddRefed<CompositorVsyncDispatcher> GetCompositorVsyncDispatcher() = 0;
+  virtual void ObserveVsync(VsyncObserver* aObserver) = 0;
 
   virtual WinCompositorWidget* AsWindows() {
     return nullptr;
   }
 
   /**
    * Return the platform-specific delegate for the widget, if any.
    */
--- a/widget/InProcessCompositorWidget.cpp
+++ b/widget/InProcessCompositorWidget.cpp
@@ -119,18 +119,18 @@ InProcessCompositorWidget::GetWidgetKey(
 }
 
 nsIWidget*
 InProcessCompositorWidget::RealWidget()
 {
   return mWidget;
 }
 
-already_AddRefed<CompositorVsyncDispatcher>
-InProcessCompositorWidget::GetCompositorVsyncDispatcher()
+void
+InProcessCompositorWidget::ObserveVsync(VsyncObserver* aObserver)
 {
   RefPtr<CompositorVsyncDispatcher> cvd = mWidget->GetCompositorVsyncDispatcher();
-  return cvd.forget();
+  cvd->SetCompositorVsyncObserver(aObserver);
 }
 
 } // namespace widget
 } // namespace mozilla
 
--- a/widget/InProcessCompositorWidget.h
+++ b/widget/InProcessCompositorWidget.h
@@ -31,17 +31,17 @@ public:
   virtual void EndRemoteDrawingInRegion(gfx::DrawTarget* aDrawTarget,
                                         LayoutDeviceIntRegion& aInvalidRegion) override;
   virtual void CleanupRemoteDrawing() override;
   virtual void CleanupWindowEffects() override;
   virtual bool InitCompositor(layers::Compositor* aCompositor) override;
   virtual LayoutDeviceIntSize GetClientSize() override;
   virtual uint32_t GetGLFrameBufferFormat() override;
   virtual layers::Composer2D* GetComposer2D() override;
-  virtual already_AddRefed<CompositorVsyncDispatcher> GetCompositorVsyncDispatcher() override;
+  virtual void ObserveVsync(VsyncObserver* aObserver) override;
   virtual uintptr_t GetWidgetKey() override;
 
   // If you can override this method, inherit from CompositorWidget instead.
   nsIWidget* RealWidget() override;
 
 private:
   nsBaseWidget* mWidget;
 };
--- a/widget/windows/WinCompositorWidget.cpp
+++ b/widget/windows/WinCompositorWidget.cpp
@@ -168,21 +168,21 @@ WinCompositorWidget::EndBackBufferDrawin
   if (mLockedBackBufferData) {
     MOZ_ASSERT(mLastBackBuffer);
     mLastBackBuffer->ReleaseBits(mLockedBackBufferData);
     mLockedBackBufferData = nullptr;
   }
   return CompositorWidget::EndBackBufferDrawing();
 }
 
-already_AddRefed<CompositorVsyncDispatcher>
-WinCompositorWidget::GetCompositorVsyncDispatcher()
+void
+WinCompositorWidget::ObserveVsync(VsyncObserver* aObserver)
 {
   RefPtr<CompositorVsyncDispatcher> cvd = mWindow->GetCompositorVsyncDispatcher();
-  return cvd.forget();
+  cvd->SetCompositorVsyncObserver(aObserver);
 }
 
 uintptr_t
 WinCompositorWidget::GetWidgetKey()
 {
   return mWidgetKey;
 }
 
--- a/widget/windows/WinCompositorWidget.h
+++ b/widget/windows/WinCompositorWidget.h
@@ -53,17 +53,17 @@ public:
   void PostRender(layers::LayerManagerComposite*) override;
   already_AddRefed<gfx::DrawTarget> StartRemoteDrawing() override;
   void EndRemoteDrawing() override;
   LayoutDeviceIntSize GetClientSize() override;
   already_AddRefed<gfx::DrawTarget> GetBackBufferDrawTarget(gfx::DrawTarget* aScreenTarget,
                                                             const LayoutDeviceIntRect& aRect,
                                                             const LayoutDeviceIntRect& aClearRect) override;
   already_AddRefed<gfx::SourceSurface> EndBackBufferDrawing() override;
-  already_AddRefed<CompositorVsyncDispatcher> GetCompositorVsyncDispatcher() override;
+  void ObserveVsync(VsyncObserver* aObserver) override;
   uintptr_t GetWidgetKey() override;
   nsIWidget* RealWidget() override;
   WinCompositorWidget* AsWindows() override {
     return this;
   }
   CompositorWidgetDelegate* AsDelegate() override {
     return this;
   }