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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/debug/trace_event.h"
6
7 #include "content/common/gpu/client/gpu_memory_buffer_impl_foobar.h"
8
9 #include "ui/gl/gl_bindings.h"
10
11 extern "C" {
12 #include <libdrm/intel_bufmgr.h>
13 }
14
15 char GetZCopy() {
16 // 0 off, 't' tiled, 'u' untiled
17 static char mode;
18 static char done = 0;
19 if (!done) {
20 done = 1;
21 mode = 0;
22 char *e = getenv("ZCOPY");
23 if (e) {
24 if (e[0] == 't') {
25 mode = 't';
26 TRACE_EVENT0("zcopy", "zero copy enabled - tiled mode");
27 } else if (e[0] == 'u') {
28 mode = 'u';
29 TRACE_EVENT0("zcopy", "zero copy enabled - untiled mode");
30 }
31 }
32 if (!mode) {
33 TRACE_EVENT0("zcopy", "zero copy disabled");
34 }
35 }
36 return mode;
37 }
38
39 namespace content {
40
41 GpuMemoryBufferImplFoobar::GpuMemoryBufferImplFoobar(
42 gfx::Size size, unsigned internalformat)
43 : GpuMemoryBufferImpl(size, internalformat), _prime_fd(-1) {
44 }
45
46 GpuMemoryBufferImplFoobar::~GpuMemoryBufferImplFoobar() {
47 if (_prime_fd >= 0) {
48 close(_prime_fd);
49 }
50 drm_intel_bo_unreference(foobar_object);
51 }
52
53 int GpuMemoryBufferImplFoobar::prime_fd() const {
54 if (_prime_fd < 0) {
55 DCHECK(foobar_object);
56 drm_intel_bo_gem_export_to_prime(foobar_object, &_prime_fd);
57 }
58 return _prime_fd;
59 }
60
61 // static
62 bool GpuMemoryBufferImplFoobar::IsFormatSupported(unsigned internalformat) {
63 return GetZCopy() && internalformat == GL_BGRA8_EXT;
64 }
65
66 bool GpuMemoryBufferImplFoobar::InitializeFromFoobarObject(
67 void *foobar_object) {
68 this->foobar_object = (drm_intel_bo *) foobar_object;
69 return true;
70 }
71
72 void GpuMemoryBufferImplFoobar::Map(AccessMode mode, void** vaddr) {
73 DCHECK(!mapped_);
74 drm_intel_bo_map(foobar_object, 1);
75 *vaddr = foobar_object->virt;
76 mapped_ = true;
77 }
78
79 void GpuMemoryBufferImplFoobar::Unmap() {
80 DCHECK(mapped_);
81 drm_intel_bo_unmap(foobar_object);
82 mapped_ = false;
83 }
84
85 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplFoobar::GetHandle() const {
86 gfx::GpuMemoryBufferHandle handle;
87 handle.type = gfx::FOOBAR_BUFFER;
88 handle.handle.fd = prime_fd();
89 return handle;
90 }
91
92 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698