OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #if defined(OS_WIN) | 5 #if defined(OS_WIN) |
6 #include <windows.h> | 6 #include <windows.h> |
7 #endif | 7 #endif |
8 | 8 |
9 #include "content/common/gpu/gpu_channel.h" | 9 #include "content/common/gpu/gpu_channel.h" |
10 | 10 |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 | 820 |
821 uint64 GpuChannel::GetMemoryUsage() { | 821 uint64 GpuChannel::GetMemoryUsage() { |
822 uint64 size = 0; | 822 uint64 size = 0; |
823 for (StubMap::Iterator<GpuCommandBufferStub> it(&stubs_); | 823 for (StubMap::Iterator<GpuCommandBufferStub> it(&stubs_); |
824 !it.IsAtEnd(); it.Advance()) { | 824 !it.IsAtEnd(); it.Advance()) { |
825 size += it.GetCurrentValue()->GetMemoryUsage(); | 825 size += it.GetCurrentValue()->GetMemoryUsage(); |
826 } | 826 } |
827 return size; | 827 return size; |
828 } | 828 } |
829 | 829 |
830 scoped_refptr<gfx::GLImage> GpuChannel::CreateImageForGpuMemoryBuffer( | 830 scoped_refptr<gfx::GLImage> GpuChannel::CreateImageForGpuMemoryBuffers( |
831 const gfx::GpuMemoryBufferHandle& handle, | 831 const std::vector<gfx::GpuMemoryBufferHandle>& handles, |
832 const gfx::Size& size, | 832 const gfx::Size& size, |
833 gfx::GpuMemoryBuffer::Format format, | 833 const std::vector<gfx::GpuMemoryBuffer::Format>& formats, |
834 uint32 internalformat) { | 834 uint32 internalformat) { |
835 switch (handle.type) { | 835 int num_buffers = |
| 836 gpu::ImageFactory::GpuMemoryBufferCountForImageFormat(internalformat); |
| 837 |
| 838 // Make sure that the gives vectors have the correct size. |
| 839 DCHECK_EQ(static_cast<int>(handles.size()), num_buffers); |
| 840 DCHECK_EQ(static_cast<int>(formats.size()), num_buffers); |
| 841 |
| 842 // Check if all the handle types are equal, and if they aren't, return an |
| 843 // empty image. |
| 844 gfx::GpuMemoryBufferType handle_type = handles[0].type; |
| 845 for (int i = 1; i < num_buffers; ++i) { |
| 846 if (handles[i].type != handle_type) |
| 847 return scoped_refptr<gfx::GLImage>(); |
| 848 } |
| 849 |
| 850 switch (handle_type) { |
836 case gfx::SHARED_MEMORY_BUFFER: { | 851 case gfx::SHARED_MEMORY_BUFFER: { |
| 852 // TODO(emircan): See http://crbug.com/439520; support passing multiple |
| 853 // buffers when new multi-planar formats are added. |
| 854 if (num_buffers != 1) { |
| 855 NOTIMPLEMENTED(); |
| 856 return scoped_refptr<gfx::GLImage>(); |
| 857 } |
| 858 |
837 scoped_refptr<gfx::GLImageSharedMemory> image( | 859 scoped_refptr<gfx::GLImageSharedMemory> image( |
838 new gfx::GLImageSharedMemory(size, internalformat)); | 860 new gfx::GLImageSharedMemory(size, internalformat)); |
839 if (!image->Initialize(handle, format)) | 861 if (!image->Initialize(handles[0], formats[0])) |
840 return scoped_refptr<gfx::GLImage>(); | 862 return scoped_refptr<gfx::GLImage>(); |
841 | |
842 return image; | 863 return image; |
843 } | 864 } |
844 default: { | 865 default: { |
845 GpuChannelManager* manager = gpu_channel_manager(); | 866 GpuChannelManager* manager = gpu_channel_manager(); |
846 if (!manager->gpu_memory_buffer_factory()) | 867 if (!manager->gpu_memory_buffer_factory()) |
847 return scoped_refptr<gfx::GLImage>(); | 868 return scoped_refptr<gfx::GLImage>(); |
848 | 869 |
849 return manager->gpu_memory_buffer_factory() | 870 return manager->gpu_memory_buffer_factory() |
850 ->AsImageFactory() | 871 ->AsImageFactory() |
851 ->CreateImageForGpuMemoryBuffer(handle, | 872 ->CreateImageForGpuMemoryBuffers(handles, size, formats, |
852 size, | 873 internalformat, client_id_); |
853 format, | |
854 internalformat, | |
855 client_id_); | |
856 } | 874 } |
857 } | 875 } |
858 } | 876 } |
859 | 877 |
860 void GpuChannel::HandleUpdateValueState( | 878 void GpuChannel::HandleUpdateValueState( |
861 unsigned int target, const gpu::ValueState& state) { | 879 unsigned int target, const gpu::ValueState& state) { |
862 pending_valuebuffer_state_->UpdateState(target, state); | 880 pending_valuebuffer_state_->UpdateState(target, state); |
863 } | 881 } |
864 | 882 |
865 } // namespace content | 883 } // namespace content |
OLD | NEW |