| 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/layers/painted_scrollbar_layer_impl.h" | 7 #include "cc/layers/painted_scrollbar_layer_impl.h" |
| 8 #include "cc/layers/solid_color_scrollbar_layer_impl.h" | 8 #include "cc/layers/solid_color_scrollbar_layer_impl.h" |
| 9 #include "cc/output/filter_operation.h" | 9 #include "cc/output/filter_operation.h" |
| 10 #include "cc/output/filter_operations.h" | 10 #include "cc/output/filter_operations.h" |
| 11 #include "cc/test/fake_impl_proxy.h" | 11 #include "cc/test/fake_impl_task_runner_provider.h" |
| 12 #include "cc/test/fake_layer_tree_host_impl.h" | 12 #include "cc/test/fake_layer_tree_host_impl.h" |
| 13 #include "cc/test/fake_output_surface.h" | 13 #include "cc/test/fake_output_surface.h" |
| 14 #include "cc/test/geometry_test_utils.h" | 14 #include "cc/test/geometry_test_utils.h" |
| 15 #include "cc/test/test_shared_bitmap_manager.h" | 15 #include "cc/test/test_shared_bitmap_manager.h" |
| 16 #include "cc/test/test_task_graph_runner.h" | 16 #include "cc/test/test_task_graph_runner.h" |
| 17 #include "cc/trees/layer_tree_impl.h" | 17 #include "cc/trees/layer_tree_impl.h" |
| 18 #include "cc/trees/single_thread_proxy.h" | 18 #include "cc/trees/single_thread_proxy.h" |
| 19 #include "cc/trees/tree_synchronizer.h" | 19 #include "cc/trees/tree_synchronizer.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 code_to_test; \ | 79 code_to_test; \ |
| 80 EXPECT_FALSE(host_impl.active_tree()->needs_update_draw_properties()); | 80 EXPECT_FALSE(host_impl.active_tree()->needs_update_draw_properties()); |
| 81 | 81 |
| 82 TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) { | 82 TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) { |
| 83 // | 83 // |
| 84 // This test checks that layerPropertyChanged() has the correct behavior. | 84 // This test checks that layerPropertyChanged() has the correct behavior. |
| 85 // | 85 // |
| 86 | 86 |
| 87 // The constructor on this will fake that we are on the correct thread. | 87 // The constructor on this will fake that we are on the correct thread. |
| 88 // Create a simple LayerImpl tree: | 88 // Create a simple LayerImpl tree: |
| 89 FakeImplProxy proxy; | 89 FakeImplTaskRunnerProvider task_runner_provider; |
| 90 TestSharedBitmapManager shared_bitmap_manager; | 90 TestSharedBitmapManager shared_bitmap_manager; |
| 91 TestTaskGraphRunner task_graph_runner; | 91 TestTaskGraphRunner task_graph_runner; |
| 92 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); | 92 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); |
| 93 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, | 93 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
| 94 &task_graph_runner); | 94 &task_graph_runner); |
| 95 host_impl.SetVisible(true); | 95 host_impl.SetVisible(true); |
| 96 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); | 96 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); |
| 97 scoped_ptr<LayerImpl> root_clip = | 97 scoped_ptr<LayerImpl> root_clip = |
| 98 LayerImpl::Create(host_impl.active_tree(), 1); | 98 LayerImpl::Create(host_impl.active_tree(), 1); |
| 99 scoped_ptr<LayerImpl> root_ptr = | 99 scoped_ptr<LayerImpl> root_ptr = |
| 100 LayerImpl::Create(host_impl.active_tree(), 2); | 100 LayerImpl::Create(host_impl.active_tree(), 2); |
| 101 LayerImpl* root = root_ptr.get(); | 101 LayerImpl* root = root_ptr.get(); |
| 102 root_clip->AddChild(root_ptr.Pass()); | 102 root_clip->AddChild(root_ptr.Pass()); |
| 103 scoped_ptr<LayerImpl> scroll_parent = | 103 scoped_ptr<LayerImpl> scroll_parent = |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 root->SetScrollParent(scroll_parent.get())); | 239 root->SetScrollParent(scroll_parent.get())); |
| 240 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( | 240 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( |
| 241 root->SetScrollChildren(scroll_children)); | 241 root->SetScrollChildren(scroll_children)); |
| 242 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( | 242 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( |
| 243 root->SetClipParent(clip_parent.get())); | 243 root->SetClipParent(clip_parent.get())); |
| 244 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( | 244 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( |
| 245 root->SetClipChildren(clip_children)); | 245 root->SetClipChildren(clip_children)); |
| 246 } | 246 } |
| 247 | 247 |
| 248 TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) { | 248 TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) { |
| 249 FakeImplProxy proxy; | 249 FakeImplTaskRunnerProvider task_runner_provider; |
| 250 TestSharedBitmapManager shared_bitmap_manager; | 250 TestSharedBitmapManager shared_bitmap_manager; |
| 251 TestTaskGraphRunner task_graph_runner; | 251 TestTaskGraphRunner task_graph_runner; |
| 252 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); | 252 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); |
| 253 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, | 253 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
| 254 &task_graph_runner); | 254 &task_graph_runner); |
| 255 host_impl.SetVisible(true); | 255 host_impl.SetVisible(true); |
| 256 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); | 256 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); |
| 257 host_impl.active_tree()->SetRootLayer( | 257 host_impl.active_tree()->SetRootLayer( |
| 258 LayerImpl::Create(host_impl.active_tree(), 1)); | 258 LayerImpl::Create(host_impl.active_tree(), 1)); |
| 259 LayerImpl* root = host_impl.active_tree()->root_layer(); | 259 LayerImpl* root = host_impl.active_tree()->root_layer(); |
| 260 root->SetHasRenderSurface(true); | 260 root->SetHasRenderSurface(true); |
| 261 scoped_ptr<LayerImpl> layer_ptr = | 261 scoped_ptr<LayerImpl> layer_ptr = |
| 262 LayerImpl::Create(host_impl.active_tree(), 2); | 262 LayerImpl::Create(host_impl.active_tree(), 2); |
| 263 LayerImpl* layer = layer_ptr.get(); | 263 LayerImpl* layer = layer_ptr.get(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( | 355 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( |
| 356 layer->SetBlendMode(arbitrary_blend_mode)); | 356 layer->SetBlendMode(arbitrary_blend_mode)); |
| 357 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( | 357 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( |
| 358 layer->SetIsRootForIsolatedGroup(true)); | 358 layer->SetIsRootForIsolatedGroup(true)); |
| 359 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( | 359 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( |
| 360 layer->SetTransform(arbitrary_transform)); | 360 layer->SetTransform(arbitrary_transform)); |
| 361 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(arbitrary_size)); | 361 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(arbitrary_size)); |
| 362 } | 362 } |
| 363 | 363 |
| 364 TEST(LayerImplTest, SafeOpaqueBackgroundColor) { | 364 TEST(LayerImplTest, SafeOpaqueBackgroundColor) { |
| 365 FakeImplProxy proxy; | 365 FakeImplTaskRunnerProvider task_runner_provider; |
| 366 TestSharedBitmapManager shared_bitmap_manager; | 366 TestSharedBitmapManager shared_bitmap_manager; |
| 367 TestTaskGraphRunner task_graph_runner; | 367 TestTaskGraphRunner task_graph_runner; |
| 368 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); | 368 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); |
| 369 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, | 369 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
| 370 &task_graph_runner); | 370 &task_graph_runner); |
| 371 host_impl.SetVisible(true); | 371 host_impl.SetVisible(true); |
| 372 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); | 372 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); |
| 373 scoped_ptr<LayerImpl> layer = LayerImpl::Create(host_impl.active_tree(), 1); | 373 scoped_ptr<LayerImpl> layer = LayerImpl::Create(host_impl.active_tree(), 1); |
| 374 | 374 |
| 375 for (int contents_opaque = 0; contents_opaque < 2; ++contents_opaque) { | 375 for (int contents_opaque = 0; contents_opaque < 2; ++contents_opaque) { |
| 376 for (int layer_opaque = 0; layer_opaque < 2; ++layer_opaque) { | 376 for (int layer_opaque = 0; layer_opaque < 2; ++layer_opaque) { |
| 377 for (int host_opaque = 0; host_opaque < 2; ++host_opaque) { | 377 for (int host_opaque = 0; host_opaque < 2; ++host_opaque) { |
| 378 layer->SetContentsOpaque(!!contents_opaque); | 378 layer->SetContentsOpaque(!!contents_opaque); |
| 379 layer->SetBackgroundColor(layer_opaque ? SK_ColorRED | 379 layer->SetBackgroundColor(layer_opaque ? SK_ColorRED |
| (...skipping 10 matching lines...) Expand all Loading... |
| 390 EXPECT_NE(SkColorGetA(safe_color), 255u) | 390 EXPECT_NE(SkColorGetA(safe_color), 255u) |
| 391 << "Flags: " << contents_opaque << ", " << layer_opaque << ", " | 391 << "Flags: " << contents_opaque << ", " << layer_opaque << ", " |
| 392 << host_opaque << "\n"; | 392 << host_opaque << "\n"; |
| 393 } | 393 } |
| 394 } | 394 } |
| 395 } | 395 } |
| 396 } | 396 } |
| 397 } | 397 } |
| 398 | 398 |
| 399 TEST(LayerImplTest, TransformInvertibility) { | 399 TEST(LayerImplTest, TransformInvertibility) { |
| 400 FakeImplProxy proxy; | 400 FakeImplTaskRunnerProvider task_runner_provider; |
| 401 TestSharedBitmapManager shared_bitmap_manager; | 401 TestSharedBitmapManager shared_bitmap_manager; |
| 402 TestTaskGraphRunner task_graph_runner; | 402 TestTaskGraphRunner task_graph_runner; |
| 403 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, | 403 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
| 404 &task_graph_runner); | 404 &task_graph_runner); |
| 405 | 405 |
| 406 scoped_ptr<LayerImpl> layer = LayerImpl::Create(host_impl.active_tree(), 1); | 406 scoped_ptr<LayerImpl> layer = LayerImpl::Create(host_impl.active_tree(), 1); |
| 407 EXPECT_TRUE(layer->transform().IsInvertible()); | 407 EXPECT_TRUE(layer->transform().IsInvertible()); |
| 408 EXPECT_TRUE(layer->transform_is_invertible()); | 408 EXPECT_TRUE(layer->transform_is_invertible()); |
| 409 | 409 |
| 410 gfx::Transform transform; | 410 gfx::Transform transform; |
| 411 transform.Scale3d( | 411 transform.Scale3d( |
| 412 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); | 412 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 413 layer->SetTransform(transform); | 413 layer->SetTransform(transform); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 425 | 425 |
| 426 layer->SetTransform(transform); | 426 layer->SetTransform(transform); |
| 427 EXPECT_TRUE(layer->transform().IsInvertible()); | 427 EXPECT_TRUE(layer->transform().IsInvertible()); |
| 428 EXPECT_TRUE(layer->transform_is_invertible()); | 428 EXPECT_TRUE(layer->transform_is_invertible()); |
| 429 } | 429 } |
| 430 | 430 |
| 431 class LayerImplScrollTest : public testing::Test { | 431 class LayerImplScrollTest : public testing::Test { |
| 432 public: | 432 public: |
| 433 LayerImplScrollTest() | 433 LayerImplScrollTest() |
| 434 : host_impl_(settings(), | 434 : host_impl_(settings(), |
| 435 &proxy_, | 435 &task_runner_provider_, |
| 436 &shared_bitmap_manager_, | 436 &shared_bitmap_manager_, |
| 437 &task_graph_runner_), | 437 &task_graph_runner_), |
| 438 root_id_(7) { | 438 root_id_(7) { |
| 439 host_impl_.active_tree()->SetRootLayer( | 439 host_impl_.active_tree()->SetRootLayer( |
| 440 LayerImpl::Create(host_impl_.active_tree(), root_id_)); | 440 LayerImpl::Create(host_impl_.active_tree(), root_id_)); |
| 441 host_impl_.active_tree()->root_layer()->AddChild( | 441 host_impl_.active_tree()->root_layer()->AddChild( |
| 442 LayerImpl::Create(host_impl_.active_tree(), root_id_ + 1)); | 442 LayerImpl::Create(host_impl_.active_tree(), root_id_ + 1)); |
| 443 layer()->SetScrollClipLayer(root_id_); | 443 layer()->SetScrollClipLayer(root_id_); |
| 444 // Set the max scroll offset by noting that the root layer has bounds (1,1), | 444 // Set the max scroll offset by noting that the root layer has bounds (1,1), |
| 445 // thus whatever bounds are set for the layer will be the max scroll | 445 // thus whatever bounds are set for the layer will be the max scroll |
| (...skipping 10 matching lines...) Expand all Loading... |
| 456 LayerTreeHostImpl& host_impl() { return host_impl_; } | 456 LayerTreeHostImpl& host_impl() { return host_impl_; } |
| 457 | 457 |
| 458 LayerTreeImpl* tree() { return host_impl_.active_tree(); } | 458 LayerTreeImpl* tree() { return host_impl_.active_tree(); } |
| 459 | 459 |
| 460 LayerTreeSettings settings() { | 460 LayerTreeSettings settings() { |
| 461 LayerTreeSettings settings; | 461 LayerTreeSettings settings; |
| 462 return settings; | 462 return settings; |
| 463 } | 463 } |
| 464 | 464 |
| 465 private: | 465 private: |
| 466 FakeImplProxy proxy_; | 466 FakeImplTaskRunnerProvider task_runner_provider_; |
| 467 TestSharedBitmapManager shared_bitmap_manager_; | 467 TestSharedBitmapManager shared_bitmap_manager_; |
| 468 TestTaskGraphRunner task_graph_runner_; | 468 TestTaskGraphRunner task_graph_runner_; |
| 469 FakeLayerTreeHostImpl host_impl_; | 469 FakeLayerTreeHostImpl host_impl_; |
| 470 int root_id_; | 470 int root_id_; |
| 471 }; | 471 }; |
| 472 | 472 |
| 473 TEST_F(LayerImplScrollTest, ScrollByWithZeroOffset) { | 473 TEST_F(LayerImplScrollTest, ScrollByWithZeroOffset) { |
| 474 // Test that LayerImpl::ScrollBy only affects ScrollDelta and total scroll | 474 // Test that LayerImpl::ScrollBy only affects ScrollDelta and total scroll |
| 475 // offset is bounded by the range [0, max scroll offset]. | 475 // offset is bounded by the range [0, max scroll offset]. |
| 476 | 476 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 | 573 |
| 574 pending_layer->PushPropertiesTo(layer()); | 574 pending_layer->PushPropertiesTo(layer()); |
| 575 | 575 |
| 576 EXPECT_VECTOR_EQ(gfx::Vector2dF(22, 23), layer()->CurrentScrollOffset()); | 576 EXPECT_VECTOR_EQ(gfx::Vector2dF(22, 23), layer()->CurrentScrollOffset()); |
| 577 EXPECT_VECTOR_EQ(layer()->CurrentScrollOffset(), | 577 EXPECT_VECTOR_EQ(layer()->CurrentScrollOffset(), |
| 578 pending_layer->CurrentScrollOffset()); | 578 pending_layer->CurrentScrollOffset()); |
| 579 } | 579 } |
| 580 | 580 |
| 581 } // namespace | 581 } // namespace |
| 582 } // namespace cc | 582 } // namespace cc |
| OLD | NEW |