Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: gpu/command_buffer/service/in_process_command_buffer.cc

Issue 962723002: Change CHROMIUM_image declarations to support multi planar input. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Trybot issues fixed. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Check the buffer count for the given |internalformat| and initialize the
717 internalformat, gpu_memory_buffer->GetFormat())); 713 // vectors where data will be passed. Log and return if the |internalformat|
714 // isn't supported.
715 int num_buffers =
716 gpu::ImageFactory::GpuMemoryBufferCountForImageFormat(internalformat);
717 if (num_buffers < 1) {
718 LOG(ERROR) << "Internalformat is not supported.";
719 return -1;
720 }
721 std::vector<gfx::GpuMemoryBufferHandle> handles;
722 handles.reserve(num_buffers);
723 std::vector<gfx::GpuMemoryBuffer::Format> formats;
724 formats.reserve(num_buffers);
725 bool requires_sync_point = false;
718 726
719 // This handle is owned by the GPU thread and must be passed to it or it 727 for (int i = 0; i < num_buffers; ++i) {
720 // will leak. In otherwords, do not early out on error between here and the 728 gfx::GpuMemoryBuffer* gpu_memory_buffer =
721 // queuing of the CreateImage task below. 729 gpu_memory_buffer_manager_->GpuMemoryBufferFromClientBuffer(buffers[i]);
722 bool requires_sync_point = false; 730 DCHECK(gpu_memory_buffer);
723 gfx::GpuMemoryBufferHandle handle = 731
724 ShareGpuMemoryBufferToGpuThread(gpu_memory_buffer->GetHandle(), 732 formats.push_back(gpu_memory_buffer->GetFormat());
725 &requires_sync_point); 733 DCHECK(gpu::ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat(
734 gfx::Size(width, height), formats[i]));
735 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
736 internalformat, i, formats[i]));
737
738 bool buffer_requires_sync_point = false;
739 // This handle is owned by the GPU thread and must be passed to it or it
740 // will leak. In other words, do not early out on error between here and the
741 // queuing of the CreateImage task below.
742 handles.push_back(ShareGpuMemoryBufferToGpuThread(
743 gpu_memory_buffer->GetHandle(), &buffer_requires_sync_point));
744
745 // We want to set a destruction sync point on all buffers if one happen to
746 // require one.
747 requires_sync_point |= buffer_requires_sync_point;
748 }
726 749
727 QueueTask(base::Bind(&InProcessCommandBuffer::CreateImageOnGpuThread, 750 QueueTask(base::Bind(&InProcessCommandBuffer::CreateImageOnGpuThread,
728 base::Unretained(this), 751 base::Unretained(this),
729 new_id, 752 new_id,
730 handle, 753 handles,
731 gfx::Size(width, height), 754 gfx::Size(width, height),
732 gpu_memory_buffer->GetFormat(), 755 formats,
733 internalformat)); 756 internalformat));
734 757
735 if (requires_sync_point) { 758 if (requires_sync_point) {
736 gpu_memory_buffer_manager_->SetDestructionSyncPoint(gpu_memory_buffer, 759 for (int 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 InsertSyncPoint());
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
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 int num_buffers =
830 gpu::ImageFactory::GpuMemoryBufferCountForImageFormat(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 client_buffers.reserve(num_buffers);
840 for (int i = 0; i < num_buffers; ++i) {
841 gfx::GpuMemoryBuffer::Format format =
842 gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormat(internalformat,
843 i);
844 buffers.push_back(gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer(
845 gfx::Size(width, height), format,
846 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage)));
847
848 if (!buffers[i])
849 return -1;
850
851 client_buffers[i] = buffers[i]->AsClientBuffer();
852 }
853 return CreateImage(client_buffers.data(), width, height, internalformat);
811 } 854 }
812 855
813 uint32 InProcessCommandBuffer::InsertSyncPoint() { 856 uint32 InProcessCommandBuffer::InsertSyncPoint() {
814 uint32 sync_point = g_sync_point_manager.Get().GenerateSyncPoint(); 857 uint32 sync_point = g_sync_point_manager.Get().GenerateSyncPoint();
815 QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread, 858 QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread,
816 base::Unretained(this), 859 base::Unretained(this),
817 sync_point)); 860 sync_point));
818 return sync_point; 861 return sync_point;
819 } 862 }
820 863
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 1004
962 #if defined(OS_ANDROID) 1005 #if defined(OS_ANDROID)
963 scoped_refptr<gfx::SurfaceTexture> 1006 scoped_refptr<gfx::SurfaceTexture>
964 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { 1007 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) {
965 DCHECK(stream_texture_manager_); 1008 DCHECK(stream_texture_manager_);
966 return stream_texture_manager_->GetSurfaceTexture(stream_id); 1009 return stream_texture_manager_->GetSurfaceTexture(stream_id);
967 } 1010 }
968 #endif 1011 #endif
969 1012
970 } // namespace gpu 1013 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698