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

Changeset 285205 in webkit


Ignore:
Timestamp:
Nov 3, 2021, 7:37:04 AM (5 years ago)
Author:
Chris Lord
Message:

[GTK][WPE] Use the display refresh to drive scrolling animations (sync scroll)
​https://bugs.webkit.org/show_bug.cgi?id=232077

Reviewed by Simon Fraser.

Service sync scroll animations as part of the scroll phase in
Page::updateRendering, which is driven by the display refresh.

No new tests, covered by existing tests.

  • dom/Document.cpp:

(WebCore::serviceScrollAnimationForScrollableArea):
(WebCore::Document::runScrollSteps):

  • page/FrameView.cpp:

(WebCore::FrameView::didStartScrollAnimation):

  • page/FrameView.h:
  • platform/ScrollAnimator.cpp:

(WebCore::ScrollAnimator::ScrollAnimator):
(WebCore::ScrollAnimator::startAnimationCallback):
(WebCore::ScrollAnimator::stopAnimationCallback):
(WebCore::ScrollAnimator::serviceScrollAnimation):
(WebCore::ScrollAnimator::scrollControllerAnimationTimerFired): Deleted.

  • platform/ScrollAnimator.h:
  • platform/ScrollableArea.h:

(WebCore::ScrollableArea::didStartScrollAnimation):

  • platform/ScrollingEffectsController.cpp:

(WebCore::ScrollingEffectsController::retargetAnimatedScrollBy):

  • rendering/RenderLayerScrollableArea.cpp:

(WebCore::RenderLayerScrollableArea::didStartScrollAnimation):

  • rendering/RenderLayerScrollableArea.h:
  • rendering/RenderListBox.cpp:

(WebCore::RenderListBox::didStartScrollAnimation):

  • rendering/RenderListBox.h:
