Title: [285883] trunk/Source/WebCore
Revision
285883
Author
[email protected]
Date
2021-11-16 14:05:01 -0800 (Tue, 16 Nov 2021)

Log Message

Use IOHIDEvent timestamps for momentum velocity computation
https://bugs.webkit.org/show_bug.cgi?id=233168

Reviewed by Tim Horton.

NSEvent timetamps can have some jitter on some devices (rdar://85309639) so drop
down to IOHIDEvent timestamps when computing the initial velocity for a momentum
scroll animation, for improved accuracy.

* page/mac/WheelEventDeltaFilterMac.h:
* page/mac/WheelEventDeltaFilterMac.mm:
(WebCore::WheelEventDeltaFilterMac::updateFromEvent):
(WebCore::WheelEventDeltaFilterMac::reset):
* page/scrolling/ThreadedScrollingTree.cpp:
(WebCore::ThreadedScrollingTree::willStartRenderingUpdate):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (285882 => 285883)


--- trunk/Source/WebCore/ChangeLog	2021-11-16 21:53:42 UTC (rev 285882)
+++ trunk/Source/WebCore/ChangeLog	2021-11-16 22:05:01 UTC (rev 285883)
@@ -1,3 +1,21 @@
+2021-11-16  Simon Fraser  <[email protected]>
+
+        Use IOHIDEvent timestamps for momentum velocity computation
+        https://bugs.webkit.org/show_bug.cgi?id=233168
+
+        Reviewed by Tim Horton.
+
+        NSEvent timetamps can have some jitter on some devices (rdar://85309639) so drop
+        down to IOHIDEvent timestamps when computing the initial velocity for a momentum
+        scroll animation, for improved accuracy.
+
+        * page/mac/WheelEventDeltaFilterMac.h:
+        * page/mac/WheelEventDeltaFilterMac.mm:
+        (WebCore::WheelEventDeltaFilterMac::updateFromEvent):
+        (WebCore::WheelEventDeltaFilterMac::reset):
+        * page/scrolling/ThreadedScrollingTree.cpp:
+        (WebCore::ThreadedScrollingTree::willStartRenderingUpdate):
+
 2021-11-16  Andres Gonzalez  <[email protected]>
 
         Fix for accessibility/mac/replace-text-with-range-on-webarea-element.html in isolated tree mode.

Modified: trunk/Source/WebCore/page/mac/WheelEventDeltaFilterMac.h (285882 => 285883)


--- trunk/Source/WebCore/page/mac/WheelEventDeltaFilterMac.h	2021-11-16 21:53:42 UTC (rev 285882)
+++ trunk/Source/WebCore/page/mac/WheelEventDeltaFilterMac.h	2021-11-16 22:05:01 UTC (rev 285883)
@@ -47,6 +47,7 @@
 
     RetainPtr<_NSScrollingPredominantAxisFilter> m_predominantAxisFilter;
     WallTime m_initialWallTime;
+    WallTime m_lastIOHIDEventTimestamp;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/mac/WheelEventDeltaFilterMac.mm (285882 => 285883)


--- trunk/Source/WebCore/page/mac/WheelEventDeltaFilterMac.mm	2021-11-16 21:53:42 UTC (rev 285882)
+++ trunk/Source/WebCore/page/mac/WheelEventDeltaFilterMac.mm	2021-11-16 22:05:01 UTC (rev 285883)
@@ -29,6 +29,7 @@
 #import "WheelEventDeltaFilterMac.h"
 
 #import "FloatPoint.h"
+#import "Logging.h"
 #import "PlatformWheelEvent.h"
 #import <pal/spi/mac/NSScrollingInputFilterSPI.h>
 
@@ -43,8 +44,10 @@
 
 void WheelEventDeltaFilterMac::updateFromEvent(const PlatformWheelEvent& event)
 {
-    if (event.momentumPhase() != PlatformWheelEventPhase::None)
+    if (event.momentumPhase() != PlatformWheelEventPhase::None) {
+        m_lastIOHIDEventTimestamp = event.ioHIDEventTimestamp();
         return;
+    }
 
     // The absolute value of timestamp doesn't matter; the filter looks at deltas from the previous event.
     auto timestamp = event.timestamp() - m_initialWallTime;
@@ -51,25 +54,42 @@
 
     switch (event.phase()) {
     case PlatformWheelEventPhase::None:
+    case PlatformWheelEventPhase::Ended:
         break;
 
     case PlatformWheelEventPhase::Began:
+        reset();
+        FALLTHROUGH;
     case PlatformWheelEventPhase::Changed: {
         NSPoint filteredDeltaResult;
         NSPoint filteredVelocityResult;
 
         [m_predominantAxisFilter filterInputDelta:toFloatPoint(event.delta()) timestamp:timestamp.seconds() outputDelta:&filteredDeltaResult velocity:&filteredVelocityResult];
-        m_currentFilteredVelocity = toFloatSize(filteredVelocityResult);
+        auto axisFilteredVelocity = toFloatSize(filteredVelocityResult);
         m_currentFilteredDelta = toFloatSize(filteredDeltaResult);
+
+        // Use a 1ms minimum to avoid divide by zero. The usual cadence of these events matches screen refresh rate.
+        auto deltaFromLastEvent = std::max(event.ioHIDEventTimestamp() - m_lastIOHIDEventTimestamp, 1_ms);
+        m_currentFilteredVelocity = event.delta() / deltaFromLastEvent.seconds();
+
+        // Apply the axis-locking that m_predominantAxisFilter does.
+        if (!axisFilteredVelocity.width())
+            m_currentFilteredVelocity.setWidth(0);
+        if (!axisFilteredVelocity.height())
+            m_currentFilteredVelocity.setHeight(0);
+
+        LOG(ScrollAnimations, "WheelEventDeltaFilterMac::updateFromEvent: _NSScrollingPredominantAxisFilter velocity %.2f, %2f, IOHIDEvent velocity %.2f,%.2f",
+            axisFilteredVelocity.width(), axisFilteredVelocity.height(), m_currentFilteredVelocity.width(), m_currentFilteredVelocity.height());
         break;
     }
     case PlatformWheelEventPhase::MayBegin:
     case PlatformWheelEventPhase::Cancelled:
     case PlatformWheelEventPhase::Stationary:
-    case PlatformWheelEventPhase::Ended:
         reset();
         break;
     }
+
+    m_lastIOHIDEventTimestamp = event.ioHIDEventTimestamp();
 }
 
 void WheelEventDeltaFilterMac::reset()
@@ -77,6 +97,7 @@
     [m_predominantAxisFilter reset];
     m_currentFilteredVelocity = { };
     m_currentFilteredDelta = { };
+    m_lastIOHIDEventTimestamp = { };
 }
 
 }

Modified: trunk/Source/WebCore/page/scrolling/ThreadedScrollingTree.cpp (285882 => 285883)


--- trunk/Source/WebCore/page/scrolling/ThreadedScrollingTree.cpp	2021-11-16 21:53:42 UTC (rev 285882)
+++ trunk/Source/WebCore/page/scrolling/ThreadedScrollingTree.cpp	2021-11-16 22:05:01 UTC (rev 285883)
@@ -337,8 +337,6 @@
 {
     ASSERT(isMainThread());
 
-    LOG_WITH_STREAM(ScrollAnimations, stream << "ThreadedScrollingTree::willStartRenderingUpdate - scrollingThreadIsActive " << scrollingThreadIsActive());
-
     if (!scrollingThreadIsActive())
         return;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to