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

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

Powered by Google App Engine
This is Rietveld 408576698