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 |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 #if defined(OS_ANDROID) | 41 #if defined(OS_ANDROID) |
42 #include "gpu/command_buffer/service/stream_texture_manager_in_process_android.h
" | 42 #include "gpu/command_buffer/service/stream_texture_manager_in_process_android.h
" |
43 #include "ui/gl/android/surface_texture.h" | 43 #include "ui/gl/android/surface_texture.h" |
44 #endif | 44 #endif |
45 | 45 |
46 namespace gpu { | 46 namespace gpu { |
47 | 47 |
48 namespace { | 48 namespace { |
49 | 49 |
50 static InProcessGpuMemoryBufferFactory* g_gpu_memory_buffer_factory = NULL; | |
51 | |
52 template <typename T> | 50 template <typename T> |
53 static void RunTaskWithResult(base::Callback<T(void)> task, | 51 static void RunTaskWithResult(base::Callback<T(void)> task, |
54 T* result, | 52 T* result, |
55 base::WaitableEvent* completion) { | 53 base::WaitableEvent* completion) { |
56 *result = task.Run(); | 54 *result = task.Run(); |
57 completion->Signal(); | 55 completion->Signal(); |
58 } | 56 } |
59 | 57 |
60 class GpuInProcessThread | 58 class GpuInProcessThread |
61 : public base::Thread, | 59 : public base::Thread, |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 base::Bind(&InProcessCommandBuffer::InitializeOnGpuThread, | 296 base::Bind(&InProcessCommandBuffer::InitializeOnGpuThread, |
299 base::Unretained(this), | 297 base::Unretained(this), |
300 params); | 298 params); |
301 | 299 |
302 base::WaitableEvent completion(true, false); | 300 base::WaitableEvent completion(true, false); |
303 bool result = false; | 301 bool result = false; |
304 QueueTask( | 302 QueueTask( |
305 base::Bind(&RunTaskWithResult<bool>, init_task, &result, &completion)); | 303 base::Bind(&RunTaskWithResult<bool>, init_task, &result, &completion)); |
306 completion.Wait(); | 304 completion.Wait(); |
307 | 305 |
308 if (result) { | 306 if (result) |
309 capabilities_ = capabilities; | 307 capabilities_ = capabilities; |
310 capabilities_.map_image = | 308 |
311 capabilities_.map_image && g_gpu_memory_buffer_factory; | |
312 } | |
313 return result; | 309 return result; |
314 } | 310 } |
315 | 311 |
316 bool InProcessCommandBuffer::InitializeOnGpuThread( | 312 bool InProcessCommandBuffer::InitializeOnGpuThread( |
317 const InitializeOnGpuThreadParams& params) { | 313 const InitializeOnGpuThreadParams& params) { |
318 CheckSequencedThread(); | 314 CheckSequencedThread(); |
319 gpu_thread_weak_ptr_ = gpu_thread_weak_ptr_factory_.GetWeakPtr(); | 315 gpu_thread_weak_ptr_ = gpu_thread_weak_ptr_factory_.GetWeakPtr(); |
320 | 316 |
321 DCHECK(params.size.width() >= 0 && params.size.height() >= 0); | 317 DCHECK(params.size.width() >= 0 && params.size.height() >= 0); |
322 | 318 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 gpu::Capabilities InProcessCommandBuffer::GetCapabilities() { | 608 gpu::Capabilities InProcessCommandBuffer::GetCapabilities() { |
613 return capabilities_; | 609 return capabilities_; |
614 } | 610 } |
615 | 611 |
616 gfx::GpuMemoryBuffer* InProcessCommandBuffer::CreateGpuMemoryBuffer( | 612 gfx::GpuMemoryBuffer* InProcessCommandBuffer::CreateGpuMemoryBuffer( |
617 size_t width, | 613 size_t width, |
618 size_t height, | 614 size_t height, |
619 unsigned internalformat, | 615 unsigned internalformat, |
620 unsigned usage, | 616 unsigned usage, |
621 int32* id) { | 617 int32* id) { |
622 CheckSequencedThread(); | 618 NOTREACHED(); |
623 | 619 return NULL; |
624 *id = -1; | |
625 | |
626 scoped_ptr<gfx::GpuMemoryBuffer> buffer = | |
627 g_gpu_memory_buffer_factory->AllocateGpuMemoryBuffer( | |
628 width, height, internalformat, usage); | |
629 if (!buffer.get()) | |
630 return NULL; | |
631 | |
632 static int32 next_id = 1; | |
633 int32 new_id = next_id++; | |
634 | |
635 base::Closure task = | |
636 base::Bind(&InProcessCommandBuffer::RegisterGpuMemoryBufferOnGpuThread, | |
637 base::Unretained(this), | |
638 new_id, | |
639 buffer->GetHandle(), | |
640 width, | |
641 height, | |
642 internalformat); | |
643 | |
644 QueueTask(task); | |
645 | |
646 *id = new_id; | |
647 DCHECK(gpu_memory_buffers_.find(new_id) == gpu_memory_buffers_.end()); | |
648 return gpu_memory_buffers_.add(new_id, buffer.Pass()).first->second; | |
649 } | |
650 | |
651 void InProcessCommandBuffer::RegisterGpuMemoryBufferOnGpuThread( | |
652 int32 id, | |
653 const gfx::GpuMemoryBufferHandle& handle, | |
654 size_t width, | |
655 size_t height, | |
656 unsigned internalformat) { | |
657 scoped_refptr<gfx::GLImage> image = | |
658 g_gpu_memory_buffer_factory->CreateImageForGpuMemoryBuffer( | |
659 handle, gfx::Size(width, height), internalformat); | |
660 if (!image.get()) | |
661 return; | |
662 | |
663 // For Android specific workaround. | |
664 gles2::ContextGroup* context_group = decoder_->GetContextGroup(); | |
665 if (context_group->feature_info()->workarounds().release_image_after_use) | |
666 image->SetReleaseAfterUse(); | |
667 | |
668 if (decoder_) { | |
669 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); | |
670 DCHECK(image_manager); | |
671 image_manager->AddImage(image.get(), id); | |
672 } | |
673 } | 620 } |
674 | 621 |
675 void InProcessCommandBuffer::DestroyGpuMemoryBuffer(int32 id) { | 622 void InProcessCommandBuffer::DestroyGpuMemoryBuffer(int32 id) { |
676 CheckSequencedThread(); | 623 NOTREACHED(); |
677 | |
678 base::Closure task = | |
679 base::Bind(&InProcessCommandBuffer::UnregisterGpuMemoryBufferOnGpuThread, | |
680 base::Unretained(this), | |
681 id); | |
682 | |
683 QueueTask(task); | |
684 | |
685 gpu_memory_buffers_.erase(id); | |
686 } | |
687 | |
688 void InProcessCommandBuffer::UnregisterGpuMemoryBufferOnGpuThread(int32 id) { | |
689 if (decoder_) { | |
690 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); | |
691 DCHECK(image_manager); | |
692 image_manager->RemoveImage(id); | |
693 } | |
694 } | 624 } |
695 | 625 |
696 uint32 InProcessCommandBuffer::InsertSyncPoint() { | 626 uint32 InProcessCommandBuffer::InsertSyncPoint() { |
697 uint32 sync_point = g_sync_point_manager.Get().GenerateSyncPoint(); | 627 uint32 sync_point = g_sync_point_manager.Get().GenerateSyncPoint(); |
698 QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread, | 628 QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread, |
699 base::Unretained(this), | 629 base::Unretained(this), |
700 sync_point)); | 630 sync_point)); |
701 return sync_point; | 631 return sync_point; |
702 } | 632 } |
703 | 633 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 } | 772 } |
843 | 773 |
844 #if defined(OS_ANDROID) | 774 #if defined(OS_ANDROID) |
845 scoped_refptr<gfx::SurfaceTexture> | 775 scoped_refptr<gfx::SurfaceTexture> |
846 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { | 776 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { |
847 DCHECK(stream_texture_manager_); | 777 DCHECK(stream_texture_manager_); |
848 return stream_texture_manager_->GetSurfaceTexture(stream_id); | 778 return stream_texture_manager_->GetSurfaceTexture(stream_id); |
849 } | 779 } |
850 #endif | 780 #endif |
851 | 781 |
852 // static | |
853 void InProcessCommandBuffer::SetGpuMemoryBufferFactory( | |
854 InProcessGpuMemoryBufferFactory* factory) { | |
855 g_gpu_memory_buffer_factory = factory; | |
856 } | |
857 | |
858 } // namespace gpu | 782 } // namespace gpu |
OLD | NEW |