Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1030)

Unified Diff: content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc

Issue 77023002: gpu: Add IOSurface backed GpuMemoryBuffer implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review feedback Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..de5daae6cedab533c932e16540e169017160f83c
--- /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::IsFormatSupported(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();
Ken Russell (switch to Gerrit) 2013/12/03 22:36:13 Consider caching this object as a member.
reveman 2013/12/04 02:00:31 Done.
+ if (!io_surface_support) {
+ LOG(ERROR) << "IOSurfaces only supported on 10.6.";
Ken Russell (switch to Gerrit) 2013/12/03 22:36:13 Chrome doesn't run on 10.5 any more, so this log m
reveman 2013/12/04 02:00:31 Added CHECK to ctor.
+ 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

Powered by Google App Engine
This is Rietveld 408576698