Bug 1364622 - Factor out a helper function for computing the current async transform for a HitTestingTreeNode. r=kats
authorBotond Ballo <botond@mozilla.com>
Wed, 17 May 2017 15:02:18 -0400
changeset 579734 9da6da9c2a6580b7b028356d2a04265ebd18d9ec
parent 579733 3fdd6a00215ba8bfc9a717d3ab0e7ba0e21d4700
child 579735 cb603b519a5db41cd74ebdf2a9245480e9549fac
push id59357
push userbballo@mozilla.com
push dateWed, 17 May 2017 19:07:47 +0000
reviewerskats
bugs1364622
milestone55.0a1
Bug 1364622 - Factor out a helper function for computing the current async transform for a HitTestingTreeNode. r=kats MozReview-Commit-ID: 8ySehvzTMDl
gfx/layers/apz/src/APZCTreeManager.cpp
gfx/layers/apz/src/APZCTreeManager.h
gfx/layers/apz/src/HitTestingTreeNode.cpp
gfx/layers/apz/src/HitTestingTreeNode.h
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -1836,30 +1836,31 @@ APZCTreeManager::GetAPZCAtPoint(HitTesti
   // APZCs front-to-back on the screen.
   HitTestingTreeNode* resultNode;
   HitTestingTreeNode* root = aNode;
   std::stack<LayerPoint> hitTestPoints;
   hitTestPoints.push(ViewAs<LayerPixel>(aHitTestPoint,
       PixelCastJustification::MovingDownToChildren));
 
   ForEachNode<ReverseIterator>(root,
-      [&hitTestPoints](HitTestingTreeNode* aNode) {
+      [&hitTestPoints, this](HitTestingTreeNode* aNode) {
         ParentLayerPoint hitTestPointForParent = ViewAs<ParentLayerPixel>(hitTestPoints.top(),
             PixelCastJustification::MovingDownToChildren);
         if (aNode->IsOutsideClip(hitTestPointForParent)) {
           // If the point being tested is outside the clip region for this node
           // then we don't need to test against this node or any of its children.
           // Just skip it and move on.
           APZCTM_LOG("Point %f %f outside clip for node %p\n",
             hitTestPoints.top().x, hitTestPoints.top().y, aNode);
           return TraversalFlag::Skip;
         }
         // First check the subtree rooted at this node, because deeper nodes
         // are more "in front".
-        Maybe<LayerPoint> hitTestPoint = aNode->Untransform(hitTestPointForParent);
+        Maybe<LayerPoint> hitTestPoint = aNode->Untransform(
+            hitTestPointForParent, ComputeTransformForNode(aNode));
         APZCTM_LOG("Transformed ParentLayer point %s to layer %s\n",
                 Stringify(hitTestPointForParent).c_str(),
                 hitTestPoint ? Stringify(hitTestPoint.ref()).c_str() : "nil");
         if (!hitTestPoint) {
           return TraversalFlag::Skip;
         }
         hitTestPoints.push(hitTestPoint.ref());
         return TraversalFlag::Continue;
@@ -2199,16 +2200,27 @@ APZCTreeManager::CommonAncestor(AsyncPan
       break;
     }
     aApzc1 = aApzc1->GetParent();
     aApzc2 = aApzc2->GetParent();
   }
   return ancestor.forget();
 }
 
+LayerToParentLayerMatrix4x4
+APZCTreeManager::ComputeTransformForNode(const HitTestingTreeNode* aNode) const
+{
+  AsyncPanZoomController* apzc = aNode->GetApzc();
+  return aNode->GetTransform() *
+      CompleteAsyncTransform(
+        apzc
+      ? apzc->GetCurrentAsyncTransformWithOverscroll(AsyncPanZoomController::NORMAL)
+      : AsyncTransformComponentMatrix());
+}
+
 #if defined(MOZ_WIDGET_ANDROID)
 void
 APZCTreeManager::InitializeDynamicToolbarAnimator(const int64_t& aRootLayerTreeId)
 {
   MOZ_ASSERT(mToolbarAnimator);
   mToolbarAnimator->Initialize(aRootLayerTreeId);
 }
 
--- a/gfx/layers/apz/src/APZCTreeManager.h
+++ b/gfx/layers/apz/src/APZCTreeManager.h
@@ -500,16 +500,19 @@ private:
                                           TreeBuildingState& aState);
 
   template<class ScrollNode>
   void PrintAPZCInfo(const ScrollNode& aLayer,
                      const AsyncPanZoomController* apzc);
 
   void NotifyScrollbarDragRejected(const ScrollableLayerGuid& aGuid) const;
 
+  // Requires the caller to hold mTreeLock.
+  LayerToParentLayerMatrix4x4 ComputeTransformForNode(const HitTestingTreeNode* aNode) const;
+
 protected:
   /* The input queue where input events are held until we know enough to
    * figure out where they're going. Protected so gtests can access it.
    */
   RefPtr<InputQueue> mInputQueue;
 
 private:
   /* Whenever walking or mutating the tree rooted at mRootNode, mTreeLock must be held.
--- a/gfx/layers/apz/src/HitTestingTreeNode.cpp
+++ b/gfx/layers/apz/src/HitTestingTreeNode.cpp
@@ -242,25 +242,20 @@ HitTestingTreeNode::SetHitTestData(const
 bool
 HitTestingTreeNode::IsOutsideClip(const ParentLayerPoint& aPoint) const
 {
   // test against clip rect in ParentLayer coordinate space
   return (mClipRegion.isSome() && !mClipRegion->Contains(aPoint.x, aPoint.y));
 }
 
 Maybe<LayerPoint>
-HitTestingTreeNode::Untransform(const ParentLayerPoint& aPoint) const
+HitTestingTreeNode::Untransform(const ParentLayerPoint& aPoint,
+                                const LayerToParentLayerMatrix4x4& aTransform) const
 {
-  // convert into Layer coordinate space
-  LayerToParentLayerMatrix4x4 transform = mTransform *
-      CompleteAsyncTransform(
-        mApzc
-      ? mApzc->GetCurrentAsyncTransformWithOverscroll(AsyncPanZoomController::NORMAL)
-      : AsyncTransformComponentMatrix());
-  Maybe<ParentLayerToLayerMatrix4x4> inverse = transform.MaybeInverse();
+  Maybe<ParentLayerToLayerMatrix4x4> inverse = aTransform.MaybeInverse();
   if (inverse) {
     return UntransformBy(inverse.ref(), aPoint);
   }
   return Nothing();
 }
 
 HitTestResult
 HitTestingTreeNode::HitTest(const LayerPoint& aPoint) const
@@ -298,16 +293,22 @@ HitTestingTreeNode::HitTest(const LayerP
 }
 
 EventRegionsOverride
 HitTestingTreeNode::GetEventRegionsOverride() const
 {
   return mOverride;
 }
 
+const CSSTransformMatrix&
+HitTestingTreeNode::GetTransform() const
+{
+  return mTransform;
+}
+
 void
 HitTestingTreeNode::Dump(const char* aPrefix) const
 {
   if (mPrevSibling) {
     mPrevSibling->Dump(aPrefix);
   }
   printf_stderr("%sHitTestingTreeNode (%p) APZC (%p) g=(%s) %s%s%sr=(%s) t=(%s) c=(%s)\n",
     aPrefix, this, mApzc.get(),
--- a/gfx/layers/apz/src/HitTestingTreeNode.h
+++ b/gfx/layers/apz/src/HitTestingTreeNode.h
@@ -100,24 +100,27 @@ public:
   FrameMetrics::ViewID GetScrollTargetId() const;
   const ScrollThumbData& GetScrollThumbData() const;
 
   /* Fixed pos info */
 
   void SetFixedPosData(FrameMetrics::ViewID aFixedPosTarget);
   FrameMetrics::ViewID GetFixedPosTarget() const;
 
-  /* Convert aPoint into the LayerPixel space for the layer corresponding to
+  /* Convert |aPoint| into the LayerPixel space for the layer corresponding to
+   * this node. |aTransform| is the complete (content + async) transform for
    * this node. */
-  Maybe<LayerPoint> Untransform(const ParentLayerPoint& aPoint) const;
+  Maybe<LayerPoint> Untransform(const ParentLayerPoint& aPoint,
+                                const LayerToParentLayerMatrix4x4& aTransform) const;
   /* Assuming aPoint is inside the clip region for this node, check which of the
    * event region spaces it falls inside. */
   HitTestResult HitTest(const LayerPoint& aPoint) const;
   /* Returns the mOverride flag. */
   EventRegionsOverride GetEventRegionsOverride() const;
+  const CSSTransformMatrix& GetTransform() const;
 
   /* Debug helpers */
   void Dump(const char* aPrefix = "") const;
 
 private:
   void SetApzcParent(AsyncPanZoomController* aApzc);
 
   RefPtr<HitTestingTreeNode> mLastChild;