Index: content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc |
diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc b/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f37e8d43ccfd526e49046a477229207342cc3e58 |
--- /dev/null |
+++ b/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc |
@@ -0,0 +1,87 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" |
+ |
+#include "base/logging.h" |
+#include "ui/gl/gl_bindings.h" |
+#include "ui/gl/io_surface_support_mac.h" |
+ |
+namespace content { |
+ |
+GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface( |
+ gfx::Size size, unsigned internalformat) |
+ : GpuMemoryBufferImpl(size, internalformat) { |
+} |
+ |
+GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() { |
+} |
+ |
+// static |
+bool GpuMemoryBufferImplIOSurface::IsFormatValid(unsigned internalformat) { |
+ switch (internalformat) { |
+ case GL_BGRA8_EXT: |
+ return true; |
+ default: |
+ return false; |
+ } |
+} |
+ |
+// static |
+uint32 GpuMemoryBufferImplIOSurface::PixelFormat(unsigned internalformat) { |
+ switch (internalformat) { |
+ case GL_BGRA8_EXT: |
+ return 'BGRA'; |
+ default: |
+ NOTREACHED(); |
+ return 0; |
+ } |
+} |
+ |
+bool GpuMemoryBufferImplIOSurface::Initialize( |
+ gfx::GpuMemoryBufferHandle handle) { |
+ IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); |
+ if (!io_surface_support) { |
+ LOG(ERROR) << "IOSurfaces only supported on 10.6."; |
+ return false; |
+ } |
+ |
+ io_surface_.reset(io_surface_support->IOSurfaceLookup(handle.io_surface_id)); |
+ if (!io_surface_) { |
+ LOG(ERROR) << "IOSurface lookup failed"; |
+ return false; |
+ } |
+ |
+ return true; |
+} |
+ |
+void GpuMemoryBufferImplIOSurface::Map(AccessMode mode, void** vaddr) { |
+ DCHECK(!mapped_); |
+ IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); |
+ io_surface_support->IOSurfaceLock(io_surface_, 0, NULL); |
+ *vaddr = io_surface_support->IOSurfaceGetBaseAddress(io_surface_); |
+ mapped_ = true; |
+} |
+ |
+void GpuMemoryBufferImplIOSurface::Unmap() { |
+ DCHECK(mapped_); |
+ IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); |
+ io_surface_support->IOSurfaceUnlock(io_surface_, 0, NULL); |
+ mapped_ = false; |
+} |
+ |
+uint32 GpuMemoryBufferImplIOSurface::GetStride() const { |
+ IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); |
+ return io_surface_support->IOSurfaceGetBytesPerRow(io_surface_); |
+} |
+ |
+gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { |
+ gfx::GpuMemoryBufferHandle handle; |
+ handle.type = gfx::IO_SURFACE_BUFFER; |
+ IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); |
+ handle.io_surface_id = io_surface_support->IOSurfaceGetID(io_surface_); |
+ return handle; |
+} |
+ |
+} // namespace content |