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/gles2_cmd_decoder_unittest_base.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 using ::testing::InSequence; | 29 using ::testing::InSequence; |
30 using ::testing::MatcherCast; | 30 using ::testing::MatcherCast; |
31 using ::testing::Pointee; | 31 using ::testing::Pointee; |
32 using ::testing::Return; | 32 using ::testing::Return; |
33 using ::testing::SetArrayArgument; | 33 using ::testing::SetArrayArgument; |
34 using ::testing::SetArgPointee; | 34 using ::testing::SetArgPointee; |
35 using ::testing::SetArgumentPointee; | 35 using ::testing::SetArgumentPointee; |
36 using ::testing::StrEq; | 36 using ::testing::StrEq; |
37 using ::testing::StrictMock; | 37 using ::testing::StrictMock; |
38 | 38 |
| 39 namespace { |
| 40 |
| 41 void NormalizeInitState(gpu::gles2::GLES2DecoderTestBase::InitState* init) { |
| 42 CHECK(init); |
| 43 const char* kVAOExtensions[] = { |
| 44 "GL_OES_vertex_array_object", |
| 45 "GL_ARB_vertex_array_object", |
| 46 "GL_APPLE_vertex_array_object" |
| 47 }; |
| 48 bool contains_vao_extension = false; |
| 49 for (size_t ii = 0; ii < arraysize(kVAOExtensions); ++ii) { |
| 50 if (init->extensions.find(kVAOExtensions[ii]) != std::string::npos) { |
| 51 contains_vao_extension = true; |
| 52 break; |
| 53 } |
| 54 } |
| 55 if (init->use_native_vao) { |
| 56 if (contains_vao_extension) |
| 57 return; |
| 58 if (!init->extensions.empty()) |
| 59 init->extensions += " "; |
| 60 if (StartsWithASCII(init->gl_version, "opengl es", false)) { |
| 61 init->extensions += kVAOExtensions[0]; |
| 62 } else { |
| 63 #if !defined(OS_MACOSX) |
| 64 init->extensions += kVAOExtensions[1]; |
| 65 #else |
| 66 init->extensions += kVAOExtensions[2]; |
| 67 #endif // OS_MACOSX |
| 68 } |
| 69 } else { |
| 70 // Make sure we don't set up an invalid InitState. |
| 71 CHECK(!contains_vao_extension); |
| 72 } |
| 73 } |
| 74 |
| 75 } // namespace Anonymous |
| 76 |
39 namespace gpu { | 77 namespace gpu { |
40 namespace gles2 { | 78 namespace gles2 { |
41 | 79 |
42 GLES2DecoderTestBase::GLES2DecoderTestBase() | 80 GLES2DecoderTestBase::GLES2DecoderTestBase() |
43 : surface_(NULL), | 81 : surface_(NULL), |
44 context_(NULL), | 82 context_(NULL), |
45 memory_tracker_(NULL), | 83 memory_tracker_(NULL), |
46 client_buffer_id_(100), | 84 client_buffer_id_(100), |
47 client_framebuffer_id_(101), | 85 client_framebuffer_id_(101), |
48 client_program_id_(102), | 86 client_program_id_(102), |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } | 125 } |
88 | 126 |
89 GLES2DecoderTestBase::InitState::InitState() | 127 GLES2DecoderTestBase::InitState::InitState() |
90 : has_alpha(false), | 128 : has_alpha(false), |
91 has_depth(false), | 129 has_depth(false), |
92 has_stencil(false), | 130 has_stencil(false), |
93 request_alpha(false), | 131 request_alpha(false), |
94 request_depth(false), | 132 request_depth(false), |
95 request_stencil(false), | 133 request_stencil(false), |
96 bind_generates_resource(false), | 134 bind_generates_resource(false), |
97 lose_context_when_out_of_memory(false) { | 135 lose_context_when_out_of_memory(false), |
| 136 use_native_vao(true) { |
98 } | 137 } |
99 | 138 |
100 void GLES2DecoderTestBase::InitDecoder(const InitState& init) { | 139 void GLES2DecoderTestBase::InitDecoder(const InitState& init) { |
101 InitDecoderWithCommandLine(init, NULL); | 140 InitDecoderWithCommandLine(init, NULL); |
102 } | 141 } |
103 | 142 |
104 void GLES2DecoderTestBase::InitDecoderWithCommandLine( | 143 void GLES2DecoderTestBase::InitDecoderWithCommandLine( |
105 const InitState& init, | 144 const InitState& init, |
106 const base::CommandLine* command_line) { | 145 const base::CommandLine* command_line) { |
| 146 InitState normalized_init = init; |
| 147 NormalizeInitState(&normalized_init); |
107 Framebuffer::ClearFramebufferCompleteComboMap(); | 148 Framebuffer::ClearFramebufferCompleteComboMap(); |
108 | 149 |
109 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress); | 150 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress); |
110 gfx::GLSurface::InitializeOneOffWithMockBindingsForTests(); | 151 gfx::GLSurface::InitializeOneOffWithMockBindingsForTests(); |
111 | 152 |
112 gl_.reset(new StrictMock<MockGLInterface>()); | 153 gl_.reset(new StrictMock<MockGLInterface>()); |
113 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); | 154 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); |
114 | 155 |
115 // Only create stream texture manager if extension is requested. | 156 // Only create stream texture manager if extension is requested. |
116 std::vector<std::string> list; | 157 std::vector<std::string> list; |
117 base::SplitString(init.extensions, ' ', &list); | 158 base::SplitString(normalized_init.extensions, ' ', &list); |
118 scoped_refptr<FeatureInfo> feature_info; | 159 scoped_refptr<FeatureInfo> feature_info; |
119 if (command_line) | 160 if (command_line) |
120 feature_info = new FeatureInfo(*command_line); | 161 feature_info = new FeatureInfo(*command_line); |
121 group_ = scoped_refptr<ContextGroup>( | 162 group_ = scoped_refptr<ContextGroup>( |
122 new ContextGroup(NULL, | 163 new ContextGroup(NULL, |
123 NULL, | 164 NULL, |
124 memory_tracker_, | 165 memory_tracker_, |
125 new ShaderTranslatorCache, | 166 new ShaderTranslatorCache, |
126 feature_info.get(), | 167 feature_info.get(), |
127 init.bind_generates_resource)); | 168 normalized_init.bind_generates_resource)); |
128 bool use_default_textures = init.bind_generates_resource; | 169 bool use_default_textures = normalized_init.bind_generates_resource; |
129 | 170 |
130 InSequence sequence; | 171 InSequence sequence; |
131 | 172 |
132 surface_ = new gfx::GLSurfaceStub; | 173 surface_ = new gfx::GLSurfaceStub; |
133 surface_->SetSize(gfx::Size(kBackBufferWidth, kBackBufferHeight)); | 174 surface_->SetSize(gfx::Size(kBackBufferWidth, kBackBufferHeight)); |
134 | 175 |
135 // Context needs to be created before initializing ContextGroup, which will | 176 // Context needs to be created before initializing ContextGroup, which will |
136 // in turn initialize FeatureInfo, which needs a context to determine | 177 // in turn initialize FeatureInfo, which needs a context to determine |
137 // extension support. | 178 // extension support. |
138 context_ = new gfx::GLContextStubWithExtensions; | 179 context_ = new gfx::GLContextStubWithExtensions; |
139 context_->AddExtensionsString(init.extensions.c_str()); | 180 context_->AddExtensionsString(normalized_init.extensions.c_str()); |
140 context_->SetGLVersionString(init.gl_version.c_str()); | 181 context_->SetGLVersionString(normalized_init.gl_version.c_str()); |
141 | 182 |
142 context_->MakeCurrent(surface_.get()); | 183 context_->MakeCurrent(surface_.get()); |
143 gfx::GLSurface::InitializeDynamicMockBindingsForTests(context_); | 184 gfx::GLSurface::InitializeDynamicMockBindingsForTests(context_); |
144 | 185 |
145 TestHelper::SetupContextGroupInitExpectations(gl_.get(), | 186 TestHelper::SetupContextGroupInitExpectations( |
146 DisallowedFeatures(), | 187 gl_.get(), |
147 init.extensions.c_str(), | 188 DisallowedFeatures(), |
148 init.gl_version.c_str(), | 189 normalized_init.extensions.c_str(), |
149 init.bind_generates_resource); | 190 normalized_init.gl_version.c_str(), |
| 191 normalized_init.bind_generates_resource); |
150 | 192 |
151 // We initialize the ContextGroup with a MockGLES2Decoder so that | 193 // We initialize the ContextGroup with a MockGLES2Decoder so that |
152 // we can use the ContextGroup to figure out how the real GLES2Decoder | 194 // we can use the ContextGroup to figure out how the real GLES2Decoder |
153 // will initialize itself. | 195 // will initialize itself. |
154 mock_decoder_.reset(new MockGLES2Decoder()); | 196 mock_decoder_.reset(new MockGLES2Decoder()); |
155 EXPECT_TRUE( | 197 EXPECT_TRUE( |
156 group_->Initialize(mock_decoder_.get(), DisallowedFeatures())); | 198 group_->Initialize(mock_decoder_.get(), DisallowedFeatures())); |
157 | 199 |
158 if (group_->feature_info()->feature_flags().native_vertex_array_object) { | 200 if (group_->feature_info()->feature_flags().native_vertex_array_object) { |
159 EXPECT_CALL(*gl_, GenVertexArraysOES(1, _)).Times(1).RetiresOnSaturation(); | 201 EXPECT_CALL(*gl_, GenVertexArraysOES(1, _)) |
| 202 .WillOnce(SetArgumentPointee<1>(kServiceVertexArrayId)) |
| 203 .RetiresOnSaturation(); |
160 EXPECT_CALL(*gl_, BindVertexArrayOES(_)).Times(1).RetiresOnSaturation(); | 204 EXPECT_CALL(*gl_, BindVertexArrayOES(_)).Times(1).RetiresOnSaturation(); |
161 } | 205 } |
162 | 206 |
163 if (group_->feature_info()->workarounds().init_vertex_attributes) | 207 if (group_->feature_info()->workarounds().init_vertex_attributes) |
164 AddExpectationsForVertexAttribManager(); | 208 AddExpectationsForVertexAttribManager(); |
165 | 209 |
166 AddExpectationsForBindVertexArrayOES(); | 210 AddExpectationsForBindVertexArrayOES(); |
167 | 211 |
168 EXPECT_CALL(*gl_, EnableVertexAttribArray(0)) | 212 EXPECT_CALL(*gl_, EnableVertexAttribArray(0)) |
169 .Times(1) | 213 .Times(1) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 .RetiresOnSaturation(); | 276 .RetiresOnSaturation(); |
233 } | 277 } |
234 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) | 278 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) |
235 .Times(1) | 279 .Times(1) |
236 .RetiresOnSaturation(); | 280 .RetiresOnSaturation(); |
237 | 281 |
238 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0)) | 282 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0)) |
239 .Times(1) | 283 .Times(1) |
240 .RetiresOnSaturation(); | 284 .RetiresOnSaturation(); |
241 EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _)) | 285 EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _)) |
242 .WillOnce(SetArgumentPointee<1>(init.has_alpha ? 8 : 0)) | 286 .WillOnce(SetArgumentPointee<1>(normalized_init.has_alpha ? 8 : 0)) |
243 .RetiresOnSaturation(); | 287 .RetiresOnSaturation(); |
244 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _)) | 288 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _)) |
245 .WillOnce(SetArgumentPointee<1>(init.has_depth ? 24 : 0)) | 289 .WillOnce(SetArgumentPointee<1>(normalized_init.has_depth ? 24 : 0)) |
246 .RetiresOnSaturation(); | 290 .RetiresOnSaturation(); |
247 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _)) | 291 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _)) |
248 .WillOnce(SetArgumentPointee<1>(init.has_stencil ? 8 : 0)) | 292 .WillOnce(SetArgumentPointee<1>(normalized_init.has_stencil ? 8 : 0)) |
249 .RetiresOnSaturation(); | 293 .RetiresOnSaturation(); |
250 | 294 |
251 EXPECT_CALL(*gl_, Enable(GL_VERTEX_PROGRAM_POINT_SIZE)) | 295 EXPECT_CALL(*gl_, Enable(GL_VERTEX_PROGRAM_POINT_SIZE)) |
252 .Times(1) | 296 .Times(1) |
253 .RetiresOnSaturation(); | 297 .RetiresOnSaturation(); |
254 | 298 |
255 EXPECT_CALL(*gl_, Enable(GL_POINT_SPRITE)) | 299 EXPECT_CALL(*gl_, Enable(GL_POINT_SPRITE)) |
256 .Times(1) | 300 .Times(1) |
257 .RetiresOnSaturation(); | 301 .RetiresOnSaturation(); |
258 | 302 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 scoped_refptr<gpu::Buffer> buffer = | 342 scoped_refptr<gpu::Buffer> buffer = |
299 engine_->GetSharedMemoryBuffer(kSharedMemoryId); | 343 engine_->GetSharedMemoryBuffer(kSharedMemoryId); |
300 shared_memory_offset_ = kSharedMemoryOffset; | 344 shared_memory_offset_ = kSharedMemoryOffset; |
301 shared_memory_address_ = | 345 shared_memory_address_ = |
302 reinterpret_cast<int8*>(buffer->memory()) + shared_memory_offset_; | 346 reinterpret_cast<int8*>(buffer->memory()) + shared_memory_offset_; |
303 shared_memory_id_ = kSharedMemoryId; | 347 shared_memory_id_ = kSharedMemoryId; |
304 shared_memory_base_ = buffer->memory(); | 348 shared_memory_base_ = buffer->memory(); |
305 | 349 |
306 static const int32 kLoseContextWhenOutOfMemory = 0x10003; | 350 static const int32 kLoseContextWhenOutOfMemory = 0x10003; |
307 | 351 |
308 int32 attributes[] = {EGL_ALPHA_SIZE, | 352 int32 attributes[] = { |
309 init.request_alpha ? 8 : 0, | 353 EGL_ALPHA_SIZE, |
310 EGL_DEPTH_SIZE, | 354 normalized_init.request_alpha ? 8 : 0, |
311 init.request_depth ? 24 : 0, | 355 EGL_DEPTH_SIZE, |
312 EGL_STENCIL_SIZE, | 356 normalized_init.request_depth ? 24 : 0, |
313 init.request_stencil ? 8 : 0, | 357 EGL_STENCIL_SIZE, |
314 kLoseContextWhenOutOfMemory, | 358 normalized_init.request_stencil ? 8 : 0, |
315 init.lose_context_when_out_of_memory ? 1 : 0, }; | 359 kLoseContextWhenOutOfMemory, |
| 360 normalized_init.lose_context_when_out_of_memory ? 1 : 0, }; |
316 std::vector<int32> attribs(attributes, attributes + arraysize(attributes)); | 361 std::vector<int32> attribs(attributes, attributes + arraysize(attributes)); |
317 | 362 |
318 decoder_.reset(GLES2Decoder::Create(group_.get())); | 363 decoder_.reset(GLES2Decoder::Create(group_.get())); |
319 decoder_->SetIgnoreCachedStateForTest(ignore_cached_state_for_test_); | 364 decoder_->SetIgnoreCachedStateForTest(ignore_cached_state_for_test_); |
320 decoder_->GetLogger()->set_log_synthesized_gl_errors(false); | 365 decoder_->GetLogger()->set_log_synthesized_gl_errors(false); |
321 decoder_->Initialize(surface_, | 366 decoder_->Initialize(surface_, |
322 context_, | 367 context_, |
323 false, | 368 false, |
324 surface_->GetSize(), | 369 surface_->GetSize(), |
325 DisallowedFeatures(), | 370 DisallowedFeatures(), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 | 402 |
358 void GLES2DecoderTestBase::ResetDecoder() { | 403 void GLES2DecoderTestBase::ResetDecoder() { |
359 if (!decoder_.get()) | 404 if (!decoder_.get()) |
360 return; | 405 return; |
361 // All Tests should have read all their GLErrors before getting here. | 406 // All Tests should have read all their GLErrors before getting here. |
362 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 407 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
363 | 408 |
364 EXPECT_CALL(*gl_, DeleteBuffersARB(1, _)) | 409 EXPECT_CALL(*gl_, DeleteBuffersARB(1, _)) |
365 .Times(2) | 410 .Times(2) |
366 .RetiresOnSaturation(); | 411 .RetiresOnSaturation(); |
| 412 if (group_->feature_info()->feature_flags().native_vertex_array_object) { |
| 413 EXPECT_CALL(*gl_, DeleteVertexArraysOES(1, Pointee(kServiceVertexArrayId))) |
| 414 .Times(1) |
| 415 .RetiresOnSaturation(); |
| 416 } |
367 | 417 |
368 decoder_->EndDecoding(); | 418 decoder_->EndDecoding(); |
369 decoder_->Destroy(true); | 419 decoder_->Destroy(true); |
370 decoder_.reset(); | 420 decoder_.reset(); |
371 group_->Destroy(mock_decoder_.get(), false); | 421 group_->Destroy(mock_decoder_.get(), false); |
372 engine_.reset(); | 422 engine_.reset(); |
373 ::gfx::MockGLInterface::SetGLInterface(NULL); | 423 ::gfx::MockGLInterface::SetGLInterface(NULL); |
374 gl_.reset(); | 424 gl_.reset(); |
375 } | 425 } |
376 | 426 |
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1559 SetupDefaultProgram(); | 1609 SetupDefaultProgram(); |
1560 } | 1610 } |
1561 | 1611 |
1562 // Include the auto-generated part of this file. We split this because it means | 1612 // Include the auto-generated part of this file. We split this because it means |
1563 // we can easily edit the non-auto generated parts right here in this file | 1613 // we can easily edit the non-auto generated parts right here in this file |
1564 // instead of having to edit some template or the code generator. | 1614 // instead of having to edit some template or the code generator. |
1565 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h" | 1615 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h" |
1566 | 1616 |
1567 } // namespace gles2 | 1617 } // namespace gles2 |
1568 } // namespace gpu | 1618 } // namespace gpu |
OLD | NEW |