Changeset 277587 in webkit
- Timestamp:
- May 17, 2021, 10:59:47 AM (5 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 5 edited
-
ChangeLog (modified) (1 diff)
-
Shared/WebWheelEventCoalescer.cpp (modified) (4 diffs)
-
Shared/WebWheelEventCoalescer.h (modified) (3 diffs)
-
UIProcess/WebPageProxy.cpp (modified) (2 diffs)
-
UIProcess/WebPageProxy.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r277584 r277587 1 2021-05-14 Simon Fraser <simon.fraser@apple.com> 2 3 Allow wheel events to be coalesced during scroll deceleration 4 https://bugs.webkit.org/show_bug.cgi?id=225834 5 <rdar://70402512> 6 7 Reviewed by Tim Horton. 8 9 When scrolling slows down towards the tail end of a momentum scroll, we can reduce our 10 commit frequency to save power, but we only want to do this on displays whose refresh rate 11 is higher than the default "update rendering" frequency. 12 13 We do this by leveraging the existing WebWheelEventCoalescer, which coalesces events 14 in the UI process. It tracks time since previous event, and coalesces when the 15 instantaneous velocity is less than 320 points per second (matching other frameworks 16 on the system). 17 18 WebWheelEventCoalescer needs to know when to enable coalescing, which it computes 19 on creation, and when the window is moved to a different screen with potentially 20 a different refresh rate. 21 22 * Shared/WebWheelEventCoalescer.cpp: 23 (WebKit::WebWheelEventCoalescer::isInMomentumPhase): 24 (WebKit::WebWheelEventCoalescer::shouldDispatchEvent): 25 * Shared/WebWheelEventCoalescer.h: 26 (WebKit::WebWheelEventCoalescer::shouldCoalesceEventsDuringDeceleration const): 27 (WebKit::WebWheelEventCoalescer::setShouldCoalesceEventsDuringDeceleration): 28 * UIProcess/WebPageProxy.cpp: 29 (WebKit::WebPageProxy::wheelEventCoalescer): 30 (WebKit::WebPageProxy::shouldCoalesceWheelEventsDuringDeceleration const): 31 (WebKit::WebPageProxy::windowScreenDidChange): 32 * UIProcess/WebPageProxy.h: 33 1 34 2021-05-17 Peng Liu <peng.liu6@apple.com> 2 35 -
trunk/Source/WebKit/Shared/WebWheelEventCoalescer.cpp
r268522 r277587 30 30 #include "NativeWebWheelEvent.h" 31 31 #include "WebEventConversion.h" 32 #include <WebCore/AnimationFrameRate.h> 32 33 #include <wtf/text/TextStream.h> 33 34 … … 87 88 } 88 89 90 bool WebWheelEventCoalescer::isMomentumPhaseEvent(const WebWheelEvent& event) 91 { 92 return event.phase() == WebWheelEvent::Phase::PhaseNone && event.momentumPhase() == WebWheelEvent::Phase::PhaseChanged; 93 } 94 89 95 bool WebWheelEventCoalescer::shouldDispatchEventNow(const WebWheelEvent& event) const 90 96 { … … 136 142 bool WebWheelEventCoalescer::shouldDispatchEvent(const NativeWebWheelEvent& event) 137 143 { 138 LOG_WITH_STREAM(WheelEvents, stream << "WebWheelEventCoalescer::shouldDispatchEvent " << event << " (" << m_wheelEventQueue.size() << " events in the queue, " << m_eventsBeingProcessed.size() << " event sequences being processed )");144 LOG_WITH_STREAM(WheelEvents, stream << "WebWheelEventCoalescer::shouldDispatchEvent " << event << " (" << m_wheelEventQueue.size() << " events in the queue, " << m_eventsBeingProcessed.size() << " event sequences being processed, coalesce during decleration " << m_shouldCoalesceEventsDuringDeceleration << ")"); 139 145 140 146 m_wheelEventQueue.append(event); 147 148 auto lastEventInterval = event.timestamp() - m_lastEventTime; 149 m_lastEventTime = event.timestamp(); 150 151 if (isMomentumPhaseEvent(event) && shouldCoalesceEventsDuringDeceleration() && lastEventInterval) { 152 constexpr double momentumVelocityEventFrequencyReductionThreashold = 320.0; // Points per second. 153 auto instantaneousVelocity = std::max(std::abs(event.delta().width()), std::abs(event.delta().height())) / lastEventInterval.seconds(); 154 155 constexpr auto maxCoalescingInterval = WebCore::FullSpeedAnimationInterval; 156 auto lastDispatchedEventInterval = event.timestamp() - m_lastDispatchedEventTime; 157 158 if (instantaneousVelocity < momentumVelocityEventFrequencyReductionThreashold && lastDispatchedEventInterval < maxCoalescingInterval) { 159 LOG_WITH_STREAM(WheelEvents, stream << " coalesced event that came within " << lastDispatchedEventInterval.milliseconds() << " of previous dispatch"); 160 return false; 161 } 162 } 141 163 142 164 if (!m_eventsBeingProcessed.isEmpty()) { … … 149 171 } 150 172 173 m_lastDispatchedEventTime = event.timestamp(); 151 174 return true; 152 175 } -
trunk/Source/WebKit/Shared/WebWheelEventCoalescer.h
r268287 r277587 29 29 #include <wtf/Deque.h> 30 30 #include <wtf/FastMalloc.h> 31 #include <wtf/WallTime.h> 31 32 32 33 namespace WebKit { … … 38 39 bool shouldDispatchEvent(const NativeWebWheelEvent&); 39 40 Optional<WebWheelEvent> nextEventToDispatch(); 40 41 41 42 NativeWebWheelEvent takeOldestEventBeingProcessed(); 42 43 43 44 bool hasEventsBeingProcessed() const { return !m_eventsBeingProcessed.isEmpty(); } 44 45 46 bool shouldCoalesceEventsDuringDeceleration() const { return m_shouldCoalesceEventsDuringDeceleration; } 47 void setShouldCoalesceEventsDuringDeceleration(bool shouldCoalsce) { m_shouldCoalesceEventsDuringDeceleration = shouldCoalsce; } 48 45 49 void clear(); 46 50 … … 51 55 static WebWheelEvent coalesce(const WebWheelEvent&, const WebWheelEvent&); 52 56 57 static bool isMomentumPhaseEvent(const WebWheelEvent&); 58 53 59 bool shouldDispatchEventNow(const WebWheelEvent&) const; 54 60 55 61 Deque<NativeWebWheelEvent, 2> m_wheelEventQueue; 56 62 Deque<std::unique_ptr<CoalescedEventSequence>> m_eventsBeingProcessed; 63 64 WallTime m_lastEventTime; 65 WallTime m_lastDispatchedEventTime; 66 bool m_shouldCoalesceEventsDuringDeceleration { false }; 57 67 }; 58 68 -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r277573 r277587 2852 2852 WebWheelEventCoalescer& WebPageProxy::wheelEventCoalescer() 2853 2853 { 2854 if (!m_wheelEventCoalescer) 2854 if (!m_wheelEventCoalescer) { 2855 2855 m_wheelEventCoalescer = makeUnique<WebWheelEventCoalescer>(); 2856 m_wheelEventCoalescer->setShouldCoalesceEventsDuringDeceleration(shouldCoalesceWheelEventsDuringDeceleration()); 2857 } 2856 2858 2857 2859 return *m_wheelEventCoalescer; 2860 } 2861 2862 bool WebPageProxy::shouldCoalesceWheelEventsDuringDeceleration() const 2863 { 2864 #if HAVE(CVDISPLAYLINK) 2865 if (!m_displayID) 2866 return false; 2867 2868 auto framesPerSecond = m_process->processPool().nominalFramesPerSecondForDisplay(*m_displayID); 2869 return framesPerSecond > WebCore::FullSpeedFramesPerSecond; 2870 #else 2871 return false; 2872 #endif 2858 2873 } 2859 2874 … … 3871 3886 { 3872 3887 m_displayID = displayID; 3888 3889 if (m_wheelEventCoalescer) 3890 m_wheelEventCoalescer->setShouldCoalesceEventsDuringDeceleration(shouldCoalesceWheelEventsDuringDeceleration()); 3873 3891 3874 3892 if (!hasRunningProcess()) -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r277505 r277587 2336 2336 2337 2337 WebWheelEventCoalescer& wheelEventCoalescer(); 2338 bool shouldCoalesceWheelEventsDuringDeceleration() const; 2338 2339 2339 2340 #if HAVE(CVDISPLAYLINK)
Note:
See TracChangeset
for help on using the changeset viewer.