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