Title: [285205] trunk/Source/WebCore
Revision
285205
Author
[email protected]
Date
2021-11-03 07:37:04 -0700 (Wed, 03 Nov 2021)

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (285204 => 285205)


--- trunk/Source/WebCore/ChangeLog	2021-11-03 13:37:55 UTC (rev 285204)
+++ trunk/Source/WebCore/ChangeLog	2021-11-03 14:37:04 UTC (rev 285205)
@@ -1,3 +1,39 @@
+2021-11-03  Chris Lord  <[email protected]>
+
+        [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:
+
 2021-11-03  Zalan Bujtas  <[email protected]>
 
         [LFC][IFC] Display box builder should take visual order into account when computing horizontal positions

Modified: trunk/Source/WebCore/dom/Document.cpp (285204 => 285205)


--- trunk/Source/WebCore/dom/Document.cpp	2021-11-03 13:37:55 UTC (rev 285204)
+++ trunk/Source/WebCore/dom/Document.cpp	2021-11-03 14:37:04 UTC (rev 285205)
@@ -211,6 +211,7 @@
 #include "ScriptSourceCode.h"
 #include "ScriptState.h"
 #include "ScriptedAnimationController.h"
+#include "ScrollAnimator.h"
 #include "ScrollbarTheme.h"
 #include "ScrollingCoordinator.h"
 #include "SecurityOrigin.h"
@@ -4347,9 +4348,35 @@
     m_needsVisualViewportScrollEvent = true;
 }
 
