egl: Don't query EGL_POST_SUB_BUFFER_SUPPORTED_NV without extension
[chromium-blink-merge.git] / content / child / child_gpu_memory_buffer_manager.cc
blob7cb793d5240c112e0e64134c571dcba8f1c77a06
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/child/child_thread.h"
8 #include "content/common/child_process_messages.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(
34 const gfx::Size& size,
35 gfx::GpuMemoryBuffer::Format format,
36 gfx::GpuMemoryBuffer::Usage usage) {
37 TRACE_EVENT2("renderer",
38 "ChildGpuMemoryBufferManager::AllocateGpuMemoryBuffer",
39 "width",
40 size.width(),
41 "height",
42 size.height());
44 gfx::GpuMemoryBufferHandle handle;
45 IPC::Message* message = new ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer(
46 size.width(), size.height(), format, usage, &handle);
47 bool success = sender_->Send(message);
48 if (!success)
49 return scoped_ptr<gfx::GpuMemoryBuffer>();
51 scoped_ptr<GpuMemoryBufferImpl> buffer(GpuMemoryBufferImpl::CreateFromHandle(
52 handle,
53 size,
54 format,
55 base::Bind(&DeletedGpuMemoryBuffer, sender_, handle.id)));
56 if (!buffer) {
57 sender_->Send(new ChildProcessHostMsg_DeletedGpuMemoryBuffer(handle.id, 0));
58 return scoped_ptr<gfx::GpuMemoryBuffer>();
61 return buffer.Pass();
64 gfx::GpuMemoryBuffer*
65 ChildGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer(
66 ClientBuffer buffer) {
67 return GpuMemoryBufferImpl::FromClientBuffer(buffer);
70 void ChildGpuMemoryBufferManager::SetDestructionSyncPoint(
71 gfx::GpuMemoryBuffer* buffer,
72 uint32 sync_point) {
73 static_cast<GpuMemoryBufferImpl*>(buffer)
74 ->set_destruction_sync_point(sync_point);
77 } // namespace content