OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/linux/client_native_pixmap_dmabuf.h" | 5 #include "ui/gfx/linux/client_native_pixmap_dmabuf.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <linux/version.h> | 8 #include <linux/version.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <sys/ioctl.h> |
10 #include <sys/mman.h> | 11 #include <sys/mman.h> |
11 #include <xf86drm.h> | 12 #include <xf86drm.h> |
12 | 13 |
13 #include "base/debug/crash_logging.h" | 14 #include "base/debug/crash_logging.h" |
14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/posix/eintr_wrapper.h" |
15 #include "base/process/memory.h" | 17 #include "base/process/memory.h" |
16 #include "base/process/process_metrics.h" | 18 #include "base/process/process_metrics.h" |
17 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
18 #include "base/trace_event/trace_event.h" | 20 #include "base/trace_event/trace_event.h" |
19 | 21 |
20 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0) | 22 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) |
| 23 #include <linux/dma-buf.h> |
| 24 #else |
21 #include <linux/types.h> | 25 #include <linux/types.h> |
22 | 26 |
23 struct local_dma_buf_sync { | 27 struct dma_buf_sync { |
24 __u64 flags; | 28 __u64 flags; |
25 }; | 29 }; |
26 | 30 |
27 #define LOCAL_DMA_BUF_SYNC_READ (1 << 0) | 31 #define DMA_BUF_SYNC_READ (1 << 0) |
28 #define LOCAL_DMA_BUF_SYNC_WRITE (2 << 0) | 32 #define DMA_BUF_SYNC_WRITE (2 << 0) |
29 #define LOCAL_DMA_BUF_SYNC_RW \ | 33 #define DMA_BUF_SYNC_RW (DMA_BUF_SYNC_READ | DMA_BUF_SYNC_WRITE) |
30 (LOCAL_DMA_BUF_SYNC_READ | LOCAL_DMA_BUF_SYNC_WRITE) | 34 #define DMA_BUF_SYNC_START (0 << 2) |
31 #define LOCAL_DMA_BUF_SYNC_START (0 << 2) | 35 #define DMA_BUF_SYNC_END (1 << 2) |
32 #define LOCAL_DMA_BUF_SYNC_END (1 << 2) | |
33 | 36 |
34 #define LOCAL_DMA_BUF_BASE 'b' | 37 #define DMA_BUF_BASE 'b' |
35 #define LOCAL_DMA_BUF_IOCTL_SYNC \ | 38 #define DMA_BUF_IOCTL_SYNC _IOW(DMA_BUF_BASE, 0, struct dma_buf_sync) |
36 _IOW(LOCAL_DMA_BUF_BASE, 0, struct local_dma_buf_sync) | |
37 | |
38 #else | |
39 #include <linux/dma-buf.h> | |
40 #endif | 39 #endif |
41 | 40 |
42 namespace gfx { | 41 namespace gfx { |
43 | 42 |
44 namespace { | 43 namespace { |
45 | 44 |
46 void PrimeSyncStart(int dmabuf_fd) { | 45 void PrimeSyncStart(int dmabuf_fd) { |
47 struct local_dma_buf_sync sync_start = {0}; | 46 struct dma_buf_sync sync_start = {0}; |
48 | 47 |
49 sync_start.flags = LOCAL_DMA_BUF_SYNC_START | LOCAL_DMA_BUF_SYNC_RW; | 48 sync_start.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_RW; |
50 #if DCHECK_IS_ON() | 49 int rv = HANDLE_EINTR(ioctl(dmabuf_fd, DMA_BUF_IOCTL_SYNC, &sync_start)); |
51 int rv = | 50 PLOG_IF(ERROR, rv) << "Failed DMA_BUF_SYNC_START"; |
52 #endif | |
53 drmIoctl(dmabuf_fd, LOCAL_DMA_BUF_IOCTL_SYNC, &sync_start); | |
54 DPLOG_IF(ERROR, rv) << "Failed DMA_BUF_SYNC_START"; | |
55 } | 51 } |
56 | 52 |
57 void PrimeSyncEnd(int dmabuf_fd) { | 53 void PrimeSyncEnd(int dmabuf_fd) { |
58 struct local_dma_buf_sync sync_end = {0}; | 54 struct dma_buf_sync sync_end = {0}; |
59 | 55 |
60 sync_end.flags = LOCAL_DMA_BUF_SYNC_END | LOCAL_DMA_BUF_SYNC_RW; | 56 sync_end.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_RW; |
61 #if DCHECK_IS_ON() | 57 int rv = HANDLE_EINTR(ioctl(dmabuf_fd, DMA_BUF_IOCTL_SYNC, &sync_end)); |
62 int rv = | 58 PLOG_IF(ERROR, rv) << "Failed DMA_BUF_SYNC_END"; |
63 #endif | |
64 drmIoctl(dmabuf_fd, LOCAL_DMA_BUF_IOCTL_SYNC, &sync_end); | |
65 DPLOG_IF(ERROR, rv) << "Failed DMA_BUF_SYNC_END"; | |
66 } | 59 } |
67 | 60 |
68 } // namespace | 61 } // namespace |
69 | 62 |
70 // static | 63 // static |
71 std::unique_ptr<gfx::ClientNativePixmap> | 64 std::unique_ptr<gfx::ClientNativePixmap> |
72 ClientNativePixmapDmaBuf::ImportFromDmabuf( | 65 ClientNativePixmapDmaBuf::ImportFromDmabuf( |
73 const gfx::NativePixmapHandle& handle, | 66 const gfx::NativePixmapHandle& handle, |
74 const gfx::Size& size) { | 67 const gfx::Size& size) { |
75 return base::WrapUnique(new ClientNativePixmapDmaBuf(handle, size)); | 68 return base::WrapUnique(new ClientNativePixmapDmaBuf(handle, size)); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 uint8_t* address = reinterpret_cast<uint8_t*>(data_); | 140 uint8_t* address = reinterpret_cast<uint8_t*>(data_); |
148 return address + pixmap_handle_.planes[plane].offset; | 141 return address + pixmap_handle_.planes[plane].offset; |
149 } | 142 } |
150 | 143 |
151 int ClientNativePixmapDmaBuf::GetStride(size_t plane) const { | 144 int ClientNativePixmapDmaBuf::GetStride(size_t plane) const { |
152 DCHECK_LT(plane, pixmap_handle_.planes.size()); | 145 DCHECK_LT(plane, pixmap_handle_.planes.size()); |
153 return pixmap_handle_.planes[plane].stride; | 146 return pixmap_handle_.planes[plane].stride; |
154 } | 147 } |
155 | 148 |
156 } // namespace gfx | 149 } // namespace gfx |
OLD | NEW |