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

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: reveman@ comments. 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 // 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
735 if (requires_sync_point) { 757 if (requires_sync_point) {
736 gpu_memory_buffer_manager_->SetDestructionSyncPoint(gpu_memory_buffer, 758 uint32 sync_point = InsertSyncPoint();
737 InsertSyncPoint()); 759 for (size_t i = 0; i < num_buffers; ++i) {
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 14 matching lines...) Expand all
790 818
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();
828 DCHECK(gpu::ImageFactory::IsImageFormatSupported(internalformat));
829 DCHECK(gpu_memory_buffer_manager_);
800 830
801 DCHECK(gpu_memory_buffer_manager_); 831 size_t num_buffers =
802 scoped_ptr<gfx::GpuMemoryBuffer> buffer( 832 gpu::ImageFactory::NumberOfPlanesForImageFormat(internalformat);
803 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( 833 ScopedVector<gfx::GpuMemoryBuffer> buffers;
804 gfx::Size(width, height), 834 std::vector<ClientBuffer> client_buffers;
805 gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormat(internalformat),
806 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage)));
807 if (!buffer)
808 return -1;
809 835
810 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); 836 for (size_t i = 0; i < num_buffers; ++i) {
837 gfx::GpuMemoryBuffer::Format format =
838 gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormat(internalformat,
839 i);
840 buffers.push_back(gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer(
841 gfx::Size(width, height), format,
842 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage)));
843
844 if (!buffers[i])
845 return -1;
846
847 client_buffers[i] = buffers[i]->AsClientBuffer();
848 }
849 return CreateImage(client_buffers.data(), width, height, internalformat);
811 } 850 }
812 851
813 uint32 InProcessCommandBuffer::InsertSyncPoint() { 852 uint32 InProcessCommandBuffer::InsertSyncPoint() {
814 uint32 sync_point = g_sync_point_manager.Get().GenerateSyncPoint(); 853 uint32 sync_point = g_sync_point_manager.Get().GenerateSyncPoint();
815 QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread, 854 QueueTask(base::Bind(&InProcessCommandBuffer::RetireSyncPointOnGpuThread,
816 base::Unretained(this), 855 base::Unretained(this),
817 sync_point)); 856 sync_point));
818 return sync_point; 857 return sync_point;
819 } 858 }
820 859
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 1000
962 #if defined(OS_ANDROID) 1001 #if defined(OS_ANDROID)
963 scoped_refptr<gfx::SurfaceTexture> 1002 scoped_refptr<gfx::SurfaceTexture>
964 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { 1003 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) {
965 DCHECK(stream_texture_manager_); 1004 DCHECK(stream_texture_manager_);
966 return stream_texture_manager_->GetSurfaceTexture(stream_id); 1005 return stream_texture_manager_->GetSurfaceTexture(stream_id);
967 } 1006 }
968 #endif 1007 #endif
969 1008
970 } // namespace gpu 1009 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698