Chromium Code Reviews| 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_manager.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_scheduler.h" | 31 #include "gpu/command_buffer/service/gpu_scheduler.h" |
| 32 #include "gpu/command_buffer/service/image_factory.h" | |
| 31 #include "gpu/command_buffer/service/image_manager.h" | 33 #include "gpu/command_buffer/service/image_manager.h" |
| 32 #include "gpu/command_buffer/service/mailbox_manager.h" | 34 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 33 #include "gpu/command_buffer/service/memory_tracking.h" | 35 #include "gpu/command_buffer/service/memory_tracking.h" |
| 34 #include "gpu/command_buffer/service/query_manager.h" | 36 #include "gpu/command_buffer/service/query_manager.h" |
| 35 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 37 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
| 36 #include "ui/gfx/size.h" | 38 #include "ui/gfx/size.h" |
| 37 #include "ui/gl/gl_context.h" | 39 #include "ui/gl/gl_context.h" |
| 38 #include "ui/gl/gl_image.h" | 40 #include "ui/gl/gl_image.h" |
| 39 #include "ui/gl/gl_share_group.h" | 41 #include "ui/gl/gl_share_group.h" |
| 40 | 42 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 } else { | 208 } else { |
| 207 service = new GpuInProcessThread; | 209 service = new GpuInProcessThread; |
| 208 } | 210 } |
| 209 return service; | 211 return service; |
| 210 } | 212 } |
| 211 | 213 |
| 212 InProcessCommandBuffer::InProcessCommandBuffer( | 214 InProcessCommandBuffer::InProcessCommandBuffer( |
| 213 const scoped_refptr<Service>& service) | 215 const scoped_refptr<Service>& service) |
| 214 : context_lost_(false), | 216 : context_lost_(false), |
| 215 idle_work_pending_(false), | 217 idle_work_pending_(false), |
| 218 image_factory_(nullptr), | |
| 216 last_put_offset_(-1), | 219 last_put_offset_(-1), |
| 220 gpu_memory_buffer_manager_(nullptr), | |
| 217 flush_event_(false, false), | 221 flush_event_(false, false), |
| 218 service_(service.get() ? service : GetDefaultService()), | 222 service_(service.get() ? service : GetDefaultService()), |
| 219 gpu_thread_weak_ptr_factory_(this) { | 223 gpu_thread_weak_ptr_factory_(this) { |
| 220 if (!service.get()) { | 224 if (!service.get()) { |
| 221 base::AutoLock lock(default_thread_clients_lock_.Get()); | 225 base::AutoLock lock(default_thread_clients_lock_.Get()); |
| 222 default_thread_clients_.Get().insert(this); | 226 default_thread_clients_.Get().insert(this); |
| 223 } | 227 } |
| 224 } | 228 } |
| 225 | 229 |
| 226 InProcessCommandBuffer::~InProcessCommandBuffer() { | 230 InProcessCommandBuffer::~InProcessCommandBuffer() { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 } | 269 } |
| 266 | 270 |
| 267 bool InProcessCommandBuffer::Initialize( | 271 bool InProcessCommandBuffer::Initialize( |
| 268 scoped_refptr<gfx::GLSurface> surface, | 272 scoped_refptr<gfx::GLSurface> surface, |
| 269 bool is_offscreen, | 273 bool is_offscreen, |
| 270 gfx::AcceleratedWidget window, | 274 gfx::AcceleratedWidget window, |
| 271 const gfx::Size& size, | 275 const gfx::Size& size, |
| 272 const std::vector<int32>& attribs, | 276 const std::vector<int32>& attribs, |
| 273 gfx::GpuPreference gpu_preference, | 277 gfx::GpuPreference gpu_preference, |
| 274 const base::Closure& context_lost_callback, | 278 const base::Closure& context_lost_callback, |
| 275 InProcessCommandBuffer* share_group) { | 279 InProcessCommandBuffer* share_group, |
| 280 GpuMemoryBufferManager* gpu_memory_buffer_manager, | |
| 281 ImageFactory* image_factory) { | |
|
no sievers
2014/10/17 21:16:50
DCHECK(!gpu_memory_buffer_manager || image_factory
reveman
2014/10/17 22:36:17
What if an image factory instance is provided by n
| |
| 276 DCHECK(!share_group || service_.get() == share_group->service_.get()); | 282 DCHECK(!share_group || service_.get() == share_group->service_.get()); |
| 277 context_lost_callback_ = WrapCallback(context_lost_callback); | 283 context_lost_callback_ = WrapCallback(context_lost_callback); |
| 278 | 284 |
| 279 if (surface.get()) { | 285 if (surface.get()) { |
| 280 // GPU thread must be the same as client thread due to GLSurface not being | 286 // GPU thread must be the same as client thread due to GLSurface not being |
| 281 // thread safe. | 287 // thread safe. |
| 282 sequence_checker_.reset(new base::SequenceChecker); | 288 sequence_checker_.reset(new base::SequenceChecker); |
| 283 surface_ = surface; | 289 surface_ = surface; |
| 284 } | 290 } |
| 285 | 291 |
| 286 gpu::Capabilities capabilities; | 292 gpu::Capabilities capabilities; |
| 287 InitializeOnGpuThreadParams params(is_offscreen, | 293 InitializeOnGpuThreadParams params(is_offscreen, |
| 288 window, | 294 window, |
| 289 size, | 295 size, |
| 290 attribs, | 296 attribs, |
| 291 gpu_preference, | 297 gpu_preference, |
| 292 &capabilities, | 298 &capabilities, |
| 293 share_group); | 299 share_group, |
| 300 image_factory); | |
| 294 | 301 |
| 295 base::Callback<bool(void)> init_task = | 302 base::Callback<bool(void)> init_task = |
| 296 base::Bind(&InProcessCommandBuffer::InitializeOnGpuThread, | 303 base::Bind(&InProcessCommandBuffer::InitializeOnGpuThread, |
| 297 base::Unretained(this), | 304 base::Unretained(this), |
| 298 params); | 305 params); |
| 299 | 306 |
| 300 base::WaitableEvent completion(true, false); | 307 base::WaitableEvent completion(true, false); |
| 301 bool result = false; | 308 bool result = false; |
| 302 QueueTask( | 309 QueueTask( |
| 303 base::Bind(&RunTaskWithResult<bool>, init_task, &result, &completion)); | 310 base::Bind(&RunTaskWithResult<bool>, init_task, &result, &completion)); |
| 304 completion.Wait(); | 311 completion.Wait(); |
| 305 | 312 |
| 306 if (result) | 313 gpu_memory_buffer_manager_ = gpu_memory_buffer_manager; |
| 314 | |
| 315 if (result) { | |
| 307 capabilities_ = capabilities; | 316 capabilities_ = capabilities; |
| 317 capabilities_.image = capabilities_.image && gpu_memory_buffer_manager_; | |
| 318 } | |
| 308 | 319 |
| 309 return result; | 320 return result; |
| 310 } | 321 } |
| 311 | 322 |
| 312 bool InProcessCommandBuffer::InitializeOnGpuThread( | 323 bool InProcessCommandBuffer::InitializeOnGpuThread( |
| 313 const InitializeOnGpuThreadParams& params) { | 324 const InitializeOnGpuThreadParams& params) { |
| 314 CheckSequencedThread(); | 325 CheckSequencedThread(); |
| 315 gpu_thread_weak_ptr_ = gpu_thread_weak_ptr_factory_.GetWeakPtr(); | 326 gpu_thread_weak_ptr_ = gpu_thread_weak_ptr_factory_.GetWeakPtr(); |
| 316 | 327 |
| 317 DCHECK(params.size.width() >= 0 && params.size.height() >= 0); | 328 DCHECK(params.size.width() >= 0 && params.size.height() >= 0); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 return false; | 428 return false; |
| 418 } | 429 } |
| 419 *params.capabilities = decoder_->GetCapabilities(); | 430 *params.capabilities = decoder_->GetCapabilities(); |
| 420 | 431 |
| 421 if (!params.is_offscreen) { | 432 if (!params.is_offscreen) { |
| 422 decoder_->SetResizeCallback(base::Bind( | 433 decoder_->SetResizeCallback(base::Bind( |
| 423 &InProcessCommandBuffer::OnResizeView, gpu_thread_weak_ptr_)); | 434 &InProcessCommandBuffer::OnResizeView, gpu_thread_weak_ptr_)); |
| 424 } | 435 } |
| 425 decoder_->SetWaitSyncPointCallback(base::Bind(&WaitSyncPoint)); | 436 decoder_->SetWaitSyncPointCallback(base::Bind(&WaitSyncPoint)); |
| 426 | 437 |
| 438 image_factory_ = params.image_factory; | |
| 439 params.capabilities->image = params.capabilities->image && image_factory_; | |
|
no sievers
2014/10/17 21:16:50
isn't params.capabilities uninitialized?
reveman
2014/10/17 22:36:17
we set it above with a call to decoder_->GetCapabi
| |
| 440 | |
| 427 return true; | 441 return true; |
| 428 } | 442 } |
| 429 | 443 |
| 430 void InProcessCommandBuffer::Destroy() { | 444 void InProcessCommandBuffer::Destroy() { |
| 431 CheckSequencedThread(); | 445 CheckSequencedThread(); |
| 432 | 446 |
| 433 base::WaitableEvent completion(true, false); | 447 base::WaitableEvent completion(true, false); |
| 434 bool result = false; | 448 bool result = false; |
| 435 base::Callback<bool(void)> destroy_task = base::Bind( | 449 base::Callback<bool(void)> destroy_task = base::Bind( |
| 436 &InProcessCommandBuffer::DestroyOnGpuThread, base::Unretained(this)); | 450 &InProcessCommandBuffer::DestroyOnGpuThread, base::Unretained(this)); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 606 } | 620 } |
| 607 | 621 |
| 608 gpu::Capabilities InProcessCommandBuffer::GetCapabilities() { | 622 gpu::Capabilities InProcessCommandBuffer::GetCapabilities() { |
| 609 return capabilities_; | 623 return capabilities_; |
| 610 } | 624 } |
| 611 | 625 |
| 612 int32 InProcessCommandBuffer::CreateImage(ClientBuffer buffer, | 626 int32 InProcessCommandBuffer::CreateImage(ClientBuffer buffer, |
| 613 size_t width, | 627 size_t width, |
| 614 size_t height, | 628 size_t height, |
| 615 unsigned internalformat) { | 629 unsigned internalformat) { |
| 616 NOTREACHED(); | 630 CheckSequencedThread(); |
| 617 return -1; | 631 |
| 632 gfx::Size size(width, height); | |
| 633 | |
| 634 DCHECK(gpu_memory_buffer_manager_); | |
| 635 gfx::GpuMemoryBuffer* gpu_memory_buffer = | |
| 636 gpu_memory_buffer_manager_->GpuMemoryBufferFromClientBuffer(buffer); | |
| 637 DCHECK(gpu_memory_buffer); | |
| 638 | |
| 639 int32 new_id = next_image_id_.GetNext(); | |
| 640 | |
| 641 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( | |
| 642 internalformat, gpu_memory_buffer->GetFormat())); | |
| 643 QueueTask(base::Bind(&InProcessCommandBuffer::CreateImageOnGpuThread, | |
| 644 base::Unretained(this), | |
| 645 new_id, | |
| 646 gpu_memory_buffer->GetHandle(), | |
| 647 size, | |
| 648 gpu_memory_buffer->GetFormat(), | |
| 649 internalformat)); | |
| 650 return new_id; | |
| 651 } | |
| 652 | |
| 653 void InProcessCommandBuffer::CreateImageOnGpuThread( | |
| 654 int32 id, | |
| 655 const gfx::GpuMemoryBufferHandle& handle, | |
| 656 const gfx::Size& size, | |
| 657 gfx::GpuMemoryBuffer::Format format, | |
| 658 uint32 internalformat) { | |
| 659 if (!decoder_) | |
| 660 return; | |
| 661 | |
| 662 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); | |
| 663 DCHECK(image_manager); | |
| 664 if (image_manager->LookupImage(id)) { | |
| 665 LOG(ERROR) << "Image already exists with same ID."; | |
| 666 return; | |
| 667 } | |
| 668 | |
| 669 // Note: this assumes that client ID is always 0. | |
| 670 const int kClientId = 0; | |
| 671 | |
| 672 DCHECK(image_factory_); | |
| 673 scoped_refptr<gfx::GLImage> image = | |
| 674 image_factory_->CreateImageForGpuMemoryBuffer( | |
| 675 handle, size, format, internalformat, kClientId); | |
| 676 if (!image.get()) | |
| 677 return; | |
| 678 | |
| 679 image_manager->AddImage(image.get(), id); | |
| 618 } | 680 } |
| 619 | 681 |
| 620 void InProcessCommandBuffer::DestroyImage(int32 id) { | 682 void InProcessCommandBuffer::DestroyImage(int32 id) { |
| 621 NOTREACHED(); | 683 CheckSequencedThread(); |
| 684 | |
| 685 QueueTask(base::Bind(&InProcessCommandBuffer::DestroyImageOnGpuThread, | |
| 686 base::Unretained(this), | |
| 687 id)); | |
| 688 } | |
| 689 | |
| 690 void InProcessCommandBuffer::DestroyImageOnGpuThread(int32 id) { | |
| 691 if (!decoder_) | |
| 692 return; | |
| 693 | |
| 694 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); | |
| 695 DCHECK(image_manager); | |
| 696 if (!image_manager->LookupImage(id)) { | |
| 697 LOG(ERROR) << "Image with ID doesn't exist."; | |
| 698 return; | |
| 699 } | |
| 700 | |
| 701 image_manager->RemoveImage(id); | |
| 622 } | 702 } |
| 623 | 703 |
| 624 int32 InProcessCommandBuffer::CreateGpuMemoryBufferImage( | 704 int32 InProcessCommandBuffer::CreateGpuMemoryBufferImage( |
| 625 size_t width, | 705 size_t width, |
| 626 size_t height, | 706 size_t height, |
| 627 unsigned internalformat, | 707 unsigned internalformat, |
| 628 unsigned usage) { | 708 unsigned usage) { |
| 629 NOTREACHED(); | 709 CheckSequencedThread(); |
| 630 return -1; | 710 |
| 711 gfx::Size size(width, height); | |
| 712 | |
| 713 DCHECK(gpu_memory_buffer_manager_); | |
| 714 scoped_ptr<gfx::GpuMemoryBuffer> buffer( | |
| 715 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | |
| 716 gfx::Size(width, height), | |
| 717 gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormat(internalformat), | |
| 718 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage))); | |
| 719 if (!buffer) | |
| 720 return -1; | |
| 721 | |
| 722 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); | |
| 631 } | 723 } |
| 632 | 724 |
| 633 uint32 InProcessCommandBuffer::InsertSyncPoint() { | 725 uint32 InProcessCommandBuffer::InsertSyncPoint() { |
| 634 uint32 sync_point = g_sync_point_manager.Get().GenerateSyncPoint(); | 726 uint32 sync_point = g_sync_point_manager.Get().GenerateSyncPoint(); |
| 635 QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread, | 727 QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread, |
| 636 base::Unretained(this), | 728 base::Unretained(this), |
| 637 sync_point)); | 729 sync_point)); |
| 638 return sync_point; | 730 return sync_point; |
| 639 } | 731 } |
| 640 | 732 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 778 | 870 |
| 779 #if defined(OS_ANDROID) | 871 #if defined(OS_ANDROID) |
| 780 scoped_refptr<gfx::SurfaceTexture> | 872 scoped_refptr<gfx::SurfaceTexture> |
| 781 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { | 873 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { |
| 782 DCHECK(stream_texture_manager_); | 874 DCHECK(stream_texture_manager_); |
| 783 return stream_texture_manager_->GetSurfaceTexture(stream_id); | 875 return stream_texture_manager_->GetSurfaceTexture(stream_id); |
| 784 } | 876 } |
| 785 #endif | 877 #endif |
| 786 | 878 |
| 787 } // namespace gpu | 879 } // namespace gpu |
| OLD | NEW |