| 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 <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include <GLES2/gl2.h> | 11 #include <GLES2/gl2.h> |
| 12 #ifndef GL_GLEXT_PROTOTYPES | 12 #ifndef GL_GLEXT_PROTOTYPES |
| 13 #define GL_GLEXT_PROTOTYPES 1 | 13 #define GL_GLEXT_PROTOTYPES 1 |
| 14 #endif | 14 #endif |
| 15 #include <GLES2/gl2ext.h> | 15 #include <GLES2/gl2ext.h> |
| 16 #include <GLES2/gl2extchromium.h> | 16 #include <GLES2/gl2extchromium.h> |
| 17 | 17 |
| 18 #include "base/bind.h" | 18 #include "base/bind.h" |
| 19 #include "base/bind_helpers.h" | 19 #include "base/bind_helpers.h" |
| 20 #include "base/lazy_instance.h" | 20 #include "base/lazy_instance.h" |
| 21 #include "base/logging.h" | 21 #include "base/logging.h" |
| 22 #include "base/memory/weak_ptr.h" | 22 #include "base/memory/weak_ptr.h" |
| 23 #include "base/message_loop/message_loop_proxy.h" | 23 #include "base/message_loop/message_loop_proxy.h" |
| 24 #include "base/sequence_checker.h" | 24 #include "base/sequence_checker.h" |
| 25 #include "base/synchronization/condition_variable.h" | 25 #include "base/synchronization/condition_variable.h" |
| 26 #include "base/threading/thread.h" | 26 #include "base/threading/thread.h" |
| 27 #include "gpu/command_buffer/client/gpu_memory_buffer_factory.h" |
| 27 #include "gpu/command_buffer/service/command_buffer_service.h" | 28 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 28 #include "gpu/command_buffer/service/context_group.h" | 29 #include "gpu/command_buffer/service/context_group.h" |
| 29 #include "gpu/command_buffer/service/gl_context_virtual.h" | 30 #include "gpu/command_buffer/service/gl_context_virtual.h" |
| 30 #include "gpu/command_buffer/service/gpu_control_service.h" | 31 #include "gpu/command_buffer/service/gpu_control_service.h" |
| 31 #include "gpu/command_buffer/service/gpu_scheduler.h" | 32 #include "gpu/command_buffer/service/gpu_scheduler.h" |
| 32 #include "gpu/command_buffer/service/image_manager.h" | 33 #include "gpu/command_buffer/service/image_manager.h" |
| 33 #include "gpu/command_buffer/service/mailbox_manager.h" | 34 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 34 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 35 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
| 35 #include "ui/gfx/size.h" | 36 #include "ui/gfx/size.h" |
| 36 #include "ui/gl/gl_context.h" | 37 #include "ui/gl/gl_context.h" |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 base::Bind(&InProcessCommandBuffer::InitializeOnGpuThread, | 290 base::Bind(&InProcessCommandBuffer::InitializeOnGpuThread, |
| 290 base::Unretained(this), | 291 base::Unretained(this), |
| 291 params); | 292 params); |
| 292 | 293 |
| 293 base::WaitableEvent completion(true, false); | 294 base::WaitableEvent completion(true, false); |
| 294 bool result = false; | 295 bool result = false; |
| 295 QueueTask( | 296 QueueTask( |
| 296 base::Bind(&RunTaskWithResult<bool>, init_task, &result, &completion)); | 297 base::Bind(&RunTaskWithResult<bool>, init_task, &result, &completion)); |
| 297 completion.Wait(); | 298 completion.Wait(); |
| 298 | 299 |
| 299 if (result) | 300 if (result) { |
| 300 capabilities_ = capabilities; | 301 capabilities_ = capabilities; |
| 302 capabilities_.map_image = |
| 303 capabilities_.map_image && g_gpu_memory_buffer_factory; |
| 304 } |
| 301 return result; | 305 return result; |
| 302 } | 306 } |
| 303 | 307 |
| 304 bool InProcessCommandBuffer::InitializeOnGpuThread( | 308 bool InProcessCommandBuffer::InitializeOnGpuThread( |
| 305 const InitializeOnGpuThreadParams& params) { | 309 const InitializeOnGpuThreadParams& params) { |
| 306 CheckSequencedThread(); | 310 CheckSequencedThread(); |
| 307 gpu_thread_weak_ptr_ = gpu_thread_weak_ptr_factory_.GetWeakPtr(); | 311 gpu_thread_weak_ptr_ = gpu_thread_weak_ptr_factory_.GetWeakPtr(); |
| 308 | 312 |
| 309 DCHECK(params.size.width() >= 0 && params.size.height() >= 0); | 313 DCHECK(params.size.width() >= 0 && params.size.height() >= 0); |
| 310 | 314 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 if (!decoder_->Initialize(surface_, | 406 if (!decoder_->Initialize(surface_, |
| 403 context_, | 407 context_, |
| 404 params.is_offscreen, | 408 params.is_offscreen, |
| 405 params.size, | 409 params.size, |
| 406 disallowed_features, | 410 disallowed_features, |
| 407 params.attribs)) { | 411 params.attribs)) { |
| 408 LOG(ERROR) << "Could not initialize decoder."; | 412 LOG(ERROR) << "Could not initialize decoder."; |
| 409 DestroyOnGpuThread(); | 413 DestroyOnGpuThread(); |
| 410 return false; | 414 return false; |
| 411 } | 415 } |
| 416 *params.capabilities = decoder_->GetCapabilities(); |
| 412 | 417 |
| 413 gpu_control_.reset( | 418 gpu_control_.reset( |
| 414 new GpuControlService(decoder_->GetContextGroup()->image_manager(), | 419 new GpuControlService(decoder_->GetContextGroup()->image_manager(), |
| 415 g_gpu_memory_buffer_factory, | 420 decoder_->GetQueryManager())); |
| 416 decoder_->GetContextGroup()->mailbox_manager(), | |
| 417 decoder_->GetQueryManager(), | |
| 418 decoder_->GetCapabilities())); | |
| 419 | |
| 420 *params.capabilities = gpu_control_->GetCapabilities(); | |
| 421 | 421 |
| 422 if (!params.is_offscreen) { | 422 if (!params.is_offscreen) { |
| 423 decoder_->SetResizeCallback(base::Bind( | 423 decoder_->SetResizeCallback(base::Bind( |
| 424 &InProcessCommandBuffer::OnResizeView, gpu_thread_weak_ptr_)); | 424 &InProcessCommandBuffer::OnResizeView, gpu_thread_weak_ptr_)); |
| 425 } | 425 } |
| 426 decoder_->SetWaitSyncPointCallback(base::Bind(&WaitSyncPoint)); | 426 decoder_->SetWaitSyncPointCallback(base::Bind(&WaitSyncPoint)); |
| 427 | 427 |
| 428 return true; | 428 return true; |
| 429 } | 429 } |
| 430 | 430 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 gpu::Capabilities InProcessCommandBuffer::GetCapabilities() { | 602 gpu::Capabilities InProcessCommandBuffer::GetCapabilities() { |
| 603 return capabilities_; | 603 return capabilities_; |
| 604 } | 604 } |
| 605 | 605 |
| 606 gfx::GpuMemoryBuffer* InProcessCommandBuffer::CreateGpuMemoryBuffer( | 606 gfx::GpuMemoryBuffer* InProcessCommandBuffer::CreateGpuMemoryBuffer( |
| 607 size_t width, | 607 size_t width, |
| 608 size_t height, | 608 size_t height, |
| 609 unsigned internalformat, | 609 unsigned internalformat, |
| 610 int32* id) { | 610 int32* id) { |
| 611 CheckSequencedThread(); | 611 CheckSequencedThread(); |
| 612 base::AutoLock lock(command_buffer_lock_); | 612 |
| 613 return gpu_control_->CreateGpuMemoryBuffer(width, | 613 *id = -1; |
| 614 height, | 614 linked_ptr<gfx::GpuMemoryBuffer> buffer = |
| 615 internalformat, | 615 make_linked_ptr(g_gpu_memory_buffer_factory->CreateGpuMemoryBuffer( |
| 616 id); | 616 width, height, internalformat)); |
| 617 if (!buffer.get()) |
| 618 return NULL; |
| 619 |
| 620 static int32 next_id = 1; |
| 621 *id = next_id++; |
| 622 |
| 623 base::Closure task = base::Bind(&GpuControlService::RegisterGpuMemoryBuffer, |
| 624 base::Unretained(gpu_control_.get()), |
| 625 *id, |
| 626 buffer->GetHandle(), |
| 627 width, |
| 628 height, |
| 629 internalformat); |
| 630 |
| 631 QueueTask(task); |
| 632 |
| 633 gpu_memory_buffers_[*id] = buffer; |
| 634 return buffer.get(); |
| 617 } | 635 } |
| 618 | 636 |
| 619 void InProcessCommandBuffer::DestroyGpuMemoryBuffer(int32 id) { | 637 void InProcessCommandBuffer::DestroyGpuMemoryBuffer(int32 id) { |
| 620 CheckSequencedThread(); | 638 CheckSequencedThread(); |
| 621 base::Closure task = base::Bind(&GpuControl::DestroyGpuMemoryBuffer, | 639 GpuMemoryBufferMap::iterator it = gpu_memory_buffers_.find(id); |
| 640 if (it != gpu_memory_buffers_.end()) |
| 641 gpu_memory_buffers_.erase(it); |
| 642 base::Closure task = base::Bind(&GpuControlService::UnregisterGpuMemoryBuffer, |
| 622 base::Unretained(gpu_control_.get()), | 643 base::Unretained(gpu_control_.get()), |
| 623 id); | 644 id); |
| 624 | 645 |
| 625 QueueTask(task); | 646 QueueTask(task); |
| 626 } | 647 } |
| 627 | 648 |
| 628 uint32 InProcessCommandBuffer::InsertSyncPoint() { | 649 uint32 InProcessCommandBuffer::InsertSyncPoint() { |
| 629 uint32 sync_point = g_sync_point_manager.Get().GenerateSyncPoint(); | 650 uint32 sync_point = g_sync_point_manager.Get().GenerateSyncPoint(); |
| 630 QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread, | 651 QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread, |
| 631 base::Unretained(this), | 652 base::Unretained(this), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 660 base::Bind(&InProcessCommandBuffer::SignalSyncPointOnGpuThread, | 681 base::Bind(&InProcessCommandBuffer::SignalSyncPointOnGpuThread, |
| 661 gpu_thread_weak_ptr_, | 682 gpu_thread_weak_ptr_, |
| 662 sync_point, | 683 sync_point, |
| 663 callback)); | 684 callback)); |
| 664 } | 685 } |
| 665 } | 686 } |
| 666 | 687 |
| 667 void InProcessCommandBuffer::SignalQuery(unsigned query, | 688 void InProcessCommandBuffer::SignalQuery(unsigned query, |
| 668 const base::Closure& callback) { | 689 const base::Closure& callback) { |
| 669 CheckSequencedThread(); | 690 CheckSequencedThread(); |
| 670 QueueTask(base::Bind(&GpuControl::SignalQuery, | 691 QueueTask(base::Bind(&GpuControlService::SignalQuery, |
| 671 base::Unretained(gpu_control_.get()), | 692 base::Unretained(gpu_control_.get()), |
| 672 query, | 693 query, |
| 673 WrapCallback(callback))); | 694 WrapCallback(callback))); |
| 674 } | 695 } |
| 675 | 696 |
| 676 void InProcessCommandBuffer::SetSurfaceVisible(bool visible) {} | 697 void InProcessCommandBuffer::SetSurfaceVisible(bool visible) {} |
| 677 | 698 |
| 678 void InProcessCommandBuffer::SendManagedMemoryStats( | 699 void InProcessCommandBuffer::SendManagedMemoryStats( |
| 679 const gpu::ManagedMemoryStats& stats) { | 700 const gpu::ManagedMemoryStats& stats) { |
| 680 } | 701 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 } | 776 } |
| 756 #endif | 777 #endif |
| 757 | 778 |
| 758 // static | 779 // static |
| 759 void InProcessCommandBuffer::SetGpuMemoryBufferFactory( | 780 void InProcessCommandBuffer::SetGpuMemoryBufferFactory( |
| 760 GpuMemoryBufferFactory* factory) { | 781 GpuMemoryBufferFactory* factory) { |
| 761 g_gpu_memory_buffer_factory = factory; | 782 g_gpu_memory_buffer_factory = factory; |
| 762 } | 783 } |
| 763 | 784 |
| 764 } // namespace gpu | 785 } // namespace gpu |
| OLD | NEW |