Remove the TaskThrottler. (bug 1192919 part 6, r=kats)
authorDavid Anderson <danderson@mozilla.com>
Mon, 21 Dec 2015 09:36:36 -0500
changeset 312311 e1654855ca072fc098fe503d24fb2cc70972e89c
parent 312310 3ec64106acb3a0a772f9b09d6cfbd622beedee24
child 312312 203644fd8bbf4573d640bad79b5587bbfeefd299
push id5703
push userraliiev@mozilla.com
push dateMon, 07 Mar 2016 14:18:41 +0000
treeherdermozilla-beta@31e373ad5b5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1192919
milestone46.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
Remove the TaskThrottler. (bug 1192919 part 6, r=kats)
gfx/layers/apz/src/APZCTreeManager.cpp
gfx/layers/apz/src/APZCTreeManager.h
gfx/layers/apz/src/AsyncPanZoomController.cpp
gfx/layers/apz/src/AsyncPanZoomController.h
gfx/layers/apz/src/TaskThrottler.cpp
gfx/layers/apz/src/TaskThrottler.h
gfx/layers/apz/test/gtest/TestAsyncPanZoomController.cpp
gfx/layers/ipc/CompositorParent.cpp
gfx/layers/moz.build
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -23,17 +23,16 @@
 #include "mozilla/mozalloc.h"           // for operator new
 #include "mozilla/TouchEvents.h"
 #include "mozilla/Preferences.h"        // for Preferences
 #include "mozilla/EventStateManager.h"  // for WheelPrefs
 #include "nsDebug.h"                    // for NS_WARNING
 #include "nsPoint.h"                    // for nsIntPoint
 #include "nsThreadUtils.h"              // for NS_IsMainThread
 #include "OverscrollHandoffState.h"     // for OverscrollHandoffState
-#include "TaskThrottler.h"              // for TaskThrottler
 #include "TreeTraversal.h"              // for generic tree traveral algorithms
 #include "LayersLogging.h"              // for Stringify
 #include "Units.h"                      // for ParentlayerPixel
 #include "GestureEventListener.h"       // for GestureEventListener::setLongTapEnabled
 #include "UnitTransforms.h"             // for ViewAs
 
 #define ENABLE_APZCTM_LOGGING 0
 // #define ENABLE_APZCTM_LOGGING 1
@@ -105,21 +104,20 @@ APZCTreeManager::APZCTreeManager()
 }
 
 APZCTreeManager::~APZCTreeManager()
 {
 }
 
 AsyncPanZoomController*
 APZCTreeManager::NewAPZCInstance(uint64_t aLayersId,
-                                 GeckoContentController* aController,
-                                 TaskThrottler* aPaintThrottler)
+                                 GeckoContentController* aController)
 {
   return new AsyncPanZoomController(aLayersId, this, mInputQueue,
-    aController, aPaintThrottler, AsyncPanZoomController::USE_GESTURE_DETECTOR);
+    aController, AsyncPanZoomController::USE_GESTURE_DETECTOR);
 }
 
 TimeStamp
 APZCTreeManager::GetFrameTime()
 {
   return TimeStamp::Now();
 }
 
@@ -195,42 +193,16 @@ APZCTreeManager::UpdateHitTestingTree(Co
 
 #if ENABLE_APZCTM_LOGGING
   // Make the hit-test tree line up with the layer dump
   printf_stderr("APZCTreeManager (%p)\n", this);
   mRootNode->Dump("  ");
 #endif
 }
 
