| 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/compiler_specific.h" | 19 #include "base/compiler_specific.h" |
| 20 #include "base/memory/ptr_util.h" |
| 20 #include "gpu/command_buffer/client/client_test_helper.h" | 21 #include "gpu/command_buffer/client/client_test_helper.h" |
| 21 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 22 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
| 22 #include "gpu/command_buffer/client/program_info_manager.h" | 23 #include "gpu/command_buffer/client/program_info_manager.h" |
| 23 #include "gpu/command_buffer/client/query_tracker.h" | 24 #include "gpu/command_buffer/client/query_tracker.h" |
| 24 #include "gpu/command_buffer/client/ring_buffer.h" | 25 #include "gpu/command_buffer/client/ring_buffer.h" |
| 25 #include "gpu/command_buffer/client/shared_memory_limits.h" | 26 #include "gpu/command_buffer/client/shared_memory_limits.h" |
| 26 #include "gpu/command_buffer/client/transfer_buffer.h" | 27 #include "gpu/command_buffer/client/transfer_buffer.h" |
| 27 #include "gpu/command_buffer/common/command_buffer.h" | 28 #include "gpu/command_buffer/common/command_buffer.h" |
| 28 #include "gpu/command_buffer/common/sync_token.h" | 29 #include "gpu/command_buffer/common/sync_token.h" |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 263 |
| 263 void* MockTransferBuffer::GetResultBuffer() { | 264 void* MockTransferBuffer::GetResultBuffer() { |
| 264 return actual_buffer() + actual_buffer_index_ * alignment_; | 265 return actual_buffer() + actual_buffer_index_ * alignment_; |
| 265 } | 266 } |
| 266 | 267 |
| 267 int MockTransferBuffer::GetResultOffset() { | 268 int MockTransferBuffer::GetResultOffset() { |
| 268 return actual_buffer_index_ * alignment_; | 269 return actual_buffer_index_ * alignment_; |
| 269 } | 270 } |
| 270 | 271 |
| 271 void MockTransferBuffer::Free() { | 272 void MockTransferBuffer::Free() { |
| 272 NOTREACHED(); | |
| 273 } | 273 } |
| 274 | 274 |
| 275 bool MockTransferBuffer::HaveBuffer() const { | 275 bool MockTransferBuffer::HaveBuffer() const { |
| 276 return true; | 276 return true; |
| 277 } | 277 } |
| 278 | 278 |
| 279 void* MockTransferBuffer::AllocUpTo( | 279 void* MockTransferBuffer::AllocUpTo( |
| 280 unsigned int size, unsigned int* size_allocated) { | 280 unsigned int size, unsigned int* size_allocated) { |
| 281 EXPECT_TRUE(size_allocated != NULL); | 281 EXPECT_TRUE(size_allocated != NULL); |
| 282 EXPECT_TRUE(last_alloc_ == NULL); | 282 EXPECT_TRUE(last_alloc_ == NULL); |
| (...skipping 4319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4602 } | 4602 } |
| 4603 | 4603 |
| 4604 TEST_F(GLES2ImplementationManualInitTest, FailInitOnTransferBufferFail) { | 4604 TEST_F(GLES2ImplementationManualInitTest, FailInitOnTransferBufferFail) { |
| 4605 ContextInitOptions init_options; | 4605 ContextInitOptions init_options; |
| 4606 init_options.transfer_buffer_initialize_fail = true; | 4606 init_options.transfer_buffer_initialize_fail = true; |
| 4607 EXPECT_FALSE(Initialize(init_options)); | 4607 EXPECT_FALSE(Initialize(init_options)); |
| 4608 } | 4608 } |
| 4609 | 4609 |
| 4610 TEST_F(GLES2ImplementationTest, ClientVisibility) { | 4610 TEST_F(GLES2ImplementationTest, ClientVisibility) { |
| 4611 EXPECT_FALSE(gl_->AnyClientsVisible()); | 4611 EXPECT_FALSE(gl_->AnyClientsVisible()); |
| 4612 gl_->SetClientVisible(0, true); | 4612 { |
| 4613 EXPECT_TRUE(gl_->AnyClientsVisible()); | 4613 auto visibility_0 = gl_->ClientBecameVisible(); |
| 4614 gl_->SetClientVisible(0, false); | 4614 EXPECT_TRUE(gl_->AnyClientsVisible()); |
| 4615 gl_->ClientBecameNotVisible(std::move(visibility_0)); |
| 4616 EXPECT_FALSE(gl_->AnyClientsVisible()); |
| 4617 } |
| 4618 { |
| 4619 auto visibility_0 = gl_->ClientBecameVisible(); |
| 4620 auto visibility_1 = gl_->ClientBecameVisible(); |
| 4621 EXPECT_TRUE(gl_->AnyClientsVisible()); |
| 4622 gl_->ClientBecameNotVisible(std::move(visibility_0)); |
| 4623 EXPECT_TRUE(gl_->AnyClientsVisible()); |
| 4624 gl_->ClientBecameNotVisible(std::move(visibility_1)); |
| 4625 EXPECT_FALSE(gl_->AnyClientsVisible()); |
| 4626 } |
| 4627 } |
| 4628 |
| 4629 TEST_F(GLES2ImplementationTest, TrimResources) { |
| 4615 EXPECT_FALSE(gl_->AnyClientsVisible()); | 4630 EXPECT_FALSE(gl_->AnyClientsVisible()); |
| 4616 gl_->SetClientVisible(0, true); | 4631 |
| 4617 gl_->SetClientVisible(1, true); | 4632 // TrimResources while no clients vivisble, this should persist |
| 4618 EXPECT_TRUE(gl_->AnyClientsVisible()); | 4633 // aggressively_free_resources_, causing further flushes to trim. |
| 4619 gl_->SetClientVisible(0, false); | 4634 EXPECT_CALL(*command_buffer(), OnFlush()).Times(2); |
| 4620 EXPECT_TRUE(gl_->AnyClientsVisible()); | 4635 EXPECT_CALL(*command_buffer(), DestroyTransferBuffer(_)).Times(2); |
| 4621 gl_->SetClientVisible(1, false); | 4636 gl_->TrimResources(); |
| 4622 EXPECT_FALSE(gl_->AnyClientsVisible()); | 4637 gl_->Flush(); |
| 4638 Mock::VerifyAndClearExpectations(command_buffer()); |
| 4639 |
| 4640 { |
| 4641 // TrimResources while visible, this should not persisit |
| 4642 // aggressively_free_resources_, and further flushes should not trim. |
| 4643 auto visibility_0 = gl_->ClientBecameVisible(); |
| 4644 EXPECT_TRUE(gl_->AnyClientsVisible()); |
| 4645 EXPECT_CALL(*command_buffer(), OnFlush()).Times(2); |
| 4646 EXPECT_CALL(*command_buffer(), DestroyTransferBuffer(_)).Times(1); |
| 4647 gl_->Flush(); |
| 4648 gl_->TrimResources(); |
| 4649 gl_->Flush(); |
| 4650 Mock::VerifyAndClearExpectations(command_buffer()); |
| 4651 } |
| 4623 } | 4652 } |
| 4624 | 4653 |
| 4625 #include "base/macros.h" | 4654 #include "base/macros.h" |
| 4626 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" | 4655 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" |
| 4627 | 4656 |
| 4628 } // namespace gles2 | 4657 } // namespace gles2 |
| 4629 } // namespace gpu | 4658 } // namespace gpu |
| OLD | NEW |