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 8241812cc2af9aa068f6bce602727e67ecf841eb..b0dd9e52df5db05146440856a20f3bded1eba72d 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,34 +359,62 @@ 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. |
| + // Check the buffer count for the given |internalformat| and initialize the |
| + // vectors where data will be passed. Log and return if the |internalformat| |
| + // isn't supported. |
| + int num_buffers = |
| + gpu::ImageFactory::GpuMemoryBufferCountForImageFormat(internalformat); |
| + if (num_buffers < 1) { |
| + LOG(ERROR) << "Internalformat is not supported."; |
| + return -1; |
| + } |
| + std::vector<gfx::GpuMemoryBufferHandle> handles; |
| + handles.reserve(num_buffers); |
|
reveman
2015/03/12 19:37:22
Don't bother with this micro optimization. Just le
emircan
2015/03/12 22:34:26
Done.
I still think it might be worth it in the
|
| + std::vector<gfx::GpuMemoryBuffer::Format> formats; |
| + formats.reserve(num_buffers); |
|
reveman
2015/03/12 19:37:22
Ditto.
emircan
2015/03/12 22:34:26
Done.
|
| bool requires_sync_point = false; |
| - gfx::GpuMemoryBufferHandle handle = |
| - channel_->ShareGpuMemoryBufferToGpuProcess(gpu_memory_buffer->GetHandle(), |
| - &requires_sync_point); |
| - |
| - DCHECK(gpu::ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat( |
| - gfx::Size(width, height), gpu_memory_buffer->GetFormat())); |
| - DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( |
| - internalformat, gpu_memory_buffer->GetFormat())); |
| + |
| + for (int i = 0; i < num_buffers; ++i) { |
| + gfx::GpuMemoryBuffer* gpu_memory_buffer = |
| + gpu_memory_buffer_manager->GpuMemoryBufferFromClientBuffer(buffers[i]); |
| + DCHECK(gpu_memory_buffer); |
| + |
| + formats.push_back(gpu_memory_buffer->GetFormat()); |
| + DCHECK(gpu::ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat( |
| + gfx::Size(width, height), formats[i])); |
| + DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( |
| + internalformat, i, formats[i])); |
| + |
| + bool buffer_requires_sync_point = 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.push_back(channel_->ShareGpuMemoryBufferToGpuProcess( |
| + gpu_memory_buffer->GetHandle(), &buffer_requires_sync_point)); |
| + |
| + // We want to set a destruction sync point on all buffers if one happen to |
|
reveman
2015/03/12 19:37:22
s/want to// as "want to" makes it sound like we ha
emircan
2015/03/12 22:34:26
Done.
|
| + // require one. |
| + requires_sync_point |= buffer_requires_sync_point; |
| + } |
| + |
| 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) { |
| + gfx::GpuMemoryBuffer* gpu_memory_buffer = |
| + gpu_memory_buffer_manager->GpuMemoryBufferFromClientBuffer( |
| + buffers[i]); |
| + gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer, |
| + InsertSyncPoint()); |
|
reveman
2015/03/12 19:37:22
InsertSyncPoint() is a relatively expensive call.
emircan
2015/03/12 22:34:26
Done.
|
| + } |
| } |
| return new_id; |
| @@ -406,15 +434,32 @@ 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) |
| + |
| + int num_buffers = |
| + gpu::ImageFactory::GpuMemoryBufferCountForImageFormat(internalformat); |
| + if (num_buffers < 1) { |
| + LOG(ERROR) << "Internalformat is not supported."; |
| return -1; |
| + } |
| - return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); |
| + ScopedVector<gfx::GpuMemoryBuffer> buffers; |
| + buffers.reserve(num_buffers); |
|
reveman
2015/03/12 19:37:22
Skip this optimization.
emircan
2015/03/12 22:34:26
Done.
|
| + std::vector<ClientBuffer> client_buffers; |
| + client_buffers.reserve(num_buffers); |
|
reveman
2015/03/12 19:37:22
Ditto.
emircan
2015/03/12 22:34:26
Done.
|
| + for (int i = 0; i < num_buffers; ++i) { |
| + gfx::GpuMemoryBuffer::Format format = |
| + gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormat(internalformat, |
| + i); |
| + buffers.push_back( |
| + channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( |
| + gfx::Size(width, height), format, |
| + gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage))); |
| + if (!buffers[i]) |
| + return -1; |
| + |
| + client_buffers[i] = buffers[i]->AsClientBuffer(); |
| + } |
| + return CreateImage(client_buffers.data(), width, height, internalformat); |
| } |
| int CommandBufferProxyImpl::GetRouteID() const { |