| 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 #include "gpu/command_buffer/service/program_manager.h" | 5 #include "gpu/command_buffer/service/program_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 10 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 12 #include "gpu/command_buffer/common/gl_mock.h" | 13 #include "gpu/command_buffer/common/gl_mock.h" |
| 13 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 14 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 14 #include "gpu/command_buffer/service/common_decoder.h" | 15 #include "gpu/command_buffer/service/common_decoder.h" |
| 15 #include "gpu/command_buffer/service/mocks.h" | 16 #include "gpu/command_buffer/service/mocks.h" |
| 16 #include "gpu/command_buffer/service/test_helper.h" | 17 #include "gpu/command_buffer/service/test_helper.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 using ::gfx::MockGLInterface; | 20 using ::gfx::MockGLInterface; |
| 20 using ::testing::_; | 21 using ::testing::_; |
| 21 using ::testing::DoAll; | 22 using ::testing::DoAll; |
| 22 using ::testing::InSequence; | 23 using ::testing::InSequence; |
| 23 using ::testing::MatcherCast; | 24 using ::testing::MatcherCast; |
| 24 using ::testing::Pointee; | 25 using ::testing::Pointee; |
| 25 using ::testing::Return; | 26 using ::testing::Return; |
| 26 using ::testing::ReturnRef; | 27 using ::testing::ReturnRef; |
| 27 using ::testing::SetArrayArgument; | 28 using ::testing::SetArrayArgument; |
| 28 using ::testing::SetArgumentPointee; | 29 using ::testing::SetArgumentPointee; |
| 29 using ::testing::StrEq; | 30 using ::testing::StrEq; |
| 30 using ::testing::StrictMock; | 31 using ::testing::StrictMock; |
| 31 | 32 |
| 32 namespace gpu { | 33 namespace gpu { |
| 33 namespace gles2 { | 34 namespace gles2 { |
| 35 class ProgramCache; |
| 34 | 36 |
| 35 class ProgramManagerTest : public testing::Test { | 37 class ProgramManagerTest : public testing::Test { |
| 36 public: | 38 public: |
| 37 ProgramManagerTest() { } | 39 ProgramManagerTest() : manager_(base::WeakPtr<ProgramCache>()) { } |
| 38 ~ProgramManagerTest() { | 40 ~ProgramManagerTest() { |
| 39 manager_.Destroy(false); | 41 manager_.Destroy(false); |
| 40 } | 42 } |
| 41 | 43 |
| 42 protected: | 44 protected: |
| 43 virtual void SetUp() { | 45 virtual void SetUp() { |
| 44 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); | 46 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
| 45 ::gfx::GLInterface::SetGLInterface(gl_.get()); | 47 ::gfx::GLInterface::SetGLInterface(gl_.get()); |
| 46 } | 48 } |
| 47 | 49 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 for (GLint ii = -limit; ii < limit; ii += power) { | 139 for (GLint ii = -limit; ii < limit; ii += power) { |
| 138 GLint s = manager_.SwizzleLocation(ii); | 140 GLint s = manager_.SwizzleLocation(ii); |
| 139 EXPECT_EQ(ii, manager_.UnswizzleLocation(s)); | 141 EXPECT_EQ(ii, manager_.UnswizzleLocation(s)); |
| 140 } | 142 } |
| 141 } | 143 } |
| 142 } | 144 } |
| 143 | 145 |
| 144 class ProgramManagerWithShaderTest : public testing::Test { | 146 class ProgramManagerWithShaderTest : public testing::Test { |
| 145 public: | 147 public: |
| 146 ProgramManagerWithShaderTest() | 148 ProgramManagerWithShaderTest() |
| 147 : program_info_(NULL) { | 149 : manager_(base::WeakPtr<ProgramCache>()), program_info_(NULL) { |
| 148 } | 150 } |
| 149 | 151 |
| 150 ~ProgramManagerWithShaderTest() { | 152 ~ProgramManagerWithShaderTest() { |
| 151 manager_.Destroy(false); | 153 manager_.Destroy(false); |
| 152 shader_manager_.Destroy(false); | 154 shader_manager_.Destroy(false); |
| 153 } | 155 } |
| 154 | 156 |
| 155 static const GLint kNumVertexAttribs = 16; | 157 static const GLint kNumVertexAttribs = 16; |
| 156 | 158 |
| 157 static const GLuint kClientProgramId = 123; | 159 static const GLuint kClientProgramId = 123; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 ASSERT_TRUE(fragment_shader != NULL); | 220 ASSERT_TRUE(fragment_shader != NULL); |
| 219 vertex_shader->SetStatus(true, NULL, NULL); | 221 vertex_shader->SetStatus(true, NULL, NULL); |
| 220 fragment_shader->SetStatus(true, NULL, NULL); | 222 fragment_shader->SetStatus(true, NULL, NULL); |
| 221 | 223 |
| 222 program_info_ = manager_.CreateProgramInfo( | 224 program_info_ = manager_.CreateProgramInfo( |
| 223 kClientProgramId, kServiceProgramId); | 225 kClientProgramId, kServiceProgramId); |
| 224 ASSERT_TRUE(program_info_ != NULL); | 226 ASSERT_TRUE(program_info_ != NULL); |
| 225 | 227 |
| 226 program_info_->AttachShader(&shader_manager_, vertex_shader); | 228 program_info_->AttachShader(&shader_manager_, vertex_shader); |
| 227 program_info_->AttachShader(&shader_manager_, fragment_shader); | 229 program_info_->AttachShader(&shader_manager_, fragment_shader); |
| 228 program_info_->Link(); | 230 program_info_->Link(NULL, NULL, NULL, NULL); |
| 229 } | 231 } |
| 230 | 232 |
| 231 void SetupShader(AttribInfo* attribs, size_t num_attribs, | 233 void SetupShader(AttribInfo* attribs, size_t num_attribs, |
| 232 UniformInfo* uniforms, size_t num_uniforms, | 234 UniformInfo* uniforms, size_t num_uniforms, |
| 233 GLuint service_id) { | 235 GLuint service_id) { |
| 234 TestHelper::SetupShader( | 236 TestHelper::SetupShader( |
| 235 gl_.get(), attribs, num_attribs, uniforms, num_uniforms, service_id); | 237 gl_.get(), attribs, num_attribs, uniforms, num_uniforms, service_id); |
| 236 } | 238 } |
| 237 | 239 |
| 238 void SetupDefaultShaderExpectations() { | 240 void SetupDefaultShaderExpectations() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 251 } | 253 } |
| 252 | 254 |
| 253 // Return true if link status matches expected_link_status | 255 // Return true if link status matches expected_link_status |
| 254 bool LinkAsExpected(ProgramManager::ProgramInfo* program_info, | 256 bool LinkAsExpected(ProgramManager::ProgramInfo* program_info, |
| 255 bool expected_link_status) { | 257 bool expected_link_status) { |
| 256 GLuint service_id = program_info->service_id(); | 258 GLuint service_id = program_info->service_id(); |
| 257 if (expected_link_status) { | 259 if (expected_link_status) { |
| 258 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, | 260 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, |
| 259 service_id); | 261 service_id); |
| 260 } | 262 } |
| 261 program_info->Link(); | 263 program_info->Link(NULL, NULL, NULL, NULL); |
| 262 GLint link_status; | 264 GLint link_status; |
| 263 program_info->GetProgramiv(GL_LINK_STATUS, &link_status); | 265 program_info->GetProgramiv(GL_LINK_STATUS, &link_status); |
| 264 return (static_cast<bool>(link_status) == expected_link_status); | 266 return (static_cast<bool>(link_status) == expected_link_status); |
| 265 } | 267 } |
| 266 | 268 |
| 267 static AttribInfo kAttribs[]; | 269 static AttribInfo kAttribs[]; |
| 268 static UniformInfo kUniforms[]; | 270 static UniformInfo kUniforms[]; |
| 269 | 271 |
| 270 scoped_ptr<StrictMock<gfx::MockGLInterface> > gl_; | 272 scoped_ptr<StrictMock<gfx::MockGLInterface> > gl_; |
| 271 | 273 |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 vshader->SetStatus(true, "", NULL); | 580 vshader->SetStatus(true, "", NULL); |
| 579 ShaderManager::ShaderInfo* fshader = shader_manager_.CreateShaderInfo( | 581 ShaderManager::ShaderInfo* fshader = shader_manager_.CreateShaderInfo( |
| 580 kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER); | 582 kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER); |
| 581 ASSERT_TRUE(fshader != NULL); | 583 ASSERT_TRUE(fshader != NULL); |
| 582 fshader->SetStatus(true, "", NULL); | 584 fshader->SetStatus(true, "", NULL); |
| 583 ProgramManager::ProgramInfo* program_info = | 585 ProgramManager::ProgramInfo* program_info = |
| 584 manager_.CreateProgramInfo(kClientProgramId, kServiceProgramId); | 586 manager_.CreateProgramInfo(kClientProgramId, kServiceProgramId); |
| 585 ASSERT_TRUE(program_info != NULL); | 587 ASSERT_TRUE(program_info != NULL); |
| 586 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, vshader)); | 588 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, vshader)); |
| 587 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, fshader)); | 589 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, fshader)); |
| 588 program_info->Link(); | 590 program_info->Link(NULL, NULL, NULL, NULL); |
| 589 GLint value = 0; | 591 GLint value = 0; |
| 590 program_info->GetProgramiv(GL_ACTIVE_ATTRIBUTES, &value); | 592 program_info->GetProgramiv(GL_ACTIVE_ATTRIBUTES, &value); |
| 591 EXPECT_EQ(3, value); | 593 EXPECT_EQ(3, value); |
| 592 // Check that we skipped the "gl_" uniform. | 594 // Check that we skipped the "gl_" uniform. |
| 593 program_info->GetProgramiv(GL_ACTIVE_UNIFORMS, &value); | 595 program_info->GetProgramiv(GL_ACTIVE_UNIFORMS, &value); |
| 594 EXPECT_EQ(2, value); | 596 EXPECT_EQ(2, value); |
| 595 // Check that our max length adds room for the array spec and is not as long | 597 // Check that our max length adds room for the array spec and is not as long |
| 596 // as the "gl_" uniform we skipped. | 598 // as the "gl_" uniform we skipped. |
| 597 // +4u is to account for "gl_" and NULL terminator. | 599 // +4u is to account for "gl_" and NULL terminator. |
| 598 program_info->GetProgramiv(GL_ACTIVE_UNIFORM_MAX_LENGTH, &value); | 600 program_info->GetProgramiv(GL_ACTIVE_UNIFORM_MAX_LENGTH, &value); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 const size_t kNumUniforms = arraysize(kUniforms); | 671 const size_t kNumUniforms = arraysize(kUniforms); |
| 670 static const GLuint kClientProgramId = 1234; | 672 static const GLuint kClientProgramId = 1234; |
| 671 static const GLuint kServiceProgramId = 5679; | 673 static const GLuint kServiceProgramId = 5679; |
| 672 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, | 674 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, |
| 673 kServiceProgramId); | 675 kServiceProgramId); |
| 674 ProgramManager::ProgramInfo* program_info = manager_.CreateProgramInfo( | 676 ProgramManager::ProgramInfo* program_info = manager_.CreateProgramInfo( |
| 675 kClientProgramId, kServiceProgramId); | 677 kClientProgramId, kServiceProgramId); |
| 676 ASSERT_TRUE(program_info != NULL); | 678 ASSERT_TRUE(program_info != NULL); |
| 677 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, vshader)); | 679 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, vshader)); |
| 678 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, fshader)); | 680 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, fshader)); |
| 679 program_info->Link(); | 681 program_info->Link(NULL, NULL, NULL, NULL); |
| 680 // Check that we got the good type, not the bad. | 682 // Check that we got the good type, not the bad. |
| 681 // Check Attribs | 683 // Check Attribs |
| 682 for (unsigned index = 0; index < kNumAttribs; ++index) { | 684 for (unsigned index = 0; index < kNumAttribs; ++index) { |
| 683 const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info = | 685 const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info = |
| 684 program_info->GetAttribInfo(index); | 686 program_info->GetAttribInfo(index); |
| 685 ASSERT_TRUE(attrib_info != NULL); | 687 ASSERT_TRUE(attrib_info != NULL); |
| 686 ShaderTranslator::VariableMap::const_iterator it = attrib_map.find( | 688 ShaderTranslator::VariableMap::const_iterator it = attrib_map.find( |
| 687 attrib_info->name); | 689 attrib_info->name); |
| 688 ASSERT_TRUE(it != attrib_map.end()); | 690 ASSERT_TRUE(it != attrib_map.end()); |
| 689 EXPECT_EQ(it->first, attrib_info->name); | 691 EXPECT_EQ(it->first, attrib_info->name); |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 kUniform3Type, | 988 kUniform3Type, |
| 987 kUniform3FakeLocation, | 989 kUniform3FakeLocation, |
| 988 kUniform3RealLocation, | 990 kUniform3RealLocation, |
| 989 kUniform3GoodName, | 991 kUniform3GoodName, |
| 990 }, | 992 }, |
| 991 }; | 993 }; |
| 992 const size_t kNumAttribs = arraysize(kAttribs); | 994 const size_t kNumAttribs = arraysize(kAttribs); |
| 993 const size_t kNumUniforms = arraysize(kUniforms); | 995 const size_t kNumUniforms = arraysize(kUniforms); |
| 994 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, | 996 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, |
| 995 kServiceProgramId); | 997 kServiceProgramId); |
| 996 program_info->Link(); | 998 program_info->Link(NULL, NULL, NULL, NULL); |
| 997 SetupExpectationsForClearingUniforms(kUniforms, kNumUniforms); | 999 SetupExpectationsForClearingUniforms(kUniforms, kNumUniforms); |
| 998 manager_.ClearUniforms(program_info); | 1000 manager_.ClearUniforms(program_info); |
| 999 } | 1001 } |
| 1000 } | 1002 } |
| 1001 | 1003 |
| 1002 } // namespace gles2 | 1004 } // namespace gles2 |
| 1003 } // namespace gpu | 1005 } // namespace gpu |
| 1004 | 1006 |
| 1005 | 1007 |
| OLD | NEW |