Chromium Code Reviews| Index: ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.cc |
| diff --git a/ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.cc b/ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.cc |
| index 26d123a2a452209637a928aa78f7b07d1d1dd3a9..09e8692c1dc867c2473d549d176305824dda989d 100644 |
| --- a/ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.cc |
| +++ b/ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.cc |
| @@ -12,8 +12,47 @@ |
| #include "base/process/memory.h" |
| #include "base/trace_event/trace_event.h" |
| +#if defined(OS_CHROMEOS) |
| +// TODO(vignatti): replace the local definitions below with #include |
| +// <linux/dma-buf.h> once kernel version 4.6 becomes widely used. |
| +#include <linux/types.h> |
| + |
| +struct local_dma_buf_sync { |
| + __u64 flags; |
| +}; |
| + |
| +#define LOCAL_DMA_BUF_SYNC_READ (1 << 0) |
| +#define LOCAL_DMA_BUF_SYNC_WRITE (2 << 0) |
| +#define LOCAL_DMA_BUF_SYNC_START (0 << 2) |
| +#define LOCAL_DMA_BUF_SYNC_END (1 << 2) |
| + |
| +#define LOCAL_DMA_BUF_BASE 'b' |
| +#define LOCAL_DMA_BUF_IOCTL_SYNC \ |
| + _IOW(LOCAL_DMA_BUF_BASE, 0, struct local_dma_buf_sync) |
| +#endif |
| + |
| namespace ui { |
| +namespace { |
| + |
| +void PrimeSyncStart(int dmabuf_fd) { |
| + struct local_dma_buf_sync sync_start = {0}; |
| + |
| + sync_start.flags = LOCAL_DMA_BUF_SYNC_START | LOCAL_DMA_BUF_SYNC_READ; |
| + if (drmIoctl(dmabuf_fd, LOCAL_DMA_BUF_IOCTL_SYNC, &sync_start)) |
| + PLOG(ERROR) << "Failed DMA_BUF_SYNC_START"; |
| +} |
| + |
| +void PrimeSyncEnd(int dmabuf_fd) { |
| + struct local_dma_buf_sync sync_end = {0}; |
| + |
| + sync_end.flags = LOCAL_DMA_BUF_SYNC_END | LOCAL_DMA_BUF_SYNC_WRITE; |
| + if (drmIoctl(dmabuf_fd, LOCAL_DMA_BUF_IOCTL_SYNC, &sync_end)) |
| + PLOG(ERROR) << "Failed DMA_BUF_SYNC_END"; |
| +} |
| + |
| +} // namespace |
| + |
| // static |
| scoped_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf( |
| int dmabuf_fd, |
| @@ -26,7 +65,7 @@ scoped_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf( |
| ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd, |
| const gfx::Size& size, |
| int stride) |
| - : size_(size), stride_(stride) { |
| + : dmabuf_fd_(dmabuf_fd), size_(size), stride_(stride) { |
|
rickyz (no longer on Chrome)
2016/04/06 02:04:48
Out of curiosity, where/how does this fd get expos
vignatti (out of this project)
2016/04/06 13:52:46
yes. The GPU process is the privileged process her
|
| TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf"); |
| size_t map_size = stride_ * size_.height(); |
| data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED, |
| @@ -42,10 +81,15 @@ ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() { |
| } |
| void* ClientNativePixmapDmaBuf::Map() { |
| + TRACE_EVENT0("drm", "DmaBuf:Map"); |
| + PrimeSyncStart(dmabuf_fd_.get()); |
| return data_; |
| } |
| -void ClientNativePixmapDmaBuf::Unmap() {} |
| +void ClientNativePixmapDmaBuf::Unmap() { |
| + TRACE_EVENT0("drm", "DmaBuf:Unmap"); |
| + PrimeSyncEnd(dmabuf_fd_.get()); |
| +} |
| void ClientNativePixmapDmaBuf::GetStride(int* stride) const { |
| *stride = stride_; |