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

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

Issue 800613009: Convert scroll offsets to use SyncedProperty. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Android WebView tests Created 5 years, 10 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') | cc/trees/layer_tree_host_unittest_animation.cc » ('j') | 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 <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 root_layer->SetScrollOffset(scroll_offset); 476 root_layer->SetScrollOffset(scroll_offset);
477 root_layer->ScrollBy(scroll_delta); 477 root_layer->ScrollBy(scroll_delta);
478 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); 478 host_impl_->active_tree()->SetRootLayer(root_clip.Pass());
479 } 479 }
480 LayerImpl* root = host_impl_->active_tree()->root_layer()->children()[0]; 480 LayerImpl* root = host_impl_->active_tree()->root_layer()->children()[0];
481 481
482 scoped_ptr<ScrollAndScaleSet> scroll_info; 482 scoped_ptr<ScrollAndScaleSet> scroll_info;
483 483
484 scroll_info = host_impl_->ProcessScrollDeltas(); 484 scroll_info = host_impl_->ProcessScrollDeltas();
485 ASSERT_EQ(scroll_info->scrolls.size(), 1u); 485 ASSERT_EQ(scroll_info->scrolls.size(), 1u);
486 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), scroll_delta);
487 ExpectContains(*scroll_info, root->id(), scroll_delta); 486 ExpectContains(*scroll_info, root->id(), scroll_delta);
488 487
489 gfx::Vector2d scroll_delta2(-5, 27); 488 gfx::Vector2d scroll_delta2(-5, 27);
490 root->ScrollBy(scroll_delta2); 489 root->ScrollBy(scroll_delta2);
491 scroll_info = host_impl_->ProcessScrollDeltas(); 490 scroll_info = host_impl_->ProcessScrollDeltas();
492 ASSERT_EQ(scroll_info->scrolls.size(), 1u); 491 ASSERT_EQ(scroll_info->scrolls.size(), 1u);
493 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), scroll_delta + scroll_delta2);
494 ExpectContains(*scroll_info, root->id(), scroll_delta + scroll_delta2); 492 ExpectContains(*scroll_info, root->id(), scroll_delta + scroll_delta2);
495 493
496 root->ScrollBy(gfx::Vector2d()); 494 root->ScrollBy(gfx::Vector2d());
497 scroll_info = host_impl_->ProcessScrollDeltas(); 495 scroll_info = host_impl_->ProcessScrollDeltas();
498 EXPECT_EQ(root->sent_scroll_delta(), scroll_delta + scroll_delta2); 496 ExpectContains(*scroll_info, root->id(), scroll_delta + scroll_delta2);
499 } 497 }
500 498
501 TEST_F(LayerTreeHostImplTest, ScrollRootCallsCommitAndRedraw) { 499 TEST_F(LayerTreeHostImplTest, ScrollRootCallsCommitAndRedraw) {
502 SetupScrollAndContentsLayers(gfx::Size(100, 100)); 500 SetupScrollAndContentsLayers(gfx::Size(100, 100));
503 host_impl_->SetViewportSize(gfx::Size(50, 50)); 501 host_impl_->SetViewportSize(gfx::Size(50, 50));
504 DrawFrame(); 502 DrawFrame();
505 503
506 EXPECT_EQ(InputHandler::ScrollStarted, 504 EXPECT_EQ(InputHandler::ScrollStarted,
507 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); 505 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel));
508 EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(), 506 EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(),
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 scoped_ptr<ScrollAndScaleSet> scroll_info = 1022 scoped_ptr<ScrollAndScaleSet> scroll_info =
1025 host_impl_->ProcessScrollDeltas(); 1023 host_impl_->ProcessScrollDeltas();
1026 EXPECT_EQ(scroll_info->page_scale_delta, max_page_scale); 1024 EXPECT_EQ(scroll_info->page_scale_delta, max_page_scale);
1027 } 1025 }
1028 1026
1029 // Zoom-out clamping 1027 // Zoom-out clamping
1030 { 1028 {
1031 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, 1029 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale,
1032 max_page_scale); 1030 max_page_scale);
1033 scroll_layer->SetScrollDelta(gfx::Vector2d()); 1031 scroll_layer->SetScrollDelta(gfx::Vector2d());
1032 scroll_layer->PullDeltaForMainThread();
1034 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50)); 1033 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50));
1035 1034
1036 float page_scale_delta = 0.1f; 1035 float page_scale_delta = 0.1f;
1037 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); 1036 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture);
1038 host_impl_->PinchGestureBegin(); 1037 host_impl_->PinchGestureBegin();
1039 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point()); 1038 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point());
1040 host_impl_->PinchGestureEnd(); 1039 host_impl_->PinchGestureEnd();
1041 host_impl_->ScrollEnd(); 1040 host_impl_->ScrollEnd();
1042 1041
1043 scoped_ptr<ScrollAndScaleSet> scroll_info = 1042 scoped_ptr<ScrollAndScaleSet> scroll_info =
1044 host_impl_->ProcessScrollDeltas(); 1043 host_impl_->ProcessScrollDeltas();
1045 EXPECT_EQ(scroll_info->page_scale_delta, min_page_scale); 1044 EXPECT_EQ(scroll_info->page_scale_delta, min_page_scale);
1046 1045
1047 EXPECT_TRUE(scroll_info->scrolls.empty()); 1046 EXPECT_TRUE(scroll_info->scrolls.empty());
1048 } 1047 }
1049 1048
1050 // Two-finger panning should not happen based on pinch events only 1049 // Two-finger panning should not happen based on pinch events only
1051 { 1050 {
1052 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, 1051 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale,
1053 max_page_scale); 1052 max_page_scale);
1054 scroll_layer->SetScrollDelta(gfx::Vector2d()); 1053 scroll_layer->SetScrollDelta(gfx::Vector2d());
1054 scroll_layer->PullDeltaForMainThread();
1055 scroll_layer->SetScrollOffset(gfx::ScrollOffset(20, 20)); 1055 scroll_layer->SetScrollOffset(gfx::ScrollOffset(20, 20));
1056 1056
1057 float page_scale_delta = 1.f; 1057 float page_scale_delta = 1.f;
1058 host_impl_->ScrollBegin(gfx::Point(10, 10), InputHandler::Gesture); 1058 host_impl_->ScrollBegin(gfx::Point(10, 10), InputHandler::Gesture);
1059 host_impl_->PinchGestureBegin(); 1059 host_impl_->PinchGestureBegin();
1060 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10)); 1060 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10));
1061 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20)); 1061 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20));
1062 host_impl_->PinchGestureEnd(); 1062 host_impl_->PinchGestureEnd();
1063 host_impl_->ScrollEnd(); 1063 host_impl_->ScrollEnd();
1064 1064
1065 scoped_ptr<ScrollAndScaleSet> scroll_info = 1065 scoped_ptr<ScrollAndScaleSet> scroll_info =
1066 host_impl_->ProcessScrollDeltas(); 1066 host_impl_->ProcessScrollDeltas();
1067 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); 1067 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta);
1068 EXPECT_TRUE(scroll_info->scrolls.empty()); 1068 EXPECT_TRUE(scroll_info->scrolls.empty());
1069 } 1069 }
1070 1070
1071 // Two-finger panning should work with interleaved scroll events 1071 // Two-finger panning should work with interleaved scroll events
1072 { 1072 {
1073 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, 1073 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale,
1074 max_page_scale); 1074 max_page_scale);
1075 scroll_layer->SetScrollDelta(gfx::Vector2d()); 1075 scroll_layer->SetScrollDelta(gfx::Vector2d());
1076 scroll_layer->PullDeltaForMainThread();
1076 scroll_layer->SetScrollOffset(gfx::ScrollOffset(20, 20)); 1077 scroll_layer->SetScrollOffset(gfx::ScrollOffset(20, 20));
1077 1078
1078 float page_scale_delta = 1.f; 1079 float page_scale_delta = 1.f;
1079 host_impl_->ScrollBegin(gfx::Point(10, 10), InputHandler::Gesture); 1080 host_impl_->ScrollBegin(gfx::Point(10, 10), InputHandler::Gesture);
1080 host_impl_->PinchGestureBegin(); 1081 host_impl_->PinchGestureBegin();
1081 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10)); 1082 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10));
1082 host_impl_->ScrollBy(gfx::Point(10, 10), gfx::Vector2d(-10, -10)); 1083 host_impl_->ScrollBy(gfx::Point(10, 10), gfx::Vector2d(-10, -10));
1083 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20)); 1084 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20));
1084 host_impl_->PinchGestureEnd(); 1085 host_impl_->PinchGestureEnd();
1085 host_impl_->ScrollEnd(); 1086 host_impl_->ScrollEnd();
1086 1087
1087 scoped_ptr<ScrollAndScaleSet> scroll_info = 1088 scoped_ptr<ScrollAndScaleSet> scroll_info =
1088 host_impl_->ProcessScrollDeltas(); 1089 host_impl_->ProcessScrollDeltas();
1089 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); 1090 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta);
1090 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-10, -10)); 1091 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-10, -10));
1091 } 1092 }
1092 1093
1093 // Two-finger panning should work when starting fully zoomed out. 1094 // Two-finger panning should work when starting fully zoomed out.
1094 { 1095 {
1095 host_impl_->active_tree()->PushPageScaleFromMainThread(0.5f, 0.5f, 4.f); 1096 host_impl_->active_tree()->PushPageScaleFromMainThread(0.5f, 0.5f, 4.f);
1096 scroll_layer->SetScrollDelta(gfx::Vector2d()); 1097 scroll_layer->SetScrollDelta(gfx::Vector2d());
1098 scroll_layer->PullDeltaForMainThread();
1097 scroll_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); 1099 scroll_layer->SetScrollOffset(gfx::ScrollOffset(0, 0));
1098 1100
1099 host_impl_->ScrollBegin(gfx::Point(0, 0), InputHandler::Gesture); 1101 host_impl_->ScrollBegin(gfx::Point(0, 0), InputHandler::Gesture);
1100 host_impl_->PinchGestureBegin(); 1102 host_impl_->PinchGestureBegin();
1101 host_impl_->PinchGestureUpdate(2.f, gfx::Point(0, 0)); 1103 host_impl_->PinchGestureUpdate(2.f, gfx::Point(0, 0));
1102 host_impl_->PinchGestureUpdate(1.f, gfx::Point(0, 0)); 1104 host_impl_->PinchGestureUpdate(1.f, gfx::Point(0, 0));
1103 host_impl_->ScrollBy(gfx::Point(0, 0), gfx::Vector2d(10, 10)); 1105 host_impl_->ScrollBy(gfx::Point(0, 0), gfx::Vector2d(10, 10));
1104 host_impl_->PinchGestureUpdate(1.f, gfx::Point(10, 10)); 1106 host_impl_->PinchGestureUpdate(1.f, gfx::Point(10, 10));
1105 host_impl_->PinchGestureEnd(); 1107 host_impl_->PinchGestureEnd();
1106 host_impl_->ScrollEnd(); 1108 host_impl_->ScrollEnd();
(...skipping 2627 matching lines...) Expand 10 before | Expand all | Expand 10 after
3734 float min_page_scale_factor, 3736 float min_page_scale_factor,
3735 float max_page_scale_factor) override { 3737 float max_page_scale_factor) override {
3736 DCHECK(total_scroll_offset.x() <= max_scroll_offset.x()); 3738 DCHECK(total_scroll_offset.x() <= max_scroll_offset.x());
3737 DCHECK(total_scroll_offset.y() <= max_scroll_offset.y()); 3739 DCHECK(total_scroll_offset.y() <= max_scroll_offset.y());
3738 last_set_scroll_offset_ = total_scroll_offset; 3740 last_set_scroll_offset_ = total_scroll_offset;
3739 max_scroll_offset_ = max_scroll_offset; 3741 max_scroll_offset_ = max_scroll_offset;
3740 scrollable_size_ = scrollable_size; 3742 scrollable_size_ = scrollable_size;
3741 page_scale_factor_ = page_scale_factor; 3743 page_scale_factor_ = page_scale_factor;
3742 min_page_scale_factor_ = min_page_scale_factor; 3744 min_page_scale_factor_ = min_page_scale_factor;
3743 max_page_scale_factor_ = max_page_scale_factor; 3745 max_page_scale_factor_ = max_page_scale_factor;
3746
3747 set_getter_return_value(last_set_scroll_offset_);
3744 } 3748 }
3745 3749
3746 gfx::ScrollOffset last_set_scroll_offset() { 3750 gfx::ScrollOffset last_set_scroll_offset() {
3747 return last_set_scroll_offset_; 3751 return last_set_scroll_offset_;
3748 } 3752 }
3749 3753
3750 void set_getter_return_value(const gfx::ScrollOffset& value) { 3754 void set_getter_return_value(const gfx::ScrollOffset& value) {
3751 getter_return_value_ = value; 3755 getter_return_value_ = value;
3752 } 3756 }
3753 3757
(...skipping 4120 matching lines...) Expand 10 before | Expand all | Expand 10 after
7874 7878
7875 EXPECT_VECTOR_EQ(gfx::ScrollOffset(0, 100), 7879 EXPECT_VECTOR_EQ(gfx::ScrollOffset(0, 100),
7876 scrolling_layer->TotalScrollOffset()); 7880 scrolling_layer->TotalScrollOffset());
7877 EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); 7881 EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer());
7878 } 7882 }
7879 7883
7880 TEST_F(LayerTreeHostImplTest, GetPictureLayerImplPairs) { 7884 TEST_F(LayerTreeHostImplTest, GetPictureLayerImplPairs) {
7881 host_impl_->CreatePendingTree(); 7885 host_impl_->CreatePendingTree();
7882 7886
7883 scoped_ptr<PictureLayerImpl> layer = 7887 scoped_ptr<PictureLayerImpl> layer =
7884 PictureLayerImpl::Create(host_impl_->pending_tree(), 10, false); 7888 FakePictureLayerImpl::Create(host_impl_->pending_tree(), 10);
7885 layer->SetBounds(gfx::Size(10, 10)); 7889 layer->SetBounds(gfx::Size(10, 10));
7886 7890
7887 scoped_refptr<RasterSource> pile(FakePicturePileImpl::CreateEmptyPile( 7891 scoped_refptr<RasterSource> pile(FakePicturePileImpl::CreateEmptyPile(
7888 gfx::Size(10, 10), gfx::Size(10, 10))); 7892 gfx::Size(10, 10), gfx::Size(10, 10)));
7889 Region empty_invalidation; 7893 Region empty_invalidation;
7890 const PictureLayerTilingSet* null_tiling_set = nullptr; 7894 const PictureLayerTilingSet* null_tiling_set = nullptr;
7891 layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set); 7895 layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set);
7892 7896
7893 host_impl_->pending_tree()->SetRootLayer(layer.Pass()); 7897 host_impl_->pending_tree()->SetRootLayer(layer.Pass());
7894 7898
(...skipping 29 matching lines...) Expand all
7924 layer_pairs.clear(); 7928 layer_pairs.clear();
7925 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true); 7929 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true);
7926 EXPECT_EQ(1u, layer_pairs.size()); 7930 EXPECT_EQ(1u, layer_pairs.size());
7927 EXPECT_EQ(active_layer, layer_pairs[0].active); 7931 EXPECT_EQ(active_layer, layer_pairs[0].active);
7928 EXPECT_EQ(nullptr, layer_pairs[0].pending); 7932 EXPECT_EQ(nullptr, layer_pairs[0].pending);
7929 7933
7930 // Create another layer in the pending tree that's not in the active tree. We 7934 // Create another layer in the pending tree that's not in the active tree. We
7931 // should get two pairs. 7935 // should get two pairs.
7932 host_impl_->CreatePendingTree(); 7936 host_impl_->CreatePendingTree();
7933 host_impl_->pending_tree()->root_layer()->AddChild( 7937 host_impl_->pending_tree()->root_layer()->AddChild(
7934 PictureLayerImpl::Create(host_impl_->pending_tree(), 11, false)); 7938 FakePictureLayerImpl::Create(host_impl_->pending_tree(), 11));
7935 7939
7936 LayerImpl* new_pending_layer = pending_tree->root_layer()->children()[0]; 7940 LayerImpl* new_pending_layer = pending_tree->root_layer()->children()[0];
7937 7941
7938 layer_pairs.clear(); 7942 layer_pairs.clear();
7939 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true); 7943 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true);
7940 EXPECT_EQ(2u, layer_pairs.size()); 7944 EXPECT_EQ(2u, layer_pairs.size());
7941 7945
7942 // The pair ordering is flaky, so make it consistent. 7946 // The pair ordering is flaky, so make it consistent.
7943 if (layer_pairs[0].active != active_layer) 7947 if (layer_pairs[0].active != active_layer)
7944 std::swap(layer_pairs[0], layer_pairs[1]); 7948 std::swap(layer_pairs[0], layer_pairs[1]);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
8047 // surface. 8051 // surface.
8048 EXPECT_EQ(0, num_lost_surfaces_); 8052 EXPECT_EQ(0, num_lost_surfaces_);
8049 host_impl_->DidLoseOutputSurface(); 8053 host_impl_->DidLoseOutputSurface();
8050 EXPECT_EQ(1, num_lost_surfaces_); 8054 EXPECT_EQ(1, num_lost_surfaces_);
8051 host_impl_->DidLoseOutputSurface(); 8055 host_impl_->DidLoseOutputSurface();
8052 EXPECT_LE(1, num_lost_surfaces_); 8056 EXPECT_LE(1, num_lost_surfaces_);
8053 } 8057 }
8054 8058
8055 } // namespace 8059 } // namespace
8056 } // namespace cc 8060 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | cc/trees/layer_tree_host_unittest_animation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698