Index: content/common/gpu/client/gpu_memory_buffer_impl_foobar.cc |
diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_foobar.cc b/content/common/gpu/client/gpu_memory_buffer_impl_foobar.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..de83803ddab16c4fea2fba9fddaabe2eb9758f80 |
--- /dev/null |
+++ b/content/common/gpu/client/gpu_memory_buffer_impl_foobar.cc |
@@ -0,0 +1,100 @@ |
+// 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 "base/debug/trace_event.h" |
+ |
+#include "content/common/gpu/client/gpu_memory_buffer_impl_foobar.h" |
+ |
+#include "ui/gl/gl_bindings.h" |
+ |
+extern "C" { |
+#include <libdrm/intel_bufmgr.h> |
+} |
+ |
+char GetZCopy() { |
+ // 0 off, 't' tiled, 'u' untiled |
+ static char mode; |
+ static char done = 0; |
+ if (!done) { |
+ done = 1; |
+ mode = 0; |
+ char *e = getenv("ZCOPY"); |
+ if (e) { |
+ if (e[0] == 't') { |
+ mode = 't'; |
+ TRACE_EVENT_INSTANT0("zcopy", "zero copy enabled - tiled mode", |
+ TRACE_EVENT_SCOPE_THREAD); |
+ } else if (e[0] == 'u') { |
+ mode = 'u'; |
+ TRACE_EVENT_INSTANT0("zcopy", "zero copy enabled - untiled mode", |
+ TRACE_EVENT_SCOPE_THREAD); |
+ } |
+ } |
+ if (!mode) { |
+ TRACE_EVENT_INSTANT0("zcopy", "zero copy disabled", |
+ TRACE_EVENT_SCOPE_THREAD); |
+ } |
+ } |
+ return mode; |
+} |
+ |
+namespace content { |
+ |
+GpuMemoryBufferImplFoobar::GpuMemoryBufferImplFoobar( |
+ gfx::Size size, unsigned internalformat) |
+ : GpuMemoryBufferImpl(size, internalformat), _prime_fd(-1) { |
+} |
+ |
+GpuMemoryBufferImplFoobar::~GpuMemoryBufferImplFoobar() { |
+ if (_prime_fd >= 0) { |
+ close(_prime_fd); |
+ } |
+ drm_intel_bo_unreference(foobar_object); |
+} |
+ |
+int GpuMemoryBufferImplFoobar::prime_fd() const { |
+ if (_prime_fd < 0) { |
+ TRACE_EVENT0("zcopy", "export"); |
+ DCHECK(foobar_object); |
+ drm_intel_bo_gem_export_to_prime(foobar_object, &_prime_fd); |
+ } |
+ return _prime_fd; |
+} |
+ |
+// static |
+bool GpuMemoryBufferImplFoobar::IsFormatSupported(unsigned internalformat) { |
+ return GetZCopy() && internalformat == GL_BGRA8_EXT; |
+} |
+ |
+bool GpuMemoryBufferImplFoobar::InitializeFromFoobarObject( |
+ void *foobar_object) { |
+ this->foobar_object = (drm_intel_bo *) foobar_object; |
+ return true; |
+} |
+ |
+void GpuMemoryBufferImplFoobar::Map(AccessMode mode, void** vaddr) { |
+ DCHECK(!mapped_); |
+ TRACE_EVENT0("zcopy", "map"); |
+ if (GetZCopy() == 'u') |
+ drm_intel_bo_map(foobar_object, 1); |
+ else |
+ drm_intel_gem_bo_map_gtt(foobar_object); |
+ *vaddr = foobar_object->virt; |
+ mapped_ = true; |
+} |
+ |
+void GpuMemoryBufferImplFoobar::Unmap() { |
+ DCHECK(mapped_); |
+ drm_intel_bo_unmap(foobar_object); |
+ mapped_ = false; |
+} |
+ |
+gfx::GpuMemoryBufferHandle GpuMemoryBufferImplFoobar::GetHandle() const { |
+ gfx::GpuMemoryBufferHandle handle; |
+ handle.type = gfx::FOOBAR_BUFFER; |
+ handle.handle.fd = prime_fd(); |
+ return handle; |
+} |
+ |
+} // namespace content |