Chromium Code Reviews| Index: content/common/gpu/client/command_buffer_proxy_impl.cc |
| diff --git a/content/common/gpu/client/command_buffer_proxy_impl.cc b/content/common/gpu/client/command_buffer_proxy_impl.cc |
| index 75cffa2fdd0f5340391b23bbd493ab4b7bae6b19..c6538ffcfb45d82d84473f7afe76e8624790d39a 100644 |
| --- a/content/common/gpu/client/command_buffer_proxy_impl.cc |
| +++ b/content/common/gpu/client/command_buffer_proxy_impl.cc |
| @@ -347,7 +347,7 @@ gpu::Capabilities CommandBufferProxyImpl::GetCapabilities() { |
| return capabilities_; |
| } |
| -int32_t CommandBufferProxyImpl::CreateImage(ClientBuffer buffer, |
| +int32_t CommandBufferProxyImpl::CreateImage(ClientBuffer* const buffers, |
| size_t width, |
| size_t height, |
| unsigned internalformat) { |
| @@ -359,32 +359,46 @@ int32_t CommandBufferProxyImpl::CreateImage(ClientBuffer buffer, |
| gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = |
| channel_->gpu_memory_buffer_manager(); |
| - gfx::GpuMemoryBuffer* gpu_memory_buffer = |
| - gpu_memory_buffer_manager->GpuMemoryBufferFromClientBuffer(buffer); |
| - DCHECK(gpu_memory_buffer); |
| - // This handle is owned by the GPU process and must be passed to it or it |
| - // will leak. In otherwords, do not early out on error between here and the |
| - // sending of the CreateImage IPC below. |
| - bool requires_sync_point = false; |
| - gfx::GpuMemoryBufferHandle handle = |
| - channel_->ShareGpuMemoryBufferToGpuProcess(gpu_memory_buffer->GetHandle(), |
| - &requires_sync_point); |
| - |
| - DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( |
| - internalformat, gpu_memory_buffer->GetFormat())); |
| + int num_buffers = |
| + gpu::ImageFactory::GpuMemoryBufferCountForImageFormat(internalformat); |
| + |
| + gfx::GpuMemoryBuffer* gpu_memory_buffers[num_buffers]; |
|
reveman
2015/03/05 19:35:32
nit: please avoid this array and use a temporary v
emircan
2015/03/09 21:07:22
Done.
|
| + std::vector<gfx::GpuMemoryBufferHandle> handles(num_buffers); |
|
reveman
2015/03/05 19:35:32
nit: I prefer if this is empty initially and inste
emircan
2015/03/09 21:07:22
Done.
|
| + std::vector<gfx::GpuMemoryBuffer::Format> formats(num_buffers); |
|
reveman
2015/03/05 19:35:32
ditto
emircan
2015/03/09 21:07:22
Done.
|
| + bool requires_sync_point[num_buffers]; |
|
reveman
2015/03/05 19:35:32
You can skip this array and simply set a destructi
emircan
2015/03/09 21:07:22
Done.
|
| + for (int i = 0; i < num_buffers; ++i) { |
| + gpu_memory_buffers[i] = |
| + gpu_memory_buffer_manager->GpuMemoryBufferFromClientBuffer(buffers[i]); |
| + DCHECK(gpu_memory_buffers[i]); |
| + |
| + formats[i] = gpu_memory_buffers[i]->GetFormat(); |
| + DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( |
| + internalformat, formats[i])); |
| + |
| + requires_sync_point[i] = false; |
| + |
| + // This handle is owned by the GPU process and must be passed to it or it |
| + // will leak. In other words, do not early out on error between here and the |
| + // sending of the CreateImage IPC below. |
| + handles[i] = channel_->ShareGpuMemoryBufferToGpuProcess( |
| + gpu_memory_buffers[i]->GetHandle(), &requires_sync_point[i]); |
| + } |
| + |
| if (!Send(new GpuCommandBufferMsg_CreateImage(route_id_, |
| new_id, |
| - handle, |
| + handles, |
| gfx::Size(width, height), |
| - gpu_memory_buffer->GetFormat(), |
| + formats, |
| internalformat))) { |
| return -1; |
| } |
| - if (requires_sync_point) { |
| - gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer, |
| - InsertSyncPoint()); |
| + for (int i = 0; i < num_buffers; ++i) { |
| + if (requires_sync_point[i]) { |
| + gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffers[i], |
| + InsertSyncPoint()); |
|
reveman
2015/03/05 19:35:32
Each sync point has a significant cost. Please avo
emircan
2015/03/09 21:07:22
Done.
|
| + } |
| } |
| return new_id; |
| @@ -404,15 +418,28 @@ int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( |
| unsigned internalformat, |
| unsigned usage) { |
| CheckLock(); |
| - scoped_ptr<gfx::GpuMemoryBuffer> buffer( |
| - channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( |
| - gfx::Size(width, height), |
| - gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormat(internalformat), |
| - gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage))); |
| - if (!buffer) |
| - return -1; |
| - return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); |
| + std::vector<gfx::GpuMemoryBuffer::Format> gpu_memory_buffer_formats; |
| + gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormats( |
|
reveman
2015/03/05 19:35:32
If you had a gpu::ImageFactory::ImageFormatToGpuMe
emircan
2015/03/09 21:07:22
Done.
|
| + internalformat, &gpu_memory_buffer_formats); |
| + int num_buffers = gpu_memory_buffer_formats.size(); |
|
reveman
2015/03/05 19:35:32
I prefer if you use gpu::ImageFactory::GpuMemoryBu
emircan
2015/03/09 21:07:22
Done.
|
| + |
| + DCHECK_GE(num_buffers, 1); |
| + |
| + ScopedVector<gfx::GpuMemoryBuffer> buffers; |
| + ClientBuffer client_buffers[num_buffers]; |
| + for (int i = 0; i < num_buffers; ++i) { |
| + buffers.push_back( |
| + channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( |
| + gfx::Size(width, height), gpu_memory_buffer_formats[i], |
| + gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage))); |
| + |
| + if (!buffers[i]) |
| + return -1; |
| + |
| + client_buffers[i] = buffers[i]->AsClientBuffer(); |
| + } |
| + return CreateImage(client_buffers, width, height, internalformat); |
| } |
| int CommandBufferProxyImpl::GetRouteID() const { |