Bug 1289432 - Drop the DispatchImmediate codepath. r=botond
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 14 Sep 2016 07:54:36 -0400
changeset 355215 b40d59513ee6954ab7fff73689fa834727b4a0fa
parent 355214 4284c891813dafaaacc329ca931997d16532817a
child 355216 868e5e9845acedf0bcf69c01ace18e8107f3c94c
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1289432
milestone51.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 1289432 - Drop the DispatchImmediate codepath. r=botond Instead of having this special shortcut case that goes through MaybeHandleCurrentBlock and DispatchImmediate, we can just add the input to the queue normally and call ProcessInputBlocks() which effectively does the same thing. Doing it this way also guarantees that mQueuedInputs is non-empty and mQueuedInputs[0] is the input currently being processed. This is useful for future patches because it will allow us to maintain the guarantee that the input block for the input currently being processed can be readily accessed via GetCurrentInputBlock(). MozReview-Commit-ID: JuVbpsFLURo
gfx/layers/apz/src/InputBlockState.cpp
gfx/layers/apz/src/InputBlockState.h
gfx/layers/apz/src/InputQueue.cpp
gfx/layers/apz/src/InputQueue.h
--- a/gfx/layers/apz/src/InputBlockState.cpp
+++ b/gfx/layers/apz/src/InputBlockState.cpp
@@ -220,24 +220,16 @@ CancelableBlockState::IsReadyForHandling
 {
   if (!IsTargetConfirmed()) {
     return false;
   }
   return mContentResponded || mContentResponseTimerExpired;
 }
 
 void
