| 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 <limits> | |
| 10 | |
| 11 #include <GLES2/gl2ext.h> | 9 #include <GLES2/gl2ext.h> |
| 12 #include <GLES2/gl2extchromium.h> | 10 #include <GLES2/gl2extchromium.h> |
| 13 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 14 #include "gpu/command_buffer/client/client_test_helper.h" | 12 #include "gpu/command_buffer/client/client_test_helper.h" |
| 15 #include "gpu/command_buffer/client/program_info_manager.h" | 13 #include "gpu/command_buffer/client/program_info_manager.h" |
| 16 #include "gpu/command_buffer/client/transfer_buffer.h" | 14 #include "gpu/command_buffer/client/transfer_buffer.h" |
| 17 #include "gpu/command_buffer/common/command_buffer.h" | 15 #include "gpu/command_buffer/common/command_buffer.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 20 | 18 |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 static const GLuint kTexturesStartId = 1; | 383 static const GLuint kTexturesStartId = 1; |
| 386 static const GLuint kQueriesStartId = 1; | 384 static const GLuint kQueriesStartId = 1; |
| 387 static const GLuint kVertexArraysStartId = 1; | 385 static const GLuint kVertexArraysStartId = 1; |
| 388 | 386 |
| 389 typedef MockTransferBuffer::ExpectedMemoryInfo ExpectedMemoryInfo; | 387 typedef MockTransferBuffer::ExpectedMemoryInfo ExpectedMemoryInfo; |
| 390 | 388 |
| 391 class TestContext { | 389 class TestContext { |
| 392 public: | 390 public: |
| 393 TestContext() : commands_(NULL), token_(0) {} | 391 TestContext() : commands_(NULL), token_(0) {} |
| 394 | 392 |
| 395 void Initialize(ShareGroup* share_group, | 393 void Initialize(ShareGroup* share_group, bool bind_generates_resource) { |
| 396 bool bind_generates_resource, | |
| 397 bool lose_context_when_out_of_memory) { | |
| 398 command_buffer_.reset(new StrictMock<MockClientCommandBuffer>()); | 394 command_buffer_.reset(new StrictMock<MockClientCommandBuffer>()); |
| 399 ASSERT_TRUE(command_buffer_->Initialize()); | 395 ASSERT_TRUE(command_buffer_->Initialize()); |
| 400 | 396 |
| 401 transfer_buffer_.reset( | 397 transfer_buffer_.reset( |
| 402 new MockTransferBuffer(command_buffer_.get(), | 398 new MockTransferBuffer(command_buffer_.get(), |
| 403 kTransferBufferSize, | 399 kTransferBufferSize, |
| 404 GLES2Implementation::kStartingOffset, | 400 GLES2Implementation::kStartingOffset, |
| 405 GLES2Implementation::kAlignment)); | 401 GLES2Implementation::kAlignment)); |
| 406 | 402 |
| 407 helper_.reset(new GLES2CmdHelper(command_buffer())); | 403 helper_.reset(new GLES2CmdHelper(command_buffer())); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 436 sizeof(cmds::GetShaderPrecisionFormat::Result) * 12); | 432 sizeof(cmds::GetShaderPrecisionFormat::Result) * 12); |
| 437 | 433 |
| 438 { | 434 { |
| 439 InSequence sequence; | 435 InSequence sequence; |
| 440 | 436 |
| 441 EXPECT_CALL(*command_buffer_, OnFlush()) | 437 EXPECT_CALL(*command_buffer_, OnFlush()) |
| 442 .WillOnce(SetMemory(mem1.ptr + sizeof(int_state), int_state)) | 438 .WillOnce(SetMemory(mem1.ptr + sizeof(int_state), int_state)) |
| 443 .RetiresOnSaturation(); | 439 .RetiresOnSaturation(); |
| 444 GetNextToken(); // eat the token that starting up will use. | 440 GetNextToken(); // eat the token that starting up will use. |
| 445 | 441 |
| 446 gl_.reset(new GLES2Implementation(helper_.get(), | 442 gl_.reset( |
| 447 share_group, | 443 new GLES2Implementation(helper_.get(), |
| 448 transfer_buffer_.get(), | 444 share_group, |
| 449 bind_generates_resource, | 445 transfer_buffer_.get(), |
| 450 lose_context_when_out_of_memory, | 446 bind_generates_resource, |
| 451 gpu_control_.get())); | 447 gpu_control_.get())); |
| 452 ASSERT_TRUE(gl_->Initialize(kTransferBufferSize, | 448 ASSERT_TRUE(gl_->Initialize(kTransferBufferSize, |
| 453 kTransferBufferSize, | 449 kTransferBufferSize, |
| 454 kTransferBufferSize, | 450 kTransferBufferSize, |
| 455 GLES2Implementation::kNoLimit)); | 451 GLES2Implementation::kNoLimit)); |
| 456 } | 452 } |
| 457 | 453 |
| 458 EXPECT_CALL(*command_buffer_, OnFlush()).Times(1).RetiresOnSaturation(); | 454 EXPECT_CALL(*command_buffer_, OnFlush()).Times(1).RetiresOnSaturation(); |
| 459 helper_->CommandBufferHelper::Finish(); | 455 helper_->CommandBufferHelper::Finish(); |
| 460 ::testing::Mock::VerifyAndClearExpectations(gl_.get()); | 456 ::testing::Mock::VerifyAndClearExpectations(gl_.get()); |
| 461 | 457 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 return false; | 507 return false; |
| 512 } | 508 } |
| 513 } | 509 } |
| 514 return true; | 510 return true; |
| 515 } | 511 } |
| 516 | 512 |
| 517 QueryTracker::Query* GetQuery(GLuint id) { | 513 QueryTracker::Query* GetQuery(GLuint id) { |
| 518 return gl_->query_tracker_->GetQuery(id); | 514 return gl_->query_tracker_->GetQuery(id); |
| 519 } | 515 } |
| 520 | 516 |
| 521 void Initialize(bool bind_generates_resource, | 517 void Initialize(bool bind_generates_resource) { |
| 522 bool lose_context_when_out_of_memory) { | |
| 523 share_group_ = new ShareGroup(bind_generates_resource); | 518 share_group_ = new ShareGroup(bind_generates_resource); |
| 524 | 519 |
| 525 for (int i = 0; i < kNumTestContexts; i++) | 520 for (int i = 0; i < kNumTestContexts; i++) |
| 526 test_contexts_[i].Initialize(share_group_.get(), | 521 test_contexts_[i].Initialize(share_group_.get(), bind_generates_resource); |
| 527 bind_generates_resource, | |
| 528 lose_context_when_out_of_memory); | |
| 529 | 522 |
| 530 // Default to test context 0. | 523 // Default to test context 0. |
| 531 gpu_control_ = test_contexts_[0].gpu_control_.get(); | 524 gpu_control_ = test_contexts_[0].gpu_control_.get(); |
| 532 helper_ = test_contexts_[0].helper_.get(); | 525 helper_ = test_contexts_[0].helper_.get(); |
| 533 transfer_buffer_ = test_contexts_[0].transfer_buffer_.get(); | 526 transfer_buffer_ = test_contexts_[0].transfer_buffer_.get(); |
| 534 gl_ = test_contexts_[0].gl_.get(); | 527 gl_ = test_contexts_[0].gl_.get(); |
| 535 commands_ = test_contexts_[0].commands_; | 528 commands_ = test_contexts_[0].commands_; |
| 536 } | 529 } |
| 537 | 530 |
| 538 MockClientCommandBuffer* command_buffer() const { | 531 MockClientCommandBuffer* command_buffer() const { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 | 578 |
| 586 scoped_refptr<ShareGroup> share_group_; | 579 scoped_refptr<ShareGroup> share_group_; |
| 587 MockClientGpuControl* gpu_control_; | 580 MockClientGpuControl* gpu_control_; |
| 588 GLES2CmdHelper* helper_; | 581 GLES2CmdHelper* helper_; |
| 589 MockTransferBuffer* transfer_buffer_; | 582 MockTransferBuffer* transfer_buffer_; |
| 590 GLES2Implementation* gl_; | 583 GLES2Implementation* gl_; |
| 591 CommandBufferEntry* commands_; | 584 CommandBufferEntry* commands_; |
| 592 }; | 585 }; |
| 593 | 586 |
| 594 void GLES2ImplementationTest::SetUp() { | 587 void GLES2ImplementationTest::SetUp() { |
| 595 bool bind_generates_resource = true; | 588 Initialize(true); |
| 596 bool lose_context_when_out_of_memory = false; | |
| 597 Initialize(bind_generates_resource, lose_context_when_out_of_memory); | |
| 598 } | 589 } |
| 599 | 590 |
| 600 void GLES2ImplementationTest::TearDown() { | 591 void GLES2ImplementationTest::TearDown() { |
| 601 for (int i = 0; i < kNumTestContexts; i++) | 592 for (int i = 0; i < kNumTestContexts; i++) |
| 602 test_contexts_[i].TearDown(); | 593 test_contexts_[i].TearDown(); |
| 603 } | 594 } |
| 604 | 595 |
| 605 class GLES2ImplementationManualInitTest : public GLES2ImplementationTest { | |
| 606 protected: | |
| 607 virtual void SetUp() OVERRIDE {} | |
| 608 }; | |
| 609 | |
| 610 class GLES2ImplementationStrictSharedTest : public GLES2ImplementationTest { | 596 class GLES2ImplementationStrictSharedTest : public GLES2ImplementationTest { |
| 611 protected: | 597 protected: |
| 612 virtual void SetUp() OVERRIDE; | 598 virtual void SetUp() OVERRIDE; |
| 613 | 599 |
| 614 template <class ResApi> | 600 template <class ResApi> |
| 615 void FlushGenerationTest() { | 601 void FlushGenerationTest() { |
| 616 GLuint id1, id2, id3; | 602 GLuint id1, id2, id3; |
| 617 | 603 |
| 618 // Generate valid id. | 604 // Generate valid id. |
| 619 ResApi::Gen(gl_, 1, &id1); | 605 ResApi::Gen(gl_, 1, &id1); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 EXPECT_NE(id1, id3); | 676 EXPECT_NE(id1, id3); |
| 691 | 677 |
| 692 // Lazy release triggered by another Delete. Should reuse id1. | 678 // Lazy release triggered by another Delete. Should reuse id1. |
| 693 ResApi::Delete(gl1, 1, &id2); | 679 ResApi::Delete(gl1, 1, &id2); |
| 694 ResApi::Gen(gl2, 1, &id3); | 680 ResApi::Gen(gl2, 1, &id3); |
| 695 EXPECT_EQ(id1, id3); | 681 EXPECT_EQ(id1, id3); |
| 696 } | 682 } |
| 697 }; | 683 }; |
| 698 | 684 |
| 699 void GLES2ImplementationStrictSharedTest::SetUp() { | 685 void GLES2ImplementationStrictSharedTest::SetUp() { |
| 700 bool bind_generates_resource = false; | 686 Initialize(false); |
| 701 bool lose_context_when_out_of_memory = false; | |
| 702 Initialize(bind_generates_resource, lose_context_when_out_of_memory); | |
| 703 } | 687 } |
| 704 | 688 |
| 705 // GCC requires these declarations, but MSVC requires they not be present | 689 // GCC requires these declarations, but MSVC requires they not be present |
| 706 #ifndef _MSC_VER | 690 #ifndef _MSC_VER |
| 707 const uint8 GLES2ImplementationTest::kInitialValue; | 691 const uint8 GLES2ImplementationTest::kInitialValue; |
| 708 const int32 GLES2ImplementationTest::kNumCommandEntries; | 692 const int32 GLES2ImplementationTest::kNumCommandEntries; |
| 709 const int32 GLES2ImplementationTest::kCommandBufferSizeBytes; | 693 const int32 GLES2ImplementationTest::kCommandBufferSizeBytes; |
| 710 const size_t GLES2ImplementationTest::kTransferBufferSize; | 694 const size_t GLES2ImplementationTest::kTransferBufferSize; |
| 711 const GLint GLES2ImplementationTest::kMaxCombinedTextureImageUnits; | 695 const GLint GLES2ImplementationTest::kMaxCombinedTextureImageUnits; |
| 712 const GLint GLES2ImplementationTest::kMaxCubeMapTextureSize; | 696 const GLint GLES2ImplementationTest::kMaxCubeMapTextureSize; |
| (...skipping 2396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3109 GLbyte data[64]; | 3093 GLbyte data[64]; |
| 3110 }; | 3094 }; |
| 3111 | 3095 |
| 3112 Mailbox mailbox = Mailbox::Generate(); | 3096 Mailbox mailbox = Mailbox::Generate(); |
| 3113 Cmds expected; | 3097 Cmds expected; |
| 3114 expected.cmd.Init(GL_TEXTURE_2D, mailbox.name); | 3098 expected.cmd.Init(GL_TEXTURE_2D, mailbox.name); |
| 3115 gl_->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 3099 gl_->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 3116 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); | 3100 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); |
| 3117 } | 3101 } |
| 3118 | 3102 |
| 3119 TEST_F(GLES2ImplementationManualInitTest, LoseContextOnOOM) { | |
| 3120 bool bind_generates_resource = false; | |
| 3121 bool lose_context_when_out_of_memory = true; | |
| 3122 Initialize(bind_generates_resource, lose_context_when_out_of_memory); | |
| 3123 | |
| 3124 struct Cmds { | |
| 3125 cmds::LoseContextCHROMIUM cmd; | |
| 3126 }; | |
| 3127 | |
| 3128 GLsizei max = std::numeric_limits<GLsizei>::max(); | |
| 3129 EXPECT_CALL(*gpu_control_, CreateGpuMemoryBuffer(max, max, _, _)) | |
| 3130 .WillOnce(Return(static_cast<gfx::GpuMemoryBuffer*>(NULL))); | |
| 3131 gl_->CreateImageCHROMIUM(max, max, 0); | |
| 3132 // The context should be lost. | |
| 3133 Cmds expected; | |
| 3134 expected.cmd.Init(GL_GUILTY_CONTEXT_RESET_ARB, GL_UNKNOWN_CONTEXT_RESET_ARB); | |
| 3135 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); | |
| 3136 } | |
| 3137 | |
| 3138 TEST_F(GLES2ImplementationManualInitTest, NoLoseContextOnOOM) { | |
| 3139 bool bind_generates_resource = false; | |
| 3140 bool lose_context_when_out_of_memory = false; | |
| 3141 Initialize(bind_generates_resource, lose_context_when_out_of_memory); | |
| 3142 | |
| 3143 struct Cmds { | |
| 3144 cmds::LoseContextCHROMIUM cmd; | |
| 3145 }; | |
| 3146 | |
| 3147 GLsizei max = std::numeric_limits<GLsizei>::max(); | |
| 3148 EXPECT_CALL(*gpu_control_, CreateGpuMemoryBuffer(max, max, _, _)) | |
| 3149 .WillOnce(Return(static_cast<gfx::GpuMemoryBuffer*>(NULL))); | |
| 3150 gl_->CreateImageCHROMIUM(max, max, 0); | |
| 3151 // The context should not be lost. | |
| 3152 EXPECT_TRUE(NoCommandsWritten()); | |
| 3153 } | |
| 3154 | |
| 3155 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" | 3103 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" |
| 3156 | 3104 |
| 3157 } // namespace gles2 | 3105 } // namespace gles2 |
| 3158 } // namespace gpu | 3106 } // namespace gpu |
| OLD | NEW |