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

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

Issue 186123006: zero copy - NOT FOR REVIEW Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: re-upload Created 6 years, 9 months 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_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..d1c15e2f34e891578749d10b095ab3f17885e639
--- /dev/null
+++ b/content/common/gpu/client/gpu_memory_buffer_impl_foobar.cc
@@ -0,0 +1,92 @@
+// 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_EVENT0("zcopy", "zero copy enabled - tiled mode");
+ } else if (e[0] == 'u') {
+ mode = 'u';
+ TRACE_EVENT0("zcopy", "zero copy enabled - untiled mode");
+ }
+ }
+ if (!mode) {
+ TRACE_EVENT0("zcopy", "zero copy disabled");
+ }
+ }
+ 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) {
+ 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_);
+ drm_intel_bo_map(foobar_object, 1);
+ *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

Powered by Google App Engine
This is Rietveld 408576698