From 9ebdb4f7f0c7e01f748a7fc3db4c515a8676bf44 Mon Sep 17 00:00:00 2001 From: Botond Ballo Date: Sun, 2 Apr 2017 17:20:23 -0400 Subject: [PATCH] Bug 1352564 - Add a method to invert a Matrix4x4 if it's invertible. r=botond Use it in HitTestingTreeNode::Untransform. MozReview-Commit-ID: 1JkLh99FD0h --HG-- extra : rebase_source : ca9836c1999a2af3cac5287a9efa875c415634f7 --- gfx/2d/Matrix.h | 10 ++++++++++ gfx/layers/apz/src/HitTestingTreeNode.cpp | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/gfx/2d/Matrix.h b/gfx/2d/Matrix.h index 22a01ca1031c..6a3fcf4728e3 100644 --- a/gfx/2d/Matrix.h +++ b/gfx/2d/Matrix.h @@ -1236,6 +1236,16 @@ public: return clone; } + Maybe> MaybeInverse() const + { + typedef Matrix4x4Typed InvertedMatrix; + InvertedMatrix clone = InvertedMatrix::FromUnknownMatrix(ToUnknownMatrix()); + if (clone.Invert()) { + return Some(clone); + } + return Nothing(); + } + void Normalize() { for (int i = 0; i < 4; i++) { diff --git a/gfx/layers/apz/src/HitTestingTreeNode.cpp b/gfx/layers/apz/src/HitTestingTreeNode.cpp index 8e916deeae18..0fe7ffa1d334 100644 --- a/gfx/layers/apz/src/HitTestingTreeNode.cpp +++ b/gfx/layers/apz/src/HitTestingTreeNode.cpp @@ -255,7 +255,11 @@ HitTestingTreeNode::Untransform(const ParentLayerPoint& aPoint) const mApzc ? mApzc->GetCurrentAsyncTransformWithOverscroll(AsyncPanZoomController::NORMAL) : AsyncTransformComponentMatrix()); - return UntransformBy(transform.Inverse(), aPoint); + Maybe inverse = transform.MaybeInverse(); + if (inverse) { + return UntransformBy(inverse.ref(), aPoint); + } + return Nothing(); } HitTestResult