12
12
#include " mozilla/webrender/WebRenderAPI.h"
13
13
#include " nsDebug.h" // for NS_ASSERTION
14
14
#include " nsIXULRuntime.h" // for FissionAutostart
15
+ #include " mozilla/gfx/Matrix.h"
15
16
16
17
#define APZCTM_LOG (...) \
17
18
MOZ_LOG (APZCTreeManager::sLog , LogLevel::Debug, (__VA_ARGS__))
@@ -22,6 +23,53 @@ namespace layers {
22
23
using mozilla::gfx::CompositorHitTestFlags;
23
24
using mozilla::gfx::CompositorHitTestInvisibleToHit;
24
25
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
+
25
73
IAPZHitTester::HitTestResult WRHitTester::GetAPZCAtPoint (
26
74
const ScreenPoint& aHitTestPoint,
27
75
const RecursiveMutexAutoLock& aProofOfTreeLock) {
@@ -96,6 +144,19 @@ IAPZHitTester::HitTestResult WRHitTester::GetAPZCAtPoint(
96
144
continue ;
97
145
}
98
146
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
+
99
160
APZCTM_LOG (" selecting as chosen result.\n " );
100
161
chosenResult = Some (result);
101
162
hit.mTargetApzc = node->GetApzc ();
0 commit comments