Skip to content

Commit

Permalink
cc: Avoid prefer smoothness mode when scrolling with scroll handler
Browse files Browse the repository at this point in the history
    
Avoid going into prefer smoothness mode when the scrolled layer has a
scroll handler. The presence of a scroll handler suggests that the main
thread wants to animate in response to scrolling. Avoiding smoothness
mode gives it a chance to do that while still having our deadline as a
fallback.
    
BUG=347366

Review URL: https://codereview.chromium.org/206523003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260859 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
skyostil@chromium.org committed Apr 1, 2014
1 parent 1316f7f commit f161ca9
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
26 changes: 20 additions & 6 deletions cc/trees/layer_tree_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ LayerTreeHostImpl::LayerTreeHostImpl(
did_lock_scrolling_layer_(false),
should_bubble_scrolls_(false),
wheel_scrolling_(false),
scroll_affects_scroll_handler_(false),
scroll_layer_id_when_mouse_over_scrollbar_(0),
tile_priorities_dirty_(false),
root_layer_scroll_offset_delegate_(NULL),
Expand Down Expand Up @@ -2030,7 +2031,9 @@ static LayerImpl* NextScrollLayer(LayerImpl* layer) {
LayerImpl* LayerTreeHostImpl::FindScrollLayerForDeviceViewportPoint(
const gfx::PointF& device_viewport_point,
InputHandler::ScrollInputType type,
LayerImpl* layer_impl, bool* scroll_on_main_thread) const {
LayerImpl* layer_impl,
bool* scroll_on_main_thread,
bool* has_ancestor_scroll_handler) const {
DCHECK(scroll_on_main_thread);

// Walk up the hierarchy and look for a scrollable layer.
Expand All @@ -2055,6 +2058,10 @@ LayerImpl* LayerTreeHostImpl::FindScrollLayerForDeviceViewportPoint(
return NULL;
}

if (has_ancestor_scroll_handler &&
scroll_layer_impl->have_scroll_event_handlers())
*has_ancestor_scroll_handler = true;

if (status == ScrollStarted && !potentially_scrolling_layer_impl)
potentially_scrolling_layer_impl = scroll_layer_impl;
}
Expand Down Expand Up @@ -2083,8 +2090,11 @@ InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin(
active_tree_->RenderSurfaceLayerList());
bool scroll_on_main_thread = false;
LayerImpl* potentially_scrolling_layer_impl =
FindScrollLayerForDeviceViewportPoint(device_viewport_point, type,
layer_impl, &scroll_on_main_thread);
FindScrollLayerForDeviceViewportPoint(device_viewport_point,
type,
layer_impl,
&scroll_on_main_thread,
&scroll_affects_scroll_handler_);

if (scroll_on_main_thread) {
UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", true);
Expand Down Expand Up @@ -2383,6 +2393,7 @@ void LayerTreeHostImpl::OnRootLayerDelegatedScrollOffsetChanged() {
void LayerTreeHostImpl::ClearCurrentlyScrollingLayer() {
active_tree_->ClearCurrentlyScrollingLayer();
did_lock_scrolling_layer_ = false;
scroll_affects_scroll_handler_ = false;
accumulated_root_overscroll_ = gfx::Vector2dF();
current_fling_velocity_ = gfx::Vector2dF();
}
Expand Down Expand Up @@ -2468,9 +2479,12 @@ void LayerTreeHostImpl::MouseMoveAt(const gfx::Point& viewport_point) {
}

bool scroll_on_main_thread = false;
LayerImpl* scroll_layer_impl = FindScrollLayerForDeviceViewportPoint(
device_viewport_point, InputHandler::Gesture, layer_impl,
&scroll_on_main_thread);
LayerImpl* scroll_layer_impl =
FindScrollLayerForDeviceViewportPoint(device_viewport_point,
InputHandler::Gesture,
layer_impl,
&scroll_on_main_thread,
NULL);
if (scroll_on_main_thread || !scroll_layer_impl)
return;

Expand Down
9 changes: 7 additions & 2 deletions cc/trees/layer_tree_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,12 @@ class CC_EXPORT LayerTreeHostImpl
LayerImpl* OuterViewportScrollLayer() const;
LayerImpl* CurrentlyScrollingLayer() const;

int scroll_layer_id_when_mouse_over_scrollbar() {
int scroll_layer_id_when_mouse_over_scrollbar() const {
return scroll_layer_id_when_mouse_over_scrollbar_;
}
bool scroll_affects_scroll_handler() const {
return scroll_affects_scroll_handler_;
}

bool IsCurrentlyScrolling() const;

Expand Down Expand Up @@ -508,7 +511,8 @@ class CC_EXPORT LayerTreeHostImpl
const gfx::PointF& device_viewport_point,
InputHandler::ScrollInputType type,
LayerImpl* layer_hit_by_point,
bool* scroll_on_main_thread) const;
bool* scroll_on_main_thread,
bool* has_ancestor_scroll_handler) const;
float DeviceSpaceDistanceToLayer(const gfx::PointF& device_viewport_point,
LayerImpl* layer_impl);
void StartScrollbarAnimationRecursive(LayerImpl* layer, base::TimeTicks time);
Expand Down Expand Up @@ -557,6 +561,7 @@ class CC_EXPORT LayerTreeHostImpl
bool did_lock_scrolling_layer_;
bool should_bubble_scrolls_;
bool wheel_scrolling_;
bool scroll_affects_scroll_handler_;
int scroll_layer_id_when_mouse_over_scrollbar_;

bool tile_priorities_dirty_;
Expand Down
26 changes: 26 additions & 0 deletions cc/trees/layer_tree_host_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,32 @@ TEST_F(LayerTreeHostImplTest, NonFastScrollableRegionWithOffset) {
InputHandler::Wheel));
}

TEST_F(LayerTreeHostImplTest, ScrollHandlerNotPresent) {
LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(200, 200));
EXPECT_FALSE(scroll_layer->have_scroll_event_handlers());
host_impl_->SetViewportSize(gfx::Size(50, 50));
DrawFrame();

EXPECT_FALSE(host_impl_->scroll_affects_scroll_handler());
host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture);
EXPECT_FALSE(host_impl_->scroll_affects_scroll_handler());
host_impl_->ScrollEnd();
EXPECT_FALSE(host_impl_->scroll_affects_scroll_handler());
}

