| 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.h" | 5 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" |
| 6 | 6 |
| 7 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" | 7 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" |
| 8 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" | 8 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| 11 | 11 |
| 12 // static | 12 // static |
| 13 void GpuMemoryBufferImpl::Create(const gfx::Size& size, | 13 void GpuMemoryBufferImpl::Create(gfx::GpuMemoryBufferId id, |
| 14 const gfx::Size& size, |
| 14 Format format, | 15 Format format, |
| 15 Usage usage, | 16 Usage usage, |
| 16 int client_id, | 17 int client_id, |
| 17 const CreationCallback& callback) { | 18 const CreationCallback& callback) { |
| 18 if (GpuMemoryBufferImplIOSurface::IsConfigurationSupported(format, usage)) { | 19 if (GpuMemoryBufferImplIOSurface::IsConfigurationSupported(format, usage)) { |
| 19 GpuMemoryBufferImplIOSurface::Create(size, format, client_id, callback); | 20 GpuMemoryBufferImplIOSurface::Create(id, size, format, client_id, callback); |
| 20 return; | 21 return; |
| 21 } | 22 } |
| 22 | 23 |
| 23 if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported( | 24 if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported( |
| 24 size, format, usage)) { | 25 size, format, usage)) { |
| 25 GpuMemoryBufferImplSharedMemory::Create(size, format, callback); | 26 GpuMemoryBufferImplSharedMemory::Create(id, size, format, callback); |
| 26 return; | 27 return; |
| 27 } | 28 } |
| 28 | 29 |
| 29 callback.Run(scoped_ptr<GpuMemoryBufferImpl>()); | 30 callback.Run(scoped_ptr<GpuMemoryBufferImpl>()); |
| 30 } | 31 } |
| 31 | 32 |
| 32 // static | 33 // static |
| 33 void GpuMemoryBufferImpl::AllocateForChildProcess( | 34 void GpuMemoryBufferImpl::AllocateForChildProcess( |
| 35 gfx::GpuMemoryBufferId id, |
| 34 const gfx::Size& size, | 36 const gfx::Size& size, |
| 35 Format format, | 37 Format format, |
| 36 Usage usage, | 38 Usage usage, |
| 37 base::ProcessHandle child_process, | 39 base::ProcessHandle child_process, |
| 38 int child_client_id, | 40 int child_client_id, |
| 39 const AllocationCallback& callback) { | 41 const AllocationCallback& callback) { |
| 40 if (GpuMemoryBufferImplIOSurface::IsConfigurationSupported(format, usage)) { | 42 if (GpuMemoryBufferImplIOSurface::IsConfigurationSupported(format, usage)) { |
| 41 GpuMemoryBufferImplIOSurface::AllocateForChildProcess( | 43 GpuMemoryBufferImplIOSurface::AllocateForChildProcess( |
| 42 size, format, child_client_id, callback); | 44 id, size, format, child_client_id, callback); |
| 43 return; | 45 return; |
| 44 } | 46 } |
| 45 | 47 |
| 46 if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported( | 48 if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported( |
| 47 size, format, usage)) { | 49 size, format, usage)) { |
| 48 GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( | 50 GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( |
| 49 size, format, child_process, callback); | 51 id, size, format, child_process, callback); |
| 50 return; | 52 return; |
| 51 } | 53 } |
| 52 | 54 |
| 53 callback.Run(gfx::GpuMemoryBufferHandle()); | 55 callback.Run(gfx::GpuMemoryBufferHandle()); |
| 54 } | 56 } |
| 55 | 57 |
| 56 // static | 58 // static |
| 57 void GpuMemoryBufferImpl::DeletedByChildProcess( | 59 void GpuMemoryBufferImpl::DeletedByChildProcess( |
| 58 gfx::GpuMemoryBufferType type, | 60 gfx::GpuMemoryBufferType type, |
| 59 const gfx::GpuMemoryBufferId& id, | 61 gfx::GpuMemoryBufferId id, |
| 60 base::ProcessHandle child_process, | 62 base::ProcessHandle child_process, |
| 61 int child_client_id, | 63 int child_client_id, |
| 62 uint32 sync_point) { | 64 uint32 sync_point) { |
| 63 switch (type) { | 65 switch (type) { |
| 64 case gfx::SHARED_MEMORY_BUFFER: | 66 case gfx::SHARED_MEMORY_BUFFER: |
| 65 break; | 67 break; |
| 66 case gfx::IO_SURFACE_BUFFER: | 68 case gfx::IO_SURFACE_BUFFER: |
| 67 if (id.secondary_id != child_client_id) { | 69 GpuMemoryBufferImplIOSurface::DeletedByChildProcess(id, sync_point); |
| 68 LOG(ERROR) | |
| 69 << "Child attempting to delete GpuMemoryBuffer it does not own"; | |
| 70 } else { | |
| 71 GpuMemoryBufferImplIOSurface::DeletedByChildProcess(id, sync_point); | |
| 72 } | |
| 73 break; | 70 break; |
| 74 default: | 71 default: |
| 75 NOTREACHED(); | 72 NOTREACHED(); |
| 73 break; |
| 76 } | 74 } |
| 77 } | 75 } |
| 78 | 76 |
| 79 // static | 77 // static |
| 80 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle( | 78 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle( |
| 81 const gfx::GpuMemoryBufferHandle& handle, | 79 const gfx::GpuMemoryBufferHandle& handle, |
| 82 const gfx::Size& size, | 80 const gfx::Size& size, |
| 83 Format format, | 81 Format format, |
| 84 const DestructionCallback& callback) { | 82 const DestructionCallback& callback) { |
| 85 switch (handle.type) { | 83 switch (handle.type) { |
| 86 case gfx::SHARED_MEMORY_BUFFER: | 84 case gfx::SHARED_MEMORY_BUFFER: |
| 87 return GpuMemoryBufferImplSharedMemory::CreateFromHandle( | 85 return GpuMemoryBufferImplSharedMemory::CreateFromHandle( |
| 88 handle, size, format, callback); | 86 handle, size, format, callback); |
| 89 case gfx::IO_SURFACE_BUFFER: | 87 case gfx::IO_SURFACE_BUFFER: |
| 90 return GpuMemoryBufferImplIOSurface::CreateFromHandle( | 88 return GpuMemoryBufferImplIOSurface::CreateFromHandle( |
| 91 handle, size, format, callback); | 89 handle, size, format, callback); |
| 92 default: | 90 default: |
| 93 return scoped_ptr<GpuMemoryBufferImpl>(); | 91 return scoped_ptr<GpuMemoryBufferImpl>(); |
| 94 } | 92 } |
| 95 } | 93 } |
| 96 | 94 |
| 97 } // namespace content | 95 } // namespace content |
| OLD | NEW |