| 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 <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <sys/mman.h> | 9 #include <sys/mman.h> |
| 10 #include <xf86drm.h> | 10 #include <xf86drm.h> |
| 11 | 11 |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/process/memory.h" | 13 #include "base/process/memory.h" |
| 13 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 14 | 15 |
| 15 #if defined(OS_CHROMEOS) | 16 #if defined(OS_CHROMEOS) |
| 16 // TODO(vignatti): replace the local definitions below with #include | 17 // TODO(vignatti): replace the local definitions below with #include |
| 17 // <linux/dma-buf.h> once kernel version 4.6 becomes widely used. | 18 // <linux/dma-buf.h> once kernel version 4.6 becomes widely used. |
| 18 #include <linux/types.h> | 19 #include <linux/types.h> |
| 19 | 20 |
| 20 struct local_dma_buf_sync { | 21 struct local_dma_buf_sync { |
| 21 __u64 flags; | 22 __u64 flags; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 47 struct local_dma_buf_sync sync_end = {0}; | 48 struct local_dma_buf_sync sync_end = {0}; |
| 48 | 49 |
| 49 sync_end.flags = LOCAL_DMA_BUF_SYNC_END | LOCAL_DMA_BUF_SYNC_WRITE; | 50 sync_end.flags = LOCAL_DMA_BUF_SYNC_END | LOCAL_DMA_BUF_SYNC_WRITE; |
| 50 if (drmIoctl(dmabuf_fd, LOCAL_DMA_BUF_IOCTL_SYNC, &sync_end)) | 51 if (drmIoctl(dmabuf_fd, LOCAL_DMA_BUF_IOCTL_SYNC, &sync_end)) |
| 51 PLOG(ERROR) << "Failed DMA_BUF_SYNC_END"; | 52 PLOG(ERROR) << "Failed DMA_BUF_SYNC_END"; |
| 52 } | 53 } |
| 53 | 54 |
| 54 } // namespace | 55 } // namespace |
| 55 | 56 |
| 56 // static | 57 // static |
| 57 scoped_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf( | 58 std::unique_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf( |
| 58 int dmabuf_fd, | 59 int dmabuf_fd, |
| 59 const gfx::Size& size, | 60 const gfx::Size& size, |
| 60 int stride) { | 61 int stride) { |
| 61 DCHECK_GE(dmabuf_fd, 0); | 62 DCHECK_GE(dmabuf_fd, 0); |
| 62 return make_scoped_ptr(new ClientNativePixmapDmaBuf(dmabuf_fd, size, stride)); | 63 return base::WrapUnique( |
| 64 new ClientNativePixmapDmaBuf(dmabuf_fd, size, stride)); |
| 63 } | 65 } |
| 64 | 66 |
| 65 ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd, | 67 ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd, |
| 66 const gfx::Size& size, | 68 const gfx::Size& size, |
| 67 int stride) | 69 int stride) |
| 68 : dmabuf_fd_(dmabuf_fd), size_(size), stride_(stride) { | 70 : dmabuf_fd_(dmabuf_fd), size_(size), stride_(stride) { |
| 69 TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf"); | 71 TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf"); |
| 70 size_t map_size = stride_ * size_.height(); | 72 size_t map_size = stride_ * size_.height(); |
| 71 data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED, | 73 data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED, |
| 72 dmabuf_fd, 0); | 74 dmabuf_fd, 0); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 89 void ClientNativePixmapDmaBuf::Unmap() { | 91 void ClientNativePixmapDmaBuf::Unmap() { |
| 90 TRACE_EVENT0("drm", "DmaBuf:Unmap"); | 92 TRACE_EVENT0("drm", "DmaBuf:Unmap"); |
| 91 PrimeSyncEnd(dmabuf_fd_.get()); | 93 PrimeSyncEnd(dmabuf_fd_.get()); |
| 92 } | 94 } |
| 93 | 95 |
| 94 void ClientNativePixmapDmaBuf::GetStride(int* stride) const { | 96 void ClientNativePixmapDmaBuf::GetStride(int* stride) const { |
| 95 *stride = stride_; | 97 *stride = stride_; |
| 96 } | 98 } |
| 97 | 99 |
| 98 } // namespace ui | 100 } // namespace ui |
| OLD | NEW |