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 <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 struct ExpectedMemoryInfo { | 86 struct ExpectedMemoryInfo { |
87 uint32 offset; | 87 uint32 offset; |
88 int32 id; | 88 int32 id; |
89 uint8* ptr; | 89 uint8* ptr; |
90 }; | 90 }; |
91 | 91 |
92 MockTransferBuffer( | 92 MockTransferBuffer( |
93 CommandBuffer* command_buffer, | 93 CommandBuffer* command_buffer, |
94 unsigned int size, | 94 unsigned int size, |
95 unsigned int result_size, | 95 unsigned int result_size, |
96 unsigned int alignment) | 96 unsigned int alignment, |
| 97 bool initialize_fail) |
97 : command_buffer_(command_buffer), | 98 : command_buffer_(command_buffer), |
98 size_(size), | 99 size_(size), |
99 result_size_(result_size), | 100 result_size_(result_size), |
100 alignment_(alignment), | 101 alignment_(alignment), |
101 actual_buffer_index_(0), | 102 actual_buffer_index_(0), |
102 expected_buffer_index_(0), | 103 expected_buffer_index_(0), |
103 last_alloc_(NULL), | 104 last_alloc_(NULL), |
104 expected_offset_(result_size), | 105 expected_offset_(result_size), |
105 actual_offset_(result_size) { | 106 actual_offset_(result_size), |
| 107 initialize_fail_(initialize_fail) { |
106 // We have to allocate the buffers here because | 108 // We have to allocate the buffers here because |
107 // we need to know their address before GLES2Implementation::Initialize | 109 // we need to know their address before GLES2Implementation::Initialize |
108 // is called. | 110 // is called. |
109 for (int ii = 0; ii < kNumBuffers; ++ii) { | 111 for (int ii = 0; ii < kNumBuffers; ++ii) { |
110 buffers_[ii] = command_buffer_->CreateTransferBuffer( | 112 buffers_[ii] = command_buffer_->CreateTransferBuffer( |
111 size_ + ii * alignment_, | 113 size_ + ii * alignment_, |
112 &buffer_ids_[ii]); | 114 &buffer_ids_[ii]); |
113 EXPECT_NE(-1, buffer_ids_[ii]); | 115 EXPECT_NE(-1, buffer_ids_[ii]); |
114 } | 116 } |
115 } | 117 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 size_t size_; | 215 size_t size_; |
214 size_t result_size_; | 216 size_t result_size_; |
215 uint32 alignment_; | 217 uint32 alignment_; |
216 int buffer_ids_[kNumBuffers]; | 218 int buffer_ids_[kNumBuffers]; |
217 scoped_refptr<Buffer> buffers_[kNumBuffers]; | 219 scoped_refptr<Buffer> buffers_[kNumBuffers]; |
218 int actual_buffer_index_; | 220 int actual_buffer_index_; |
219 int expected_buffer_index_; | 221 int expected_buffer_index_; |
220 void* last_alloc_; | 222 void* last_alloc_; |
221 uint32 expected_offset_; | 223 uint32 expected_offset_; |
222 uint32 actual_offset_; | 224 uint32 actual_offset_; |
| 225 bool initialize_fail_; |
223 | 226 |
224 DISALLOW_COPY_AND_ASSIGN(MockTransferBuffer); | 227 DISALLOW_COPY_AND_ASSIGN(MockTransferBuffer); |
225 }; | 228 }; |
226 | 229 |
227 bool MockTransferBuffer::Initialize( | 230 bool MockTransferBuffer::Initialize( |
228 unsigned int starting_buffer_size, | 231 unsigned int starting_buffer_size, |
229 unsigned int result_size, | 232 unsigned int result_size, |
230 unsigned int /* min_buffer_size */, | 233 unsigned int /* min_buffer_size */, |
231 unsigned int /* max_buffer_size */, | 234 unsigned int /* max_buffer_size */, |
232 unsigned int alignment, | 235 unsigned int alignment, |
233 unsigned int /* size_to_flush */) { | 236 unsigned int /* size_to_flush */) { |
234 // Just check they match. | 237 // Just check they match. |
235 return size_ == starting_buffer_size && | 238 return size_ == starting_buffer_size && |
236 result_size_ == result_size && | 239 result_size_ == result_size && |
237 alignment_ == alignment; | 240 alignment_ == alignment && !initialize_fail_; |
238 }; | 241 }; |
239 | 242 |
240 int MockTransferBuffer::GetShmId() { | 243 int MockTransferBuffer::GetShmId() { |
241 return buffer_ids_[actual_buffer_index_]; | 244 return buffer_ids_[actual_buffer_index_]; |
242 } | 245 } |
243 | 246 |
244 void* MockTransferBuffer::GetResultBuffer() { | 247 void* MockTransferBuffer::GetResultBuffer() { |
245 return actual_buffer() + actual_buffer_index_ * alignment_; | 248 return actual_buffer() + actual_buffer_index_ * alignment_; |
246 } | 249 } |
247 | 250 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 | 390 |
388 typedef MockTransferBuffer::ExpectedMemoryInfo ExpectedMemoryInfo; | 391 typedef MockTransferBuffer::ExpectedMemoryInfo ExpectedMemoryInfo; |
389 | 392 |
390 class TestContext { | 393 class TestContext { |
391 public: | 394 public: |
392 TestContext() : commands_(NULL), token_(0) {} | 395 TestContext() : commands_(NULL), token_(0) {} |
393 | 396 |
394 bool Initialize(ShareGroup* share_group, | 397 bool Initialize(ShareGroup* share_group, |
395 bool bind_generates_resource_client, | 398 bool bind_generates_resource_client, |
396 bool bind_generates_resource_service, | 399 bool bind_generates_resource_service, |
397 bool lose_context_when_out_of_memory) { | 400 bool lose_context_when_out_of_memory, |
| 401 bool transfer_buffer_initialize_fail) { |
398 command_buffer_.reset(new StrictMock<MockClientCommandBuffer>()); | 402 command_buffer_.reset(new StrictMock<MockClientCommandBuffer>()); |
399 if (!command_buffer_->Initialize()) | 403 if (!command_buffer_->Initialize()) |
400 return false; | 404 return false; |
401 | 405 |
402 transfer_buffer_.reset( | 406 transfer_buffer_.reset( |
403 new MockTransferBuffer(command_buffer_.get(), | 407 new MockTransferBuffer(command_buffer_.get(), |
404 kTransferBufferSize, | 408 kTransferBufferSize, |
405 GLES2Implementation::kStartingOffset, | 409 GLES2Implementation::kStartingOffset, |
406 GLES2Implementation::kAlignment)); | 410 GLES2Implementation::kAlignment, |
| 411 transfer_buffer_initialize_fail)); |
407 | 412 |
408 helper_.reset(new GLES2CmdHelper(command_buffer())); | 413 helper_.reset(new GLES2CmdHelper(command_buffer())); |
409 helper_->Initialize(kCommandBufferSizeBytes); | 414 helper_->Initialize(kCommandBufferSizeBytes); |
410 | 415 |
411 gpu_control_.reset(new StrictMock<MockClientGpuControl>()); | 416 gpu_control_.reset(new StrictMock<MockClientGpuControl>()); |
412 Capabilities capabilities; | 417 Capabilities capabilities; |
413 capabilities.VisitPrecisions( | 418 capabilities.VisitPrecisions( |
414 [](GLenum shader, GLenum type, | 419 [](GLenum shader, GLenum type, |
415 Capabilities::ShaderPrecision* precision) { | 420 Capabilities::ShaderPrecision* precision) { |
416 precision->min_range = 3; | 421 precision->min_range = 3; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 } | 520 } |
516 | 521 |
517 QueryTracker::Query* GetQuery(GLuint id) { | 522 QueryTracker::Query* GetQuery(GLuint id) { |
518 return gl_->query_tracker_->GetQuery(id); | 523 return gl_->query_tracker_->GetQuery(id); |
519 } | 524 } |
520 | 525 |
521 struct ContextInitOptions { | 526 struct ContextInitOptions { |
522 ContextInitOptions() | 527 ContextInitOptions() |
523 : bind_generates_resource_client(true), | 528 : bind_generates_resource_client(true), |
524 bind_generates_resource_service(true), | 529 bind_generates_resource_service(true), |
525 lose_context_when_out_of_memory(false) {} | 530 lose_context_when_out_of_memory(false), |
| 531 transfer_buffer_initialize_fail(false) {} |
526 | 532 |
527 bool bind_generates_resource_client; | 533 bool bind_generates_resource_client; |
528 bool bind_generates_resource_service; | 534 bool bind_generates_resource_service; |
529 bool lose_context_when_out_of_memory; | 535 bool lose_context_when_out_of_memory; |
| 536 bool transfer_buffer_initialize_fail; |
530 }; | 537 }; |
531 | 538 |
532 bool Initialize(const ContextInitOptions& init_options) { | 539 bool Initialize(const ContextInitOptions& init_options) { |
533 bool success = true; | 540 bool success = true; |
534 share_group_ = new ShareGroup(init_options.bind_generates_resource_client); | 541 share_group_ = new ShareGroup(init_options.bind_generates_resource_client); |
535 | 542 |
536 for (int i = 0; i < kNumTestContexts; i++) { | 543 for (int i = 0; i < kNumTestContexts; i++) { |
537 if (!test_contexts_[i].Initialize( | 544 if (!test_contexts_[i].Initialize( |
538 share_group_.get(), | 545 share_group_.get(), |
539 init_options.bind_generates_resource_client, | 546 init_options.bind_generates_resource_client, |
540 init_options.bind_generates_resource_service, | 547 init_options.bind_generates_resource_service, |
541 init_options.lose_context_when_out_of_memory)) | 548 init_options.lose_context_when_out_of_memory, |
| 549 init_options.transfer_buffer_initialize_fail)) |
542 success = false; | 550 success = false; |
543 } | 551 } |
544 | 552 |
545 // Default to test context 0. | 553 // Default to test context 0. |
546 gpu_control_ = test_contexts_[0].gpu_control_.get(); | 554 gpu_control_ = test_contexts_[0].gpu_control_.get(); |
547 helper_ = test_contexts_[0].helper_.get(); | 555 helper_ = test_contexts_[0].helper_.get(); |
548 transfer_buffer_ = test_contexts_[0].transfer_buffer_.get(); | 556 transfer_buffer_ = test_contexts_[0].transfer_buffer_.get(); |
549 gl_ = test_contexts_[0].gl_.get(); | 557 gl_ = test_contexts_[0].gl_.get(); |
550 commands_ = test_contexts_[0].commands_; | 558 commands_ = test_contexts_[0].commands_; |
551 return success; | 559 return success; |
(...skipping 2743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3295 EXPECT_FALSE(Initialize(init_options)); | 3303 EXPECT_FALSE(Initialize(init_options)); |
3296 } | 3304 } |
3297 | 3305 |
3298 TEST_F(GLES2ImplementationManualInitTest, FailInitOnBGRMismatch2) { | 3306 TEST_F(GLES2ImplementationManualInitTest, FailInitOnBGRMismatch2) { |
3299 ContextInitOptions init_options; | 3307 ContextInitOptions init_options; |
3300 init_options.bind_generates_resource_client = true; | 3308 init_options.bind_generates_resource_client = true; |
3301 init_options.bind_generates_resource_service = false; | 3309 init_options.bind_generates_resource_service = false; |
3302 EXPECT_FALSE(Initialize(init_options)); | 3310 EXPECT_FALSE(Initialize(init_options)); |
3303 } | 3311 } |
3304 | 3312 |
| 3313 TEST_F(GLES2ImplementationManualInitTest, FailInitOnTransferBufferFail) { |
| 3314 ContextInitOptions init_options; |
| 3315 init_options.transfer_buffer_initialize_fail = true; |
| 3316 EXPECT_FALSE(Initialize(init_options)); |
| 3317 } |
| 3318 |
3305 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" | 3319 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" |
3306 | 3320 |
3307 } // namespace gles2 | 3321 } // namespace gles2 |
3308 } // namespace gpu | 3322 } // namespace gpu |
OLD | NEW |