+static bool serviceScrollAnimationForScrollableArea(ScrollableArea* scrollableArea, MonotonicTime time)
+{
+    if (!scrollableArea)
+        return false;
+
+    if (auto* animator = scrollableArea->existingScrollAnimator())
+        return animator->serviceScrollAnimation(time) == ScrollAnimationStatus::Animating;
+
+    return false;
+}
+
 // https://drafts.csswg.org/cssom-view/#run-the-scroll-steps
 void Document::runScrollSteps()
 {
+    // Service user scroll animations before scroll event dispatch.
+    RefPtr<FrameView> frameView = view();
+    if (frameView) {
+        MonotonicTime now = MonotonicTime::now();
+        bool scrollAnimationsInProgress = serviceScrollAnimationForScrollableArea(frameView.get(), now);
+        if (auto* scrollableAreas = frameView->scrollableAreas()) {
+            for (auto* scrollableArea : *scrollableAreas) {
+                if (serviceScrollAnimationForScrollableArea(scrollableArea, now))
+                    scrollAnimationsInProgress = true;
+            }
+        }
+        if (scrollAnimationsInProgress)
+            page()->scheduleRenderingUpdate({ RenderingUpdateStep::Scroll });
+    }
+
     // FIXME: The order of dispatching is not specified: https://github.com/WICG/visual-viewport/issues/66.
     if (m_pendingScrollEventTargetList && !m_pendingScrollEventTargetList->targets.isEmpty()) {
         LOG_WITH_STREAM(Events, stream << "Document " << this << " sending scroll events to pending scroll event targets");

Modified: trunk/Source/WebCore/page/FrameView.cpp (285204 => 285205)


--- trunk/Source/WebCore/page/FrameView.cpp	2021-11-03 13:37:55 UTC (rev 285204)
+++ trunk/Source/WebCore/page/FrameView.cpp	2021-11-03 14:37:04 UTC (rev 285205)
@@ -5700,6 +5700,12 @@
     return frame().frameScaleFactor();
 }
 
+void FrameView::didStartScrollAnimation()
+{
+    if (auto* page = frame().page())
+        page->scheduleRenderingUpdate({ RenderingUpdateStep::Scroll });
+}
+
 void FrameView::updateScrollbarSteps()
 {
     auto* documentElement = frame().document() ? frame().document()->documentElement() : nullptr;

Modified: trunk/Source/WebCore/page/FrameView.h (285204 => 285205)


--- trunk/Source/WebCore/page/FrameView.h	2021-11-03 13:37:55 UTC (rev 285204)
+++ trunk/Source/WebCore/page/FrameView.h	2021-11-03 14:37:04 UTC (rev 285205)
@@ -876,6 +876,7 @@
 
     // ScrollableArea.
     float pageScaleFactor() const override;
+    void didStartScrollAnimation() final;
 
     static MonotonicTime sCurrentPaintTimeStamp; // used for detecting decoded resource thrash in the cache
 

Modified: trunk/Source/WebCore/platform/ScrollAnimator.cpp (285204 => 285205)


--- trunk/Source/WebCore/platform/ScrollAnimator.cpp	2021-11-03 13:37:55 UTC (rev 285204)
+++ trunk/Source/WebCore/platform/ScrollAnimator.cpp	2021-11-03 14:37:04 UTC (rev 285205)
@@ -54,7 +54,6 @@
 ScrollAnimator::ScrollAnimator(ScrollableArea& scrollableArea)
     : m_scrollableArea(scrollableArea)
     , m_scrollController(*this)
-    , m_scrollControllerAnimationTimer(*this, &ScrollAnimator::scrollControllerAnimationTimerFired)
     , m_keyboardScrollingAnimator(makeUnique<KeyboardScrollingAnimator>(*this, m_scrollController))
 {
 }
@@ -384,22 +383,17 @@
 
 void ScrollAnimator::startAnimationCallback(ScrollingEffectsController&)
 {
-    if (m_scrollControllerAnimationTimer.isActive())
-        return;
-
-    m_scrollControllerAnimationTimer.startRepeating(1_s / 60.);
+    if (!m_scrollAnimationScheduled) {
+        m_scrollAnimationScheduled = true;
+        m_scrollableArea.didStartScrollAnimation();
+    }
 }
 
 void ScrollAnimator::stopAnimationCallback(ScrollingEffectsController&)
 {
-    m_scrollControllerAnimationTimer.stop();
+    m_scrollAnimationScheduled = false;
 }
 
-void ScrollAnimator::scrollControllerAnimationTimerFired()
-{
-    m_scrollController.animationCallback(MonotonicTime::now());
-}
-
 #if PLATFORM(MAC)
 void ScrollAnimator::deferWheelEventTestCompletionForReason(WheelEventTestMonitor::ScrollableAreaIdentifier identifier, WheelEventTestMonitor::DeferReason reason) const
 {
@@ -465,4 +459,11 @@
     return m_scrollController.adjustedScrollDestination(axis, newOffset, velocityInScrollAxis, originalOffset);
 }
 
+ScrollAnimationStatus ScrollAnimator::serviceScrollAnimation(MonotonicTime time)
+{
+    if (m_scrollAnimationScheduled)
+        m_scrollController.animationCallback(time);
+    return m_scrollAnimationScheduled ? ScrollAnimationStatus::Animating : ScrollAnimationStatus::NotAnimating;
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/ScrollAnimator.h (285204 => 285205)


--- trunk/Source/WebCore/platform/ScrollAnimator.h	2021-11-03 13:37:55 UTC (rev 285204)
+++ trunk/Source/WebCore/platform/ScrollAnimator.h	2021-11-03 14:37:04 UTC (rev 285205)
@@ -123,6 +123,8 @@
     const LayoutScrollSnapOffsetsInfo* snapOffsetsInfo() const;
     void resnapAfterLayout();
 
+    ScrollAnimationStatus serviceScrollAnimation(MonotonicTime);
+
 protected:
     virtual bool platformAllowsScrollAnimation() const { return true; }
 
@@ -129,7 +131,6 @@
 private:
     void notifyPositionChanged(const FloatSize& delta);
 
-    void scrollControllerAnimationTimerFired();
     void updateActiveScrollSnapIndexForOffset();
 
     FloatPoint offsetFromPosition(const FloatPoint& position) const;
@@ -176,10 +177,12 @@
     ScrollableArea& m_scrollableArea;
     RefPtr<WheelEventTestMonitor> m_wheelEventTestMonitor;
     ScrollingEffectsController m_scrollController;
-    Timer m_scrollControllerAnimationTimer;
     FloatPoint m_currentPosition;
 
     std::unique_ptr<KeyboardScrollingAnimator> m_keyboardScrollingAnimator;
+
+private:
+    bool m_scrollAnimationScheduled { false };
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/ScrollableArea.h (285204 => 285205)


--- trunk/Source/WebCore/platform/ScrollableArea.h	2021-11-03 13:37:55 UTC (rev 285204)
+++ trunk/Source/WebCore/platform/ScrollableArea.h	2021-11-03 14:37:04 UTC (rev 285205)
@@ -353,6 +353,8 @@
         return 1.0f;
     }
 
+    virtual void didStartScrollAnimation() { }
+
 protected:
     WEBCORE_EXPORT ScrollableArea();
     WEBCORE_EXPORT virtual ~ScrollableArea();
@@ -413,6 +415,7 @@
     bool m_inLiveResize { false };
     bool m_scrollOriginChanged { false };
     bool m_scrollShouldClearLatchedState { false };
+    bool m_hasActiveScrollAnimation { false };
 };
 
 WTF::TextStream& operator<<(WTF::TextStream&, const ScrollableArea&);

Modified: trunk/Source/WebCore/platform/ScrollingEffectsController.cpp (285204 => 285205)


--- trunk/Source/WebCore/platform/ScrollingEffectsController.cpp	2021-11-03 13:37:55 UTC (rev 285204)
+++ trunk/Source/WebCore/platform/ScrollingEffectsController.cpp	2021-11-03 14:37:04 UTC (rev 285205)
@@ -120,12 +120,11 @@
 
 bool ScrollingEffectsController::retargetAnimatedScrollBy(FloatSize offset)
 {
-    if (!is<ScrollAnimationSmooth>(m_currentAnimation.get()))
+    if (!is<ScrollAnimationSmooth>(m_currentAnimation.get()) || !m_currentAnimation->isActive())
         return false;
 
     LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " retargetAnimatedScrollBy " << offset);
 
-    ASSERT(m_currentAnimation->isActive());
     if (auto destinationOffset = m_currentAnimation->destinationOffset())
         return m_currentAnimation->retargetActiveAnimation(*destinationOffset + offset);
 

Modified: trunk/Source/WebCore/rendering/RenderLayerScrollableArea.cpp (285204 => 285205)


--- trunk/Source/WebCore/rendering/RenderLayerScrollableArea.cpp	2021-11-03 13:37:55 UTC (rev 285204)
+++ trunk/Source/WebCore/rendering/RenderLayerScrollableArea.cpp	2021-11-03 14:37:04 UTC (rev 285205)
@@ -1840,4 +1840,9 @@
     return m_layer.debugDescription();
 }
 
