⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 285883 in webkit


Ignore:
Timestamp:
Nov 16, 2021, 2:05:01 PM (5 years ago)
Author:
Simon Fraser
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):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r285872 r285883  
     12021-11-16  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Use IOHIDEvent timestamps for momentum velocity computation
     4        https://bugs.webkit.org/show_bug.cgi?id=233168
     5
     6        Reviewed by Tim Horton.
     7
     8        NSEvent timetamps can have some jitter on some devices (rdar://85309639) so drop
     9        down to IOHIDEvent timestamps when computing the initial velocity for a momentum
     10        scroll animation, for improved accuracy.
     11
     12        * page/mac/WheelEventDeltaFilterMac.h:
     13        * page/mac/WheelEventDeltaFilterMac.mm:
     14        (WebCore::WheelEventDeltaFilterMac::updateFromEvent):
     15        (WebCore::WheelEventDeltaFilterMac::reset):
     16        * page/scrolling/ThreadedScrollingTree.cpp:
     17        (WebCore::ThreadedScrollingTree::willStartRenderingUpdate):
     18
    1192021-11-16  Andres Gonzalez  <andresg_22@apple.com>
    220
  • trunk/Source/WebCore/page/mac/WheelEventDeltaFilterMac.h

    r285367 r285883  
    4848    RetainPtr<_NSScrollingPredominantAxisFilter> m_predominantAxisFilter;
    4949    WallTime m_initialWallTime;
     50    WallTime m_lastIOHIDEventTimestamp;
    5051};
    5152
  • trunk/Source/WebCore/page/mac/WheelEventDeltaFilterMac.mm

    r285367 r285883  
    3030
    3131#import "FloatPoint.h"
     32#import "Logging.h"
    3233#import "PlatformWheelEvent.h"
    3334#import <pal/spi/mac/NSScrollingInputFilterSPI.h>
     
    4445void WheelEventDeltaFilterMac::updateFromEvent(const PlatformWheelEvent& event)
    4546{
    46     if (event.momentumPhase() != PlatformWheelEventPhase::None)
     47    if (event.momentumPhase() != PlatformWheelEventPhase::None) {
     48        m_lastIOHIDEventTimestamp = event.ioHIDEventTimestamp();
    4749        return;
     50    }
    4851
    4952    // The absolute value of timestamp doesn't matter; the filter looks at deltas from the previous event.
     
    5255    switch (event.phase()) {
    5356    case PlatformWheelEventPhase::None:
     57    case PlatformWheelEventPhase::Ended:
    5458        break;
    5559
    5660    case PlatformWheelEventPhase::Began:
     61        reset();
     62        FALLTHROUGH;
    5763    case PlatformWheelEventPhase::Changed: {
    5864        NSPoint filteredDeltaResult;
     
    6066
    6167        [m_predominantAxisFilter filterInputDelta:toFloatPoint(event.delta()) timestamp:timestamp.seconds() outputDelta:&filteredDeltaResult velocity:&filteredVelocityResult];
    62         m_currentFilteredVelocity = toFloatSize(filteredVelocityResult);
     68        auto axisFilteredVelocity = toFloatSize(filteredVelocityResult);
    6369        m_currentFilteredDelta = toFloatSize(filteredDeltaResult);
     70
     71        // Use a 1ms minimum to avoid divide by zero. The usual cadence of these events matches screen refresh rate.
     72        auto deltaFromLastEvent = std::max(event.ioHIDEventTimestamp() - m_lastIOHIDEventTimestamp, 1_ms);
     73        m_currentFilteredVelocity = event.delta() / deltaFromLastEvent.seconds();
     74
     75        // Apply the axis-locking that m_predominantAxisFilter does.
     76        if (!axisFilteredVelocity.width())
     77            m_currentFilteredVelocity.setWidth(0);
     78        if (!axisFilteredVelocity.height())
     79            m_currentFilteredVelocity.setHeight(0);
     80
     81        LOG(ScrollAnimations, "WheelEventDeltaFilterMac::updateFromEvent: _NSScrollingPredominantAxisFilter velocity %.2f, %2f, IOHIDEvent velocity %.2f,%.2f",
     82            axisFilteredVelocity.width(), axisFilteredVelocity.height(), m_currentFilteredVelocity.width(), m_currentFilteredVelocity.height());
    6483        break;
    6584    }
     
    6786    case PlatformWheelEventPhase::Cancelled:
    6887    case PlatformWheelEventPhase::Stationary:
    69     case PlatformWheelEventPhase::Ended:
    7088        reset();
    7189        break;
    7290    }
     91
     92    m_lastIOHIDEventTimestamp = event.ioHIDEventTimestamp();
    7393}
    7494
     
    7898    m_currentFilteredVelocity = { };
    7999    m_currentFilteredDelta = { };
     100    m_lastIOHIDEventTimestamp = { };
    80101}
    81102
  • trunk/Source/WebCore/page/scrolling/ThreadedScrollingTree.cpp

    r285858 r285883  
    338338    ASSERT(isMainThread());
    339339
    340     LOG_WITH_STREAM(ScrollAnimations, stream << "ThreadedScrollingTree::willStartRenderingUpdate - scrollingThreadIsActive " << scrollingThreadIsActive());
    341 
    342340    if (!scrollingThreadIsActive())
    343341        return;
Note: See TracChangeset for help on using the changeset viewer.