| 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/test_helper.h" | 5 #include "gpu/command_buffer/service/test_helper.h" |
| 6 | 6 |
| 7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "base/string_tokenizer.h" | 8 #include "base/string_tokenizer.h" |
| 9 #include "gpu/command_buffer/common/gl_mock.h" | 9 #include "gpu/command_buffer/common/gl_mock.h" |
| 10 #include "gpu/command_buffer/common/types.h" | 10 #include "gpu/command_buffer/common/types.h" |
| 11 #include "gpu/command_buffer/service/gl_utils.h" | 11 #include "gpu/command_buffer/service/gl_utils.h" |
| 12 #include "gpu/command_buffer/service/program_manager.h" | 12 #include "gpu/command_buffer/service/program_manager.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 #include <algorithm> |
| 15 #include <string.h> | 16 #include <string.h> |
| 16 | 17 |
| 17 using ::testing::_; | 18 using ::testing::_; |
| 18 using ::testing::DoAll; | 19 using ::testing::DoAll; |
| 19 using ::testing::InSequence; | 20 using ::testing::InSequence; |
| 20 using ::testing::MatcherCast; | 21 using ::testing::MatcherCast; |
| 21 using ::testing::Pointee; | 22 using ::testing::Pointee; |
| 22 using ::testing::Return; | 23 using ::testing::Return; |
| 23 using ::testing::SetArrayArgument; | 24 using ::testing::SetArrayArgument; |
| 24 using ::testing::SetArgumentPointee; | 25 using ::testing::SetArgumentPointee; |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 .Times(1) | 362 .Times(1) |
| 362 .RetiresOnSaturation(); | 363 .RetiresOnSaturation(); |
| 363 break; | 364 break; |
| 364 default: | 365 default: |
| 365 NOTREACHED(); | 366 NOTREACHED(); |
| 366 break; | 367 break; |
| 367 } | 368 } |
| 368 } | 369 } |
| 369 } | 370 } |
| 370 | 371 |
| 372 namespace { |
| 373 |
| 374 struct UniformInfoComparer { |
| 375 bool operator()(const TestHelper::UniformInfo& lhs, |
| 376 const TestHelper::UniformInfo& rhs) const { |
| 377 return strcmp(lhs.name, rhs.name) < 0; |
| 378 } |
| 379 }; |
| 380 |
| 381 } // anonymous namespace. |
| 382 |
| 371 void TestHelper::SetupShader( | 383 void TestHelper::SetupShader( |
| 372 ::gfx::MockGLInterface* gl, | 384 ::gfx::MockGLInterface* gl, |
| 373 AttribInfo* attribs, size_t num_attribs, | 385 AttribInfo* attribs, size_t num_attribs, |
| 374 UniformInfo* uniforms, size_t num_uniforms, | 386 UniformInfo* uniforms, size_t num_uniforms, |
| 375 GLuint service_id) { | 387 GLuint service_id) { |
| 376 InSequence s; | 388 InSequence s; |
| 377 | 389 |
| 378 EXPECT_CALL(*gl, | 390 EXPECT_CALL(*gl, |
| 379 LinkProgram(service_id)) | 391 LinkProgram(service_id)) |
| 380 .Times(1) | 392 .Times(1) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 393 .RetiresOnSaturation(); | 405 .RetiresOnSaturation(); |
| 394 size_t max_attrib_len = 0; | 406 size_t max_attrib_len = 0; |
| 395 for (size_t ii = 0; ii < num_attribs; ++ii) { | 407 for (size_t ii = 0; ii < num_attribs; ++ii) { |
| 396 size_t len = strlen(attribs[ii].name) + 1; | 408 size_t len = strlen(attribs[ii].name) + 1; |
| 397 max_attrib_len = std::max(max_attrib_len, len); | 409 max_attrib_len = std::max(max_attrib_len, len); |
| 398 } | 410 } |
| 399 EXPECT_CALL(*gl, | 411 EXPECT_CALL(*gl, |
| 400 GetProgramiv(service_id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, _)) | 412 GetProgramiv(service_id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, _)) |
| 401 .WillOnce(SetArgumentPointee<2>(max_attrib_len)) | 413 .WillOnce(SetArgumentPointee<2>(max_attrib_len)) |
| 402 .RetiresOnSaturation(); | 414 .RetiresOnSaturation(); |
| 415 |
| 403 for (size_t ii = 0; ii < num_attribs; ++ii) { | 416 for (size_t ii = 0; ii < num_attribs; ++ii) { |
| 404 const AttribInfo& info = attribs[ii]; | 417 const AttribInfo& info = attribs[ii]; |
| 405 EXPECT_CALL(*gl, | 418 EXPECT_CALL(*gl, |
| 406 GetActiveAttrib(service_id, ii, | 419 GetActiveAttrib(service_id, ii, |
| 407 max_attrib_len, _, _, _, _)) | 420 max_attrib_len, _, _, _, _)) |
| 408 .WillOnce(DoAll( | 421 .WillOnce(DoAll( |
| 409 SetArgumentPointee<3>(strlen(info.name)), | 422 SetArgumentPointee<3>(strlen(info.name)), |
| 410 SetArgumentPointee<4>(info.size), | 423 SetArgumentPointee<4>(info.size), |
| 411 SetArgumentPointee<5>(info.type), | 424 SetArgumentPointee<5>(info.type), |
| 412 SetArrayArgument<6>(info.name, | 425 SetArrayArgument<6>(info.name, |
| 413 info.name + strlen(info.name) + 1))) | 426 info.name + strlen(info.name) + 1))) |
| 414 .RetiresOnSaturation(); | 427 .RetiresOnSaturation(); |
| 415 if (!ProgramManager::IsInvalidPrefix(info.name, strlen(info.name))) { | 428 if (!ProgramManager::IsInvalidPrefix(info.name, strlen(info.name))) { |
| 416 EXPECT_CALL(*gl, GetAttribLocation(service_id, StrEq(info.name))) | 429 EXPECT_CALL(*gl, GetAttribLocation(service_id, StrEq(info.name))) |
| 417 .WillOnce(Return(info.location)) | 430 .WillOnce(Return(info.location)) |
| 418 .RetiresOnSaturation(); | 431 .RetiresOnSaturation(); |
| 419 } | 432 } |
| 420 } | 433 } |
| 421 EXPECT_CALL(*gl, | 434 EXPECT_CALL(*gl, |
| 422 GetProgramiv(service_id, GL_ACTIVE_UNIFORMS, _)) | 435 GetProgramiv(service_id, GL_ACTIVE_UNIFORMS, _)) |
| 423 .WillOnce(SetArgumentPointee<2>(num_uniforms)) | 436 .WillOnce(SetArgumentPointee<2>(num_uniforms)) |
| 424 .RetiresOnSaturation(); | 437 .RetiresOnSaturation(); |
| 438 |
| 439 scoped_array<UniformInfo> sorted_uniforms(new UniformInfo[num_uniforms]); |
| 440 size_t num_valid_uniforms = 0; |
| 441 |
| 425 size_t max_uniform_len = 0; | 442 size_t max_uniform_len = 0; |
| 426 for (size_t ii = 0; ii < num_uniforms; ++ii) { | 443 for (size_t ii = 0; ii < num_uniforms; ++ii) { |
| 427 size_t len = strlen(uniforms[ii].name) + 1; | 444 size_t len = strlen(uniforms[ii].name) + 1; |
| 428 max_uniform_len = std::max(max_uniform_len, len); | 445 max_uniform_len = std::max(max_uniform_len, len); |
| 429 } | 446 } |
| 430 EXPECT_CALL(*gl, | 447 EXPECT_CALL(*gl, |
| 431 GetProgramiv(service_id, GL_ACTIVE_UNIFORM_MAX_LENGTH, _)) | 448 GetProgramiv(service_id, GL_ACTIVE_UNIFORM_MAX_LENGTH, _)) |
| 432 .WillOnce(SetArgumentPointee<2>(max_uniform_len)) | 449 .WillOnce(SetArgumentPointee<2>(max_uniform_len)) |
| 433 .RetiresOnSaturation(); | 450 .RetiresOnSaturation(); |
| 434 for (size_t ii = 0; ii < num_uniforms; ++ii) { | 451 for (size_t ii = 0; ii < num_uniforms; ++ii) { |
| 435 const UniformInfo& info = uniforms[ii]; | 452 const UniformInfo& info = uniforms[ii]; |
| 436 EXPECT_CALL(*gl, | 453 EXPECT_CALL(*gl, |
| 437 GetActiveUniform(service_id, ii, | 454 GetActiveUniform(service_id, ii, |
| 438 max_uniform_len, _, _, _, _)) | 455 max_uniform_len, _, _, _, _)) |
| 439 .WillOnce(DoAll( | 456 .WillOnce(DoAll( |
| 440 SetArgumentPointee<3>(strlen(info.name)), | 457 SetArgumentPointee<3>(strlen(info.name)), |
| 441 SetArgumentPointee<4>(info.size), | 458 SetArgumentPointee<4>(info.size), |
| 442 SetArgumentPointee<5>(info.type), | 459 SetArgumentPointee<5>(info.type), |
| 443 SetArrayArgument<6>(info.name, | 460 SetArrayArgument<6>(info.name, |
| 444 info.name + strlen(info.name) + 1))) | 461 info.name + strlen(info.name) + 1))) |
| 445 .RetiresOnSaturation(); | 462 .RetiresOnSaturation(); |
| 446 if (!ProgramManager::IsInvalidPrefix(info.name, strlen(info.name))) { | 463 if (!ProgramManager::IsInvalidPrefix(info.name, strlen(info.name))) { |
| 447 EXPECT_CALL(*gl, GetUniformLocation(service_id, StrEq(info.name))) | 464 sorted_uniforms[num_valid_uniforms++] = uniforms[ii]; |
| 448 .WillOnce(Return(info.real_location)) | 465 } |
| 449 .RetiresOnSaturation(); | 466 } |
| 450 if (info.size > 1) { | 467 |
| 451 std::string base_name = info.name; | 468 std::sort( |
| 452 size_t array_pos = base_name.rfind("[0]"); | 469 &sorted_uniforms[0], &sorted_uniforms[num_valid_uniforms], |
| 453 if (base_name.size() > 3 && array_pos == base_name.size() - 3) { | 470 UniformInfoComparer()); |
| 454 base_name = base_name.substr(0, base_name.size() - 3); | 471 |
| 455 } | 472 for (size_t ii = 0; ii < num_valid_uniforms; ++ii) { |
| 456 for (GLsizei jj = 1; jj < info.size; ++jj) { | 473 const UniformInfo& info = sorted_uniforms[ii]; |
| 457 std::string element_name( | 474 EXPECT_CALL(*gl, GetUniformLocation(service_id, StrEq(info.name))) |
| 458 std::string(base_name) + "[" + base::IntToString(jj) + "]"); | 475 .WillOnce(Return(info.real_location)) |
| 459 EXPECT_CALL(*gl, GetUniformLocation(service_id, StrEq(element_name))) | 476 .RetiresOnSaturation(); |
| 460 .WillOnce(Return(info.real_location + jj * 2)) | 477 if (info.size > 1) { |
| 461 .RetiresOnSaturation(); | 478 std::string base_name = info.name; |
| 462 } | 479 size_t array_pos = base_name.rfind("[0]"); |
| 480 if (base_name.size() > 3 && array_pos == base_name.size() - 3) { |
| 481 base_name = base_name.substr(0, base_name.size() - 3); |
| 482 } |
| 483 for (GLsizei jj = 1; jj < info.size; ++jj) { |
| 484 std::string element_name( |
| 485 std::string(base_name) + "[" + base::IntToString(jj) + "]"); |
| 486 EXPECT_CALL(*gl, GetUniformLocation(service_id, StrEq(element_name))) |
| 487 .WillOnce(Return(info.real_location + jj * 2)) |
| 488 .RetiresOnSaturation(); |
| 463 } | 489 } |
| 464 } | 490 } |
| 465 } | 491 } |
| 466 } | 492 } |
| 467 | 493 |
| 468 | |
| 469 } // namespace gles2 | 494 } // namespace gles2 |
| 470 } // namespace gpu | 495 } // namespace gpu |
| 471 | 496 |
| OLD | NEW |