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

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

Issue 783543003: Update from https://crrev.com/306901 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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_unittest_delegated.cc ('k') | cc/trees/layer_tree_impl.h » ('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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
8 #include "cc/layers/layer.h" 8 #include "cc/layers/layer.h"
9 #include "cc/layers/layer_impl.h" 9 #include "cc/layers/layer_impl.h"
10 #include "cc/layers/picture_layer.h" 10 #include "cc/layers/picture_layer.h"
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 299
300 if (impl->active_tree()->source_frame_number() == 0 && 300 if (impl->active_tree()->source_frame_number() == 0 &&
301 impl->SourceAnimationFrameNumber() == 1) { 301 impl->SourceAnimationFrameNumber() == 1) {
302 // First draw 302 // First draw
303 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d()); 303 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d());
304 root_scroll_layer->ScrollBy(impl_scroll_); 304 root_scroll_layer->ScrollBy(impl_scroll_);
305 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), impl_scroll_); 305 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), impl_scroll_);
306 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), initial_scroll_); 306 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), initial_scroll_);
307 307
308 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); 308 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta());
309 EXPECT_EQ(1.f, impl->active_tree()->total_page_scale_factor()); 309 EXPECT_EQ(1.f, impl->active_tree()->current_page_scale_factor());
310 impl->active_tree()->SetPageScaleDelta(impl_scale_); 310 impl->SetPageScaleOnActiveTree(impl_scale_);
311 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta()); 311 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta());
312 EXPECT_EQ(impl_scale_, impl->active_tree()->total_page_scale_factor()); 312 EXPECT_EQ(impl_scale_, impl->active_tree()->current_page_scale_factor());
313 313
314 // To simplify the testing flow, don't redraw here, just commit. 314 // To simplify the testing flow, don't redraw here, just commit.
315 impl->SetNeedsCommit(); 315 impl->SetNeedsCommit();
316 } else if (impl->active_tree()->source_frame_number() == 0 && 316 } else if (impl->active_tree()->source_frame_number() == 0 &&
317 impl->SourceAnimationFrameNumber() == 2) { 317 impl->SourceAnimationFrameNumber() == 2) {
318 // Test a second draw after an aborted commit. 318 // Test a second draw after an aborted commit.
319 // The scroll/scale values should be baked into the offset/scale factor 319 // The scroll/scale values should be baked into the offset/scale factor
320 // since the main thread consumed but aborted the begin frame. 320 // since the main thread consumed but aborted the begin frame.
321 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d()); 321 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d());
322 root_scroll_layer->ScrollBy(impl_scroll_); 322 root_scroll_layer->ScrollBy(impl_scroll_);
323 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), impl_scroll_); 323 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), impl_scroll_);
324 EXPECT_VECTOR_EQ( 324 EXPECT_VECTOR_EQ(
325 root_scroll_layer->scroll_offset(), 325 root_scroll_layer->scroll_offset(),
326 gfx::ScrollOffsetWithDelta(initial_scroll_, impl_scroll_)); 326 gfx::ScrollOffsetWithDelta(initial_scroll_, impl_scroll_));
327 327
328 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); 328 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta());
329 EXPECT_EQ(impl_scale_, impl->active_tree()->total_page_scale_factor()); 329 EXPECT_EQ(impl_scale_, impl->active_tree()->current_page_scale_factor());
330 impl->active_tree()->SetPageScaleDelta(impl_scale_); 330 impl->SetPageScaleOnActiveTree(impl_scale_ * impl_scale_);
331 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta()); 331 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta());
332 EXPECT_EQ(impl_scale_ * impl_scale_, 332 EXPECT_EQ(impl_scale_ * impl_scale_,
333 impl->active_tree()->total_page_scale_factor()); 333 impl->active_tree()->current_page_scale_factor());
334 334
335 impl->SetNeedsCommit(); 335 impl->SetNeedsCommit();
336 } else if (impl->active_tree()->source_frame_number() == 1) { 336 } else if (impl->active_tree()->source_frame_number() == 1) {
337 // Commit for source frame 1 is aborted. 337 // Commit for source frame 1 is aborted.
338 NOTREACHED(); 338 NOTREACHED();
339 } else if (impl->active_tree()->source_frame_number() == 2 && 339 } else if (impl->active_tree()->source_frame_number() == 2 &&
340 impl->SourceAnimationFrameNumber() == 3) { 340 impl->SourceAnimationFrameNumber() == 3) {
341 // Third draw after the second full commit. 341 // Third draw after the second full commit.
342 EXPECT_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d()); 342 EXPECT_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d());
343 root_scroll_layer->ScrollBy(impl_scroll_); 343 root_scroll_layer->ScrollBy(impl_scroll_);
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestSimple); 890 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestSimple);
891 891
892 // This test makes sure that layers pick up scrolls that occur between 892 // This test makes sure that layers pick up scrolls that occur between
893 // beginning a commit and finishing a commit (aka scroll deltas not 893 // beginning a commit and finishing a commit (aka scroll deltas not
894 // included in sent scroll delta) still apply to layers that don't 894 // included in sent scroll delta) still apply to layers that don't
895 // push properties. 895 // push properties.
896 class ImplSidePaintingScrollTestImplOnlyScroll 896 class ImplSidePaintingScrollTestImplOnlyScroll
897 : public ImplSidePaintingScrollTest { 897 : public ImplSidePaintingScrollTest {
898 public: 898 public:
899 ImplSidePaintingScrollTestImplOnlyScroll() 899 ImplSidePaintingScrollTestImplOnlyScroll()
900 : initial_scroll_(20, 10), impl_thread_scroll_(-2, 3) {} 900 : initial_scroll_(20, 10), impl_thread_scroll_(-2, 3), impl_scale_(2.f) {}
901 901
902 void SetupTree() override { 902 void SetupTree() override {
903 LayerTreeHostScrollTest::SetupTree(); 903 LayerTreeHostScrollTest::SetupTree();
904 Layer* root_layer = layer_tree_host()->root_layer(); 904 Layer* root_layer = layer_tree_host()->root_layer();
905 scoped_refptr<Layer> root_scroll_layer = Layer::Create(); 905 scoped_refptr<Layer> root_scroll_layer = Layer::Create();
906 root_scroll_layer->SetScrollClipLayerId(root_layer->id()); 906 root_scroll_layer->SetScrollClipLayerId(root_layer->id());
907 root_scroll_layer->SetScrollOffset(initial_scroll_); 907 root_scroll_layer->SetScrollOffset(initial_scroll_);
908 root_scroll_layer->SetBounds( 908 root_scroll_layer->SetBounds(
909 gfx::Size(root_layer->bounds().width() + 100, 909 gfx::Size(root_layer->bounds().width() + 100,
910 root_layer->bounds().height() + 100)); 910 root_layer->bounds().height() + 100));
(...skipping 25 matching lines...) Expand all
936 } 936 }
937 937
938 void BeginCommitOnThread(LayerTreeHostImpl* impl) override { 938 void BeginCommitOnThread(LayerTreeHostImpl* impl) override {
939 // Scroll after the 2nd commit has started. 939 // Scroll after the 2nd commit has started.
940 if (impl->active_tree()->source_frame_number() == 0) { 940 if (impl->active_tree()->source_frame_number() == 0) {
941 LayerImpl* active_root = impl->active_tree()->root_layer(); 941 LayerImpl* active_root = impl->active_tree()->root_layer();
942 LayerImpl* active_scroll_layer = active_root->children()[0]; 942 LayerImpl* active_scroll_layer = active_root->children()[0];
943 ASSERT_TRUE(active_root); 943 ASSERT_TRUE(active_root);
944 ASSERT_TRUE(active_scroll_layer); 944 ASSERT_TRUE(active_scroll_layer);
945 active_scroll_layer->ScrollBy(impl_thread_scroll_); 945 active_scroll_layer->ScrollBy(impl_thread_scroll_);
946 impl->SetPageScaleOnActiveTree(impl_scale_);
946 } 947 }
947 } 948 }
948 949
949 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 950 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
950 // We force a second draw here of the first commit before activating 951 // We force a second draw here of the first commit before activating
951 // the second commit. 952 // the second commit.
952 LayerImpl* active_root = impl->active_tree()->root_layer(); 953 LayerImpl* active_root = impl->active_tree()->root_layer();
953 LayerImpl* active_scroll_layer = 954 LayerImpl* active_scroll_layer =
954 active_root ? active_root->children()[0] : NULL; 955 active_root ? active_root->children()[0] : NULL;
955 LayerImpl* pending_root = impl->pending_tree()->root_layer(); 956 LayerImpl* pending_root = impl->pending_tree()->root_layer();
(...skipping 27 matching lines...) Expand all
983 gfx::Vector2d()); 984 gfx::Vector2d());
984 break; 985 break;
985 case 2: 986 case 2:
986 // On the next commit, this delta should have been sent and applied. 987 // On the next commit, this delta should have been sent and applied.
987 EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(), 988 EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(),
988 gfx::ScrollOffsetWithDelta(initial_scroll_, 989 gfx::ScrollOffsetWithDelta(initial_scroll_,
989 impl_thread_scroll_)); 990 impl_thread_scroll_));
990 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), gfx::Vector2d()); 991 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), gfx::Vector2d());
991 EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(), 992 EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(),
992 gfx::Vector2d()); 993 gfx::Vector2d());
993 EndTest();
994 break; 994 break;
995 } 995 }
996 } 996 }
997 997
998 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 998 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
999 ImplSidePaintingScrollTest::DrawLayersOnThread(impl); 999 ImplSidePaintingScrollTest::DrawLayersOnThread(impl);
1000 1000
1001 LayerImpl* root = impl->active_tree()->root_layer(); 1001 LayerImpl* root = impl->active_tree()->root_layer();
1002 LayerImpl* scroll_layer = root->children()[0]; 1002 LayerImpl* scroll_layer = root->children()[0];
1003 1003
1004 switch (impl->active_tree()->source_frame_number()) { 1004 switch (impl->active_tree()->source_frame_number()) {
1005 case 0: 1005 case 0:
1006 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); 1006 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_);
1007 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d()); 1007 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d());
1008 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); 1008 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d());
1009 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta());
1010 EXPECT_EQ(1.f, impl->active_tree()->current_page_scale_factor());
1009 PostSetNeedsCommitToMainThread(); 1011 PostSetNeedsCommitToMainThread();
1010 break; 1012 break;
1011 case 1: 1013 case 1:
1012 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); 1014 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_);
1013 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll_); 1015 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll_);
1014 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); 1016 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d());
1017 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta());
1018 EXPECT_EQ(impl_scale_,
1019 impl->active_tree()->current_page_scale_factor());
1015 PostSetNeedsCommitToMainThread(); 1020 PostSetNeedsCommitToMainThread();
1016 break; 1021 break;
1022 case 2:
1023 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta());
1024 EXPECT_EQ(impl_scale_,
1025 impl->active_tree()->current_page_scale_factor());
1026 EndTest();
1027 break;
1017 } 1028 }
1018 } 1029 }
1019 1030
1020 void AfterTest() override {} 1031 void AfterTest() override {}
1021 1032
1022 private: 1033 private:
1023 gfx::ScrollOffset initial_scroll_; 1034 gfx::ScrollOffset initial_scroll_;
1024 gfx::Vector2dF impl_thread_scroll_; 1035 gfx::Vector2dF impl_thread_scroll_;
1036 float impl_scale_;
1025 }; 1037 };
1026 1038
1027 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestImplOnlyScroll); 1039 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestImplOnlyScroll);
1028 1040
1029 class LayerTreeHostScrollTestScrollZeroMaxScrollOffset 1041 class LayerTreeHostScrollTestScrollZeroMaxScrollOffset
1030 : public LayerTreeHostScrollTest { 1042 : public LayerTreeHostScrollTest {
1031 public: 1043 public:
1032 LayerTreeHostScrollTestScrollZeroMaxScrollOffset() {} 1044 LayerTreeHostScrollTestScrollZeroMaxScrollOffset() {}
1033 1045
1034 void SetupTree() override { 1046 void SetupTree() override {
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 RunTest(true, false, true); 1239 RunTest(true, false, true);
1228 } 1240 }
1229 1241
1230 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { 1242 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) {
1231 scroll_destroy_whole_tree_ = true; 1243 scroll_destroy_whole_tree_ = true;
1232 RunTest(true, false, true); 1244 RunTest(true, false, true);
1233 } 1245 }
1234 1246
1235 } // namespace 1247 } // namespace
1236 } // namespace cc 1248 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest_delegated.cc ('k') | cc/trees/layer_tree_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698