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

Side by Side Diff: ui/ozone/platform/drm/gpu/client_native_pixmap_vgem.cc

Issue 1134993003: ozone: Implement zero/one-copy texture for Ozone GBM. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make content_unittests (GpuMemoryBuffer*) pass Created 5 years, 4 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 2015 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 "ui/ozone/platform/drm/gpu/client_native_pixmap_vgem.h"
6
7 #include <fcntl.h>
8 #include <sys/mman.h>
9 #include <vgem_drm.h>
10 #include <xf86drm.h>
11
12 #include "base/trace_event/trace_event.h"
13
14 namespace ui {
15
16 // static
17 scoped_ptr<ClientNativePixmap> ClientNativePixmapVgem::Create(
18 const gfx::NativePixmapHandle& handle,
19 const base::FileDescriptor& vgem_handle,
20 const gfx::Size& size) {
21 DCHECK_GE(vgem_handle.fd, 0);
22 DCHECK_GE(handle.fd.fd, 0);
23 uint32_t vgem_bo_handle = 0;
24 int ret = drmPrimeFDToHandle(vgem_handle.fd, handle.fd.fd, &vgem_bo_handle);
25 if (ret) {
26 PLOG(ERROR) << "drmPrimeFDToHandle failed, handle:" << vgem_bo_handle;
27 return nullptr;
28 }
29 return make_scoped_ptr(
30 new ClientNativePixmapVgem(handle, vgem_handle, size, vgem_bo_handle));
31 }
32
33 ClientNativePixmapVgem::ClientNativePixmapVgem(
34 const gfx::NativePixmapHandle& handle,
35 const base::FileDescriptor& vgem_handle,
36 const gfx::Size& size,
37 uint32_t vgem_bo_handle)
38 : dma_buf_(handle.fd.fd),
39 vgem_fd_(vgem_handle),
40 size_(size),
41 vgem_bo_handle_(vgem_bo_handle),
42 stride_(handle.stride),
43 data_(nullptr) {
44 DCHECK(vgem_bo_handle_);
45 }
46
47 ClientNativePixmapVgem::~ClientNativePixmapVgem() {
48 DCHECK(!data_);
49 struct drm_gem_close close = {0};
50 close.handle = vgem_bo_handle_;
51 int ret = drmIoctl(vgem_fd_.fd, DRM_IOCTL_GEM_CLOSE, &close);
52 if (ret)
53 PLOG(ERROR) << "fail to free a vgem buffer. error:" << ret;
54 vgem_bo_handle_ = 0;
55 }
56
57 bool ClientNativePixmapVgem::Map(void** data) {
58 TRACE_EVENT0("gpu", "ClientNativePixmapVgem::Map");
59 DCHECK(!data_);
60 struct drm_mode_map_dumb mmap_arg = {0};
61 mmap_arg.handle = vgem_bo_handle_;
62
63 int ret = drmIoctl(vgem_fd_.fd, DRM_IOCTL_VGEM_MODE_MAP_DUMB, &mmap_arg);
64 if (ret) {
65 PLOG(ERROR) << "fail to map a vgem buffer. error:" << ret;
66 return false;
67 }
68 DCHECK(mmap_arg.offset);
69
70 size_t size = stride_ * size_.height();
71 data_ = mmap(nullptr, size, (PROT_READ | PROT_WRITE), MAP_SHARED, vgem_fd_.fd,
72 mmap_arg.offset);
73 DCHECK_NE(data_, MAP_FAILED);
74 *data = data_;
75 return true;
76 }
77
78 void ClientNativePixmapVgem::Unmap() {
79 TRACE_EVENT0("gpu", "ClientNativePixmapVgem::Unmap");
80 DCHECK(data_);
81
82 // TODO(dshwang): keep it consistently mapped, and unmap it in dtor.
83 size_t size = stride_ * size_.height();
84 int ret = munmap(data_, size);
85 if (ret)
86 PLOG(ERROR) << "fail to munmap a vgem buffer. error:" << ret;
87 data_ = nullptr;
88 }
89
90 void ClientNativePixmapVgem::GetStride(int* stride) const {
91 *stride = stride_;
92 }
93
94 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698