diff options
Diffstat (limited to 'chromium/cc/trees/layer_tree_host_unittest_scroll.cc')
-rw-r--r-- | chromium/cc/trees/layer_tree_host_unittest_scroll.cc | 364 |
1 files changed, 240 insertions, 124 deletions
diff --git a/chromium/cc/trees/layer_tree_host_unittest_scroll.cc b/chromium/cc/trees/layer_tree_host_unittest_scroll.cc index 38711545636..05a58764018 100644 --- a/chromium/cc/trees/layer_tree_host_unittest_scroll.cc +++ b/chromium/cc/trees/layer_tree_host_unittest_scroll.cc @@ -12,6 +12,7 @@ #include "cc/test/fake_layer_tree_host_client.h" #include "cc/test/geometry_test_utils.h" #include "cc/test/layer_tree_test.h" +#include "cc/test/test_shared_bitmap_manager.h" #include "cc/trees/layer_tree_impl.h" #include "ui/gfx/point_conversions.h" #include "ui/gfx/size_conversions.h" @@ -31,48 +32,59 @@ class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest { num_scrolls_(0) {} virtual void BeginTest() OVERRIDE { - layer_tree_host()->root_layer()->SetScrollable(true); - layer_tree_host()->root_layer() - ->SetMaxScrollOffset(gfx::Vector2d(100, 100)); - layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_); + Layer* root_layer = layer_tree_host()->root_layer(); + scoped_refptr<Layer> scroll_layer = Layer::Create(); + root_layer->AddChild(scroll_layer); + // Create an effective max_scroll_offset of (100, 100). + scroll_layer->SetBounds(gfx::Size(root_layer->bounds().width() + 100, + root_layer->bounds().height() + 100)); + scroll_layer->SetIsDrawable(true); + scroll_layer->SetIsContainerForFixedPositionLayers(true); + scroll_layer->SetScrollClipLayerId(root_layer->id()); + scroll_layer->SetScrollOffset(initial_scroll_); + layer_tree_host()->RegisterViewportLayers(root_layer, scroll_layer, NULL); PostSetNeedsCommitToMainThread(); } virtual void Layout() OVERRIDE { Layer* root = layer_tree_host()->root_layer(); + Layer* scroll_layer = root->children()[0]; if (!layer_tree_host()->source_frame_number()) { - EXPECT_VECTOR_EQ(initial_scroll_, root->scroll_offset()); + EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset()); } else { - EXPECT_VECTOR_EQ(initial_scroll_ + scroll_amount_, root->scroll_offset()); + EXPECT_VECTOR_EQ(initial_scroll_ + scroll_amount_, + scroll_layer->scroll_offset()); // Pretend like Javascript updated the scroll position itself. - root->SetScrollOffset(second_scroll_); + scroll_layer->SetScrollOffset(second_scroll_); } } virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { LayerImpl* root = impl->active_tree()->root_layer(); - EXPECT_VECTOR_EQ(gfx::Vector2d(), root->ScrollDelta()); + LayerImpl* scroll_layer = root->children()[0]; + EXPECT_VECTOR_EQ(gfx::Vector2d(), scroll_layer->ScrollDelta()); - root->SetScrollable(true); - root->SetMaxScrollOffset(gfx::Vector2d(100, 100)); - root->ScrollBy(scroll_amount_); + scroll_layer->SetScrollClipLayer(root->id()); + scroll_layer->SetBounds( + gfx::Size(root->bounds().width() + 100, root->bounds().height() + 100)); + scroll_layer->ScrollBy(scroll_amount_); switch (impl->active_tree()->source_frame_number()) { case 0: - EXPECT_VECTOR_EQ(initial_scroll_, root->scroll_offset()); - EXPECT_VECTOR_EQ(scroll_amount_, root->ScrollDelta()); + EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset()); + EXPECT_VECTOR_EQ(scroll_amount_, scroll_layer->ScrollDelta()); PostSetNeedsCommitToMainThread(); break; case 1: - EXPECT_VECTOR_EQ(root->scroll_offset(), second_scroll_); - EXPECT_VECTOR_EQ(root->ScrollDelta(), scroll_amount_); + EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), second_scroll_); + EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), scroll_amount_); EndTest(); break; } } - virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, + virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta, float scale) OVERRIDE { num_scrolls_++; } @@ -95,61 +107,68 @@ class LayerTreeHostScrollTestScrollMultipleRedraw : initial_scroll_(40, 10), scroll_amount_(-3, 17), num_scrolls_(0) {} virtual void BeginTest() OVERRIDE { - layer_tree_host()->root_layer()->SetScrollable(true); - layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_); - layer_tree_host()->root_layer()->SetBounds(gfx::Size(200, 200)); - layer_tree_host()->root_layer() - ->SetMaxScrollOffset(gfx::Vector2d(100, 100)); + Layer* root_layer = layer_tree_host()->root_layer(); + scroll_layer_ = Layer::Create(); + root_layer->AddChild(scroll_layer_); + // Create an effective max_scroll_offset of (100, 100). + scroll_layer_->SetBounds(gfx::Size(root_layer->bounds().width() + 100, + root_layer->bounds().height() + 100)); + scroll_layer_->SetIsDrawable(true); + scroll_layer_->SetIsContainerForFixedPositionLayers(true); + scroll_layer_->SetScrollClipLayerId(root_layer->id()); + scroll_layer_->SetScrollOffset(initial_scroll_); + layer_tree_host()->RegisterViewportLayers(root_layer, scroll_layer_, NULL); PostSetNeedsCommitToMainThread(); } virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE { - Layer* root = layer_tree_host()->root_layer(); switch (layer_tree_host()->source_frame_number()) { case 0: - EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); + EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), initial_scroll_); break; case 1: - EXPECT_VECTOR_EQ(root->scroll_offset(), + EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), initial_scroll_ + scroll_amount_ + scroll_amount_); case 2: - EXPECT_VECTOR_EQ(root->scroll_offset(), + EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), initial_scroll_ + scroll_amount_ + scroll_amount_); break; } } virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { - LayerImpl* root = impl->active_tree()->root_layer(); + LayerImpl* scroll_layer = + impl->active_tree()->LayerById(scroll_layer_->id()); if (impl->active_tree()->source_frame_number() == 0 && impl->SourceAnimationFrameNumber() == 1) { // First draw after first commit. - EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); - root->ScrollBy(scroll_amount_); - EXPECT_VECTOR_EQ(root->ScrollDelta(), scroll_amount_); + EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d()); + scroll_layer->ScrollBy(scroll_amount_); + EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), scroll_amount_); - EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); + EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); PostSetNeedsRedrawToMainThread(); } else if (impl->active_tree()->source_frame_number() == 0 && impl->SourceAnimationFrameNumber() == 2) { // Second draw after first commit. - EXPECT_EQ(root->ScrollDelta(), scroll_amount_); - root->ScrollBy(scroll_amount_); - EXPECT_VECTOR_EQ(root->ScrollDelta(), scroll_amount_ + scroll_amount_); + EXPECT_EQ(scroll_layer->ScrollDelta(), scroll_amount_); + scroll_layer->ScrollBy(scroll_amount_); + EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), + scroll_amount_ + scroll_amount_); - EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); + EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), initial_scroll_); PostSetNeedsCommitToMainThread(); } else if (impl->active_tree()->source_frame_number() == 1) { // Third or later draw after second commit. EXPECT_GE(impl->SourceAnimationFrameNumber(), 3); - EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); - EXPECT_VECTOR_EQ(root->scroll_offset(), + EXPECT_VECTOR_EQ(scroll_layer_->ScrollDelta(), gfx::Vector2d()); + EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), initial_scroll_ + scroll_amount_ + scroll_amount_); EndTest(); } } - virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, + virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta, float scale) OVERRIDE { num_scrolls_++; } @@ -160,6 +179,7 @@ class LayerTreeHostScrollTestScrollMultipleRedraw gfx::Vector2d initial_scroll_; gfx::Vector2d scroll_amount_; int num_scrolls_; + scoped_refptr<Layer> scroll_layer_; }; MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollMultipleRedraw); @@ -183,14 +203,17 @@ class LayerTreeHostScrollTestScrollAbortedCommit virtual void SetupTree() OVERRIDE { LayerTreeHostScrollTest::SetupTree(); + Layer* root_layer = layer_tree_host()->root_layer(); scoped_refptr<Layer> root_scroll_layer = Layer::Create(); - root_scroll_layer->SetScrollable(true); + root_scroll_layer->SetScrollClipLayerId(root_layer->id()); root_scroll_layer->SetScrollOffset(initial_scroll_); root_scroll_layer->SetBounds(gfx::Size(200, 200)); - root_scroll_layer->SetMaxScrollOffset(gfx::Vector2d(100, 100)); root_scroll_layer->SetIsDrawable(true); - layer_tree_host()->root_layer()->AddChild(root_scroll_layer); + root_scroll_layer->SetIsContainerForFixedPositionLayers(true); + root_layer->AddChild(root_scroll_layer); + layer_tree_host()->RegisterViewportLayers( + root_layer, root_scroll_layer, NULL); layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); } @@ -218,7 +241,8 @@ class LayerTreeHostScrollTestScrollAbortedCommit case 3: // This commit will not be aborted because of the scroll change. EXPECT_EQ(2, num_impl_scrolls_); - EXPECT_EQ(1, layer_tree_host()->source_frame_number()); + // The source frame number still increases even with the abort. + EXPECT_EQ(2, layer_tree_host()->source_frame_number()); EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), initial_scroll_ + impl_scroll_ + impl_scroll_); EXPECT_EQ(impl_scale_ * impl_scale_, @@ -229,7 +253,7 @@ class LayerTreeHostScrollTestScrollAbortedCommit case 4: // This commit will also be aborted. EXPECT_EQ(3, num_impl_scrolls_); - EXPECT_EQ(2, layer_tree_host()->source_frame_number()); + EXPECT_EQ(3, layer_tree_host()->source_frame_number()); EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), initial_scroll_ + impl_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_); @@ -288,7 +312,10 @@ class LayerTreeHostScrollTestScrollAbortedCommit impl->active_tree()->total_page_scale_factor()); impl->SetNeedsCommit(); - } else if (impl->active_tree()->source_frame_number() == 1 && + } else if (impl->active_tree()->source_frame_number() == 1) { + // Commit for source frame 1 is aborted. + NOTREACHED(); + } else if (impl->active_tree()->source_frame_number() == 2 && impl->SourceAnimationFrameNumber() == 3) { // Third draw after the second full commit. EXPECT_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d()); @@ -298,7 +325,7 @@ class LayerTreeHostScrollTestScrollAbortedCommit EXPECT_VECTOR_EQ( root_scroll_layer->scroll_offset(), initial_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_); - } else if (impl->active_tree()->source_frame_number() == 1 && + } else if (impl->active_tree()->source_frame_number() == 2 && impl->SourceAnimationFrameNumber() == 4) { // Final draw after the second aborted commit. EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d()); @@ -306,10 +333,13 @@ class LayerTreeHostScrollTestScrollAbortedCommit initial_scroll_ + impl_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_); EndTest(); + } else { + // Commit for source frame 3 is aborted. + NOTREACHED(); } } - virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, + virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta, float scale) OVERRIDE { num_impl_scrolls_++; } @@ -344,42 +374,57 @@ class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest { public: LayerTreeHostScrollTestFractionalScroll() : scroll_amount_(1.75, 0) {} + virtual void SetupTree() OVERRIDE { + LayerTreeHostScrollTest::SetupTree(); + Layer* root_layer = layer_tree_host()->root_layer(); + scoped_refptr<Layer> root_scroll_layer = Layer::Create(); + root_scroll_layer->SetScrollClipLayerId(root_layer->id()); + root_scroll_layer->SetBounds( + gfx::Size(root_layer->bounds().width() + 100, + root_layer->bounds().height() + 100)); + root_scroll_layer->SetIsDrawable(true); + root_scroll_layer->SetIsContainerForFixedPositionLayers(true); + root_layer->AddChild(root_scroll_layer); + + layer_tree_host()->RegisterViewportLayers( + root_layer, root_scroll_layer, NULL); + layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); + } + virtual void BeginTest() OVERRIDE { - layer_tree_host()->root_layer()->SetScrollable(true); - layer_tree_host()->root_layer() - ->SetMaxScrollOffset(gfx::Vector2d(100, 100)); PostSetNeedsCommitToMainThread(); } virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { LayerImpl* root = impl->active_tree()->root_layer(); + LayerImpl* scroll_layer = root->children()[0]; // Check that a fractional scroll delta is correctly accumulated over // multiple commits. switch (impl->active_tree()->source_frame_number()) { case 0: - EXPECT_VECTOR_EQ(root->scroll_offset(), gfx::Vector2d(0, 0)); - EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d(0, 0)); + EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), gfx::Vector2d(0, 0)); + EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d(0, 0)); PostSetNeedsCommitToMainThread(); break; case 1: - EXPECT_VECTOR_EQ(root->scroll_offset(), + EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), gfx::ToFlooredVector2d(scroll_amount_)); - EXPECT_VECTOR_EQ(root->ScrollDelta(), + EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2dF(fmod(scroll_amount_.x(), 1.0f), 0.0f)); PostSetNeedsCommitToMainThread(); break; case 2: EXPECT_VECTOR_EQ( - root->scroll_offset(), + scroll_layer->scroll_offset(), gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_)); EXPECT_VECTOR_EQ( - root->ScrollDelta(), + scroll_layer->ScrollDelta(), gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f)); EndTest(); break; } - root->ScrollBy(scroll_amount_); + scroll_layer->ScrollBy(scroll_amount_); } virtual void AfterTest() OVERRIDE {} @@ -408,11 +453,10 @@ class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest { root_scroll_layer_->SetBounds(gfx::Size(110, 110)); root_scroll_layer_->SetPosition(gfx::Point()); - root_scroll_layer_->SetAnchorPoint(gfx::PointF()); root_scroll_layer_->SetIsDrawable(true); - root_scroll_layer_->SetScrollable(true); - root_scroll_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100)); + root_scroll_layer_->SetScrollClipLayerId(root_layer->id()); + root_scroll_layer_->SetIsContainerForFixedPositionLayers(true); root_layer->AddChild(root_scroll_layer_); child_layer_ = ContentLayer::Create(&fake_content_layer_client_); @@ -430,11 +474,10 @@ class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest { // Adjust the child layer horizontally so that scrolls will never hit it. child_layer_->SetPosition(gfx::Point(60, 5)); } - child_layer_->SetAnchorPoint(gfx::PointF()); child_layer_->SetIsDrawable(true); - child_layer_->SetScrollable(true); - child_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100)); + child_layer_->SetScrollClipLayerId(root_layer->id()); + child_layer_->SetBounds(root_scroll_layer_->bounds()); root_scroll_layer_->AddChild(child_layer_); if (scroll_child_layer_) { @@ -448,6 +491,8 @@ class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest { expected_scroll_layer_->SetScrollOffset(initial_offset_); layer_tree_host()->SetRootLayer(root_layer); + layer_tree_host()->RegisterViewportLayers( + root_layer, root_scroll_layer_, NULL); LayerTreeHostScrollTest::SetupTree(); } @@ -465,7 +510,7 @@ class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest { final_scroll_offset_ = expected_scroll_layer_->scroll_offset(); } - virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, + virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta, float scale) OVERRIDE { num_scrolls_++; } @@ -724,26 +769,41 @@ class ImplSidePaintingScrollTestSimple : public ImplSidePaintingScrollTest { impl_thread_scroll2_(-3, 10), num_scrolls_(0) {} + virtual void SetupTree() OVERRIDE { + LayerTreeHostScrollTest::SetupTree(); + Layer* root_layer = layer_tree_host()->root_layer(); + scoped_refptr<Layer> root_scroll_layer = Layer::Create(); + root_scroll_layer->SetScrollClipLayerId(root_layer->id()); + root_scroll_layer->SetScrollOffset(initial_scroll_); + root_scroll_layer->SetBounds( + gfx::Size(root_layer->bounds().width() + 100, + root_layer->bounds().height() + 100)); + root_scroll_layer->SetIsDrawable(true); + root_scroll_layer->SetIsContainerForFixedPositionLayers(true); + root_layer->AddChild(root_scroll_layer); + + layer_tree_host()->RegisterViewportLayers( + root_layer, root_scroll_layer, NULL); + layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); + } + virtual void BeginTest() OVERRIDE { - layer_tree_host()->root_layer()->SetScrollable(true); - layer_tree_host()->root_layer() - ->SetMaxScrollOffset(gfx::Vector2d(100, 100)); - layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_); PostSetNeedsCommitToMainThread(); } virtual void Layout() OVERRIDE { Layer* root = layer_tree_host()->root_layer(); + Layer* scroll_layer = root->children()[0]; if (!layer_tree_host()->source_frame_number()) { - EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); + EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); } else { - EXPECT_VECTOR_EQ(root->scroll_offset(), + EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_ + impl_thread_scroll1_); // Pretend like Javascript updated the scroll position itself with a // change of main_thread_scroll. - root->SetScrollOffset(initial_scroll_ + main_thread_scroll_ + - impl_thread_scroll1_); + scroll_layer->SetScrollOffset(initial_scroll_ + main_thread_scroll_ + + impl_thread_scroll1_); } } @@ -758,6 +818,7 @@ class ImplSidePaintingScrollTestSimple : public ImplSidePaintingScrollTest { ImplSidePaintingScrollTest::DrawLayersOnThread(impl); LayerImpl* root = impl->active_tree()->root_layer(); + LayerImpl* scroll_layer = root->children()[0]; LayerImpl* pending_root = impl->active_tree()->FindPendingTreeLayerById(root->id()); @@ -765,12 +826,12 @@ class ImplSidePaintingScrollTestSimple : public ImplSidePaintingScrollTest { case 0: if (!impl->pending_tree()) { impl->BlockNotifyReadyToActivateForTesting(true); - EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); - root->ScrollBy(impl_thread_scroll1_); + EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d()); + scroll_layer->ScrollBy(impl_thread_scroll1_); - EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); - EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll1_); - EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); + EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); + EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll1_); + EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); PostSetNeedsCommitToMainThread(); // CommitCompleteOnThread will trigger this function again @@ -780,32 +841,36 @@ class ImplSidePaintingScrollTestSimple : public ImplSidePaintingScrollTest { ASSERT_TRUE(pending_root); EXPECT_EQ(impl->pending_tree()->source_frame_number(), 1); - root->ScrollBy(impl_thread_scroll2_); - EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); - EXPECT_VECTOR_EQ(root->ScrollDelta(), + scroll_layer->ScrollBy(impl_thread_scroll2_); + EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); + EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll1_ + impl_thread_scroll2_); - EXPECT_VECTOR_EQ(root->sent_scroll_delta(), impl_thread_scroll1_); + EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), + impl_thread_scroll1_); + LayerImpl* pending_scroll_layer = pending_root->children()[0]; EXPECT_VECTOR_EQ( - pending_root->scroll_offset(), + pending_scroll_layer->scroll_offset(), initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); - EXPECT_VECTOR_EQ(pending_root->ScrollDelta(), impl_thread_scroll2_); - EXPECT_VECTOR_EQ(pending_root->sent_scroll_delta(), gfx::Vector2d()); + EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), + impl_thread_scroll2_); + EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(), + gfx::Vector2d()); } break; case 1: EXPECT_FALSE(impl->pending_tree()); EXPECT_VECTOR_EQ( - root->scroll_offset(), + scroll_layer->scroll_offset(), initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); - EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll2_); - EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); + EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll2_); + EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); EndTest(); break; } } - virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, + virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta, float scale) OVERRIDE { num_scrolls_++; } @@ -832,25 +897,40 @@ class ImplSidePaintingScrollTestImplOnlyScroll ImplSidePaintingScrollTestImplOnlyScroll() : initial_scroll_(20, 10), impl_thread_scroll_(-2, 3) {} + virtual void SetupTree() OVERRIDE { + LayerTreeHostScrollTest::SetupTree(); + Layer* root_layer = layer_tree_host()->root_layer(); + scoped_refptr<Layer> root_scroll_layer = Layer::Create(); + root_scroll_layer->SetScrollClipLayerId(root_layer->id()); + root_scroll_layer->SetScrollOffset(initial_scroll_); + root_scroll_layer->SetBounds( + gfx::Size(root_layer->bounds().width() + 100, + root_layer->bounds().height() + 100)); + root_scroll_layer->SetIsDrawable(true); + root_scroll_layer->SetIsContainerForFixedPositionLayers(true); + root_layer->AddChild(root_scroll_layer); + + layer_tree_host()->RegisterViewportLayers( + root_layer, root_scroll_layer, NULL); + layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); + } + virtual void BeginTest() OVERRIDE { - layer_tree_host()->root_layer()->SetScrollable(true); - layer_tree_host()->root_layer()->SetMaxScrollOffset( - gfx::Vector2d(100, 100)); - layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_); PostSetNeedsCommitToMainThread(); } virtual void WillCommit() OVERRIDE { Layer* root = layer_tree_host()->root_layer(); + Layer* scroll_layer = root->children()[0]; switch (layer_tree_host()->source_frame_number()) { case 0: - EXPECT_TRUE(root->needs_push_properties()); + EXPECT_TRUE(scroll_layer->needs_push_properties()); break; case 1: // Even if this layer doesn't need push properties, it should // still pick up scrolls that happen on the active layer during // commit. - EXPECT_FALSE(root->needs_push_properties()); + EXPECT_FALSE(scroll_layer->needs_push_properties()); break; } } @@ -859,8 +939,10 @@ class ImplSidePaintingScrollTestImplOnlyScroll // Scroll after the 2nd commit has started. if (impl->active_tree()->source_frame_number() == 0) { LayerImpl* active_root = impl->active_tree()->root_layer(); + LayerImpl* active_scroll_layer = active_root->children()[0]; ASSERT_TRUE(active_root); - active_root->ScrollBy(impl_thread_scroll_); + ASSERT_TRUE(active_scroll_layer); + active_scroll_layer->ScrollBy(impl_thread_scroll_); } } @@ -868,33 +950,45 @@ class ImplSidePaintingScrollTestImplOnlyScroll // We force a second draw here of the first commit before activating // the second commit. LayerImpl* active_root = impl->active_tree()->root_layer(); + LayerImpl* active_scroll_layer = + active_root ? active_root->children()[0] : NULL; LayerImpl* pending_root = impl->pending_tree()->root_layer(); + LayerImpl* pending_scroll_layer = pending_root->children()[0]; ASSERT_TRUE(pending_root); + ASSERT_TRUE(pending_scroll_layer); switch (impl->pending_tree()->source_frame_number()) { case 0: - EXPECT_VECTOR_EQ(pending_root->scroll_offset(), initial_scroll_); - EXPECT_VECTOR_EQ(pending_root->ScrollDelta(), gfx::Vector2d()); - EXPECT_VECTOR_EQ(pending_root->sent_scroll_delta(), gfx::Vector2d()); + EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(), + initial_scroll_); + EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), gfx::Vector2d()); + EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(), + gfx::Vector2d()); EXPECT_FALSE(active_root); break; case 1: // Even though the scroll happened during the commit, both layers // should have the appropriate scroll delta. - EXPECT_VECTOR_EQ(pending_root->scroll_offset(), initial_scroll_); - EXPECT_VECTOR_EQ(pending_root->ScrollDelta(), impl_thread_scroll_); - EXPECT_VECTOR_EQ(pending_root->sent_scroll_delta(), gfx::Vector2d()); + EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(), + initial_scroll_); + EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), + impl_thread_scroll_); + EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(), + gfx::Vector2d()); ASSERT_TRUE(active_root); - EXPECT_VECTOR_EQ(active_root->scroll_offset(), initial_scroll_); - EXPECT_VECTOR_EQ(active_root->ScrollDelta(), impl_thread_scroll_); - EXPECT_VECTOR_EQ(active_root->sent_scroll_delta(), gfx::Vector2d()); + EXPECT_VECTOR_EQ(active_scroll_layer->scroll_offset(), initial_scroll_); + EXPECT_VECTOR_EQ(active_scroll_layer->ScrollDelta(), + impl_thread_scroll_); + EXPECT_VECTOR_EQ(active_scroll_layer->sent_scroll_delta(), + gfx::Vector2d()); break; case 2: // On the next commit, this delta should have been sent and applied. - EXPECT_VECTOR_EQ(pending_root->scroll_offset(), + EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(), initial_scroll_ + impl_thread_scroll_); - EXPECT_VECTOR_EQ(pending_root->ScrollDelta(), gfx::Vector2d()); - EXPECT_VECTOR_EQ(pending_root->sent_scroll_delta(), gfx::Vector2d()); + EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), gfx::Vector2d()); + EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(), + gfx::Vector2d()); EndTest(); break; } @@ -904,18 +998,19 @@ class ImplSidePaintingScrollTestImplOnlyScroll ImplSidePaintingScrollTest::DrawLayersOnThread(impl); LayerImpl* root = impl->active_tree()->root_layer(); + LayerImpl* scroll_layer = root->children()[0]; switch (impl->active_tree()->source_frame_number()) { case 0: - EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); - EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); - EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); + EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); + EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d()); + EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); PostSetNeedsCommitToMainThread(); break; case 1: - EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); - EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll_); - EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); + EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); + EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll_); + EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); PostSetNeedsCommitToMainThread(); break; } @@ -935,23 +1030,37 @@ class LayerTreeHostScrollTestScrollZeroMaxScrollOffset public: LayerTreeHostScrollTestScrollZeroMaxScrollOffset() {} + virtual void SetupTree() OVERRIDE { + LayerTreeTest::SetupTree(); + scoped_refptr<Layer> scroll_layer = Layer::Create(); + layer_tree_host()->root_layer()->AddChild(scroll_layer); + } + virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { LayerImpl* root = impl->active_tree()->root_layer(); - root->SetScrollable(true); + LayerImpl* scroll_layer = root->children()[0]; + scroll_layer->SetScrollClipLayer(root->id()); - root->SetMaxScrollOffset(gfx::Vector2d(100, 100)); + // Set max_scroll_offset = (100, 100). + scroll_layer->SetBounds( + gfx::Size(root->bounds().width() + 100, root->bounds().height() + 100)); EXPECT_EQ(InputHandler::ScrollStarted, - root->TryScroll(gfx::PointF(0.0f, 1.0f), InputHandler::Gesture)); + scroll_layer->TryScroll(gfx::PointF(0.0f, 1.0f), + InputHandler::Gesture)); - root->SetMaxScrollOffset(gfx::Vector2d(0, 0)); + // Set max_scroll_offset = (0, 0). + scroll_layer->SetBounds(root->bounds()); EXPECT_EQ(InputHandler::ScrollIgnored, - root->TryScroll(gfx::PointF(0.0f, 1.0f), InputHandler::Gesture)); + scroll_layer->TryScroll(gfx::PointF(0.0f, 1.0f), + InputHandler::Gesture)); - root->SetMaxScrollOffset(gfx::Vector2d(-100, -100)); + // Set max_scroll_offset = (-100, -100). + scroll_layer->SetBounds(gfx::Size()); EXPECT_EQ(InputHandler::ScrollIgnored, - root->TryScroll(gfx::PointF(0.0f, 1.0f), InputHandler::Gesture)); + scroll_layer->TryScroll(gfx::PointF(0.0f, 1.0f), + InputHandler::Gesture)); EndTest(); } @@ -984,7 +1093,9 @@ class ThreadCheckingInputHandlerClient : public InputHandlerClient { *received_stop_flinging_ = true; } - virtual void DidOverscroll(const DidOverscrollParams& params) OVERRIDE { + virtual void DidOverscroll(const gfx::Vector2dF& accumulated_overscroll, + const gfx::Vector2dF& latest_overscroll_delta) + OVERRIDE { if (!task_runner_->BelongsToCurrentThread()) ADD_FAILURE() << "DidOverscroll called on wrong thread"; } @@ -1012,8 +1123,13 @@ TEST(LayerTreeHostFlingTest, DidStopFlingingThread) { FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); ASSERT_TRUE(impl_thread.message_loop_proxy().get()); - scoped_ptr<LayerTreeHost> layer_tree_host = LayerTreeHost::CreateThreaded( - &client, NULL, settings, impl_thread.message_loop_proxy()); + scoped_ptr<SharedBitmapManager> shared_bitmap_manager( + new TestSharedBitmapManager()); + scoped_ptr<LayerTreeHost> layer_tree_host = + LayerTreeHost::CreateThreaded(&client, + shared_bitmap_manager.get(), + settings, + impl_thread.message_loop_proxy()); impl_thread.message_loop_proxy() ->PostTask(FROM_HERE, @@ -1091,10 +1207,10 @@ class LayerTreeHostScrollTestLayerStructureChange ContentLayer::Create(&fake_content_layer_client_); scroll_layer->SetBounds(gfx::Size(110, 110)); scroll_layer->SetPosition(gfx::Point(0, 0)); - scroll_layer->SetAnchorPoint(gfx::PointF()); scroll_layer->SetIsDrawable(true); - scroll_layer->SetScrollable(true); - scroll_layer->SetMaxScrollOffset(gfx::Vector2d(100, 100)); + scroll_layer->SetScrollClipLayerId(parent->id()); + scroll_layer->SetBounds(gfx::Size(parent->bounds().width() + 100, + parent->bounds().height() + 100)); scroll_layer->set_did_scroll_callback(base::Bind( &FakeLayerScrollClient::DidScroll, base::Unretained(client))); client->owner_ = this; |