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 <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_tokenizer.h" | 11 #include "base/strings/string_tokenizer.h" |
12 #include "gpu/command_buffer/service/buffer_manager.h" | 12 #include "gpu/command_buffer/service/buffer_manager.h" |
13 #include "gpu/command_buffer/service/error_state_mock.h" | 13 #include "gpu/command_buffer/service/error_state_mock.h" |
14 #include "gpu/command_buffer/service/gl_utils.h" | 14 #include "gpu/command_buffer/service/gl_utils.h" |
15 #include "gpu/command_buffer/service/gpu_switches.h" | 15 #include "gpu/command_buffer/service/gpu_switches.h" |
| 16 #include "gpu/command_buffer/service/mocks.h" |
16 #include "gpu/command_buffer/service/program_manager.h" | 17 #include "gpu/command_buffer/service/program_manager.h" |
17 #include "gpu/command_buffer/service/texture_manager.h" | 18 #include "gpu/command_buffer/service/texture_manager.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "ui/gl/gl_mock.h" | 20 #include "ui/gl/gl_mock.h" |
20 | 21 |
21 using ::testing::_; | 22 using ::testing::_; |
22 using ::testing::DoAll; | 23 using ::testing::DoAll; |
23 using ::testing::InSequence; | 24 using ::testing::InSequence; |
24 using ::testing::MatcherCast; | 25 using ::testing::MatcherCast; |
25 using ::testing::Pointee; | 26 using ::testing::Pointee; |
| 27 using ::testing::NotNull; |
26 using ::testing::Return; | 28 using ::testing::Return; |
27 using ::testing::SetArrayArgument; | 29 using ::testing::SetArrayArgument; |
28 using ::testing::SetArgumentPointee; | 30 using ::testing::SetArgumentPointee; |
29 using ::testing::StrEq; | 31 using ::testing::StrEq; |
30 using ::testing::StrictMock; | 32 using ::testing::StrictMock; |
31 | 33 |
32 namespace gpu { | 34 namespace gpu { |
33 namespace gles2 { | 35 namespace gles2 { |
34 | 36 |
35 // GCC requires these declarations, but MSVC requires they not be present | 37 // GCC requires these declarations, but MSVC requires they not be present |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 .Times(1) | 635 .Times(1) |
634 .RetiresOnSaturation(); | 636 .RetiresOnSaturation(); |
635 } else { | 637 } else { |
636 EXPECT_CALL(*error_state, SetGLErrorInvalidParami(_, _, error, _, _, _)) | 638 EXPECT_CALL(*error_state, SetGLErrorInvalidParami(_, _, error, _, _, _)) |
637 .Times(1) | 639 .Times(1) |
638 .RetiresOnSaturation(); | 640 .RetiresOnSaturation(); |
639 } | 641 } |
640 manager->SetParameteri("", error_state, texture_ref, pname, value); | 642 manager->SetParameteri("", error_state, texture_ref, pname, value); |
641 } | 643 } |
642 | 644 |
| 645 // static |
| 646 void TestHelper::SetShaderStates( |
| 647 ::gfx::MockGLInterface* gl, Shader* shader, |
| 648 bool expected_valid, |
| 649 const std::string* const expected_log_info, |
| 650 const std::string* const expected_translated_source, |
| 651 const ShaderTranslatorInterface::VariableMap* const expected_attrib_map, |
| 652 const ShaderTranslatorInterface::VariableMap* const expected_uniform_map, |
| 653 const ShaderTranslatorInterface::VariableMap* const expected_varying_map, |
| 654 const ShaderTranslatorInterface::NameMap* const expected_name_map) { |
| 655 const std::string empty_log_info; |
| 656 const std::string* log_info = (expected_log_info && !expected_valid) ? |
| 657 expected_log_info : &empty_log_info; |
| 658 const std::string empty_translated_source; |
| 659 const std::string* translated_source = |
| 660 (expected_translated_source && expected_valid) ? |
| 661 expected_translated_source : &empty_translated_source; |
| 662 const ShaderTranslatorInterface::VariableMap empty_attrib_map; |
| 663 const ShaderTranslatorInterface::VariableMap* attrib_map = |
| 664 (expected_attrib_map && expected_valid) ? |
| 665 expected_attrib_map : &empty_attrib_map; |
| 666 const ShaderTranslatorInterface::VariableMap empty_uniform_map; |
| 667 const ShaderTranslatorInterface::VariableMap* uniform_map = |
| 668 (expected_uniform_map && expected_valid) ? |
| 669 expected_uniform_map : &empty_uniform_map; |
| 670 const ShaderTranslatorInterface::VariableMap empty_varying_map; |
| 671 const ShaderTranslatorInterface::VariableMap* varying_map = |
| 672 (expected_varying_map && expected_valid) ? |
| 673 expected_varying_map : &empty_varying_map; |
| 674 const ShaderTranslatorInterface::NameMap empty_name_map; |
| 675 const ShaderTranslatorInterface::NameMap* name_map = |
| 676 (expected_name_map && expected_valid) ? |
| 677 expected_name_map : &empty_name_map; |
| 678 |
| 679 MockShaderTranslator translator; |
| 680 EXPECT_CALL(translator, Translate(_, |
| 681 NotNull(), // log_info |
| 682 NotNull(), // translated_source |
| 683 NotNull(), // attrib_map |
| 684 NotNull(), // uniform_map |
| 685 NotNull(), // varying_map |
| 686 NotNull())) // name_map |
| 687 .WillOnce(DoAll(SetArgumentPointee<1>(*log_info), |
| 688 SetArgumentPointee<2>(*translated_source), |
| 689 SetArgumentPointee<3>(*attrib_map), |
| 690 SetArgumentPointee<4>(*uniform_map), |
| 691 SetArgumentPointee<5>(*varying_map), |
| 692 SetArgumentPointee<6>(*name_map), |
| 693 Return(expected_valid))) |
| 694 .RetiresOnSaturation(); |
| 695 if (expected_valid) { |
| 696 EXPECT_CALL(*gl, ShaderSource(shader->service_id(), 1, _, NULL)) |
| 697 .Times(1) |
| 698 .RetiresOnSaturation(); |
| 699 EXPECT_CALL(*gl, CompileShader(shader->service_id())) |
| 700 .Times(1) |
| 701 .RetiresOnSaturation(); |
| 702 EXPECT_CALL(*gl, GetShaderiv(shader->service_id(), |
| 703 GL_COMPILE_STATUS, |
| 704 NotNull())) // status |
| 705 .WillOnce(SetArgumentPointee<2>(GL_TRUE)) |
| 706 .RetiresOnSaturation(); |
| 707 } |
| 708 shader->DoCompile(&translator, Shader::kGL); |
| 709 } |
| 710 |
| 711 // static |
| 712 void TestHelper::SetShaderStates( |
| 713 ::gfx::MockGLInterface* gl, Shader* shader, bool valid) { |
| 714 SetShaderStates(gl, shader, valid, NULL, NULL, NULL, NULL, NULL, NULL); |
| 715 } |
| 716 |
643 ScopedGLImplementationSetter::ScopedGLImplementationSetter( | 717 ScopedGLImplementationSetter::ScopedGLImplementationSetter( |
644 gfx::GLImplementation implementation) | 718 gfx::GLImplementation implementation) |
645 : old_implementation_(gfx::GetGLImplementation()) { | 719 : old_implementation_(gfx::GetGLImplementation()) { |
646 gfx::SetGLImplementation(implementation); | 720 gfx::SetGLImplementation(implementation); |
647 } | 721 } |
648 | 722 |
649 ScopedGLImplementationSetter::~ScopedGLImplementationSetter() { | 723 ScopedGLImplementationSetter::~ScopedGLImplementationSetter() { |
650 gfx::SetGLImplementation(old_implementation_); | 724 gfx::SetGLImplementation(old_implementation_); |
651 } | 725 } |
652 | 726 |
653 } // namespace gles2 | 727 } // namespace gles2 |
654 } // namespace gpu | 728 } // namespace gpu |
655 | 729 |
OLD | NEW |