-CancelableBlockState::DispatchImmediate(const InputData& aEvent) const
-{
-  MOZ_ASSERT(!HasEvents());
-  MOZ_ASSERT(GetTargetApzc());
-  DispatchEvent(aEvent);
-}
-
-void
 CancelableBlockState::DispatchEvent(const InputData& aEvent) const
 {
   GetTargetApzc()->HandleInputEvent(aEvent, mTransformToApzc);
 }
 
 void
 CancelableBlockState::RecordContentResponseTime()
 {
--- a/gfx/layers/apz/src/InputBlockState.h
+++ b/gfx/layers/apz/src/InputBlockState.h
@@ -160,23 +160,16 @@ public:
   bool IsContentResponseTimerExpired() const;
 
   /**
    * @return true iff web content cancelled this block of events.
    */
   bool IsDefaultPrevented() const;
 
   /**
-   * Process the given event using this input block's target apzc.
-   * This input block must not have pending events, and its apzc must not be
-   * nullptr.
-   */
-  void DispatchImmediate(const InputData& aEvent) const;
-
-  /**
    * Dispatch the event to the target APZC. Mostly this is a hook for
    * subclasses to do any per-event processing they need to.
    */
   virtual void DispatchEvent(const InputData& aEvent) const;
 
   /**
    * @return true iff this block has received all the information it could
    *         have gotten from the content thread.
--- a/gfx/layers/apz/src/InputQueue.cpp
+++ b/gfx/layers/apz/src/InputQueue.cpp
@@ -61,33 +61,16 @@ InputQueue::ReceiveInputEvent(const RefP
       // The return value for non-touch input is only used by tests, so just pass
       // through the return value for now. This can be changed later if needed.
       // TODO (bug 1098430): we will eventually need to have smarter handling for
       // non-touch events as well.
       return aTarget->HandleInputEvent(aEvent, aTarget->GetTransformToThis());
   }
 }
 
-bool
-InputQueue::MaybeHandleCurrentBlock(CancelableBlockState *block,
-                                    const InputData& aEvent) {
-  if (mQueuedInputs.IsEmpty() && block->IsReadyForHandling()) {
-    const RefPtr<AsyncPanZoomController>& target = block->GetTargetApzc();
-    INPQ_LOG("current block is ready with target %p preventdefault %d\n",
-        target.get(), block->IsDefaultPrevented());
-    if (!target || block->IsDefaultPrevented()) {
-      return true;
-    }
-    UpdateActiveApzc(block->GetTargetApzc());
-    block->DispatchImmediate(aEvent);
-    return true;
-  }
-  return false;
-}
-
 nsEventStatus
 InputQueue::ReceiveTouchInput(const RefPtr<AsyncPanZoomController>& aTarget,
                               bool aTargetConfirmed,
                               const MultiTouchInput& aEvent,
                               uint64_t* aOutInputBlockId) {
   TouchBlockState* block = nullptr;
   if (aEvent.mType == MultiTouchInput::MULTITOUCH_START) {
     nsTArray<TouchBehaviorFlags> currentBehaviors;
@@ -165,20 +148,19 @@ InputQueue::ReceiveTouchInput(const RefP
       result = nsEventStatus_eConsumeNoDefault;
     } else {
       result = nsEventStatus_eConsumeDoDefault;
     }
   } else if (block->UpdateSlopState(aEvent.AsMultiTouchInput(), false)) {
     INPQ_LOG("dropping event due to block %p being in mini-slop\n", block);
     result = nsEventStatus_eConsumeNoDefault;
   }
-  if (!MaybeHandleCurrentBlock(block, aEvent)) {
-    block->AddEvent(aEvent.AsMultiTouchInput());
-    mQueuedInputs.AppendElement(MakeUnique<QueuedInput>(aEvent.AsMultiTouchInput(), *block));
-  }
+  block->AddEvent(aEvent.AsMultiTouchInput());
+  mQueuedInputs.AppendElement(MakeUnique<QueuedInput>(aEvent.AsMultiTouchInput(), *block));
+  ProcessInputBlocks();
   return result;
 }
 
 nsEventStatus
 InputQueue::ReceiveMouseInput(const RefPtr<AsyncPanZoomController>& aTarget,
                               bool aTargetConfirmed,
                               const MouseInput& aEvent,
                               uint64_t* aOutInputBlockId) {
@@ -221,20 +203,19 @@ InputQueue::ReceiveMouseInput(const RefP
     CancelAnimationsForNewBlock(block);
     MaybeRequestContentResponse(aTarget, block);
   }
 
   if (aOutInputBlockId) {
     *aOutInputBlockId = block->GetBlockId();
   }
 
-  if (!MaybeHandleCurrentBlock(block, aEvent)) {
-    block->AddEvent(aEvent.AsMouseInput());
-    mQueuedInputs.AppendElement(MakeUnique<QueuedInput>(aEvent.AsMouseInput(), *block));
-  }
+  block->AddEvent(aEvent.AsMouseInput());
+  mQueuedInputs.AppendElement(MakeUnique<QueuedInput>(aEvent.AsMouseInput(), *block));
+  ProcessInputBlocks();
 
   if (DragTracker::EndsDrag(aEvent)) {
     block->MarkMouseUpReceived();
   }
 
   // The event is part of a drag block and could potentially cause
   // scrolling, so return DoDefault.
   return nsEventStatus_eConsumeDoDefault;
@@ -279,21 +260,20 @@ InputQueue::ReceiveScrollWheelInput(cons
   // Copy the event, since WheelBlockState needs to affix a counter.
   ScrollWheelInput event(aEvent);
   block->Update(event);
 
   // Note that the |aTarget| the APZCTM sent us may contradict the confirmed
   // target set on the block. In this case the confirmed target (which may be
   // null) should take priority. This is equivalent to just always using the
   // target (confirmed or not) from the block, which is what
-  // MaybeHandleCurrentBlock() does.
-  if (!MaybeHandleCurrentBlock(block, event)) {
-    block->AddEvent(event);
-    mQueuedInputs.AppendElement(MakeUnique<QueuedInput>(event, *block));
-  }
+  // ProcessInputBlocks() does.
+  block->AddEvent(event);
+  mQueuedInputs.AppendElement(MakeUnique<QueuedInput>(event, *block));
+  ProcessInputBlocks();
 
   return nsEventStatus_eConsumeDoDefault;
 }
 
 static bool
 CanScrollTargetHorizontally(const PanGestureInput& aInitialEvent,
                             PanGestureBlockState* aBlock)
 {
@@ -363,21 +343,20 @@ InputQueue::ReceivePanGestureInput(const
   if (aOutInputBlockId) {
     *aOutInputBlockId = block->GetBlockId();
   }
 
   // Note that the |aTarget| the APZCTM sent us may contradict the confirmed
   // target set on the block. In this case the confirmed target (which may be
   // null) should take priority. This is equivalent to just always using the
   // target (confirmed or not) from the block, which is what
-  // MaybeHandleCurrentBlock() does.
-  if (!MaybeHandleCurrentBlock(block, event)) {
-    block->AddEvent(event.AsPanGestureInput());
-    mQueuedInputs.AppendElement(MakeUnique<QueuedInput>(event.AsPanGestureInput(), *block));
-  }
+  // ProcessInputBlocks() does.
+  block->AddEvent(event.AsPanGestureInput());
+  mQueuedInputs.AppendElement(MakeUnique<QueuedInput>(event.AsPanGestureInput(), *block));
+  ProcessInputBlocks();
 
   return result;
 }
 
 void
 InputQueue::CancelAnimationsForNewBlock(CancelableBlockState* aBlock)
 {
   // We want to cancel animations here as soon as possible (i.e. without waiting for
--- a/gfx/layers/apz/src/InputQueue.h
+++ b/gfx/layers/apz/src/InputQueue.h
@@ -167,23 +167,16 @@ private:
                                         const PanGestureInput& aEvent,
                                         uint64_t* aOutInputBlockId);
 
   /**
    * Remove any blocks that are inactive - not ready, and having no events.
    */
   void SweepDepletedBlocks();
 
-  /**
-   * Processes the current block if it's ready for handling, using the block's
-   * target APZC.
-   */
-  bool MaybeHandleCurrentBlock(CancelableBlockState* block,
-                               const InputData& aEvent);
-
   void ScheduleMainThreadTimeout(const RefPtr<AsyncPanZoomController>& aTarget,
                                  CancelableBlockState* aBlock);
   void MainThreadTimeout(const uint64_t& aInputBlockId);
   void ProcessInputBlocks();
   void ClearActiveBlock(CancelableBlockState* aBlock);
   void UpdateActiveApzc(const RefPtr<AsyncPanZoomController>& aNewActive);
 
 private: