Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: gpu/command_buffer/service/test_helper.cc

Issue 10635011: Add glBindUniformLocationCHROMIUM (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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>
16 #include <string.h> 15 #include <string.h>
17 16
18 using ::testing::_; 17 using ::testing::_;
19 using ::testing::DoAll; 18 using ::testing::DoAll;
20 using ::testing::InSequence; 19 using ::testing::InSequence;
21 using ::testing::MatcherCast; 20 using ::testing::MatcherCast;
22 using ::testing::Pointee; 21 using ::testing::Pointee;
23 using ::testing::Return; 22 using ::testing::Return;
24 using ::testing::SetArrayArgument; 23 using ::testing::SetArrayArgument;
25 using ::testing::SetArgumentPointee; 24 using ::testing::SetArgumentPointee;
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 .Times(1) 361 .Times(1)
363 .RetiresOnSaturation(); 362 .RetiresOnSaturation();
364 break; 363 break;
365 default: 364 default:
366 NOTREACHED(); 365 NOTREACHED();
367 break; 366 break;
368 } 367 }
369 } 368 }
370 } 369 }
371 370
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
383 void TestHelper::SetupShader( 371 void TestHelper::SetupShader(
384 ::gfx::MockGLInterface* gl, 372 ::gfx::MockGLInterface* gl,
385 AttribInfo* attribs, size_t num_attribs, 373 AttribInfo* attribs, size_t num_attribs,
386 UniformInfo* uniforms, size_t num_uniforms, 374 UniformInfo* uniforms, size_t num_uniforms,
387 GLuint service_id) { 375 GLuint service_id) {
388 InSequence s; 376 InSequence s;
389 377
390 EXPECT_CALL(*gl, 378 EXPECT_CALL(*gl,
391 LinkProgram(service_id)) 379 LinkProgram(service_id))
392 .Times(1) 380 .Times(1)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 EXPECT_CALL(*gl, GetAttribLocation(service_id, StrEq(info.name))) 417 EXPECT_CALL(*gl, GetAttribLocation(service_id, StrEq(info.name)))
430 .WillOnce(Return(info.location)) 418 .WillOnce(Return(info.location))
431 .RetiresOnSaturation(); 419 .RetiresOnSaturation();
432 } 420 }
433 } 421 }
434 EXPECT_CALL(*gl, 422 EXPECT_CALL(*gl,
435 GetProgramiv(service_id, GL_ACTIVE_UNIFORMS, _)) 423 GetProgramiv(service_id, GL_ACTIVE_UNIFORMS, _))
436 .WillOnce(SetArgumentPointee<2>(num_uniforms)) 424 .WillOnce(SetArgumentPointee<2>(num_uniforms))
437 .RetiresOnSaturation(); 425 .RetiresOnSaturation();
438 426
439 scoped_array<UniformInfo> sorted_uniforms(new UniformInfo[num_uniforms]);
440 size_t num_valid_uniforms = 0;
441
442 size_t max_uniform_len = 0; 427 size_t max_uniform_len = 0;
443 for (size_t ii = 0; ii < num_uniforms; ++ii) { 428 for (size_t ii = 0; ii < num_uniforms; ++ii) {
444 size_t len = strlen(uniforms[ii].name) + 1; 429 size_t len = strlen(uniforms[ii].name) + 1;
445 max_uniform_len = std::max(max_uniform_len, len); 430 max_uniform_len = std::max(max_uniform_len, len);
446 } 431 }
447 EXPECT_CALL(*gl, 432 EXPECT_CALL(*gl,
448 GetProgramiv(service_id, GL_ACTIVE_UNIFORM_MAX_LENGTH, _)) 433 GetProgramiv(service_id, GL_ACTIVE_UNIFORM_MAX_LENGTH, _))
449 .WillOnce(SetArgumentPointee<2>(max_uniform_len)) 434 .WillOnce(SetArgumentPointee<2>(max_uniform_len))
450 .RetiresOnSaturation(); 435 .RetiresOnSaturation();
451 for (size_t ii = 0; ii < num_uniforms; ++ii) { 436 for (size_t ii = 0; ii < num_uniforms; ++ii) {
452 const UniformInfo& info = uniforms[ii]; 437 const UniformInfo& info = uniforms[ii];
453 EXPECT_CALL(*gl, 438 EXPECT_CALL(*gl,
454 GetActiveUniform(service_id, ii, 439 GetActiveUniform(service_id, ii,
455 max_uniform_len, _, _, _, _)) 440 max_uniform_len, _, _, _, _))
456 .WillOnce(DoAll( 441 .WillOnce(DoAll(
457 SetArgumentPointee<3>(strlen(info.name)), 442 SetArgumentPointee<3>(strlen(info.name)),
458 SetArgumentPointee<4>(info.size), 443 SetArgumentPointee<4>(info.size),
459 SetArgumentPointee<5>(info.type), 444 SetArgumentPointee<5>(info.type),
460 SetArrayArgument<6>(info.name, 445 SetArrayArgument<6>(info.name,
461 info.name + strlen(info.name) + 1))) 446 info.name + strlen(info.name) + 1)))
462 .RetiresOnSaturation(); 447 .RetiresOnSaturation();
463 if (!ProgramManager::IsInvalidPrefix(info.name, strlen(info.name))) {
464 sorted_uniforms[num_valid_uniforms++] = uniforms[ii];
465 }
466 } 448 }
467 449
468 std::sort( 450 for (int pass = 0; pass < 2; ++pass) {
469 &sorted_uniforms[0], &sorted_uniforms[num_valid_uniforms], 451 for (size_t ii = 0; ii < num_uniforms; ++ii) {
470 UniformInfoComparer()); 452 const UniformInfo& info = uniforms[ii];
471 453 if (ProgramManager::IsInvalidPrefix(info.name, strlen(info.name))) {
472 for (size_t ii = 0; ii < num_valid_uniforms; ++ii) { 454 continue;
473 const UniformInfo& info = sorted_uniforms[ii];
474 EXPECT_CALL(*gl, GetUniformLocation(service_id, StrEq(info.name)))
475 .WillOnce(Return(info.real_location))
476 .RetiresOnSaturation();
477 if (info.size > 1) {
478 std::string base_name = info.name;
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 } 455 }
483 for (GLsizei jj = 1; jj < info.size; ++jj) { 456 if (pass == 0) {
484 std::string element_name( 457 EXPECT_CALL(*gl, GetUniformLocation(service_id, StrEq(info.name)))
485 std::string(base_name) + "[" + base::IntToString(jj) + "]"); 458 .WillOnce(Return(info.real_location))
486 EXPECT_CALL(*gl, GetUniformLocation(service_id, StrEq(element_name)))
487 .WillOnce(Return(info.real_location + jj * 2))
488 .RetiresOnSaturation(); 459 .RetiresOnSaturation();
489 } 460 }
461 if ((pass == 0 && info.desired_location >= 0) ||
462 (pass == 1 && info.desired_location < 0)) {
463 if (info.size > 1) {
464 std::string base_name = info.name;
465 size_t array_pos = base_name.rfind("[0]");
466 if (base_name.size() > 3 && array_pos == base_name.size() - 3) {
467 base_name = base_name.substr(0, base_name.size() - 3);
468 }
469 for (GLsizei jj = 1; jj < info.size; ++jj) {
470 std::string element_name(
471 std::string(base_name) + "[" + base::IntToString(jj) + "]");
472 EXPECT_CALL(*gl, GetUniformLocation(
473 service_id, StrEq(element_name)))
474 .WillOnce(Return(info.real_location + jj * 2))
475 .RetiresOnSaturation();
476 }
477 }
478 }
490 } 479 }
491 } 480 }
492 } 481 }
493 482
494 } // namespace gles2 483 } // namespace gles2
495 } // namespace gpu 484 } // namespace gpu
496 485
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/test_helper.h ('k') | gpu/command_buffer/tests/gl_bind_uniform_location_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698