| 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 #include "content/common/mac/io_surface_manager.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 return make_scoped_ptr<GpuMemoryBufferImpl>( | 54 return make_scoped_ptr<GpuMemoryBufferImpl>( |
| 55 new GpuMemoryBufferImplIOSurface(handle.id, size, format, callback, | 55 new GpuMemoryBufferImplIOSurface(handle.id, size, format, callback, |
| 56 io_surface.release(), LockFlags(usage))); | 56 io_surface.release(), LockFlags(usage))); |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool GpuMemoryBufferImplIOSurface::Map(void** data) { | 59 bool GpuMemoryBufferImplIOSurface::Map(void** data) { |
| 60 DCHECK(!mapped_); | 60 DCHECK(!mapped_); |
| 61 IOReturn status = IOSurfaceLock(io_surface_, lock_flags_, NULL); | 61 IOReturn status = IOSurfaceLock(io_surface_, lock_flags_, NULL); |
| 62 DCHECK_NE(status, kIOReturnCannotLock); | 62 DCHECK_NE(status, kIOReturnCannotLock); |
| 63 mapped_ = true; | 63 mapped_ = true; |
| 64 *data = IOSurfaceGetBaseAddress(io_surface_); | 64 size_t num_planes = GpuMemoryBuffer::NumberOfPlanes(GetFormat()); |
| 65 for (size_t plane = 0; plane < num_planes; ++plane) |
| 66 data[plane] = IOSurfaceGetBaseAddressOfPlane(io_surface_, plane); |
| 65 return true; | 67 return true; |
| 66 } | 68 } |
| 67 | 69 |
| 68 void GpuMemoryBufferImplIOSurface::Unmap() { | 70 void GpuMemoryBufferImplIOSurface::Unmap() { |
| 69 DCHECK(mapped_); | 71 DCHECK(mapped_); |
| 70 IOSurfaceUnlock(io_surface_, lock_flags_, NULL); | 72 IOSurfaceUnlock(io_surface_, lock_flags_, NULL); |
| 71 mapped_ = false; | 73 mapped_ = false; |
| 72 } | 74 } |
| 73 | 75 |
| 74 void GpuMemoryBufferImplIOSurface::GetStride(int* stride) const { | 76 void GpuMemoryBufferImplIOSurface::GetStride(int* strides) const { |
| 75 *stride = IOSurfaceGetBytesPerRow(io_surface_); | 77 size_t num_planes = GpuMemoryBuffer::NumberOfPlanes(GetFormat()); |
| 78 for (size_t plane = 0; plane < num_planes; ++plane) |
| 79 strides[plane] = IOSurfaceGetBytesPerRowOfPlane(io_surface_, plane); |
| 76 } | 80 } |
| 77 | 81 |
| 78 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { | 82 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { |
| 79 gfx::GpuMemoryBufferHandle handle; | 83 gfx::GpuMemoryBufferHandle handle; |
| 80 handle.type = gfx::IO_SURFACE_BUFFER; | 84 handle.type = gfx::IO_SURFACE_BUFFER; |
| 81 handle.id = id_; | 85 handle.id = id_; |
| 82 return handle; | 86 return handle; |
| 83 } | 87 } |
| 84 | 88 |
| 85 } // namespace content | 89 } // namespace content |
| OLD | NEW |