| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/common/mac/io_surface_manager.h" |
| 8 | 9 |
| 9 namespace content { | 10 namespace content { |
| 10 | 11 |
| 11 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface( | 12 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface( |
| 12 gfx::GpuMemoryBufferId id, | 13 gfx::GpuMemoryBufferId id, |
| 13 const gfx::Size& size, | 14 const gfx::Size& size, |
| 14 Format format, | 15 Format format, |
| 15 const DestructionCallback& callback, | 16 const DestructionCallback& callback, |
| 16 IOSurfaceRef io_surface) | 17 IOSurfaceRef io_surface) |
| 17 : GpuMemoryBufferImpl(id, size, format, callback), io_surface_(io_surface) { | 18 : GpuMemoryBufferImpl(id, size, format, callback), io_surface_(io_surface) { |
| 18 } | 19 } |
| 19 | 20 |
| 20 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() { | 21 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() { |
| 21 } | 22 } |
| 22 | 23 |
| 23 // static | 24 // static |
| 24 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplIOSurface::CreateFromHandle( | 25 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplIOSurface::CreateFromHandle( |
| 25 const gfx::GpuMemoryBufferHandle& handle, | 26 const gfx::GpuMemoryBufferHandle& handle, |
| 26 const gfx::Size& size, | 27 const gfx::Size& size, |
| 27 Format format, | 28 Format format, |
| 28 const DestructionCallback& callback) { | 29 const DestructionCallback& callback) { |
| 29 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( | 30 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( |
| 30 IOSurfaceLookup(handle.io_surface_id)); | 31 IOSurfaceManager::GetInstance()->AcquireIOSurface(handle.id)); |
| 31 if (!io_surface) | 32 if (!io_surface) |
| 32 return scoped_ptr<GpuMemoryBufferImpl>(); | 33 return scoped_ptr<GpuMemoryBufferImpl>(); |
| 33 | 34 |
| 34 return make_scoped_ptr<GpuMemoryBufferImpl>(new GpuMemoryBufferImplIOSurface( | 35 return make_scoped_ptr<GpuMemoryBufferImpl>(new GpuMemoryBufferImplIOSurface( |
| 35 handle.id, size, format, callback, io_surface.release())); | 36 handle.id, size, format, callback, io_surface.release())); |
| 36 } | 37 } |
| 37 | 38 |
| 38 bool GpuMemoryBufferImplIOSurface::Map(void** data) { | 39 bool GpuMemoryBufferImplIOSurface::Map(void** data) { |
| 39 DCHECK(!mapped_); | 40 DCHECK(!mapped_); |
| 40 IOSurfaceLock(io_surface_, 0, NULL); | 41 IOSurfaceLock(io_surface_, 0, NULL); |
| 41 mapped_ = true; | 42 mapped_ = true; |
| 42 *data = IOSurfaceGetBaseAddress(io_surface_); | 43 *data = IOSurfaceGetBaseAddress(io_surface_); |
| 43 return true; | 44 return true; |
| 44 } | 45 } |
| 45 | 46 |
| 46 void GpuMemoryBufferImplIOSurface::Unmap() { | 47 void GpuMemoryBufferImplIOSurface::Unmap() { |
| 47 DCHECK(mapped_); | 48 DCHECK(mapped_); |
| 48 IOSurfaceUnlock(io_surface_, 0, NULL); | 49 IOSurfaceUnlock(io_surface_, 0, NULL); |
| 49 mapped_ = false; | 50 mapped_ = false; |
| 50 } | 51 } |
| 51 | 52 |
| 52 void GpuMemoryBufferImplIOSurface::GetStride(int* stride) const { | 53 void GpuMemoryBufferImplIOSurface::GetStride(int* stride) const { |
| 53 *stride = IOSurfaceGetBytesPerRow(io_surface_); | 54 *stride = IOSurfaceGetBytesPerRow(io_surface_); |
| 54 } | 55 } |
| 55 | 56 |
| 56 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { | 57 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { |
| 57 gfx::GpuMemoryBufferHandle handle; | 58 gfx::GpuMemoryBufferHandle handle; |
| 58 handle.type = gfx::IO_SURFACE_BUFFER; | 59 handle.type = gfx::IO_SURFACE_BUFFER; |
| 59 handle.id = id_; | 60 handle.id = id_; |
| 60 handle.io_surface_id = IOSurfaceGetID(io_surface_); | |
| 61 return handle; | 61 return handle; |
| 62 } | 62 } |
| 63 | 63 |
| 64 } // namespace content | 64 } // namespace content |
| OLD | NEW |