| 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" | |
| 8 #include "base/bind.h" | 7 #include "base/bind.h" |
| 9 #include "base/logging.h" | 8 #include "base/logging.h" |
| 10 #include "content/common/gpu/client/gpu_memory_buffer_factory_host.h" | 9 #include "content/common/gpu/client/gpu_memory_buffer_factory_host.h" |
| 11 #include "ui/gl/gl_bindings.h" | 10 #include "ui/gl/gl_bindings.h" |
| 12 | 11 |
| 13 namespace content { | 12 namespace content { |
| 14 namespace { | 13 namespace { |
| 15 | 14 |
| 16 base::StaticAtomicSequenceNumber g_next_buffer_id; | 15 void GpuMemoryBufferDeleted(gfx::GpuMemoryBufferId id, |
| 17 | 16 int client_id, |
| 18 void GpuMemoryBufferDeleted(const gfx::GpuMemoryBufferHandle& handle, | |
| 19 uint32 sync_point) { | 17 uint32 sync_point) { |
| 20 GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer(handle, | 18 GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer( |
| 21 sync_point); | 19 gfx::IO_SURFACE_BUFFER, id, client_id, sync_point); |
| 22 } | 20 } |
| 23 | 21 |
| 24 void GpuMemoryBufferCreated( | 22 void GpuMemoryBufferCreated( |
| 25 const gfx::Size& size, | 23 const gfx::Size& size, |
| 26 gfx::GpuMemoryBuffer::Format format, | 24 gfx::GpuMemoryBuffer::Format format, |
| 25 int client_id, |
| 27 const GpuMemoryBufferImpl::CreationCallback& callback, | 26 const GpuMemoryBufferImpl::CreationCallback& callback, |
| 28 const gfx::GpuMemoryBufferHandle& handle) { | 27 const gfx::GpuMemoryBufferHandle& handle) { |
| 29 DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type); | 28 DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type); |
| 30 | 29 |
| 31 callback.Run(GpuMemoryBufferImplIOSurface::CreateFromHandle( | 30 callback.Run(GpuMemoryBufferImplIOSurface::CreateFromHandle( |
| 32 handle, size, format, base::Bind(&GpuMemoryBufferDeleted, handle))); | 31 handle, |
| 32 size, |
| 33 format, |
| 34 base::Bind(&GpuMemoryBufferDeleted, handle.id, client_id))); |
| 33 } | 35 } |
| 34 | 36 |
| 35 void GpuMemoryBufferCreatedForChildProcess( | 37 void GpuMemoryBufferCreatedForChildProcess( |
| 36 const GpuMemoryBufferImpl::AllocationCallback& callback, | 38 const GpuMemoryBufferImpl::AllocationCallback& callback, |
| 37 const gfx::GpuMemoryBufferHandle& handle) { | 39 const gfx::GpuMemoryBufferHandle& handle) { |
| 38 DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type); | 40 DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type); |
| 39 | 41 |
| 40 callback.Run(handle); | 42 callback.Run(handle); |
| 41 } | 43 } |
| 42 | 44 |
| 43 } // namespace | 45 } // namespace |
| 44 | 46 |
| 45 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface( | 47 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface( |
| 48 gfx::GpuMemoryBufferId id, |
| 46 const gfx::Size& size, | 49 const gfx::Size& size, |
| 47 Format format, | 50 Format format, |
| 48 const DestructionCallback& callback, | 51 const DestructionCallback& callback, |
| 49 IOSurfaceRef io_surface) | 52 IOSurfaceRef io_surface) |
| 50 : GpuMemoryBufferImpl(size, format, callback), io_surface_(io_surface) { | 53 : GpuMemoryBufferImpl(id, size, format, callback), io_surface_(io_surface) { |
| 51 } | 54 } |
| 52 | 55 |
| 53 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() { | 56 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() { |
| 54 } | 57 } |
| 55 | 58 |
| 56 // static | 59 // static |
| 57 void GpuMemoryBufferImplIOSurface::Create(const gfx::Size& size, | 60 void GpuMemoryBufferImplIOSurface::Create(gfx::GpuMemoryBufferId id, |
| 61 const gfx::Size& size, |
| 58 Format format, | 62 Format format, |
| 59 int client_id, | 63 int client_id, |
| 60 const CreationCallback& callback) { | 64 const CreationCallback& callback) { |
| 61 gfx::GpuMemoryBufferHandle handle; | |
| 62 handle.type = gfx::IO_SURFACE_BUFFER; | |
| 63 handle.global_id.primary_id = g_next_buffer_id.GetNext(); | |
| 64 handle.global_id.secondary_id = client_id; | |
| 65 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( | 65 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( |
| 66 handle, | 66 gfx::IO_SURFACE_BUFFER, |
| 67 id, |
| 67 size, | 68 size, |
| 68 format, | 69 format, |
| 69 MAP, | 70 MAP, |
| 70 base::Bind(&GpuMemoryBufferCreated, size, format, callback)); | 71 client_id, |
| 72 base::Bind(&GpuMemoryBufferCreated, size, format, client_id, callback)); |
| 71 } | 73 } |
| 72 | 74 |
| 73 // static | 75 // static |
| 74 void GpuMemoryBufferImplIOSurface::AllocateForChildProcess( | 76 void GpuMemoryBufferImplIOSurface::AllocateForChildProcess( |
| 77 gfx::GpuMemoryBufferId id, |
| 75 const gfx::Size& size, | 78 const gfx::Size& size, |
| 76 Format format, | 79 Format format, |
| 77 int child_client_id, | 80 int child_client_id, |
| 78 const AllocationCallback& callback) { | 81 const AllocationCallback& callback) { |
| 79 gfx::GpuMemoryBufferHandle handle; | |
| 80 handle.type = gfx::IO_SURFACE_BUFFER; | |
| 81 handle.global_id.primary_id = g_next_buffer_id.GetNext(); | |
| 82 handle.global_id.secondary_id = child_client_id; | |
| 83 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( | 82 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( |
| 84 handle, | 83 gfx::IO_SURFACE_BUFFER, |
| 84 id, |
| 85 size, | 85 size, |
| 86 format, | 86 format, |
| 87 MAP, | 87 MAP, |
| 88 child_client_id, |
| 88 base::Bind(&GpuMemoryBufferCreatedForChildProcess, callback)); | 89 base::Bind(&GpuMemoryBufferCreatedForChildProcess, callback)); |
| 89 } | 90 } |
| 90 | 91 |
| 91 // static | 92 // static |
| 92 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplIOSurface::CreateFromHandle( | 93 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplIOSurface::CreateFromHandle( |
| 93 const gfx::GpuMemoryBufferHandle& handle, | 94 const gfx::GpuMemoryBufferHandle& handle, |
| 94 const gfx::Size& size, | 95 const gfx::Size& size, |
| 95 Format format, | 96 Format format, |
| 96 const DestructionCallback& callback) { | 97 const DestructionCallback& callback) { |
| 97 DCHECK(IsFormatSupported(format)); | 98 DCHECK(IsFormatSupported(format)); |
| 98 | 99 |
| 99 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( | 100 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( |
| 100 IOSurfaceLookup(handle.io_surface_id)); | 101 IOSurfaceLookup(handle.io_surface_id)); |
| 101 if (!io_surface) | 102 if (!io_surface) |
| 102 return scoped_ptr<GpuMemoryBufferImpl>(); | 103 return scoped_ptr<GpuMemoryBufferImpl>(); |
| 103 | 104 |
| 104 return make_scoped_ptr<GpuMemoryBufferImpl>(new GpuMemoryBufferImplIOSurface( | 105 return make_scoped_ptr<GpuMemoryBufferImpl>(new GpuMemoryBufferImplIOSurface( |
| 105 size, format, callback, io_surface.get())); | 106 handle.id, size, format, callback, io_surface.get())); |
| 106 } | |
| 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 } | 107 } |
| 117 | 108 |
| 118 // static | 109 // static |
| 110 void GpuMemoryBufferImplIOSurface::DeletedByChildProcess( |
| 111 gfx::GpuMemoryBufferId id, |
| 112 int child_client_id, |
| 113 uint32_t sync_point) { |
| 114 GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer( |
| 115 gfx::IO_SURFACE_BUFFER, id, child_client_id, sync_point); |
| 116 } |
| 117 |
| 118 // static |
| 119 bool GpuMemoryBufferImplIOSurface::IsFormatSupported(Format format) { | 119 bool GpuMemoryBufferImplIOSurface::IsFormatSupported(Format format) { |
| 120 switch (format) { | 120 switch (format) { |
| 121 case BGRA_8888: | 121 case BGRA_8888: |
| 122 return true; | 122 return true; |
| 123 case RGBA_8888: | 123 case RGBA_8888: |
| 124 case RGBX_8888: | 124 case RGBX_8888: |
| 125 return false; | 125 return false; |
| 126 } | 126 } |
| 127 | 127 |
| 128 NOTREACHED(); | 128 NOTREACHED(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 mapped_ = false; | 176 mapped_ = false; |
| 177 } | 177 } |
| 178 | 178 |
| 179 uint32 GpuMemoryBufferImplIOSurface::GetStride() const { | 179 uint32 GpuMemoryBufferImplIOSurface::GetStride() const { |
| 180 return IOSurfaceGetBytesPerRow(io_surface_); | 180 return IOSurfaceGetBytesPerRow(io_surface_); |
| 181 } | 181 } |
| 182 | 182 |
| 183 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { | 183 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { |
| 184 gfx::GpuMemoryBufferHandle handle; | 184 gfx::GpuMemoryBufferHandle handle; |
| 185 handle.type = gfx::IO_SURFACE_BUFFER; | 185 handle.type = gfx::IO_SURFACE_BUFFER; |
| 186 handle.id = id_; |
| 186 handle.io_surface_id = IOSurfaceGetID(io_surface_); | 187 handle.io_surface_id = IOSurfaceGetID(io_surface_); |
| 187 return handle; | 188 return handle; |
| 188 } | 189 } |
| 189 | 190 |
| 190 } // namespace content | 191 } // namespace content |
| OLD | NEW |