| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/in_process_command_buffer.h" | 5 #include "gpu/command_buffer/service/in_process_command_buffer.h" |
| 6 | 6 |
| 7 #include <queue> | 7 #include <queue> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include <GLES2/gl2.h> | 10 #include <GLES2/gl2.h> |
| 11 #ifndef GL_GLEXT_PROTOTYPES | 11 #ifndef GL_GLEXT_PROTOTYPES |
| 12 #define GL_GLEXT_PROTOTYPES 1 | 12 #define GL_GLEXT_PROTOTYPES 1 |
| 13 #endif | 13 #endif |
| 14 #include <GLES2/gl2ext.h> | 14 #include <GLES2/gl2ext.h> |
| 15 #include <GLES2/gl2extchromium.h> | 15 #include <GLES2/gl2extchromium.h> |
| 16 | 16 |
| 17 #include "base/bind.h" | 17 #include "base/bind.h" |
| 18 #include "base/bind_helpers.h" | 18 #include "base/bind_helpers.h" |
| 19 #include "base/lazy_instance.h" | 19 #include "base/lazy_instance.h" |
| 20 #include "base/logging.h" | 20 #include "base/logging.h" |
| 21 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
| 22 #include "base/message_loop/message_loop_proxy.h" | 22 #include "base/message_loop/message_loop_proxy.h" |
| 23 #include "base/sequence_checker.h" | 23 #include "base/sequence_checker.h" |
| 24 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
| 25 #include "gpu/command_buffer/common/id_allocator.h" | |
| 26 #include "gpu/command_buffer/service/command_buffer_service.h" | 25 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 27 #include "gpu/command_buffer/service/context_group.h" | 26 #include "gpu/command_buffer/service/context_group.h" |
| 28 #include "gpu/command_buffer/service/gl_context_virtual.h" | 27 #include "gpu/command_buffer/service/gl_context_virtual.h" |
| 28 #include "gpu/command_buffer/service/gpu_control_service.h" |
| 29 #include "gpu/command_buffer/service/gpu_scheduler.h" | 29 #include "gpu/command_buffer/service/gpu_scheduler.h" |
| 30 #include "gpu/command_buffer/service/image_manager.h" | 30 #include "gpu/command_buffer/service/image_manager.h" |
| 31 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 31 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
| 32 #include "ui/gfx/size.h" | 32 #include "ui/gfx/size.h" |
| 33 #include "ui/gl/gl_context.h" | 33 #include "ui/gl/gl_context.h" |
| 34 #include "ui/gl/gl_image.h" | 34 #include "ui/gl/gl_image.h" |
| 35 #include "ui/gl/gl_share_group.h" | 35 #include "ui/gl/gl_share_group.h" |
| 36 | 36 |
| 37 namespace gpu { | 37 namespace gpu { |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 static base::LazyInstance<std::set<InProcessCommandBuffer*> > | 41 static base::LazyInstance<std::set<InProcessCommandBuffer*> > |
| 42 g_all_shared_contexts = LAZY_INSTANCE_INITIALIZER; | 42 g_all_shared_contexts = LAZY_INSTANCE_INITIALIZER; |
| 43 | 43 |
| 44 static bool g_use_virtualized_gl_context = false; | 44 static bool g_use_virtualized_gl_context = false; |
| 45 static bool g_uses_explicit_scheduling = false; | 45 static bool g_uses_explicit_scheduling = false; |
| 46 static GpuMemoryBufferFactory* g_gpu_memory_buffer_factory = NULL; |
| 46 | 47 |
| 47 template <typename T> | 48 template <typename T> |
| 48 static void RunTaskWithResult(base::Callback<T(void)> task, | 49 static void RunTaskWithResult(base::Callback<T(void)> task, |
| 49 T* result, | 50 T* result, |
| 50 base::WaitableEvent* completion) { | 51 base::WaitableEvent* completion) { |
| 51 *result = task.Run(); | 52 *result = task.Run(); |
| 52 completion->Signal(); | 53 completion->Signal(); |
| 53 } | 54 } |
| 54 | 55 |
| 55 class GpuInProcessThread | 56 class GpuInProcessThread |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 context_group ? context_group->decoder_->GetContextGroup() | 384 context_group ? context_group->decoder_->GetContextGroup() |
| 384 : new gles2::ContextGroup( | 385 : new gles2::ContextGroup( |
| 385 NULL, NULL, NULL, NULL, bind_generates_resource))); | 386 NULL, NULL, NULL, NULL, bind_generates_resource))); |
| 386 | 387 |
| 387 gpu_scheduler_.reset( | 388 gpu_scheduler_.reset( |
| 388 new GpuScheduler(command_buffer.get(), decoder_.get(), decoder_.get())); | 389 new GpuScheduler(command_buffer.get(), decoder_.get(), decoder_.get())); |
| 389 command_buffer->SetGetBufferChangeCallback(base::Bind( | 390 command_buffer->SetGetBufferChangeCallback(base::Bind( |
| 390 &GpuScheduler::SetGetBuffer, base::Unretained(gpu_scheduler_.get()))); | 391 &GpuScheduler::SetGetBuffer, base::Unretained(gpu_scheduler_.get()))); |
| 391 command_buffer_ = command_buffer.Pass(); | 392 command_buffer_ = command_buffer.Pass(); |
| 392 | 393 |
| 394 gpu_control_.reset( |
| 395 new GpuControlService(decoder_->GetContextGroup()->image_manager(), |
| 396 g_gpu_memory_buffer_factory)); |
| 397 |
| 393 decoder_->set_engine(gpu_scheduler_.get()); | 398 decoder_->set_engine(gpu_scheduler_.get()); |
| 394 | 399 |
| 395 if (!surface_) { | 400 if (!surface_) { |
| 396 if (is_offscreen) | 401 if (is_offscreen) |
| 397 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(size); | 402 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(size); |
| 398 else | 403 else |
| 399 surface_ = gfx::GLSurface::CreateViewGLSurface(window); | 404 surface_ = gfx::GLSurface::CreateViewGLSurface(window); |
| 400 } | 405 } |
| 401 | 406 |
| 402 if (!surface_.get()) { | 407 if (!surface_.get()) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 | 494 |
| 490 g_all_shared_contexts.Pointer()->erase(this); | 495 g_all_shared_contexts.Pointer()->erase(this); |
| 491 return true; | 496 return true; |
| 492 } | 497 } |
| 493 | 498 |
| 494 void InProcessCommandBuffer::CheckSequencedThread() { | 499 void InProcessCommandBuffer::CheckSequencedThread() { |
| 495 DCHECK(!sequence_checker_ || | 500 DCHECK(!sequence_checker_ || |
| 496 sequence_checker_->CalledOnValidSequencedThread()); | 501 sequence_checker_->CalledOnValidSequencedThread()); |
| 497 } | 502 } |
| 498 | 503 |
| 499 unsigned int InProcessCommandBuffer::CreateImageForGpuMemoryBuffer( | |
| 500 gfx::GpuMemoryBufferHandle buffer, | |
| 501 gfx::Size size) { | |
| 502 CheckSequencedThread(); | |
| 503 unsigned int image_id; | |
| 504 { | |
| 505 // TODO: ID allocation should go through CommandBuffer | |
| 506 base::AutoLock lock(command_buffer_lock_); | |
| 507 gles2::ContextGroup* group = decoder_->GetContextGroup(); | |
| 508 image_id = | |
| 509 group->GetIdAllocator(gles2::id_namespaces::kImages)->AllocateID(); | |
| 510 } | |
| 511 base::Closure image_task = | |
| 512 base::Bind(&InProcessCommandBuffer::CreateImageOnGpuThread, | |
| 513 base::Unretained(this), buffer, size, image_id); | |
| 514 QueueTask(image_task); | |
| 515 return image_id; | |
| 516 } | |
| 517 | |
| 518 void InProcessCommandBuffer::CreateImageOnGpuThread( | |
| 519 gfx::GpuMemoryBufferHandle buffer, | |
| 520 gfx::Size size, | |
| 521 unsigned int image_id) { | |
| 522 CheckSequencedThread(); | |
| 523 scoped_refptr<gfx::GLImage> gl_image = | |
| 524 gfx::GLImage::CreateGLImageForGpuMemoryBuffer(buffer, size); | |
| 525 decoder_->GetContextGroup()->image_manager()->AddImage(gl_image, image_id); | |
| 526 } | |
| 527 | |
| 528 void InProcessCommandBuffer::RemoveImage(unsigned int image_id) { | |
| 529 CheckSequencedThread(); | |
| 530 { | |
| 531 // TODO: ID allocation should go through CommandBuffer | |
| 532 base::AutoLock lock(command_buffer_lock_); | |
| 533 gles2::ContextGroup* group = decoder_->GetContextGroup(); | |
| 534 group->GetIdAllocator(gles2::id_namespaces::kImages)->FreeID(image_id); | |
| 535 } | |
| 536 base::Closure image_manager_task = | |
| 537 base::Bind(&InProcessCommandBuffer::RemoveImageOnGpuThread, | |
| 538 base::Unretained(this), | |
| 539 image_id); | |
| 540 QueueTask(image_manager_task); | |
| 541 } | |
| 542 | |
| 543 void InProcessCommandBuffer::RemoveImageOnGpuThread(unsigned int image_id) { | |
| 544 CheckSequencedThread(); | |
| 545 decoder_->GetContextGroup()->image_manager()->RemoveImage(image_id); | |
| 546 } | |
| 547 | |
| 548 void InProcessCommandBuffer::OnContextLost() { | 504 void InProcessCommandBuffer::OnContextLost() { |
| 549 CheckSequencedThread(); | 505 CheckSequencedThread(); |
| 550 if (!context_lost_callback_.is_null()) { | 506 if (!context_lost_callback_.is_null()) { |
| 551 context_lost_callback_.Run(); | 507 context_lost_callback_.Run(); |
| 552 context_lost_callback_.Reset(); | 508 context_lost_callback_.Reset(); |
| 553 } | 509 } |
| 554 | 510 |
| 555 context_lost_ = true; | 511 context_lost_ = true; |
| 556 if (share_resources_) { | 512 if (share_resources_) { |
| 557 for (std::set<InProcessCommandBuffer*>::iterator it = | 513 for (std::set<InProcessCommandBuffer*>::iterator it = |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 uint32 InProcessCommandBuffer::InsertSyncPoint() { | 629 uint32 InProcessCommandBuffer::InsertSyncPoint() { |
| 674 NOTREACHED(); | 630 NOTREACHED(); |
| 675 return 0; | 631 return 0; |
| 676 } | 632 } |
| 677 void InProcessCommandBuffer::SignalSyncPoint(unsigned sync_point, | 633 void InProcessCommandBuffer::SignalSyncPoint(unsigned sync_point, |
| 678 const base::Closure& callback) { | 634 const base::Closure& callback) { |
| 679 CheckSequencedThread(); | 635 CheckSequencedThread(); |
| 680 QueueTask(WrapCallback(callback)); | 636 QueueTask(WrapCallback(callback)); |
| 681 } | 637 } |
| 682 | 638 |
| 639 gfx::GpuMemoryBuffer* InProcessCommandBuffer::CreateGpuMemoryBuffer( |
| 640 size_t width, |
| 641 size_t height, |
| 642 unsigned internalformat, |
| 643 int32* id) { |
| 644 CheckSequencedThread(); |
| 645 base::AutoLock lock(command_buffer_lock_); |
| 646 return gpu_control_->CreateGpuMemoryBuffer(width, |
| 647 height, |
| 648 internalformat, |
| 649 id); |
| 650 } |
| 651 |
| 652 void InProcessCommandBuffer::DestroyGpuMemoryBuffer(int32 id) { |
| 653 CheckSequencedThread(); |
| 654 base::Closure task = base::Bind(&GpuControl::DestroyGpuMemoryBuffer, |
| 655 base::Unretained(gpu_control_.get()), |
| 656 id); |
| 657 |
| 658 QueueTask(task); |
| 659 } |
| 660 |
| 683 gpu::error::Error InProcessCommandBuffer::GetLastError() { | 661 gpu::error::Error InProcessCommandBuffer::GetLastError() { |
| 684 CheckSequencedThread(); | 662 CheckSequencedThread(); |
| 685 return last_state_.error; | 663 return last_state_.error; |
| 686 } | 664 } |
| 687 | 665 |
| 688 bool InProcessCommandBuffer::Initialize() { | 666 bool InProcessCommandBuffer::Initialize() { |
| 689 NOTREACHED(); | 667 NOTREACHED(); |
| 690 return false; | 668 return false; |
| 691 } | 669 } |
| 692 | 670 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 DCHECK(!SchedulerClientBase::HasClients()); | 724 DCHECK(!SchedulerClientBase::HasClients()); |
| 747 g_uses_explicit_scheduling = true; | 725 g_uses_explicit_scheduling = true; |
| 748 g_gpu_queue.Get().SetScheduleCallback(callback); | 726 g_gpu_queue.Get().SetScheduleCallback(callback); |
| 749 } | 727 } |
| 750 | 728 |
| 751 // static | 729 // static |
| 752 void InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread() { | 730 void InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread() { |
| 753 g_gpu_queue.Get().RunTasks(); | 731 g_gpu_queue.Get().RunTasks(); |
| 754 } | 732 } |
| 755 | 733 |
| 734 // static |
| 735 void InProcessCommandBuffer::SetGpuMemoryBufferFactory( |
| 736 GpuMemoryBufferFactory* factory) { |
| 737 g_gpu_memory_buffer_factory = factory; |
| 738 } |
| 739 |
| 756 } // namespace gpu | 740 } // namespace gpu |
| OLD | NEW |