Location:
trunk/Source/WebCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r285204 r285205  
     12021-11-03  Chris Lord  <clord@igalia.com>
     2
     3        [GTK][WPE] Use the display refresh to drive scrolling animations (sync scroll)
     4        https://bugs.webkit.org/show_bug.cgi?id=232077
     5
     6        Reviewed by Simon Fraser.
     7
     8        Service sync scroll animations as part of the scroll phase in
     9        Page::updateRendering, which is driven by the display refresh.
     10
     11        No new tests, covered by existing tests.
     12
     13        * dom/Document.cpp:
     14        (WebCore::serviceScrollAnimationForScrollableArea):
     15        (WebCore::Document::runScrollSteps):
     16        * page/FrameView.cpp:
     17        (WebCore::FrameView::didStartScrollAnimation):
     18        * page/FrameView.h:
     19        * platform/ScrollAnimator.cpp:
     20        (WebCore::ScrollAnimator::ScrollAnimator):
     21        (WebCore::ScrollAnimator::startAnimationCallback):
     22        (WebCore::ScrollAnimator::stopAnimationCallback):
     23        (WebCore::ScrollAnimator::serviceScrollAnimation):
     24        (WebCore::ScrollAnimator::scrollControllerAnimationTimerFired): Deleted.
     25        * platform/ScrollAnimator.h:
     26        * platform/ScrollableArea.h:
     27        (WebCore::ScrollableArea::didStartScrollAnimation):
     28        * platform/ScrollingEffectsController.cpp:
     29        (WebCore::ScrollingEffectsController::retargetAnimatedScrollBy):
     30        * rendering/RenderLayerScrollableArea.cpp:
     31        (WebCore::RenderLayerScrollableArea::didStartScrollAnimation):
     32        * rendering/RenderLayerScrollableArea.h:
     33        * rendering/RenderListBox.cpp:
     34        (WebCore::RenderListBox::didStartScrollAnimation):
     35        * rendering/RenderListBox.h:
     36
    1372021-11-03  Zalan Bujtas  <zalan@apple.com>
    238
  • trunk/Source/WebCore/dom/Document.cpp

    r284857 r285205  
    212212#include "ScriptState.h"
    213213#include "ScriptedAnimationController.h"
     214#include "ScrollAnimator.h"
    214215#include "ScrollbarTheme.h"
    215216#include "ScrollingCoordinator.h"
    … …  
    43484349}
    43494350
     4351static bool serviceScrollAnimationForScrollableArea(ScrollableArea* scrollableArea, MonotonicTime time)
     4352{
     4353    if (!scrollableArea)
     4354        return false;
     4355
     4356    if (auto* animator = scrollableArea->existingScrollAnimator())
     4357        return animator->serviceScrollAnimation(time) == ScrollAnimationStatus::Animating;
     4358
     4359    return false;
     4360}
     4361
    43504362// https://drafts.csswg.org/cssom-view/#run-the-scroll-steps
    43514363void Document::runScrollSteps()
    43524364{
     4365    // Service user scroll animations before scroll event dispatch.
     4366    RefPtr<FrameView> frameView = view();
     4367    if (frameView) {
     4368        MonotonicTime now = MonotonicTime::now();
     4369        bool scrollAnimationsInProgress = serviceScrollAnimationForScrollableArea(frameView.get(), now);
     4370        if (auto* scrollableAreas = frameView->scrollableAreas()) {
     4371            for (auto* scrollableArea : *scrollableAreas) {
     4372                if (serviceScrollAnimationForScrollableArea(scrollableArea, now))
     4373                    scrollAnimationsInProgress = true;
     4374            }
     4375        }
     4376        if (scrollAnimationsInProgress)
     4377            page()->scheduleRenderingUpdate({ RenderingUpdateStep::Scroll });
     4378    }
     4379
    43534380    // FIXME: The order of dispatching is not specified: https://github.com/WICG/visual-viewport/issues/66.
    43544381    if (m_pendingScrollEventTargetList && !m_pendingScrollEventTargetList->targets.isEmpty()) {
  • trunk/Source/WebCore/page/FrameView.cpp

    r285120 r285205  
    57015701}
    57025702
     5703void FrameView::didStartScrollAnimation()
     5704{
     5705    if (auto* page = frame().page())
     5706        page->scheduleRenderingUpdate({ RenderingUpdateStep::Scroll });
     5707}
     5708
    57035709void FrameView::updateScrollbarSteps()
    57045710{
  • trunk/Source/WebCore/page/FrameView.h

    r284857 r285205  
    877877    // ScrollableArea.
    878878    float pageScaleFactor() const override;
     879    void didStartScrollAnimation() final;
    879880
    880881    static MonotonicTime sCurrentPaintTimeStamp; // used for detecting decoded resource thrash in the cache
  • trunk/Source/WebCore/platform/ScrollAnimator.cpp

    r284857 r285205  
    5555    : m_scrollableArea(scrollableArea)
    5656    , m_scrollController(*this)
    57     , m_scrollControllerAnimationTimer(*this, &ScrollAnimator::scrollControllerAnimationTimerFired)
    5857    , m_keyboardScrollingAnimator(makeUnique<KeyboardScrollingAnimator>(*this, m_scrollController))
    5958{
    … …  
    385384void ScrollAnimator::startAnimationCallback(ScrollingEffectsController&)
    386385{
    387     if (m_scrollControllerAnimationTimer.isActive())
    388         return;
    389 
    390     m_scrollControllerAnimationTimer.startRepeating(1_s / 60.);
     386    if (!m_scrollAnimationScheduled) {
     387        m_scrollAnimationScheduled = true;
     388        m_scrollableArea.didStartScrollAnimation();
     389    }
    391390}
    392391
    393392void ScrollAnimator::stopAnimationCallback(ScrollingEffectsController&)
    394393{
    395     m_scrollControllerAnimationTimer.stop();
    396 }
    397 
    398 void ScrollAnimator::scrollControllerAnimationTimerFired()
    399 {
    400     m_scrollController.animationCallback(MonotonicTime::now());
     394    m_scrollAnimationScheduled = false;
    401395}
    402396
    … …  
    466460}
    467461
     462ScrollAnimationStatus ScrollAnimator::serviceScrollAnimation(MonotonicTime time)
     463{
     464    if (m_scrollAnimationScheduled)
     465        m_scrollController.animationCallback(time);
     466    return m_scrollAnimationScheduled ? ScrollAnimationStatus::Animating : ScrollAnimationStatus::NotAnimating;
     467}
     468
    468469} // namespace WebCore
  • trunk/Source/WebCore/platform/ScrollAnimator.h

    r284575 r285205  
    124124    void resnapAfterLayout();
    125125
     126    ScrollAnimationStatus serviceScrollAnimation(MonotonicTime);
     127
    126128protected:
    127129    virtual bool platformAllowsScrollAnimation() const { return true; }
    … …  
    130132    void notifyPositionChanged(const FloatSize& delta);
    131133
    132     void scrollControllerAnimationTimerFired();
    133134    void updateActiveScrollSnapIndexForOffset();
    134135
    … …  
    177178    RefPtr<WheelEventTestMonitor> m_wheelEventTestMonitor;
    178179    ScrollingEffectsController m_scrollController;
    179     Timer m_scrollControllerAnimationTimer;
    180180    FloatPoint m_currentPosition;
    181181
    182182    std::unique_ptr<KeyboardScrollingAnimator> m_keyboardScrollingAnimator;
     183
     184private:
     185    bool m_scrollAnimationScheduled { false };
    183186};
    184187
  • trunk/Source/WebCore/platform/ScrollableArea.h

    r284575 r285205  
    354354    }
    355355
     356    virtual void didStartScrollAnimation() { }
     357
    356358protected:
    357359    WEBCORE_EXPORT ScrollableArea();
    … …  
    414416    bool m_scrollOriginChanged { false };
    415417    bool m_scrollShouldClearLatchedState { false };
     418    bool m_hasActiveScrollAnimation { false };
    416419};
    417420
  • trunk/Source/WebCore/platform/ScrollingEffectsController.cpp

    r284596 r285205  
    121121bool ScrollingEffectsController::retargetAnimatedScrollBy(FloatSize offset)
    122122{
    123     if (!is<ScrollAnimationSmooth>(m_currentAnimation.get()))
     123    if (!is<ScrollAnimationSmooth>(m_currentAnimation.get()) || !m_currentAnimation->isActive())
    124124        return false;
    125125
    126126    LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " retargetAnimatedScrollBy " << offset);
    127127
    128     ASSERT(m_currentAnimation->isActive());
    129128    if (auto destinationOffset = m_currentAnimation->destinationOffset())
    130129        return m_currentAnimation->retargetActiveAnimation(*destinationOffset + offset);
  • trunk/Source/WebCore/rendering/RenderLayerScrollableArea.cpp

    r284138 r285205  
    18411841}
    18421842
     1843void RenderLayerScrollableArea::didStartScrollAnimation()
     1844{
     1845    m_layer.page().scheduleRenderingUpdate({ RenderingUpdateStep::Scroll });
     1846}
     1847
    18431848} // namespace WebCore
  • trunk/Source/WebCore/rendering/RenderLayerScrollableArea.h

    r284138 r285205  
    195195
    196196    String debugDescription() const final;
     197    void didStartScrollAnimation() final;
    197198
    198199    IntSize visibleSize() const final;
  • trunk/Source/WebCore/rendering/RenderListBox.cpp

    r284857 r285205  
    909909}
    910910
     911void RenderListBox::didStartScrollAnimation()
     912{
     913    page().scheduleRenderingUpdate({ RenderingUpdateStep::Scroll });
     914}
     915
    911916Ref<Scrollbar> RenderListBox::createScrollbar()
    912917{
  • trunk/Source/WebCore/rendering/RenderListBox.h

    r284857 r285205  
    142142    void logMockScrollAnimatorMessage(const String&) const final;
    143143    String debugDescription() const final;
     144    void didStartScrollAnimation() final;
    144145
    145146    // NOTE: This should only be called by the overridden setScrollOffset from ScrollableArea.
Note: See TracChangeset for help on using the changeset viewer.