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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
693 | 693 |
694 void InProcessCommandBuffer::DestroyTransferBufferOnGpuThread(int32 id) { | 694 void InProcessCommandBuffer::DestroyTransferBufferOnGpuThread(int32 id) { |
695 base::AutoLock lock(command_buffer_lock_); | 695 base::AutoLock lock(command_buffer_lock_); |
696 command_buffer_->DestroyTransferBuffer(id); | 696 command_buffer_->DestroyTransferBuffer(id); |
697 } | 697 } |
698 | 698 |
699 gpu::Capabilities InProcessCommandBuffer::GetCapabilities() { | 699 gpu::Capabilities InProcessCommandBuffer::GetCapabilities() { |
700 return capabilities_; | 700 return capabilities_; |
701 } | 701 } |
702 | 702 |
703 int32 InProcessCommandBuffer::CreateImage(ClientBuffer buffer, | 703 int32 InProcessCommandBuffer::CreateImage(ClientBuffer* const buffers, |
704 size_t width, | 704 size_t width, |
705 size_t height, | 705 size_t height, |
706 unsigned internalformat) { | 706 unsigned internalformat) { |
707 CheckSequencedThread(); | 707 CheckSequencedThread(); |
708 | 708 |
709 DCHECK(gpu_memory_buffer_manager_); | 709 DCHECK(gpu_memory_buffer_manager_); |
710 gfx::GpuMemoryBuffer* gpu_memory_buffer = | |
711 gpu_memory_buffer_manager_->GpuMemoryBufferFromClientBuffer(buffer); | |
712 DCHECK(gpu_memory_buffer); | |
713 | |
714 int32 new_id = next_image_id_.GetNext(); | 710 int32 new_id = next_image_id_.GetNext(); |
715 | 711 |
716 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( | 712 // Log and return if the |internalformat| isn't supported. |
717 internalformat, gpu_memory_buffer->GetFormat())); | 713 if (!gpu::ImageFactory::IsImageFormatSupported(internalformat)) { |
714 LOG(ERROR) << "Internalformat is not supported."; | |
715 return -1; | |
716 } | |
718 | 717 |
719 // This handle is owned by the GPU thread and must be passed to it or it | 718 // Check the buffer count for the given |internalformat| and initialize the |
720 // will leak. In otherwords, do not early out on error between here and the | 719 // vectors where data will be passed. |
721 // queuing of the CreateImage task below. | 720 size_t num_buffers = |
721 gpu::ImageFactory::NumberOfPlanesForImageFormat(internalformat); | |
722 std::vector<gfx::GpuMemoryBufferHandle> handles; | |
723 std::vector<gfx::GpuMemoryBuffer::Format> formats; | |
722 bool requires_sync_point = false; | 724 bool requires_sync_point = false; |
723 gfx::GpuMemoryBufferHandle handle = | 725 |
724 ShareGpuMemoryBufferToGpuThread(gpu_memory_buffer->GetHandle(), | 726 for (size_t i = 0; i < num_buffers; ++i) { |
725 &requires_sync_point); | 727 gfx::GpuMemoryBuffer* gpu_memory_buffer = |
728 gpu_memory_buffer_manager_->GpuMemoryBufferFromClientBuffer(buffers[i]); | |
729 DCHECK(gpu_memory_buffer); | |
730 | |
731 formats.push_back(gpu_memory_buffer->GetFormat()); | |
732 DCHECK(gpu::ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat( | |
733 gfx::Size(width, height), formats[i])); | |
734 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( | |
735 internalformat, i, formats[i])); | |
736 | |
737 bool buffer_requires_sync_point = false; | |
738 // This handle is owned by the GPU thread and must be passed to it or it | |
739 // will leak. In other words, do not early out on error between here and the | |
740 // queuing of the CreateImage task below. | |
741 handles.push_back(ShareGpuMemoryBufferToGpuThread( | |
742 gpu_memory_buffer->GetHandle(), &buffer_requires_sync_point)); | |
743 | |
744 // We set a destruction sync point on all buffers if one happen to require | |
745 // one. | |
746 requires_sync_point |= buffer_requires_sync_point; | |
747 } | |
726 | 748 |
727 QueueTask(base::Bind(&InProcessCommandBuffer::CreateImageOnGpuThread, | 749 QueueTask(base::Bind(&InProcessCommandBuffer::CreateImageOnGpuThread, |
728 base::Unretained(this), | 750 base::Unretained(this), |
729 new_id, | 751 new_id, |
730 handle, | 752 handles, |
731 gfx::Size(width, height), | 753 gfx::Size(width, height), |
732 gpu_memory_buffer->GetFormat(), | 754 formats, |
733 internalformat)); | 755 internalformat)); |
734 | 756 |
757 uint32 sync_point = InsertSyncPoint(); | |
reveman
2015/03/18 16:59:01
Please move inside "if (requires_sync_point)" scop
emircan
2015/03/18 23:51:26
Done.
| |
735 if (requires_sync_point) { | 758 if (requires_sync_point) { |
736 gpu_memory_buffer_manager_->SetDestructionSyncPoint(gpu_memory_buffer, | 759 for (size_t i = 0; i < num_buffers; ++i) { |
737 InsertSyncPoint()); | 760 gfx::GpuMemoryBuffer* gpu_memory_buffer = |
761 gpu_memory_buffer_manager_->GpuMemoryBufferFromClientBuffer( | |
762 buffers[i]); | |
763 gpu_memory_buffer_manager_->SetDestructionSyncPoint(gpu_memory_buffer, | |
764 sync_point); | |
765 } | |
738 } | 766 } |
739 | 767 |
740 return new_id; | 768 return new_id; |
741 } | 769 } |
742 | 770 |
743 void InProcessCommandBuffer::CreateImageOnGpuThread( | 771 void InProcessCommandBuffer::CreateImageOnGpuThread( |
744 int32 id, | 772 int32 id, |
745 const gfx::GpuMemoryBufferHandle& handle, | 773 const std::vector<gfx::GpuMemoryBufferHandle>& handles, |
746 const gfx::Size& size, | 774 const gfx::Size& size, |
747 gfx::GpuMemoryBuffer::Format format, | 775 const std::vector<gfx::GpuMemoryBuffer::Format>& formats, |
748 uint32 internalformat) { | 776 uint32 internalformat) { |
749 if (!decoder_) | 777 if (!decoder_) |
750 return; | 778 return; |
751 | 779 |
752 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); | 780 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); |
753 DCHECK(image_manager); | 781 DCHECK(image_manager); |
754 if (image_manager->LookupImage(id)) { | 782 if (image_manager->LookupImage(id)) { |
755 LOG(ERROR) << "Image already exists with same ID."; | 783 LOG(ERROR) << "Image already exists with same ID."; |
756 return; | 784 return; |
757 } | 785 } |
758 | 786 |
759 // Note: this assumes that client ID is always 0. | 787 // Note: this assumes that client ID is always 0. |
760 const int kClientId = 0; | 788 const int kClientId = 0; |
761 | 789 |
762 DCHECK(image_factory_); | 790 DCHECK(image_factory_); |
763 scoped_refptr<gfx::GLImage> image = | 791 scoped_refptr<gfx::GLImage> image = |
764 image_factory_->CreateImageForGpuMemoryBuffer( | 792 image_factory_->CreateImageForGpuMemoryBuffers(handles, size, formats, |
765 handle, size, format, internalformat, kClientId); | 793 internalformat, kClientId); |
766 if (!image.get()) | 794 if (!image.get()) |
767 return; | 795 return; |
768 | 796 |
769 image_manager->AddImage(image.get(), id); | 797 image_manager->AddImage(image.get(), id); |
770 } | 798 } |
771 | 799 |
772 void InProcessCommandBuffer::DestroyImage(int32 id) { | 800 void InProcessCommandBuffer::DestroyImage(int32 id) { |
773 CheckSequencedThread(); | 801 CheckSequencedThread(); |
774 | 802 |
775 QueueTask(base::Bind(&InProcessCommandBuffer::DestroyImageOnGpuThread, | 803 QueueTask(base::Bind(&InProcessCommandBuffer::DestroyImageOnGpuThread, |
(...skipping 15 matching lines...) Expand all Loading... | |
791 image_manager->RemoveImage(id); | 819 image_manager->RemoveImage(id); |
792 } | 820 } |
793 | 821 |
794 int32 InProcessCommandBuffer::CreateGpuMemoryBufferImage( | 822 int32 InProcessCommandBuffer::CreateGpuMemoryBufferImage( |
795 size_t width, | 823 size_t width, |
796 size_t height, | 824 size_t height, |
797 unsigned internalformat, | 825 unsigned internalformat, |
798 unsigned usage) { | 826 unsigned usage) { |
799 CheckSequencedThread(); | 827 CheckSequencedThread(); |
800 | 828 |
829 size_t num_buffers = | |
reveman
2015/03/18 16:59:01
IsImageFormatSupported check instead?
emircan
2015/03/18 23:51:26
Done.
| |
830 gpu::ImageFactory::NumberOfPlanesForImageFormat(internalformat); | |
831 if (num_buffers < 1) { | |
832 LOG(ERROR) << "Internalformat is not supported."; | |
833 return -1; | |
834 } | |
801 DCHECK(gpu_memory_buffer_manager_); | 835 DCHECK(gpu_memory_buffer_manager_); |
802 scoped_ptr<gfx::GpuMemoryBuffer> buffer( | |
803 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | |
804 gfx::Size(width, height), | |
805 gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormat(internalformat), | |
806 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage))); | |
807 if (!buffer) | |
808 return -1; | |
809 | 836 |
810 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); | 837 ScopedVector<gfx::GpuMemoryBuffer> buffers; |
838 std::vector<ClientBuffer> client_buffers; | |
839 for (size_t i = 0; i < num_buffers; ++i) { | |
840 gfx::GpuMemoryBuffer::Format format = | |
841 gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormat(internalformat, | |
842 i); | |
843 buffers.push_back(gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | |
844 gfx::Size(width, height), format, | |
845 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage))); | |
846 | |
847 if (!buffers[i]) | |
848 return -1; | |
849 | |
850 client_buffers[i] = buffers[i]->AsClientBuffer(); | |
851 } | |
852 return CreateImage(client_buffers.data(), width, height, internalformat); | |
811 } | 853 } |
812 | 854 |
813 uint32 InProcessCommandBuffer::InsertSyncPoint() { | 855 uint32 InProcessCommandBuffer::InsertSyncPoint() { |
814 uint32 sync_point = g_sync_point_manager.Get().GenerateSyncPoint(); | 856 uint32 sync_point = g_sync_point_manager.Get().GenerateSyncPoint(); |
815 QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread, | 857 QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread, |
816 base::Unretained(this), | 858 base::Unretained(this), |
817 sync_point)); | 859 sync_point)); |
818 return sync_point; | 860 return sync_point; |
819 } | 861 } |
820 | 862 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
961 | 1003 |
962 #if defined(OS_ANDROID) | 1004 #if defined(OS_ANDROID) |
963 scoped_refptr<gfx::SurfaceTexture> | 1005 scoped_refptr<gfx::SurfaceTexture> |
964 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { | 1006 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { |
965 DCHECK(stream_texture_manager_); | 1007 DCHECK(stream_texture_manager_); |
966 return stream_texture_manager_->GetSurfaceTexture(stream_id); | 1008 return stream_texture_manager_->GetSurfaceTexture(stream_id); |
967 } | 1009 } |
968 #endif | 1010 #endif |
969 | 1011 |
970 } // namespace gpu | 1012 } // namespace gpu |
OLD | NEW |