| 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/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 const uint32 kMaxVaryingVectors = 8; | 38 const uint32 kMaxVaryingVectors = 8; |
| 39 | 39 |
| 40 void ShaderCacheCb(const std::string& key, const std::string& shader) {} | 40 void ShaderCacheCb(const std::string& key, const std::string& shader) {} |
| 41 } // namespace anonymous | 41 } // namespace anonymous |
| 42 | 42 |
| 43 class ProgramManagerTest : public GpuServiceTest { | 43 class ProgramManagerTest : public GpuServiceTest { |
| 44 public: | 44 public: |
| 45 ProgramManagerTest() : manager_(NULL, kMaxVaryingVectors) { } | 45 ProgramManagerTest() : manager_(NULL, kMaxVaryingVectors) { } |
| 46 virtual ~ProgramManagerTest() { | 46 ~ProgramManagerTest() override { manager_.Destroy(false); } |
| 47 manager_.Destroy(false); | |
| 48 } | |
| 49 | 47 |
| 50 protected: | 48 protected: |
| 51 ProgramManager manager_; | 49 ProgramManager manager_; |
| 52 }; | 50 }; |
| 53 | 51 |
| 54 TEST_F(ProgramManagerTest, Basic) { | 52 TEST_F(ProgramManagerTest, Basic) { |
| 55 const GLuint kClient1Id = 1; | 53 const GLuint kClient1Id = 1; |
| 56 const GLuint kService1Id = 11; | 54 const GLuint kService1Id = 11; |
| 57 const GLuint kClient2Id = 2; | 55 const GLuint kClient2Id = 2; |
| 58 // Check we can create program. | 56 // Check we can create program. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 EXPECT_FALSE(program1->CanLink()); | 122 EXPECT_FALSE(program1->CanLink()); |
| 125 EXPECT_TRUE(program1->log_info() == NULL); | 123 EXPECT_TRUE(program1->log_info() == NULL); |
| 126 } | 124 } |
| 127 | 125 |
| 128 class ProgramManagerWithShaderTest : public GpuServiceTest { | 126 class ProgramManagerWithShaderTest : public GpuServiceTest { |
| 129 public: | 127 public: |
| 130 ProgramManagerWithShaderTest() | 128 ProgramManagerWithShaderTest() |
| 131 : manager_(NULL, kMaxVaryingVectors), program_(NULL) { | 129 : manager_(NULL, kMaxVaryingVectors), program_(NULL) { |
| 132 } | 130 } |
| 133 | 131 |
| 134 virtual ~ProgramManagerWithShaderTest() { | 132 ~ProgramManagerWithShaderTest() override { |
| 135 manager_.Destroy(false); | 133 manager_.Destroy(false); |
| 136 shader_manager_.Destroy(false); | 134 shader_manager_.Destroy(false); |
| 137 } | 135 } |
| 138 | 136 |
| 139 static const GLint kNumVertexAttribs = 16; | 137 static const GLint kNumVertexAttribs = 16; |
| 140 | 138 |
| 141 static const GLuint kClientProgramId = 123; | 139 static const GLuint kClientProgramId = 123; |
| 142 static const GLuint kServiceProgramId = 456; | 140 static const GLuint kServiceProgramId = 456; |
| 143 static const GLuint kVertexShaderClientId = 201; | 141 static const GLuint kVertexShaderClientId = 201; |
| 144 static const GLuint kFragmentShaderClientId = 202; | 142 static const GLuint kFragmentShaderClientId = 202; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 165 static const GLint kBadAttribIndex = kNumVertexAttribs; | 163 static const GLint kBadAttribIndex = kNumVertexAttribs; |
| 166 | 164 |
| 167 static const char* kUniform1Name; | 165 static const char* kUniform1Name; |
| 168 static const char* kUniform2Name; | 166 static const char* kUniform2Name; |
| 169 static const char* kUniform2NameWithArrayIndex; | 167 static const char* kUniform2NameWithArrayIndex; |
| 170 static const char* kUniform3Name; | 168 static const char* kUniform3Name; |
| 171 static const char* kUniform3NameWithArrayIndex; | 169 static const char* kUniform3NameWithArrayIndex; |
| 172 static const GLint kUniform1Size = 1; | 170 static const GLint kUniform1Size = 1; |
| 173 static const GLint kUniform2Size = 3; | 171 static const GLint kUniform2Size = 3; |
| 174 static const GLint kUniform3Size = 2; | 172 static const GLint kUniform3Size = 2; |
| 175 static const int kUniform1Precision = SH_PRECISION_LOWP; | 173 static const int kUniform1Precision = GL_LOW_FLOAT; |
| 176 static const int kUniform2Precision = SH_PRECISION_MEDIUMP; | 174 static const int kUniform2Precision = GL_MEDIUM_INT; |
| 177 static const int kUniform3Precision = SH_PRECISION_HIGHP; | 175 static const int kUniform3Precision = GL_HIGH_FLOAT; |
| 178 static const int kUniform1StaticUse = 1; | 176 static const int kUniform1StaticUse = 1; |
| 179 static const int kUniform2StaticUse = 1; | 177 static const int kUniform2StaticUse = 1; |
| 180 static const int kUniform3StaticUse = 1; | 178 static const int kUniform3StaticUse = 1; |
| 181 static const GLint kUniform1FakeLocation = 0; // These are hard coded | 179 static const GLint kUniform1FakeLocation = 0; // These are hard coded |
| 182 static const GLint kUniform2FakeLocation = 1; // to match | 180 static const GLint kUniform2FakeLocation = 1; // to match |
| 183 static const GLint kUniform3FakeLocation = 2; // ProgramManager. | 181 static const GLint kUniform3FakeLocation = 2; // ProgramManager. |
| 184 static const GLint kUniform1RealLocation = 11; | 182 static const GLint kUniform1RealLocation = 11; |
| 185 static const GLint kUniform2RealLocation = 22; | 183 static const GLint kUniform2RealLocation = 22; |
| 186 static const GLint kUniform3RealLocation = 33; | 184 static const GLint kUniform3RealLocation = 33; |
| 187 static const GLint kUniform1DesiredLocation = -1; | 185 static const GLint kUniform1DesiredLocation = -1; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 208 | 206 |
| 209 typedef struct { | 207 typedef struct { |
| 210 GLenum type; | 208 GLenum type; |
| 211 GLint size; | 209 GLint size; |
| 212 GLenum precision; | 210 GLenum precision; |
| 213 bool static_use; | 211 bool static_use; |
| 214 std::string name; | 212 std::string name; |
| 215 VarCategory category; | 213 VarCategory category; |
| 216 } VarInfo; | 214 } VarInfo; |
| 217 | 215 |
| 218 virtual void SetUp() { | 216 void SetUp() override { |
| 219 GpuServiceTest::SetUp(); | 217 GpuServiceTest::SetUp(); |
| 220 | 218 |
| 221 SetupDefaultShaderExpectations(); | 219 SetupDefaultShaderExpectations(); |
| 222 | 220 |
| 223 Shader* vertex_shader = shader_manager_.CreateShader( | 221 Shader* vertex_shader = shader_manager_.CreateShader( |
| 224 kVertexShaderClientId, kVertexShaderServiceId, GL_VERTEX_SHADER); | 222 kVertexShaderClientId, kVertexShaderServiceId, GL_VERTEX_SHADER); |
| 225 Shader* fragment_shader = | 223 Shader* fragment_shader = |
| 226 shader_manager_.CreateShader( | 224 shader_manager_.CreateShader( |
| 227 kFragmentShaderClientId, kFragmentShaderServiceId, | 225 kFragmentShaderClientId, kFragmentShaderServiceId, |
| 228 GL_FRAGMENT_SHADER); | 226 GL_FRAGMENT_SHADER); |
| (...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 // Set up shader | 1121 // Set up shader |
| 1124 const GLuint kVShaderClientId = 1; | 1122 const GLuint kVShaderClientId = 1; |
| 1125 const GLuint kVShaderServiceId = 11; | 1123 const GLuint kVShaderServiceId = 11; |
| 1126 const GLuint kFShaderClientId = 2; | 1124 const GLuint kFShaderClientId = 2; |
| 1127 const GLuint kFShaderServiceId = 12; | 1125 const GLuint kFShaderServiceId = 12; |
| 1128 AttributeMap attrib_map; | 1126 AttributeMap attrib_map; |
| 1129 for (uint32 ii = 0; ii < kNumAttribs; ++ii) { | 1127 for (uint32 ii = 0; ii < kNumAttribs; ++ii) { |
| 1130 attrib_map[kAttribs[ii].name] = TestHelper::ConstructAttribute( | 1128 attrib_map[kAttribs[ii].name] = TestHelper::ConstructAttribute( |
| 1131 kAttribs[ii].type, | 1129 kAttribs[ii].type, |
| 1132 kAttribs[ii].size, | 1130 kAttribs[ii].size, |
| 1133 SH_PRECISION_MEDIUMP, | 1131 GL_MEDIUM_FLOAT, |
| 1134 kAttribStaticUse, | 1132 kAttribStaticUse, |
| 1135 kAttribs[ii].name); | 1133 kAttribs[ii].name); |
| 1136 } | 1134 } |
| 1137 const char kAttribMatName[] = "matAttrib"; | 1135 const char kAttribMatName[] = "matAttrib"; |
| 1138 attrib_map[kAttribMatName] = TestHelper::ConstructAttribute( | 1136 attrib_map[kAttribMatName] = TestHelper::ConstructAttribute( |
| 1139 GL_FLOAT_MAT2, | 1137 GL_FLOAT_MAT2, |
| 1140 1, | 1138 1, |
| 1141 SH_PRECISION_MEDIUMP, | 1139 GL_MEDIUM_FLOAT, |
| 1142 kAttribStaticUse, | 1140 kAttribStaticUse, |
| 1143 kAttribMatName); | 1141 kAttribMatName); |
| 1144 // Check we can create shader. | 1142 // Check we can create shader. |
| 1145 Shader* vshader = shader_manager_.CreateShader( | 1143 Shader* vshader = shader_manager_.CreateShader( |
| 1146 kVShaderClientId, kVShaderServiceId, GL_VERTEX_SHADER); | 1144 kVShaderClientId, kVShaderServiceId, GL_VERTEX_SHADER); |
| 1147 Shader* fshader = shader_manager_.CreateShader( | 1145 Shader* fshader = shader_manager_.CreateShader( |
| 1148 kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER); | 1146 kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER); |
| 1149 // Check shader got created. | 1147 // Check shader got created. |
| 1150 ASSERT_TRUE(vshader != NULL && fshader != NULL); | 1148 ASSERT_TRUE(vshader != NULL && fshader != NULL); |
| 1151 // Set Status | 1149 // Set Status |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1572 static const GLuint kVertexShaderServiceId = 3; | 1570 static const GLuint kVertexShaderServiceId = 3; |
| 1573 static const GLuint kFragmentShaderServiceId = 30; | 1571 static const GLuint kFragmentShaderServiceId = 30; |
| 1574 | 1572 |
| 1575 ProgramManagerWithCacheTest() | 1573 ProgramManagerWithCacheTest() |
| 1576 : cache_(new MockProgramCache()), | 1574 : cache_(new MockProgramCache()), |
| 1577 manager_(cache_.get(), kMaxVaryingVectors), | 1575 manager_(cache_.get(), kMaxVaryingVectors), |
| 1578 vertex_shader_(NULL), | 1576 vertex_shader_(NULL), |
| 1579 fragment_shader_(NULL), | 1577 fragment_shader_(NULL), |
| 1580 program_(NULL) { | 1578 program_(NULL) { |
| 1581 } | 1579 } |
| 1582 virtual ~ProgramManagerWithCacheTest() { | 1580 ~ProgramManagerWithCacheTest() override { |
| 1583 manager_.Destroy(false); | 1581 manager_.Destroy(false); |
| 1584 shader_manager_.Destroy(false); | 1582 shader_manager_.Destroy(false); |
| 1585 } | 1583 } |
| 1586 | 1584 |
| 1587 protected: | 1585 protected: |
| 1588 virtual void SetUp() { | 1586 void SetUp() override { |
| 1589 GpuServiceTest::SetUp(); | 1587 GpuServiceTest::SetUp(); |
| 1590 | 1588 |
| 1591 vertex_shader_ = shader_manager_.CreateShader( | 1589 vertex_shader_ = shader_manager_.CreateShader( |
| 1592 kVertexShaderClientId, kVertexShaderServiceId, GL_VERTEX_SHADER); | 1590 kVertexShaderClientId, kVertexShaderServiceId, GL_VERTEX_SHADER); |
| 1593 fragment_shader_ = shader_manager_.CreateShader( | 1591 fragment_shader_ = shader_manager_.CreateShader( |
| 1594 kFragmentShaderClientId, kFragmentShaderServiceId, GL_FRAGMENT_SHADER); | 1592 kFragmentShaderClientId, kFragmentShaderServiceId, GL_FRAGMENT_SHADER); |
| 1595 ASSERT_TRUE(vertex_shader_ != NULL); | 1593 ASSERT_TRUE(vertex_shader_ != NULL); |
| 1596 ASSERT_TRUE(fragment_shader_ != NULL); | 1594 ASSERT_TRUE(fragment_shader_ != NULL); |
| 1597 vertex_shader_->set_source("lka asjf bjajsdfj"); | 1595 vertex_shader_->set_source("lka asjf bjajsdfj"); |
| 1598 fragment_shader_->set_source("lka asjf a fasgag 3rdsf3 bjajsdfj"); | 1596 fragment_shader_->set_source("lka asjf a fasgag 3rdsf3 bjajsdfj"); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1782 SetExpectationsForProgramLoad(ProgramCache::PROGRAM_LOAD_SUCCESS); | 1780 SetExpectationsForProgramLoad(ProgramCache::PROGRAM_LOAD_SUCCESS); |
| 1783 SetExpectationsForNotCachingProgram(); | 1781 SetExpectationsForNotCachingProgram(); |
| 1784 SetExpectationsForProgramLoadSuccess(); | 1782 SetExpectationsForProgramLoadSuccess(); |
| 1785 | 1783 |
| 1786 EXPECT_TRUE(program_->Link(NULL, NULL, NULL, | 1784 EXPECT_TRUE(program_->Link(NULL, NULL, NULL, |
| 1787 Program::kCountOnlyStaticallyUsed, base::Bind(&ShaderCacheCb))); | 1785 Program::kCountOnlyStaticallyUsed, base::Bind(&ShaderCacheCb))); |
| 1788 } | 1786 } |
| 1789 | 1787 |
| 1790 } // namespace gles2 | 1788 } // namespace gles2 |
| 1791 } // namespace gpu | 1789 } // namespace gpu |
| OLD | NEW |