| 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 "ui/gl/gl_bindings.h" | 8 #include "ui/gl/gl_bindings.h" |
| 9 #include "ui/gl/io_surface_support_mac.h" | |
| 10 | 9 |
| 11 namespace content { | 10 namespace content { |
| 12 | 11 |
| 13 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface( | 12 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface( |
| 14 const gfx::Size& size, | 13 const gfx::Size& size, |
| 15 unsigned internalformat) | 14 unsigned internalformat) |
| 16 : GpuMemoryBufferImpl(size, internalformat), | 15 : GpuMemoryBufferImpl(size, internalformat) {} |
| 17 io_surface_support_(IOSurfaceSupport::Initialize()) { | |
| 18 CHECK(io_surface_support_); | |
| 19 } | |
| 20 | 16 |
| 21 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() {} | 17 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() {} |
| 22 | 18 |
| 23 // static | 19 // static |
| 24 bool GpuMemoryBufferImplIOSurface::IsFormatSupported(unsigned internalformat) { | 20 bool GpuMemoryBufferImplIOSurface::IsFormatSupported(unsigned internalformat) { |
| 25 switch (internalformat) { | 21 switch (internalformat) { |
| 26 case GL_BGRA8_EXT: | 22 case GL_BGRA8_EXT: |
| 27 return true; | 23 return true; |
| 28 default: | 24 default: |
| 29 return false; | 25 return false; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 54 return 'BGRA'; | 50 return 'BGRA'; |
| 55 default: | 51 default: |
| 56 NOTREACHED(); | 52 NOTREACHED(); |
| 57 return 0; | 53 return 0; |
| 58 } | 54 } |
| 59 } | 55 } |
| 60 | 56 |
| 61 bool GpuMemoryBufferImplIOSurface::InitializeFromHandle( | 57 bool GpuMemoryBufferImplIOSurface::InitializeFromHandle( |
| 62 gfx::GpuMemoryBufferHandle handle) { | 58 gfx::GpuMemoryBufferHandle handle) { |
| 63 DCHECK(IsFormatSupported(internalformat_)); | 59 DCHECK(IsFormatSupported(internalformat_)); |
| 64 io_surface_.reset(io_surface_support_->IOSurfaceLookup(handle.io_surface_id)); | 60 io_surface_.reset(IOSurfaceLookup(handle.io_surface_id)); |
| 65 if (!io_surface_) { | 61 if (!io_surface_) { |
| 66 VLOG(1) << "IOSurface lookup failed"; | 62 VLOG(1) << "IOSurface lookup failed"; |
| 67 return false; | 63 return false; |
| 68 } | 64 } |
| 69 | 65 |
| 70 return true; | 66 return true; |
| 71 } | 67 } |
| 72 | 68 |
| 73 void* GpuMemoryBufferImplIOSurface::Map() { | 69 void* GpuMemoryBufferImplIOSurface::Map() { |
| 74 DCHECK(!mapped_); | 70 DCHECK(!mapped_); |
| 75 io_surface_support_->IOSurfaceLock(io_surface_, 0, NULL); | 71 IOSurfaceLock(io_surface_, 0, NULL); |
| 76 mapped_ = true; | 72 mapped_ = true; |
| 77 return io_surface_support_->IOSurfaceGetBaseAddress(io_surface_); | 73 return IOSurfaceGetBaseAddress(io_surface_); |
| 78 } | 74 } |
| 79 | 75 |
| 80 void GpuMemoryBufferImplIOSurface::Unmap() { | 76 void GpuMemoryBufferImplIOSurface::Unmap() { |
| 81 DCHECK(mapped_); | 77 DCHECK(mapped_); |
| 82 io_surface_support_->IOSurfaceUnlock(io_surface_, 0, NULL); | 78 IOSurfaceUnlock(io_surface_, 0, NULL); |
| 83 mapped_ = false; | 79 mapped_ = false; |
| 84 } | 80 } |
| 85 | 81 |
| 86 uint32 GpuMemoryBufferImplIOSurface::GetStride() const { | 82 uint32 GpuMemoryBufferImplIOSurface::GetStride() const { |
| 87 return io_surface_support_->IOSurfaceGetBytesPerRow(io_surface_); | 83 return IOSurfaceGetBytesPerRow(io_surface_); |
| 88 } | 84 } |
| 89 | 85 |
| 90 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { | 86 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { |
| 91 gfx::GpuMemoryBufferHandle handle; | 87 gfx::GpuMemoryBufferHandle handle; |
| 92 handle.type = gfx::IO_SURFACE_BUFFER; | 88 handle.type = gfx::IO_SURFACE_BUFFER; |
| 93 handle.io_surface_id = io_surface_support_->IOSurfaceGetID(io_surface_); | 89 handle.io_surface_id = IOSurfaceGetID(io_surface_); |
| 94 return handle; | 90 return handle; |
| 95 } | 91 } |
| 96 | 92 |
| 97 } // namespace content | 93 } // namespace content |
| OLD | NEW |