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/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h"
7 #include "base/atomic_sequence_num.h"
9 #include "content/common/gpu/client/gpu_memory_buffer_factory_host.h"
10 #include "ui/gl/gl_bindings.h"
15 base::StaticAtomicSequenceNumber g_next_buffer_id;
20 void GpuMemoryBufferCreated(
21 const gfx::Size& size,
22 unsigned internalformat,
23 const GpuMemoryBufferImpl::CreationCallback& callback,
24 const gfx::GpuMemoryBufferHandle& handle) {
25 DCHECK_EQ(gfx::OZONE_NATIVE_BUFFER, handle.type);
27 callback.Run(GpuMemoryBufferImplOzoneNativeBuffer::CreateFromHandle(
28 handle, size, internalformat, base::Bind(&Noop)));
31 void GpuMemoryBufferCreatedForChildProcess(
32 const GpuMemoryBufferImpl::AllocationCallback& callback,
33 const gfx::GpuMemoryBufferHandle& handle) {
34 DCHECK_EQ(gfx::OZONE_NATIVE_BUFFER, handle.type);
41 GpuMemoryBufferImplOzoneNativeBuffer::GpuMemoryBufferImplOzoneNativeBuffer(
42 const gfx::Size& size,
43 unsigned internalformat,
44 const DestructionCallback& callback,
45 const gfx::GpuMemoryBufferId& id)
46 : GpuMemoryBufferImpl(size, internalformat, callback), id_(id) {
49 GpuMemoryBufferImplOzoneNativeBuffer::~GpuMemoryBufferImplOzoneNativeBuffer() {
53 void GpuMemoryBufferImplOzoneNativeBuffer::Create(
54 const gfx::Size& size,
55 unsigned internalformat,
58 const CreationCallback& callback) {
59 gfx::GpuMemoryBufferHandle handle;
60 handle.global_id.primary_id = g_next_buffer_id.GetNext();
61 handle.global_id.secondary_id = client_id;
62 handle.type = gfx::OZONE_NATIVE_BUFFER;
63 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer(
68 base::Bind(&GpuMemoryBufferCreated, size, internalformat, callback));
72 void GpuMemoryBufferImplOzoneNativeBuffer::AllocateForChildProcess(
73 const gfx::Size& size,
74 unsigned internalformat,
77 const AllocationCallback& callback) {
78 gfx::GpuMemoryBufferHandle handle;
79 handle.global_id.primary_id = g_next_buffer_id.GetNext();
80 handle.global_id.secondary_id = child_client_id;
81 handle.type = gfx::OZONE_NATIVE_BUFFER;
82 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer(
87 base::Bind(&GpuMemoryBufferCreatedForChildProcess, callback));
91 scoped_ptr<GpuMemoryBufferImpl>
92 GpuMemoryBufferImplOzoneNativeBuffer::CreateFromHandle(
93 const gfx::GpuMemoryBufferHandle& handle,
94 const gfx::Size& size,
95 unsigned internalformat,
96 const DestructionCallback& callback) {
97 DCHECK(IsFormatSupported(internalformat));
99 return make_scoped_ptr<GpuMemoryBufferImpl>(
100 new GpuMemoryBufferImplOzoneNativeBuffer(
101 size, internalformat, callback, handle.global_id));
105 bool GpuMemoryBufferImplOzoneNativeBuffer::IsFormatSupported(
106 unsigned internalformat) {
107 switch (internalformat) {
117 bool GpuMemoryBufferImplOzoneNativeBuffer::IsUsageSupported(unsigned usage) {
119 case GL_IMAGE_SCANOUT_CHROMIUM:
127 bool GpuMemoryBufferImplOzoneNativeBuffer::IsConfigurationSupported(
128 unsigned internalformat,
130 return IsFormatSupported(internalformat) && IsUsageSupported(usage);
133 void* GpuMemoryBufferImplOzoneNativeBuffer::Map() {
138 void GpuMemoryBufferImplOzoneNativeBuffer::Unmap() {
142 uint32 GpuMemoryBufferImplOzoneNativeBuffer::GetStride() const {
147 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativeBuffer::GetHandle()
149 gfx::GpuMemoryBufferHandle handle;
150 handle.type = gfx::OZONE_NATIVE_BUFFER;
151 handle.global_id = id_;
155 } // namespace content