Make USB permissions work in the new permission message system
[chromium-blink-merge.git] / content / child / child_gpu_memory_buffer_manager.cc
blob1c7b67bcc5c6ce7a559869884432a6d1cd598fa6
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/generic_shared_memory_id_generator.h"
9 #include "content/common/gpu/client/gpu_memory_buffer_impl.h"
11 namespace content {
12 namespace {
14 void DeletedGpuMemoryBuffer(ThreadSafeSender* sender,
15 gfx::GpuMemoryBufferId id,
16 uint32 sync_point) {
17 TRACE_EVENT0("renderer",
18 "ChildGpuMemoryBufferManager::DeletedGpuMemoryBuffer");
19 sender->Send(new ChildProcessHostMsg_DeletedGpuMemoryBuffer(id, sync_point));
22 } // namespace
24 ChildGpuMemoryBufferManager::ChildGpuMemoryBufferManager(
25 ThreadSafeSender* sender)
26 : sender_(sender) {
29 ChildGpuMemoryBufferManager::~ChildGpuMemoryBufferManager() {
32 scoped_ptr<gfx::GpuMemoryBuffer>
33 ChildGpuMemoryBufferManager::AllocateGpuMemoryBuffer(const gfx::Size& size,
34 gfx::BufferFormat format,
35 gfx::BufferUsage usage) {
36 TRACE_EVENT2("renderer",
37 "ChildGpuMemoryBufferManager::AllocateGpuMemoryBuffer",
38 "width",
39 size.width(),
40 "height",
41 size.height());
43 gfx::GpuMemoryBufferHandle handle;
44 IPC::Message* message = new ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer(
45 content::GetNextGenericSharedMemoryId(), size.width(), size.height(),
46 format, usage, &handle);
47 bool success = sender_->Send(message);
48 if (!success || handle.is_null())
49 return nullptr;
51 scoped_ptr<GpuMemoryBufferImpl> buffer(GpuMemoryBufferImpl::CreateFromHandle(
52 handle, size, format, usage,
53 base::Bind(&DeletedGpuMemoryBuffer, sender_, handle.id)));
54 if (!buffer) {
55 sender_->Send(new ChildProcessHostMsg_DeletedGpuMemoryBuffer(handle.id, 0));
56 return nullptr;
59 return buffer.Pass();
62 gfx::GpuMemoryBuffer*
63 ChildGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer(
64 ClientBuffer buffer) {
65 return GpuMemoryBufferImpl::FromClientBuffer(buffer);
68 void ChildGpuMemoryBufferManager::SetDestructionSyncPoint(
69 gfx::GpuMemoryBuffer* buffer,
70 uint32 sync_point) {
71 static_cast<GpuMemoryBufferImpl*>(buffer)
72 ->set_destruction_sync_point(sync_point);
75 } // namespace content