| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Tests for GLES2Implementation. | 5 // Tests for GLES2Implementation. |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 8 | 8 |
| 9 #include <GLES2/gl2.h> | 9 #include <GLES2/gl2.h> |
| 10 #include <GLES2/gl2ext.h> | 10 #include <GLES2/gl2ext.h> |
| 11 #include <GLES2/gl2extchromium.h> | 11 #include <GLES2/gl2extchromium.h> |
| 12 #include <GLES3/gl3.h> | 12 #include <GLES3/gl3.h> |
| 13 | 13 |
| 14 #include <stddef.h> | 14 #include <stddef.h> |
| 15 #include <stdint.h> | 15 #include <stdint.h> |
| 16 | 16 |
| 17 #include <memory> | 17 #include <memory> |
| 18 | 18 |
| 19 #include "base/bind.h" |
| 19 #include "base/compiler_specific.h" | 20 #include "base/compiler_specific.h" |
| 20 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
| 22 #include "base/test/test_mock_time_task_runner.h" |
| 23 #include "base/threading/thread_task_runner_handle.h" |
| 21 #include "gpu/command_buffer/client/client_test_helper.h" | 24 #include "gpu/command_buffer/client/client_test_helper.h" |
| 22 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 25 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
| 23 #include "gpu/command_buffer/client/program_info_manager.h" | 26 #include "gpu/command_buffer/client/program_info_manager.h" |
| 24 #include "gpu/command_buffer/client/query_tracker.h" | 27 #include "gpu/command_buffer/client/query_tracker.h" |
| 25 #include "gpu/command_buffer/client/ring_buffer.h" | 28 #include "gpu/command_buffer/client/ring_buffer.h" |
| 26 #include "gpu/command_buffer/client/shared_memory_limits.h" | 29 #include "gpu/command_buffer/client/shared_memory_limits.h" |
| 27 #include "gpu/command_buffer/client/transfer_buffer.h" | 30 #include "gpu/command_buffer/client/transfer_buffer.h" |
| 28 #include "gpu/command_buffer/common/command_buffer.h" | 31 #include "gpu/command_buffer/common/command_buffer.h" |
| 29 #include "gpu/command_buffer/common/sync_token.h" | 32 #include "gpu/command_buffer/common/sync_token.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 capabilities.bind_generates_resource_chromium = | 479 capabilities.bind_generates_resource_chromium = |
| 477 bind_generates_resource_service ? 1 : 0; | 480 bind_generates_resource_service ? 1 : 0; |
| 478 capabilities.sync_query = sync_query; | 481 capabilities.sync_query = sync_query; |
| 479 capabilities.occlusion_query_boolean = occlusion_query_boolean; | 482 capabilities.occlusion_query_boolean = occlusion_query_boolean; |
| 480 capabilities.timer_queries = timer_queries; | 483 capabilities.timer_queries = timer_queries; |
| 481 capabilities.major_version = major_version; | 484 capabilities.major_version = major_version; |
| 482 capabilities.minor_version = minor_version; | 485 capabilities.minor_version = minor_version; |
| 483 EXPECT_CALL(*gpu_control_, GetCapabilities()) | 486 EXPECT_CALL(*gpu_control_, GetCapabilities()) |
| 484 .WillOnce(Return(capabilities)); | 487 .WillOnce(Return(capabilities)); |
| 485 | 488 |
| 489 task_runner_ = make_scoped_refptr(new base::TestMockTimeTaskRunner()); |
| 490 |
| 486 { | 491 { |
| 487 InSequence sequence; | 492 InSequence sequence; |
| 488 | 493 |
| 489 const bool support_client_side_arrays = true; | 494 const bool support_client_side_arrays = true; |
| 490 gl_.reset(new GLES2Implementation( | 495 gl_.reset(new GLES2Implementation( |
| 491 helper_.get(), share_group, transfer_buffer_.get(), | 496 helper_.get(), share_group, transfer_buffer_.get(), |
| 492 bind_generates_resource_client, lose_context_when_out_of_memory, | 497 bind_generates_resource_client, lose_context_when_out_of_memory, |
| 493 support_client_side_arrays, gpu_control_.get(), nullptr)); | 498 support_client_side_arrays, gpu_control_.get(), task_runner_)); |
| 494 } | 499 } |
| 495 | 500 |
| 496 // The client should be set to something non-null. | 501 // The client should be set to something non-null. |
| 497 EXPECT_CALL(*gpu_control_, SetGpuControlClient(gl_.get())).Times(1); | 502 EXPECT_CALL(*gpu_control_, SetGpuControlClient(gl_.get())).Times(1); |
| 498 | 503 |
| 499 if (!gl_->Initialize(kTransferBufferSize, kTransferBufferSize, | 504 if (!gl_->Initialize(kTransferBufferSize, kTransferBufferSize, |
| 500 kTransferBufferSize, SharedMemoryLimits::kNoLimit)) | 505 kTransferBufferSize, SharedMemoryLimits::kNoLimit)) |
| 501 return false; | 506 return false; |
| 502 | 507 |
| 503 helper_->CommandBufferHelper::Finish(); | 508 helper_->CommandBufferHelper::Finish(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 533 void ClearCommands() { | 538 void ClearCommands() { |
| 534 scoped_refptr<Buffer> ring_buffer = helper_->get_ring_buffer(); | 539 scoped_refptr<Buffer> ring_buffer = helper_->get_ring_buffer(); |
| 535 memset(ring_buffer->memory(), kInitialValue, ring_buffer->size()); | 540 memset(ring_buffer->memory(), kInitialValue, ring_buffer->size()); |
| 536 } | 541 } |
| 537 | 542 |
| 538 std::unique_ptr<MockClientCommandBuffer> command_buffer_; | 543 std::unique_ptr<MockClientCommandBuffer> command_buffer_; |
| 539 std::unique_ptr<MockClientGpuControl> gpu_control_; | 544 std::unique_ptr<MockClientGpuControl> gpu_control_; |
| 540 std::unique_ptr<GLES2CmdHelper> helper_; | 545 std::unique_ptr<GLES2CmdHelper> helper_; |
| 541 std::unique_ptr<MockTransferBuffer> transfer_buffer_; | 546 std::unique_ptr<MockTransferBuffer> transfer_buffer_; |
| 542 std::unique_ptr<GLES2Implementation> gl_; | 547 std::unique_ptr<GLES2Implementation> gl_; |
| 548 scoped_refptr<base::TestMockTimeTaskRunner> task_runner_; |
| 543 CommandBufferEntry* commands_; | 549 CommandBufferEntry* commands_; |
| 544 int token_; | 550 int token_; |
| 545 }; | 551 }; |
| 546 | 552 |
| 547 GLES2ImplementationTest() : commands_(NULL) {} | 553 GLES2ImplementationTest() : commands_(NULL) {} |
| 548 | 554 |
| 549 void SetUp() override; | 555 void SetUp() override; |
| 550 void TearDown() override; | 556 void TearDown() override; |
| 551 | 557 |
| 552 bool NoCommandsWritten() { | 558 bool NoCommandsWritten() { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 transfer_buffer_ = test_contexts_[0].transfer_buffer_.get(); | 625 transfer_buffer_ = test_contexts_[0].transfer_buffer_.get(); |
| 620 gl_ = test_contexts_[0].gl_.get(); | 626 gl_ = test_contexts_[0].gl_.get(); |
| 621 commands_ = test_contexts_[0].commands_; | 627 commands_ = test_contexts_[0].commands_; |
| 622 return success; | 628 return success; |
| 623 } | 629 } |
| 624 | 630 |
| 625 MockClientCommandBuffer* command_buffer() const { | 631 MockClientCommandBuffer* command_buffer() const { |
| 626 return test_contexts_[0].command_buffer_.get(); | 632 return test_contexts_[0].command_buffer_.get(); |
| 627 } | 633 } |
| 628 | 634 |
| 635 base::TestMockTimeTaskRunner* task_runner() const { |
| 636 return test_contexts_[0].task_runner_.get(); |
| 637 } |
| 638 |
| 629 int GetNextToken() { return test_contexts_[0].GetNextToken(); } | 639 int GetNextToken() { return test_contexts_[0].GetNextToken(); } |
| 630 | 640 |
| 631 const void* GetPut() { | 641 const void* GetPut() { |
| 632 return helper_->GetSpace(0); | 642 return helper_->GetSpace(0); |
| 633 } | 643 } |
| 634 | 644 |
| 635 void ClearCommands() { | 645 void ClearCommands() { |
| 636 scoped_refptr<Buffer> ring_buffer = helper_->get_ring_buffer(); | 646 scoped_refptr<Buffer> ring_buffer = helper_->get_ring_buffer(); |
| 637 memset(ring_buffer->memory(), kInitialValue, ring_buffer->size()); | 647 memset(ring_buffer->memory(), kInitialValue, ring_buffer->size()); |
| 638 } | 648 } |
| (...skipping 4002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4641 EXPECT_TRUE(gl_->AnyClientsVisible()); | 4651 EXPECT_TRUE(gl_->AnyClientsVisible()); |
| 4642 EXPECT_CALL(*command_buffer(), OnFlush()).Times(2); | 4652 EXPECT_CALL(*command_buffer(), OnFlush()).Times(2); |
| 4643 EXPECT_CALL(*command_buffer(), DestroyTransferBuffer(_)).Times(1); | 4653 EXPECT_CALL(*command_buffer(), DestroyTransferBuffer(_)).Times(1); |
| 4644 gl_->Flush(); | 4654 gl_->Flush(); |
| 4645 gl_->TrimResources(); | 4655 gl_->TrimResources(); |
| 4646 gl_->Flush(); | 4656 gl_->Flush(); |
| 4647 Mock::VerifyAndClearExpectations(command_buffer()); | 4657 Mock::VerifyAndClearExpectations(command_buffer()); |
| 4648 } | 4658 } |
| 4649 } | 4659 } |
| 4650 | 4660 |
| 4661 TEST_F(GLES2ImplementationTest, ClientBusyBasic) { |
| 4662 bool signaled = false; |
| 4663 gl_->SetIdleCallback( |
| 4664 base::Bind([](bool* signaled) { *signaled = true; }, &signaled)); |
| 4665 auto busy = gl_->ClientBecameBusy(); |
| 4666 gl_->ClientBecameNotBusy(std::move(busy)); |
| 4667 |
| 4668 task_runner()->FastForwardBy(base::TimeDelta::FromSeconds(5)); |
| 4669 EXPECT_TRUE(signaled); |
| 4670 } |
| 4671 |
| 4672 TEST_F(GLES2ImplementationTest, ClientBusyCancelled) { |
| 4673 auto runner = make_scoped_refptr(new base::TestMockTimeTaskRunner()); |
| 4674 base::ThreadTaskRunnerHandle handle(runner); |
| 4675 |
| 4676 bool signaled = false; |
| 4677 gl_->SetIdleCallback( |
| 4678 base::Bind([](bool* signaled) { *signaled = true; }, &signaled)); |
| 4679 auto busy = gl_->ClientBecameBusy(); |
| 4680 |
| 4681 // This will trigger the idle callback to start counting down. |
| 4682 gl_->ClientBecameNotBusy(std::move(busy)); |
| 4683 |
| 4684 // Immediately take another busy lock to stop the countdown. |
| 4685 busy = gl_->ClientBecameBusy(); |
| 4686 |
| 4687 // Advance time and ensure that our callback was cancelled (does not run). |
| 4688 task_runner()->FastForwardBy(base::TimeDelta::FromSeconds(5)); |
| 4689 EXPECT_FALSE(signaled); |
| 4690 |
| 4691 // Release our busy lock, and let the idle callback run. |
| 4692 gl_->ClientBecameNotBusy(std::move(busy)); |
| 4693 |
| 4694 task_runner()->FastForwardBy(base::TimeDelta::FromSeconds(5)); |
| 4695 EXPECT_TRUE(signaled); |
| 4696 } |
| 4697 |
| 4651 #include "base/macros.h" | 4698 #include "base/macros.h" |
| 4652 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" | 4699 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" |
| 4653 | 4700 |
| 4654 } // namespace gles2 | 4701 } // namespace gles2 |
| 4655 } // namespace gpu | 4702 } // namespace gpu |
| OLD | NEW |