| 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 gfx::GpuMemoryBufferType type, |
| 23 gfx::GpuMemoryBufferId id, |
| 23 const gfx::Size& size, | 24 const gfx::Size& size, |
| 24 gfx::GpuMemoryBuffer::Format format, | 25 gfx::GpuMemoryBuffer::Format format, |
| 25 gfx::GpuMemoryBuffer::Usage usage, | 26 gfx::GpuMemoryBuffer::Usage usage, |
| 27 int client_id, |
| 26 const CreateGpuMemoryBufferCallback& callback) { | 28 const CreateGpuMemoryBufferCallback& callback) { |
| 27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 28 | 30 |
| 29 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); | 31 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); |
| 30 if (!host) { | 32 if (!host) { |
| 31 callback.Run(gfx::GpuMemoryBufferHandle()); | 33 callback.Run(gfx::GpuMemoryBufferHandle()); |
| 32 return; | 34 return; |
| 33 } | 35 } |
| 34 | 36 |
| 35 uint32 request_id = next_create_gpu_memory_buffer_request_id_++; | 37 uint32 request_id = next_create_gpu_memory_buffer_request_id_++; |
| 36 create_gpu_memory_buffer_requests_[request_id] = callback; | 38 create_gpu_memory_buffer_requests_[request_id] = callback; |
| 37 | 39 |
| 38 host->CreateGpuMemoryBuffer( | 40 host->CreateGpuMemoryBuffer( |
| 39 handle, | 41 type, |
| 42 id, |
| 40 size, | 43 size, |
| 41 format, | 44 format, |
| 42 usage, | 45 usage, |
| 46 client_id, |
| 43 base::Bind(&GpuMemoryBufferFactoryHostImpl::OnGpuMemoryBufferCreated, | 47 base::Bind(&GpuMemoryBufferFactoryHostImpl::OnGpuMemoryBufferCreated, |
| 44 base::Unretained(this), | 48 base::Unretained(this), |
| 45 request_id)); | 49 request_id)); |
| 46 } | 50 } |
| 47 | 51 |
| 48 void GpuMemoryBufferFactoryHostImpl::DestroyGpuMemoryBuffer( | 52 void GpuMemoryBufferFactoryHostImpl::DestroyGpuMemoryBuffer( |
| 49 const gfx::GpuMemoryBufferHandle& handle, | 53 gfx::GpuMemoryBufferType type, |
| 54 gfx::GpuMemoryBufferId id, |
| 55 int client_id, |
| 50 int32 sync_point) { | 56 int32 sync_point) { |
| 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 52 | 58 |
| 53 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); | 59 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); |
| 54 if (!host) | 60 if (!host) |
| 55 return; | 61 return; |
| 56 | 62 |
| 57 host->DestroyGpuMemoryBuffer(handle, sync_point); | 63 host->DestroyGpuMemoryBuffer(type, id, client_id, sync_point); |
| 58 } | 64 } |
| 59 | 65 |
| 60 void GpuMemoryBufferFactoryHostImpl::OnGpuMemoryBufferCreated( | 66 void GpuMemoryBufferFactoryHostImpl::OnGpuMemoryBufferCreated( |
| 61 uint32 request_id, | 67 uint32 request_id, |
| 62 const gfx::GpuMemoryBufferHandle& handle) { | 68 const gfx::GpuMemoryBufferHandle& handle) { |
| 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 64 | 70 |
| 65 CreateGpuMemoryBufferCallbackMap::iterator iter = | 71 CreateGpuMemoryBufferCallbackMap::iterator iter = |
| 66 create_gpu_memory_buffer_requests_.find(request_id); | 72 create_gpu_memory_buffer_requests_.find(request_id); |
| 67 DCHECK(iter != create_gpu_memory_buffer_requests_.end()); | 73 DCHECK(iter != create_gpu_memory_buffer_requests_.end()); |
| 68 iter->second.Run(handle); | 74 iter->second.Run(handle); |
| 69 create_gpu_memory_buffer_requests_.erase(iter); | 75 create_gpu_memory_buffer_requests_.erase(iter); |
| 70 } | 76 } |
| 71 | 77 |
| 72 } // namespace content | 78 } // namespace content |
| OLD | NEW |