| 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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 auto mock_worker_context_provider = make_scoped_refptr( | 443 auto mock_worker_context_provider = make_scoped_refptr( |
| 444 new MockContextProvider(std::move(mock_worker_context_support_owned))); | 444 new MockContextProvider(std::move(mock_worker_context_support_owned))); |
| 445 mock_context_provider_ptr_ = mock_worker_context_provider.get(); | 445 mock_context_provider_ptr_ = mock_worker_context_provider.get(); |
| 446 | 446 |
| 447 // Workers are bound on the main thread. | 447 // Workers are bound on the main thread. |
| 448 mock_worker_context_provider->BindToCurrentThread(); | 448 mock_worker_context_provider->BindToCurrentThread(); |
| 449 | 449 |
| 450 // Ensure that our mock calls execute in sequence. | 450 // Ensure that our mock calls execute in sequence. |
| 451 ::testing::InSequence s; | 451 ::testing::InSequence s; |
| 452 | 452 |
| 453 // At init, visibility is set to true and we will call | 453 // At init, visibility is set to true. |
| 454 // SetAggressivelyFreeResources(false). | 454 EXPECT_CALL(*mock_context_support_ptr_, ClientBecameVisible()) |
| 455 EXPECT_CALL(*mock_context_support_ptr_, SetClientVisible(0, true)); | 455 .WillOnce( |
| 456 ::testing::Invoke(mock_context_support_ptr_, |
| 457 &MockContextSupport::SuperClientBecameVisible)); |
| 456 EXPECT_CALL(*mock_context_support_ptr_, AnyClientsVisible()) | 458 EXPECT_CALL(*mock_context_support_ptr_, AnyClientsVisible()) |
| 457 .WillOnce(::testing::Return(true)); | 459 .WillOnce(::testing::Return(true)); |
| 458 EXPECT_CALL(*mock_context_support_ptr_, | |
| 459 SetAggressivelyFreeResources(false)); | |
| 460 | 460 |
| 461 return LayerTreeHostTest::CreateDelegatingOutputSurface( | 461 return LayerTreeHostTest::CreateDelegatingOutputSurface( |
| 462 std::move(compositor_context_provider), | 462 std::move(compositor_context_provider), |
| 463 std::move(mock_worker_context_provider)); | 463 std::move(mock_worker_context_provider)); |
| 464 } | 464 } |
| 465 | 465 |
| 466 void InitializeSettings(LayerTreeSettings* settings) override { | 466 void InitializeSettings(LayerTreeSettings* settings) override { |
| 467 settings->gpu_rasterization_enabled = true; | 467 settings->gpu_rasterization_enabled = true; |
| 468 settings->gpu_rasterization_forced = true; | 468 settings->gpu_rasterization_forced = true; |
| 469 } | 469 } |
| 470 | 470 |
| 471 void BeginTest() override {} | 471 void BeginTest() override {} |
| 472 | 472 |
| 473 void BeforeVisibilityChange() { | 473 void BeforeVisibilityChange() { |
| 474 // Ensure that our initialization expectations have completed. | 474 // Ensure that our initialization expectations have completed. |
| 475 Mock::VerifyAndClearExpectations(mock_context_support_ptr_); | 475 Mock::VerifyAndClearExpectations(mock_context_support_ptr_); |
| 476 | 476 |
| 477 // Ensure that our mock calls execute in sequence. | 477 // Ensure that our mock calls execute in sequence. |
| 478 ::testing::InSequence s; | 478 ::testing::InSequence s; |
| 479 | 479 |
| 480 // While running, visibility is set to false, and we will call | 480 // While running, visibility is set to false, and we will call |
| 481 // DeleteCachedResources and SetAggressivelyFreeResources(true). | 481 // DeleteCachedResources. |
| 482 EXPECT_CALL(*mock_context_support_ptr_, SetClientVisible(0, false)); | 482 EXPECT_CALL(*mock_context_support_ptr_, ClientBecameNotVisible_(_)) |
| 483 .WillOnce(::testing::Invoke( |
| 484 mock_context_support_ptr_, |
| 485 &MockContextSupport::SuperClientBecameNotVisible)); |
| 483 EXPECT_CALL(*mock_context_support_ptr_, AnyClientsVisible()) | 486 EXPECT_CALL(*mock_context_support_ptr_, AnyClientsVisible()) |
| 484 .WillOnce(::testing::Return(false)); | 487 .WillOnce(::testing::Return(false)); |
| 485 EXPECT_CALL(*mock_context_provider_ptr_, DeleteCachedResources()); | 488 EXPECT_CALL(*mock_context_provider_ptr_, DeleteCachedResources()) |
| 486 EXPECT_CALL(*mock_context_support_ptr_, SetAggressivelyFreeResources(true)) | 489 .WillOnce(testing::Invoke([this]() { EndTest(); })); |
| 487 .WillOnce(testing::Invoke([this](bool is_visible) { EndTest(); })); | |
| 488 } | 490 } |
| 489 | 491 |
| 490 void AfterTest() override { | 492 void AfterTest() override { |
| 491 // Ensure all expectations are satisfied. | 493 // Ensure all expectations are satisfied. |
| 492 Mock::VerifyAndClearExpectations(mock_context_support_ptr_); | 494 Mock::VerifyAndClearExpectations(mock_context_support_ptr_); |
| 493 Mock::VerifyAndClearExpectations(mock_context_provider_ptr_); | 495 Mock::VerifyAndClearExpectations(mock_context_provider_ptr_); |
| 494 } | 496 } |
| 495 | 497 |
| 496 private: | 498 private: |
| 497 class MockContextProvider : public TestContextProvider { | 499 class MockContextProvider : public TestContextProvider { |
| 498 public: | 500 public: |
| 499 explicit MockContextProvider(std::unique_ptr<TestContextSupport> support) | 501 explicit MockContextProvider(std::unique_ptr<TestContextSupport> support) |
| 500 : TestContextProvider(std::move(support), | 502 : TestContextProvider(std::move(support), |
| 501 base::MakeUnique<TestGLES2Interface>(), | 503 base::MakeUnique<TestGLES2Interface>(), |
| 502 TestWebGraphicsContext3D::Create()) {} | 504 TestWebGraphicsContext3D::Create()) {} |
| 503 | 505 |
| 504 MOCK_METHOD0(DeleteCachedResources, void()); | 506 MOCK_METHOD0(DeleteCachedResources, void()); |
| 505 | 507 |
| 506 private: | 508 private: |
| 507 ~MockContextProvider() = default; | 509 ~MockContextProvider() = default; |
| 508 }; | 510 }; |
| 509 | 511 |
| 510 class MockContextSupport : public TestContextSupport { | 512 class MockContextSupport : public TestContextSupport { |
| 511 public: | 513 public: |
| 514 using VisibilityToken = std::unique_ptr<ScopedVisibility>; |
| 512 MockContextSupport() {} | 515 MockContextSupport() {} |
| 513 MOCK_METHOD1(SetAggressivelyFreeResources, | 516 MOCK_METHOD0(ClientBecameVisible, VisibilityToken()); |
| 514 void(bool aggressively_free_resources)); | 517 MOCK_METHOD1(ClientBecameNotVisible_, |
| 515 MOCK_METHOD2(SetClientVisible, void(int client_id, bool is_visible)); | 518 void(VisibilityToken& visibility)); // NOLINT |
| 516 MOCK_CONST_METHOD0(AnyClientsVisible, bool()); | 519 MOCK_CONST_METHOD0(AnyClientsVisible, bool()); |
| 520 |
| 521 // Wrapper to allow mocking w/ move-only type. |
| 522 void ClientBecameNotVisible(VisibilityToken visibility) override { |
| 523 ClientBecameNotVisible_(visibility); |
| 524 } |
| 525 |
| 526 // Wrappers to allow forwarding to super class implementation. |
| 527 void SuperClientBecameNotVisible(VisibilityToken& visibility) { // NOLINT |
| 528 TestContextSupport::ClientBecameNotVisible(std::move(visibility)); |
| 529 } |
| 530 VisibilityToken SuperClientBecameVisible() { |
| 531 return TestContextSupport::ClientBecameVisible(); |
| 532 } |
| 517 }; | 533 }; |
| 518 | 534 |
| 519 MockContextSupport* mock_context_support_ptr_; | 535 MockContextSupport* mock_context_support_ptr_; |
| 520 MockContextProvider* mock_context_provider_ptr_; | 536 MockContextProvider* mock_context_provider_ptr_; |
| 521 }; | 537 }; |
| 522 | 538 |
| 523 // Test if the LTH successfully frees resources on the worker context when | 539 // Test if the LTH successfully frees resources on the worker context when |
| 524 // visibility is set to false. | 540 // visibility is set to false. |
| 525 class LayerTreeHostFreeWorkerContextResourcesOnInvisible | 541 class LayerTreeHostFreeWorkerContextResourcesOnInvisible |
| 526 : public LayerTreeHostFreeWorkerContextResourcesTest { | 542 : public LayerTreeHostFreeWorkerContextResourcesTest { |
| (...skipping 6504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7031 private: | 7047 private: |
| 7032 FakeContentLayerClient client_; | 7048 FakeContentLayerClient client_; |
| 7033 const gfx::Size viewport_size_; | 7049 const gfx::Size viewport_size_; |
| 7034 const gfx::Size large_image_size_; | 7050 const gfx::Size large_image_size_; |
| 7035 }; | 7051 }; |
| 7036 | 7052 |
| 7037 SINGLE_AND_MULTI_THREAD_TEST_F(GpuRasterizationSucceedsWithLargeImage); | 7053 SINGLE_AND_MULTI_THREAD_TEST_F(GpuRasterizationSucceedsWithLargeImage); |
| 7038 | 7054 |
| 7039 } // namespace | 7055 } // namespace |
| 7040 } // namespace cc | 7056 } // namespace cc |
| OLD | NEW |