OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" | 5 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" |
6 | 6 |
7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "content/common/gpu/client/gpu_memory_buffer_factory_host.h" | 10 #include "content/common/gpu/client/gpu_memory_buffer_factory_host.h" |
11 #include "ui/gl/gl_bindings.h" | 11 #include "ui/gl/gl_bindings.h" |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 namespace { | 14 namespace { |
15 | 15 |
16 base::StaticAtomicSequenceNumber g_next_buffer_id; | 16 base::StaticAtomicSequenceNumber g_next_buffer_id; |
17 | 17 |
18 void Noop() { | 18 void GpuMemoryBufferDeleted(const gfx::GpuMemoryBufferHandle& handle, |
| 19 uint32 sync_point) { |
| 20 GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer(handle, |
| 21 sync_point); |
19 } | 22 } |
20 | 23 |
21 void GpuMemoryBufferCreated( | 24 void GpuMemoryBufferCreated( |
22 const gfx::Size& size, | 25 const gfx::Size& size, |
23 gfx::GpuMemoryBuffer::Format format, | 26 gfx::GpuMemoryBuffer::Format format, |
24 const GpuMemoryBufferImpl::CreationCallback& callback, | 27 const GpuMemoryBufferImpl::CreationCallback& callback, |
25 const gfx::GpuMemoryBufferHandle& handle) { | 28 const gfx::GpuMemoryBufferHandle& handle) { |
26 DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type); | 29 DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type); |
27 | 30 |
28 callback.Run(GpuMemoryBufferImplIOSurface::CreateFromHandle( | 31 callback.Run(GpuMemoryBufferImplIOSurface::CreateFromHandle( |
29 handle, size, format, base::Bind(&Noop))); | 32 handle, size, format, base::Bind(&GpuMemoryBufferDeleted, handle))); |
30 } | 33 } |
31 | 34 |
32 void GpuMemoryBufferCreatedForChildProcess( | 35 void GpuMemoryBufferCreatedForChildProcess( |
33 const GpuMemoryBufferImpl::AllocationCallback& callback, | 36 const GpuMemoryBufferImpl::AllocationCallback& callback, |
34 const gfx::GpuMemoryBufferHandle& handle) { | 37 const gfx::GpuMemoryBufferHandle& handle) { |
35 DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type); | 38 DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type); |
36 | 39 |
37 callback.Run(handle); | 40 callback.Run(handle); |
38 } | 41 } |
39 | 42 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 98 |
96 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( | 99 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( |
97 IOSurfaceLookup(handle.io_surface_id)); | 100 IOSurfaceLookup(handle.io_surface_id)); |
98 if (!io_surface) | 101 if (!io_surface) |
99 return scoped_ptr<GpuMemoryBufferImpl>(); | 102 return scoped_ptr<GpuMemoryBufferImpl>(); |
100 | 103 |
101 return make_scoped_ptr<GpuMemoryBufferImpl>(new GpuMemoryBufferImplIOSurface( | 104 return make_scoped_ptr<GpuMemoryBufferImpl>(new GpuMemoryBufferImplIOSurface( |
102 size, format, callback, io_surface.get())); | 105 size, format, callback, io_surface.get())); |
103 } | 106 } |
104 | 107 |
| 108 void GpuMemoryBufferImplIOSurface::DeletedByChildProcess( |
| 109 const gfx::GpuMemoryBufferId& id, |
| 110 uint32_t sync_point) { |
| 111 gfx::GpuMemoryBufferHandle handle; |
| 112 handle.type = gfx::IO_SURFACE_BUFFER; |
| 113 handle.global_id = id; |
| 114 GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer(handle, |
| 115 sync_point); |
| 116 } |
| 117 |
105 // static | 118 // static |
106 bool GpuMemoryBufferImplIOSurface::IsFormatSupported(Format format) { | 119 bool GpuMemoryBufferImplIOSurface::IsFormatSupported(Format format) { |
107 switch (format) { | 120 switch (format) { |
108 case BGRA_8888: | 121 case BGRA_8888: |
109 return true; | 122 return true; |
110 case RGBA_8888: | 123 case RGBA_8888: |
111 case RGBX_8888: | 124 case RGBX_8888: |
112 return false; | 125 return false; |
113 } | 126 } |
114 | 127 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 181 } |
169 | 182 |
170 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { | 183 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { |
171 gfx::GpuMemoryBufferHandle handle; | 184 gfx::GpuMemoryBufferHandle handle; |
172 handle.type = gfx::IO_SURFACE_BUFFER; | 185 handle.type = gfx::IO_SURFACE_BUFFER; |
173 handle.io_surface_id = IOSurfaceGetID(io_surface_); | 186 handle.io_surface_id = IOSurfaceGetID(io_surface_); |
174 return handle; | 187 return handle; |
175 } | 188 } |
176 | 189 |
177 } // namespace content | 190 } // namespace content |
OLD | NEW |