Bug 1352564 - Add a method to invert a Matrix4x4 if it's invertible. r=botond
authorBotond Ballo <botond@mozilla.com>
Sun, 02 Apr 2017 17:20:23 -0400
changeset 350903 6544bde4a06e
parent 350902 967edd49939b
child 350904 5af677c09ae7
push id31594
push usercbook@mozilla.com
push dateMon, 03 Apr 2017 10:14:16 +0000
treeherdermozilla-central@aaa0cd3bd620 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1352564
milestone55.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 1352564 - Add a method to invert a Matrix4x4 if it's invertible. r=botond Use it in HitTestingTreeNode::Untransform. MozReview-Commit-ID: 1JkLh99FD0h
gfx/2d/Matrix.h
gfx/layers/apz/src/HitTestingTreeNode.cpp
--- a/gfx/2d/Matrix.h
+++ b/gfx/2d/Matrix.h
@@ -1231,16 +1231,26 @@ public:
   {
     typedef Matrix4x4Typed<TargetUnits, SourceUnits> InvertedMatrix;
     InvertedMatrix clone = InvertedMatrix::FromUnknownMatrix(ToUnknownMatrix());
     DebugOnly<bool> inverted = clone.Invert();
     MOZ_ASSERT(inverted, "Attempted to get the inverse of a non-invertible matrix");
     return clone;
   }
 
+  Maybe<Matrix4x4Typed<TargetUnits, SourceUnits>> MaybeInverse() const
+  {
+    typedef Matrix4x4Typed<TargetUnits, SourceUnits> InvertedMatrix;
+    InvertedMatrix clone = InvertedMatrix::FromUnknownMatrix(ToUnknownMatrix());
+    if (clone.Invert()) {
+      return Some(clone);
+    }
+    return Nothing();
+  }
+  
   void Normalize()
   {
       for (int i = 0; i < 4; i++) {
           for (int j = 0; j < 4; j++) {
               (*this)[i][j] /= (*this)[3][3];
          }
       }
   }
--- a/gfx/layers/apz/src/HitTestingTreeNode.cpp
+++ b/gfx/layers/apz/src/HitTestingTreeNode.cpp
@@ -250,17 +250,21 @@ Maybe<LayerPoint>
 HitTestingTreeNode::Untransform(const ParentLayerPoint& aPoint) const
 {
   // convert into Layer coordinate space
   LayerToParentLayerMatrix4x4 transform = mTransform *
       CompleteAsyncTransform(
         mApzc
       ? mApzc->GetCurrentAsyncTransformWithOverscroll(AsyncPanZoomController::NORMAL)
       : AsyncTransformComponentMatrix());
-  return UntransformBy(transform.Inverse(), aPoint);
+  Maybe<ParentLayerToLayerMatrix4x4> inverse = transform.MaybeInverse();
+  if (inverse) {
+    return UntransformBy(inverse.ref(), aPoint);
+  }
+  return Nothing();
 }
 
 HitTestResult
 HitTestingTreeNode::HitTest(const ParentLayerPoint& aPoint) const
 {
   // This should only ever get called if the point is inside the clip region
   // for this node.
   MOZ_ASSERT(!IsOutsideClip(aPoint));