OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "ui/gl/gl_bindings.h" |
| 9 #include "ui/gl/io_surface_support_mac.h" |
| 10 |
| 11 namespace content { |
| 12 |
| 13 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface( |
| 14 gfx::Size size, unsigned internalformat) |
| 15 : GpuMemoryBufferImpl(size, internalformat) { |
| 16 } |
| 17 |
| 18 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() { |
| 19 } |
| 20 |
| 21 // static |
| 22 bool GpuMemoryBufferImplIOSurface::IsFormatValid(unsigned internalformat) { |
| 23 switch (internalformat) { |
| 24 case GL_BGRA8_EXT: |
| 25 return true; |
| 26 default: |
| 27 return false; |
| 28 } |
| 29 } |
| 30 |
| 31 // static |
| 32 uint32 GpuMemoryBufferImplIOSurface::PixelFormat(unsigned internalformat) { |
| 33 switch (internalformat) { |
| 34 case GL_BGRA8_EXT: |
| 35 return 'BGRA'; |
| 36 default: |
| 37 NOTREACHED(); |
| 38 return 0; |
| 39 } |
| 40 } |
| 41 |
| 42 bool GpuMemoryBufferImplIOSurface::Initialize( |
| 43 gfx::GpuMemoryBufferHandle handle) { |
| 44 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); |
| 45 if (!io_surface_support) { |
| 46 LOG(ERROR) << "IOSurfaces only supported on 10.6."; |
| 47 return false; |
| 48 } |
| 49 |
| 50 io_surface_.reset(io_surface_support->IOSurfaceLookup(handle.io_surface_id)); |
| 51 if (!io_surface_) { |
| 52 LOG(ERROR) << "IOSurface lookup failed"; |
| 53 return false; |
| 54 } |
| 55 |
| 56 return true; |
| 57 } |
| 58 |
| 59 void GpuMemoryBufferImplIOSurface::Map(AccessMode mode, void** vaddr) { |
| 60 DCHECK(!mapped_); |
| 61 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); |
| 62 io_surface_support->IOSurfaceLock(io_surface_, 0, NULL); |
| 63 *vaddr = io_surface_support->IOSurfaceGetBaseAddress(io_surface_); |
| 64 mapped_ = true; |
| 65 } |
| 66 |
| 67 void GpuMemoryBufferImplIOSurface::Unmap() { |
| 68 DCHECK(mapped_); |
| 69 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); |
| 70 io_surface_support->IOSurfaceUnlock(io_surface_, 0, NULL); |
| 71 mapped_ = false; |
| 72 } |
| 73 |
| 74 uint32 GpuMemoryBufferImplIOSurface::GetStride() const { |
| 75 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); |
| 76 return io_surface_support->IOSurfaceGetBytesPerRow(io_surface_); |
| 77 } |
| 78 |
| 79 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { |
| 80 gfx::GpuMemoryBufferHandle handle; |
| 81 handle.type = gfx::IO_SURFACE_BUFFER; |
| 82 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); |
| 83 handle.io_surface_id = io_surface_support->IOSurfaceGetID(io_surface_); |
| 84 return handle; |
| 85 } |
| 86 |
| 87 } // namespace content |
OLD | NEW |