Skip to content

Commit

Permalink
Determine MaxScrollOffset without using 'tree' structure of LayerTree
Browse files Browse the repository at this point in the history
* Use IsAffectedByPageScale instead of the tree structure to determine the scale factor in MaxScrollOffset();
* Fix related unit tests
* Fix a variable name issue of the previous changelist (Issue 1544103002)

BUG=568777
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

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

Cr-Commit-Position: refs/heads/master@{#368087}
  • Loading branch information
sunxd authored and Commit bot committed Jan 7, 2016
1 parent 0e35f1c commit 6766965
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 66 deletions.
16 changes: 8 additions & 8 deletions cc/layers/heads_up_display_layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ TEST(HeadsUpDisplayLayerImplTest, ResourcelessSoftwareDrawAfterResourceLoss) {
host_impl.CreatePendingTree();
host_impl.SetVisible(true);
host_impl.InitializeRenderer(output_surface.get());
scoped_ptr<HeadsUpDisplayLayerImpl> layer =
HeadsUpDisplayLayerImpl::Create(host_impl.pending_tree(), 1);
layer->SetBounds(gfx::Size(100, 100));
scoped_ptr<HeadsUpDisplayLayerImpl> layer_ptr =
HeadsUpDisplayLayerImpl::Create(host_impl.pending_tree(), 1);
layer_ptr->SetBounds(gfx::Size(100, 100));

HeadsUpDisplayLayerImpl* layer_ptr = layer.get();
HeadsUpDisplayLayerImpl* layer = layer_ptr.get();

host_impl.pending_tree()->SetRootLayer(std::move(layer));
host_impl.pending_tree()->SetRootLayer(std::move(layer_ptr));
host_impl.pending_tree()->BuildPropertyTreesForTesting();

// Check regular hardware draw is ok.
CheckDrawLayer(layer_ptr, host_impl.resource_provider(), DRAW_MODE_HARDWARE);
CheckDrawLayer(layer, host_impl.resource_provider(), DRAW_MODE_HARDWARE);

// Simulate a resource loss on transitioning to resourceless software mode.
layer_ptr->ReleaseResources();
layer->ReleaseResources();

// Should skip resourceless software draw and not crash in UpdateHudTexture.
CheckDrawLayer(layer_ptr, host_impl.resource_provider(),
CheckDrawLayer(layer, host_impl.resource_provider(),
DRAW_MODE_RESOURCELESS_SOFTWARE);
}

Expand Down
9 changes: 3 additions & 6 deletions cc/layers/layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1600,12 +1600,9 @@ gfx::ScrollOffset LayerImpl::MaxScrollOffset() const {
IsContainerForFixedPositionLayers());

float scale_factor = 1.f;
for (LayerImpl const* current_layer = this;
current_layer != scroll_clip_layer->parent();
current_layer = current_layer->parent()) {
if (current_layer == page_scale_layer)
scale_factor = layer_tree_impl()->current_page_scale_factor();
}
DCHECK(scroll_clip_layer != page_scale_layer);
if (!scroll_clip_layer->IsAffectedByPageScale() && IsAffectedByPageScale())
scale_factor = layer_tree_impl()->current_page_scale_factor();

gfx::SizeF scaled_scroll_bounds =
gfx::ScaleSize(BoundsForScrolling(), scale_factor);
Expand Down
8 changes: 6 additions & 2 deletions cc/layers/layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,13 @@ TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) {
&task_graph_runner);
host_impl.SetVisible(true);
EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get()));
scoped_ptr<LayerImpl> root_clip =
scoped_ptr<LayerImpl> root_clip_ptr =
LayerImpl::Create(host_impl.active_tree(), 1);
LayerImpl* root_clip = root_clip_ptr.get();
scoped_ptr<LayerImpl> root_ptr =
LayerImpl::Create(host_impl.active_tree(), 2);
LayerImpl* root = root_ptr.get();
root_clip->AddChild(std::move(root_ptr));
root_clip_ptr->AddChild(std::move(root_ptr));
scoped_ptr<LayerImpl> scroll_parent =
LayerImpl::Create(host_impl.active_tree(), 3);
LayerImpl* scroll_child = LayerImpl::Create(host_impl.active_tree(), 4).get();
Expand All @@ -125,6 +126,8 @@ TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) {
LayerImpl* child = root->children()[0].get();
child->AddChild(LayerImpl::Create(host_impl.active_tree(), 8));
LayerImpl* grand_child = child->children()[0].get();
host_impl.active_tree()->SetRootLayer(std::move(root_clip_ptr));
host_impl.active_tree()->BuildPropertyTreesForTesting();

root->SetScrollClipLayer(root_clip->id());

Expand Down Expand Up @@ -464,6 +467,7 @@ class LayerImplScrollTest : public testing::Test {
LayerImpl::Create(host_impl_.active_tree(), root_id_));
host_impl_.active_tree()->root_layer()->AddChild(
LayerImpl::Create(host_impl_.active_tree(), root_id_ + 1));
host_impl_.active_tree()->BuildPropertyTreesForTesting();
layer()->SetScrollClipLayer(root_id_);
// Set the max scroll offset by noting that the root layer has bounds (1,1),
// thus whatever bounds are set for the layer will be the max scroll
Expand Down
2 changes: 2 additions & 0 deletions cc/layers/scrollbar_layer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) {
content_layer->SetBounds(gfx::Size(1000, 2000));
content_layer->SavePaintProperties();

layer_tree_host_->UpdateLayers();
layer_impl_tree_root = layer_tree_host_->CommitAndCreateLayerImplTree();

EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos());
Expand Down Expand Up @@ -448,6 +449,7 @@ TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) {
scroll_layer->InsertChild(child2, 1);
layer_tree_root->AddChild(scroll_layer);
layer_tree_host_->SetRootLayer(layer_tree_root);
layer_tree_host_->UpdateLayers();
}
LayerImpl* layer_impl_tree_root =
layer_tree_host_->CommitAndCreateLayerImplTree();
Expand Down
3 changes: 1 addition & 2 deletions cc/test/layer_tree_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ void CreateVirtualViewportLayers(Layer* root_layer,

inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
outer_scroll_layer->SetIsContainerForFixedPositionLayers(true);
host->RegisterViewportLayers(NULL,
root_layer,
host->RegisterViewportLayers(NULL, page_scale_layer,
inner_viewport_scroll_layer,
outer_scroll_layer);
}
Expand Down
100 changes: 63 additions & 37 deletions cc/trees/layer_tree_host_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ class LayerTreeHostImplTest : public testing::Test,
host_impl_->InnerViewportScrollLayer()->parent()->parent();
inner_clip_layer->SetBounds(viewport_size);
host_impl_->InnerViewportScrollLayer()->SetBounds(viewport_size);
host_impl_->active_tree()->BuildPropertyTreesForTesting();

host_impl_->SetViewportSize(viewport_size);
host_impl_->active_tree()->DidBecomeActive();
Expand Down Expand Up @@ -571,9 +572,11 @@ TEST_F(LayerTreeHostImplTest, ScrollDeltaRepeatedScrolls) {
root_layer->SetBounds(gfx::Size(110, 110));
root_layer->SetScrollClipLayer(root_clip->id());
root_layer->PushScrollOffsetFromMainThread(scroll_offset);
root_layer->ScrollBy(scroll_delta);
host_impl_->active_tree()->SetRootLayer(std::move(root_clip));
host_impl_->active_tree()->BuildPropertyTreesForTesting();
root_layer->ScrollBy(scroll_delta);
}

LayerImpl* root =
host_impl_->active_tree()->root_layer()->children()[0].get();

Expand Down Expand Up @@ -1088,7 +1091,7 @@ TEST_F(LayerTreeHostImplTest, ScrollWithUserUnscrollableLayers) {
ASSERT_EQ(1u, scroll_layer->children().size());
LayerImpl* overflow = scroll_layer->children()[0].get();
overflow->SetBounds(overflow_size);
overflow->SetScrollClipLayer(scroll_layer->parent()->id());
overflow->SetScrollClipLayer(scroll_layer->parent()->parent()->id());
overflow->PushScrollOffsetFromMainThread(gfx::ScrollOffset());
overflow->SetPosition(gfx::PointF());

Expand Down Expand Up @@ -2224,6 +2227,7 @@ TEST_F(LayerTreeHostImplTest, PageScaleAnimationTransferedOnSyncTreeActivate) {
CreateScrollAndContentsLayers(
host_impl_->pending_tree(),
gfx::Size(100, 100));
host_impl_->pending_tree()->BuildPropertyTreesForTesting();
host_impl_->ActivateSyncTree();
DrawFrame();

Expand Down Expand Up @@ -3547,6 +3551,7 @@ TEST_F(LayerTreeHostImplTest, ClampingAfterActivation) {
host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f);
CreateScrollAndContentsLayers(host_impl_->pending_tree(),
gfx::Size(100, 100));
host_impl_->pending_tree()->BuildPropertyTreesForTesting();
host_impl_->ActivateSyncTree();

host_impl_->CreatePendingTree();
Expand Down Expand Up @@ -3635,6 +3640,7 @@ class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest {
host_impl_->active_tree()->SetViewportLayersFromIds(
Layer::INVALID_ID, page_scale_layer_id, inner_viewport_scroll_layer_id,
outer_viewport_scroll_layer_id);
host_impl_->active_tree()->BuildPropertyTreesForTesting();

host_impl_->SetViewportSize(inner_viewport_size);
LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer();
Expand Down Expand Up @@ -4634,26 +4640,30 @@ TEST_F(LayerTreeHostImplTest, ScrollWithoutBubbling) {
// the scroll doesn't bubble up to the parent layer.
gfx::Size surface_size(20, 20);
gfx::Size viewport_size(10, 10);
scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1);
root->SetForceRenderSurface(true);
scoped_ptr<LayerImpl> root_ptr =
LayerImpl::Create(host_impl_->active_tree(), 1);
scoped_ptr<LayerImpl> root_clip =
LayerImpl::Create(host_impl_->active_tree(), 2);
root_clip->SetForceRenderSurface(true);
scoped_ptr<LayerImpl> root_scrolling =
CreateScrollableLayer(2, surface_size, root.get());
CreateScrollableLayer(3, surface_size, root_clip.get());
root_scrolling->SetIsContainerForFixedPositionLayers(true);

scoped_ptr<LayerImpl> grand_child =
CreateScrollableLayer(4, surface_size, root.get());
CreateScrollableLayer(5, surface_size, root_clip.get());

scoped_ptr<LayerImpl> child =
CreateScrollableLayer(3, surface_size, root.get());
CreateScrollableLayer(4, surface_size, root_clip.get());
LayerImpl* grand_child_layer = grand_child.get();
child->AddChild(std::move(grand_child));

LayerImpl* child_layer = child.get();
root_scrolling->AddChild(std::move(child));
root->AddChild(std::move(root_scrolling));
EXPECT_EQ(viewport_size, root->bounds());
host_impl_->active_tree()->SetRootLayer(std::move(root));
host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 2,
root_clip->AddChild(std::move(root_scrolling));
EXPECT_EQ(viewport_size, root_clip->bounds());
root_ptr->AddChild(std::move(root_clip));
host_impl_->active_tree()->SetRootLayer(std::move(root_ptr));
host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 3,
Layer::INVALID_ID);
host_impl_->active_tree()->DidBecomeActive();
host_impl_->SetViewportSize(viewport_size);
Expand All @@ -4674,9 +4684,12 @@ TEST_F(LayerTreeHostImplTest, ScrollWithoutBubbling) {
host_impl_->ProcessScrollDeltas();

// The grand child should have scrolled up to its limit.
LayerImpl* child =
host_impl_->active_tree()->root_layer()->children()[0]->children()
[0].get();
LayerImpl* child = host_impl_->active_tree()
->root_layer()
->children()[0]
->children()[0]
->children()[0]
.get();
LayerImpl* grand_child = child->children()[0].get();
EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), grand_child->id(),
gfx::Vector2d(0, -2)));
Expand Down Expand Up @@ -4749,25 +4762,28 @@ TEST_F(LayerTreeHostImplTest, ScrollEventBubbling) {
// should be applied to one of its ancestors if possible.
gfx::Size surface_size(10, 10);
gfx::Size content_size(20, 20);
scoped_ptr<LayerImpl> root_ptr =
LayerImpl::Create(host_impl_->active_tree(), 4);
scoped_ptr<LayerImpl> root_clip =
LayerImpl::Create(host_impl_->active_tree(), 3);
root_clip->SetForceRenderSurface(true);
scoped_ptr<LayerImpl> root =
scoped_ptr<LayerImpl> root_scroll =
CreateScrollableLayer(1, content_size, root_clip.get());
// Make 'root' the clip layer for child: since they have the same sizes the
// child will have zero max_scroll_offset and scrolls will bubble.
scoped_ptr<LayerImpl> child =
CreateScrollableLayer(2, content_size, root.get());
CreateScrollableLayer(2, content_size, root_scroll.get());
child->SetIsContainerForFixedPositionLayers(true);
root->SetBounds(content_size);
root_scroll->SetBounds(content_size);

int root_scroll_id = root->id();
root->AddChild(std::move(child));
root_clip->AddChild(std::move(root));
int root_scroll_id = root_scroll->id();
root_scroll->AddChild(std::move(child));
root_clip->AddChild(std::move(root_scroll));
root_ptr->AddChild(std::move(root_clip));

host_impl_->SetViewportSize(surface_size);
host_impl_->active_tree()->SetRootLayer(std::move(root_clip));
host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 3, 2,
host_impl_->active_tree()->SetRootLayer(std::move(root_ptr));
host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 4, 2,
Layer::INVALID_ID);
host_impl_->active_tree()->DidBecomeActive();
DrawFrame();
Expand All @@ -4790,15 +4806,18 @@ TEST_F(LayerTreeHostImplTest, ScrollEventBubbling) {

TEST_F(LayerTreeHostImplTest, ScrollBeforeRedraw) {
gfx::Size surface_size(10, 10);
scoped_ptr<LayerImpl> root_clip =
scoped_ptr<LayerImpl> root_ptr =
LayerImpl::Create(host_impl_->active_tree(), 1);
scoped_ptr<LayerImpl> root_clip =
LayerImpl::Create(host_impl_->active_tree(), 2);
scoped_ptr<LayerImpl> root_scroll =
CreateScrollableLayer(2, surface_size, root_clip.get());
CreateScrollableLayer(3, surface_size, root_clip.get());
root_scroll->SetIsContainerForFixedPositionLayers(true);
root_clip->SetForceRenderSurface(true);
root_clip->AddChild(std::move(root_scroll));
host_impl_->active_tree()->SetRootLayer(std::move(root_clip));
host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 2,
root_ptr->AddChild(std::move(root_clip));
host_impl_->active_tree()->SetRootLayer(std::move(root_ptr));
host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 3,
Layer::INVALID_ID);
host_impl_->active_tree()->DidBecomeActive();
host_impl_->SetViewportSize(surface_size);
Expand All @@ -4807,15 +4826,18 @@ TEST_F(LayerTreeHostImplTest, ScrollBeforeRedraw) {
// synchronization.
DrawFrame();
host_impl_->active_tree()->DetachLayerTree();
scoped_ptr<LayerImpl> root_ptr2 =
LayerImpl::Create(host_impl_->active_tree(), 4);
scoped_ptr<LayerImpl> root_clip2 =
LayerImpl::Create(host_impl_->active_tree(), 3);
LayerImpl::Create(host_impl_->active_tree(), 5);
scoped_ptr<LayerImpl> root_scroll2 =
CreateScrollableLayer(4, surface_size, root_clip2.get());
CreateScrollableLayer(6, surface_size, root_clip2.get());
root_scroll2->SetIsContainerForFixedPositionLayers(true);
root_clip2->AddChild(std::move(root_scroll2));
root_clip2->SetForceRenderSurface(true);
host_impl_->active_tree()->SetRootLayer(std::move(root_clip2));
host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 3, 4,
root_ptr2->AddChild(std::move(root_clip2));
host_impl_->active_tree()->SetRootLayer(std::move(root_ptr2));
host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 4, 6,
Layer::INVALID_ID);
host_impl_->active_tree()->DidBecomeActive();

Expand Down Expand Up @@ -5220,6 +5242,7 @@ TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) {
host_impl_->CreatePendingTree();
host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f);
CreateScrollAndContentsLayers(host_impl_->pending_tree(), new_size);
host_impl_->pending_tree()->BuildPropertyTreesForTesting();
host_impl_->ActivateSyncTree();
EXPECT_EQ(gfx::SizeF(new_size), scroll_watcher.scrollable_size());

Expand Down Expand Up @@ -7213,23 +7236,26 @@ TEST_F(LayerTreeHostImplTest, TouchFlingShouldNotBubble) {
// bubble).
gfx::Size surface_size(10, 10);
gfx::Size content_size(20, 20);
scoped_ptr<LayerImpl> root_ptr =
LayerImpl::Create(host_impl_->active_tree(), 4);
scoped_ptr<LayerImpl> root_clip =
LayerImpl::Create(host_impl_->active_tree(), 3);
root_clip->SetForceRenderSurface(true);

scoped_ptr<LayerImpl> root =
scoped_ptr<LayerImpl> root_scroll =
CreateScrollableLayer(1, content_size, root_clip.get());
root->SetIsContainerForFixedPositionLayers(true);
root_scroll->SetIsContainerForFixedPositionLayers(true);
scoped_ptr<LayerImpl> child =
CreateScrollableLayer(2, content_size, root_clip.get());

root->AddChild(std::move(child));
int root_id = root->id();
root_clip->AddChild(std::move(root));
root_scroll->AddChild(std::move(child));
int root_id = root_scroll->id();
root_clip->AddChild(std::move(root_scroll));
root_ptr->AddChild(std::move(root_clip));

host_impl_->SetViewportSize(surface_size);
host_impl_->active_tree()->SetRootLayer(std::move(root_clip));
host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 3, 1,
host_impl_->active_tree()->SetRootLayer(std::move(root_ptr));
host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 4, 1,
Layer::INVALID_ID);
host_impl_->active_tree()->DidBecomeActive();
DrawFrame();
Expand Down
16 changes: 11 additions & 5 deletions cc/trees/layer_tree_host_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5188,12 +5188,15 @@ class LayerTreeHostTestCrispUpAfterPinchEnds : public LayerTreeHostTest {

scoped_refptr<Layer> root = Layer::Create(layer_settings());
root->SetBounds(gfx::Size(500, 500));
scoped_refptr<Layer> clip = Layer::Create(layer_settings());
clip->SetBounds(gfx::Size(500, 500));

scoped_refptr<Layer> pinch = Layer::Create(layer_settings());
pinch->SetBounds(gfx::Size(500, 500));
pinch->SetScrollClipLayerId(root->id());
pinch->SetScrollClipLayerId(clip->id());
pinch->SetIsContainerForFixedPositionLayers(true);
root->AddChild(pinch);
clip->AddChild(pinch);
root->AddChild(clip);

scoped_ptr<FakeDisplayListRecordingSource> recording(
new FakeDisplayListRecordingSource);
Expand Down Expand Up @@ -5489,12 +5492,15 @@ class LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles

scoped_refptr<Layer> root = Layer::Create(layer_settings());
root->SetBounds(gfx::Size(500, 500));
scoped_refptr<Layer> clip = Layer::Create(layer_settings());
clip->SetBounds(gfx::Size(500, 500));

scoped_refptr<Layer> pinch = Layer::Create(layer_settings());
pinch->SetBounds(gfx::Size(500, 500));
pinch->SetScrollClipLayerId(root->id());
pinch->SetScrollClipLayerId(clip->id());
pinch->SetIsContainerForFixedPositionLayers(true);
root->AddChild(pinch);
clip->AddChild(pinch);
root->AddChild(clip);

scoped_ptr<FakeDisplayListRecordingSource> recording(
new FakeDisplayListRecordingSource);
Expand All @@ -5512,7 +5518,7 @@ class LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles
layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 1.f, 4.f);
layer_tree_host()->SetRootLayer(root);
LayerTreeHostTest::SetupTree();
client_.set_bounds(root->bounds());
client_.set_bounds(clip->bounds());
}

// Returns the delta scale of all quads in the frame's root pass from their
Expand Down
Loading

0 comments on commit 6766965

Please sign in to comment.