| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "base/scoped_ptr.h" | 6 #include "base/scoped_ptr.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "gpu/command_buffer/service/gl_mock.h" | 9 #include "gpu/command_buffer/service/gl_mock.h" |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 virtual void SetUp() { | 31 virtual void SetUp() { |
| 32 } | 32 } |
| 33 | 33 |
| 34 virtual void TearDown() { | 34 virtual void TearDown() { |
| 35 } | 35 } |
| 36 | 36 |
| 37 ProgramManager manager_; | 37 ProgramManager manager_; |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 TEST_F(ProgramManagerTest, Basic) { | 40 TEST_F(ProgramManagerTest, Basic) { |
| 41 const GLuint kProgram1Id = 1; | 41 const GLuint kClient1Id = 1; |
| 42 const GLuint kProgram2Id = 2; | 42 const GLuint kService1Id = 11; |
| 43 const GLuint kClient2Id = 2; |
| 43 // Check we can create program. | 44 // Check we can create program. |
| 44 manager_.CreateProgramInfo(kProgram1Id); | 45 manager_.CreateProgramInfo(kClient1Id, kService1Id); |
| 45 // Check program got created. | 46 // Check program got created. |
| 46 ProgramManager::ProgramInfo* info1 = manager_.GetProgramInfo(kProgram1Id); | 47 ProgramManager::ProgramInfo* info1 = manager_.GetProgramInfo(kClient1Id); |
| 47 ASSERT_TRUE(info1 != NULL); | 48 ASSERT_TRUE(info1 != NULL); |
| 49 EXPECT_EQ(kService1Id, info1->service_id()); |
| 48 // Check we get nothing for a non-existent program. | 50 // Check we get nothing for a non-existent program. |
| 49 EXPECT_TRUE(manager_.GetProgramInfo(kProgram2Id) == NULL); | 51 EXPECT_TRUE(manager_.GetProgramInfo(kClient2Id) == NULL); |
| 50 // Check trying to a remove non-existent programs does not crash. | 52 // Check trying to a remove non-existent programs does not crash. |
| 51 manager_.RemoveProgramInfo(kProgram2Id); | 53 manager_.RemoveProgramInfo(kClient2Id); |
| 52 // Check we can't get the program after we remove it. | 54 // Check we can't get the program after we remove it. |
| 53 manager_.RemoveProgramInfo(kProgram1Id); | 55 manager_.RemoveProgramInfo(kClient1Id); |
| 54 EXPECT_TRUE(manager_.GetProgramInfo(kProgram1Id) == NULL); | 56 EXPECT_TRUE(manager_.GetProgramInfo(kClient1Id) == NULL); |
| 55 } | 57 } |
| 56 | 58 |
| 57 class ProgramManagerWithShaderTest : public testing::Test { | 59 class ProgramManagerWithShaderTest : public testing::Test { |
| 58 public: | 60 public: |
| 59 ProgramManagerWithShaderTest() | 61 ProgramManagerWithShaderTest() |
| 60 : program_info_(NULL) { | 62 : program_info_(NULL) { |
| 61 } | 63 } |
| 62 | 64 |
| 63 static const GLint kNumVertexAttribs = 16; | 65 static const GLint kNumVertexAttribs = 16; |
| 64 | 66 |
| 65 static const GLuint kProgramId = 123; | 67 static const GLuint kClientProgramId = 123; |
| 68 static const GLuint kServiceProgramId = 456; |
| 66 | 69 |
| 67 static const char* kAttrib1Name; | 70 static const char* kAttrib1Name; |
| 68 static const char* kAttrib2Name; | 71 static const char* kAttrib2Name; |
| 69 static const char* kAttrib3Name; | 72 static const char* kAttrib3Name; |
| 70 static const GLint kAttrib1Size = 1; | 73 static const GLint kAttrib1Size = 1; |
| 71 static const GLint kAttrib2Size = 1; | 74 static const GLint kAttrib2Size = 1; |
| 72 static const GLint kAttrib3Size = 1; | 75 static const GLint kAttrib3Size = 1; |
| 73 static const GLint kAttrib1Location = 0; | 76 static const GLint kAttrib1Location = 0; |
| 74 static const GLint kAttrib2Location = 1; | 77 static const GLint kAttrib2Location = 1; |
| 75 static const GLint kAttrib3Location = 2; | 78 static const GLint kAttrib3Location = 2; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 GLenum type; | 114 GLenum type; |
| 112 GLint location; | 115 GLint location; |
| 113 }; | 116 }; |
| 114 | 117 |
| 115 virtual void SetUp() { | 118 virtual void SetUp() { |
| 116 gl_.reset(new StrictMock<MockGLInterface>()); | 119 gl_.reset(new StrictMock<MockGLInterface>()); |
| 117 ::gles2::GLInterface::SetGLInterface(gl_.get()); | 120 ::gles2::GLInterface::SetGLInterface(gl_.get()); |
| 118 | 121 |
| 119 SetupDefaultShaderExpectations(); | 122 SetupDefaultShaderExpectations(); |
| 120 | 123 |
| 121 manager_.CreateProgramInfo(kProgramId); | 124 manager_.CreateProgramInfo(kClientProgramId, kServiceProgramId); |
| 122 program_info_ = manager_.GetProgramInfo(kProgramId); | 125 program_info_ = manager_.GetProgramInfo(kClientProgramId); |
| 123 program_info_->Update(); | 126 program_info_->Update(); |
| 124 } | 127 } |
| 125 | 128 |
| 126 void SetupShader(AttribInfo* attribs, size_t num_attribs, | 129 void SetupShader(AttribInfo* attribs, size_t num_attribs, |
| 127 UniformInfo* uniforms, size_t num_uniforms, | 130 UniformInfo* uniforms, size_t num_uniforms, |
| 128 GLuint service_id) { | 131 GLuint service_id) { |
| 129 InSequence s; | 132 InSequence s; |
| 130 EXPECT_CALL(*gl_, | 133 EXPECT_CALL(*gl_, |
| 131 GetProgramiv(service_id, GL_ACTIVE_ATTRIBUTES, _)) | 134 GetProgramiv(service_id, GL_ACTIVE_ATTRIBUTES, _)) |
| 132 .WillOnce(SetArgumentPointee<2>(num_attribs)) | 135 .WillOnce(SetArgumentPointee<2>(num_attribs)) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 .RetiresOnSaturation(); | 202 .RetiresOnSaturation(); |
| 200 } | 203 } |
| 201 } | 204 } |
| 202 } | 205 } |
| 203 } | 206 } |
| 204 } | 207 } |
| 205 | 208 |
| 206 | 209 |
| 207 void SetupDefaultShaderExpectations() { | 210 void SetupDefaultShaderExpectations() { |
| 208 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, | 211 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, |
| 209 kProgramId); | 212 kServiceProgramId); |
| 210 } | 213 } |
| 211 | 214 |
| 212 virtual void TearDown() { | 215 virtual void TearDown() { |
| 213 } | 216 } |
| 214 | 217 |
| 215 static AttribInfo kAttribs[]; | 218 static AttribInfo kAttribs[]; |
| 216 static UniformInfo kUniforms[]; | 219 static UniformInfo kUniforms[]; |
| 217 | 220 |
| 218 scoped_ptr<StrictMock<MockGLInterface> > gl_; | 221 scoped_ptr<StrictMock<MockGLInterface> > gl_; |
| 219 | 222 |
| 220 ProgramManager manager_; | 223 ProgramManager manager_; |
| 221 | 224 |
| 222 ProgramManager::ProgramInfo* program_info_; | 225 ProgramManager::ProgramInfo* program_info_; |
| 223 }; | 226 }; |
| 224 | 227 |
| 225 ProgramManagerWithShaderTest::AttribInfo | 228 ProgramManagerWithShaderTest::AttribInfo |
| 226 ProgramManagerWithShaderTest::kAttribs[] = { | 229 ProgramManagerWithShaderTest::kAttribs[] = { |
| 227 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, }, | 230 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, }, |
| 228 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, }, | 231 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, }, |
| 229 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, }, | 232 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, }, |
| 230 }; | 233 }; |
| 231 | 234 |
| 232 // GCC requires these declarations, but MSVC requires they not be present | 235 // GCC requires these declarations, but MSVC requires they not be present |
| 233 #ifndef COMPILER_MSVC | 236 #ifndef COMPILER_MSVC |
| 234 const GLint ProgramManagerWithShaderTest::kNumVertexAttribs; | 237 const GLint ProgramManagerWithShaderTest::kNumVertexAttribs; |
| 235 const GLuint ProgramManagerWithShaderTest::kProgramId; | 238 const GLuint ProgramManagerWithShaderTest::kClientProgramId; |
| 239 const GLuint ProgramManagerWithShaderTest::kServiceProgramId; |
| 236 const GLint ProgramManagerWithShaderTest::kAttrib1Size; | 240 const GLint ProgramManagerWithShaderTest::kAttrib1Size; |
| 237 const GLint ProgramManagerWithShaderTest::kAttrib2Size; | 241 const GLint ProgramManagerWithShaderTest::kAttrib2Size; |
| 238 const GLint ProgramManagerWithShaderTest::kAttrib3Size; | 242 const GLint ProgramManagerWithShaderTest::kAttrib3Size; |
| 239 const GLint ProgramManagerWithShaderTest::kAttrib1Location; | 243 const GLint ProgramManagerWithShaderTest::kAttrib1Location; |
| 240 const GLint ProgramManagerWithShaderTest::kAttrib2Location; | 244 const GLint ProgramManagerWithShaderTest::kAttrib2Location; |
| 241 const GLint ProgramManagerWithShaderTest::kAttrib3Location; | 245 const GLint ProgramManagerWithShaderTest::kAttrib3Location; |
| 242 const GLenum ProgramManagerWithShaderTest::kAttrib1Type; | 246 const GLenum ProgramManagerWithShaderTest::kAttrib1Type; |
| 243 const GLenum ProgramManagerWithShaderTest::kAttrib2Type; | 247 const GLenum ProgramManagerWithShaderTest::kAttrib2Type; |
| 244 const GLenum ProgramManagerWithShaderTest::kAttrib3Type; | 248 const GLenum ProgramManagerWithShaderTest::kAttrib3Type; |
| 245 const GLint ProgramManagerWithShaderTest::kInvalidAttribLocation; | 249 const GLint ProgramManagerWithShaderTest::kInvalidAttribLocation; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 274 const char* ProgramManagerWithShaderTest::kAttrib2Name = "attrib2"; | 278 const char* ProgramManagerWithShaderTest::kAttrib2Name = "attrib2"; |
| 275 const char* ProgramManagerWithShaderTest::kAttrib3Name = "attrib3"; | 279 const char* ProgramManagerWithShaderTest::kAttrib3Name = "attrib3"; |
| 276 const char* ProgramManagerWithShaderTest::kUniform1Name = "uniform1"; | 280 const char* ProgramManagerWithShaderTest::kUniform1Name = "uniform1"; |
| 277 // Correctly has array spec. | 281 // Correctly has array spec. |
| 278 const char* ProgramManagerWithShaderTest::kUniform2Name = "uniform2[0]"; | 282 const char* ProgramManagerWithShaderTest::kUniform2Name = "uniform2[0]"; |
| 279 // Incorrectly missing array spec. | 283 // Incorrectly missing array spec. |
| 280 const char* ProgramManagerWithShaderTest::kUniform3Name = "uniform3"; | 284 const char* ProgramManagerWithShaderTest::kUniform3Name = "uniform3"; |
| 281 | 285 |
| 282 TEST_F(ProgramManagerWithShaderTest, GetAttribInfos) { | 286 TEST_F(ProgramManagerWithShaderTest, GetAttribInfos) { |
| 283 const ProgramManager::ProgramInfo* program_info = | 287 const ProgramManager::ProgramInfo* program_info = |
| 284 manager_.GetProgramInfo(kProgramId); | 288 manager_.GetProgramInfo(kClientProgramId); |
| 285 ASSERT_TRUE(program_info != NULL); | 289 ASSERT_TRUE(program_info != NULL); |
| 286 const ProgramManager::ProgramInfo::AttribInfoVector& infos = | 290 const ProgramManager::ProgramInfo::AttribInfoVector& infos = |
| 287 program_info->GetAttribInfos(); | 291 program_info->GetAttribInfos(); |
| 288 for (size_t ii = 0; ii < kNumAttribs; ++ii) { | 292 for (size_t ii = 0; ii < kNumAttribs; ++ii) { |
| 289 const ProgramManager::ProgramInfo::VertexAttribInfo& info = infos[ii]; | 293 const ProgramManager::ProgramInfo::VertexAttribInfo& info = infos[ii]; |
| 290 const AttribInfo& expected = kAttribs[ii]; | 294 const AttribInfo& expected = kAttribs[ii]; |
| 291 EXPECT_EQ(expected.size, info.size); | 295 EXPECT_EQ(expected.size, info.size); |
| 292 EXPECT_EQ(expected.type, info.type); | 296 EXPECT_EQ(expected.type, info.type); |
| 293 EXPECT_EQ(expected.location, info.location); | 297 EXPECT_EQ(expected.location, info.location); |
| 294 EXPECT_STREQ(expected.name, info.name.c_str()); | 298 EXPECT_STREQ(expected.name, info.name.c_str()); |
| 295 } | 299 } |
| 296 } | 300 } |
| 297 | 301 |
| 298 TEST_F(ProgramManagerWithShaderTest, GetAttribInfo) { | 302 TEST_F(ProgramManagerWithShaderTest, GetAttribInfo) { |
| 299 const GLint kValidIndex = 1; | 303 const GLint kValidIndex = 1; |
| 300 const GLint kInvalidIndex = 1000; | 304 const GLint kInvalidIndex = 1000; |
| 301 const ProgramManager::ProgramInfo* program_info = | 305 const ProgramManager::ProgramInfo* program_info = |
| 302 manager_.GetProgramInfo(kProgramId); | 306 manager_.GetProgramInfo(kClientProgramId); |
| 303 ASSERT_TRUE(program_info != NULL); | 307 ASSERT_TRUE(program_info != NULL); |
| 304 const ProgramManager::ProgramInfo::VertexAttribInfo* info = | 308 const ProgramManager::ProgramInfo::VertexAttribInfo* info = |
| 305 program_info->GetAttribInfo(kValidIndex); | 309 program_info->GetAttribInfo(kValidIndex); |
| 306 ASSERT_TRUE(info != NULL); | 310 ASSERT_TRUE(info != NULL); |
| 307 EXPECT_EQ(kAttrib2Size, info->size); | 311 EXPECT_EQ(kAttrib2Size, info->size); |
| 308 EXPECT_EQ(kAttrib2Type, info->type); | 312 EXPECT_EQ(kAttrib2Type, info->type); |
| 309 EXPECT_EQ(kAttrib2Location, info->location); | 313 EXPECT_EQ(kAttrib2Location, info->location); |
| 310 EXPECT_STREQ(kAttrib2Name, info->name.c_str()); | 314 EXPECT_STREQ(kAttrib2Name, info->name.c_str()); |
| 311 EXPECT_TRUE(program_info->GetAttribInfo(kInvalidIndex) == NULL); | 315 EXPECT_TRUE(program_info->GetAttribInfo(kInvalidIndex) == NULL); |
| 312 } | 316 } |
| 313 | 317 |
| 314 TEST_F(ProgramManagerWithShaderTest, GetAttribLocation) { | 318 TEST_F(ProgramManagerWithShaderTest, GetAttribLocation) { |
| 315 const char* kInvalidName = "foo"; | 319 const char* kInvalidName = "foo"; |
| 316 const ProgramManager::ProgramInfo* program_info = | 320 const ProgramManager::ProgramInfo* program_info = |
| 317 manager_.GetProgramInfo(kProgramId); | 321 manager_.GetProgramInfo(kClientProgramId); |
| 318 ASSERT_TRUE(program_info != NULL); | 322 ASSERT_TRUE(program_info != NULL); |
| 319 EXPECT_EQ(kAttrib2Location, program_info->GetAttribLocation(kAttrib2Name)); | 323 EXPECT_EQ(kAttrib2Location, program_info->GetAttribLocation(kAttrib2Name)); |
| 320 EXPECT_EQ(-1, program_info->GetAttribLocation(kInvalidName)); | 324 EXPECT_EQ(-1, program_info->GetAttribLocation(kInvalidName)); |
| 321 } | 325 } |
| 322 | 326 |
| 323 TEST_F(ProgramManagerWithShaderTest, GetUniformInfo) { | 327 TEST_F(ProgramManagerWithShaderTest, GetUniformInfo) { |
| 324 const GLint kInvalidIndex = 1000; | 328 const GLint kInvalidIndex = 1000; |
| 325 const ProgramManager::ProgramInfo* program_info = | 329 const ProgramManager::ProgramInfo* program_info = |
| 326 manager_.GetProgramInfo(kProgramId); | 330 manager_.GetProgramInfo(kClientProgramId); |
| 327 ASSERT_TRUE(program_info != NULL); | 331 ASSERT_TRUE(program_info != NULL); |
| 328 const ProgramManager::ProgramInfo::UniformInfo* info = | 332 const ProgramManager::ProgramInfo::UniformInfo* info = |
| 329 program_info->GetUniformInfo(0); | 333 program_info->GetUniformInfo(0); |
| 330 ASSERT_TRUE(info != NULL); | 334 ASSERT_TRUE(info != NULL); |
| 331 EXPECT_EQ(kUniform1Size, info->size); | 335 EXPECT_EQ(kUniform1Size, info->size); |
| 332 EXPECT_EQ(kUniform1Type, info->type); | 336 EXPECT_EQ(kUniform1Type, info->type); |
| 333 EXPECT_EQ(kUniform1Location, info->element_locations[0]); | 337 EXPECT_EQ(kUniform1Location, info->element_locations[0]); |
| 334 EXPECT_STREQ(kUniform1Name, info->name.c_str()); | 338 EXPECT_STREQ(kUniform1Name, info->name.c_str()); |
| 335 info = program_info->GetUniformInfo(1); | 339 info = program_info->GetUniformInfo(1); |
| 336 ASSERT_TRUE(info != NULL); | 340 ASSERT_TRUE(info != NULL); |
| 337 EXPECT_EQ(kUniform2Size, info->size); | 341 EXPECT_EQ(kUniform2Size, info->size); |
| 338 EXPECT_EQ(kUniform2Type, info->type); | 342 EXPECT_EQ(kUniform2Type, info->type); |
| 339 EXPECT_EQ(kUniform2Location, info->element_locations[0]); | 343 EXPECT_EQ(kUniform2Location, info->element_locations[0]); |
| 340 EXPECT_STREQ(kUniform2Name, info->name.c_str()); | 344 EXPECT_STREQ(kUniform2Name, info->name.c_str()); |
| 341 info = program_info->GetUniformInfo(2); | 345 info = program_info->GetUniformInfo(2); |
| 342 // We emulate certain OpenGL drivers by supplying the name without | 346 // We emulate certain OpenGL drivers by supplying the name without |
| 343 // the array spec. Our implementation should correctly add the required spec. | 347 // the array spec. Our implementation should correctly add the required spec. |
| 344 const std::string expected_name(std::string(kUniform3Name) + "[0]"); | 348 const std::string expected_name(std::string(kUniform3Name) + "[0]"); |
| 345 ASSERT_TRUE(info != NULL); | 349 ASSERT_TRUE(info != NULL); |
| 346 EXPECT_EQ(kUniform3Size, info->size); | 350 EXPECT_EQ(kUniform3Size, info->size); |
| 347 EXPECT_EQ(kUniform3Type, info->type); | 351 EXPECT_EQ(kUniform3Type, info->type); |
| 348 EXPECT_EQ(kUniform3Location, info->element_locations[0]); | 352 EXPECT_EQ(kUniform3Location, info->element_locations[0]); |
| 349 EXPECT_STREQ(expected_name.c_str(), info->name.c_str()); | 353 EXPECT_STREQ(expected_name.c_str(), info->name.c_str()); |
| 350 EXPECT_TRUE(program_info->GetUniformInfo(kInvalidIndex) == NULL); | 354 EXPECT_TRUE(program_info->GetUniformInfo(kInvalidIndex) == NULL); |
| 351 } | 355 } |
| 352 | 356 |
| 353 TEST_F(ProgramManagerWithShaderTest, GetUniformLocation) { | 357 TEST_F(ProgramManagerWithShaderTest, GetUniformLocation) { |
| 354 const ProgramManager::ProgramInfo* program_info = | 358 const ProgramManager::ProgramInfo* program_info = |
| 355 manager_.GetProgramInfo(kProgramId); | 359 manager_.GetProgramInfo(kClientProgramId); |
| 356 ASSERT_TRUE(program_info != NULL); | 360 ASSERT_TRUE(program_info != NULL); |
| 357 EXPECT_EQ(kUniform1Location, program_info->GetUniformLocation(kUniform1Name)); | 361 EXPECT_EQ(kUniform1Location, program_info->GetUniformLocation(kUniform1Name)); |
| 358 EXPECT_EQ(kUniform2Location, program_info->GetUniformLocation(kUniform2Name)); | 362 EXPECT_EQ(kUniform2Location, program_info->GetUniformLocation(kUniform2Name)); |
| 359 EXPECT_EQ(kUniform3Location, program_info->GetUniformLocation(kUniform3Name)); | 363 EXPECT_EQ(kUniform3Location, program_info->GetUniformLocation(kUniform3Name)); |
| 360 // Check we can get uniform2 as "uniform2" even though the name is | 364 // Check we can get uniform2 as "uniform2" even though the name is |
| 361 // "uniform2[0]" | 365 // "uniform2[0]" |
| 362 EXPECT_EQ(kUniform2Location, program_info->GetUniformLocation("uniform2")); | 366 EXPECT_EQ(kUniform2Location, program_info->GetUniformLocation("uniform2")); |
| 363 // Check we can get uniform3 as "uniform3[0]" even though we simulated GL | 367 // Check we can get uniform3 as "uniform3[0]" even though we simulated GL |
| 364 // returning "uniform3" | 368 // returning "uniform3" |
| 365 EXPECT_EQ(kUniform3Location, program_info->GetUniformLocation("uniform3[0]")); | 369 EXPECT_EQ(kUniform3Location, program_info->GetUniformLocation("uniform3[0]")); |
| 366 // Check that we can get the locations of the array elements > 1 | 370 // Check that we can get the locations of the array elements > 1 |
| 367 EXPECT_EQ(kUniform2Location + 2, | 371 EXPECT_EQ(kUniform2Location + 2, |
| 368 program_info->GetUniformLocation("uniform2[1]")); | 372 program_info->GetUniformLocation("uniform2[1]")); |
| 369 EXPECT_EQ(kUniform2Location + 4, | 373 EXPECT_EQ(kUniform2Location + 4, |
| 370 program_info->GetUniformLocation("uniform2[2]")); | 374 program_info->GetUniformLocation("uniform2[2]")); |
| 371 EXPECT_EQ(-1, | 375 EXPECT_EQ(-1, |
| 372 program_info->GetUniformLocation("uniform2[3]")); | 376 program_info->GetUniformLocation("uniform2[3]")); |
| 373 EXPECT_EQ(kUniform3Location + 2, | 377 EXPECT_EQ(kUniform3Location + 2, |
| 374 program_info->GetUniformLocation("uniform3[1]")); | 378 program_info->GetUniformLocation("uniform3[1]")); |
| 375 EXPECT_EQ(-1, | 379 EXPECT_EQ(-1, |
| 376 program_info->GetUniformLocation("uniform3[2]")); | 380 program_info->GetUniformLocation("uniform3[2]")); |
| 377 } | 381 } |
| 378 | 382 |
| 379 TEST_F(ProgramManagerWithShaderTest, GetUniformTypeByLocation) { | 383 TEST_F(ProgramManagerWithShaderTest, GetUniformTypeByLocation) { |
| 380 const GLint kInvalidLocation = 1234; | 384 const GLint kInvalidLocation = 1234; |
| 381 GLenum type = 0u; | 385 GLenum type = 0u; |
| 382 const ProgramManager::ProgramInfo* program_info = | 386 const ProgramManager::ProgramInfo* program_info = |
| 383 manager_.GetProgramInfo(kProgramId); | 387 manager_.GetProgramInfo(kClientProgramId); |
| 384 ASSERT_TRUE(program_info != NULL); | 388 ASSERT_TRUE(program_info != NULL); |
| 385 EXPECT_TRUE(program_info->GetUniformTypeByLocation(kUniform2Location, &type)); | 389 EXPECT_TRUE(program_info->GetUniformTypeByLocation(kUniform2Location, &type)); |
| 386 EXPECT_EQ(kUniform2Type, type); | 390 EXPECT_EQ(kUniform2Type, type); |
| 387 type = 0u; | 391 type = 0u; |
| 388 EXPECT_FALSE(program_info->GetUniformTypeByLocation( | 392 EXPECT_FALSE(program_info->GetUniformTypeByLocation( |
| 389 kInvalidLocation, &type)); | 393 kInvalidLocation, &type)); |
| 390 EXPECT_EQ(0u, type); | 394 EXPECT_EQ(0u, type); |
| 391 } | 395 } |
| 392 | 396 |
| 393 // Some GL drivers incorrectly return gl_DepthRange and possibly other uniforms | 397 // Some GL drivers incorrectly return gl_DepthRange and possibly other uniforms |
| 394 // that start with "gl_". Our implementation catches these and does not allow | 398 // that start with "gl_". Our implementation catches these and does not allow |
| 395 // them back to client. | 399 // them back to client. |
| 396 TEST_F(ProgramManagerWithShaderTest, GLDriverReturnsGLUnderscoreUniform) { | 400 TEST_F(ProgramManagerWithShaderTest, GLDriverReturnsGLUnderscoreUniform) { |
| 397 static const char* kUniform2Name = "gl_longNameWeCanCheckFor"; | 401 static const char* kUniform2Name = "gl_longNameWeCanCheckFor"; |
| 398 static ProgramManagerWithShaderTest::UniformInfo kUniforms[] = { | 402 static ProgramManagerWithShaderTest::UniformInfo kUniforms[] = { |
| 399 { kUniform1Name, kUniform1Size, kUniform1Type, kUniform1Location, }, | 403 { kUniform1Name, kUniform1Size, kUniform1Type, kUniform1Location, }, |
| 400 { kUniform2Name, kUniform2Size, kUniform2Type, kUniform2Location, }, | 404 { kUniform2Name, kUniform2Size, kUniform2Type, kUniform2Location, }, |
| 401 { kUniform3Name, kUniform3Size, kUniform3Type, kUniform3Location, }, | 405 { kUniform3Name, kUniform3Size, kUniform3Type, kUniform3Location, }, |
| 402 }; | 406 }; |
| 403 const size_t kNumUniforms = arraysize(kUniforms); | 407 const size_t kNumUniforms = arraysize(kUniforms); |
| 404 static const GLuint kProgramId = 1234; | 408 static const GLuint kClientProgramId = 1234; |
| 405 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, kProgramId); | 409 static const GLuint kServiceProgramId = 5679; |
| 406 manager_.CreateProgramInfo(kProgramId); | 410 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, |
| 411 kServiceProgramId); |
| 412 manager_.CreateProgramInfo(kClientProgramId, kServiceProgramId); |
| 407 ProgramManager::ProgramInfo* program_info = | 413 ProgramManager::ProgramInfo* program_info = |
| 408 manager_.GetProgramInfo(kProgramId); | 414 manager_.GetProgramInfo(kClientProgramId); |
| 409 ASSERT_TRUE(program_info != NULL); | 415 ASSERT_TRUE(program_info != NULL); |
| 410 program_info->Update(); | 416 program_info->Update(); |
| 411 GLint value = 0; | 417 GLint value = 0; |
| 412 program_info->GetProgramiv(GL_ACTIVE_ATTRIBUTES, &value); | 418 program_info->GetProgramiv(GL_ACTIVE_ATTRIBUTES, &value); |
| 413 EXPECT_EQ(3, value); | 419 EXPECT_EQ(3, value); |
| 414 // Check that we skipped the "gl_" uniform. | 420 // Check that we skipped the "gl_" uniform. |
| 415 program_info->GetProgramiv(GL_ACTIVE_UNIFORMS, &value); | 421 program_info->GetProgramiv(GL_ACTIVE_UNIFORMS, &value); |
| 416 EXPECT_EQ(2, value); | 422 EXPECT_EQ(2, value); |
| 417 // Check that our max length adds room for the array spec and is not as long | 423 // Check that our max length adds room for the array spec and is not as long |
| 418 // as the "gl_" uniform we skipped. | 424 // as the "gl_" uniform we skipped. |
| 419 program_info->GetProgramiv(GL_ACTIVE_UNIFORM_MAX_LENGTH, &value); | 425 program_info->GetProgramiv(GL_ACTIVE_UNIFORM_MAX_LENGTH, &value); |
| 420 EXPECT_EQ(strlen(kUniform3Name) + 3u, static_cast<size_t>(value)); | 426 EXPECT_EQ(strlen(kUniform3Name) + 3u, static_cast<size_t>(value)); |
| 421 } | 427 } |
| 422 | 428 |
| 423 } // namespace gles2 | 429 } // namespace gles2 |
| 424 } // namespace gpu | 430 } // namespace gpu |
| 425 | 431 |
| 426 | 432 |
| OLD | NEW |