OLD | NEW |
---|---|
(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> | |
vignatti (out of this project)
2015/08/06 20:56:26
IIUC this header file is meant to be used within t
dshwang
2015/08/07 08:54:53
it is in /usr/include/libdrm/vgem_drm.h. In my opi
| |
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 gfx::BufferFormat format, | |
22 gfx::BufferUsage usage) { | |
23 DCHECK_GE(vgem_handle.fd, 0); | |
24 DCHECK_GE(handle.fd.fd, 0); | |
25 DCHECK(usage != gfx::BufferUsage::SCANOUT); | |
reveman
2015/08/07 14:35:16
Why do we care? What part of the code here doesn't
dshwang
2015/08/07 15:36:46
drmPrimeFDToHandle can fail on the hardware, which
| |
26 uint32_t vgem_bo_handle = 0; | |
27 int ret = drmPrimeFDToHandle(vgem_handle.fd, handle.fd.fd, &vgem_bo_handle); | |
reveman
2015/08/07 14:35:16
Would it not be more appropriate to keep this code
dshwang
2015/08/07 15:36:46
ClientNativePixmapFactoryGbm has role to manage vg
reveman
2015/08/07 17:59:44
ClientNativePixmapFactoryGbm is clearly aware of v
dshwang
2015/08/11 17:44:55
I still think drmPrimeFDToHandle() is Pixmap's job
| |
28 if (ret) { | |
29 PLOG(ERROR) << "drmPrimeFDToHandle failed, handle:" << vgem_bo_handle; | |
30 return nullptr; | |
31 } | |
32 return make_scoped_ptr(new ClientNativePixmapVgem( | |
33 handle, vgem_handle, size, format, usage, vgem_bo_handle)); | |
34 } | |
35 | |
36 ClientNativePixmapVgem::ClientNativePixmapVgem( | |
37 const gfx::NativePixmapHandle& handle, | |
38 const base::FileDescriptor& vgem_handle, | |
39 const gfx::Size& size, | |
40 gfx::BufferFormat format, | |
41 gfx::BufferUsage usage, | |
42 uint32_t vgem_bo_handle) | |
43 : dma_buf_(handle.fd.fd), | |
44 vgem_fd_(vgem_handle), | |
45 size_(size), | |
46 format_(format), | |
47 usage_(usage), | |
48 vgem_bo_handle_(vgem_bo_handle), | |
49 stride_(handle.stride), | |
50 mmap_ptr_(nullptr) { | |
51 DCHECK(vgem_bo_handle_); | |
52 } | |
53 | |
54 ClientNativePixmapVgem::~ClientNativePixmapVgem() { | |
55 if (mmap_ptr_) { | |
56 size_t size = stride_ * size_.height(); | |
57 int ret = munmap(mmap_ptr_, size); | |
58 if (ret) | |
59 PLOG(ERROR) << "fail to munmap a vgem buffer. error:" << ret; | |
60 mmap_ptr_ = nullptr; | |
61 } | |
62 | |
63 struct drm_gem_close close = {0}; | |
64 close.handle = vgem_bo_handle_; | |
65 int ret = drmIoctl(vgem_fd_.fd, DRM_IOCTL_GEM_CLOSE, &close); | |
66 if (ret) | |
67 PLOG(ERROR) << "fail to free a vgem buffer. error:" << ret; | |
68 vgem_bo_handle_ = 0; | |
69 } | |
70 | |
71 bool ClientNativePixmapVgem::Map(void** data) { | |
72 TRACE_EVENT0("gpu", "ClientNativePixmapVgem::Map"); | |
73 if (mmap_ptr_) { | |
74 *data = mmap_ptr_; | |
75 return true; | |
76 } | |
77 | |
78 struct drm_mode_map_dumb mmap_arg = {0}; | |
79 mmap_arg.handle = vgem_bo_handle_; | |
80 | |
81 int ret = drmIoctl(vgem_fd_.fd, DRM_IOCTL_VGEM_MODE_MAP_DUMB, &mmap_arg); | |
82 if (ret) { | |
83 PLOG(ERROR) << "fail to map a vgem buffer. error:" << ret; | |
84 return false; | |
85 } | |
86 DCHECK(mmap_arg.offset); | |
87 | |
88 size_t size = stride_ * size_.height(); | |
89 mmap_ptr_ = mmap(nullptr, size, (PROT_READ | PROT_WRITE), MAP_SHARED, | |
reveman
2015/08/07 14:35:16
Why not mmap in the ctor instead? I think that wou
dshwang
2015/08/07 15:36:46
I roll back consistent map. It worked well with Ha
| |
90 vgem_fd_.fd, mmap_arg.offset); | |
91 DCHECK(mmap_ptr_ != MAP_FAILED); | |
reveman
2015/08/07 14:35:16
nit: DCHECK_NE
dshwang
2015/08/07 15:36:46
Done.
| |
92 *data = mmap_ptr_; | |
93 return true; | |
94 } | |
95 | |
96 void ClientNativePixmapVgem::Unmap() { | |
97 TRACE_EVENT0("gpu", "ClientNativePixmapVgem::Unmap"); | |
reveman
2015/08/07 14:35:16
this trace doesn't seem very useful
dshwang
2015/08/07 15:36:46
after roll back, it seems useful
| |
98 DCHECK(mmap_ptr_); | |
99 // keep it consistently mapped, and unmap it in dtor. | |
100 } | |
101 | |
102 void ClientNativePixmapVgem::GetStride(int* stride) const { | |
103 *stride = stride_; | |
104 } | |
105 | |
106 } // namespace ui | |
OLD | NEW |