TEST_F(LayerTreeHostImplTest, ScrollHandlerPresent) {
LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(200, 200));
scroll_layer->SetHaveScrollEventHandlers(true);
host_impl_->SetViewportSize(gfx::Size(50, 50));
DrawFrame();

EXPECT_FALSE(host_impl_->scroll_affects_scroll_handler());
host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture);
EXPECT_TRUE(host_impl_->scroll_affects_scroll_handler());
host_impl_->ScrollEnd();
EXPECT_FALSE(host_impl_->scroll_affects_scroll_handler());
}

TEST_F(LayerTreeHostImplTest, ScrollByReturnsCorrectValue) {
SetupScrollAndContentsLayers(gfx::Size(200, 200));
host_impl_->SetViewportSize(gfx::Size(100, 100));
Expand Down
5 changes: 3 additions & 2 deletions cc/trees/thread_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1626,8 +1626,9 @@ void ThreadProxy::RenewTreePriority() {
DCHECK(IsImplThread());
bool smoothness_takes_priority =
impl().layer_tree_host_impl->pinch_gesture_active() ||
impl().layer_tree_host_impl->IsCurrentlyScrolling() ||
impl().layer_tree_host_impl->page_scale_animation_active();
impl().layer_tree_host_impl->page_scale_animation_active() ||
(impl().layer_tree_host_impl->IsCurrentlyScrolling() &&
!impl().layer_tree_host_impl->scroll_affects_scroll_handler());

base::TimeTicks now = impl().layer_tree_host_impl->CurrentFrameTimeTicks();

Expand Down

0 comments on commit f161ca9

Please sign in to comment.