Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 "content/browser/gpu/gpu_memory_buffer_factory_host_impl.h" | 5 #include "content/browser/gpu/gpu_memory_buffer_factory_host_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "content/browser/gpu/gpu_process_host.h" | 8 #include "content/browser/gpu/gpu_process_host.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "ui/gfx/gpu_memory_buffer.h" | 10 #include "ui/gfx/gpu_memory_buffer.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 | 13 |
| 14 GpuMemoryBufferFactoryHostImpl::GpuMemoryBufferFactoryHostImpl() | 14 GpuMemoryBufferFactoryHostImpl::GpuMemoryBufferFactoryHostImpl() |
| 15 : gpu_host_id_(0), next_create_gpu_memory_buffer_request_id_(0) { | 15 : gpu_host_id_(0), next_create_gpu_memory_buffer_request_id_(0) { |
| 16 } | 16 } |
| 17 | 17 |
| 18 GpuMemoryBufferFactoryHostImpl::~GpuMemoryBufferFactoryHostImpl() { | 18 GpuMemoryBufferFactoryHostImpl::~GpuMemoryBufferFactoryHostImpl() { |
| 19 } | 19 } |
| 20 | 20 |
| 21 void GpuMemoryBufferFactoryHostImpl::CreateGpuMemoryBuffer( | 21 void GpuMemoryBufferFactoryHostImpl::CreateGpuMemoryBuffer( |
| 22 const gfx::GpuMemoryBufferHandle& handle, | 22 const gfx::GpuMemoryBufferHandle& handle, |
| 23 const gfx::Size& size, | 23 const gfx::Size& size, |
| 24 gfx::GpuMemoryBuffer::Format format, | 24 gfx::GpuMemoryBuffer::Format format, |
| 25 gfx::GpuMemoryBuffer::Usage usage, | 25 gfx::GpuMemoryBuffer::Usage usage, |
| 26 const CreateGpuMemoryBufferCallback& callback) { | 26 const CreateGpuMemoryBufferCallback& callback) { |
| 27 BrowserThread::PostTask( | |
| 28 BrowserThread::IO, FROM_HERE, | |
| 29 base::Bind(&GpuMemoryBufferFactoryHostImpl::CreateGpuMemoryBufferOnIO, | |
| 30 base::Unretained(this), handle, size, format, usage, | |
| 31 callback)); | |
|
reveman
2014/11/03 22:26:12
nit: cl format?
| |
| 32 } | |
| 33 | |
| 34 void GpuMemoryBufferFactoryHostImpl::CreateGpuMemoryBufferOnIO( | |
| 35 const gfx::GpuMemoryBufferHandle& handle, | |
| 36 const gfx::Size& size, | |
| 37 gfx::GpuMemoryBuffer::Format format, | |
| 38 gfx::GpuMemoryBuffer::Usage usage, | |
| 39 const CreateGpuMemoryBufferCallback& callback) { | |
| 27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 28 | 41 |
| 29 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); | 42 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); |
| 30 if (!host) { | 43 if (!host) { |
| 31 callback.Run(gfx::GpuMemoryBufferHandle()); | 44 callback.Run(gfx::GpuMemoryBufferHandle()); |
| 32 return; | 45 return; |
| 33 } | 46 } |
| 34 | 47 |
| 35 uint32 request_id = next_create_gpu_memory_buffer_request_id_++; | 48 uint32 request_id = next_create_gpu_memory_buffer_request_id_++; |
| 36 create_gpu_memory_buffer_requests_[request_id] = callback; | 49 create_gpu_memory_buffer_requests_[request_id] = callback; |
| 37 | 50 |
| 38 host->CreateGpuMemoryBuffer( | 51 host->CreateGpuMemoryBuffer( |
| 39 handle, | 52 handle, |
| 40 size, | 53 size, |
| 41 format, | 54 format, |
| 42 usage, | 55 usage, |
| 43 base::Bind(&GpuMemoryBufferFactoryHostImpl::OnGpuMemoryBufferCreated, | 56 base::Bind(&GpuMemoryBufferFactoryHostImpl::OnGpuMemoryBufferCreated, |
| 44 base::Unretained(this), | 57 base::Unretained(this), |
| 45 request_id)); | 58 request_id)); |
| 46 } | 59 } |
| 47 | 60 |
| 48 void GpuMemoryBufferFactoryHostImpl::DestroyGpuMemoryBuffer( | 61 void GpuMemoryBufferFactoryHostImpl::DestroyGpuMemoryBuffer( |
| 49 const gfx::GpuMemoryBufferHandle& handle, | 62 const gfx::GpuMemoryBufferHandle& handle, |
| 50 int32 sync_point) { | 63 int32 sync_point) { |
| 64 BrowserThread::PostTask( | |
| 65 BrowserThread::IO, FROM_HERE, | |
| 66 base::Bind(&GpuMemoryBufferFactoryHostImpl::DestroyGpuMemoryBufferOnIO, | |
| 67 base::Unretained(this), handle, sync_point)); | |
|
reveman
2014/11/03 22:26:12
nit: cl format?
alexst (slow to review)
2014/11/03 22:47:42
I was as surprised as you, this is the result of '
| |
| 68 } | |
| 69 | |
| 70 void GpuMemoryBufferFactoryHostImpl::DestroyGpuMemoryBufferOnIO( | |
| 71 const gfx::GpuMemoryBufferHandle& handle, | |
| 72 int32 sync_point) { | |
| 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 52 | 74 |
| 53 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); | 75 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); |
| 54 if (!host) | 76 if (!host) |
| 55 return; | 77 return; |
| 56 | 78 |
| 57 host->DestroyGpuMemoryBuffer(handle, sync_point); | 79 host->DestroyGpuMemoryBuffer(handle, sync_point); |
| 58 } | 80 } |
| 59 | 81 |
| 60 void GpuMemoryBufferFactoryHostImpl::OnGpuMemoryBufferCreated( | 82 void GpuMemoryBufferFactoryHostImpl::OnGpuMemoryBufferCreated( |
| 61 uint32 request_id, | 83 uint32 request_id, |
| 62 const gfx::GpuMemoryBufferHandle& handle) { | 84 const gfx::GpuMemoryBufferHandle& handle) { |
| 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 64 | 86 |
| 65 CreateGpuMemoryBufferCallbackMap::iterator iter = | 87 CreateGpuMemoryBufferCallbackMap::iterator iter = |
| 66 create_gpu_memory_buffer_requests_.find(request_id); | 88 create_gpu_memory_buffer_requests_.find(request_id); |
| 67 DCHECK(iter != create_gpu_memory_buffer_requests_.end()); | 89 DCHECK(iter != create_gpu_memory_buffer_requests_.end()); |
| 68 iter->second.Run(handle); | 90 iter->second.Run(handle); |
| 69 create_gpu_memory_buffer_requests_.erase(iter); | 91 create_gpu_memory_buffer_requests_.erase(iter); |
| 70 } | 92 } |
| 71 | 93 |
| 72 } // namespace content | 94 } // namespace content |
| OLD | NEW |