-void
-APZCTreeManager::InitializeForLayersId(uint64_t aLayersId)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  auto throttlerInsertResult = mPaintThrottlerMap.insert(
-    std::make_pair(aLayersId, RefPtr<TaskThrottler>()));
-  if (throttlerInsertResult.second) {
-    throttlerInsertResult.first->second = new TaskThrottler(
-      GetFrameTime(), TimeDuration::FromMilliseconds(500));
-  }
-}
-
-void
-APZCTreeManager::AdoptLayersId(uint64_t aLayersId, APZCTreeManager* aOldManager)
-{
-  MOZ_ASSERT(aOldManager);
-  if (aOldManager == this) {
-    return;
-  }
-  auto iter = aOldManager->mPaintThrottlerMap.find(aLayersId);
-  if (iter != aOldManager->mPaintThrottlerMap.end()) {
-    mPaintThrottlerMap[aLayersId] = iter->second;
-    aOldManager->mPaintThrottlerMap.erase(iter);
-  }
-}
-
 // Compute the clip region to be used for a layer with an APZC. This function
 // is only called for layers which actually have scrollable metrics and an APZC.
 static ParentLayerIntRegion
 ComputeClipRegion(GeckoContentController* aController,
                   const LayerMetricsWrapper& aLayer)
 {
   ParentLayerIntRegion clipRegion;
   if (aLayer.GetClipRect()) {
@@ -456,22 +428,17 @@ APZCTreeManager::PrepareNodeForLayer(con
     }
 
     // The APZC we get off the layer may have been destroyed previously if the
     // layer was inactive or omitted from the layer tree for whatever reason
     // from a layers update. If it later comes back it will have a reference to
     // a destroyed APZC and so we need to throw that out and make a new one.
     bool newApzc = (apzc == nullptr || apzc->IsDestroyed());
     if (newApzc) {
-      // Look up the paint throttler for this layers id, or create it if
-      // this is the first APZC for this layers id.
-      RefPtr<TaskThrottler> throttler = mPaintThrottlerMap[aLayersId];
-      MOZ_ASSERT(throttler);
-
-      apzc = NewAPZCInstance(aLayersId, state->mController, throttler);
+      apzc = NewAPZCInstance(aLayersId, state->mController);
       apzc->SetCompositorParent(aState.mCompositor);
       if (state->mCrossProcessParent != nullptr) {
         apzc->ShareFrameMetricsAcrossProcesses();
       }
       MOZ_ASSERT(node == nullptr);
       node = new HitTestingTreeNode(apzc, true, aLayersId);
     } else {
       // If we are re-using a node for this layer clear the tree pointers
@@ -651,33 +618,20 @@ WillHandleInput(const PanGestureOrScroll
 
   WidgetWheelEvent wheelEvent = aPanInput.ToWidgetWheelEvent(nullptr);
   return WillHandleWheelEvent(&wheelEvent);
 }
 
 void
 APZCTreeManager::FlushApzRepaints(uint64_t aLayersId)
 {
+  // Previously, paints were throttled and therefore this method was used to
+  // ensure any pending paints were flushed. Now, paints are flushed
+  // immediately, so it is safe to simply send a notification now.
   APZCTM_LOG("Flushing repaints for layers id %" PRIu64, aLayersId);
-  { // scope lock
-    MonitorAutoLock lock(mTreeLock);
-    mTreeLock.AssertCurrentThreadOwns();
-
-    ForEachNode(mRootNode.get(),
-        [aLayersId](HitTestingTreeNode* aNode)
-        {
-          if (aNode->IsPrimaryHolder()) {
-            AsyncPanZoomController* apzc = aNode->GetApzc();
-            MOZ_ASSERT(apzc);
-            if (apzc->GetGuid().mLayersId == aLayersId) {
-              apzc->FlushRepaintIfPending();
-            }
-          }
-        });
-  }
   const CompositorParent::LayerTreeState* state = CompositorParent::GetIndirectShadowTree(aLayersId);
   MOZ_ASSERT(state && state->mController);
   NS_DispatchToMainThread(NS_NewRunnableMethod(
     state->mController.get(), &GeckoContentController::NotifyFlushComplete));
 }
 
 nsEventStatus
 APZCTreeManager::ReceiveInputEvent(InputData& aEvent,
--- a/gfx/layers/apz/src/APZCTreeManager.h
+++ b/gfx/layers/apz/src/APZCTreeManager.h
@@ -47,17 +47,16 @@ class AsyncPanZoomController;
 class CompositorParent;
 class OverscrollHandoffChain;
 struct OverscrollHandoffState;
 struct FlingHandoffState;
 class LayerMetricsWrapper;
 class InputQueue;
 class GeckoContentController;
 class HitTestingTreeNode;
-class TaskThrottler;
 
 /**
  * ****************** NOTE ON LOCK ORDERING IN APZ **************************
  *
  * There are two kinds of locks used by APZ: APZCTreeManager::mTreeLock
  * ("the tree lock") and AsyncPanZoomController::mMonitor ("APZC locks").
  *
  * To avoid deadlock, we impose a lock ordering between these locks, which is:
@@ -133,27 +132,16 @@ public:
    */
   void UpdateHitTestingTree(CompositorParent* aCompositor,
                             Layer* aRoot,
                             bool aIsFirstPaint,
                             uint64_t aOriginatingLayersId,
                             uint32_t aPaintSequenceNumber);
 
   /**
-   * Do any per-layers-id setup needed. This will be called on the main thread,
-   * and may be called multiple times for the same layers id.
-   */
-  void InitializeForLayersId(uint64_t aLayersId);
-
-  /**
-   * Move any per-layers-id state from the old APZCTreeManager to this one.
-   */
-  void AdoptLayersId(uint64_t aLayersId, APZCTreeManager* aOldManager);
-
-  /**
    * Walk the tree of APZCs and flushes the repaint requests for all the APZCS
    * corresponding to the given layers id. Finally, sends a flush complete
    * notification to the GeckoContentController for the layers id.
    */
   void FlushApzRepaints(uint64_t aLayersId);
 
   /**
    * General handler for incoming input events. Manipulates the frame metrics
@@ -414,18 +402,17 @@ public:
   static void SetLongTapEnabled(bool aTapGestureEnabled);
 
 protected:
   // Protected destructor, to discourage deletion outside of Release():
   virtual ~APZCTreeManager();
 
   // Protected hooks for gtests subclass
   virtual AsyncPanZoomController* NewAPZCInstance(uint64_t aLayersId,
-                                                  GeckoContentController* aController,
-                                                  TaskThrottler* aPaintThrottler);
+                                                  GeckoContentController* aController);
 public:
   // Public hooks for gtests subclass
   virtual TimeStamp GetFrameTime();
 
 public:
   /* Some helper functions to find an APZC given some identifying input. These functions
      lock the tree of APZCs while they find the right one, and then return an addref'd
      pointer to it. This allows caller code to just use the target APZC without worrying
@@ -530,20 +517,16 @@ private:
    * is considered part of the APZC tree management state.
    * Finally, the lock needs to be held when accessing mZoomConstraints.
    * IMPORTANT: See the note about lock ordering at the top of this file. */
   mutable mozilla::Monitor mTreeLock;
   RefPtr<HitTestingTreeNode> mRootNode;
   /* Holds the zoom constraints for scrollable layers, as determined by the
    * the main-thread gecko code. */
   std::map<ScrollableLayerGuid, ZoomConstraints> mZoomConstraints;
-  /* Stores a paint throttler for each layers id. There is one for each layers
-   * id to ensure that one child process painting slowly doesn't hold up
-   * another. */
-  std::map<uint64_t, RefPtr<TaskThrottler>> mPaintThrottlerMap;
   /* This tracks the APZC that should receive all inputs for the current input event block.
    * This allows touch points to move outside the thing they started on, but still have the
    * touch events delivered to the same initial APZC. This will only ever be touched on the
    * input delivery thread, and so does not require locking.
    */
   RefPtr<AsyncPanZoomController> mApzcForInputBlock;
   /* The hit result for the current input event block; this should always be in
    * sync with mApzcForInputBlock.
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -13,17 +13,16 @@
 #include "Compositor.h"                 // for Compositor
 #include "FrameMetrics.h"               // for FrameMetrics, etc
 #include "GestureEventListener.h"       // for GestureEventListener
 #include "HitTestingTreeNode.h"         // for HitTestingTreeNode
 #include "InputData.h"                  // for MultiTouchInput, etc
 #include "InputBlockState.h"            // for InputBlockState, TouchBlockState
 #include "InputQueue.h"                 // for InputQueue
 #include "OverscrollHandoffState.h"     // for OverscrollHandoffState
-#include "TaskThrottler.h"              // for TaskThrottler
 #include "Units.h"                      // for CSSRect, CSSPoint, etc
 #include "UnitTransforms.h"             // for TransformTo
 #include "base/message_loop.h"          // for MessageLoop
 #include "base/task.h"                  // for NewRunnableMethod, etc
 #include "base/tracked.h"               // for FROM_HERE
 #include "gfxPrefs.h"                   // for gfxPrefs
 #include "gfxTypes.h"                   // for gfxFloat
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
@@ -843,20 +842,18 @@ AsyncPanZoomController::InitializeGlobal
   uint64_t threshold = 1LL << 32; // 4 GB in bytes
   gIsHighMemSystem = sysmem >= threshold;
 }
 
 AsyncPanZoomController::AsyncPanZoomController(uint64_t aLayersId,
                                                APZCTreeManager* aTreeManager,
                                                const RefPtr<InputQueue>& aInputQueue,
                                                GeckoContentController* aGeckoContentController,
-                                               TaskThrottler* aPaintThrottler,
                                                GestureBehavior aGestures)
   :  mLayersId(aLayersId),
-     mPaintThrottler(aPaintThrottler),
      mGeckoContentController(aGeckoContentController),
      mRefPtrMonitor("RefPtrMonitor"),
      // mTreeManager must be initialized before GetFrameTime() is called
      mTreeManager(aTreeManager),
      mSharingFrameMetricsAcrossProcesses(false),
      mMonitor("AsyncPanZoomController"),
      mX(this),
      mY(this),
@@ -2759,19 +2756,16 @@ void AsyncPanZoomController::FlushRepain
 void AsyncPanZoomController::FlushRepaintForNewInputBlock() {
   APZC_LOG("%p flushing repaint for new input block\n", this);
 
   ReentrantMonitorAutoEnter lock(mMonitor);
   RequestContentRepaint(mFrameMetrics);
   UpdateSharedCompositorFrameMetrics();
 }
 
-void AsyncPanZoomController::FlushRepaintIfPending() {
-}
-
 bool AsyncPanZoomController::SnapBackIfOverscrolled() {
   ReentrantMonitorAutoEnter lock(mMonitor);
   // It's possible that we're already in the middle of an overscroll
   // animation - if so, don't start a new one.
   if (IsOverscrolled() && mState != OVERSCROLL_ANIMATION) {
     APZC_LOG("%p is overscrolled, starting snap-back\n", this);
     StartOverscrollAnimation(ParentLayerPoint(0, 0));
     return true;
--- a/gfx/layers/apz/src/AsyncPanZoomController.h
+++ b/gfx/layers/apz/src/AsyncPanZoomController.h
@@ -19,17 +19,16 @@
 #include "mozilla/UniquePtr.h"
 #include "mozilla/Atomics.h"
 #include "InputData.h"
 #include "Axis.h"
 #include "InputQueue.h"
 #include "APZUtils.h"
 #include "Layers.h"                     // for Layer::ScrollDirection
 #include "LayersTypes.h"
-#include "TaskThrottler.h"
 #include "mozilla/gfx/Matrix.h"
 #include "nsRegion.h"
 
 #include "base/message_loop.h"
 
 namespace mozilla {
 
 namespace ipc {
@@ -99,17 +98,16 @@ public:
    *       distance, but it's the closest thing we currently have.
    */
   static ScreenCoord GetTouchStartTolerance();
 
   AsyncPanZoomController(uint64_t aLayersId,
                          APZCTreeManager* aTreeManager,
                          const RefPtr<InputQueue>& aInputQueue,
                          GeckoContentController* aController,
-                         TaskThrottler* aPaintThrottler,
                          GestureBehavior aGestures = DEFAULT_GESTURES);
 
   // --------------------------------------------------------------------------
   // These methods must only be called on the gecko thread.
   //
 
   /**
    * Read the various prefs and do any global initialization for all APZC instances.
@@ -182,21 +180,16 @@ public:
    * for the container layer corresponding to this APZC.
    * |aIsFirstPaint| is a flag passed from the shadow
    * layers code indicating that the frame metrics being sent with this call are
    * the initial metrics and the initial paint of the frame has just happened.
    */
   void NotifyLayersUpdated(const FrameMetrics& aLayerMetrics, bool aIsFirstPaint);
 
   /**
-   * Flush any pending repaint request.
-   */
-  void FlushRepaintIfPending();
-
-  /**
    * The platform implementation must set the compositor parent so that we can
    * request composites.
    */
   void SetCompositorParent(CompositorParent* aCompositorParent);
 
   /**
    * Inform this APZC that it will be sharing its FrameMetrics with a cross-process
    * compositor so that the associated content process can access it. This is only
@@ -645,17 +638,16 @@ protected:
 
   // This is called to request that the main thread snap the scroll position
   // to a nearby snap position if appropriate. The current scroll position is
   // used as the final destination.
   void RequestSnap();
 
   uint64_t mLayersId;
   RefPtr<CompositorParent> mCompositorParent;
-  RefPtr<TaskThrottler> mPaintThrottler;
 
   /* Access to the following two fields is protected by the mRefPtrMonitor,
      since they are accessed on the UI thread but can be cleared on the
      compositor thread. */
   RefPtr<GeckoContentController> mGeckoContentController;
   RefPtr<GestureEventListener> mGestureEventListener;
   mutable Monitor mRefPtrMonitor;
 
deleted file mode 100644
--- a/gfx/layers/apz/src/TaskThrottler.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
-/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*- */
-/* vim: set sw=2 sts=2 ts=8 et tw=80 : */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * 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 "TaskThrottler.h"
-
-#include "mozilla/layers/APZThreadUtils.h"
-
-#define TASK_LOG(...)
-// #define TASK_LOG(...) printf_stderr("TASK: " __VA_ARGS__)
-
-namespace mozilla {
-namespace layers {
-
-TaskThrottler::TaskThrottler(const TimeStamp& aTimeStamp, const TimeDuration& aMaxWait)
-  : mMonitor("TaskThrottler")
-  , mOutstanding(false)
-  , mQueuedTask(nullptr)
-  , mStartTime(aTimeStamp)
-  , mMaxWait(aMaxWait)
-  , mMean(1)
-  , mTimeoutTask(nullptr)
-{
-}
-
-TaskThrottler::~TaskThrottler()
-{
-  // The timeout task holds a strong reference to the TaskThrottler, so if the
-  // TaskThrottler is being destroyed, there's no need to cancel the task.
-}
-
-void
-TaskThrottler::PostTask(const tracked_objects::Location& aLocation,
-                        UniquePtr<CancelableTask> aTask, const TimeStamp& aTimeStamp)
-{
-  MonitorAutoLock lock(mMonitor);
-
-  TASK_LOG("%p got a task posted; mOutstanding=%d\n", this, mOutstanding);
-  aTask->SetBirthPlace(aLocation);
-
-  if (mOutstanding) {
-    CancelPendingTask(lock);
-    if (TimeSinceLastRequest(aTimeStamp, lock) < mMaxWait) {
-      mQueuedTask = Move(aTask);
-      TASK_LOG("%p queued task %p\n", this, mQueuedTask.get());
-      // Make sure the queued task is sent after mMaxWait time elapses,
-      // even if we don't get a TaskComplete() until then.
-      TimeDuration timeout = mMaxWait - TimeSinceLastRequest(aTimeStamp, lock);
-      mTimeoutTask = NewRunnableMethod(this, &TaskThrottler::OnTimeout);
-      APZThreadUtils::RunDelayedTaskOnCurrentThread(mTimeoutTask, timeout);
-      return;
-    }
-    // we've been waiting for more than the max-wait limit, so just fall through
-    // and send the new task already.
-  }
-
-  mStartTime = aTimeStamp;
-  aTask->Run();
-  mOutstanding = true;
-}
-
-void
-TaskThrottler::OnTimeout()
-{
-  MonitorAutoLock lock(mMonitor);
-  if (mQueuedTask) {
-    RunQueuedTask(TimeStamp::Now(), lock);
-  }
-  // The message loop will delete the posted timeout task. Make sure we don't
-  // keep a dangling pointer to it.
-  mTimeoutTask = nullptr;
-}
-
-void
-TaskThrottler::TaskComplete(const TimeStamp& aTimeStamp)
-{
-  MonitorAutoLock lock(mMonitor);
-
-  if (!mOutstanding) {
-    return;
-  }
-
-  mMean.insert(aTimeStamp - mStartTime);
-
-  if (mQueuedTask) {
-    RunQueuedTask(aTimeStamp, lock);
-    CancelTimeoutTask(lock);
-  } else {
-    mOutstanding = false;
-  }
-}
-
-TimeDuration
-TaskThrottler::AverageDuration()
-{
-  MonitorAutoLock lock(mMonitor);
-
-  return mMean.empty() ? TimeDuration() : mMean.mean();
-}
-
-void
-TaskThrottler::RunQueuedTask(const TimeStamp& aTimeStamp,
-                             const MonitorAutoLock& aProofOfLock)
-{
-  TASK_LOG("%p running task %p\n", this, mQueuedTask.get());
-  mStartTime = aTimeStamp;
-  mQueuedTask->Run();
-  mQueuedTask = nullptr;
-}
-
-void
-TaskThrottler::CancelPendingTask()
-{
-  MonitorAutoLock lock(mMonitor);
-  CancelPendingTask(lock);
-}
-
-void
-TaskThrottler::CancelPendingTask(const MonitorAutoLock& aProofOfLock)
-{
-  if (mQueuedTask) {
-    TASK_LOG("%p cancelling task %p\n", this, mQueuedTask.get());
-    mQueuedTask->Cancel();
-    mQueuedTask = nullptr;
-    CancelTimeoutTask(aProofOfLock);
-  }
-}
-
-void
-TaskThrottler::CancelTimeoutTask(const MonitorAutoLock& aProofOfLock)
-{
-  if (mTimeoutTask) {
-    mTimeoutTask->Cancel();
-    mTimeoutTask = nullptr;  // the MessageLoop will destroy it
-  }
-}
-
-TimeDuration
-TaskThrottler::TimeSinceLastRequest(const TimeStamp& aTimeStamp)
-{
-  MonitorAutoLock lock(mMonitor);
-  return TimeSinceLastRequest(aTimeStamp, lock);
-}
-
-TimeDuration
-TaskThrottler::TimeSinceLastRequest(const TimeStamp& aTimeStamp,
-                                    const MonitorAutoLock& aProofOfLock)
-{
-  return aTimeStamp - mStartTime;
-}
-
-void
-TaskThrottler::ClearHistory()
-{
-  MonitorAutoLock lock(mMonitor);
-
-  mMean.clear();
-}
-
-void
-TaskThrottler::SetMaxDurations(uint32_t aMaxDurations)
-{
-  MonitorAutoLock lock(mMonitor);
-
-  if (aMaxDurations != mMean.maxValues()) {
-    mMean = RollingMean<TimeDuration, TimeDuration>(aMaxDurations);
-  }
-}
-
-} // namespace layers
-} // namespace mozilla
deleted file mode 100644
--- a/gfx/layers/apz/src/TaskThrottler.h
+++ /dev/null
@@ -1,119 +0,0 @@
-/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 2; -*- */
-/* vim: set sw=4 ts=8 et tw=80 : */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * 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/. */
-
-#ifndef mozilla_dom_TaskThrottler_h
-#define mozilla_dom_TaskThrottler_h
-
-#include <stdint.h>                     // for uint32_t
-#include "base/task.h"                  // for CancelableTask
-#include "mozilla/Monitor.h"            // for Monitor
-#include "mozilla/mozalloc.h"           // for operator delete
-#include "mozilla/RollingMean.h"        // for RollingMean
-#include "mozilla/TimeStamp.h"          // for TimeDuration, TimeStamp
-#include "mozilla/UniquePtr.h"          // for UniquePtr
-#include "nsCOMPtr.h"                   // for nsCOMPtr
-#include "nsISupportsImpl.h"            // for NS_INLINE_DECL_THREADSAFE_REFCOUNTING
-#include "nsTArray.h"                   // for nsTArray
-
-namespace tracked_objects {
-class Location;
-} // namespace tracked_objects
-
-namespace mozilla {
-namespace layers {
-
-/** The TaskThrottler prevents update event overruns. It is used in cases where
- * you're sending an async message and waiting for a reply. You need to call
- * PostTask to queue a task and TaskComplete when you get a response.
- *
- * The call to TaskComplete will run the most recent task posted since the last
- * request was sent, if any. This means that at any time there can be at most 1
- * outstanding request being processed and at most 1 queued behind it.
- *
- * However, to guard against task runs that error out and fail to call TaskComplete,
- * the TaskThrottler also has a max-wait timeout. If the caller requests a new
- * task be posted, and it has been greater than the max-wait timeout since the
- * last one was sent, then we send the new one regardless of whether or not the
- * last one was marked as completed.
- *
- * This is used in the context of repainting a scrollable region. While another
- * process is painting you might get several updates from the UI thread but when
- * the paint is complete you want to send the most recent.
- */
-
-class TaskThrottler {
-public:
-  TaskThrottler(const TimeStamp& aTimeStamp, const TimeDuration& aMaxWait);
-
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TaskThrottler)
-
-  /** Post a task to be run as soon as there are no outstanding tasks, or
-   * post it immediately if it has been more than the max-wait time since
-   * the last task was posted.
-   *
-   * @param aLocation Use the macro FROM_HERE
-   * @param aTask     Ownership of this object is transferred to TaskThrottler
-   *                  which will delete it when it is either run or becomes
-   *                  obsolete or the TaskThrottler is destructed.
-   */
-  void PostTask(const tracked_objects::Location& aLocation,
-                UniquePtr<CancelableTask> aTask, const TimeStamp& aTimeStamp);
-  /**
-   * Mark the task as complete and process the next queued task.
-   */
-  void TaskComplete(const TimeStamp& aTimeStamp);
-
-  /**
-   * Calculate the average time between processing the posted task and getting
-   * the TaskComplete() call back.
-   */
-  TimeDuration AverageDuration();
-
-  /**
-   * Cancel the queued task if there is one.
-   */
-  void CancelPendingTask();
-
-  /**
-   * Return the time elapsed since the last request was processed
-   */
-  TimeDuration TimeSinceLastRequest(const TimeStamp& aTimeStamp);
-
-  /**
-   * Clear average history.
-   */
-  void ClearHistory();
-
-  /**
-   * @param aMaxDurations The maximum number of durations to measure.
-   */
-
-  void SetMaxDurations(uint32_t aMaxDurations);
-
-private:
-  mutable Monitor mMonitor;
-  bool mOutstanding;
-  UniquePtr<CancelableTask> mQueuedTask;
-  TimeStamp mStartTime;
-  TimeDuration mMaxWait;
-  RollingMean<TimeDuration, TimeDuration> mMean;
-  CancelableTask* mTimeoutTask;  // not owned because it's posted to a MessageLoop
-                                 // which deletes it
-
-  ~TaskThrottler();
-  void RunQueuedTask(const TimeStamp& aTimeStamp,
-                     const MonitorAutoLock& aProofOfLock);
-  void CancelPendingTask(const MonitorAutoLock& aProofOfLock);
-  TimeDuration TimeSinceLastRequest(const TimeStamp& aTimeStamp,
-                                    const MonitorAutoLock& aProofOfLock);
-  void OnTimeout();
-  void CancelTimeoutTask(const MonitorAutoLock& aProofOfLock);
-};
-
-} // namespace layers
-} // namespace mozilla
-
-#endif // mozilla_dom_TaskThrottler_h
--- a/gfx/layers/apz/test/gtest/TestAsyncPanZoomController.cpp
+++ b/gfx/layers/apz/test/gtest/TestAsyncPanZoomController.cpp
@@ -149,35 +149,33 @@ public:
   explicit TestAPZCTreeManager(MockContentControllerDelayed* aMcc) : mcc(aMcc) {}
 
   RefPtr<InputQueue> GetInputQueue() const {
     return mInputQueue;
   }
 
 protected:
   AsyncPanZoomController* NewAPZCInstance(uint64_t aLayersId,
-                                          GeckoContentController* aController,
-                                          TaskThrottler* aPaintThrottler) override;
+                                          GeckoContentController* aController) override;
 
   TimeStamp GetFrameTime() override {
     return mcc->Time();
   }
 
 private:
   RefPtr<MockContentControllerDelayed> mcc;
 };
 
 class TestAsyncPanZoomController : public AsyncPanZoomController {
 public:
   TestAsyncPanZoomController(uint64_t aLayersId, MockContentControllerDelayed* aMcc,
                              TestAPZCTreeManager* aTreeManager,
-                             TaskThrottler* aPaintThrottler,
                              GestureBehavior aBehavior = DEFAULT_GESTURES)
     : AsyncPanZoomController(aLayersId, aTreeManager, aTreeManager->GetInputQueue(),
-        aMcc, aPaintThrottler, aBehavior)
+        aMcc, aBehavior)
     , mWaitForMainThread(false)
     , mcc(aMcc)
   {}
 
   nsEventStatus ReceiveInputEvent(const InputData& aEvent, ScrollableLayerGuid* aDummy, uint64_t* aOutInputBlockId) {
     // This is a function whose signature matches exactly the ReceiveInputEvent
     // on APZCTreeManager. This allows us to templates for functions like
     // TouchDown, TouchUp, etc so that we can reuse the code for dispatching
@@ -256,21 +254,20 @@ public:
 
 private:
   bool mWaitForMainThread;
   MockContentControllerDelayed* mcc;
 };
 
 AsyncPanZoomController*
 TestAPZCTreeManager::NewAPZCInstance(uint64_t aLayersId,
-                                     GeckoContentController* aController,
-                                     TaskThrottler* aPaintThrottler)
+                                     GeckoContentController* aController)
 {
   MockContentControllerDelayed* mcc = static_cast<MockContentControllerDelayed*>(aController);
-  return new TestAsyncPanZoomController(aLayersId, mcc, this, aPaintThrottler,
+  return new TestAsyncPanZoomController(aLayersId, mcc, this,
       AsyncPanZoomController::USE_GESTURE_DETECTOR);
 }
 
 static FrameMetrics
 TestFrameMetrics()
 {
   FrameMetrics fm;
 
@@ -292,19 +289,18 @@ public:
 protected:
   virtual void SetUp()
   {
     gfxPrefs::GetSingleton();
     APZThreadUtils::SetThreadAssertionsEnabled(false);
     APZThreadUtils::SetControllerThread(MessageLoop::current());
 
     mcc = new NiceMock<MockContentControllerDelayed>();
-    mPaintThrottler = new TaskThrottler(mcc->Time(), TimeDuration::FromMilliseconds(500));
     tm = new TestAPZCTreeManager(mcc);
-    apzc = new TestAsyncPanZoomController(0, mcc, tm, mPaintThrottler, mGestureBehavior);
+    apzc = new TestAsyncPanZoomController(0, mcc, tm, mGestureBehavior);
     apzc->SetFrameMetrics(TestFrameMetrics());
   }
 
   /**
    * Get the APZC's scroll range in CSS pixels.
    */
   CSSRect GetScrollRange() const
   {
@@ -377,17 +373,16 @@ protected:
     EXPECT_TRUE(recoveredFromOverscroll);
     apzc->AssertStateIsReset();
   }
 
   void TestOverscroll();
 
   AsyncPanZoomController::GestureBehavior mGestureBehavior;
   RefPtr<MockContentControllerDelayed> mcc;
-  RefPtr<TaskThrottler> mPaintThrottler;
   RefPtr<TestAPZCTreeManager> tm;
   RefPtr<TestAsyncPanZoomController> apzc;
 };
 
 class APZCGestureDetectorTester : public APZCBasicTester {
 public:
   APZCGestureDetectorTester()
     : APZCBasicTester(AsyncPanZoomController::USE_GESTURE_DETECTOR)
@@ -1137,17 +1132,17 @@ TEST_F(APZCBasicTester, ComplexTransform
   // CSS transforms, the two layers are the same size in screen
   // pixels.
   //
   // The screen itself is 24x24 in screen pixels (therefore 4x4 in
   // CSS pixels). The displayport is 1 extra CSS pixel on all
   // sides.
 
   RefPtr<TestAsyncPanZoomController> childApzc =
-      new TestAsyncPanZoomController(0, mcc, tm, mPaintThrottler);
+      new TestAsyncPanZoomController(0, mcc, tm);
 
   const char* layerTreeSyntax = "c(c)";
   // LayerID                     0 1
   nsIntRegion layerVisibleRegion[] = {
     nsIntRegion(IntRect(0, 0, 300, 300)),
     nsIntRegion(IntRect(0, 0, 150, 300)),
   };
   Matrix4x4 transforms[] = {
@@ -3488,94 +3483,8 @@ public:
 
   virtual void Cancel() {
     mMetrics.IncrementCancelCount();
   }
 
 private:
   TaskRunMetrics& mMetrics;
 };
-
-class APZTaskThrottlerTester : public ::testing::Test {
-public:
-  APZTaskThrottlerTester()
-  {
-    now = TimeStamp::Now();
-    throttler = new TaskThrottler(now, TimeDuration::FromMilliseconds(100));
-  }
-
-protected:
-  TimeStamp Advance(int aMillis = 5)
-  {
-    now = now + TimeDuration::FromMilliseconds(aMillis);
-    return now;
-  }
-
-  UniquePtr<CancelableTask> NewTask()
-  {
-    return MakeUnique<MockTask>(metrics);
-  }
-
-  TimeStamp now;
-  RefPtr<TaskThrottler> throttler;
-  TaskRunMetrics metrics;
-};
-
-TEST_F(APZTaskThrottlerTester, BasicTest) {
-  // Check that posting the first task runs right away
-  throttler->PostTask(FROM_HERE, NewTask(), Advance());         // task 1
-  EXPECT_EQ(1, metrics.GetAndClearRunCount());
-
-  // Check that posting the second task doesn't run until the first one is done
-  throttler->PostTask(FROM_HERE, NewTask(), Advance());         // task 2
-  EXPECT_EQ(0, metrics.GetAndClearRunCount());
-  throttler->TaskComplete(Advance());                           // for task 1
-  EXPECT_EQ(1, metrics.GetAndClearRunCount());
-  EXPECT_EQ(0, metrics.GetAndClearCancelCount());
-
-  // Check that tasks are coalesced: dispatch 5 tasks
-  // while there is still one outstanding, and ensure
-  // that only one of the 5 runs
-  throttler->PostTask(FROM_HERE, NewTask(), Advance());         // task 3
-  throttler->PostTask(FROM_HERE, NewTask(), Advance());         // task 4
-  throttler->PostTask(FROM_HERE, NewTask(), Advance());         // task 5
-  throttler->PostTask(FROM_HERE, NewTask(), Advance());         // task 6
-  throttler->PostTask(FROM_HERE, NewTask(), Advance());         // task 7
-  EXPECT_EQ(0, metrics.GetAndClearRunCount());
-  EXPECT_EQ(4, metrics.GetAndClearCancelCount());
-
-  throttler->TaskComplete(Advance());                           // for task 2
-  EXPECT_EQ(1, metrics.GetAndClearRunCount());
-  throttler->TaskComplete(Advance());                           // for task 7 (tasks 3..6 were cancelled)
-  EXPECT_EQ(0, metrics.GetAndClearRunCount());
-  EXPECT_EQ(0, metrics.GetAndClearCancelCount());
-}
-
-TEST_F(APZTaskThrottlerTester, TimeoutTest) {
-  // Check that posting the first task runs right away
-  throttler->PostTask(FROM_HERE, NewTask(), Advance());         // task 1
-  EXPECT_EQ(1, metrics.GetAndClearRunCount());
-
-  // Because we let 100ms pass, the second task should
-  // run immediately even though the first one isn't
-  // done yet
-  throttler->PostTask(FROM_HERE, NewTask(), Advance(100));      // task 2; task 1 is assumed lost
-  EXPECT_EQ(1, metrics.GetAndClearRunCount());
-  throttler->TaskComplete(Advance());                           // for task 1, but TaskThrottler thinks it's for task 2
-  throttler->TaskComplete(Advance());                           // for task 2, TaskThrottler ignores it
-  EXPECT_EQ(0, metrics.GetAndClearRunCount());
-  EXPECT_EQ(0, metrics.GetAndClearCancelCount());
-
-  // This time queue up a few tasks before the timeout expires
-  // and ensure cancellation still works as expected
-  throttler->PostTask(FROM_HERE, NewTask(), Advance());         // task 3
-  EXPECT_EQ(1, metrics.GetAndClearRunCount());
-  throttler->PostTask(FROM_HERE, NewTask(), Advance());         // task 4
-  throttler->PostTask(FROM_HERE, NewTask(), Advance());         // task 5
-  throttler->PostTask(FROM_HERE, NewTask(), Advance());         // task 6
-  EXPECT_EQ(0, metrics.GetAndClearRunCount());
-  throttler->PostTask(FROM_HERE, NewTask(), Advance(100));      // task 7; task 3 is assumed lost
-  EXPECT_EQ(1, metrics.GetAndClearRunCount());
-  EXPECT_EQ(3, metrics.GetAndClearCancelCount());               // tasks 4..6 should have been cancelled
-  throttler->TaskComplete(Advance());                           // for task 7
-  EXPECT_EQ(0, metrics.GetAndClearRunCount());
-  EXPECT_EQ(0, metrics.GetAndClearCancelCount());
-}
--- a/gfx/layers/ipc/CompositorParent.cpp
+++ b/gfx/layers/ipc/CompositorParent.cpp
@@ -1541,32 +1541,25 @@ CompositorParent::RecvNotifyChildCreated
   MonitorAutoLock lock(*sIndirectLayerTreesLock);
   NotifyChildCreated(child);
   return true;
 }
 
 void
 CompositorParent::NotifyChildCreated(const uint64_t& aChild)
 {
-  if (mApzcTreeManager) {
-    NS_DispatchToMainThread(NS_NewRunnableMethodWithArg<uint64_t>(
-        mApzcTreeManager, &APZCTreeManager::InitializeForLayersId, aChild));
-  }
   sIndirectLayerTreesLock->AssertCurrentThreadOwns();
   sIndirectLayerTrees[aChild].mParent = this;
   sIndirectLayerTrees[aChild].mLayerManager = mLayerManager;
 }
 
 bool
 CompositorParent::RecvAdoptChild(const uint64_t& child)
 {
   MonitorAutoLock lock(*sIndirectLayerTreesLock);
-  if (mApzcTreeManager) {
-    mApzcTreeManager->AdoptLayersId(child, sIndirectLayerTrees[child].mParent->mApzcTreeManager.get());
-  }
   NotifyChildCreated(child);
   if (sIndirectLayerTrees[child].mLayerTree) {
     sIndirectLayerTrees[child].mLayerTree->mLayerManager = mLayerManager;
   }
   if (sIndirectLayerTrees[child].mRoot) {
     sIndirectLayerTrees[child].mRoot->AsLayerComposite()->SetLayerManager(mLayerManager);
   }
   return true;
@@ -1628,35 +1621,31 @@ UpdateControllerForLayersId(uint64_t aLa
 
 ScopedLayerTreeRegistration::ScopedLayerTreeRegistration(APZCTreeManager* aApzctm,
                                                          uint64_t aLayersId,
                                                          Layer* aRoot,
                                                          GeckoContentController* aController)
     : mLayersId(aLayersId)
 {
   EnsureLayerTreeMapReady();
-  aApzctm->InitializeForLayersId(aLayersId);
   MonitorAutoLock lock(*sIndirectLayerTreesLock);
   sIndirectLayerTrees[aLayersId].mRoot = aRoot;
   sIndirectLayerTrees[aLayersId].mController = aController;
 }
 
 ScopedLayerTreeRegistration::~ScopedLayerTreeRegistration()
 {
   MonitorAutoLock lock(*sIndirectLayerTreesLock);
   sIndirectLayerTrees.erase(mLayersId);
 }
 
 /*static*/ void
 CompositorParent::SetControllerForLayerTree(uint64_t aLayersId,
                                             GeckoContentController* aController)
 {
-  if (APZCTreeManager* apzctm = GetAPZCTreeManager(aLayersId)) {
-    apzctm->InitializeForLayersId(aLayersId);
-  }
   // This ref is adopted by UpdateControllerForLayersId().
   aController->AddRef();
   CompositorLoop()->PostTask(FROM_HERE,
                              NewRunnableFunction(&UpdateControllerForLayersId,
                                                  aLayersId,
                                                  aController));
 }
 
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -244,17 +244,16 @@ UNIFIED_SOURCES += [
     'apz/src/APZCTreeManager.cpp',
     'apz/src/AsyncPanZoomController.cpp',
     'apz/src/Axis.cpp',
     'apz/src/GestureEventListener.cpp',
     'apz/src/HitTestingTreeNode.cpp',
     'apz/src/InputBlockState.cpp',
     'apz/src/InputQueue.cpp',
     'apz/src/OverscrollHandoffState.cpp',
-    'apz/src/TaskThrottler.cpp',
     'apz/src/TouchCounter.cpp',
     'apz/src/WheelScrollAnimation.cpp',
     'apz/testutil/APZTestData.cpp',
     'apz/util/ActiveElementManager.cpp',
     'apz/util/APZCCallbackHelper.cpp',
     'apz/util/APZEventState.cpp',
     'apz/util/APZThreadUtils.cpp',
     'apz/util/ChromeProcessController.cpp',