+void RenderLayerScrollableArea::didStartScrollAnimation()
+{
+    m_layer.page().scheduleRenderingUpdate({ RenderingUpdateStep::Scroll });
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/rendering/RenderLayerScrollableArea.h (285204 => 285205)


--- trunk/Source/WebCore/rendering/RenderLayerScrollableArea.h	2021-11-03 13:37:55 UTC (rev 285204)
+++ trunk/Source/WebCore/rendering/RenderLayerScrollableArea.h	2021-11-03 14:37:04 UTC (rev 285205)
@@ -194,6 +194,7 @@
     void logMockScrollAnimatorMessage(const String&) const final;
 
     String debugDescription() const final;
+    void didStartScrollAnimation() final;
 
     IntSize visibleSize() const final;
     IntSize contentsSize() const final;

Modified: trunk/Source/WebCore/rendering/RenderListBox.cpp (285204 => 285205)


--- trunk/Source/WebCore/rendering/RenderListBox.cpp	2021-11-03 13:37:55 UTC (rev 285204)
+++ trunk/Source/WebCore/rendering/RenderListBox.cpp	2021-11-03 14:37:04 UTC (rev 285205)
@@ -908,6 +908,11 @@
     return RenderObject::debugDescription();
 }
 
+void RenderListBox::didStartScrollAnimation()
+{
+    page().scheduleRenderingUpdate({ RenderingUpdateStep::Scroll });
+}
+
 Ref<Scrollbar> RenderListBox::createScrollbar()
 {
     RefPtr<Scrollbar> widget;

Modified: trunk/Source/WebCore/rendering/RenderListBox.h (285204 => 285205)


--- trunk/Source/WebCore/rendering/RenderListBox.h	2021-11-03 13:37:55 UTC (rev 285204)
+++ trunk/Source/WebCore/rendering/RenderListBox.h	2021-11-03 14:37:04 UTC (rev 285205)
@@ -141,6 +141,7 @@
     bool mockScrollAnimatorEnabled() const final;
     void logMockScrollAnimatorMessage(const String&) const final;
     String debugDescription() const final;
+    void didStartScrollAnimation() final;
 
     // NOTE: This should only be called by the overridden setScrollOffset from ScrollableArea.
     void scrollTo(int newOffset);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to