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
3 // found in the LICENSE file.
5 #include "content/browser/gpu/gpu_memory_buffer_factory_host_impl.h"
8 #include "content/browser/gpu/gpu_process_host.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "ui/gfx/gpu_memory_buffer.h"
14 GpuMemoryBufferFactoryHostImpl::GpuMemoryBufferFactoryHostImpl()
15 : gpu_host_id_(0), next_create_gpu_memory_buffer_request_id_(0) {
18 GpuMemoryBufferFactoryHostImpl::~GpuMemoryBufferFactoryHostImpl() {
21 void GpuMemoryBufferFactoryHostImpl::CreateGpuMemoryBuffer(
22 gfx::GpuMemoryBufferType type,
23 gfx::GpuMemoryBufferId id,
24 const gfx::Size& size,
25 gfx::GpuMemoryBuffer::Format format,
26 gfx::GpuMemoryBuffer::Usage usage,
28 const CreateGpuMemoryBufferCallback& callback) {
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
31 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_);
33 callback.Run(gfx::GpuMemoryBufferHandle());
37 uint32 request_id = next_create_gpu_memory_buffer_request_id_++;
38 create_gpu_memory_buffer_requests_[request_id] = callback;
40 host->CreateGpuMemoryBuffer(
47 base::Bind(&GpuMemoryBufferFactoryHostImpl::OnGpuMemoryBufferCreated,
48 base::Unretained(this),
52 void GpuMemoryBufferFactoryHostImpl::DestroyGpuMemoryBuffer(
53 gfx::GpuMemoryBufferType type,
54 gfx::GpuMemoryBufferId id,
57 BrowserThread::PostTask(
60 base::Bind(&GpuMemoryBufferFactoryHostImpl::DestroyGpuMemoryBufferOnIO,
61 base::Unretained(this),
68 void GpuMemoryBufferFactoryHostImpl::DestroyGpuMemoryBufferOnIO(
69 gfx::GpuMemoryBufferType type,
70 gfx::GpuMemoryBufferId id,
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
75 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_);
79 host->DestroyGpuMemoryBuffer(type, id, client_id, sync_point);
82 void GpuMemoryBufferFactoryHostImpl::OnGpuMemoryBufferCreated(
84 const gfx::GpuMemoryBufferHandle& handle) {
85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
87 CreateGpuMemoryBufferCallbackMap::iterator iter =
88 create_gpu_memory_buffer_requests_.find(request_id);
89 DCHECK(iter != create_gpu_memory_buffer_requests_.end());
90 iter->second.Run(handle);
91 create_gpu_memory_buffer_requests_.erase(iter);
94 } // namespace content