| OLD | NEW |
| 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 27 matching lines...) Expand all Loading... |
| 38 Layer* root_layer = layer_tree_host()->root_layer(); | 38 Layer* root_layer = layer_tree_host()->root_layer(); |
| 39 scoped_refptr<Layer> scroll_layer = Layer::Create(); | 39 scoped_refptr<Layer> scroll_layer = Layer::Create(); |
| 40 root_layer->AddChild(scroll_layer); | 40 root_layer->AddChild(scroll_layer); |
| 41 // Create an effective max_scroll_offset of (100, 100). | 41 // Create an effective max_scroll_offset of (100, 100). |
| 42 scroll_layer->SetBounds(gfx::Size(root_layer->bounds().width() + 100, | 42 scroll_layer->SetBounds(gfx::Size(root_layer->bounds().width() + 100, |
| 43 root_layer->bounds().height() + 100)); | 43 root_layer->bounds().height() + 100)); |
| 44 scroll_layer->SetIsDrawable(true); | 44 scroll_layer->SetIsDrawable(true); |
| 45 scroll_layer->SetIsContainerForFixedPositionLayers(true); | 45 scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 46 scroll_layer->SetScrollClipLayerId(root_layer->id()); | 46 scroll_layer->SetScrollClipLayerId(root_layer->id()); |
| 47 scroll_layer->SetScrollOffset(initial_scroll_); | 47 scroll_layer->SetScrollOffset(initial_scroll_); |
| 48 layer_tree_host()->RegisterViewportLayers(root_layer, scroll_layer, NULL); | 48 layer_tree_host()->RegisterViewportLayers(NULL, root_layer, scroll_layer, |
| 49 NULL); |
| 49 PostSetNeedsCommitToMainThread(); | 50 PostSetNeedsCommitToMainThread(); |
| 50 } | 51 } |
| 51 | 52 |
| 52 void Layout() override { | 53 void Layout() override { |
| 53 Layer* root = layer_tree_host()->root_layer(); | 54 Layer* root = layer_tree_host()->root_layer(); |
| 54 Layer* scroll_layer = root->children()[0].get(); | 55 Layer* scroll_layer = root->children()[0].get(); |
| 55 if (!layer_tree_host()->source_frame_number()) { | 56 if (!layer_tree_host()->source_frame_number()) { |
| 56 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset()); | 57 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset()); |
| 57 } else { | 58 } else { |
| 58 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(initial_scroll_, | 59 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(initial_scroll_, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 Layer* root_layer = layer_tree_host()->root_layer(); | 116 Layer* root_layer = layer_tree_host()->root_layer(); |
| 116 scroll_layer_ = Layer::Create(); | 117 scroll_layer_ = Layer::Create(); |
| 117 root_layer->AddChild(scroll_layer_); | 118 root_layer->AddChild(scroll_layer_); |
| 118 // Create an effective max_scroll_offset of (100, 100). | 119 // Create an effective max_scroll_offset of (100, 100). |
| 119 scroll_layer_->SetBounds(gfx::Size(root_layer->bounds().width() + 100, | 120 scroll_layer_->SetBounds(gfx::Size(root_layer->bounds().width() + 100, |
| 120 root_layer->bounds().height() + 100)); | 121 root_layer->bounds().height() + 100)); |
| 121 scroll_layer_->SetIsDrawable(true); | 122 scroll_layer_->SetIsDrawable(true); |
| 122 scroll_layer_->SetIsContainerForFixedPositionLayers(true); | 123 scroll_layer_->SetIsContainerForFixedPositionLayers(true); |
| 123 scroll_layer_->SetScrollClipLayerId(root_layer->id()); | 124 scroll_layer_->SetScrollClipLayerId(root_layer->id()); |
| 124 scroll_layer_->SetScrollOffset(initial_scroll_); | 125 scroll_layer_->SetScrollOffset(initial_scroll_); |
| 125 layer_tree_host()->RegisterViewportLayers(root_layer, scroll_layer_, NULL); | 126 layer_tree_host()->RegisterViewportLayers(NULL, root_layer, scroll_layer_, |
| 127 NULL); |
| 126 PostSetNeedsCommitToMainThread(); | 128 PostSetNeedsCommitToMainThread(); |
| 127 } | 129 } |
| 128 | 130 |
| 129 void BeginCommitOnThread(LayerTreeHostImpl* impl) override { | 131 void BeginCommitOnThread(LayerTreeHostImpl* impl) override { |
| 130 switch (layer_tree_host()->source_frame_number()) { | 132 switch (layer_tree_host()->source_frame_number()) { |
| 131 case 0: | 133 case 0: |
| 132 EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), initial_scroll_); | 134 EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), initial_scroll_); |
| 133 break; | 135 break; |
| 134 case 1: | 136 case 1: |
| 135 EXPECT_VECTOR_EQ( | 137 EXPECT_VECTOR_EQ( |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 LayerTreeHostScrollTest::SetupTree(); | 219 LayerTreeHostScrollTest::SetupTree(); |
| 218 Layer* root_layer = layer_tree_host()->root_layer(); | 220 Layer* root_layer = layer_tree_host()->root_layer(); |
| 219 scoped_refptr<Layer> root_scroll_layer = Layer::Create(); | 221 scoped_refptr<Layer> root_scroll_layer = Layer::Create(); |
| 220 root_scroll_layer->SetScrollClipLayerId(root_layer->id()); | 222 root_scroll_layer->SetScrollClipLayerId(root_layer->id()); |
| 221 root_scroll_layer->SetScrollOffset(initial_scroll_); | 223 root_scroll_layer->SetScrollOffset(initial_scroll_); |
| 222 root_scroll_layer->SetBounds(gfx::Size(200, 200)); | 224 root_scroll_layer->SetBounds(gfx::Size(200, 200)); |
| 223 root_scroll_layer->SetIsDrawable(true); | 225 root_scroll_layer->SetIsDrawable(true); |
| 224 root_scroll_layer->SetIsContainerForFixedPositionLayers(true); | 226 root_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 225 root_layer->AddChild(root_scroll_layer); | 227 root_layer->AddChild(root_scroll_layer); |
| 226 | 228 |
| 227 layer_tree_host()->RegisterViewportLayers( | 229 layer_tree_host()->RegisterViewportLayers(NULL, root_layer, |
| 228 root_layer, root_scroll_layer, NULL); | 230 root_scroll_layer, NULL); |
| 229 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); | 231 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); |
| 230 } | 232 } |
| 231 | 233 |
| 232 void WillBeginMainFrame() override { | 234 void WillBeginMainFrame() override { |
| 233 num_will_begin_main_frames_++; | 235 num_will_begin_main_frames_++; |
| 234 Layer* root_scroll_layer = | 236 Layer* root_scroll_layer = |
| 235 layer_tree_host()->root_layer()->children()[0].get(); | 237 layer_tree_host()->root_layer()->children()[0].get(); |
| 236 switch (num_will_begin_main_frames_) { | 238 switch (num_will_begin_main_frames_) { |
| 237 case 1: | 239 case 1: |
| 238 // This will not be aborted because of the initial prop changes. | 240 // This will not be aborted because of the initial prop changes. |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 Layer* root_layer = layer_tree_host()->root_layer(); | 402 Layer* root_layer = layer_tree_host()->root_layer(); |
| 401 scoped_refptr<Layer> root_scroll_layer = Layer::Create(); | 403 scoped_refptr<Layer> root_scroll_layer = Layer::Create(); |
| 402 root_scroll_layer->SetScrollClipLayerId(root_layer->id()); | 404 root_scroll_layer->SetScrollClipLayerId(root_layer->id()); |
| 403 root_scroll_layer->SetBounds( | 405 root_scroll_layer->SetBounds( |
| 404 gfx::Size(root_layer->bounds().width() + 100, | 406 gfx::Size(root_layer->bounds().width() + 100, |
| 405 root_layer->bounds().height() + 100)); | 407 root_layer->bounds().height() + 100)); |
| 406 root_scroll_layer->SetIsDrawable(true); | 408 root_scroll_layer->SetIsDrawable(true); |
| 407 root_scroll_layer->SetIsContainerForFixedPositionLayers(true); | 409 root_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 408 root_layer->AddChild(root_scroll_layer); | 410 root_layer->AddChild(root_scroll_layer); |
| 409 | 411 |
| 410 layer_tree_host()->RegisterViewportLayers( | 412 layer_tree_host()->RegisterViewportLayers(NULL, root_layer, |
| 411 root_layer, root_scroll_layer, NULL); | 413 root_scroll_layer, NULL); |
| 412 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); | 414 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); |
| 413 } | 415 } |
| 414 | 416 |
| 415 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 417 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 416 | 418 |
| 417 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | 419 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| 418 LayerImpl* root = impl->active_tree()->root_layer(); | 420 LayerImpl* root = impl->active_tree()->root_layer(); |
| 419 LayerImpl* scroll_layer = root->children()[0]; | 421 LayerImpl* scroll_layer = root->children()[0]; |
| 420 | 422 |
| 421 // Check that a fractional scroll delta is correctly accumulated over | 423 // Check that a fractional scroll delta is correctly accumulated over |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 expected_scroll_layer_ = child_layer_; | 505 expected_scroll_layer_ = child_layer_; |
| 504 expected_no_scroll_layer_ = root_scroll_layer_; | 506 expected_no_scroll_layer_ = root_scroll_layer_; |
| 505 } else { | 507 } else { |
| 506 expected_scroll_layer_ = root_scroll_layer_; | 508 expected_scroll_layer_ = root_scroll_layer_; |
| 507 expected_no_scroll_layer_ = child_layer_; | 509 expected_no_scroll_layer_ = child_layer_; |
| 508 } | 510 } |
| 509 | 511 |
| 510 expected_scroll_layer_->SetScrollOffset(initial_offset_); | 512 expected_scroll_layer_->SetScrollOffset(initial_offset_); |
| 511 | 513 |
| 512 layer_tree_host()->SetRootLayer(root_layer); | 514 layer_tree_host()->SetRootLayer(root_layer); |
| 513 layer_tree_host()->RegisterViewportLayers( | 515 layer_tree_host()->RegisterViewportLayers(NULL, root_layer, |
| 514 root_layer, root_scroll_layer_, NULL); | 516 root_scroll_layer_, NULL); |
| 515 LayerTreeHostScrollTest::SetupTree(); | 517 LayerTreeHostScrollTest::SetupTree(); |
| 516 } | 518 } |
| 517 | 519 |
| 518 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 520 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 519 | 521 |
| 520 void WillCommit() override { | 522 void WillCommit() override { |
| 521 // Keep the test committing (otherwise the early out for no update | 523 // Keep the test committing (otherwise the early out for no update |
| 522 // will stall the test). | 524 // will stall the test). |
| 523 if (layer_tree_host()->source_frame_number() < 2) { | 525 if (layer_tree_host()->source_frame_number() < 2) { |
| 524 layer_tree_host()->SetNeedsCommit(); | 526 layer_tree_host()->SetNeedsCommit(); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 scoped_refptr<Layer> root_scroll_layer = Layer::Create(); | 774 scoped_refptr<Layer> root_scroll_layer = Layer::Create(); |
| 773 root_scroll_layer->SetScrollClipLayerId(root_layer->id()); | 775 root_scroll_layer->SetScrollClipLayerId(root_layer->id()); |
| 774 root_scroll_layer->SetScrollOffset(initial_scroll_); | 776 root_scroll_layer->SetScrollOffset(initial_scroll_); |
| 775 root_scroll_layer->SetBounds( | 777 root_scroll_layer->SetBounds( |
| 776 gfx::Size(root_layer->bounds().width() + 100, | 778 gfx::Size(root_layer->bounds().width() + 100, |
| 777 root_layer->bounds().height() + 100)); | 779 root_layer->bounds().height() + 100)); |
| 778 root_scroll_layer->SetIsDrawable(true); | 780 root_scroll_layer->SetIsDrawable(true); |
| 779 root_scroll_layer->SetIsContainerForFixedPositionLayers(true); | 781 root_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 780 root_layer->AddChild(root_scroll_layer); | 782 root_layer->AddChild(root_scroll_layer); |
| 781 | 783 |
| 782 layer_tree_host()->RegisterViewportLayers( | 784 layer_tree_host()->RegisterViewportLayers(NULL, root_layer, |
| 783 root_layer, root_scroll_layer, NULL); | 785 root_scroll_layer, NULL); |
| 784 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); | 786 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); |
| 785 } | 787 } |
| 786 | 788 |
| 787 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 789 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 788 | 790 |
| 789 void Layout() override { | 791 void Layout() override { |
| 790 Layer* root = layer_tree_host()->root_layer(); | 792 Layer* root = layer_tree_host()->root_layer(); |
| 791 Layer* scroll_layer = root->children()[0].get(); | 793 Layer* scroll_layer = root->children()[0].get(); |
| 792 if (!layer_tree_host()->source_frame_number()) { | 794 if (!layer_tree_host()->source_frame_number()) { |
| 793 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); | 795 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 scoped_refptr<Layer> root_scroll_layer = Layer::Create(); | 905 scoped_refptr<Layer> root_scroll_layer = Layer::Create(); |
| 904 root_scroll_layer->SetScrollClipLayerId(root_layer->id()); | 906 root_scroll_layer->SetScrollClipLayerId(root_layer->id()); |
| 905 root_scroll_layer->SetScrollOffset(initial_scroll_); | 907 root_scroll_layer->SetScrollOffset(initial_scroll_); |
| 906 root_scroll_layer->SetBounds( | 908 root_scroll_layer->SetBounds( |
| 907 gfx::Size(root_layer->bounds().width() + 100, | 909 gfx::Size(root_layer->bounds().width() + 100, |
| 908 root_layer->bounds().height() + 100)); | 910 root_layer->bounds().height() + 100)); |
| 909 root_scroll_layer->SetIsDrawable(true); | 911 root_scroll_layer->SetIsDrawable(true); |
| 910 root_scroll_layer->SetIsContainerForFixedPositionLayers(true); | 912 root_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 911 root_layer->AddChild(root_scroll_layer); | 913 root_layer->AddChild(root_scroll_layer); |
| 912 | 914 |
| 913 layer_tree_host()->RegisterViewportLayers( | 915 layer_tree_host()->RegisterViewportLayers(NULL, root_layer, |
| 914 root_layer, root_scroll_layer, NULL); | 916 root_scroll_layer, NULL); |
| 915 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); | 917 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); |
| 916 } | 918 } |
| 917 | 919 |
| 918 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 920 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 919 | 921 |
| 920 void WillCommit() override { | 922 void WillCommit() override { |
| 921 Layer* root = layer_tree_host()->root_layer(); | 923 Layer* root = layer_tree_host()->root_layer(); |
| 922 Layer* scroll_layer = root->children()[0].get(); | 924 Layer* scroll_layer = root->children()[0].get(); |
| 923 switch (layer_tree_host()->source_frame_number()) { | 925 switch (layer_tree_host()->source_frame_number()) { |
| 924 case 0: | 926 case 0: |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1225 RunTest(true, false, true); | 1227 RunTest(true, false, true); |
| 1226 } | 1228 } |
| 1227 | 1229 |
| 1228 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { | 1230 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { |
| 1229 scroll_destroy_whole_tree_ = true; | 1231 scroll_destroy_whole_tree_ = true; |
| 1230 RunTest(true, false, true); | 1232 RunTest(true, false, true); |
| 1231 } | 1233 } |
| 1232 | 1234 |
| 1233 } // namespace | 1235 } // namespace |
| 1234 } // namespace cc | 1236 } // namespace cc |
| OLD | NEW |