summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authoraelias@chromium.org <aelias@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-18 06:45:20 +0000
committeraelias@chromium.org <aelias@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-18 06:45:20 +0000
commit0fc818ec6e012243303de3e013037c8c0221c83f (patch)
tree968a152d95cd78ac42fa616fd34e2509144b267e /cc
parent32eee898d3d502b8b62e8f48f5eb9ac021e3489d (diff)
downloadchromium_src-0fc818ec6e012243303de3e013037c8c0221c83f.zip
chromium_src-0fc818ec6e012243303de3e013037c8c0221c83f.tar.gz
chromium_src-0fc818ec6e012243303de3e013037c8c0221c83f.tar.bz2
cc: Delay start of scrollbar animation setNeedsRedraw.
This adds a 300ms delay triggered at ScrollEnd in order to avoid beginning the setNeedsRedraw cycle until we really start fading the scrollbar, in order to improve performance during non-fling scrolls. Notes: - I switched to notifying the animator about ScrollBegin/ScrollEnd when the currently scrolling layer is attached/detached, and suppress fading until ScrollEnd. - The scrollUpdate path is still needed for when the scroll position changes due to e.g. Javascript, but it's a no-op during a scroll gesture. - I deleted the pinchGesture logic for simplicity, as there's no reason to treat pinches differently from scrolls. - I switches cc::Thread to use TimeDelta for its postDelayedTask since I ran into some bugs with the flooring to milliseconds. I updated the few other callers. NOTRY=true BUG=181417 Review URL: https://chromiumcodereview.appspot.com/12408028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188684 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r--cc/base/thread.h3
-rw-r--r--cc/base/thread_impl.cc5
-rw-r--r--cc/base/thread_impl.h4
-rw-r--r--cc/delay_based_time_source.cc2
-rw-r--r--cc/layer_impl.cc9
-rw-r--r--cc/layer_tree_host_impl.cc46
-rw-r--r--cc/layer_tree_host_impl.h5
-rw-r--r--cc/layer_tree_host_impl_unittest.cc1
-rw-r--r--cc/layer_tree_impl.cc18
-rw-r--r--cc/layer_tree_impl.h5
-rw-r--r--cc/resource_update_controller.cc2
-rw-r--r--cc/scrollbar_animation_controller.h10
-rw-r--r--cc/scrollbar_animation_controller_linear_fade.cc48
-rw-r--r--cc/scrollbar_animation_controller_linear_fade.h20
-rw-r--r--cc/scrollbar_animation_controller_linear_fade_unittest.cc49
-rw-r--r--cc/single_thread_proxy.h2
-rw-r--r--cc/test/fake_layer_tree_host_impl_client.h2
-rw-r--r--cc/test/layer_tree_test_common.cc2
-rw-r--r--cc/test/scheduler_test_common.cc6
-rw-r--r--cc/test/scheduler_test_common.h4
-rw-r--r--cc/thread_proxy.cc13
-rw-r--r--cc/thread_proxy.h3
22 files changed, 176 insertions, 83 deletions
diff --git a/cc/base/thread.h b/cc/base/thread.h
index 62fb89c..44be3b4 100644
--- a/cc/base/thread.h
+++ b/cc/base/thread.h
@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/callback.h"
+#include "base/time.h"
#include "cc/base/cc_export.h"
namespace cc {
@@ -21,7 +22,7 @@ class CC_EXPORT Thread {
virtual void PostTask(base::Closure cb) = 0;
// Executes the task after the specified delay.
- virtual void PostDelayedTask(base::Closure cb, long long delay_ms) = 0;
+ virtual void PostDelayedTask(base::Closure cb, base::TimeDelta delay) = 0;
virtual bool BelongsToCurrentThread() const = 0;
};
diff --git a/cc/base/thread_impl.cc b/cc/base/thread_impl.cc
index 0328e27..8e779cb 100644
--- a/cc/base/thread_impl.cc
+++ b/cc/base/thread_impl.cc
@@ -24,9 +24,8 @@ void ThreadImpl::PostTask(base::Closure cb) {
thread_->PostTask(FROM_HERE, cb);
}
-void ThreadImpl::PostDelayedTask(base::Closure cb, long long delay_ms) {
- thread_->PostDelayedTask(
- FROM_HERE, cb, base::TimeDelta::FromMilliseconds(delay_ms));
+void ThreadImpl::PostDelayedTask(base::Closure cb, base::TimeDelta delay) {
+ thread_->PostDelayedTask(FROM_HERE, cb, delay);
}
bool ThreadImpl::BelongsToCurrentThread() const {
diff --git a/cc/base/thread_impl.h b/cc/base/thread_impl.h
index da97d9a..064c8bf 100644
--- a/cc/base/thread_impl.h
+++ b/cc/base/thread_impl.h
@@ -25,9 +25,9 @@ class CC_EXPORT ThreadImpl : public Thread {
virtual ~ThreadImpl();
- // Thread implementation
virtual void PostTask(base::Closure cb) OVERRIDE;
- virtual void PostDelayedTask(base::Closure cb, long long delay_ms) OVERRIDE;
+ virtual void PostDelayedTask(base::Closure cb, base::TimeDelta delay)
+ OVERRIDE;
virtual bool BelongsToCurrentThread() const OVERRIDE;
private:
diff --git a/cc/delay_based_time_source.cc b/cc/delay_based_time_source.cc
index 902b749..db42105 100644
--- a/cc/delay_based_time_source.cc
+++ b/cc/delay_based_time_source.cc
@@ -225,7 +225,7 @@ void DelayBasedTimeSource::postNextTickTask(base::TimeTicks now)
m_nextParameters.interval.InMillisecondsF() * (1.0 + doubleTickThreshold));
m_thread->PostDelayedTask(base::Bind(&DelayBasedTimeSource::onTimerFired,
m_weakFactory.GetWeakPtr()),
- delay.InMilliseconds());
+ delay);
m_nextParameters.tickTarget = newTickTarget;
m_currentParameters = m_nextParameters;
diff --git a/cc/layer_impl.cc b/cc/layer_impl.cc
index d70b5b3..6f3e9d6 100644
--- a/cc/layer_impl.cc
+++ b/cc/layer_impl.cc
@@ -815,8 +815,9 @@ void LayerImpl::UpdateScrollbarPositions() {
return;
last_scroll_offset_ = current_offset;
- if (scrollbar_animation_controller_) {
- scrollbar_animation_controller_->didUpdateScrollOffset(
+ if (scrollbar_animation_controller_ &&
+ !scrollbar_animation_controller_->isScrollGestureInProgress()) {
+ scrollbar_animation_controller_->didProgrammaticallyUpdateScroll(
base::TimeTicks::Now());
}
@@ -906,8 +907,8 @@ void LayerImpl::SetScrollbarOpacity(float opacity) {
inline scoped_ptr<ScrollbarAnimationController>
CreateScrollbarAnimationControllerWithFade(LayerImpl* layer) {
- double fadeout_delay = 0.3;
- double fadeout_length = 0.3;
+ base::TimeDelta fadeout_delay = base::TimeDelta::FromMilliseconds(300);
+ base::TimeDelta fadeout_length = base::TimeDelta::FromMilliseconds(300);
return ScrollbarAnimationControllerLinearFade::create(
layer, fadeout_delay, fadeout_length)
.PassAs<ScrollbarAnimationController>();
diff --git a/cc/layer_tree_host_impl.cc b/cc/layer_tree_host_impl.cc
index 32290c4..3270702 100644
--- a/cc/layer_tree_host_impl.cc
+++ b/cc/layer_tree_host_impl.cc
@@ -1392,7 +1392,7 @@ InputHandlerClient::ScrollStatus LayerTreeHostImpl::ScrollBegin(
}
if (potentially_scrolling_layer_impl) {
- active_tree_->set_currently_scrolling_layer(
+ active_tree_->SetCurrentlyScrollingLayer(
potentially_scrolling_layer_impl);
should_bubble_scrolls_ = (type != NonBubblingGesture);
wheel_scrolling_ = (type == Wheel);
@@ -1534,7 +1534,7 @@ bool LayerTreeHostImpl::ScrollBy(gfx::Point viewport_point,
did_scroll = true;
did_lock_scrolling_layer_ = true;
if (!should_bubble_scrolls_) {
- active_tree_->set_currently_scrolling_layer(layer_impl);
+ active_tree_->SetCurrentlyScrollingLayer(layer_impl);
break;
}
@@ -1576,6 +1576,7 @@ void LayerTreeHostImpl::ScrollEnd() {
top_controls_manager_->ScrollEnd();
ClearCurrentlyScrollingLayer();
active_tree()->DidEndScroll();
+ StartScrollbarAnimation(base::TimeTicks::Now());
}
void LayerTreeHostImpl::PinchGestureBegin() {
@@ -1608,11 +1609,6 @@ void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta,
RootScrollLayer()->ScrollBy(move);
- if (RootScrollLayer()->scrollbar_animation_controller()) {
- RootScrollLayer()->scrollbar_animation_controller()->
- didPinchGestureUpdate(base::TimeTicks::Now());
- }
-
client_->SetNeedsCommitOnImplThread();
client_->SetNeedsRedrawOnImplThread();
client_->RenewTreePriority();
@@ -1620,13 +1616,6 @@ void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta,
void LayerTreeHostImpl::PinchGestureEnd() {
pinch_gesture_active_ = false;
-
- if (RootScrollLayer() &&
- RootScrollLayer()->scrollbar_animation_controller()) {
- RootScrollLayer()->scrollbar_animation_controller()->
- didPinchGestureEnd(base::TimeTicks::Now());
- }
-
client_->SetNeedsCommitOnImplThread();
}
@@ -1855,13 +1844,40 @@ void LayerTreeHostImpl::AnimateScrollbarsRecursive(LayerImpl* layer,
ScrollbarAnimationController* scrollbar_controller =
layer->scrollbar_animation_controller();
- if (scrollbar_controller && scrollbar_controller->animate(time))
+ if (scrollbar_controller && scrollbar_controller->animate(time)) {
+ TRACE_EVENT_INSTANT0(
+ "cc", "LayerTreeHostImpl::SetNeedsRedraw due to AnimateScrollbars");
client_->SetNeedsRedrawOnImplThread();
+ }
for (size_t i = 0; i < layer->children().size(); ++i)
AnimateScrollbarsRecursive(layer->children()[i], time);
}
+void LayerTreeHostImpl::StartScrollbarAnimation(base::TimeTicks time) {
+ TRACE_EVENT0("cc", "LayerTreeHostImpl::StartScrollbarAnimation");
+ StartScrollbarAnimationRecursive(RootLayer(), time);
+}
+
+void LayerTreeHostImpl::StartScrollbarAnimationRecursive(LayerImpl* layer,
+ base::TimeTicks time) {
+ if (!layer)
+ return;
+
+ ScrollbarAnimationController* scrollbar_controller =
+ layer->scrollbar_animation_controller();
+ if (scrollbar_controller && scrollbar_controller->isAnimating()) {
+ base::TimeDelta delay = scrollbar_controller->delayBeforeStart(time);
+ if (delay > base::TimeDelta())
+ client_->RequestScrollbarAnimationOnImplThread(delay);
+ else if (scrollbar_controller->animate(time))
+ client_->SetNeedsRedrawOnImplThread();
+ }
+
+ for (size_t i = 0; i < layer->children().size(); ++i)
+ StartScrollbarAnimationRecursive(layer->children()[i], time);
+}
+
void LayerTreeHostImpl::SetTreePriority(TreePriority priority) {
if (!tile_manager_)
return;
diff --git a/cc/layer_tree_host_impl.h b/cc/layer_tree_host_impl.h
index b2b70e0..a6ecfa9 100644
--- a/cc/layer_tree_host_impl.h
+++ b/cc/layer_tree_host_impl.h
@@ -65,6 +65,7 @@ class LayerTreeHostImplClient {
virtual void SendManagedMemoryStats() = 0;
virtual bool IsInsideDraw() = 0;
virtual void RenewTreePriority() = 0;
+ virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) = 0;
};
// LayerTreeHostImpl owns the LayerImpl trees as well as associated rendering
@@ -107,6 +108,8 @@ class CC_EXPORT LayerTreeHostImpl : public InputHandlerClient,
virtual void setNeedsRedraw() OVERRIDE;
virtual bool haveRootScrollLayer() const OVERRIDE;
+ void StartScrollbarAnimation(base::TimeTicks now);
+
struct CC_EXPORT FrameData : public RenderPassSink {
FrameData();
~FrameData();
@@ -381,6 +384,8 @@ class CC_EXPORT LayerTreeHostImpl : public InputHandlerClient,
static LayerImpl* GetNonCompositedContentLayerRecursive(LayerImpl* layer);
+ void StartScrollbarAnimationRecursive(LayerImpl* layer, base::TimeTicks time);
+
scoped_ptr<OutputSurface> output_surface_;
scoped_ptr<ResourceProvider> resource_provider_;
scoped_ptr<Renderer> renderer_;
diff --git a/cc/layer_tree_host_impl_unittest.cc b/cc/layer_tree_host_impl_unittest.cc
index 170617c..0f8024f 100644
--- a/cc/layer_tree_host_impl_unittest.cc
+++ b/cc/layer_tree_host_impl_unittest.cc
@@ -102,6 +102,7 @@ public:
virtual void SendManagedMemoryStats() OVERRIDE { }
virtual bool IsInsideDraw() OVERRIDE { return false; }
virtual void RenewTreePriority() OVERRIDE { }
+ virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) OVERRIDE { }
void setReduceMemoryResult(bool reduceMemoryResult) { m_reduceMemoryResult = reduceMemoryResult; }
diff --git a/cc/layer_tree_impl.cc b/cc/layer_tree_impl.cc
index dde8fe4..10747b8 100644
--- a/cc/layer_tree_impl.cc
+++ b/cc/layer_tree_impl.cc
@@ -13,6 +13,7 @@
#include "cc/layer_tree_host_common.h"
#include "cc/layer_tree_host_impl.h"
#include "cc/pinch_zoom_scrollbar.h"
+#include "cc/scrollbar_animation_controller.h"
#include "cc/scrollbar_layer_impl.h"
#include "ui/gfx/size_conversions.h"
#include "ui/gfx/vector2d_conversions.h"
@@ -145,8 +146,21 @@ LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const {
return currently_scrolling_layer_;
}
+void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) {
+ if (currently_scrolling_layer_ == layer)
+ return;
+
+ if (currently_scrolling_layer_ &&
+ currently_scrolling_layer_->scrollbar_animation_controller())
+ currently_scrolling_layer_->scrollbar_animation_controller()
+ ->didScrollGestureEnd(base::TimeTicks::Now());
+ currently_scrolling_layer_ = layer;
+ if (layer && layer->scrollbar_animation_controller())
+ layer->scrollbar_animation_controller()->didScrollGestureBegin();
+}
+
void LayerTreeImpl::ClearCurrentlyScrollingLayer() {
- currently_scrolling_layer_ = NULL;
+ SetCurrentlyScrollingLayer(NULL);
scrolling_layer_id_from_previous_tree_ = 0;
}
@@ -362,7 +376,7 @@ void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) {
void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pendingTree) {
int id = currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
- pendingTree->set_currently_scrolling_layer(
+ pendingTree->SetCurrentlyScrollingLayer(
LayerTreeHostCommon::findLayerInSubtree(pendingTree->root_layer(), id));
}
diff --git a/cc/layer_tree_impl.h b/cc/layer_tree_impl.h
index 1297c8e..e44bae5 100644
--- a/cc/layer_tree_impl.h
+++ b/cc/layer_tree_impl.h
@@ -102,10 +102,7 @@ class CC_EXPORT LayerTreeImpl {
LayerImpl* RootScrollLayer() const;
LayerImpl* RootClipLayer() const;
LayerImpl* CurrentlyScrollingLayer() const;
- void set_currently_scrolling_layer(LayerImpl* layer) {
- currently_scrolling_layer_ = layer;
- }
-
+ void SetCurrentlyScrollingLayer(LayerImpl* layer);
void ClearCurrentlyScrollingLayer();
void FindRootScrollLayer();
diff --git a/cc/resource_update_controller.cc b/cc/resource_update_controller.cc
index 1ce1f4f..443d71ae 100644
--- a/cc/resource_update_controller.cc
+++ b/cc/resource_update_controller.cc
@@ -255,7 +255,7 @@ bool ResourceUpdateController::UpdateMoreTexturesIfEnoughTimeRemaining() {
thread_->PostDelayedTask(
base::Bind(&ResourceUpdateController::OnTimerFired,
weak_factory_.GetWeakPtr()),
- kUploaderBusyTickRate * 1000);
+ base::TimeDelta::FromMilliseconds(kUploaderBusyTickRate * 1000));
return true;
}
diff --git a/cc/scrollbar_animation_controller.h b/cc/scrollbar_animation_controller.h
index f75e8d3..e660e8f 100644
--- a/cc/scrollbar_animation_controller.h
+++ b/cc/scrollbar_animation_controller.h
@@ -17,10 +17,14 @@ class CC_EXPORT ScrollbarAnimationController {
public:
virtual ~ScrollbarAnimationController() {}
+ virtual bool isScrollGestureInProgress() const = 0;
+ virtual bool isAnimating() const = 0;
+ virtual base::TimeDelta delayBeforeStart(base::TimeTicks now) const = 0;
+
virtual bool animate(base::TimeTicks) = 0;
- virtual void didPinchGestureUpdate(base::TimeTicks) = 0;
- virtual void didPinchGestureEnd(base::TimeTicks) = 0;
- virtual void didUpdateScrollOffset(base::TimeTicks) = 0;
+ virtual void didScrollGestureBegin() = 0;
+ virtual void didScrollGestureEnd(base::TimeTicks now) = 0;
+ virtual void didProgrammaticallyUpdateScroll(base::TimeTicks now) = 0;
};
} // namespace cc
diff --git a/cc/scrollbar_animation_controller_linear_fade.cc b/cc/scrollbar_animation_controller_linear_fade.cc
index eee6b06..f4f4acf 100644
--- a/cc/scrollbar_animation_controller_linear_fade.cc
+++ b/cc/scrollbar_animation_controller_linear_fade.cc
@@ -9,15 +9,15 @@
namespace cc {
-scoped_ptr<ScrollbarAnimationControllerLinearFade> ScrollbarAnimationControllerLinearFade::create(LayerImpl* scrollLayer, double fadeoutDelay, double fadeoutLength)
+scoped_ptr<ScrollbarAnimationControllerLinearFade> ScrollbarAnimationControllerLinearFade::create(LayerImpl* scrollLayer, base::TimeDelta fadeoutDelay, base::TimeDelta fadeoutLength)
{
return make_scoped_ptr(new ScrollbarAnimationControllerLinearFade(scrollLayer, fadeoutDelay, fadeoutLength));
}
-ScrollbarAnimationControllerLinearFade::ScrollbarAnimationControllerLinearFade(LayerImpl* scrollLayer, double fadeoutDelay, double fadeoutLength)
+ScrollbarAnimationControllerLinearFade::ScrollbarAnimationControllerLinearFade(LayerImpl* scrollLayer, base::TimeDelta fadeoutDelay, base::TimeDelta fadeoutLength)
: ScrollbarAnimationController()
, m_scrollLayer(scrollLayer)
- , m_pinchGestureInEffect(false)
+ , m_scrollGestureInProgress(false)
, m_fadeoutDelay(fadeoutDelay)
, m_fadeoutLength(fadeoutLength)
{
@@ -27,43 +27,67 @@ ScrollbarAnimationControllerLinearFade::~ScrollbarAnimationControllerLinearFade(
{
}
+bool ScrollbarAnimationControllerLinearFade::isScrollGestureInProgress() const
+{
+ return m_scrollGestureInProgress;
+}
+
+bool ScrollbarAnimationControllerLinearFade::isAnimating() const
+{
+ return !m_lastAwakenTime.is_null();
+}
+
+base::TimeDelta ScrollbarAnimationControllerLinearFade::delayBeforeStart(base::TimeTicks now) const
+{
+ if (now > m_lastAwakenTime + m_fadeoutDelay)
+ return base::TimeDelta();
+ return m_fadeoutDelay - (now - m_lastAwakenTime);
+}
+
bool ScrollbarAnimationControllerLinearFade::animate(base::TimeTicks now)
{
float opacity = opacityAtTime(now);
m_scrollLayer->SetScrollbarOpacity(opacity);
- return opacity;
+ if (!opacity)
+ m_lastAwakenTime = base::TimeTicks();
+ return isAnimating() && delayBeforeStart(now) == base::TimeDelta();
}
-void ScrollbarAnimationControllerLinearFade::didPinchGestureUpdate(base::TimeTicks now)
+void ScrollbarAnimationControllerLinearFade::didScrollGestureBegin()
{
- m_pinchGestureInEffect = true;
+ m_scrollLayer->SetScrollbarOpacity(1);
+ m_scrollGestureInProgress = true;
+ m_lastAwakenTime = base::TimeTicks();
}
-void ScrollbarAnimationControllerLinearFade::didPinchGestureEnd(base::TimeTicks now)
+void ScrollbarAnimationControllerLinearFade::didScrollGestureEnd(base::TimeTicks now)
{
- m_pinchGestureInEffect = false;
+ m_scrollGestureInProgress = false;
m_lastAwakenTime = now;
}
-void ScrollbarAnimationControllerLinearFade::didUpdateScrollOffset(base::TimeTicks now)
+void ScrollbarAnimationControllerLinearFade::didProgrammaticallyUpdateScroll(base::TimeTicks now)
{
+ // Don't set m_scrollGestureInProgress as this scroll is not from a gesture
+ // and we won't receive ScrollEnd.
+ m_scrollLayer->SetScrollbarOpacity(1);
m_lastAwakenTime = now;
}
float ScrollbarAnimationControllerLinearFade::opacityAtTime(base::TimeTicks now)
{
- if (m_pinchGestureInEffect)
+ if (m_scrollGestureInProgress)
return 1;
if (m_lastAwakenTime.is_null())
return 0;
- double delta = (now - m_lastAwakenTime).InSecondsF();
+ base::TimeDelta delta = now - m_lastAwakenTime;
if (delta <= m_fadeoutDelay)
return 1;
if (delta < m_fadeoutDelay + m_fadeoutLength)
- return (m_fadeoutDelay + m_fadeoutLength - delta) / m_fadeoutLength;
+ return (m_fadeoutDelay + m_fadeoutLength - delta).InSecondsF() / m_fadeoutLength.InSecondsF();
return 0;
}
diff --git a/cc/scrollbar_animation_controller_linear_fade.h b/cc/scrollbar_animation_controller_linear_fade.h
index 709bdde..81dba25 100644
--- a/cc/scrollbar_animation_controller_linear_fade.h
+++ b/cc/scrollbar_animation_controller_linear_fade.h
@@ -14,18 +14,22 @@ class LayerImpl;
class CC_EXPORT ScrollbarAnimationControllerLinearFade : public ScrollbarAnimationController {
public:
- static scoped_ptr<ScrollbarAnimationControllerLinearFade> create(LayerImpl* scrollLayer, double fadeoutDelay, double fadeoutLength);
+ static scoped_ptr<ScrollbarAnimationControllerLinearFade> create(LayerImpl* scrollLayer, base::TimeDelta fadeoutDelay, base::TimeDelta fadeoutLength);
virtual ~ScrollbarAnimationControllerLinearFade();
// ScrollbarAnimationController overrides.
+ virtual bool isScrollGestureInProgress() const OVERRIDE;
+ virtual bool isAnimating() const OVERRIDE;
+ virtual base::TimeDelta delayBeforeStart(base::TimeTicks now) const OVERRIDE;
+
virtual bool animate(base::TimeTicks) OVERRIDE;
- virtual void didPinchGestureUpdate(base::TimeTicks) OVERRIDE;
- virtual void didPinchGestureEnd(base::TimeTicks) OVERRIDE;
- virtual void didUpdateScrollOffset(base::TimeTicks) OVERRIDE;
+ virtual void didScrollGestureBegin() OVERRIDE;
+ virtual void didScrollGestureEnd(base::TimeTicks now) OVERRIDE;
+ virtual void didProgrammaticallyUpdateScroll(base::TimeTicks now) OVERRIDE;
protected:
- ScrollbarAnimationControllerLinearFade(LayerImpl* scrollLayer, double fadeoutDelay, double fadeoutLength);
+ ScrollbarAnimationControllerLinearFade(LayerImpl* scrollLayer, base::TimeDelta fadeoutDelay, base::TimeDelta fadeoutLength);
private:
float opacityAtTime(base::TimeTicks);
@@ -33,10 +37,10 @@ private:
LayerImpl* m_scrollLayer;
base::TimeTicks m_lastAwakenTime;
- bool m_pinchGestureInEffect;
+ bool m_scrollGestureInProgress;
- double m_fadeoutDelay;
- double m_fadeoutLength;
+ base::TimeDelta m_fadeoutDelay;
+ base::TimeDelta m_fadeoutLength;
double m_currentTimeForTesting;
};
diff --git a/cc/scrollbar_animation_controller_linear_fade_unittest.cc b/cc/scrollbar_animation_controller_linear_fade_unittest.cc
index e3c2c23..0513190 100644
--- a/cc/scrollbar_animation_controller_linear_fade_unittest.cc
+++ b/cc/scrollbar_animation_controller_linear_fade_unittest.cc
@@ -32,7 +32,7 @@ protected:
m_scrollLayer->SetBounds(gfx::Size(50, 50));
m_scrollLayer->SetHorizontalScrollbarLayer(m_scrollbarLayer.get());
- m_scrollbarController = ScrollbarAnimationControllerLinearFade::create(m_scrollLayer.get(), 2, 3);
+ m_scrollbarController = ScrollbarAnimationControllerLinearFade::create(m_scrollLayer.get(), base::TimeDelta::FromSeconds(2), base::TimeDelta::FromSeconds(3));
}
FakeImplProxy m_proxy;
@@ -49,18 +49,23 @@ TEST_F(ScrollbarAnimationControllerLinearFadeTest, verifyHiddenInBegin)
EXPECT_FLOAT_EQ(0, m_scrollbarLayer->opacity());
}
-TEST_F(ScrollbarAnimationControllerLinearFadeTest, verifyAwakenByScroll)
+TEST_F(ScrollbarAnimationControllerLinearFadeTest, verifyAwakenByScrollGesture)
{
base::TimeTicks time;
time += base::TimeDelta::FromSeconds(1);
- m_scrollbarController->didUpdateScrollOffset(time);
- m_scrollbarController->animate(time);
+ m_scrollbarController->didScrollGestureBegin();
+ EXPECT_TRUE(m_scrollbarController->isScrollGestureInProgress());
+ EXPECT_FALSE(m_scrollbarController->isAnimating());
EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());
- time += base::TimeDelta::FromSeconds(1);
+ time += base::TimeDelta::FromSeconds(100);
m_scrollbarController->animate(time);
EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());
- m_scrollbarController->didUpdateScrollOffset(time);
+ m_scrollbarController->didScrollGestureEnd(time);
+
+ EXPECT_FALSE(m_scrollbarController->isScrollGestureInProgress());
+ EXPECT_TRUE(m_scrollbarController->isAnimating());
+ EXPECT_EQ(2, m_scrollbarController->delayBeforeStart(time).InSeconds());
time += base::TimeDelta::FromSeconds(1);
m_scrollbarController->animate(time);
@@ -79,7 +84,10 @@ TEST_F(ScrollbarAnimationControllerLinearFadeTest, verifyAwakenByScroll)
EXPECT_FLOAT_EQ(1.0f / 3.0f, m_scrollbarLayer->opacity());
time += base::TimeDelta::FromSeconds(1);
- m_scrollbarController->didUpdateScrollOffset(time);
+
+ m_scrollbarController->didScrollGestureBegin();
+ m_scrollbarController->didScrollGestureEnd(time);
+
time += base::TimeDelta::FromSeconds(1);
m_scrollbarController->animate(time);
EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());
@@ -101,22 +109,21 @@ TEST_F(ScrollbarAnimationControllerLinearFadeTest, verifyAwakenByScroll)
EXPECT_FLOAT_EQ(0, m_scrollbarLayer->opacity());
}
-TEST_F(ScrollbarAnimationControllerLinearFadeTest, verifyForceAwakenByPinch)
+TEST_F(ScrollbarAnimationControllerLinearFadeTest, verifyAwakenByProgrammaticScroll)
{
base::TimeTicks time;
- m_scrollbarController->didPinchGestureUpdate(time);
- m_scrollbarController->animate(time);
- EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());
-
time += base::TimeDelta::FromSeconds(1);
+ m_scrollbarController->didProgrammaticallyUpdateScroll(time);
+ EXPECT_FALSE(m_scrollbarController->isScrollGestureInProgress());
+ EXPECT_TRUE(m_scrollbarController->isAnimating());
+ EXPECT_EQ(2, m_scrollbarController->delayBeforeStart(time).InSeconds());
m_scrollbarController->animate(time);
EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());
time += base::TimeDelta::FromSeconds(1);
m_scrollbarController->animate(time);
- m_scrollbarController->didUpdateScrollOffset(time);
- m_scrollbarController->animate(time);
EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());
+ m_scrollbarController->didProgrammaticallyUpdateScroll(time);
time += base::TimeDelta::FromSeconds(1);
m_scrollbarController->animate(time);
@@ -128,14 +135,15 @@ TEST_F(ScrollbarAnimationControllerLinearFadeTest, verifyForceAwakenByPinch)
time += base::TimeDelta::FromSeconds(1);
m_scrollbarController->animate(time);
- EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());
+ EXPECT_FLOAT_EQ(2.0f / 3.0f, m_scrollbarLayer->opacity());
time += base::TimeDelta::FromSeconds(1);
m_scrollbarController->animate(time);
- EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());
+ EXPECT_FLOAT_EQ(1.0f / 3.0f, m_scrollbarLayer->opacity());
time += base::TimeDelta::FromSeconds(1);
- m_scrollbarController->didPinchGestureEnd(time);
+ m_scrollbarController->didProgrammaticallyUpdateScroll(time);
+ time += base::TimeDelta::FromSeconds(1);
m_scrollbarController->animate(time);
EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());
@@ -143,18 +151,17 @@ TEST_F(ScrollbarAnimationControllerLinearFadeTest, verifyForceAwakenByPinch)
m_scrollbarController->animate(time);
EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());
- time += base::TimeDelta::FromSeconds(2);
+ time += base::TimeDelta::FromSeconds(1);
m_scrollbarController->animate(time);
- EXPECT_FLOAT_EQ(2 / 3.0f, m_scrollbarLayer->opacity());
+ EXPECT_FLOAT_EQ(2.0f / 3.0f, m_scrollbarLayer->opacity());
time += base::TimeDelta::FromSeconds(1);
m_scrollbarController->animate(time);
- EXPECT_FLOAT_EQ(1 / 3.0f, m_scrollbarLayer->opacity());
+ EXPECT_FLOAT_EQ(1.0f / 3.0f, m_scrollbarLayer->opacity());
time += base::TimeDelta::FromSeconds(1);
m_scrollbarController->animate(time);
EXPECT_FLOAT_EQ(0, m_scrollbarLayer->opacity());
-
}
} // namespace
diff --git a/cc/single_thread_proxy.h b/cc/single_thread_proxy.h
index 3e89643..6a19006 100644
--- a/cc/single_thread_proxy.h
+++ b/cc/single_thread_proxy.h
@@ -73,6 +73,8 @@ class SingleThreadProxy : public Proxy, LayerTreeHostImplClient {
virtual void SendManagedMemoryStats() OVERRIDE;
virtual bool IsInsideDraw() OVERRIDE;
virtual void RenewTreePriority() OVERRIDE {}
+ virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay)
+ OVERRIDE {}
// Called by the legacy path where RenderWidget does the scheduling.
void CompositeImmediately(base::TimeTicks frame_begin_time);
diff --git a/cc/test/fake_layer_tree_host_impl_client.h b/cc/test/fake_layer_tree_host_impl_client.h
index 937e366..e82c2d9 100644
--- a/cc/test/fake_layer_tree_host_impl_client.h
+++ b/cc/test/fake_layer_tree_host_impl_client.h
@@ -33,6 +33,8 @@ class FakeLayerTreeHostImplClient : public LayerTreeHostImplClient {
virtual void SendManagedMemoryStats() OVERRIDE {}
virtual bool IsInsideDraw() OVERRIDE;
virtual void RenewTreePriority() OVERRIDE {}
+ virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta)
+ OVERRIDE {}
};
} // namespace cc
diff --git a/cc/test/layer_tree_test_common.cc b/cc/test/layer_tree_test_common.cc
index 8528a3c..35274e8 100644
--- a/cc/test/layer_tree_test_common.cc
+++ b/cc/test/layer_tree_test_common.cc
@@ -510,7 +510,7 @@ void ThreadedTest::runTest(bool threaded)
m_mainCCThread->PostTask(base::Bind(&ThreadedTest::doBeginTest, base::Unretained(this)));
m_timeout.Reset(base::Bind(&ThreadedTest::timeout, base::Unretained(this)));
- m_mainCCThread->PostDelayedTask(m_timeout.callback(), 5000);
+ m_mainCCThread->PostDelayedTask(m_timeout.callback(), base::TimeDelta::FromSeconds(5));
MessageLoop::current()->Run();
if (m_layerTreeHost.get() && m_layerTreeHost->root_layer())
m_layerTreeHost->root_layer()->SetLayerTreeHost(NULL);
diff --git a/cc/test/scheduler_test_common.cc b/cc/test/scheduler_test_common.cc
index 9f399c7..ebef8b0 100644
--- a/cc/test/scheduler_test_common.cc
+++ b/cc/test/scheduler_test_common.cc
@@ -31,17 +31,17 @@ void FakeThread::runPendingTask()
void FakeThread::PostTask(base::Closure cb)
{
- PostDelayedTask(cb, 0);
+ PostDelayedTask(cb, base::TimeDelta());
}
-void FakeThread::PostDelayedTask(base::Closure cb, long long delay)
+void FakeThread::PostDelayedTask(base::Closure cb, base::TimeDelta delay)
{
if (m_runPendingTaskOnOverwrite && hasPendingTask())
runPendingTask();
ASSERT_FALSE(hasPendingTask());
m_pendingTask.reset(new base::Closure(cb));
- m_pendingTaskDelay = delay;
+ m_pendingTaskDelay = delay.InMilliseconds();
}
bool FakeThread::BelongsToCurrentThread() const
diff --git a/cc/test/scheduler_test_common.h b/cc/test/scheduler_test_common.h
index e5faaa5..760ba2568 100644
--- a/cc/test/scheduler_test_common.h
+++ b/cc/test/scheduler_test_common.h
@@ -6,6 +6,7 @@
#define CC_TEST_SCHEDULER_TEST_COMMON_H_
#include "base/memory/scoped_ptr.h"
+#include "base/time.h"
#include "cc/base/thread.h"
#include "cc/delay_based_time_source.h"
#include "cc/frame_rate_controller.h"
@@ -52,7 +53,8 @@ public:
}
virtual void PostTask(base::Closure cb) OVERRIDE;
- virtual void PostDelayedTask(base::Closure cb, long long delay_ms) OVERRIDE;
+ virtual void PostDelayedTask(base::Closure cb, base::TimeDelta delay)
+ OVERRIDE;
virtual bool BelongsToCurrentThread() const OVERRIDE;
protected:
diff --git a/cc/thread_proxy.cc b/cc/thread_proxy.cc
index 0d8beb1..661ba77 100644
--- a/cc/thread_proxy.cc
+++ b/cc/thread_proxy.cc
@@ -1315,7 +1315,7 @@ void ThreadProxy::RenewTreePriority() {
Proxy::ImplThread()->PostDelayedTask(
base::Bind(&ThreadProxy::RenewTreePriorityOnImplThread,
weak_factory_on_impl_thread_.GetWeakPtr()),
- delay.InMilliseconds());
+ delay);
renew_tree_priority_on_impl_thread_pending_ = true;
}
@@ -1327,4 +1327,15 @@ void ThreadProxy::RenewTreePriorityOnImplThread() {
RenewTreePriority();
}
+void ThreadProxy::RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) {
+ Proxy::ImplThread()->PostDelayedTask(
+ base::Bind(&ThreadProxy::StartScrollbarAnimationOnImplThread,
+ impl_thread_weak_ptr_),
+ delay);
+}
+
+void ThreadProxy::StartScrollbarAnimationOnImplThread() {
+ layer_tree_host_impl_->StartScrollbarAnimation(base::TimeTicks::Now());
+}
+
} // namespace cc
diff --git a/cc/thread_proxy.h b/cc/thread_proxy.h
index c57a4ee..9415475 100644
--- a/cc/thread_proxy.h
+++ b/cc/thread_proxy.h
@@ -86,6 +86,8 @@ class ThreadProxy : public Proxy,
virtual void SendManagedMemoryStats() OVERRIDE;
virtual bool IsInsideDraw() OVERRIDE;
virtual void RenewTreePriority() OVERRIDE;
+ virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay)
+ OVERRIDE;
// SchedulerClient implementation
virtual void ScheduledActionBeginFrame() OVERRIDE;
@@ -186,6 +188,7 @@ class ThreadProxy : public Proxy,
base::DictionaryValue* state) const;
void RenewTreePriorityOnImplThread();
void DidSwapUseIncompleteTileOnImplThread();
+ void StartScrollbarAnimationOnImplThread();
// Accessed on main thread only.