diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-29 16:19:57 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-29 16:19:57 +0000 |
commit | d685a68049c3bacf00e108afe1da6a0807b2ab3c (patch) | |
tree | 93a622490926084dd45916d9ebc55593fc8c7a41 | |
parent | ac99f574ce31ea615eeb80252b0d0f9a8ed16a36 (diff) | |
download | chromium_src-d685a68049c3bacf00e108afe1da6a0807b2ab3c.zip chromium_src-d685a68049c3bacf00e108afe1da6a0807b2ab3c.tar.gz chromium_src-d685a68049c3bacf00e108afe1da6a0807b2ab3c.tar.bz2 |
Fix Issue that glProgramInfoLog was not called if program did not link.
TEST=unit tests
BUG=none
Review URL: http://codereview.chromium.org/6904077
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83523 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder.cc | 34 | ||||
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder_unittest_1.cc | 61 | ||||
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder_unittest_3.cc | 39 | ||||
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder_unittest_3_autogen.h | 14 | ||||
-rw-r--r-- | gpu/command_buffer/service/program_manager.cc | 41 | ||||
-rw-r--r-- | gpu/command_buffer/service/program_manager.h | 36 | ||||
-rw-r--r-- | gpu/command_buffer/service/program_manager_unittest.cc | 212 | ||||
-rw-r--r-- | gpu/command_buffer/service/shader_manager.cc | 8 | ||||
-rw-r--r-- | gpu/command_buffer/service/shader_manager.h | 7 | ||||
-rw-r--r-- | gpu/command_buffer/service/shader_manager_unittest.cc | 38 | ||||
-rw-r--r-- | gpu/gpu.gyp | 2 |
11 files changed, 337 insertions, 155 deletions
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index d7dccf2..13e73c1 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -858,8 +858,9 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, const void * data); // Creates a ProgramInfo for the given program. - void CreateProgramInfo(GLuint client_id, GLuint service_id) { - program_manager()->CreateProgramInfo(client_id, service_id); + ProgramManager::ProgramInfo* CreateProgramInfo( + GLuint client_id, GLuint service_id) { + return program_manager()->CreateProgramInfo(client_id, service_id); } // Gets the program info for the given program. Returns NULL if none exists. @@ -887,10 +888,12 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, // Creates a ShaderInfo for the given shader. - void CreateShaderInfo(GLuint client_id, - GLuint service_id, - GLenum shader_type) { - shader_manager()->CreateShaderInfo(client_id, service_id, shader_type); + ShaderManager::ShaderInfo* CreateShaderInfo( + GLuint client_id, + GLuint service_id, + GLenum shader_type) { + return shader_manager()->CreateShaderInfo( + client_id, service_id, shader_type); } // Gets the shader info for the given shader. Returns NULL if none exists. @@ -3709,17 +3712,7 @@ void GLES2DecoderImpl::DoLinkProgram(GLuint program) { return; } - info->ClearLinkStatus(); - if (!info->CanLink()) { - return; - } - - glLinkProgram(info->service_id()); - GLint success = 0; - glGetProgramiv(info->service_id(), GL_LINK_STATUS, &success); - if (success) { - info->Update(); - } + info->Link(); }; void GLES2DecoderImpl::DoTexParameterf( @@ -4625,12 +4618,7 @@ void GLES2DecoderImpl::DoValidateProgram(GLuint program_client_id) { if (!info) { return; } - if (!info->CanLink()) { - info->set_log_info("Missing Shader"); - return; - } - glValidateProgram(info->service_id()); - info->UpdateLogInfo(); + info->Validate(); } void GLES2DecoderImpl::DoGetVertexAttribfv( diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_1.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_1.cc index 3e7b33a..9497dbc 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_1.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_1.cc @@ -149,8 +149,67 @@ void GLES2DecoderTestBase::SpecializedSetup<GetRenderbufferParameteriv, 0>( template <> void GLES2DecoderTestBase::SpecializedSetup<GetProgramInfoLog, 0>( bool /* valid */) { + const GLuint kClientVertexShaderId = 5001; + const GLuint kServiceVertexShaderId = 6001; + const GLuint kClientFragmentShaderId = 5002; + const GLuint kServiceFragmentShaderId = 6002; + const char* log = "hello"; // Matches auto-generated unit test. + DoCreateShader( + GL_VERTEX_SHADER, kClientVertexShaderId, kServiceVertexShaderId); + DoCreateShader( + GL_FRAGMENT_SHADER, kClientFragmentShaderId, kServiceFragmentShaderId); + + GetShaderInfo(kClientVertexShaderId)->SetStatus(true, "", NULL); + GetShaderInfo(kClientFragmentShaderId)->SetStatus(true, "", NULL); + + InSequence dummy; + EXPECT_CALL(*gl_, + AttachShader(kServiceProgramId, kServiceVertexShaderId)) + .Times(1) + .RetiresOnSaturation(); + EXPECT_CALL(*gl_, + AttachShader(kServiceProgramId, kServiceFragmentShaderId)) + .Times(1) + .RetiresOnSaturation(); + EXPECT_CALL(*gl_, LinkProgram(kServiceProgramId)) + .Times(1) + .RetiresOnSaturation(); + EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _)) + .WillOnce(SetArgumentPointee<2>(1)); + EXPECT_CALL(*gl_, + GetProgramiv(kServiceProgramId, GL_INFO_LOG_LENGTH, _)) + .WillOnce(SetArgumentPointee<2>(strlen(log) + 1)) + .RetiresOnSaturation(); + EXPECT_CALL(*gl_, + GetProgramInfoLog(kServiceProgramId, strlen(log) + 1, _, _)) + .WillOnce(DoAll( + SetArgumentPointee<2>(strlen(log)), + SetArrayArgument<3>(log, log + strlen(log) + 1))) + .RetiresOnSaturation(); + EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_ACTIVE_ATTRIBUTES, _)) + .WillOnce(SetArgumentPointee<2>(0)); + EXPECT_CALL( + *gl_, + GetProgramiv(kServiceProgramId, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, _)) + .WillOnce(SetArgumentPointee<2>(0)); + EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_ACTIVE_UNIFORMS, _)) + .WillOnce(SetArgumentPointee<2>(0)); + EXPECT_CALL( + *gl_, + GetProgramiv(kServiceProgramId, GL_ACTIVE_UNIFORM_MAX_LENGTH, _)) + .WillOnce(SetArgumentPointee<2>(0)); + ProgramManager::ProgramInfo* info = GetProgramInfo(client_program_id_); - info->set_log_info("hello"); + ASSERT_TRUE(info != NULL); + + AttachShader attach_cmd; + attach_cmd.Init(client_program_id_, kClientVertexShaderId); + EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd)); + + attach_cmd.Init(client_program_id_, kClientFragmentShaderId); + EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd)); + + info->Link(); }; template <> diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_3.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_3.cc new file mode 100644 index 0000000..04ae5c3 --- /dev/null +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_3.cc @@ -0,0 +1,39 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "gpu/command_buffer/service/gles2_cmd_decoder.h" + +#include "gpu/command_buffer/common/gl_mock.h" +#include "gpu/command_buffer/common/gles2_cmd_format.h" +#include "gpu/command_buffer/common/gles2_cmd_utils.h" +#include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h" +#include "gpu/command_buffer/service/cmd_buffer_engine.h" +#include "gpu/command_buffer/service/context_group.h" +#include "gpu/command_buffer/service/program_manager.h" +#include "testing/gtest/include/gtest/gtest.h" + +using ::gfx::MockGLInterface; +using ::testing::_; +using ::testing::DoAll; +using ::testing::InSequence; +using ::testing::MatcherCast; +using ::testing::Pointee; +using ::testing::Return; +using ::testing::SetArrayArgument; +using ::testing::SetArgumentPointee; +using ::testing::StrEq; + +namespace gpu { +namespace gles2 { + +class GLES2DecoderTest3 : public GLES2DecoderTestBase { + public: + GLES2DecoderTest3() { } +}; + +#include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_3_autogen.h" + +} // namespace gles2 +} // namespace gpu + diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_3_autogen.h b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_3_autogen.h new file mode 100644 index 0000000..72cd0c3 --- /dev/null +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_3_autogen.h @@ -0,0 +1,14 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file is auto-generated. DO NOT EDIT! + +// It is included by gles2_cmd_decoder_unittest_3.cc +#ifndef GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_3_AUTOGEN_H_ +#define GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_3_AUTOGEN_H_ + +// TODO(gman): WaitLatchCHROMIUM + +#endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_3_AUTOGEN_H_ + diff --git a/gpu/command_buffer/service/program_manager.cc b/gpu/command_buffer/service/program_manager.cc index 3bc5dea..3591e4d 100644 --- a/gpu/command_buffer/service/program_manager.cc +++ b/gpu/command_buffer/service/program_manager.cc @@ -27,9 +27,10 @@ static int ShaderTypeToIndex(GLenum shader_type) { } } -ProgramManager::ProgramInfo::UniformInfo::UniformInfo(GLsizei _size, - GLenum _type, - const std::string& _name) +ProgramManager::ProgramInfo::UniformInfo::UniformInfo( + GLsizei _size, + GLenum _type, + const std::string& _name) : size(_size), type(_type), is_array(false), @@ -63,7 +64,6 @@ void ProgramManager::ProgramInfo::Reset() { sampler_indices_.clear(); attrib_location_to_index_map_.clear(); location_infos_.clear(); - UpdateLogInfo(); } void ProgramManager::ProgramInfo::UpdateLogInfo() { @@ -83,6 +83,7 @@ void ProgramManager::ProgramInfo::UpdateLogInfo() { void ProgramManager::ProgramInfo::Update() { Reset(); + UpdateLogInfo(); link_status_ = true; GLint num_attribs = 0; GLint max_len = 0; @@ -171,6 +172,32 @@ void ProgramManager::ProgramInfo::Update() { valid_ = true; } +void ProgramManager::ProgramInfo::Link() { + ClearLinkStatus(); + if (!CanLink()) { + set_log_info("missing shaders"); + return; + } + + glLinkProgram(service_id()); + GLint success = 0; + glGetProgramiv(service_id(), GL_LINK_STATUS, &success); + if (success) { + Update(); + } else { + UpdateLogInfo(); + } +} + +void ProgramManager::ProgramInfo::Validate() { + if (!IsValid()) { + set_log_info("program not linked"); + return; + } + glValidateProgram(service_id()); + UpdateLogInfo(); +} + GLint ProgramManager::ProgramInfo::GetUniformLocation( const std::string& name) const { for (GLuint ii = 0; ii < uniform_infos_.size(); ++ii) { @@ -354,7 +381,7 @@ void ProgramManager::ProgramInfo::GetProgramiv(GLenum pname, GLint* params) { *params = log_info_.get() ? (log_info_->size() + 1) : 0; break; case GL_VALIDATE_STATUS: - if (!CanLink()) { + if (!IsValid()) { *params = GL_FALSE; } else { glGetProgramiv(service_id_, pname, params); @@ -432,12 +459,14 @@ void ProgramManager::Destroy(bool have_context) { } } -void ProgramManager::CreateProgramInfo(GLuint client_id, GLuint service_id) { +ProgramManager::ProgramInfo* ProgramManager::CreateProgramInfo( + GLuint client_id, GLuint service_id) { std::pair<ProgramInfoMap::iterator, bool> result = program_infos_.insert( std::make_pair(client_id, ProgramInfo::Ref(new ProgramInfo(service_id)))); DCHECK(result.second); + return result.first->second; } ProgramManager::ProgramInfo* ProgramManager::GetProgramInfo(GLuint client_id) { diff --git a/gpu/command_buffer/service/program_manager.h b/gpu/command_buffer/service/program_manager.h index 3255db6..4344a88 100644 --- a/gpu/command_buffer/service/program_manager.h +++ b/gpu/command_buffer/service/program_manager.h @@ -76,12 +76,6 @@ class ProgramManager { return sampler_indices_; } - // Updates the program info after a successful link. - void Update(); - - // Updates the program log info. - void UpdateLogInfo(); - const AttribInfoVector& GetAttribInfos() const { return attrib_infos_; } @@ -130,23 +124,21 @@ class ProgramManager { return valid_; } - void ClearLinkStatus() { - link_status_ = false; - } - bool AttachShader(ShaderManager* manager, ShaderManager::ShaderInfo* info); bool DetachShader(ShaderManager* manager, ShaderManager::ShaderInfo* info); bool CanLink() const; + // Performs glLinkProgram and related activities. + void Link(); + + // Performs glValidateProgram and related activities. + void Validate(); + const std::string* log_info() const { return log_info_.get(); } - void set_log_info(const char* str) { - log_info_.reset(str ? new std::string(str) : NULL); - } - bool InUse() const { DCHECK_GE(use_count_, 0); return use_count_ != 0; @@ -172,6 +164,14 @@ class ProgramManager { ~ProgramInfo(); + void set_log_info(const char* str) { + log_info_.reset(str ? new std::string(str) : NULL); + } + + void ClearLinkStatus() { + link_status_ = false; + } + void IncUseCount() { ++use_count_; } @@ -189,6 +189,12 @@ class ProgramManager { // Resets the program. void Reset(); + // Updates the program info after a successful link. + void Update(); + + // Updates the program log info from GL + void UpdateLogInfo(); + const UniformInfo* AddUniformInfo( GLsizei size, GLenum type, GLint location, const std::string& name); @@ -242,7 +248,7 @@ class ProgramManager { void Destroy(bool have_context); // Creates a new program info. - void CreateProgramInfo(GLuint client_id, GLuint service_id); + ProgramInfo* CreateProgramInfo(GLuint client_id, GLuint service_id); // Gets a program info ProgramInfo* GetProgramInfo(GLuint client_id); diff --git a/gpu/command_buffer/service/program_manager_unittest.cc b/gpu/command_buffer/service/program_manager_unittest.cc index a6edd9f..bb3fb0f 100644 --- a/gpu/command_buffer/service/program_manager_unittest.cc +++ b/gpu/command_buffer/service/program_manager_unittest.cc @@ -72,11 +72,12 @@ TEST_F(ProgramManagerTest, Destroy) { const GLuint kClient1Id = 1; const GLuint kService1Id = 11; // Check we can create program. - manager_.CreateProgramInfo(kClient1Id, kService1Id); + ProgramManager::ProgramInfo* info0 = manager_.CreateProgramInfo( + kClient1Id, kService1Id); + ASSERT_TRUE(info0 != NULL); // Check program got created. - ProgramManager::ProgramInfo* info1 = - manager_.GetProgramInfo(kClient1Id); - ASSERT_TRUE(info1 != NULL); + ProgramManager::ProgramInfo* info1 = manager_.GetProgramInfo(kClient1Id); + ASSERT_EQ(info0, info1); EXPECT_CALL(*gl_, DeleteProgram(kService1Id)) .Times(1) .RetiresOnSaturation(); @@ -93,13 +94,13 @@ TEST_F(ProgramManagerTest, DeleteBug) { const GLuint kService1Id = 11; const GLuint kService2Id = 12; // Check we can create program. - manager_.CreateProgramInfo(kClient1Id, kService1Id); - manager_.CreateProgramInfo(kClient2Id, kService2Id); + ProgramManager::ProgramInfo::Ref info1( + manager_.CreateProgramInfo(kClient1Id, kService1Id)); + ProgramManager::ProgramInfo::Ref info2( + manager_.CreateProgramInfo(kClient2Id, kService2Id)); // Check program got created. - ProgramManager::ProgramInfo::Ref info1(manager_.GetProgramInfo(kClient1Id)); - ProgramManager::ProgramInfo::Ref info2(manager_.GetProgramInfo(kClient2Id)); - ASSERT_TRUE(info1.get() != NULL); - ASSERT_TRUE(info2.get() != NULL); + ASSERT_TRUE(info1); + ASSERT_TRUE(info2); manager_.UseProgram(info1); manager_.MarkAsDeleted(&shader_manager, info1); manager_.MarkAsDeleted(&shader_manager, info2); @@ -111,10 +112,9 @@ TEST_F(ProgramManagerTest, ProgramInfo) { const GLuint kClient1Id = 1; const GLuint kService1Id = 11; // Check we can create program. - manager_.CreateProgramInfo(kClient1Id, kService1Id); - // Check program got created. - ProgramManager::ProgramInfo* info1 = manager_.GetProgramInfo(kClient1Id); - ASSERT_TRUE(info1 != NULL); + ProgramManager::ProgramInfo* info1 = manager_.CreateProgramInfo( + kClient1Id, kService1Id); + ASSERT_TRUE(info1); EXPECT_EQ(kService1Id, info1->service_id()); EXPECT_FALSE(info1->InUse()); EXPECT_FALSE(info1->IsValid()); @@ -131,12 +131,17 @@ class ProgramManagerWithShaderTest : public testing::Test { ~ProgramManagerWithShaderTest() { manager_.Destroy(false); + shader_manager_.Destroy(false); } static const GLint kNumVertexAttribs = 16; static const GLuint kClientProgramId = 123; static const GLuint kServiceProgramId = 456; + static const GLuint kVertexShaderClientId = 201; + static const GLuint kFragmentShaderClientId = 202; + static const GLuint kVertexShaderServiceId = 301; + static const GLuint kFragmentShaderServiceId = 302; static const char* kAttrib1Name; static const char* kAttrib2Name; @@ -193,15 +198,39 @@ class ProgramManagerWithShaderTest : public testing::Test { SetupDefaultShaderExpectations(); - manager_.CreateProgramInfo(kClientProgramId, kServiceProgramId); - program_info_ = manager_.GetProgramInfo(kClientProgramId); - program_info_->Update(); + ShaderManager::ShaderInfo* vertex_shader = shader_manager_.CreateShaderInfo( + kVertexShaderClientId, kVertexShaderServiceId, GL_VERTEX_SHADER); + ShaderManager::ShaderInfo* fragment_shader = + shader_manager_.CreateShaderInfo( + kFragmentShaderClientId, kFragmentShaderServiceId, + GL_FRAGMENT_SHADER); + ASSERT_TRUE(vertex_shader != NULL); + ASSERT_TRUE(fragment_shader != NULL); + vertex_shader->SetStatus(true, NULL, NULL); + fragment_shader->SetStatus(true, NULL, NULL); + + program_info_ = manager_.CreateProgramInfo( + kClientProgramId, kServiceProgramId); + ASSERT_TRUE(program_info_ != NULL); + + program_info_->AttachShader(&shader_manager_, vertex_shader); + program_info_->AttachShader(&shader_manager_, fragment_shader); + program_info_->Link(); } void SetupShader(AttribInfo* attribs, size_t num_attribs, UniformInfo* uniforms, size_t num_uniforms, GLuint service_id) { InSequence s; + + EXPECT_CALL(*gl_, + LinkProgram(service_id)) + .Times(1) + .RetiresOnSaturation(); + EXPECT_CALL(*gl_, + GetProgramiv(service_id, GL_LINK_STATUS, _)) + .WillOnce(SetArgumentPointee<2>(1)) + .RetiresOnSaturation(); EXPECT_CALL(*gl_, GetProgramiv(service_id, GL_INFO_LOG_LENGTH, _)) .WillOnce(SetArgumentPointee<2>(0)) @@ -303,8 +332,8 @@ class ProgramManagerWithShaderTest : public testing::Test { scoped_ptr<StrictMock<gfx::MockGLInterface> > gl_; ProgramManager manager_; - ProgramManager::ProgramInfo* program_info_; + ShaderManager shader_manager_; }; ProgramManagerWithShaderTest::AttribInfo @@ -319,6 +348,10 @@ ProgramManagerWithShaderTest::AttribInfo const GLint ProgramManagerWithShaderTest::kNumVertexAttribs; const GLuint ProgramManagerWithShaderTest::kClientProgramId; const GLuint ProgramManagerWithShaderTest::kServiceProgramId; +const GLuint ProgramManagerWithShaderTest::kVertexShaderClientId; +const GLuint ProgramManagerWithShaderTest::kFragmentShaderClientId; +const GLuint ProgramManagerWithShaderTest::kVertexShaderServiceId; +const GLuint ProgramManagerWithShaderTest::kFragmentShaderServiceId; const GLint ProgramManagerWithShaderTest::kAttrib1Size; const GLint ProgramManagerWithShaderTest::kAttrib2Size; const GLint ProgramManagerWithShaderTest::kAttrib3Size; @@ -372,6 +405,7 @@ TEST_F(ProgramManagerWithShaderTest, GetAttribInfos) { ASSERT_TRUE(program_info != NULL); const ProgramManager::ProgramInfo::AttribInfoVector& infos = program_info->GetAttribInfos(); + ASSERT_EQ(kNumAttribs, infos.size()); for (size_t ii = 0; ii < kNumAttribs; ++ii) { const ProgramManager::ProgramInfo::VertexAttribInfo& info = infos[ii]; const AttribInfo& expected = kAttribs[ii]; @@ -437,38 +471,37 @@ TEST_F(ProgramManagerWithShaderTest, GetUniformInfo) { } TEST_F(ProgramManagerWithShaderTest, AttachDetachShader) { - ShaderManager shader_manager; - ProgramManager::ProgramInfo* program_info = - manager_.GetProgramInfo(kClientProgramId); + static const GLuint kClientProgramId = 124; + static const GLuint kServiceProgramId = 457; + ProgramManager::ProgramInfo* program_info = manager_.CreateProgramInfo( + kClientProgramId, kServiceProgramId); ASSERT_TRUE(program_info != NULL); EXPECT_FALSE(program_info->CanLink()); const GLuint kVShaderClientId = 2001; const GLuint kFShaderClientId = 2002; const GLuint kVShaderServiceId = 3001; const GLuint kFShaderServiceId = 3002; - shader_manager.CreateShaderInfo( + ShaderManager::ShaderInfo* vshader = shader_manager_.CreateShaderInfo( kVShaderClientId, kVShaderServiceId, GL_VERTEX_SHADER); - ShaderManager::ShaderInfo* vshader = shader_manager.GetShaderInfo( - kVShaderClientId); + ASSERT_TRUE(vshader != NULL); vshader->SetStatus(true, "", NULL); - shader_manager.CreateShaderInfo( + ShaderManager::ShaderInfo* fshader = shader_manager_.CreateShaderInfo( kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER); - ShaderManager::ShaderInfo* fshader = shader_manager.GetShaderInfo( - kFShaderClientId); + ASSERT_TRUE(fshader != NULL); fshader->SetStatus(true, "", NULL); - EXPECT_TRUE(program_info->AttachShader(&shader_manager, vshader)); + EXPECT_TRUE(program_info->AttachShader(&shader_manager_, vshader)); EXPECT_FALSE(program_info->CanLink()); - EXPECT_TRUE(program_info->AttachShader(&shader_manager, fshader)); + EXPECT_TRUE(program_info->AttachShader(&shader_manager_, fshader)); EXPECT_TRUE(program_info->CanLink()); - program_info->DetachShader(&shader_manager, vshader); + program_info->DetachShader(&shader_manager_, vshader); EXPECT_FALSE(program_info->CanLink()); - EXPECT_TRUE(program_info->AttachShader(&shader_manager, vshader)); + EXPECT_TRUE(program_info->AttachShader(&shader_manager_, vshader)); EXPECT_TRUE(program_info->CanLink()); - program_info->DetachShader(&shader_manager, fshader); + program_info->DetachShader(&shader_manager_, fshader); EXPECT_FALSE(program_info->CanLink()); - EXPECT_FALSE(program_info->AttachShader(&shader_manager, vshader)); + EXPECT_FALSE(program_info->AttachShader(&shader_manager_, vshader)); EXPECT_FALSE(program_info->CanLink()); - EXPECT_TRUE(program_info->AttachShader(&shader_manager, fshader)); + EXPECT_TRUE(program_info->AttachShader(&shader_manager_, fshader)); EXPECT_TRUE(program_info->CanLink()); vshader->SetStatus(false, "", NULL); EXPECT_FALSE(program_info->CanLink()); @@ -478,9 +511,8 @@ TEST_F(ProgramManagerWithShaderTest, AttachDetachShader) { EXPECT_FALSE(program_info->CanLink()); fshader->SetStatus(true, "", NULL); EXPECT_TRUE(program_info->CanLink()); - EXPECT_TRUE(program_info->DetachShader(&shader_manager, fshader)); - EXPECT_FALSE(program_info->DetachShader(&shader_manager, fshader)); - shader_manager.Destroy(false); + EXPECT_TRUE(program_info->DetachShader(&shader_manager_, fshader)); + EXPECT_FALSE(program_info->DetachShader(&shader_manager_, fshader)); } TEST_F(ProgramManagerWithShaderTest, GetUniformLocation) { @@ -547,13 +579,26 @@ TEST_F(ProgramManagerWithShaderTest, GLDriverReturnsGLUnderscoreUniform) { const size_t kNumUniforms = arraysize(kUniforms); static const GLuint kClientProgramId = 1234; static const GLuint kServiceProgramId = 5679; - SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, - kServiceProgramId); - manager_.CreateProgramInfo(kClientProgramId, kServiceProgramId); + const GLuint kVShaderClientId = 2001; + const GLuint kFShaderClientId = 2002; + const GLuint kVShaderServiceId = 3001; + const GLuint kFShaderServiceId = 3002; + SetupShader( + kAttribs, kNumAttribs, kUniforms, kNumUniforms, kServiceProgramId); + ShaderManager::ShaderInfo* vshader = shader_manager_.CreateShaderInfo( + kVShaderClientId, kVShaderServiceId, GL_VERTEX_SHADER); + ASSERT_TRUE(vshader != NULL); + vshader->SetStatus(true, "", NULL); + ShaderManager::ShaderInfo* fshader = shader_manager_.CreateShaderInfo( + kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER); + ASSERT_TRUE(fshader != NULL); + fshader->SetStatus(true, "", NULL); ProgramManager::ProgramInfo* program_info = - manager_.GetProgramInfo(kClientProgramId); + manager_.CreateProgramInfo(kClientProgramId, kServiceProgramId); ASSERT_TRUE(program_info != NULL); - program_info->Update(); + EXPECT_TRUE(program_info->AttachShader(&shader_manager_, vshader)); + EXPECT_TRUE(program_info->AttachShader(&shader_manager_, fshader)); + program_info->Link(); GLint value = 0; program_info->GetProgramiv(GL_ACTIVE_ATTRIBUTES, &value); EXPECT_EQ(3, value); @@ -570,8 +615,6 @@ TEST_F(ProgramManagerWithShaderTest, GLDriverReturnsGLUnderscoreUniform) { // Some GL drivers incorrectly return the wrong type. For example they return // GL_FLOAT_VEC2 when they should return GL_FLOAT_MAT2. Check we handle this. TEST_F(ProgramManagerWithShaderTest, GLDriverReturnsWrongTypeInfo) { - const GLuint kShaderClientId = 999; - const GLuint kShaderServiceId = 998; static GLenum kAttrib2BadType = GL_FLOAT_VEC2; static GLenum kAttrib2GoodType = GL_FLOAT_MAT2; static GLenum kUniform2BadType = GL_FLOAT_VEC3; @@ -595,12 +638,18 @@ TEST_F(ProgramManagerWithShaderTest, GLDriverReturnsWrongTypeInfo) { .WillRepeatedly(ReturnRef(attrib_map)); EXPECT_CALL(shader_translator, uniform_map()) .WillRepeatedly(ReturnRef(uniform_map)); - ShaderManager shader_manager; - shader_manager.CreateShaderInfo( - kShaderClientId, kShaderServiceId, GL_FRAGMENT_SHADER); - ShaderManager::ShaderInfo* shader_info = - shader_manager.GetShaderInfo(kShaderClientId); - shader_info->SetStatus(true, "", &shader_translator); + const GLuint kVShaderClientId = 2001; + const GLuint kFShaderClientId = 2002; + const GLuint kVShaderServiceId = 3001; + const GLuint kFShaderServiceId = 3002; + ShaderManager::ShaderInfo* vshader = shader_manager_.CreateShaderInfo( + kVShaderClientId, kVShaderServiceId, GL_VERTEX_SHADER); + ASSERT_TRUE(vshader != NULL); + vshader->SetStatus(true, "", &shader_translator); + ShaderManager::ShaderInfo* fshader = shader_manager_.CreateShaderInfo( + kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER); + ASSERT_TRUE(fshader != NULL); + fshader->SetStatus(true, "", &shader_translator); static ProgramManagerWithShaderTest::AttribInfo kAttribs[] = { { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, }, { kAttrib2Name, kAttrib2Size, kAttrib2BadType, kAttrib2Location, }, @@ -617,12 +666,12 @@ TEST_F(ProgramManagerWithShaderTest, GLDriverReturnsWrongTypeInfo) { static const GLuint kServiceProgramId = 5679; SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, kServiceProgramId); - manager_.CreateProgramInfo(kClientProgramId, kServiceProgramId); - ProgramManager::ProgramInfo* program_info = - manager_.GetProgramInfo(kClientProgramId); + ProgramManager::ProgramInfo* program_info = manager_.CreateProgramInfo( + kClientProgramId, kServiceProgramId); ASSERT_TRUE(program_info != NULL); - EXPECT_TRUE(program_info->AttachShader(&shader_manager, shader_info)); - program_info->Update(); + EXPECT_TRUE(program_info->AttachShader(&shader_manager_, vshader)); + EXPECT_TRUE(program_info->AttachShader(&shader_manager_, fshader)); + program_info->Link(); // Check that we got the good type, not the bad. // Check Attribs for (unsigned index = 0; index < kNumAttribs; ++index) { @@ -648,36 +697,32 @@ TEST_F(ProgramManagerWithShaderTest, GLDriverReturnsWrongTypeInfo) { EXPECT_EQ(static_cast<GLenum>(it->second.type), uniform_info->type); EXPECT_EQ(it->second.size, uniform_info->size); } - shader_manager.Destroy(false); } TEST_F(ProgramManagerWithShaderTest, ProgramInfoUseCount) { - ShaderManager shader_manager; - ProgramManager::ProgramInfo* program_info = - manager_.GetProgramInfo(kClientProgramId); + static const GLuint kClientProgramId = 124; + static const GLuint kServiceProgramId = 457; + ProgramManager::ProgramInfo* program_info = manager_.CreateProgramInfo( + kClientProgramId, kServiceProgramId); ASSERT_TRUE(program_info != NULL); EXPECT_FALSE(program_info->CanLink()); const GLuint kVShaderClientId = 2001; const GLuint kFShaderClientId = 2002; const GLuint kVShaderServiceId = 3001; const GLuint kFShaderServiceId = 3002; - shader_manager.CreateShaderInfo( + ShaderManager::ShaderInfo* vshader = shader_manager_.CreateShaderInfo( kVShaderClientId, kVShaderServiceId, GL_VERTEX_SHADER); - ShaderManager::ShaderInfo* vshader = shader_manager.GetShaderInfo( - kVShaderClientId); ASSERT_TRUE(vshader != NULL); vshader->SetStatus(true, "", NULL); - shader_manager.CreateShaderInfo( + ShaderManager::ShaderInfo* fshader = shader_manager_.CreateShaderInfo( kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER); - ShaderManager::ShaderInfo* fshader = shader_manager.GetShaderInfo( - kFShaderClientId); ASSERT_TRUE(fshader != NULL); fshader->SetStatus(true, "", NULL); EXPECT_FALSE(vshader->InUse()); EXPECT_FALSE(fshader->InUse()); - EXPECT_TRUE(program_info->AttachShader(&shader_manager, vshader)); + EXPECT_TRUE(program_info->AttachShader(&shader_manager_, vshader)); EXPECT_TRUE(vshader->InUse()); - EXPECT_TRUE(program_info->AttachShader(&shader_manager, fshader)); + EXPECT_TRUE(program_info->AttachShader(&shader_manager_, fshader)); EXPECT_TRUE(fshader->InUse()); EXPECT_TRUE(program_info->CanLink()); EXPECT_FALSE(program_info->InUse()); @@ -686,49 +731,45 @@ TEST_F(ProgramManagerWithShaderTest, ProgramInfoUseCount) { EXPECT_TRUE(program_info->InUse()); manager_.UseProgram(program_info); EXPECT_TRUE(program_info->InUse()); - manager_.MarkAsDeleted(&shader_manager, program_info); + manager_.MarkAsDeleted(&shader_manager_, program_info); EXPECT_TRUE(program_info->IsDeleted()); ProgramManager::ProgramInfo* info2 = manager_.GetProgramInfo(kClientProgramId); EXPECT_EQ(program_info, info2); - manager_.UnuseProgram(&shader_manager, program_info); + manager_.UnuseProgram(&shader_manager_, program_info); EXPECT_TRUE(program_info->InUse()); // this should delete the info. - manager_.UnuseProgram(&shader_manager, program_info); + manager_.UnuseProgram(&shader_manager_, program_info); info2 = manager_.GetProgramInfo(kClientProgramId); EXPECT_TRUE(info2 == NULL); EXPECT_FALSE(vshader->InUse()); EXPECT_FALSE(fshader->InUse()); - shader_manager.Destroy(false); } TEST_F(ProgramManagerWithShaderTest, ProgramInfoUseCount2) { - ShaderManager shader_manager; - ProgramManager::ProgramInfo* program_info = - manager_.GetProgramInfo(kClientProgramId); + static const GLuint kClientProgramId = 124; + static const GLuint kServiceProgramId = 457; + ProgramManager::ProgramInfo* program_info = manager_.CreateProgramInfo( + kClientProgramId, kServiceProgramId); ASSERT_TRUE(program_info != NULL); EXPECT_FALSE(program_info->CanLink()); const GLuint kVShaderClientId = 2001; const GLuint kFShaderClientId = 2002; const GLuint kVShaderServiceId = 3001; const GLuint kFShaderServiceId = 3002; - shader_manager.CreateShaderInfo( + ShaderManager::ShaderInfo* vshader = shader_manager_.CreateShaderInfo( kVShaderClientId, kVShaderServiceId, GL_VERTEX_SHADER); - ShaderManager::ShaderInfo* vshader = shader_manager.GetShaderInfo( - kVShaderClientId); ASSERT_TRUE(vshader != NULL); vshader->SetStatus(true, "", NULL); - shader_manager.CreateShaderInfo( + ShaderManager::ShaderInfo* fshader = shader_manager_.CreateShaderInfo( kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER); - ShaderManager::ShaderInfo* fshader = shader_manager.GetShaderInfo( - kFShaderClientId); ASSERT_TRUE(fshader != NULL); fshader->SetStatus(true, "", NULL); EXPECT_FALSE(vshader->InUse()); EXPECT_FALSE(fshader->InUse()); - EXPECT_TRUE(program_info->AttachShader(&shader_manager, vshader)); + EXPECT_TRUE(program_info->AttachShader(&shader_manager_, vshader)); EXPECT_TRUE(vshader->InUse()); - EXPECT_TRUE(program_info->AttachShader(&shader_manager, fshader)); + EXPECT_TRUE(program_info->AttachShader(&shader_manager_, fshader)); EXPECT_TRUE(fshader->InUse()); EXPECT_TRUE(program_info->CanLink()); EXPECT_FALSE(program_info->InUse()); @@ -737,20 +778,19 @@ TEST_F(ProgramManagerWithShaderTest, ProgramInfoUseCount2) { EXPECT_TRUE(program_info->InUse()); manager_.UseProgram(program_info); EXPECT_TRUE(program_info->InUse()); - manager_.UnuseProgram(&shader_manager, program_info); + manager_.UnuseProgram(&shader_manager_, program_info); EXPECT_TRUE(program_info->InUse()); - manager_.UnuseProgram(&shader_manager, program_info); + manager_.UnuseProgram(&shader_manager_, program_info); EXPECT_FALSE(program_info->InUse()); ProgramManager::ProgramInfo* info2 = manager_.GetProgramInfo(kClientProgramId); EXPECT_EQ(program_info, info2); // this should delete the program. - manager_.MarkAsDeleted(&shader_manager, program_info); + manager_.MarkAsDeleted(&shader_manager_, program_info); info2 = manager_.GetProgramInfo(kClientProgramId); EXPECT_TRUE(info2 == NULL); EXPECT_FALSE(vshader->InUse()); EXPECT_FALSE(fshader->InUse()); - shader_manager.Destroy(false); } } // namespace gles2 diff --git a/gpu/command_buffer/service/shader_manager.cc b/gpu/command_buffer/service/shader_manager.cc index f85eb4d..b230581 100644 --- a/gpu/command_buffer/service/shader_manager.cc +++ b/gpu/command_buffer/service/shader_manager.cc @@ -78,13 +78,15 @@ void ShaderManager::Destroy(bool have_context) { } } -void ShaderManager::CreateShaderInfo(GLuint client_id, - GLuint service_id, - GLenum shader_type) { +ShaderManager::ShaderInfo* ShaderManager::CreateShaderInfo( + GLuint client_id, + GLuint service_id, + GLenum shader_type) { std::pair<ShaderInfoMap::iterator, bool> result = shader_infos_.insert(std::make_pair( client_id, ShaderInfo::Ref(new ShaderInfo(service_id, shader_type)))); DCHECK(result.second); + return result.first->second; } ShaderManager::ShaderInfo* ShaderManager::GetShaderInfo(GLuint client_id) { diff --git a/gpu/command_buffer/service/shader_manager.h b/gpu/command_buffer/service/shader_manager.h index 59dbca8..c0f8e68 100644 --- a/gpu/command_buffer/service/shader_manager.h +++ b/gpu/command_buffer/service/shader_manager.h @@ -113,9 +113,10 @@ class ShaderManager { void Destroy(bool have_context); // Creates a shader info for the given shader ID. - void CreateShaderInfo(GLuint client_id, - GLuint service_id, - GLenum shader_type); + ShaderInfo* CreateShaderInfo( + GLuint client_id, + GLuint service_id, + GLenum shader_type); // Gets an existing shader info for the given shader ID. Returns NULL if none // exists. diff --git a/gpu/command_buffer/service/shader_manager_unittest.cc b/gpu/command_buffer/service/shader_manager_unittest.cc index acde8783..ea1fcf5 100644 --- a/gpu/command_buffer/service/shader_manager_unittest.cc +++ b/gpu/command_buffer/service/shader_manager_unittest.cc @@ -46,10 +46,12 @@ TEST_F(ShaderManagerTest, Basic) { const GLenum kShader1Type = GL_VERTEX_SHADER; const GLuint kClient2Id = 2; // Check we can create shader. - manager_.CreateShaderInfo(kClient1Id, kService1Id, kShader1Type); + ShaderManager::ShaderInfo* info0 = manager_.CreateShaderInfo( + kClient1Id, kService1Id, kShader1Type); // Check shader got created. + ASSERT_TRUE(info0 != NULL); ShaderManager::ShaderInfo* info1 = manager_.GetShaderInfo(kClient1Id); - ASSERT_TRUE(info1 != NULL); + ASSERT_EQ(info0, info1); // Check we get nothing for a non-existent shader. EXPECT_TRUE(manager_.GetShaderInfo(kClient2Id) == NULL); // Check we can't get the shader after we remove it. @@ -62,9 +64,9 @@ TEST_F(ShaderManagerTest, Destroy) { const GLuint kService1Id = 11; const GLenum kShader1Type = GL_VERTEX_SHADER; // Check we can create shader. - manager_.CreateShaderInfo(kClient1Id, kService1Id, kShader1Type); + ShaderManager::ShaderInfo* info1 = manager_.CreateShaderInfo( + kClient1Id, kService1Id, kShader1Type); // Check shader got created. - ShaderManager::ShaderInfo* info1 = manager_.GetShaderInfo(kClient1Id); ASSERT_TRUE(info1 != NULL); EXPECT_CALL(*gl_, DeleteShader(kService1Id)) .Times(1) @@ -82,12 +84,12 @@ TEST_F(ShaderManagerTest, DeleteBug) { const GLuint kService2Id = 12; const GLenum kShaderType = GL_VERTEX_SHADER; // Check we can create shader. - manager_.CreateShaderInfo(kClient1Id, kService1Id, kShaderType); - manager_.CreateShaderInfo(kClient2Id, kService2Id, kShaderType); - ShaderManager::ShaderInfo::Ref info1(manager_.GetShaderInfo(kClient1Id)); - ShaderManager::ShaderInfo::Ref info2(manager_.GetShaderInfo(kClient2Id)); - ASSERT_TRUE(info1.get() != NULL); - ASSERT_TRUE(info2.get() != NULL); + ShaderManager::ShaderInfo::Ref info1( + manager_.CreateShaderInfo(kClient1Id, kService1Id, kShaderType)); + ShaderManager::ShaderInfo::Ref info2( + manager_.CreateShaderInfo(kClient2Id, kService2Id, kShaderType)); + ASSERT_TRUE(info1); + ASSERT_TRUE(info2); manager_.UseShader(info1); manager_.MarkAsDeleted(info1); manager_.MarkAsDeleted(info2); @@ -101,9 +103,9 @@ TEST_F(ShaderManagerTest, ShaderInfo) { const GLenum kShader1Type = GL_VERTEX_SHADER; const char* kClient1Source = "hello world"; // Check we can create shader. - manager_.CreateShaderInfo(kClient1Id, kService1Id, kShader1Type); + ShaderManager::ShaderInfo* info1 = manager_.CreateShaderInfo( + kClient1Id, kService1Id, kShader1Type); // Check shader got created. - ShaderManager::ShaderInfo* info1 = manager_.GetShaderInfo(kClient1Id); ASSERT_TRUE(info1 != NULL); EXPECT_EQ(kService1Id, info1->service_id()); // Check if the shader has correct type. @@ -153,9 +155,10 @@ TEST_F(ShaderManagerTest, GetInfo) { EXPECT_CALL(shader_translator, uniform_map()) .WillRepeatedly(ReturnRef(uniform_map)); // Check we can create shader. - manager_.CreateShaderInfo(kClient1Id, kService1Id, kShader1Type); + ShaderManager::ShaderInfo* info1 = manager_.CreateShaderInfo( + kClient1Id, kService1Id, kShader1Type); // Check shader got created. - ShaderManager::ShaderInfo* info1 = manager_.GetShaderInfo(kClient1Id); + ASSERT_TRUE(info1 != NULL); // Set Status info1->SetStatus(true, "", &shader_translator); // Check attrib and uniform infos got copied. @@ -197,9 +200,9 @@ TEST_F(ShaderManagerTest, ShaderInfoUseCount) { const GLuint kService1Id = 11; const GLenum kShader1Type = GL_VERTEX_SHADER; // Check we can create shader. - manager_.CreateShaderInfo(kClient1Id, kService1Id, kShader1Type); + ShaderManager::ShaderInfo* info1 = manager_.CreateShaderInfo( + kClient1Id, kService1Id, kShader1Type); // Check shader got created. - ShaderManager::ShaderInfo* info1 = manager_.GetShaderInfo(kClient1Id); ASSERT_TRUE(info1 != NULL); EXPECT_FALSE(info1->InUse()); EXPECT_FALSE(info1->IsDeleted()); @@ -217,8 +220,7 @@ TEST_F(ShaderManagerTest, ShaderInfoUseCount) { info2 = manager_.GetShaderInfo(kClient1Id); EXPECT_TRUE(info2 == NULL); - manager_.CreateShaderInfo(kClient1Id, kService1Id, kShader1Type); - info1 = manager_.GetShaderInfo(kClient1Id); + info1 = manager_.CreateShaderInfo(kClient1Id, kService1Id, kShader1Type); ASSERT_TRUE(info1 != NULL); EXPECT_FALSE(info1->InUse()); manager_.UseShader(info1); diff --git a/gpu/gpu.gyp b/gpu/gpu.gyp index 86cc084..265ec80 100644 --- a/gpu/gpu.gyp +++ b/gpu/gpu.gyp @@ -308,6 +308,8 @@ 'command_buffer/service/gles2_cmd_decoder_unittest_1_autogen.h', 'command_buffer/service/gles2_cmd_decoder_unittest_2.cc', 'command_buffer/service/gles2_cmd_decoder_unittest_2_autogen.h', + 'command_buffer/service/gles2_cmd_decoder_unittest_3.cc', + 'command_buffer/service/gles2_cmd_decoder_unittest_3_autogen.h', 'command_buffer/service/id_manager_unittest.cc', 'command_buffer/service/mocks.cc', 'command_buffer/service/mocks.h', |