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/tests/gl_manager.h" | 5 #include "gpu/command_buffer/tests/gl_manager.h" |
6 | 6 |
7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
9 #include <GLES2/gl2extchromium.h> | 9 #include <GLES2/gl2extchromium.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 #include "ui/gl/init/gl_factory.h" | 48 #include "ui/gl/init/gl_factory.h" |
49 | 49 |
50 #if defined(OS_MACOSX) | 50 #if defined(OS_MACOSX) |
51 #include "ui/gfx/mac/io_surface.h" | 51 #include "ui/gfx/mac/io_surface.h" |
52 #include "ui/gl/gl_image_io_surface.h" | 52 #include "ui/gl/gl_image_io_surface.h" |
53 #endif | 53 #endif |
54 | 54 |
55 namespace gpu { | 55 namespace gpu { |
56 namespace { | 56 namespace { |
57 | 57 |
58 uint64_t g_next_command_buffer_id = 0; | 58 uint64_t g_next_command_buffer_id = 1; |
59 | 59 |
60 void InitializeGpuPreferencesForTestingFromCommandLine( | 60 void InitializeGpuPreferencesForTestingFromCommandLine( |
61 const base::CommandLine& command_line, | 61 const base::CommandLine& command_line, |
62 GpuPreferences* preferences) { | 62 GpuPreferences* preferences) { |
63 // Only initialize specific GpuPreferences members used for testing. | 63 // Only initialize specific GpuPreferences members used for testing. |
64 preferences->use_passthrough_cmd_decoder = | 64 preferences->use_passthrough_cmd_decoder = |
65 command_line.HasSwitch(switches::kUsePassthroughCmdDecoder); | 65 command_line.HasSwitch(switches::kUsePassthroughCmdDecoder); |
66 } | 66 } |
67 | 67 |
68 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { | 68 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 | 342 |
343 ASSERT_TRUE(context_->MakeCurrent(surface_.get())); | 343 ASSERT_TRUE(context_->MakeCurrent(surface_.get())); |
344 | 344 |
345 if (!decoder_->Initialize(surface_.get(), context_.get(), true, | 345 if (!decoder_->Initialize(surface_.get(), context_.get(), true, |
346 ::gpu::gles2::DisallowedFeatures(), attribs)) { | 346 ::gpu::gles2::DisallowedFeatures(), attribs)) { |
347 return; | 347 return; |
348 } | 348 } |
349 | 349 |
350 if (options.sync_point_manager) { | 350 if (options.sync_point_manager) { |
351 sync_point_manager_ = options.sync_point_manager; | 351 sync_point_manager_ = options.sync_point_manager; |
352 sync_point_order_data_ = SyncPointOrderData::Create(); | 352 sync_point_order_data_ = sync_point_manager_->CreateSyncPointOrderData(); |
353 sync_point_client_ = base::MakeUnique<SyncPointClient>( | 353 sync_point_client_state_ = sync_point_manager_->CreateSyncPointClientState( |
354 sync_point_manager_, sync_point_order_data_, GetNamespaceID(), | 354 GetNamespaceID(), GetCommandBufferID(), |
355 GetCommandBufferID()); | 355 sync_point_order_data_->sequence_id()); |
356 | 356 |
357 decoder_->SetFenceSyncReleaseCallback( | 357 decoder_->SetFenceSyncReleaseCallback( |
358 base::Bind(&GLManager::OnFenceSyncRelease, base::Unretained(this))); | 358 base::Bind(&GLManager::OnFenceSyncRelease, base::Unretained(this))); |
359 decoder_->SetWaitSyncTokenCallback( | 359 decoder_->SetWaitSyncTokenCallback( |
360 base::Bind(&GLManager::OnWaitSyncToken, base::Unretained(this))); | 360 base::Bind(&GLManager::OnWaitSyncToken, base::Unretained(this))); |
361 } else { | 361 } else { |
362 sync_point_manager_ = nullptr; | 362 sync_point_manager_ = nullptr; |
363 sync_point_order_data_ = nullptr; | 363 sync_point_order_data_ = nullptr; |
364 sync_point_client_ = nullptr; | 364 sync_point_client_state_ = nullptr; |
365 } | 365 } |
366 | 366 |
367 command_buffer_->SetPutOffsetChangeCallback( | 367 command_buffer_->SetPutOffsetChangeCallback( |
368 base::Bind(&GLManager::PumpCommands, base::Unretained(this))); | 368 base::Bind(&GLManager::PumpCommands, base::Unretained(this))); |
369 command_buffer_->SetGetBufferChangeCallback( | 369 command_buffer_->SetGetBufferChangeCallback( |
370 base::Bind(&GLManager::GetBufferChanged, base::Unretained(this))); | 370 base::Bind(&GLManager::GetBufferChanged, base::Unretained(this))); |
371 | 371 |
372 // Create the GLES2 helper, which writes the command buffer protocol. | 372 // Create the GLES2 helper, which writes the command buffer protocol. |
373 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); | 373 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); |
374 ASSERT_TRUE(gles2_helper_->Initialize(kCommandBufferSize)); | 374 ASSERT_TRUE(gles2_helper_->Initialize(kCommandBufferSize)); |
(...skipping 27 matching lines...) Expand all Loading... |
402 gl::init::CreateOffscreenGLSurface(size)); | 402 gl::init::CreateOffscreenGLSurface(size)); |
403 base_context_ = new scoped_refptr<gl::GLContext>(gl::init::CreateGLContext( | 403 base_context_ = new scoped_refptr<gl::GLContext>(gl::init::CreateGLContext( |
404 base_share_group_->get(), base_surface_->get(), | 404 base_share_group_->get(), base_surface_->get(), |
405 gl::GLContextAttribs())); | 405 gl::GLContextAttribs())); |
406 #endif | 406 #endif |
407 } | 407 } |
408 ++use_count_; | 408 ++use_count_; |
409 } | 409 } |
410 | 410 |
411 void GLManager::OnFenceSyncRelease(uint64_t release) { | 411 void GLManager::OnFenceSyncRelease(uint64_t release) { |
412 DCHECK(sync_point_client_); | 412 DCHECK(sync_point_client_state_); |
413 command_buffer_->SetReleaseCount(release); | 413 command_buffer_->SetReleaseCount(release); |
414 sync_point_client_->ReleaseFenceSync(release); | 414 sync_point_client_state_->ReleaseFenceSync(release); |
415 } | 415 } |
416 | 416 |
417 bool GLManager::OnWaitSyncToken(const SyncToken& sync_token) { | 417 bool GLManager::OnWaitSyncToken(const SyncToken& sync_token) { |
418 DCHECK(sync_point_manager_); | 418 DCHECK(sync_point_manager_); |
419 // GLManager does not support being multithreaded at this point, so the fence | 419 // GLManager does not support being multithreaded at this point, so the fence |
420 // sync must be released by the time wait is called. | 420 // sync must be released by the time wait is called. |
421 DCHECK(sync_point_manager_->IsSyncTokenReleased(sync_token)); | 421 DCHECK(sync_point_manager_->IsSyncTokenReleased(sync_token)); |
422 return false; | 422 return false; |
423 } | 423 } |
424 | 424 |
(...skipping 13 matching lines...) Expand all Loading... |
438 if (gles2_implementation_.get()) { | 438 if (gles2_implementation_.get()) { |
439 MakeCurrent(); | 439 MakeCurrent(); |
440 EXPECT_TRUE(glGetError() == GL_NONE); | 440 EXPECT_TRUE(glGetError() == GL_NONE); |
441 gles2_implementation_->Flush(); | 441 gles2_implementation_->Flush(); |
442 gles2_implementation_.reset(); | 442 gles2_implementation_.reset(); |
443 } | 443 } |
444 transfer_buffer_.reset(); | 444 transfer_buffer_.reset(); |
445 gles2_helper_.reset(); | 445 gles2_helper_.reset(); |
446 command_buffer_.reset(); | 446 command_buffer_.reset(); |
447 sync_point_manager_ = nullptr; | 447 sync_point_manager_ = nullptr; |
448 sync_point_client_ = nullptr; | |
449 if (sync_point_order_data_) { | 448 if (sync_point_order_data_) { |
450 sync_point_order_data_->Destroy(); | 449 sync_point_order_data_->Destroy(); |
451 sync_point_order_data_ = nullptr; | 450 sync_point_order_data_ = nullptr; |
452 } | 451 } |
| 452 if (sync_point_client_state_) { |
| 453 sync_point_client_state_->Destroy(); |
| 454 sync_point_client_state_ = nullptr; |
| 455 } |
453 if (decoder_.get()) { | 456 if (decoder_.get()) { |
454 bool have_context = decoder_->GetGLContext() && | 457 bool have_context = decoder_->GetGLContext() && |
455 decoder_->GetGLContext()->MakeCurrent(surface_.get()); | 458 decoder_->GetGLContext()->MakeCurrent(surface_.get()); |
456 decoder_->Destroy(have_context); | 459 decoder_->Destroy(have_context); |
457 decoder_.reset(); | 460 decoder_.reset(); |
458 } | 461 } |
459 } | 462 } |
460 | 463 |
461 const GpuDriverBugWorkarounds& GLManager::workarounds() const { | 464 const GpuDriverBugWorkarounds& GLManager::workarounds() const { |
462 return decoder_->GetContextGroup()->feature_info()->workarounds(); | 465 return decoder_->GetContextGroup()->feature_info()->workarounds(); |
463 } | 466 } |
464 | 467 |
465 void GLManager::PumpCommands() { | 468 void GLManager::PumpCommands() { |
466 if (!decoder_->MakeCurrent()) { | 469 if (!decoder_->MakeCurrent()) { |
467 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); | 470 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); |
468 command_buffer_->SetParseError(::gpu::error::kLostContext); | 471 command_buffer_->SetParseError(::gpu::error::kLostContext); |
469 return; | 472 return; |
470 } | 473 } |
471 uint32_t order_num = 0; | 474 uint32_t order_num = 0; |
472 if (sync_point_manager_) { | 475 if (sync_point_manager_) { |
473 // If sync point manager is supported, assign order numbers to commands. | 476 // If sync point manager is supported, assign order numbers to commands. |
474 if (paused_order_num_) { | 477 if (paused_order_num_) { |
475 // Was previous paused, continue to process the order number. | 478 // Was previous paused, continue to process the order number. |
476 order_num = paused_order_num_; | 479 order_num = paused_order_num_; |
477 paused_order_num_ = 0; | 480 paused_order_num_ = 0; |
478 } else { | 481 } else { |
479 order_num = sync_point_order_data_->GenerateUnprocessedOrderNumber( | 482 order_num = sync_point_order_data_->GenerateUnprocessedOrderNumber(); |
480 sync_point_manager_); | |
481 } | 483 } |
482 sync_point_order_data_->BeginProcessingOrderNumber(order_num); | 484 sync_point_order_data_->BeginProcessingOrderNumber(order_num); |
483 } | 485 } |
484 | 486 |
485 if (pause_commands_) { | 487 if (pause_commands_) { |
486 // Do not process commands, simply store the current order number. | 488 // Do not process commands, simply store the current order number. |
487 paused_order_num_ = order_num; | 489 paused_order_num_ = order_num; |
488 | 490 |
489 sync_point_order_data_->PauseProcessingOrderNumber(order_num); | 491 sync_point_order_data_->PauseProcessingOrderNumber(order_num); |
490 return; | 492 return; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 } | 605 } |
604 | 606 |
605 bool GLManager::IsFenceSyncReleased(uint64_t release) { | 607 bool GLManager::IsFenceSyncReleased(uint64_t release) { |
606 return release <= command_buffer_->GetLastState().release_count; | 608 return release <= command_buffer_->GetLastState().release_count; |
607 } | 609 } |
608 | 610 |
609 void GLManager::SignalSyncToken(const gpu::SyncToken& sync_token, | 611 void GLManager::SignalSyncToken(const gpu::SyncToken& sync_token, |
610 const base::Closure& callback) { | 612 const base::Closure& callback) { |
611 if (sync_point_manager_) { | 613 if (sync_point_manager_) { |
612 DCHECK(!paused_order_num_); | 614 DCHECK(!paused_order_num_); |
613 uint32_t order_num = sync_point_order_data_->GenerateUnprocessedOrderNumber( | 615 uint32_t order_num = |
614 sync_point_manager_); | 616 sync_point_order_data_->GenerateUnprocessedOrderNumber(); |
615 sync_point_order_data_->BeginProcessingOrderNumber(order_num); | 617 sync_point_order_data_->BeginProcessingOrderNumber(order_num); |
616 if (!sync_point_client_->Wait(sync_token, callback)) | 618 if (!sync_point_client_state_->Wait(sync_token, callback)) |
617 callback.Run(); | 619 callback.Run(); |
618 sync_point_order_data_->FinishProcessingOrderNumber(order_num); | 620 sync_point_order_data_->FinishProcessingOrderNumber(order_num); |
619 } else { | 621 } else { |
620 callback.Run(); | 622 callback.Run(); |
621 } | 623 } |
622 } | 624 } |
623 | 625 |
624 void GLManager::WaitSyncTokenHint(const gpu::SyncToken& sync_token) {} | 626 void GLManager::WaitSyncTokenHint(const gpu::SyncToken& sync_token) {} |
625 | 627 |
626 bool GLManager::CanWaitUnverifiedSyncToken(const gpu::SyncToken& sync_token) { | 628 bool GLManager::CanWaitUnverifiedSyncToken(const gpu::SyncToken& sync_token) { |
627 return false; | 629 return false; |
628 } | 630 } |
629 | 631 |
630 } // namespace gpu | 632 } // namespace gpu |
OLD | NEW |