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/ozone/platform/drm/common/client_native_pixmap_dmabuf.h" | 5 #include "ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.h" |
| 6 | 6 |
| 7 #include <errno.h> | |
| 7 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <linux/dma-buf.h> | |
| 8 #include <stddef.h> | 10 #include <stddef.h> |
| 9 #include <sys/mman.h> | 11 #include <sys/mman.h> |
| 10 #include <xf86drm.h> | 12 #include <xf86drm.h> |
| 11 | 13 |
| 12 #include "base/process/memory.h" | 14 #include "base/process/memory.h" |
| 13 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 14 | 16 |
| 15 namespace ui { | 17 namespace ui { |
| 16 | 18 |
| 19 namespace { | |
| 20 | |
| 21 void PrimeSyncStart(int dmabuf_fd) { | |
| 22 struct dma_buf_sync sync_start = {0}; | |
| 23 | |
| 24 sync_start.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_READ; | |
| 25 if (drmIoctl(dmabuf_fd, DMA_BUF_IOCTL_SYNC, &sync_start)) | |
| 26 LOG(ERROR) << "fail to sync start dma buf fd, errno: " << errno; | |
|
spang
2016/03/30 00:19:00
PLOG(ERROR)
vignatti (out of this project)
2016/03/30 20:04:23
Done.
| |
| 27 } | |
| 28 | |
| 29 void PrimeSyncEnd(int dmabuf_fd) { | |
| 30 struct dma_buf_sync sync_end = {0}; | |
| 31 | |
| 32 sync_end.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_WRITE; | |
| 33 if (drmIoctl(dmabuf_fd, DMA_BUF_IOCTL_SYNC, &sync_end)) | |
| 34 LOG(ERROR) << "fail to sync end dma buf fd, errno " << errno; | |
|
spang
2016/03/30 00:19:00
PLOG(ERROR)
vignatti (out of this project)
2016/03/30 20:04:23
Done.
| |
| 35 } | |
| 36 } | |
|
spang
2016/03/30 00:19:00
Add a newline between the braces and say
} // na
vignatti (out of this project)
2016/03/30 20:04:23
Done.
| |
| 37 | |
| 17 // static | 38 // static |
| 18 scoped_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf( | 39 scoped_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf( |
| 19 int dmabuf_fd, | 40 int dmabuf_fd, |
| 20 const gfx::Size& size, | 41 const gfx::Size& size, |
| 21 int stride) { | 42 int stride) { |
| 22 DCHECK_GE(dmabuf_fd, 0); | 43 DCHECK_GE(dmabuf_fd, 0); |
| 23 return make_scoped_ptr(new ClientNativePixmapDmaBuf(dmabuf_fd, size, stride)); | 44 return make_scoped_ptr(new ClientNativePixmapDmaBuf(dmabuf_fd, size, stride)); |
| 24 } | 45 } |
| 25 | 46 |
| 26 ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd, | 47 ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd, |
| 27 const gfx::Size& size, | 48 const gfx::Size& size, |
| 28 int stride) | 49 int stride) |
| 29 : size_(size), stride_(stride) { | 50 : dmabuf_fd_(dmabuf_fd), size_(size), stride_(stride) { |
| 30 TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf"); | 51 TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf"); |
| 31 size_t map_size = stride_ * size_.height(); | 52 size_t map_size = stride_ * size_.height(); |
| 32 data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED, | 53 data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED, |
| 33 dmabuf_fd, 0); | 54 dmabuf_fd, 0); |
| 34 CHECK_NE(data_, MAP_FAILED); | 55 CHECK_NE(data_, MAP_FAILED); |
| 35 } | 56 } |
| 36 | 57 |
| 37 ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() { | 58 ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() { |
| 38 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf"); | 59 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf"); |
| 60 | |
| 39 size_t size = stride_ * size_.height(); | 61 size_t size = stride_ * size_.height(); |
| 40 int ret = munmap(data_, size); | 62 int ret = munmap(data_, size); |
| 41 DCHECK(!ret); | 63 DCHECK(!ret); |
| 42 } | 64 } |
| 43 | 65 |
| 44 void* ClientNativePixmapDmaBuf::Map() { | 66 void* ClientNativePixmapDmaBuf::Map() { |
| 67 TRACE_EVENT0("nativepixmap", "DmaBuf:Map"); | |
|
spang
2016/03/30 00:19:00
Please, use "drm". This doesn't warrant its own tr
vignatti (out of this project)
2016/03/30 20:04:23
Done.
| |
| 68 PrimeSyncStart(dmabuf_fd_.get()); | |
| 45 return data_; | 69 return data_; |
| 46 } | 70 } |
| 47 | 71 |
| 48 void ClientNativePixmapDmaBuf::Unmap() {} | 72 void ClientNativePixmapDmaBuf::Unmap() { |
| 73 TRACE_EVENT0("nativepixmap", "DmaBuf:Unmap"); | |
| 74 PrimeSyncEnd(dmabuf_fd_.get()); | |
| 75 } | |
| 49 | 76 |
| 50 void ClientNativePixmapDmaBuf::GetStride(int* stride) const { | 77 void ClientNativePixmapDmaBuf::GetStride(int* stride) const { |
| 51 *stride = stride_; | 78 *stride = stride_; |
| 52 } | 79 } |
| 53 | 80 |
| 54 } // namespace ui | 81 } // namespace ui |
| OLD | NEW |