Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Unified Diff: third_party/WebKit/Source/platform/scroll/ScrollAnimator.cpp

Issue 1648293003: Fix smooth scroll jump when switching scroll handling between MT and CC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: skip irrelevant test on mac Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/scroll/ScrollAnimator.cpp
diff --git a/third_party/WebKit/Source/platform/scroll/ScrollAnimator.cpp b/third_party/WebKit/Source/platform/scroll/ScrollAnimator.cpp
index a5fadca7e4645961f020556f1a68400926daaeb3..bb9b623b747eff5072409b64535cb43d2820fa18 100644
--- a/third_party/WebKit/Source/platform/scroll/ScrollAnimator.cpp
+++ b/third_party/WebKit/Source/platform/scroll/ScrollAnimator.cpp
@@ -34,6 +34,7 @@
#include "platform/animation/CompositorAnimation.h"
#include "platform/graphics/CompositorFactory.h"
#include "platform/graphics/GraphicsLayer.h"
+#include "platform/scroll/MainThreadScrollingReason.h"
#include "platform/scroll/ScrollableArea.h"
#include "public/platform/Platform.h"
#include "public/platform/WebCompositorSupport.h"
@@ -42,6 +43,15 @@
namespace blink {
+namespace {
+
+WebLayer* toWebLayer(GraphicsLayer* layer)
+{
+ return layer ? layer->platformLayer() : nullptr;
+}
+
+} // namespace
+
PassOwnPtrWillBeRawPtr<ScrollAnimatorBase> ScrollAnimatorBase::create(ScrollableArea* scrollableArea)
{
if (scrollableArea && scrollableArea->scrollAnimatorEnabled())
@@ -190,10 +200,21 @@ void ScrollAnimator::tickAnimation(double monotonicTime)
notifyPositionChanged();
}
+void ScrollAnimator::postAnimationCleanupAndReset()
+{
+ // Remove the temporary main thread scrolling reason that was added while
+ // main thread had scheduled an animation.
+ removeMainThreadScrollingReason();
+
+ resetAnimationState();
+}
+
void ScrollAnimator::updateCompositorAnimations()
{
- if (m_runState == RunState::PostAnimationCleanup)
- return resetAnimationState();
+ if (m_runState == RunState::PostAnimationCleanup) {
+ postAnimationCleanupAndReset();
+ return;
+ }
if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor
&& m_runState != RunState::RunningOnCompositorButNeedsUpdate) {
@@ -209,7 +230,8 @@ void ScrollAnimator::updateCompositorAnimations()
m_compositorAnimationId = 0;
m_compositorAnimationGroupId = 0;
if (m_runState == RunState::WaitingToCancelOnCompositor) {
- return resetAnimationState();
+ postAnimationCleanupAndReset();
+ return;
}
}
@@ -263,10 +285,34 @@ void ScrollAnimator::updateCompositorAnimations()
}
}
+ bool runningOnMainThread = false;
if (!sentToCompositor) {
- if (registerAndScheduleAnimation())
+ runningOnMainThread = registerAndScheduleAnimation();
+ if (runningOnMainThread)
m_runState = RunState::RunningOnMainThread;
}
+
+ // Main thread should deal with the scroll animations it started.
+ if (sentToCompositor || runningOnMainThread)
+ addMainThreadScrollingReason();
+ else
+ removeMainThreadScrollingReason();
+ }
+}
+
+void ScrollAnimator::addMainThreadScrollingReason()
+{
+ if (WebLayer* scrollLayer = toWebLayer(scrollableArea()->layerForScrolling())) {
+ scrollLayer->addMainThreadScrollingReasons(
+ MainThreadScrollingReason::kAnimatingScrollOnMainThread);
+ }
+}
+
+void ScrollAnimator::removeMainThreadScrollingReason()
+{
+ if (WebLayer* scrollLayer = toWebLayer(scrollableArea()->layerForScrolling())) {
+ scrollLayer->clearMainThreadScrollingReasons(
+ MainThreadScrollingReason::kAnimatingScrollOnMainThread);
}
}
@@ -290,7 +336,8 @@ void ScrollAnimator::cancelAnimation()
void ScrollAnimator::layerForCompositedScrollingDidChange(
CompositorAnimationTimeline* timeline)
{
- reattachCompositorPlayerIfNeeded(timeline);
+ if (reattachCompositorPlayerIfNeeded(timeline) && m_animationCurve)
+ addMainThreadScrollingReason();
}
bool ScrollAnimator::registerAndScheduleAnimation()

Powered by Google App Engine
This is Rietveld 408576698