Chromium Code Reviews| 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" |
| 15 #include "base/process/memory.h" | 16 #include "base/process/memory.h" |
| 16 #include "base/process/process_metrics.h" | 17 #include "base/process/process_metrics.h" |
| 17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 18 #include "base/trace_event/trace_event.h" | 19 #include "base/trace_event/trace_event.h" |
| 19 | 20 |
| 20 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0) | 21 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) |
|
dshwang
2017/04/06 00:56:31
I want to change it to
#if LINUX_VERSION_CODE >= K
| |
| 22 #include <linux/dma-buf.h> | |
| 23 #else | |
| 21 #include <linux/types.h> | 24 #include <linux/types.h> |
| 22 | 25 |
| 23 struct local_dma_buf_sync { | 26 struct dma_buf_sync { |
| 24 __u64 flags; | 27 __u64 flags; |
| 25 }; | 28 }; |
| 26 | 29 |
| 27 #define LOCAL_DMA_BUF_SYNC_READ (1 << 0) | 30 #define DMA_BUF_SYNC_READ (1 << 0) |
| 28 #define LOCAL_DMA_BUF_SYNC_WRITE (2 << 0) | 31 #define DMA_BUF_SYNC_WRITE (2 << 0) |
| 29 #define LOCAL_DMA_BUF_SYNC_RW \ | 32 #define DMA_BUF_SYNC_RW (DMA_BUF_SYNC_READ | DMA_BUF_SYNC_WRITE) |
| 30 (LOCAL_DMA_BUF_SYNC_READ | LOCAL_DMA_BUF_SYNC_WRITE) | 33 #define DMA_BUF_SYNC_START (0 << 2) |
| 31 #define LOCAL_DMA_BUF_SYNC_START (0 << 2) | 34 #define DMA_BUF_SYNC_END (1 << 2) |
| 32 #define LOCAL_DMA_BUF_SYNC_END (1 << 2) | |
| 33 | 35 |
| 34 #define LOCAL_DMA_BUF_BASE 'b' | 36 #define DMA_BUF_BASE 'b' |
| 35 #define LOCAL_DMA_BUF_IOCTL_SYNC \ | 37 #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 | 38 #endif |
| 41 | 39 |
| 42 namespace gfx { | 40 namespace gfx { |
| 43 | 41 |
| 44 namespace { | 42 namespace { |
| 45 | 43 |
| 46 void PrimeSyncStart(int dmabuf_fd) { | 44 void PrimeSyncStart(int dmabuf_fd) { |
| 47 struct local_dma_buf_sync sync_start = {0}; | 45 struct dma_buf_sync sync_start = {0}; |
| 48 | 46 |
| 49 sync_start.flags = LOCAL_DMA_BUF_SYNC_START | LOCAL_DMA_BUF_SYNC_RW; | 47 sync_start.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_RW; |
| 50 #if DCHECK_IS_ON() | 48 #if DCHECK_IS_ON() |
| 51 int rv = | 49 int rv = |
| 52 #endif | 50 #endif |
| 53 drmIoctl(dmabuf_fd, LOCAL_DMA_BUF_IOCTL_SYNC, &sync_start); | 51 ioctl(dmabuf_fd, DMA_BUF_IOCTL_SYNC, &sync_start); |
|
marcheu
2017/04/06 00:56:11
ioctl returns an error value, you have to check it
dshwang
2017/04/06 01:19:24
new patch set wraps it by HANDLE_EINTR like other
| |
| 54 DPLOG_IF(ERROR, rv) << "Failed DMA_BUF_SYNC_START"; | 52 DPLOG_IF(ERROR, rv) << "Failed DMA_BUF_SYNC_START"; |
| 55 } | 53 } |
| 56 | 54 |
| 57 void PrimeSyncEnd(int dmabuf_fd) { | 55 void PrimeSyncEnd(int dmabuf_fd) { |
| 58 struct local_dma_buf_sync sync_end = {0}; | 56 struct dma_buf_sync sync_end = {0}; |
| 59 | 57 |
| 60 sync_end.flags = LOCAL_DMA_BUF_SYNC_END | LOCAL_DMA_BUF_SYNC_RW; | 58 sync_end.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_RW; |
| 61 #if DCHECK_IS_ON() | 59 #if DCHECK_IS_ON() |
| 62 int rv = | 60 int rv = |
| 63 #endif | 61 #endif |
| 64 drmIoctl(dmabuf_fd, LOCAL_DMA_BUF_IOCTL_SYNC, &sync_end); | 62 ioctl(dmabuf_fd, DMA_BUF_IOCTL_SYNC, &sync_end); |
| 65 DPLOG_IF(ERROR, rv) << "Failed DMA_BUF_SYNC_END"; | 63 DPLOG_IF(ERROR, rv) << "Failed DMA_BUF_SYNC_END"; |
| 66 } | 64 } |
| 67 | 65 |
| 68 } // namespace | 66 } // namespace |
| 69 | 67 |
| 70 // static | 68 // static |
| 71 std::unique_ptr<gfx::ClientNativePixmap> | 69 std::unique_ptr<gfx::ClientNativePixmap> |
| 72 ClientNativePixmapDmaBuf::ImportFromDmabuf( | 70 ClientNativePixmapDmaBuf::ImportFromDmabuf( |
| 73 const gfx::NativePixmapHandle& handle, | 71 const gfx::NativePixmapHandle& handle, |
| 74 const gfx::Size& size) { | 72 const gfx::Size& size) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 uint8_t* address = reinterpret_cast<uint8_t*>(data_); | 145 uint8_t* address = reinterpret_cast<uint8_t*>(data_); |
| 148 return address + pixmap_handle_.planes[plane].offset; | 146 return address + pixmap_handle_.planes[plane].offset; |
| 149 } | 147 } |
| 150 | 148 |
| 151 int ClientNativePixmapDmaBuf::GetStride(size_t plane) const { | 149 int ClientNativePixmapDmaBuf::GetStride(size_t plane) const { |
| 152 DCHECK_LT(plane, pixmap_handle_.planes.size()); | 150 DCHECK_LT(plane, pixmap_handle_.planes.size()); |
| 153 return pixmap_handle_.planes[plane].stride; | 151 return pixmap_handle_.planes[plane].stride; |
| 154 } | 152 } |
| 155 | 153 |
| 156 } // namespace gfx | 154 } // namespace gfx |
| OLD | NEW |