| OLD | NEW |
| 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/layers/layer_impl.h" | 5 #include "cc/layers/layer_impl.h" |
| 6 | 6 |
| 7 #include "cc/animation/mutable_properties.h" | 7 #include "cc/animation/mutable_properties.h" |
| 8 #include "cc/layers/painted_scrollbar_layer_impl.h" | 8 #include "cc/layers/painted_scrollbar_layer_impl.h" |
| 9 #include "cc/layers/solid_color_scrollbar_layer_impl.h" | 9 #include "cc/layers/solid_color_scrollbar_layer_impl.h" |
| 10 #include "cc/output/filter_operation.h" | 10 #include "cc/output/filter_operation.h" |
| 11 #include "cc/output/filter_operations.h" | 11 #include "cc/output/filter_operations.h" |
| 12 #include "cc/test/animation_test_common.h" | 12 #include "cc/test/animation_test_common.h" |
| 13 #include "cc/test/fake_compositor_frame_sink.h" | 13 #include "cc/test/fake_compositor_frame_sink.h" |
| 14 #include "cc/test/fake_impl_task_runner_provider.h" | 14 #include "cc/test/fake_impl_task_runner_provider.h" |
| 15 #include "cc/test/fake_layer_tree_host_impl.h" | 15 #include "cc/test/fake_layer_tree_host_impl.h" |
| 16 #include "cc/test/geometry_test_utils.h" | 16 #include "cc/test/geometry_test_utils.h" |
| 17 #include "cc/test/test_shared_bitmap_manager.h" | |
| 18 #include "cc/test/test_task_graph_runner.h" | 17 #include "cc/test/test_task_graph_runner.h" |
| 19 #include "cc/trees/layer_tree_impl.h" | 18 #include "cc/trees/layer_tree_impl.h" |
| 20 #include "cc/trees/single_thread_proxy.h" | 19 #include "cc/trees/single_thread_proxy.h" |
| 21 #include "cc/trees/tree_synchronizer.h" | 20 #include "cc/trees/tree_synchronizer.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 24 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 23 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
| 25 | 24 |
| 26 namespace cc { | 25 namespace cc { |
| 27 namespace { | 26 namespace { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 116 } |
| 118 | 117 |
| 119 TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) { | 118 TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) { |
| 120 // | 119 // |
| 121 // This test checks that layerPropertyChanged() has the correct behavior. | 120 // This test checks that layerPropertyChanged() has the correct behavior. |
| 122 // | 121 // |
| 123 | 122 |
| 124 // The constructor on this will fake that we are on the correct thread. | 123 // The constructor on this will fake that we are on the correct thread. |
| 125 // Create a simple LayerImpl tree: | 124 // Create a simple LayerImpl tree: |
| 126 FakeImplTaskRunnerProvider task_runner_provider; | 125 FakeImplTaskRunnerProvider task_runner_provider; |
| 127 TestSharedBitmapManager shared_bitmap_manager; | |
| 128 TestTaskGraphRunner task_graph_runner; | 126 TestTaskGraphRunner task_graph_runner; |
| 129 std::unique_ptr<CompositorFrameSink> compositor_frame_sink = | 127 std::unique_ptr<CompositorFrameSink> compositor_frame_sink = |
| 130 FakeCompositorFrameSink::Create3d(); | 128 FakeCompositorFrameSink::Create3d(); |
| 131 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | 129 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
| 132 &task_graph_runner); | |
| 133 host_impl.SetVisible(true); | 130 host_impl.SetVisible(true); |
| 134 EXPECT_TRUE(host_impl.InitializeRenderer(compositor_frame_sink.get())); | 131 EXPECT_TRUE(host_impl.InitializeRenderer(compositor_frame_sink.get())); |
| 135 std::unique_ptr<LayerImpl> root_clip_ptr = | 132 std::unique_ptr<LayerImpl> root_clip_ptr = |
| 136 LayerImpl::Create(host_impl.active_tree(), 1); | 133 LayerImpl::Create(host_impl.active_tree(), 1); |
| 137 LayerImpl* root_clip = root_clip_ptr.get(); | 134 LayerImpl* root_clip = root_clip_ptr.get(); |
| 138 std::unique_ptr<LayerImpl> root_ptr = | 135 std::unique_ptr<LayerImpl> root_ptr = |
| 139 LayerImpl::Create(host_impl.active_tree(), 2); | 136 LayerImpl::Create(host_impl.active_tree(), 2); |
| 140 LayerImpl* root = root_ptr.get(); | 137 LayerImpl* root = root_ptr.get(); |
| 141 root_clip_ptr->test_properties()->AddChild(std::move(root_ptr)); | 138 root_clip_ptr->test_properties()->AddChild(std::move(root_ptr)); |
| 142 host_impl.active_tree()->SetRootLayerForTesting(std::move(root_clip_ptr)); | 139 host_impl.active_tree()->SetRootLayerForTesting(std::move(root_clip_ptr)); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( | 234 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( |
| 238 root->SetPosition(arbitrary_point_f)); | 235 root->SetPosition(arbitrary_point_f)); |
| 239 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->Set3dSortingContextId(1)); | 236 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->Set3dSortingContextId(1)); |
| 240 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetContentsOpaque(true)); | 237 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetContentsOpaque(true)); |
| 241 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetDrawsContent(true)); | 238 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetDrawsContent(true)); |
| 242 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetBounds(bounds_size)); | 239 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetBounds(bounds_size)); |
| 243 } | 240 } |
| 244 | 241 |
| 245 TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) { | 242 TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) { |
| 246 FakeImplTaskRunnerProvider task_runner_provider; | 243 FakeImplTaskRunnerProvider task_runner_provider; |
| 247 TestSharedBitmapManager shared_bitmap_manager; | |
| 248 TestTaskGraphRunner task_graph_runner; | 244 TestTaskGraphRunner task_graph_runner; |
| 249 std::unique_ptr<CompositorFrameSink> compositor_frame_sink = | 245 std::unique_ptr<CompositorFrameSink> compositor_frame_sink = |
| 250 FakeCompositorFrameSink::Create3d(); | 246 FakeCompositorFrameSink::Create3d(); |
| 251 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | 247 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
| 252 &task_graph_runner); | |
| 253 host_impl.SetVisible(true); | 248 host_impl.SetVisible(true); |
| 254 EXPECT_TRUE(host_impl.InitializeRenderer(compositor_frame_sink.get())); | 249 EXPECT_TRUE(host_impl.InitializeRenderer(compositor_frame_sink.get())); |
| 255 host_impl.active_tree()->SetRootLayerForTesting( | 250 host_impl.active_tree()->SetRootLayerForTesting( |
| 256 LayerImpl::Create(host_impl.active_tree(), 1)); | 251 LayerImpl::Create(host_impl.active_tree(), 1)); |
| 257 LayerImpl* root = host_impl.active_tree()->root_layer_for_testing(); | 252 LayerImpl* root = host_impl.active_tree()->root_layer_for_testing(); |
| 258 root->SetHasRenderSurface(true); | 253 root->SetHasRenderSurface(true); |
| 259 std::unique_ptr<LayerImpl> layer_ptr = | 254 std::unique_ptr<LayerImpl> layer_ptr = |
| 260 LayerImpl::Create(host_impl.active_tree(), 2); | 255 LayerImpl::Create(host_impl.active_tree(), 2); |
| 261 LayerImpl* layer = layer_ptr.get(); | 256 LayerImpl* layer = layer_ptr.get(); |
| 262 root->test_properties()->AddChild(std::move(layer_ptr)); | 257 root->test_properties()->AddChild(std::move(layer_ptr)); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( | 362 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( |
| 368 layer->SetBackgroundColor(arbitrary_color)); | 363 layer->SetBackgroundColor(arbitrary_color)); |
| 369 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(arbitrary_size)); | 364 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(arbitrary_size)); |
| 370 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetElementId(ElementId(2, 0))); | 365 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetElementId(ElementId(2, 0))); |
| 371 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( | 366 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( |
| 372 layer->SetMutableProperties(MutableProperty::kTransform)); | 367 layer->SetMutableProperties(MutableProperty::kTransform)); |
| 373 } | 368 } |
| 374 | 369 |
| 375 TEST(LayerImplTest, SafeOpaqueBackgroundColor) { | 370 TEST(LayerImplTest, SafeOpaqueBackgroundColor) { |
| 376 FakeImplTaskRunnerProvider task_runner_provider; | 371 FakeImplTaskRunnerProvider task_runner_provider; |
| 377 TestSharedBitmapManager shared_bitmap_manager; | |
| 378 TestTaskGraphRunner task_graph_runner; | 372 TestTaskGraphRunner task_graph_runner; |
| 379 std::unique_ptr<CompositorFrameSink> compositor_frame_sink = | 373 std::unique_ptr<CompositorFrameSink> compositor_frame_sink = |
| 380 FakeCompositorFrameSink::Create3d(); | 374 FakeCompositorFrameSink::Create3d(); |
| 381 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | 375 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
| 382 &task_graph_runner); | |
| 383 host_impl.SetVisible(true); | 376 host_impl.SetVisible(true); |
| 384 EXPECT_TRUE(host_impl.InitializeRenderer(compositor_frame_sink.get())); | 377 EXPECT_TRUE(host_impl.InitializeRenderer(compositor_frame_sink.get())); |
| 385 host_impl.active_tree()->SetRootLayerForTesting( | 378 host_impl.active_tree()->SetRootLayerForTesting( |
| 386 LayerImpl::Create(host_impl.active_tree(), 1)); | 379 LayerImpl::Create(host_impl.active_tree(), 1)); |
| 387 LayerImpl* layer = host_impl.active_tree()->root_layer_for_testing(); | 380 LayerImpl* layer = host_impl.active_tree()->root_layer_for_testing(); |
| 388 | 381 |
| 389 for (int contents_opaque = 0; contents_opaque < 2; ++contents_opaque) { | 382 for (int contents_opaque = 0; contents_opaque < 2; ++contents_opaque) { |
| 390 for (int layer_opaque = 0; layer_opaque < 2; ++layer_opaque) { | 383 for (int layer_opaque = 0; layer_opaque < 2; ++layer_opaque) { |
| 391 for (int host_opaque = 0; host_opaque < 2; ++host_opaque) { | 384 for (int host_opaque = 0; host_opaque < 2; ++host_opaque) { |
| 392 layer->SetContentsOpaque(!!contents_opaque); | 385 layer->SetContentsOpaque(!!contents_opaque); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 410 } | 403 } |
| 411 } | 404 } |
| 412 } | 405 } |
| 413 } | 406 } |
| 414 | 407 |
| 415 class LayerImplScrollTest : public testing::Test { | 408 class LayerImplScrollTest : public testing::Test { |
| 416 public: | 409 public: |
| 417 LayerImplScrollTest() | 410 LayerImplScrollTest() |
| 418 : host_impl_(settings(), | 411 : host_impl_(settings(), |
| 419 &task_runner_provider_, | 412 &task_runner_provider_, |
| 420 &shared_bitmap_manager_, | |
| 421 &task_graph_runner_), | 413 &task_graph_runner_), |
| 422 root_id_(7) { | 414 root_id_(7) { |
| 423 host_impl_.active_tree()->SetRootLayerForTesting( | 415 host_impl_.active_tree()->SetRootLayerForTesting( |
| 424 LayerImpl::Create(host_impl_.active_tree(), root_id_)); | 416 LayerImpl::Create(host_impl_.active_tree(), root_id_)); |
| 425 host_impl_.active_tree() | 417 host_impl_.active_tree() |
| 426 ->root_layer_for_testing() | 418 ->root_layer_for_testing() |
| 427 ->test_properties() | 419 ->test_properties() |
| 428 ->AddChild(LayerImpl::Create(host_impl_.active_tree(), root_id_ + 1)); | 420 ->AddChild(LayerImpl::Create(host_impl_.active_tree(), root_id_ + 1)); |
| 429 layer()->SetScrollClipLayer(root_id_); | 421 layer()->SetScrollClipLayer(root_id_); |
| 430 // Set the max scroll offset by noting that the root layer has bounds (1,1), | 422 // Set the max scroll offset by noting that the root layer has bounds (1,1), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 453 LayerTreeImpl* tree() { return host_impl_.active_tree(); } | 445 LayerTreeImpl* tree() { return host_impl_.active_tree(); } |
| 454 | 446 |
| 455 LayerTreeSettings settings() { | 447 LayerTreeSettings settings() { |
| 456 LayerTreeSettings settings; | 448 LayerTreeSettings settings; |
| 457 settings.verify_clip_tree_calculations = true; | 449 settings.verify_clip_tree_calculations = true; |
| 458 return settings; | 450 return settings; |
| 459 } | 451 } |
| 460 | 452 |
| 461 private: | 453 private: |
| 462 FakeImplTaskRunnerProvider task_runner_provider_; | 454 FakeImplTaskRunnerProvider task_runner_provider_; |
| 463 TestSharedBitmapManager shared_bitmap_manager_; | |
| 464 TestTaskGraphRunner task_graph_runner_; | 455 TestTaskGraphRunner task_graph_runner_; |
| 465 FakeLayerTreeHostImpl host_impl_; | 456 FakeLayerTreeHostImpl host_impl_; |
| 466 int root_id_; | 457 int root_id_; |
| 467 }; | 458 }; |
| 468 | 459 |
| 469 TEST_F(LayerImplScrollTest, ScrollByWithZeroOffset) { | 460 TEST_F(LayerImplScrollTest, ScrollByWithZeroOffset) { |
| 470 // Test that LayerImpl::ScrollBy only affects ScrollDelta and total scroll | 461 // Test that LayerImpl::ScrollBy only affects ScrollDelta and total scroll |
| 471 // offset is bounded by the range [0, max scroll offset]. | 462 // offset is bounded by the range [0, max scroll offset]. |
| 472 | 463 |
| 473 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->CurrentScrollOffset()); | 464 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->CurrentScrollOffset()); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 | 583 |
| 593 pending_layer->PushPropertiesTo(layer()); | 584 pending_layer->PushPropertiesTo(layer()); |
| 594 | 585 |
| 595 EXPECT_VECTOR_EQ(gfx::Vector2dF(22, 23), layer()->CurrentScrollOffset()); | 586 EXPECT_VECTOR_EQ(gfx::Vector2dF(22, 23), layer()->CurrentScrollOffset()); |
| 596 EXPECT_VECTOR_EQ(layer()->CurrentScrollOffset(), | 587 EXPECT_VECTOR_EQ(layer()->CurrentScrollOffset(), |
| 597 pending_layer->CurrentScrollOffset()); | 588 pending_layer->CurrentScrollOffset()); |
| 598 } | 589 } |
| 599 | 590 |
| 600 } // namespace | 591 } // namespace |
| 601 } // namespace cc | 592 } // namespace cc |
| OLD | NEW |