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

Changeset 285943 in webkit


Ignore:
Timestamp:
Nov 17, 2021, 11:14:41 AM (5 years ago)
Author:
Alan Coon
Message:

Cherry-pick r285883. rdar://problem/85512520

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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@285883 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Location:
branches/safari-613.1.9.0-branch/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-613.1.9.0-branch/Source/WebCore/ChangeLog

    r285942 r285943  
     12021-11-17  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r285883. rdar://problem/85512520
     4
     5    Use IOHIDEvent timestamps for momentum velocity computation
     6    https://bugs.webkit.org/show_bug.cgi?id=233168
     7   
     8    Reviewed by Tim Horton.
     9   
     10    NSEvent timetamps can have some jitter on some devices (rdar://85309639) so drop
     11    down to IOHIDEvent timestamps when computing the initial velocity for a momentum
     12    scroll animation, for improved accuracy.
     13   
     14    * page/mac/WheelEventDeltaFilterMac.h:
     15    * page/mac/WheelEventDeltaFilterMac.mm:
     16    (WebCore::WheelEventDeltaFilterMac::updateFromEvent):
     17    (WebCore::WheelEventDeltaFilterMac::reset):
     18    * page/scrolling/ThreadedScrollingTree.cpp:
     19    (WebCore::ThreadedScrollingTree::willStartRenderingUpdate):
     20   
     21   
     22    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@285883 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     23
     24    2021-11-16  Simon Fraser  <simon.fraser@apple.com>
     25
     26            Use IOHIDEvent timestamps for momentum velocity computation
     27            https://bugs.webkit.org/show_bug.cgi?id=233168
     28
     29            Reviewed by Tim Horton.
     30
     31            NSEvent timetamps can have some jitter on some devices (rdar://85309639) so drop
     32            down to IOHIDEvent timestamps when computing the initial velocity for a momentum
     33            scroll animation, for improved accuracy.
     34
     35            * page/mac/WheelEventDeltaFilterMac.h:
     36            * page/mac/WheelEventDeltaFilterMac.mm:
     37            (WebCore::WheelEventDeltaFilterMac::updateFromEvent):
     38            (WebCore::WheelEventDeltaFilterMac::reset):
     39            * page/scrolling/ThreadedScrollingTree.cpp:
     40            (WebCore::ThreadedScrollingTree::willStartRenderingUpdate):
     41
    1422021-11-17  Alan Coon  <alancoon@apple.com>
    243
  • branches/safari-613.1.9.0-branch/Source/WebCore/page/mac/WheelEventDeltaFilterMac.h

    r285367 r285943  
    4848    RetainPtr<_NSScrollingPredominantAxisFilter> m_predominantAxisFilter;
    4949    WallTime m_initialWallTime;
     50    WallTime m_lastIOHIDEventTimestamp;
    5051};
    5152
  • branches/safari-613.1.9.0-branch/Source/WebCore/page/mac/WheelEventDeltaFilterMac.mm

    r285367 r285943  
    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
  • branches/safari-613.1.9.0-branch/Source/WebCore/page/scrolling/ThreadedScrollingTree.cpp

    r285669 r285943  
    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.