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

Side by Side Diff: cc/trees/layer_tree_host_impl_unittest.cc

Issue 1841783003: Update property trees' bounds delta before updating viewport container sizes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved UpdateViewportContainerSizes instead Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/layer_tree_host_impl.h" 5 #include "cc/trees/layer_tree_host_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 3761 matching lines...) Expand 10 before | Expand all | Expand 10 after
3772 } 3772 }
3773 return init; 3773 return init;
3774 } 3774 }
3775 3775
3776 void SetupTopControlsAndScrollLayerWithVirtualViewport( 3776 void SetupTopControlsAndScrollLayerWithVirtualViewport(
3777 const gfx::Size& inner_viewport_size, 3777 const gfx::Size& inner_viewport_size,
3778 const gfx::Size& outer_viewport_size, 3778 const gfx::Size& outer_viewport_size,
3779 const gfx::Size& scroll_layer_size) { 3779 const gfx::Size& scroll_layer_size) {
3780 settings_ = DefaultSettings(); 3780 settings_ = DefaultSettings();
3781 CreateHostImpl(settings_, CreateOutputSurface()); 3781 CreateHostImpl(settings_, CreateOutputSurface());
3782 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true); 3782 SetupTopControlsAndScrollLayerWithVirtualViewport(
3783 host_impl_->sync_tree()->set_top_controls_height(top_controls_height_); 3783 host_impl_->active_tree(), inner_viewport_size, outer_viewport_size,
3784 scroll_layer_size);
3785 }
3786
3787 void SetupTopControlsAndScrollLayerWithVirtualViewport(
3788 LayerTreeImpl* tree_impl,
3789 const gfx::Size& inner_viewport_size,
3790 const gfx::Size& outer_viewport_size,
3791 const gfx::Size& scroll_layer_size) {
3792 tree_impl->set_top_controls_shrink_blink_size(true);
3793 tree_impl->set_top_controls_height(top_controls_height_);
3794 tree_impl->SetCurrentTopControlsShownRatio(1.f);
3795 tree_impl->PushPageScaleFromMainThread(1.f, 1.f, 1.f);
3784 host_impl_->DidChangeTopControlsPosition(); 3796 host_impl_->DidChangeTopControlsPosition();
3785 3797
3786 scoped_ptr<LayerImpl> root = 3798 scoped_ptr<LayerImpl> root = LayerImpl::Create(tree_impl, 1);
3787 LayerImpl::Create(host_impl_->active_tree(), 1); 3799 scoped_ptr<LayerImpl> root_clip = LayerImpl::Create(tree_impl, 2);
3788 scoped_ptr<LayerImpl> root_clip = 3800 scoped_ptr<LayerImpl> page_scale = LayerImpl::Create(tree_impl, 3);
3789 LayerImpl::Create(host_impl_->active_tree(), 2);
3790 scoped_ptr<LayerImpl> page_scale =
3791 LayerImpl::Create(host_impl_->active_tree(), 3);
3792 3801
3793 scoped_ptr<LayerImpl> outer_scroll = 3802 scoped_ptr<LayerImpl> outer_scroll = LayerImpl::Create(tree_impl, 4);
3794 LayerImpl::Create(host_impl_->active_tree(), 4); 3803 scoped_ptr<LayerImpl> outer_clip = LayerImpl::Create(tree_impl, 5);
3795 scoped_ptr<LayerImpl> outer_clip =
3796 LayerImpl::Create(host_impl_->active_tree(), 5);
3797 3804
3798 root_clip->SetBounds(inner_viewport_size); 3805 root_clip->SetBounds(inner_viewport_size);
3799 root->SetScrollClipLayer(root_clip->id()); 3806 root->SetScrollClipLayer(root_clip->id());
3800 root->SetBounds(outer_viewport_size); 3807 root->SetBounds(outer_viewport_size);
3801 root->SetPosition(gfx::PointF()); 3808 root->SetPosition(gfx::PointF());
3802 root->SetDrawsContent(false); 3809 root->SetDrawsContent(false);
3803 root->SetIsContainerForFixedPositionLayers(true); 3810 root->SetIsContainerForFixedPositionLayers(true);
3804 root_clip->SetForceRenderSurface(true); 3811 root_clip->SetForceRenderSurface(true);
3805 outer_clip->SetBounds(outer_viewport_size); 3812 outer_clip->SetBounds(outer_viewport_size);
3806 outer_scroll->SetScrollClipLayer(outer_clip->id()); 3813 outer_scroll->SetScrollClipLayer(outer_clip->id());
3807 outer_scroll->SetBounds(scroll_layer_size); 3814 outer_scroll->SetBounds(scroll_layer_size);
3808 outer_scroll->SetPosition(gfx::PointF()); 3815 outer_scroll->SetPosition(gfx::PointF());
3809 outer_scroll->SetDrawsContent(false); 3816 outer_scroll->SetDrawsContent(false);
3810 outer_scroll->SetIsContainerForFixedPositionLayers(true); 3817 outer_scroll->SetIsContainerForFixedPositionLayers(true);
3811 3818
3812 int inner_viewport_scroll_layer_id = root->id(); 3819 int inner_viewport_scroll_layer_id = root->id();
3813 int outer_viewport_scroll_layer_id = outer_scroll->id(); 3820 int outer_viewport_scroll_layer_id = outer_scroll->id();
3814 int page_scale_layer_id = page_scale->id(); 3821 int page_scale_layer_id = page_scale->id();
3815 3822
3816 outer_clip->AddChild(std::move(outer_scroll)); 3823 outer_clip->AddChild(std::move(outer_scroll));
3817 root->AddChild(std::move(outer_clip)); 3824 root->AddChild(std::move(outer_clip));
3818 page_scale->AddChild(std::move(root)); 3825 page_scale->AddChild(std::move(root));
3819 root_clip->AddChild(std::move(page_scale)); 3826 root_clip->AddChild(std::move(page_scale));
3820 3827
3821 host_impl_->active_tree()->SetRootLayer(std::move(root_clip)); 3828 tree_impl->SetRootLayer(std::move(root_clip));
3822 host_impl_->active_tree()->SetViewportLayersFromIds( 3829 tree_impl->SetViewportLayersFromIds(Layer::INVALID_ID, page_scale_layer_id,
3823 Layer::INVALID_ID, page_scale_layer_id, inner_viewport_scroll_layer_id, 3830 inner_viewport_scroll_layer_id,
3824 outer_viewport_scroll_layer_id); 3831 outer_viewport_scroll_layer_id);
3825 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 3832 tree_impl->BuildPropertyTreesForTesting();
3826 3833
3827 host_impl_->SetViewportSize(inner_viewport_size); 3834 host_impl_->SetViewportSize(inner_viewport_size);
3828 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); 3835 LayerImpl* root_clip_ptr = tree_impl->root_layer();
3829 EXPECT_EQ(inner_viewport_size, root_clip_ptr->bounds()); 3836 EXPECT_EQ(inner_viewport_size, root_clip_ptr->bounds());
3830 } 3837 }
3831 3838
3832 protected: 3839 protected:
3833 gfx::Size layer_size_; 3840 gfx::Size layer_size_;
3834 gfx::Size clip_size_; 3841 gfx::Size clip_size_;
3835 gfx::Size viewport_size_; 3842 gfx::Size viewport_size_;
3836 float top_controls_height_; 3843 float top_controls_height_;
3837 3844
3838 LayerTreeSettings settings_; 3845 LayerTreeSettings settings_;
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
4511 gfx::ScrollOffset(), 4518 gfx::ScrollOffset(),
4512 host_impl_->active_tree()->InnerViewportScrollLayer()->MaxScrollOffset()); 4519 host_impl_->active_tree()->InnerViewportScrollLayer()->MaxScrollOffset());
4513 4520
4514 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 4521 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
4515 host_impl_ 4522 host_impl_
4516 ->ScrollBegin(BeginState(gfx::Point()).get(), 4523 ->ScrollBegin(BeginState(gfx::Point()).get(),
4517 InputHandler::TOUCHSCREEN) 4524 InputHandler::TOUCHSCREEN)
4518 .thread); 4525 .thread);
4519 } 4526 }
4520 4527
4528 // Tests that activating a pending tree while there's a bounds_delta on the
4529 // viewport layers from top controls doesn't cause a scroll jump. This bug was
4530 // occurring because the UpdateViewportContainerSizes was being called before
4531 // the property trees were updated with the bounds_delta. crbug.com/597266.
4532 TEST_F(LayerTreeHostImplTopControlsTest, ViewportBoundsDeltaOnTreeActivation) {
4533 const gfx::Size inner_viewport_size(500, 500);
4534 const gfx::Size outer_viewport_size(1000, 1000);
4535 const gfx::Size content_size(2000, 2000);
4536
4537 SetupTopControlsAndScrollLayerWithVirtualViewport(
4538 inner_viewport_size, outer_viewport_size, content_size);
4539 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.25f, 4.f);
4540
4541 host_impl_->CreatePendingTree();
4542 SetupTopControlsAndScrollLayerWithVirtualViewport(
4543 host_impl_->pending_tree(), inner_viewport_size, outer_viewport_size,
4544 content_size);
4545
4546 // Zoom in to 2X.
4547 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(),
4548 InputHandler::TOUCHSCREEN);
4549 host_impl_->PinchGestureBegin();
4550 host_impl_->PinchGestureUpdate(2.f, gfx::Point());
4551 host_impl_->PinchGestureEnd();
4552 host_impl_->ScrollEnd(EndState().get());
4553
4554 ASSERT_EQ(2.0f, host_impl_->active_tree()->current_page_scale_factor());
4555
4556 // All scroll types outside this region should succeed.
4557 host_impl_->ScrollBegin(BeginState(gfx::Point(75, 75)).get(),
4558 InputHandler::TOUCHSCREEN);
4559 // Fully scroll the viewports.
4560 host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 2000)).get());
4561 host_impl_->ScrollEnd(EndState().get());
4562
4563 LayerImpl* inner_scroll =
4564 host_impl_->active_tree()->InnerViewportScrollLayer();
4565 LayerImpl* outer_scroll =
4566 host_impl_->active_tree()->OuterViewportScrollLayer();
4567
4568 EXPECT_FLOAT_EQ(0, host_impl_->top_controls_manager()->ContentTopOffset());
4569
4570 EXPECT_EQ(925, inner_scroll->MaxScrollOffset().y());
4571 EXPECT_EQ(800, outer_scroll->MaxScrollOffset().y());
4572
4573 // Activate the pending tree which should have all the same values as the
4574 // active tree.
4575 host_impl_->pending_tree()->SetCurrentTopControlsShownRatio(0);
4576 host_impl_->pending_tree()->PushPageScaleFromMainThread(2.f, 0.25f, 4.f);
4577 host_impl_->pending_tree()
4578 ->property_trees()
4579 ->scroll_tree.SetScrollOffsetDeltaForTesting(inner_scroll->id(),
4580 gfx::Vector2dF(0, 925));
4581 host_impl_->pending_tree()
4582 ->property_trees()
4583 ->scroll_tree.SetScrollOffsetDeltaForTesting(outer_scroll->id(),
4584 gfx::Vector2dF(0, 800));
4585 host_impl_->ActivateSyncTree();
4586
4587 inner_scroll = host_impl_->active_tree()->InnerViewportScrollLayer();
4588 outer_scroll = host_impl_->active_tree()->OuterViewportScrollLayer();
4589
4590 // The test should pass if the scroll offets remain as they are. We fail if
4591 // the offets get clamped due to MaxScrollOffset not having the proper
4592 // bounds_delta set when UpdateViewportContainerSizes is called.
4593 EXPECT_EQ(925, inner_scroll->CurrentScrollOffset().y());
4594 EXPECT_EQ(800, outer_scroll->CurrentScrollOffset().y());
4595 }
4596
4521 TEST_F(LayerTreeHostImplTest, ScrollNonCompositedRoot) { 4597 TEST_F(LayerTreeHostImplTest, ScrollNonCompositedRoot) {
4522 // Test the configuration where a non-composited root layer is embedded in a 4598 // Test the configuration where a non-composited root layer is embedded in a
4523 // scrollable outer layer. 4599 // scrollable outer layer.
4524 gfx::Size surface_size(10, 10); 4600 gfx::Size surface_size(10, 10);
4525 gfx::Size contents_size(20, 20); 4601 gfx::Size contents_size(20, 20);
4526 4602
4527 scoped_ptr<LayerImpl> content_layer = 4603 scoped_ptr<LayerImpl> content_layer =
4528 LayerImpl::Create(host_impl_->active_tree(), 1); 4604 LayerImpl::Create(host_impl_->active_tree(), 1);
4529 content_layer->SetDrawsContent(true); 4605 content_layer->SetDrawsContent(true);
4530 content_layer->SetPosition(gfx::PointF()); 4606 content_layer->SetPosition(gfx::PointF());
(...skipping 5848 matching lines...) Expand 10 before | Expand all | Expand 10 after
10379 // There should not be any jitter measured till we hit the fixed point hits 10455 // There should not be any jitter measured till we hit the fixed point hits
10380 // threshold. 10456 // threshold.
10381 float expected_jitter = 10457 float expected_jitter =
10382 (i == pending_tree->kFixedPointHitsThreshold) ? 500 : 0; 10458 (i == pending_tree->kFixedPointHitsThreshold) ? 500 : 0;
10383 EXPECT_EQ(jitter, expected_jitter); 10459 EXPECT_EQ(jitter, expected_jitter);
10384 } 10460 }
10385 } 10461 }
10386 10462
10387 } // namespace 10463 } // namespace
10388 } // namespace cc 10464 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698