Bug 1787099 - Change COORDINATE_EPSILON to type CSSCoord and update uses accordingly. r=botond

Differential Revision: https://phabricator.services.mozilla.com/D155707
This commit is contained in:
Razvan Cojocaru 2022-08-29 00:07:57 +00:00
parent f8a55c3c79
commit 5edbd09ad0
10 changed files with 79 additions and 33 deletions

View file

@ -2758,12 +2758,10 @@ ParentLayerPoint APZCTreeManager::DispatchFling(
// Note: it's important to compare |residualVelocity| to |availableVelocity|
// here and not to |transformedHandoffState.mVelocity|, since the latter
// may have been modified by AdjustHandoffVelocityForOverscrollBehavior().
if (!FuzzyEqualsAdditive(availableVelocity.x, residualVelocity.x,
COORDINATE_EPSILON)) {
if (!current->IsZero(availableVelocity.x - residualVelocity.x)) {
finalResidualVelocity.x *= (residualVelocity.x / availableVelocity.x);
}
if (!FuzzyEqualsAdditive(availableVelocity.y, residualVelocity.y,
COORDINATE_EPSILON)) {
if (!current->IsZero(availableVelocity.y - residualVelocity.y)) {
finalResidualVelocity.y *= (residualVelocity.y / availableVelocity.y);
}

View file

@ -74,11 +74,11 @@ inline bool ScrollSourceAllowsOverscroll(ScrollSource aSource) {
// ten thousands. Note also that the smallest legitimate difference in page
// coordinates is 1 app unit, which is 1/60 of a (CSS pixel), so this epsilon
// isn't too large.
const float COORDINATE_EPSILON = 0.02f;
const CSSCoord COORDINATE_EPSILON = 0.02f;
inline bool IsZero(const CSSPoint& aPoint) {
return FuzzyEqualsAdditive(aPoint.x, 0.0f, COORDINATE_EPSILON) &&
FuzzyEqualsAdditive(aPoint.y, 0.0f, COORDINATE_EPSILON);
return FuzzyEqualsAdditive(aPoint.x, 0.0f, COORDINATE_EPSILON.value) &&
FuzzyEqualsAdditive(aPoint.y, 0.0f, COORDINATE_EPSILON.value);
}
// Represents async transforms consisting of a scale and a translation.

View file

@ -554,6 +554,32 @@ bool AsyncPanZoomController::IsZero(const ParentLayerPoint& aPoint) const {
return layers::IsZero(aPoint / zoom);
}
bool AsyncPanZoomController::IsZero(ParentLayerCoord aCoord) const {
RecursiveMutexAutoLock lock(mRecursiveMutex);
const auto zoom = Metrics().GetZoom();
if (zoom == CSSToParentLayerScale(0)) {
return true;
}
return FuzzyEqualsAdditive((aCoord / zoom).value, 0.0f,
COORDINATE_EPSILON.value);
}
bool AsyncPanZoomController::FuzzyGreater(ParentLayerCoord aCoord1,
ParentLayerCoord aCoord2) const {
RecursiveMutexAutoLock lock(mRecursiveMutex);
const auto zoom = Metrics().GetZoom();
if (zoom == CSSToParentLayerScale(0)) {
return false;
}
return (aCoord1 - aCoord2) / zoom > COORDINATE_EPSILON;
}
class MOZ_STACK_CLASS StateChangeNotificationBlocker final {
public:
explicit StateChangeNotificationBlocker(AsyncPanZoomController* aApzc)
@ -3640,10 +3666,10 @@ void AsyncPanZoomController::OverscrollBy(ParentLayerPoint& aOverscroll) {
// Do not go into overscroll in a direction in which we have no room to
// scroll to begin with.
ScrollDirections overscrollableDirections = GetOverscrollableDirections();
if (FuzzyEqualsAdditive(aOverscroll.x, 0.0f, COORDINATE_EPSILON)) {
if (IsZero(aOverscroll.x)) {
overscrollableDirections -= ScrollDirection::eHorizontal;
}
if (FuzzyEqualsAdditive(aOverscroll.y, 0.0f, COORDINATE_EPSILON)) {
if (IsZero(aOverscroll.y)) {
overscrollableDirections -= ScrollDirection::eVertical;
}

View file

@ -575,6 +575,9 @@ class AsyncPanZoomController {
SampleTime GetFrameTime() const;
bool IsZero(const ParentLayerPoint& aPoint) const;
bool IsZero(ParentLayerCoord aCoord) const;
bool FuzzyGreater(ParentLayerCoord aCoord1, ParentLayerCoord aCoord2) const;
private:
// Get whether the horizontal content of the honoured target of auto-dir

View file

@ -30,9 +30,10 @@ static mozilla::LazyLogModule sApzAxsLog("apz.axis");
namespace mozilla {
namespace layers {
bool FuzzyEqualsCoordinate(float aValue1, float aValue2) {
return FuzzyEqualsAdditive(aValue1, aValue2, COORDINATE_EPSILON) ||
FuzzyEqualsMultiplicative(aValue1, aValue2);
bool FuzzyEqualsCoordinate(CSSCoord aValue1, CSSCoord aValue2) {
return FuzzyEqualsAdditive(aValue1.value, aValue2.value,
COORDINATE_EPSILON.value) ||
FuzzyEqualsMultiplicative(aValue1.value, aValue2.value);
}
Axis::Axis(AsyncPanZoomController* aAsyncPanZoomController)
@ -150,7 +151,7 @@ void Axis::OverscrollBy(ParentLayerCoord aOverscroll) {
MOZ_ASSERT(CanScroll());
// We can get some spurious calls to OverscrollBy() with near-zero values
// due to rounding error. Ignore those (they might trip the asserts below.)
if (FuzzyEqualsAdditive(aOverscroll.value, 0.0f, COORDINATE_EPSILON)) {
if (mAsyncPanZoomController->IsZero(aOverscroll)) {
return;
}
EndOverscrollAnimation();
@ -255,11 +256,23 @@ bool Axis::IsOverscrollAnimationAlive() const {
bool Axis::IsOverscrolled() const { return mOverscroll != 0.f; }
bool Axis::IsScrolledToStart() const {
return FuzzyEqualsCoordinate(GetOrigin().value, GetPageStart().value);
const auto zoom = GetFrameMetrics().GetZoom();
if (zoom == CSSToParentLayerScale(0)) {
return true;
}
return FuzzyEqualsCoordinate(GetOrigin() / zoom, GetPageStart() / zoom);
}
bool Axis::IsScrolledToEnd() const {
return FuzzyEqualsCoordinate(GetCompositionEnd().value, GetPageEnd().value);
const auto zoom = GetFrameMetrics().GetZoom();
if (zoom == CSSToParentLayerScale(0)) {
return true;
}
return FuzzyEqualsCoordinate(GetCompositionEnd() / zoom, GetPageEnd() / zoom);
}
bool Axis::IsInInvalidOverscroll() const {
@ -320,7 +333,8 @@ void Axis::CancelGesture() {
}
bool Axis::CanScroll() const {
return GetPageLength() - GetCompositionLength() > COORDINATE_EPSILON;
return mAsyncPanZoomController->FuzzyGreater(GetPageLength(),
GetCompositionLength());
}
bool Axis::CanScroll(CSSCoord aDelta) const {
@ -664,14 +678,17 @@ SideBits AxisY::ScrollableDirectionsWithDynamicToolbar(
SideBits directions = ScrollableDirections();
if (HasDynamicToolbar()) {
ScreenCoord toolbarHeight = ViewAs<ScreenPixel>(
GetCompositionLength() - GetCompositionLengthWithoutDynamicToolbar(),
PixelCastJustification::ScreenIsParentLayerForRoot);
ParentLayerCoord toolbarHeight =
GetCompositionLength() - GetCompositionLengthWithoutDynamicToolbar();
if (fabs(aFixedLayerMargins.bottom) > COORDINATE_EPSILON) {
ParentLayerMargin fixedLayerMargins = ViewAs<ParentLayerPixel>(
aFixedLayerMargins, PixelCastJustification::ScreenIsParentLayerForRoot);
if (!mAsyncPanZoomController->IsZero(fixedLayerMargins.bottom)) {
directions |= SideBits::eTop;
}
if (toolbarHeight + aFixedLayerMargins.bottom > COORDINATE_EPSILON) {
if (mAsyncPanZoomController->FuzzyGreater(
aFixedLayerMargins.bottom + toolbarHeight, 0)) {
directions |= SideBits::eBottom;
}
}
@ -682,8 +699,9 @@ SideBits AxisY::ScrollableDirectionsWithDynamicToolbar(
bool AxisY::CanVerticalScrollWithDynamicToolbar() const {
return !HasDynamicToolbar()
? CanScroll()
: GetPageLength() - GetCompositionLengthWithoutDynamicToolbar() >
COORDINATE_EPSILON;
: mAsyncPanZoomController->FuzzyGreater(
GetPageLength(),
GetCompositionLengthWithoutDynamicToolbar());
}
OverscrollBehavior AxisY::GetOverscrollBehavior() const {

View file

@ -30,7 +30,7 @@ const float EPSILON = 0.0001f;
* due to floating-point operations (which can be larger than COORDINATE_EPISLON
* for sufficiently large coordinate values).
*/
bool FuzzyEqualsCoordinate(float aValue1, float aValue2);
bool FuzzyEqualsCoordinate(CSSCoord aValue1, CSSCoord aValue2);
struct FrameMetrics;
class AsyncPanZoomController;

View file

@ -148,9 +148,9 @@ class GenericFlingAnimation : public AsyncPanZoomAnimation,
// We may have reached the end of the scroll range along one axis but
// not the other. In such a case we only want to hand off the relevant
// component of the fling.
if (FuzzyEqualsAdditive(overscroll.x, 0.0f, COORDINATE_EPSILON)) {
if (mApzc.IsZero(overscroll.x)) {
velocity.x = 0;
} else if (FuzzyEqualsAdditive(overscroll.y, 0.0f, COORDINATE_EPSILON)) {
} else if (mApzc.IsZero(overscroll.y)) {
velocity.y = 0;
}

View file

@ -182,10 +182,10 @@ RefPtr<AsyncPanZoomController> OverscrollHandoffChain::FindFirstScrollable(
ScrollDirections allowedOverscrollDirections =
mChain[i]->GetOverscrollableDirections();
ParentLayerPoint delta = mChain[i]->GetDeltaForEvent(aInput);
if (FuzzyEqualsAdditive(delta.x, 0.0f, COORDINATE_EPSILON)) {
if (mChain[i]->IsZero(delta.x)) {
allowedOverscrollDirections -= ScrollDirection::eHorizontal;
}
if (FuzzyEqualsAdditive(delta.y, 0.0f, COORDINATE_EPSILON)) {
if (mChain[i]->IsZero(delta.y)) {
allowedOverscrollDirections -= ScrollDirection::eVertical;
}

View file

@ -79,7 +79,7 @@ void SampledAPZCState::RemoveFractionalAsyncDelta() {
// container layers can trigger the creation of a temporary surface during
// composition, because it produces a non-integer translation that doesn't
// play well with layer clips. So we detect the case where the delta is
// uselessly small (0.01 parentlayer pixels or less) and tweak the sampled
// uselessly small (0.02 parentlayer pixels or less) and tweak the sampled
// scroll offset to eliminate it. By doing this here at sample time rather
// than elsewhere in the pipeline we are least likely to break assumptions
// and invariants elsewhere in the code, since sampling effectively takes
@ -89,10 +89,11 @@ void SampledAPZCState::RemoveFractionalAsyncDelta() {
if (mLayoutViewport.TopLeft() == mVisualScrollOffset) {
return;
}
const ParentLayerCoord EPSILON = 0.02;
ParentLayerPoint paintedOffset = mLayoutViewport.TopLeft() * mZoom;
ParentLayerPoint asyncOffset = mVisualScrollOffset * mZoom;
if (FuzzyEqualsAdditive(paintedOffset.x, asyncOffset.x, COORDINATE_EPSILON) &&
FuzzyEqualsAdditive(paintedOffset.y, asyncOffset.y, COORDINATE_EPSILON)) {
if (FuzzyEqualsAdditive(paintedOffset.x, asyncOffset.x, EPSILON.value) &&
FuzzyEqualsAdditive(paintedOffset.y, asyncOffset.y, EPSILON.value)) {
mVisualScrollOffset = mLayoutViewport.TopLeft();
}
}

View file

@ -88,9 +88,9 @@ bool SmoothMsdScrollAnimation::DoSample(FrameMetrics& aFrameMetrics,
// We may have reached the end of the scroll range along one axis but
// not the other. In such a case we only want to hand off the relevant
// component of the fling.
if (FuzzyEqualsAdditive(overscroll.x, 0.0f, COORDINATE_EPSILON)) {
if (mApzc.IsZero(overscroll.x)) {
velocity.x = 0;
} else if (FuzzyEqualsAdditive(overscroll.y, 0.0f, COORDINATE_EPSILON)) {
} else if (mApzc.IsZero(overscroll.y)) {
velocity.y = 0;
}