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..a7ac8cb5f81308250a664723a26529ba3a22ec10 100644 |
| --- a/ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.cc |
| +++ b/ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.cc |
| @@ -4,7 +4,9 @@ |
| #include "ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.h" |
| +#include <errno.h> |
| #include <fcntl.h> |
| +#include <linux/dma-buf.h> |
| #include <stddef.h> |
| #include <sys/mman.h> |
| #include <xf86drm.h> |
| @@ -14,6 +16,27 @@ |
| namespace ui { |
| +namespace { |
| + |
| +void PrimeSyncStart(int dmabuf_fd) { |
| + struct dma_buf_sync sync_start; |
| + |
| + memset(&sync_start, 0, sizeof(sync_start)); |
|
dshwang
2016/03/29 13:23:40
we can change it to c++ style.
struct dma_buf_sync
vignatti (out of this project)
2016/03/29 21:08:30
Done.
|
| + sync_start.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_READ; |
| + if (drmIoctl(dmabuf_fd, DMA_BUF_IOCTL_SYNC, &sync_start)) |
| + LOG(ERROR) << "fail to sync start dma buf fd, errno: " << errno; |
| +} |
| + |
| +void PrimeSyncEnd(int dmabuf_fd) { |
| + struct dma_buf_sync sync_end; |
| + |
| + memset(&sync_end, 0, sizeof(sync_end)); |
| + sync_end.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_WRITE; |
| + if (drmIoctl(dmabuf_fd, DMA_BUF_IOCTL_SYNC, &sync_end)) |
| + LOG(ERROR) << "fail to sync end dma buf fd, errno " << errno; |
| +} |
| +} |
| + |
| // static |
| scoped_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf( |
| int dmabuf_fd, |
| @@ -26,7 +49,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) { |
| TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf"); |
| size_t map_size = stride_ * size_.height(); |
| data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED, |
| @@ -36,16 +59,23 @@ ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd, |
| ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() { |
| TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf"); |
| + close(dmabuf_fd_); |
| + |
| size_t size = stride_ * size_.height(); |
| int ret = munmap(data_, size); |
| DCHECK(!ret); |
| } |
| void* ClientNativePixmapDmaBuf::Map() { |
| + TRACE_EVENT0("nativepixmap", "DmaBuf:Map"); |
| + PrimeSyncStart(dmabuf_fd_); |
| return data_; |
| } |
| -void ClientNativePixmapDmaBuf::Unmap() {} |
| +void ClientNativePixmapDmaBuf::Unmap() { |
| + TRACE_EVENT0("nativepixmap", "DmaBuf:Unmap"); |
| + PrimeSyncEnd(dmabuf_fd_); |
| +} |
| void ClientNativePixmapDmaBuf::GetStride(int* stride) const { |
| *stride = stride_; |