Skip to content

Commit 24843e3

Browse files
committed
Bug 1737722. r=botond
Differential Revision: https://phabricator.services.mozilla.com/D145721
1 parent b88de56 commit 24843e3

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

gfx/layers/apz/src/WRHitTester.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "mozilla/webrender/WebRenderAPI.h"
1313
#include "nsDebug.h" // for NS_ASSERTION
1414
#include "nsIXULRuntime.h" // for FissionAutostart
15+
#include "mozilla/gfx/Matrix.h"
1516

1617
#define APZCTM_LOG(...) \
1718
MOZ_LOG(APZCTreeManager::sLog, LogLevel::Debug, (__VA_ARGS__))
@@ -22,6 +23,53 @@ namespace layers {
2223
using mozilla::gfx::CompositorHitTestFlags;
2324
using mozilla::gfx::CompositorHitTestInvisibleToHit;
2425

26+
static bool CheckCloseToIdentity(const gfx::Matrix4x4& aMatrix) {
27+
// We allow a factor of 1/2048 in the multiply part of the matrix, so that if
28+
// we multiply by a point on a screen of size 2048 we would be off by at most
29+
// 1 pixel approximately.
30+
const float multiplyEps = 1 / 2048.f;
31+
// We allow 1 pixel in the translate part of the matrix.
32+
const float translateEps = 1.f;
33+
34+
if (!FuzzyEqualsAdditive(aMatrix._11, 1.f, multiplyEps) ||
35+
!FuzzyEqualsAdditive(aMatrix._12, 0.f, multiplyEps) ||
36+
!FuzzyEqualsAdditive(aMatrix._13, 0.f, multiplyEps) ||
37+
!FuzzyEqualsAdditive(aMatrix._14, 0.f, multiplyEps) ||
38+
!FuzzyEqualsAdditive(aMatrix._21, 0.f, multiplyEps) ||
39+
!FuzzyEqualsAdditive(aMatrix._22, 1.f, multiplyEps) ||
40+
!FuzzyEqualsAdditive(aMatrix._23, 0.f, multiplyEps) ||
41+
!FuzzyEqualsAdditive(aMatrix._24, 0.f, multiplyEps) ||
42+
!FuzzyEqualsAdditive(aMatrix._31, 0.f, multiplyEps) ||
43+
!FuzzyEqualsAdditive(aMatrix._32, 0.f, multiplyEps) ||
44+
!FuzzyEqualsAdditive(aMatrix._33, 1.f, multiplyEps) ||
45+
!FuzzyEqualsAdditive(aMatrix._34, 0.f, multiplyEps) ||
46+
!FuzzyEqualsAdditive(aMatrix._41, 0.f, translateEps) ||
47+
!FuzzyEqualsAdditive(aMatrix._42, 0.f, translateEps) ||
48+
!FuzzyEqualsAdditive(aMatrix._43, 0.f, translateEps) ||
49+
!FuzzyEqualsAdditive(aMatrix._44, 1.f, multiplyEps)) {
50+
return false;
51+
}
52+
return true;
53+
}
54+
55+
// Checks that within the constraints of floating point math we can invert it
56+
// reasonably enough that multiplying by the computed inverse is close to the
57+
// identity.
58+
static bool CheckInvertibleWithFinitePrecision(const gfx::Matrix4x4& aMatrix) {
59+
auto inverse = aMatrix.MaybeInverse();
60+
if (inverse.isNothing()) {
61+
// Should we return false?
62+
return true;
63+
}
64+
if (!CheckCloseToIdentity(aMatrix * *inverse)) {
65+
return false;
66+
}
67+
if (!CheckCloseToIdentity(*inverse * aMatrix)) {
68+
return false;
69+
}
70+
return true;
71+
}
72+
2573
IAPZHitTester::HitTestResult WRHitTester::GetAPZCAtPoint(
2674
const ScreenPoint& aHitTestPoint,
2775
const RecursiveMutexAutoLock& aProofOfTreeLock) {
@@ -96,6 +144,19 @@ IAPZHitTester::HitTestResult WRHitTester::GetAPZCAtPoint(
96144
continue;
97145
}
98146

147+
if (!CheckInvertibleWithFinitePrecision(
148+
mTreeManager->GetScreenToApzcTransform(node->GetApzc())
149+
.ToUnknownMatrix())) {
150+
APZCTM_LOG("skipping due to check inverse accuracy\n");
151+
continue;
152+
}
153+
if (!CheckInvertibleWithFinitePrecision(
154+
mTreeManager->GetApzcToGeckoTransform(node->GetApzc())
155+
.ToUnknownMatrix())) {
156+
APZCTM_LOG("skipping due to check inverse accuracy\n");
157+
continue;
158+
}
159+
99160
APZCTM_LOG("selecting as chosen result.\n");
100161
chosenResult = Some(result);
101162
hit.mTargetApzc = node->GetApzc();

0 commit comments

Comments
 (0)