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"
8 #include "content/common/gpu/client/gpu_memory_buffer_factory_host.h"
9 #include "ui/gl/gl_bindings.h"
14 void GpuMemoryBufferDeleted(gfx::GpuMemoryBufferId id,
17 GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer(
18 gfx::OZONE_NATIVE_BUFFER, id, client_id, sync_point);
21 void GpuMemoryBufferCreated(
22 const gfx::Size& size,
23 gfx::GpuMemoryBuffer::Format format,
25 const GpuMemoryBufferImpl::CreationCallback& callback,
26 const gfx::GpuMemoryBufferHandle& handle) {
27 if (handle.is_null()) {
28 callback.Run(scoped_ptr<GpuMemoryBufferImpl>());
32 DCHECK_EQ(gfx::OZONE_NATIVE_BUFFER, handle.type);
33 callback.Run(GpuMemoryBufferImplOzoneNativeBuffer::CreateFromHandle(
37 base::Bind(&GpuMemoryBufferDeleted, handle.id, client_id)));
40 void GpuMemoryBufferCreatedForChildProcess(
41 const GpuMemoryBufferImpl::AllocationCallback& callback,
42 const gfx::GpuMemoryBufferHandle& handle) {
43 DCHECK_IMPLIES(!handle.is_null(), gfx::OZONE_NATIVE_BUFFER == handle.type);
50 GpuMemoryBufferImplOzoneNativeBuffer::GpuMemoryBufferImplOzoneNativeBuffer(
51 gfx::GpuMemoryBufferId id,
52 const gfx::Size& size,
54 const DestructionCallback& callback)
55 : GpuMemoryBufferImpl(id, size, format, callback) {
58 GpuMemoryBufferImplOzoneNativeBuffer::~GpuMemoryBufferImplOzoneNativeBuffer() {
62 void GpuMemoryBufferImplOzoneNativeBuffer::Create(
63 gfx::GpuMemoryBufferId id,
64 const gfx::Size& size,
67 const CreationCallback& callback) {
68 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer(
69 gfx::OZONE_NATIVE_BUFFER,
75 base::Bind(&GpuMemoryBufferCreated, size, format, client_id, callback));
79 void GpuMemoryBufferImplOzoneNativeBuffer::AllocateForChildProcess(
80 gfx::GpuMemoryBufferId id,
81 const gfx::Size& size,
84 const AllocationCallback& callback) {
85 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer(
86 gfx::OZONE_NATIVE_BUFFER,
92 base::Bind(&GpuMemoryBufferCreatedForChildProcess, callback));
96 scoped_ptr<GpuMemoryBufferImpl>
97 GpuMemoryBufferImplOzoneNativeBuffer::CreateFromHandle(
98 const gfx::GpuMemoryBufferHandle& handle,
99 const gfx::Size& size,
101 const DestructionCallback& callback) {
102 DCHECK(IsFormatSupported(format));
104 return make_scoped_ptr<GpuMemoryBufferImpl>(
105 new GpuMemoryBufferImplOzoneNativeBuffer(
106 handle.id, size, format, callback));
110 void GpuMemoryBufferImplOzoneNativeBuffer::DeletedByChildProcess(
111 gfx::GpuMemoryBufferId id,
113 uint32_t sync_point) {
114 GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer(
115 gfx::OZONE_NATIVE_BUFFER, id, child_client_id, sync_point);
119 bool GpuMemoryBufferImplOzoneNativeBuffer::IsFormatSupported(Format format) {
133 bool GpuMemoryBufferImplOzoneNativeBuffer::IsUsageSupported(Usage usage) {
146 bool GpuMemoryBufferImplOzoneNativeBuffer::IsConfigurationSupported(
149 return IsFormatSupported(format) && IsUsageSupported(usage);
152 void* GpuMemoryBufferImplOzoneNativeBuffer::Map() {
157 void GpuMemoryBufferImplOzoneNativeBuffer::Unmap() {
161 uint32 GpuMemoryBufferImplOzoneNativeBuffer::GetStride() const {
166 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativeBuffer::GetHandle()
168 gfx::GpuMemoryBufferHandle handle;
169 handle.type = gfx::OZONE_NATIVE_BUFFER;
174 } // namespace content