| 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 // Tests for GLES2Implementation. | 5 // Tests for GLES2Implementation. |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 8 | 8 |
| 9 #include <GLES2/gl2ext.h> | 9 #include <GLES2/gl2ext.h> |
| 10 #include "gpu/command_buffer/client/client_test_helper.h" | 10 #include "gpu/command_buffer/client/client_test_helper.h" |
| 11 #include "gpu/command_buffer/client/program_info_manager.h" |
| 11 #include "gpu/command_buffer/client/transfer_buffer.h" | 12 #include "gpu/command_buffer/client/transfer_buffer.h" |
| 12 #include "gpu/command_buffer/common/command_buffer.h" | 13 #include "gpu/command_buffer/common/command_buffer.h" |
| 13 #include "gpu/command_buffer/common/compiler_specific.h" | 14 #include "gpu/command_buffer/common/compiler_specific.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 16 | 17 |
| 17 #if !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) | 18 #if !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) |
| 18 #define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS | 19 #define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS |
| 19 #endif | 20 #endif |
| 20 | 21 |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 } | 439 } |
| 439 | 440 |
| 440 ExpectedMemoryInfo GetExpectedMemory(size_t size) { | 441 ExpectedMemoryInfo GetExpectedMemory(size_t size) { |
| 441 return transfer_buffer_->GetExpectedMemory(size); | 442 return transfer_buffer_->GetExpectedMemory(size); |
| 442 } | 443 } |
| 443 | 444 |
| 444 ExpectedMemoryInfo GetExpectedResultMemory(size_t size) { | 445 ExpectedMemoryInfo GetExpectedResultMemory(size_t size) { |
| 445 return transfer_buffer_->GetExpectedResultMemory(size); | 446 return transfer_buffer_->GetExpectedResultMemory(size); |
| 446 } | 447 } |
| 447 | 448 |
| 449 // Sets the ProgramInfoManager. The manager will be owned |
| 450 // by the ShareGroup. |
| 451 void SetProgramInfoManager(ProgramInfoManager* manager) { |
| 452 gl_->share_group()->set_program_info_manager(manager); |
| 453 } |
| 454 |
| 448 int CheckError() { | 455 int CheckError() { |
| 449 ExpectedMemoryInfo result = | 456 ExpectedMemoryInfo result = |
| 450 GetExpectedResultMemory(sizeof(GetError::Result)); | 457 GetExpectedResultMemory(sizeof(GetError::Result)); |
| 451 EXPECT_CALL(*command_buffer(), OnFlush()) | 458 EXPECT_CALL(*command_buffer(), OnFlush()) |
| 452 .WillOnce(SetMemory(result.ptr, GLuint(GL_NO_ERROR))) | 459 .WillOnce(SetMemory(result.ptr, GLuint(GL_NO_ERROR))) |
| 453 .RetiresOnSaturation(); | 460 .RetiresOnSaturation(); |
| 454 return gl_->GetError(); | 461 return gl_->GetError(); |
| 455 } | 462 } |
| 456 | 463 |
| 457 bool GetBucketContents(uint32 bucket_id, std::vector<int8>* data) { | 464 bool GetBucketContents(uint32 bucket_id, std::vector<int8>* data) { |
| (...skipping 2093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2551 EXPECT_EQ(0xBDu, available); | 2558 EXPECT_EQ(0xBDu, available); |
| 2552 EXPECT_EQ(GL_INVALID_OPERATION, CheckError()); | 2559 EXPECT_EQ(GL_INVALID_OPERATION, CheckError()); |
| 2553 | 2560 |
| 2554 // Test GetQueryObjectuivEXT CheckResultsAvailable | 2561 // Test GetQueryObjectuivEXT CheckResultsAvailable |
| 2555 ClearCommands(); | 2562 ClearCommands(); |
| 2556 gl_->GetQueryObjectuivEXT(id1, GL_QUERY_RESULT_AVAILABLE_EXT, &available); | 2563 gl_->GetQueryObjectuivEXT(id1, GL_QUERY_RESULT_AVAILABLE_EXT, &available); |
| 2557 EXPECT_TRUE(NoCommandsWritten()); | 2564 EXPECT_TRUE(NoCommandsWritten()); |
| 2558 EXPECT_EQ(0u, available); | 2565 EXPECT_EQ(0u, available); |
| 2559 } | 2566 } |
| 2560 | 2567 |
| 2568 namespace { |
| 2569 |
| 2570 class MockProgramInfoManager : public ProgramInfoManager { |
| 2571 public: |
| 2572 virtual ~MockProgramInfoManager() {}; |
| 2573 |
| 2574 MOCK_METHOD1(CreateInfo, void(GLuint program)); |
| 2575 |
| 2576 MOCK_METHOD1(DeleteInfo, void(GLuint program)); |
| 2577 |
| 2578 MOCK_METHOD4(GetProgramiv, bool( |
| 2579 GLES2Implementation* gl, GLuint program, GLenum pname, GLint* params)); |
| 2580 |
| 2581 MOCK_METHOD3(GetAttribLocation, GLint( |
| 2582 GLES2Implementation* gl, GLuint program, const char* name)); |
| 2583 |
| 2584 MOCK_METHOD3(GetUniformLocation, GLint( |
| 2585 GLES2Implementation* gl, GLuint program, const char* name)); |
| 2586 |
| 2587 MOCK_METHOD8(GetActiveAttrib, bool( |
| 2588 GLES2Implementation* gl, |
| 2589 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, |
| 2590 GLint* size, GLenum* type, char* name)); |
| 2591 |
| 2592 MOCK_METHOD8(GetActiveUniform, bool( |
| 2593 GLES2Implementation* gl, |
| 2594 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, |
| 2595 GLint* size, GLenum* type, char* name)); |
| 2596 }; |
| 2597 |
| 2598 } // anonymous namespace |
| 2599 |
| 2561 TEST_F(GLES2ImplementationTest, GetUniformLocationsCHROMIUM) { | 2600 TEST_F(GLES2ImplementationTest, GetUniformLocationsCHROMIUM) { |
| 2601 MockProgramInfoManager* manager = new MockProgramInfoManager(); |
| 2602 SetProgramInfoManager(manager); |
| 2603 |
| 2604 const GLuint kProgramId = 123; |
| 2562 static const GLUniformDefinitionCHROMIUM good_defs[] = { | 2605 static const GLUniformDefinitionCHROMIUM good_defs[] = { |
| 2563 { GL_FLOAT_VEC4, 1, "moo", }, | 2606 { GL_FLOAT_VEC4, 1, "moo", }, |
| 2564 { GL_FLOAT_VEC4, 4, "bar", }, | 2607 { GL_FLOAT_VEC4, 4, "bar", }, |
| 2565 { GL_FLOAT_VEC4, 3, "foo", }, | 2608 { GL_FLOAT_VEC4, 3, "foo", }, |
| 2566 }; | 2609 }; |
| 2567 | 2610 |
| 2568 static const GLUniformDefinitionCHROMIUM bad_defs[] = { | 2611 static const GLUniformDefinitionCHROMIUM bad_defs[] = { |
| 2569 { GL_FLOAT_VEC4, 1, "moo", }, | 2612 { GL_FLOAT_VEC4, 1, "moo", }, |
| 2570 { GL_FLOAT_VEC4, 0, "bar", }, | 2613 { GL_FLOAT_VEC4, 0, "bar", }, |
| 2571 { GL_FLOAT_VEC4, 3, "foo", }, | 2614 { GL_FLOAT_VEC4, 3, "foo", }, |
| 2572 }; | 2615 }; |
| 2573 | 2616 |
| 2574 // Test bad count | 2617 // Test bad count |
| 2575 GLint locations[50] = { -1, }; | 2618 GLint locations[50] = { -1, }; |
| 2576 gl_->GetUniformLocationsCHROMIUM(bad_defs, 0, 1, locations); | 2619 gl_->GetUniformLocationsCHROMIUM(kProgramId, bad_defs, 0, 1, locations); |
| 2577 EXPECT_EQ(GL_INVALID_VALUE, CheckError()); | 2620 EXPECT_EQ(GL_INVALID_VALUE, CheckError()); |
| 2578 EXPECT_EQ(-1, locations[0]); | 2621 EXPECT_EQ(-1, locations[0]); |
| 2579 | 2622 |
| 2580 // Test bad size. | 2623 // Test bad size. |
| 2581 gl_->GetUniformLocationsCHROMIUM( | 2624 gl_->GetUniformLocationsCHROMIUM( |
| 2582 bad_defs, arraysize(bad_defs), 1, locations); | 2625 kProgramId, bad_defs, arraysize(bad_defs), 1, locations); |
| 2583 EXPECT_EQ(GL_INVALID_VALUE, CheckError()); | 2626 EXPECT_EQ(GL_INVALID_VALUE, CheckError()); |
| 2584 EXPECT_EQ(-1, locations[0]); | 2627 EXPECT_EQ(-1, locations[0]); |
| 2585 | 2628 |
| 2629 #if defined(GPU_CLIENT_DEBUG) |
| 2630 EXPECT_CALL(*manager, GetUniformLocation(_, kProgramId, _)) |
| 2631 .WillOnce(Return( |
| 2632 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(2, 0)))) |
| 2633 .WillOnce(Return( |
| 2634 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 0)))) |
| 2635 .WillOnce(Return( |
| 2636 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 1)))) |
| 2637 .RetiresOnSaturation(); |
| 2638 #endif |
| 2639 |
| 2586 // Test max_locations | 2640 // Test max_locations |
| 2587 gl_->GetUniformLocationsCHROMIUM( | 2641 gl_->GetUniformLocationsCHROMIUM( |
| 2588 good_defs, arraysize(good_defs), 3, locations); | 2642 kProgramId, good_defs, arraysize(good_defs), 3, locations); |
| 2589 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(2, 0)), | 2643 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(2, 0)), |
| 2590 locations[0]); | 2644 locations[0]); |
| 2591 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 0)), | 2645 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 0)), |
| 2592 locations[1]); | 2646 locations[1]); |
| 2593 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 1)), | 2647 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 1)), |
| 2594 locations[2]); | 2648 locations[2]); |
| 2595 EXPECT_EQ(0, locations[3]); | 2649 EXPECT_EQ(0, locations[3]); |
| 2596 | 2650 |
| 2651 #if defined(GPU_CLIENT_DEBUG) |
| 2652 EXPECT_CALL(*manager, GetUniformLocation(_, kProgramId, _)) |
| 2653 .WillOnce(Return( |
| 2654 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(2, 0)))) |
| 2655 .WillOnce(Return( |
| 2656 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 0)))) |
| 2657 .WillOnce(Return( |
| 2658 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 1)))) |
| 2659 .WillOnce(Return( |
| 2660 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 2)))) |
| 2661 .WillOnce(Return( |
| 2662 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 3)))) |
| 2663 .WillOnce(Return( |
| 2664 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(1, 0)))) |
| 2665 .WillOnce(Return( |
| 2666 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(1, 1)))) |
| 2667 .WillOnce(Return( |
| 2668 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(1, 2)))) |
| 2669 .RetiresOnSaturation(); |
| 2670 #endif |
| 2671 |
| 2597 // Test all. | 2672 // Test all. |
| 2598 gl_->GetUniformLocationsCHROMIUM( | 2673 gl_->GetUniformLocationsCHROMIUM( |
| 2599 good_defs, arraysize(good_defs), arraysize(locations), locations); | 2674 kProgramId, good_defs, arraysize(good_defs), arraysize(locations), |
| 2675 locations); |
| 2600 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(2, 0)), | 2676 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(2, 0)), |
| 2601 locations[0]); | 2677 locations[0]); |
| 2602 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 0)), | 2678 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 0)), |
| 2603 locations[1]); | 2679 locations[1]); |
| 2604 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 1)), | 2680 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 1)), |
| 2605 locations[2]); | 2681 locations[2]); |
| 2606 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 2)), | 2682 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 2)), |
| 2607 locations[3]); | 2683 locations[3]); |
| 2608 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 3)), | 2684 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 3)), |
| 2609 locations[4]); | 2685 locations[4]); |
| 2610 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(1, 0)), | 2686 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(1, 0)), |
| 2611 locations[5]); | 2687 locations[5]); |
| 2612 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(1, 1)), | 2688 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(1, 1)), |
| 2613 locations[6]); | 2689 locations[6]); |
| 2614 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(1, 2)), | 2690 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(1, 2)), |
| 2615 locations[7]); | 2691 locations[7]); |
| 2616 EXPECT_EQ(0, locations[8]); | 2692 EXPECT_EQ(0, locations[8]); |
| 2617 } | 2693 } |
| 2618 | 2694 |
| 2619 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" | 2695 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" |
| 2620 | 2696 |
| 2621 } // namespace gles2 | 2697 } // namespace gles2 |
| 2622 } // namespace gpu | 2698 } // namespace gpu |
| 2623 | 2699 |
| 2624 | |
| OLD | NEW |