Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / content / child / child_gpu_memory_buffer_manager.cc
blob9a7517d7b8d358bc235e59fe81da4e0764b26c06
1 // Copyright 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/child/child_gpu_memory_buffer_manager.h"
7 #include "content/common/child_process_messages.h"
8 #include "content/common/gpu/client/gpu_memory_buffer_impl.h"
10 namespace content {
11 namespace {
13 void DeletedGpuMemoryBuffer(ThreadSafeSender* sender,
14 gfx::GpuMemoryBufferId id,
15 uint32 sync_point) {
16 TRACE_EVENT0("renderer",
17 "ChildGpuMemoryBufferManager::DeletedGpuMemoryBuffer");
18 sender->Send(new ChildProcessHostMsg_DeletedGpuMemoryBuffer(id, sync_point));
21 } // namespace
23 ChildGpuMemoryBufferManager::ChildGpuMemoryBufferManager(
24 ThreadSafeSender* sender)
25 : sender_(sender) {
28 ChildGpuMemoryBufferManager::~ChildGpuMemoryBufferManager() {
31 scoped_ptr<gfx::GpuMemoryBuffer>
32 ChildGpuMemoryBufferManager::AllocateGpuMemoryBuffer(const gfx::Size& size,
33 gfx::BufferFormat format,
34 gfx::BufferUsage usage) {
35 TRACE_EVENT2("renderer",
36 "ChildGpuMemoryBufferManager::AllocateGpuMemoryBuffer",
37 "width",
38 size.width(),
39 "height",
40 size.height());
42 gfx::GpuMemoryBufferHandle handle;
43 IPC::Message* message = new ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer(
44 size.width(), size.height(), format, usage, &handle);
45 bool success = sender_->Send(message);
46 if (!success || handle.is_null())
47 return nullptr;
49 scoped_ptr<GpuMemoryBufferImpl> buffer(GpuMemoryBufferImpl::CreateFromHandle(
50 handle, size, format, usage,
51 base::Bind(&DeletedGpuMemoryBuffer, sender_, handle.id)));
52 if (!buffer) {
53 sender_->Send(new ChildProcessHostMsg_DeletedGpuMemoryBuffer(handle.id, 0));
54 return nullptr;
57 return buffer.Pass();
60 gfx::GpuMemoryBuffer*
61 ChildGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer(
62 ClientBuffer buffer) {
63 return GpuMemoryBufferImpl::FromClientBuffer(buffer);
66 void ChildGpuMemoryBufferManager::SetDestructionSyncPoint(
67 gfx::GpuMemoryBuffer* buffer,
68 uint32 sync_point) {
69 static_cast<GpuMemoryBufferImpl*>(buffer)
70 ->set_destruction_sync_point(sync_point);
73 } // namespace content