Chromium Code Reviews| 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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 | 433 |
| 434 class LayerTreeHostFreeWorkerContextResourcesTest : public LayerTreeHostTest { | 434 class LayerTreeHostFreeWorkerContextResourcesTest : public LayerTreeHostTest { |
| 435 public: | 435 public: |
| 436 std::unique_ptr<TestDelegatingOutputSurface> CreateDelegatingOutputSurface( | 436 std::unique_ptr<TestDelegatingOutputSurface> CreateDelegatingOutputSurface( |
| 437 scoped_refptr<ContextProvider> compositor_context_provider, | 437 scoped_refptr<ContextProvider> compositor_context_provider, |
| 438 scoped_refptr<ContextProvider> worker_context_provider) override { | 438 scoped_refptr<ContextProvider> worker_context_provider) override { |
| 439 auto mock_worker_context_support_owned = | 439 auto mock_worker_context_support_owned = |
| 440 base::MakeUnique<MockContextSupport>(); | 440 base::MakeUnique<MockContextSupport>(); |
| 441 mock_context_support_ptr_ = mock_worker_context_support_owned.get(); | 441 mock_context_support_ptr_ = mock_worker_context_support_owned.get(); |
| 442 | 442 |
| 443 auto mock_worker_context_provider = make_scoped_refptr( | 443 auto test_worker_context_provider = TestContextProvider::Create( |
| 444 new MockContextProvider(std::move(mock_worker_context_support_owned))); | 444 TestWebGraphicsContext3D::Create(), |
| 445 mock_context_provider_ptr_ = mock_worker_context_provider.get(); | 445 std::move(mock_worker_context_support_owned)); |
| 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 test_worker_context_provider->BindToCurrentThread(); |
| 449 | |
| 450 // Ensure that our mock calls execute in sequence. | |
| 451 ::testing::InSequence s; | |
| 452 | 449 |
| 453 // At init, visibility is set to true and we will call | 450 // At init, visibility is set to true and we will call |
| 454 // SetAggressivelyFreeResources(false). | 451 // SetAggressivelyFreeResources(false). |
| 455 EXPECT_CALL(*mock_context_support_ptr_, SetClientVisible(0, true)); | |
| 456 EXPECT_CALL(*mock_context_support_ptr_, AnyClientsVisible()) | |
| 457 .WillOnce(::testing::Return(true)); | |
| 458 EXPECT_CALL(*mock_context_support_ptr_, | 452 EXPECT_CALL(*mock_context_support_ptr_, |
| 459 SetAggressivelyFreeResources(false)); | 453 SetAggressivelyFreeResources(false)); |
| 460 | 454 |
| 461 return LayerTreeHostTest::CreateDelegatingOutputSurface( | 455 return LayerTreeHostTest::CreateDelegatingOutputSurface( |
| 462 std::move(compositor_context_provider), | 456 std::move(compositor_context_provider), |
| 463 std::move(mock_worker_context_provider)); | 457 std::move(test_worker_context_provider)); |
| 464 } | 458 } |
| 465 | 459 |
| 466 void InitializeSettings(LayerTreeSettings* settings) override { | 460 void InitializeSettings(LayerTreeSettings* settings) override { |
| 467 settings->gpu_rasterization_enabled = true; | 461 settings->gpu_rasterization_enabled = true; |
| 468 settings->gpu_rasterization_forced = true; | 462 settings->gpu_rasterization_forced = true; |
| 469 } | 463 } |
| 470 | 464 |
| 471 void BeginTest() override {} | 465 void BeginTest() override {} |
| 472 | 466 |
| 473 void BeforeVisibilityChange() { | 467 void BeforeVisibilityChange() { |
| 474 // Ensure that our initialization expectations have completed. | 468 // Ensure that our initialization expectations have completed. |
| 475 Mock::VerifyAndClearExpectations(mock_context_support_ptr_); | 469 Mock::VerifyAndClearExpectations(mock_context_support_ptr_); |
| 476 | 470 |
| 477 // Ensure that our mock calls execute in sequence. | |
| 478 ::testing::InSequence s; | |
| 479 | |
| 480 // While running, visibility is set to false, and we will call | 471 // While running, visibility is set to false, and we will call |
| 481 // DeleteCachedResources and SetAggressivelyFreeResources(true). | 472 // SetAggressivelyFreeResources(true). |
| 482 EXPECT_CALL(*mock_context_support_ptr_, SetClientVisible(0, false)); | |
| 483 EXPECT_CALL(*mock_context_support_ptr_, AnyClientsVisible()) | |
| 484 .WillOnce(::testing::Return(false)); | |
| 485 EXPECT_CALL(*mock_context_provider_ptr_, DeleteCachedResources()); | |
| 486 EXPECT_CALL(*mock_context_support_ptr_, SetAggressivelyFreeResources(true)) | 473 EXPECT_CALL(*mock_context_support_ptr_, SetAggressivelyFreeResources(true)) |
| 487 .WillOnce(testing::Invoke([this](bool is_visible) { EndTest(); })); | 474 .WillOnce(testing::Invoke([this](bool is_visible) { EndTest(); })); |
| 488 } | 475 } |
| 489 | 476 |
| 490 void AfterTest() override { | 477 void AfterTest() override { |
| 491 // Ensure all expectations are satisfied. | 478 // Ensure all expectations are satisfied. |
| 492 Mock::VerifyAndClearExpectations(mock_context_support_ptr_); | 479 Mock::VerifyAndClearExpectations(mock_context_support_ptr_); |
| 493 Mock::VerifyAndClearExpectations(mock_context_provider_ptr_); | |
| 494 } | 480 } |
| 495 | 481 |
| 496 private: | 482 private: |
| 497 class MockContextProvider : public TestContextProvider { | |
| 498 public: | |
| 499 explicit MockContextProvider(std::unique_ptr<TestContextSupport> support) | |
| 500 : TestContextProvider(std::move(support), | |
| 501 base::MakeUnique<TestGLES2Interface>(), | |
| 502 TestWebGraphicsContext3D::Create()) {} | |
| 503 | |
| 504 MOCK_METHOD0(DeleteCachedResources, void()); | |
| 505 | |
| 506 private: | |
| 507 ~MockContextProvider() = default; | |
| 508 }; | |
| 509 | |
| 510 class MockContextSupport : public TestContextSupport { | 483 class MockContextSupport : public TestContextSupport { |
| 511 public: | 484 public: |
| 512 MockContextSupport() {} | 485 MockContextSupport() {} |
| 513 MOCK_METHOD1(SetAggressivelyFreeResources, | 486 MOCK_METHOD1(SetAggressivelyFreeResources, |
| 514 void(bool aggressively_free_resources)); | 487 void(bool aggressively_free_resources)); |
| 515 MOCK_METHOD2(SetClientVisible, void(int client_id, bool is_visible)); | |
| 516 MOCK_CONST_METHOD0(AnyClientsVisible, bool()); | |
| 517 }; | 488 }; |
| 518 | 489 |
| 519 MockContextSupport* mock_context_support_ptr_; | 490 MockContextSupport* mock_context_support_ptr_; |
| 520 MockContextProvider* mock_context_provider_ptr_; | |
| 521 }; | 491 }; |
| 522 | 492 |
| 523 // Test if the LTH successfully frees resources on the worker context when | 493 // Test if the LTH successfully frees resources on the worker context when |
| 524 // visibility is set to false. | 494 // visibility is set to false. |
| 525 class LayerTreeHostFreeWorkerContextResourcesOnInvisible | 495 class LayerTreeHostFreeWorkerContextResourcesOnInvisible |
|
danakj
2016/08/26 23:49:09
Should these test the compositor context too?
..
ericrk
2016/08/29 22:43:23
SetVisible also modifies the memory policy, zeroin
| |
| 526 : public LayerTreeHostFreeWorkerContextResourcesTest { | 496 : public LayerTreeHostFreeWorkerContextResourcesTest { |
| 527 public: | 497 public: |
| 528 void InitializedRendererOnThread(LayerTreeHostImpl* host_impl, | 498 void InitializedRendererOnThread(LayerTreeHostImpl* host_impl, |
| 529 bool success) override { | 499 bool success) override { |
| 530 BeforeVisibilityChange(); | 500 BeforeVisibilityChange(); |
| 531 PostSetVisibleToMainThread(false); | 501 PostSetVisibleToMainThread(false); |
| 532 } | 502 } |
| 533 }; | 503 }; |
| 534 | 504 |
| 535 SINGLE_AND_MULTI_THREAD_TEST_F( | 505 SINGLE_AND_MULTI_THREAD_TEST_F( |
| (...skipping 6497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7033 private: | 7003 private: |
| 7034 FakeContentLayerClient client_; | 7004 FakeContentLayerClient client_; |
| 7035 const gfx::Size viewport_size_; | 7005 const gfx::Size viewport_size_; |
| 7036 const gfx::Size large_image_size_; | 7006 const gfx::Size large_image_size_; |
| 7037 }; | 7007 }; |
| 7038 | 7008 |
| 7039 SINGLE_AND_MULTI_THREAD_TEST_F(GpuRasterizationSucceedsWithLargeImage); | 7009 SINGLE_AND_MULTI_THREAD_TEST_F(GpuRasterizationSucceedsWithLargeImage); |
| 7040 | 7010 |
| 7041 } // namespace | 7011 } // namespace |
| 7042 } // namespace cc | 7012 } // namespace cc |
| OLD | NEW |