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

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

Issue 640203002: [C++11 Allowed Features] Declares a type-safe null pointer converting from NULL to nullptr [part-… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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 26 matching lines...) Expand all
37 Layer* root_layer = layer_tree_host()->root_layer(); 37 Layer* root_layer = layer_tree_host()->root_layer();
38 scoped_refptr<Layer> scroll_layer = Layer::Create(); 38 scoped_refptr<Layer> scroll_layer = Layer::Create();
39 root_layer->AddChild(scroll_layer); 39 root_layer->AddChild(scroll_layer);
40 // Create an effective max_scroll_offset of (100, 100). 40 // Create an effective max_scroll_offset of (100, 100).
41 scroll_layer->SetBounds(gfx::Size(root_layer->bounds().width() + 100, 41 scroll_layer->SetBounds(gfx::Size(root_layer->bounds().width() + 100,
42 root_layer->bounds().height() + 100)); 42 root_layer->bounds().height() + 100));
43 scroll_layer->SetIsDrawable(true); 43 scroll_layer->SetIsDrawable(true);
44 scroll_layer->SetIsContainerForFixedPositionLayers(true); 44 scroll_layer->SetIsContainerForFixedPositionLayers(true);
45 scroll_layer->SetScrollClipLayerId(root_layer->id()); 45 scroll_layer->SetScrollClipLayerId(root_layer->id());
46 scroll_layer->SetScrollOffset(initial_scroll_); 46 scroll_layer->SetScrollOffset(initial_scroll_);
47 layer_tree_host()->RegisterViewportLayers(root_layer, scroll_layer, NULL); 47 layer_tree_host()->RegisterViewportLayers(root_layer, scroll_layer, nullptr) ;
48 PostSetNeedsCommitToMainThread(); 48 PostSetNeedsCommitToMainThread();
49 } 49 }
50 50
51 virtual void Layout() override { 51 virtual void Layout() override {
52 Layer* root = layer_tree_host()->root_layer(); 52 Layer* root = layer_tree_host()->root_layer();
53 Layer* scroll_layer = root->children()[0].get(); 53 Layer* scroll_layer = root->children()[0].get();
54 if (!layer_tree_host()->source_frame_number()) { 54 if (!layer_tree_host()->source_frame_number()) {
55 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset()); 55 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset());
56 } else { 56 } else {
57 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(initial_scroll_, 57 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(initial_scroll_,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 Layer* root_layer = layer_tree_host()->root_layer(); 114 Layer* root_layer = layer_tree_host()->root_layer();
115 scroll_layer_ = Layer::Create(); 115 scroll_layer_ = Layer::Create();
116 root_layer->AddChild(scroll_layer_); 116 root_layer->AddChild(scroll_layer_);
117 // Create an effective max_scroll_offset of (100, 100). 117 // Create an effective max_scroll_offset of (100, 100).
118 scroll_layer_->SetBounds(gfx::Size(root_layer->bounds().width() + 100, 118 scroll_layer_->SetBounds(gfx::Size(root_layer->bounds().width() + 100,
119 root_layer->bounds().height() + 100)); 119 root_layer->bounds().height() + 100));
120 scroll_layer_->SetIsDrawable(true); 120 scroll_layer_->SetIsDrawable(true);
121 scroll_layer_->SetIsContainerForFixedPositionLayers(true); 121 scroll_layer_->SetIsContainerForFixedPositionLayers(true);
122 scroll_layer_->SetScrollClipLayerId(root_layer->id()); 122 scroll_layer_->SetScrollClipLayerId(root_layer->id());
123 scroll_layer_->SetScrollOffset(initial_scroll_); 123 scroll_layer_->SetScrollOffset(initial_scroll_);
124 layer_tree_host()->RegisterViewportLayers(root_layer, scroll_layer_, NULL); 124 layer_tree_host()->RegisterViewportLayers(root_layer, scroll_layer_, nullptr );
125 PostSetNeedsCommitToMainThread(); 125 PostSetNeedsCommitToMainThread();
126 } 126 }
127 127
128 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) override { 128 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) override {
129 switch (layer_tree_host()->source_frame_number()) { 129 switch (layer_tree_host()->source_frame_number()) {
130 case 0: 130 case 0:
131 EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), initial_scroll_); 131 EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), initial_scroll_);
132 break; 132 break;
133 case 1: 133 case 1:
134 EXPECT_VECTOR_EQ( 134 EXPECT_VECTOR_EQ(
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 Layer* root_layer = layer_tree_host()->root_layer(); 217 Layer* root_layer = layer_tree_host()->root_layer();
218 scoped_refptr<Layer> root_scroll_layer = Layer::Create(); 218 scoped_refptr<Layer> root_scroll_layer = Layer::Create();
219 root_scroll_layer->SetScrollClipLayerId(root_layer->id()); 219 root_scroll_layer->SetScrollClipLayerId(root_layer->id());
220 root_scroll_layer->SetScrollOffset(initial_scroll_); 220 root_scroll_layer->SetScrollOffset(initial_scroll_);
221 root_scroll_layer->SetBounds(gfx::Size(200, 200)); 221 root_scroll_layer->SetBounds(gfx::Size(200, 200));
222 root_scroll_layer->SetIsDrawable(true); 222 root_scroll_layer->SetIsDrawable(true);
223 root_scroll_layer->SetIsContainerForFixedPositionLayers(true); 223 root_scroll_layer->SetIsContainerForFixedPositionLayers(true);
224 root_layer->AddChild(root_scroll_layer); 224 root_layer->AddChild(root_scroll_layer);
225 225
226 layer_tree_host()->RegisterViewportLayers( 226 layer_tree_host()->RegisterViewportLayers(
227 root_layer, root_scroll_layer, NULL); 227 root_layer, root_scroll_layer, nullptr);
228 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); 228 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f);
229 } 229 }
230 230
231 virtual void WillBeginMainFrame() override { 231 virtual void WillBeginMainFrame() override {
232 num_will_begin_main_frames_++; 232 num_will_begin_main_frames_++;
233 Layer* root_scroll_layer = 233 Layer* root_scroll_layer =
234 layer_tree_host()->root_layer()->children()[0].get(); 234 layer_tree_host()->root_layer()->children()[0].get();
235 switch (num_will_begin_main_frames_) { 235 switch (num_will_begin_main_frames_) {
236 case 1: 236 case 1:
237 // This will not be aborted because of the initial prop changes. 237 // This will not be aborted because of the initial prop changes.
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 scoped_refptr<Layer> root_scroll_layer = Layer::Create(); 400 scoped_refptr<Layer> root_scroll_layer = Layer::Create();
401 root_scroll_layer->SetScrollClipLayerId(root_layer->id()); 401 root_scroll_layer->SetScrollClipLayerId(root_layer->id());
402 root_scroll_layer->SetBounds( 402 root_scroll_layer->SetBounds(
403 gfx::Size(root_layer->bounds().width() + 100, 403 gfx::Size(root_layer->bounds().width() + 100,
404 root_layer->bounds().height() + 100)); 404 root_layer->bounds().height() + 100));
405 root_scroll_layer->SetIsDrawable(true); 405 root_scroll_layer->SetIsDrawable(true);
406 root_scroll_layer->SetIsContainerForFixedPositionLayers(true); 406 root_scroll_layer->SetIsContainerForFixedPositionLayers(true);
407 root_layer->AddChild(root_scroll_layer); 407 root_layer->AddChild(root_scroll_layer);
408 408
409 layer_tree_host()->RegisterViewportLayers( 409 layer_tree_host()->RegisterViewportLayers(
410 root_layer, root_scroll_layer, NULL); 410 root_layer, root_scroll_layer, nullptr);
411 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); 411 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f);
412 } 412 }
413 413
414 virtual void BeginTest() override { 414 virtual void BeginTest() override {
415 PostSetNeedsCommitToMainThread(); 415 PostSetNeedsCommitToMainThread();
416 } 416 }
417 417
418 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 418 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
419 LayerImpl* root = impl->active_tree()->root_layer(); 419 LayerImpl* root = impl->active_tree()->root_layer();
420 LayerImpl* scroll_layer = root->children()[0]; 420 LayerImpl* scroll_layer = root->children()[0];
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 expected_no_scroll_layer_ = root_scroll_layer_; 505 expected_no_scroll_layer_ = root_scroll_layer_;
506 } else { 506 } else {
507 expected_scroll_layer_ = root_scroll_layer_; 507 expected_scroll_layer_ = root_scroll_layer_;
508 expected_no_scroll_layer_ = child_layer_; 508 expected_no_scroll_layer_ = child_layer_;
509 } 509 }
510 510
511 expected_scroll_layer_->SetScrollOffset(initial_offset_); 511 expected_scroll_layer_->SetScrollOffset(initial_offset_);
512 512
513 layer_tree_host()->SetRootLayer(root_layer); 513 layer_tree_host()->SetRootLayer(root_layer);
514 layer_tree_host()->RegisterViewportLayers( 514 layer_tree_host()->RegisterViewportLayers(
515 root_layer, root_scroll_layer_, NULL); 515 root_layer, root_scroll_layer_, nullptr);
516 LayerTreeHostScrollTest::SetupTree(); 516 LayerTreeHostScrollTest::SetupTree();
517 } 517 }
518 518
519 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 519 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); }
520 520
521 virtual void WillCommit() override { 521 virtual void WillCommit() override {
522 // Keep the test committing (otherwise the early out for no update 522 // Keep the test committing (otherwise the early out for no update
523 // will stall the test). 523 // will stall the test).
524 if (layer_tree_host()->source_frame_number() < 2) { 524 if (layer_tree_host()->source_frame_number() < 2) {
525 layer_tree_host()->SetNeedsCommit(); 525 layer_tree_host()->SetNeedsCommit();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 } 561 }
562 } 562 }
563 563
564 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 564 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
565 LayerImpl* root_impl = impl->active_tree()->root_layer(); 565 LayerImpl* root_impl = impl->active_tree()->root_layer();
566 FakePictureLayerImpl* root_scroll_layer_impl = 566 FakePictureLayerImpl* root_scroll_layer_impl =
567 static_cast<FakePictureLayerImpl*>(root_impl->children()[0]); 567 static_cast<FakePictureLayerImpl*>(root_impl->children()[0]);
568 FakePictureLayerImpl* child_layer_impl = static_cast<FakePictureLayerImpl*>( 568 FakePictureLayerImpl* child_layer_impl = static_cast<FakePictureLayerImpl*>(
569 root_scroll_layer_impl->children()[0]); 569 root_scroll_layer_impl->children()[0]);
570 570
571 LayerImpl* expected_scroll_layer_impl = NULL; 571 LayerImpl* expected_scroll_layer_impl = nullptr;
572 LayerImpl* expected_no_scroll_layer_impl = NULL; 572 LayerImpl* expected_no_scroll_layer_impl = nullptr;
573 if (scroll_child_layer_) { 573 if (scroll_child_layer_) {
574 expected_scroll_layer_impl = child_layer_impl; 574 expected_scroll_layer_impl = child_layer_impl;
575 expected_no_scroll_layer_impl = root_scroll_layer_impl; 575 expected_no_scroll_layer_impl = root_scroll_layer_impl;
576 } else { 576 } else {
577 expected_scroll_layer_impl = root_scroll_layer_impl; 577 expected_scroll_layer_impl = root_scroll_layer_impl;
578 expected_no_scroll_layer_impl = child_layer_impl; 578 expected_no_scroll_layer_impl = child_layer_impl;
579 } 579 }
580 580
581 EXPECT_VECTOR_EQ(gfx::Vector2d(), root_impl->ScrollDelta()); 581 EXPECT_VECTOR_EQ(gfx::Vector2d(), root_impl->ScrollDelta());
582 EXPECT_VECTOR_EQ(gfx::Vector2d(), 582 EXPECT_VECTOR_EQ(gfx::Vector2d(),
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 root_scroll_layer->SetScrollClipLayerId(root_layer->id()); 774 root_scroll_layer->SetScrollClipLayerId(root_layer->id());
775 root_scroll_layer->SetScrollOffset(initial_scroll_); 775 root_scroll_layer->SetScrollOffset(initial_scroll_);
776 root_scroll_layer->SetBounds( 776 root_scroll_layer->SetBounds(
777 gfx::Size(root_layer->bounds().width() + 100, 777 gfx::Size(root_layer->bounds().width() + 100,
778 root_layer->bounds().height() + 100)); 778 root_layer->bounds().height() + 100));
779 root_scroll_layer->SetIsDrawable(true); 779 root_scroll_layer->SetIsDrawable(true);
780 root_scroll_layer->SetIsContainerForFixedPositionLayers(true); 780 root_scroll_layer->SetIsContainerForFixedPositionLayers(true);
781 root_layer->AddChild(root_scroll_layer); 781 root_layer->AddChild(root_scroll_layer);
782 782
783 layer_tree_host()->RegisterViewportLayers( 783 layer_tree_host()->RegisterViewportLayers(
784 root_layer, root_scroll_layer, NULL); 784 root_layer, root_scroll_layer, nullptr);
785 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); 785 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f);
786 } 786 }
787 787
788 virtual void BeginTest() override { 788 virtual void BeginTest() override {
789 PostSetNeedsCommitToMainThread(); 789 PostSetNeedsCommitToMainThread();
790 } 790 }
791 791
792 virtual void Layout() override { 792 virtual void Layout() override {
793 Layer* root = layer_tree_host()->root_layer(); 793 Layer* root = layer_tree_host()->root_layer();
794 Layer* scroll_layer = root->children()[0].get(); 794 Layer* scroll_layer = root->children()[0].get();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 root_scroll_layer->SetScrollClipLayerId(root_layer->id()); 907 root_scroll_layer->SetScrollClipLayerId(root_layer->id());
908 root_scroll_layer->SetScrollOffset(initial_scroll_); 908 root_scroll_layer->SetScrollOffset(initial_scroll_);
909 root_scroll_layer->SetBounds( 909 root_scroll_layer->SetBounds(
910 gfx::Size(root_layer->bounds().width() + 100, 910 gfx::Size(root_layer->bounds().width() + 100,
911 root_layer->bounds().height() + 100)); 911 root_layer->bounds().height() + 100));
912 root_scroll_layer->SetIsDrawable(true); 912 root_scroll_layer->SetIsDrawable(true);
913 root_scroll_layer->SetIsContainerForFixedPositionLayers(true); 913 root_scroll_layer->SetIsContainerForFixedPositionLayers(true);
914 root_layer->AddChild(root_scroll_layer); 914 root_layer->AddChild(root_scroll_layer);
915 915
916 layer_tree_host()->RegisterViewportLayers( 916 layer_tree_host()->RegisterViewportLayers(
917 root_layer, root_scroll_layer, NULL); 917 root_layer, root_scroll_layer, nullptr);
918 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); 918 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f);
919 } 919 }
920 920
921 virtual void BeginTest() override { 921 virtual void BeginTest() override {
922 PostSetNeedsCommitToMainThread(); 922 PostSetNeedsCommitToMainThread();
923 } 923 }
924 924
925 virtual void WillCommit() override { 925 virtual void WillCommit() override {
926 Layer* root = layer_tree_host()->root_layer(); 926 Layer* root = layer_tree_host()->root_layer();
927 Layer* scroll_layer = root->children()[0].get(); 927 Layer* scroll_layer = root->children()[0].get();
(...skipping 19 matching lines...) Expand all
947 ASSERT_TRUE(active_scroll_layer); 947 ASSERT_TRUE(active_scroll_layer);
948 active_scroll_layer->ScrollBy(impl_thread_scroll_); 948 active_scroll_layer->ScrollBy(impl_thread_scroll_);
949 } 949 }
950 } 950 }
951 951
952 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 952 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
953 // We force a second draw here of the first commit before activating 953 // We force a second draw here of the first commit before activating
954 // the second commit. 954 // the second commit.
955 LayerImpl* active_root = impl->active_tree()->root_layer(); 955 LayerImpl* active_root = impl->active_tree()->root_layer();
956 LayerImpl* active_scroll_layer = 956 LayerImpl* active_scroll_layer =
957 active_root ? active_root->children()[0] : NULL; 957 active_root ? active_root->children()[0] : nullptr;
958 LayerImpl* pending_root = impl->pending_tree()->root_layer(); 958 LayerImpl* pending_root = impl->pending_tree()->root_layer();
959 LayerImpl* pending_scroll_layer = pending_root->children()[0]; 959 LayerImpl* pending_scroll_layer = pending_root->children()[0];
960 960
961 ASSERT_TRUE(pending_root); 961 ASSERT_TRUE(pending_root);
962 ASSERT_TRUE(pending_scroll_layer); 962 ASSERT_TRUE(pending_scroll_layer);
963 switch (impl->pending_tree()->source_frame_number()) { 963 switch (impl->pending_tree()->source_frame_number()) {
964 case 0: 964 case 0:
965 EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(), 965 EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(),
966 initial_scroll_); 966 initial_scroll_);
967 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), gfx::Vector2d()); 967 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), gfx::Vector2d());
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 case 1: 1184 case 1:
1185 EndTest(); 1185 EndTest();
1186 break; 1186 break;
1187 } 1187 }
1188 } 1188 }
1189 1189
1190 virtual void AfterTest() override {} 1190 virtual void AfterTest() override {}
1191 1191
1192 virtual void DidScroll(Layer* layer) { 1192 virtual void DidScroll(Layer* layer) {
1193 if (scroll_destroy_whole_tree_) { 1193 if (scroll_destroy_whole_tree_) {
1194 layer_tree_host()->SetRootLayer(NULL); 1194 layer_tree_host()->SetRootLayer(nullptr);
1195 EndTest(); 1195 EndTest();
1196 return; 1196 return;
1197 } 1197 }
1198 layer->RemoveFromParent(); 1198 layer->RemoveFromParent();
1199 } 1199 }
1200 1200
1201 protected: 1201 protected:
1202 class FakeLayerScrollClient { 1202 class FakeLayerScrollClient {
1203 public: 1203 public:
1204 void DidScroll() { 1204 void DidScroll() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 RunTest(true, false, true); 1238 RunTest(true, false, true);
1239 } 1239 }
1240 1240
1241 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { 1241 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) {
1242 scroll_destroy_whole_tree_ = true; 1242 scroll_destroy_whole_tree_ = true;
1243 RunTest(true, false, true); 1243 RunTest(true, false, true);
1244 } 1244 }
1245 1245
1246 } // namespace 1246 } // namespace
1247 } // namespace cc 1247 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698