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 <linux/version.h> | 8 #include <linux/version.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <sys/mman.h> | 10 #include <sys/mman.h> |
(...skipping 22 matching lines...) Expand all Loading... | |
33 | 33 |
34 #define LOCAL_DMA_BUF_BASE 'b' | 34 #define LOCAL_DMA_BUF_BASE 'b' |
35 #define LOCAL_DMA_BUF_IOCTL_SYNC \ | 35 #define LOCAL_DMA_BUF_IOCTL_SYNC \ |
36 _IOW(LOCAL_DMA_BUF_BASE, 0, struct local_dma_buf_sync) | 36 _IOW(LOCAL_DMA_BUF_BASE, 0, struct local_dma_buf_sync) |
37 | 37 |
38 #else | 38 #else |
39 #include <linux/dma-buf.h> | 39 #include <linux/dma-buf.h> |
40 #endif | 40 #endif |
41 | 41 |
42 namespace ui { | 42 namespace ui { |
43 | |
44 namespace { | 43 namespace { |
45 | 44 |
46 void PrimeSyncStart(int dmabuf_fd) { | 45 bool PrimeSyncStart(int dmabuf_fd) { |
47 struct local_dma_buf_sync sync_start = {0}; | 46 struct local_dma_buf_sync sync_start = {0}; |
48 | 47 |
49 sync_start.flags = LOCAL_DMA_BUF_SYNC_START | LOCAL_DMA_BUF_SYNC_RW; | 48 sync_start.flags = LOCAL_DMA_BUF_SYNC_START | LOCAL_DMA_BUF_SYNC_RW; |
50 if (drmIoctl(dmabuf_fd, LOCAL_DMA_BUF_IOCTL_SYNC, &sync_start)) | 49 return !drmIoctl(dmabuf_fd, LOCAL_DMA_BUF_IOCTL_SYNC, &sync_start); |
51 PLOG(ERROR) << "Failed DMA_BUF_SYNC_START"; | |
52 } | 50 } |
53 | 51 |
54 void PrimeSyncEnd(int dmabuf_fd) { | 52 bool PrimeSyncEnd(int dmabuf_fd) { |
55 struct local_dma_buf_sync sync_end = {0}; | 53 struct local_dma_buf_sync sync_end = {0}; |
56 | 54 |
57 sync_end.flags = LOCAL_DMA_BUF_SYNC_END | LOCAL_DMA_BUF_SYNC_RW; | 55 sync_end.flags = LOCAL_DMA_BUF_SYNC_END | LOCAL_DMA_BUF_SYNC_RW; |
58 if (drmIoctl(dmabuf_fd, LOCAL_DMA_BUF_IOCTL_SYNC, &sync_end)) | 56 return !drmIoctl(dmabuf_fd, LOCAL_DMA_BUF_IOCTL_SYNC, &sync_end); |
59 PLOG(ERROR) << "Failed DMA_BUF_SYNC_END"; | |
60 } | 57 } |
61 | 58 |
62 } // namespace | 59 } // namespace |
63 | 60 |
64 // static | 61 // static |
65 std::unique_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf( | 62 std::unique_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf( |
66 const gfx::NativePixmapHandle& handle, | 63 const gfx::NativePixmapHandle& handle, |
67 const gfx::Size& size) { | 64 const gfx::Size& size) { |
68 return base::WrapUnique(new ClientNativePixmapDmaBuf(handle, size)); | 65 return base::WrapUnique(new ClientNativePixmapDmaBuf(handle, size)); |
69 } | 66 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf"); | 114 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf"); |
118 size_t map_size = | 115 size_t map_size = |
119 pixmap_handle_.planes.back().offset + pixmap_handle_.planes.back().size; | 116 pixmap_handle_.planes.back().offset + pixmap_handle_.planes.back().size; |
120 int ret = munmap(data_, map_size); | 117 int ret = munmap(data_, map_size); |
121 DCHECK(!ret); | 118 DCHECK(!ret); |
122 } | 119 } |
123 | 120 |
124 bool ClientNativePixmapDmaBuf::Map() { | 121 bool ClientNativePixmapDmaBuf::Map() { |
125 TRACE_EVENT0("drm", "DmaBuf:Map"); | 122 TRACE_EVENT0("drm", "DmaBuf:Map"); |
126 if (data_ != nullptr) { | 123 if (data_ != nullptr) { |
127 PrimeSyncStart(dmabuf_fd_.get()); | 124 bool rv = PrimeSyncStart(dmabuf_fd_.get()); |
125 PLOG_IF(ERROR, !rv && !map_count_) << "PrimeSyncStart Failed"; | |
128 return true; | 126 return true; |
129 } | 127 } |
130 return false; | 128 return false; |
131 } | 129 } |
132 | 130 |
133 void ClientNativePixmapDmaBuf::Unmap() { | 131 void ClientNativePixmapDmaBuf::Unmap() { |
134 TRACE_EVENT0("drm", "DmaBuf:Unmap"); | 132 TRACE_EVENT0("drm", "DmaBuf:Unmap"); |
135 PrimeSyncEnd(dmabuf_fd_.get()); | 133 bool rv = PrimeSyncEnd(dmabuf_fd_.get()); |
134 PLOG_IF(ERROR, !rv && !map_count_) << "PrimeSyncEnd Failed"; | |
135 ++map_count_; | |
Daniele Castagna
2017/03/24 00:53:10
nit: If we increment it here it's not really a map
| |
136 } | 136 } |
137 | 137 |
138 void* ClientNativePixmapDmaBuf::GetMemoryAddress(size_t plane) const { | 138 void* ClientNativePixmapDmaBuf::GetMemoryAddress(size_t plane) const { |
139 DCHECK_LT(plane, pixmap_handle_.planes.size()); | 139 DCHECK_LT(plane, pixmap_handle_.planes.size()); |
140 uint8_t* address = reinterpret_cast<uint8_t*>(data_); | 140 uint8_t* address = reinterpret_cast<uint8_t*>(data_); |
141 return address + pixmap_handle_.planes[plane].offset; | 141 return address + pixmap_handle_.planes[plane].offset; |
142 } | 142 } |
143 | 143 |
144 int ClientNativePixmapDmaBuf::GetStride(size_t plane) const { | 144 int ClientNativePixmapDmaBuf::GetStride(size_t plane) const { |
145 DCHECK_LT(plane, pixmap_handle_.planes.size()); | 145 DCHECK_LT(plane, pixmap_handle_.planes.size()); |
146 return pixmap_handle_.planes[plane].stride; | 146 return pixmap_handle_.planes[plane].stride; |
147 } | 147 } |
148 | 148 |
149 } // namespace ui | 149 } // namespace ui |
OLD | NEW |