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/program_manager.h" | 5 #include "gpu/command_buffer/service/program_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <memory> | 11 #include <memory> |
12 | 12 |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 16 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
17 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 17 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
18 #include "gpu/command_buffer/service/common_decoder.h" | 18 #include "gpu/command_buffer/service/common_decoder.h" |
19 #include "gpu/command_buffer/service/feature_info.h" | 19 #include "gpu/command_buffer/service/feature_info.h" |
20 #include "gpu/command_buffer/service/gpu_preferences.h" | 20 #include "gpu/command_buffer/service/gpu_preferences.h" |
21 #include "gpu/command_buffer/service/gpu_service_test.h" | 21 #include "gpu/command_buffer/service/gpu_service_test.h" |
22 #include "gpu/command_buffer/service/gpu_switches.h" | 22 #include "gpu/command_buffer/service/gpu_switches.h" |
23 #include "gpu/command_buffer/service/mocks.h" | 23 #include "gpu/command_buffer/service/mocks.h" |
| 24 #include "gpu/command_buffer/service/progress_reporter_stub.h" |
24 #include "gpu/command_buffer/service/shader_manager.h" | 25 #include "gpu/command_buffer/service/shader_manager.h" |
25 #include "gpu/command_buffer/service/test_helper.h" | 26 #include "gpu/command_buffer/service/test_helper.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "ui/gl/gl_mock.h" | 28 #include "ui/gl/gl_mock.h" |
28 #include "ui/gl/gl_version_info.h" | 29 #include "ui/gl/gl_version_info.h" |
29 | 30 |
30 using ::testing::_; | 31 using ::testing::_; |
31 using ::testing::DoAll; | 32 using ::testing::DoAll; |
32 using ::testing::InSequence; | 33 using ::testing::InSequence; |
33 using ::testing::MatcherCast; | 34 using ::testing::MatcherCast; |
(...skipping 18 matching lines...) Expand all Loading... |
52 uint32_t ComputeOffset(const void* start, const void* position) { | 53 uint32_t ComputeOffset(const void* start, const void* position) { |
53 return static_cast<const uint8_t*>(position) - | 54 return static_cast<const uint8_t*>(position) - |
54 static_cast<const uint8_t*>(start); | 55 static_cast<const uint8_t*>(start); |
55 } | 56 } |
56 | 57 |
57 } // namespace anonymous | 58 } // namespace anonymous |
58 | 59 |
59 class ProgramManagerTestBase : public GpuServiceTest { | 60 class ProgramManagerTestBase : public GpuServiceTest { |
60 protected: | 61 protected: |
61 virtual void SetupProgramManager() { | 62 virtual void SetupProgramManager() { |
62 manager_.reset(new ProgramManager(nullptr, kMaxVaryingVectors, | 63 manager_.reset(new ProgramManager( |
63 kMaxDrawBuffers, | 64 nullptr, kMaxVaryingVectors, kMaxDrawBuffers, kMaxDualSourceDrawBuffers, |
64 kMaxDualSourceDrawBuffers, | 65 kMaxVertexAttribs, gpu_preferences_, feature_info_.get(), |
65 kMaxVertexAttribs, | 66 &progress_reporter_)); |
66 gpu_preferences_, | |
67 feature_info_.get())); | |
68 } | 67 } |
69 void SetUpBase(const char* gl_version, | 68 void SetUpBase(const char* gl_version, |
70 const char* gl_extensions, | 69 const char* gl_extensions, |
71 FeatureInfo* feature_info = nullptr) { | 70 FeatureInfo* feature_info = nullptr) { |
72 GpuServiceTest::SetUpWithGLVersion(gl_version, gl_extensions); | 71 GpuServiceTest::SetUpWithGLVersion(gl_version, gl_extensions); |
73 if (!feature_info) | 72 if (!feature_info) |
74 feature_info = new FeatureInfo(); | 73 feature_info = new FeatureInfo(); |
75 TestHelper::SetupFeatureInfoInitExpectationsWithGLVersion( | 74 TestHelper::SetupFeatureInfoInitExpectationsWithGLVersion( |
76 gl_.get(), gl_extensions, "", gl_version, feature_info->context_type()); | 75 gl_.get(), gl_extensions, "", gl_version, feature_info->context_type()); |
77 feature_info->InitializeForTesting(); | 76 feature_info->InitializeForTesting(); |
78 feature_info_ = feature_info; | 77 feature_info_ = feature_info; |
79 SetupProgramManager(); | 78 SetupProgramManager(); |
80 } | 79 } |
81 void SetUp() override { | 80 void SetUp() override { |
82 // Parameters same as GpuServiceTest::SetUp | 81 // Parameters same as GpuServiceTest::SetUp |
83 SetUpBase("2.0", "GL_EXT_framebuffer_object"); | 82 SetUpBase("2.0", "GL_EXT_framebuffer_object"); |
84 } | 83 } |
85 void TearDown() override { | 84 void TearDown() override { |
86 manager_->Destroy(false); | 85 manager_->Destroy(false); |
87 manager_.reset(); | 86 manager_.reset(); |
88 feature_info_ = nullptr; | 87 feature_info_ = nullptr; |
89 GpuServiceTest::TearDown(); | 88 GpuServiceTest::TearDown(); |
90 } | 89 } |
91 | 90 |
92 std::unique_ptr<ProgramManager> manager_; | 91 std::unique_ptr<ProgramManager> manager_; |
93 GpuPreferences gpu_preferences_; | 92 GpuPreferences gpu_preferences_; |
94 scoped_refptr<FeatureInfo> feature_info_; | 93 scoped_refptr<FeatureInfo> feature_info_; |
| 94 ProgressReporterStub progress_reporter_; |
95 }; | 95 }; |
96 | 96 |
97 class ProgramManagerTest : public ProgramManagerTestBase {}; | 97 class ProgramManagerTest : public ProgramManagerTestBase {}; |
98 | 98 |
99 TEST_F(ProgramManagerTest, Basic) { | 99 TEST_F(ProgramManagerTest, Basic) { |
100 const GLuint kClient1Id = 1; | 100 const GLuint kClient1Id = 1; |
101 const GLuint kService1Id = 11; | 101 const GLuint kService1Id = 11; |
102 const GLuint kClient2Id = 2; | 102 const GLuint kClient2Id = 2; |
103 // Check we can create program. | 103 // Check we can create program. |
104 manager_->CreateProgram(kClient1Id, kService1Id); | 104 manager_->CreateProgram(kClient1Id, kService1Id); |
(...skipping 19 matching lines...) Expand all Loading... |
124 EXPECT_CALL(*gl_, DeleteProgram(kService1Id)) | 124 EXPECT_CALL(*gl_, DeleteProgram(kService1Id)) |
125 .Times(1) | 125 .Times(1) |
126 .RetiresOnSaturation(); | 126 .RetiresOnSaturation(); |
127 manager_->Destroy(true); | 127 manager_->Destroy(true); |
128 // Check the resources were released. | 128 // Check the resources were released. |
129 program1 = manager_->GetProgram(kClient1Id); | 129 program1 = manager_->GetProgram(kClient1Id); |
130 ASSERT_TRUE(program1 == NULL); | 130 ASSERT_TRUE(program1 == NULL); |
131 } | 131 } |
132 | 132 |
133 TEST_F(ProgramManagerTest, DeleteBug) { | 133 TEST_F(ProgramManagerTest, DeleteBug) { |
134 ShaderManager shader_manager; | 134 ShaderManager shader_manager(&progress_reporter_); |
135 const GLuint kClient1Id = 1; | 135 const GLuint kClient1Id = 1; |
136 const GLuint kClient2Id = 2; | 136 const GLuint kClient2Id = 2; |
137 const GLuint kService1Id = 11; | 137 const GLuint kService1Id = 11; |
138 const GLuint kService2Id = 12; | 138 const GLuint kService2Id = 12; |
139 // Check we can create program. | 139 // Check we can create program. |
140 scoped_refptr<Program> program1( | 140 scoped_refptr<Program> program1( |
141 manager_->CreateProgram(kClient1Id, kService1Id)); | 141 manager_->CreateProgram(kClient1Id, kService1Id)); |
142 scoped_refptr<Program> program2( | 142 scoped_refptr<Program> program2( |
143 manager_->CreateProgram(kClient2Id, kService2Id)); | 143 manager_->CreateProgram(kClient2Id, kService2Id)); |
144 // Check program got created. | 144 // Check program got created. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 static const char* kOutputVariable1Name; | 231 static const char* kOutputVariable1Name; |
232 static const GLint kOutputVariable1Size = 1; | 232 static const GLint kOutputVariable1Size = 1; |
233 static const GLenum kOutputVariable1Precision = GL_MEDIUM_FLOAT; | 233 static const GLenum kOutputVariable1Precision = GL_MEDIUM_FLOAT; |
234 static const bool kOutputVariable1StaticUse = true; | 234 static const bool kOutputVariable1StaticUse = true; |
235 static const GLint kOutputVariable1Location = -1; | 235 static const GLint kOutputVariable1Location = -1; |
236 static const GLenum kOutputVariable1Type = GL_FLOAT_VEC4; | 236 static const GLenum kOutputVariable1Type = GL_FLOAT_VEC4; |
237 | 237 |
238 static const size_t kNumAttribs; | 238 static const size_t kNumAttribs; |
239 static const size_t kNumUniforms; | 239 static const size_t kNumUniforms; |
240 | 240 |
| 241 ProgramManagerWithShaderTest() : shader_manager_(&progress_reporter_) {} |
| 242 |
241 protected: | 243 protected: |
242 typedef TestHelper::AttribInfo AttribInfo; | 244 typedef TestHelper::AttribInfo AttribInfo; |
243 typedef TestHelper::UniformInfo UniformInfo; | 245 typedef TestHelper::UniformInfo UniformInfo; |
244 | 246 |
245 typedef enum { | 247 typedef enum { |
246 kVarUniform, | 248 kVarUniform, |
247 kVarVarying, | 249 kVarVarying, |
248 kVarAttribute, | 250 kVarAttribute, |
249 kVarOutput, | 251 kVarOutput, |
250 } VarCategory; | 252 } VarCategory; |
(...skipping 1808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2059 static const GLuint kServiceProgramId = 10; | 2061 static const GLuint kServiceProgramId = 10; |
2060 static const GLuint kVertexShaderClientId = 2; | 2062 static const GLuint kVertexShaderClientId = 2; |
2061 static const GLuint kFragmentShaderClientId = 20; | 2063 static const GLuint kFragmentShaderClientId = 20; |
2062 static const GLuint kVertexShaderServiceId = 3; | 2064 static const GLuint kVertexShaderServiceId = 3; |
2063 static const GLuint kFragmentShaderServiceId = 30; | 2065 static const GLuint kFragmentShaderServiceId = 30; |
2064 | 2066 |
2065 ProgramManagerWithCacheTest() | 2067 ProgramManagerWithCacheTest() |
2066 : cache_(new MockProgramCache()), | 2068 : cache_(new MockProgramCache()), |
2067 vertex_shader_(NULL), | 2069 vertex_shader_(NULL), |
2068 fragment_shader_(NULL), | 2070 fragment_shader_(NULL), |
2069 program_(NULL) { | 2071 program_(NULL), |
2070 } | 2072 shader_manager_(&progress_reporter_) {} |
2071 | 2073 |
2072 protected: | 2074 protected: |
2073 void SetupProgramManager() override { | 2075 void SetupProgramManager() override { |
2074 manager_.reset(new ProgramManager(cache_.get(), kMaxVaryingVectors, | 2076 manager_.reset(new ProgramManager( |
2075 kMaxDrawBuffers, | 2077 cache_.get(), kMaxVaryingVectors, kMaxDrawBuffers, |
2076 kMaxDualSourceDrawBuffers, | 2078 kMaxDualSourceDrawBuffers, kMaxVertexAttribs, gpu_preferences_, |
2077 kMaxVertexAttribs, | 2079 feature_info_.get(), &progress_reporter_)); |
2078 gpu_preferences_, | |
2079 feature_info_.get())); | |
2080 } | 2080 } |
2081 | 2081 |
2082 void SetUp() override { | 2082 void SetUp() override { |
2083 ProgramManagerTestBase::SetUp(); | 2083 ProgramManagerTestBase::SetUp(); |
2084 | 2084 |
2085 vertex_shader_ = shader_manager_.CreateShader( | 2085 vertex_shader_ = shader_manager_.CreateShader( |
2086 kVertexShaderClientId, kVertexShaderServiceId, GL_VERTEX_SHADER); | 2086 kVertexShaderClientId, kVertexShaderServiceId, GL_VERTEX_SHADER); |
2087 fragment_shader_ = shader_manager_.CreateShader( | 2087 fragment_shader_ = shader_manager_.CreateShader( |
2088 kFragmentShaderClientId, kFragmentShaderServiceId, GL_FRAGMENT_SHADER); | 2088 kFragmentShaderClientId, kFragmentShaderServiceId, GL_FRAGMENT_SHADER); |
2089 ASSERT_TRUE(vertex_shader_ != NULL); | 2089 ASSERT_TRUE(vertex_shader_ != NULL); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2241 EXPECT_CALL(*gl_.get(), GetShaderInfoLog(shader_id, 0, _, _)) | 2241 EXPECT_CALL(*gl_.get(), GetShaderInfoLog(shader_id, 0, _, _)) |
2242 .Times(1); | 2242 .Times(1); |
2243 } | 2243 } |
2244 | 2244 |
2245 std::unique_ptr<MockProgramCache> cache_; | 2245 std::unique_ptr<MockProgramCache> cache_; |
2246 | 2246 |
2247 Shader* vertex_shader_; | 2247 Shader* vertex_shader_; |
2248 Shader* fragment_shader_; | 2248 Shader* fragment_shader_; |
2249 Program* program_; | 2249 Program* program_; |
2250 ShaderManager shader_manager_; | 2250 ShaderManager shader_manager_; |
| 2251 ProgressReporterStub progress_reporter_; |
2251 }; | 2252 }; |
2252 | 2253 |
2253 // GCC requires these declarations, but MSVC requires they not be present | 2254 // GCC requires these declarations, but MSVC requires they not be present |
2254 #ifndef COMPILER_MSVC | 2255 #ifndef COMPILER_MSVC |
2255 const GLuint ProgramManagerWithCacheTest::kClientProgramId; | 2256 const GLuint ProgramManagerWithCacheTest::kClientProgramId; |
2256 const GLuint ProgramManagerWithCacheTest::kServiceProgramId; | 2257 const GLuint ProgramManagerWithCacheTest::kServiceProgramId; |
2257 const GLuint ProgramManagerWithCacheTest::kVertexShaderClientId; | 2258 const GLuint ProgramManagerWithCacheTest::kVertexShaderClientId; |
2258 const GLuint ProgramManagerWithCacheTest::kFragmentShaderClientId; | 2259 const GLuint ProgramManagerWithCacheTest::kFragmentShaderClientId; |
2259 const GLuint ProgramManagerWithCacheTest::kVertexShaderServiceId; | 2260 const GLuint ProgramManagerWithCacheTest::kVertexShaderServiceId; |
2260 const GLuint ProgramManagerWithCacheTest::kFragmentShaderServiceId; | 2261 const GLuint ProgramManagerWithCacheTest::kFragmentShaderServiceId; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2521 ProgramManagerDualSourceBlendingES2Test, | 2522 ProgramManagerDualSourceBlendingES2Test, |
2522 testing::Values( | 2523 testing::Values( |
2523 make_gl_ext_tuple("3.2", | 2524 make_gl_ext_tuple("3.2", |
2524 "GL_ARB_draw_buffers GL_ARB_blend_func_extended " | 2525 "GL_ARB_draw_buffers GL_ARB_blend_func_extended " |
2525 "GL_ARB_program_interface_query"), | 2526 "GL_ARB_program_interface_query"), |
2526 make_gl_ext_tuple("opengl es 3.1", | 2527 make_gl_ext_tuple("opengl es 3.1", |
2527 "GL_EXT_draw_buffers GL_EXT_blend_func_extended"))); | 2528 "GL_EXT_draw_buffers GL_EXT_blend_func_extended"))); |
2528 | 2529 |
2529 } // namespace gles2 | 2530 } // namespace gles2 |
2530 } // namespace gpu | 2531 } // namespace gpu |
OLD | NEW |