Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.cc

Issue 1841683003: ui/ozone: Flush CPU caches when mapping/unmapping prime pixmap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix spang comments and use local definition for ioctl Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #if defined(OS_CHROMEOS)
9 /*
10 * TODO(vignatti): replace the local definitions below with #include
11 * <linux/dma-buf.h> once kernel version 4.6 becomes widely used.
12 */
13 #include <linux/types.h>
14
15 struct local_dma_buf_sync {
16 __u64 flags;
17 };
18
19 #define LOCAL_DMA_BUF_SYNC_READ (1 << 0)
20 #define LOCAL_DMA_BUF_SYNC_WRITE (2 << 0)
21 #define LOCAL_DMA_BUF_SYNC_START (0 << 2)
22 #define LOCAL_DMA_BUF_SYNC_END (1 << 2)
23
24 #define LOCAL_DMA_BUF_BASE 'b'
25 #define LOCAL_DMA_BUF_IOCTL_SYNC _IOW(LOCAL_DMA_BUF_BASE, 0, struct local_d ma_buf_sync)
26 #endif
spang 2016/03/30 21:03:25 Use a C++ style comment and move it below the #inc
vignatti (out of this project) 2016/03/30 21:13:56 Done.
8 #include <stddef.h> 27 #include <stddef.h>
9 #include <sys/mman.h> 28 #include <sys/mman.h>
10 #include <xf86drm.h> 29 #include <xf86drm.h>
11 30
12 #include "base/process/memory.h" 31 #include "base/process/memory.h"
13 #include "base/trace_event/trace_event.h" 32 #include "base/trace_event/trace_event.h"
14 33
15 namespace ui { 34 namespace ui {
16 35
36 namespace {
37
38 void PrimeSyncStart(int dmabuf_fd) {
39 struct local_dma_buf_sync sync_start = {0};
40
41 sync_start.flags = LOCAL_DMA_BUF_SYNC_START | LOCAL_DMA_BUF_SYNC_READ;
42 if (drmIoctl(dmabuf_fd, LOCAL_DMA_BUF_IOCTL_SYNC, &sync_start))
43 PLOG(ERROR) << "fail to sync start dma buf fd";
spang 2016/03/30 21:03:25 "Failed to" or better yet "Failed DMA_BUF_IOCTL_SY
vignatti (out of this project) 2016/03/30 21:13:56 Done. But I've used "Failed DMA_BUF_SYNC_START" an
44 }
45
46 void PrimeSyncEnd(int dmabuf_fd) {
47 struct local_dma_buf_sync sync_end = {0};
48
49 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 PLOG(ERROR) << "fail to sync end dma buf fd";
52 }
53
54 } // namespace
55
17 // static 56 // static
18 scoped_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf( 57 scoped_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf(
19 int dmabuf_fd, 58 int dmabuf_fd,
20 const gfx::Size& size, 59 const gfx::Size& size,
21 int stride) { 60 int stride) {
22 DCHECK_GE(dmabuf_fd, 0); 61 DCHECK_GE(dmabuf_fd, 0);
23 return make_scoped_ptr(new ClientNativePixmapDmaBuf(dmabuf_fd, size, stride)); 62 return make_scoped_ptr(new ClientNativePixmapDmaBuf(dmabuf_fd, size, stride));
24 } 63 }
25 64
26 ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd, 65 ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd,
27 const gfx::Size& size, 66 const gfx::Size& size,
28 int stride) 67 int stride)
29 : size_(size), stride_(stride) { 68 : dmabuf_fd_(dmabuf_fd), size_(size), stride_(stride) {
30 TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf"); 69 TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf");
31 size_t map_size = stride_ * size_.height(); 70 size_t map_size = stride_ * size_.height();
32 data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED, 71 data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED,
33 dmabuf_fd, 0); 72 dmabuf_fd, 0);
34 CHECK_NE(data_, MAP_FAILED); 73 CHECK_NE(data_, MAP_FAILED);
35 } 74 }
36 75
37 ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() { 76 ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() {
38 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf"); 77 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf");
39 size_t size = stride_ * size_.height(); 78 size_t size = stride_ * size_.height();
40 int ret = munmap(data_, size); 79 int ret = munmap(data_, size);
41 DCHECK(!ret); 80 DCHECK(!ret);
42 } 81 }
43 82
44 void* ClientNativePixmapDmaBuf::Map() { 83 void* ClientNativePixmapDmaBuf::Map() {
84 TRACE_EVENT0("drm", "DmaBuf:Map");
85 PrimeSyncStart(dmabuf_fd_.get());
45 return data_; 86 return data_;
46 } 87 }
47 88
48 void ClientNativePixmapDmaBuf::Unmap() {} 89 void ClientNativePixmapDmaBuf::Unmap() {
90 TRACE_EVENT0("drm", "DmaBuf:Unmap");
91 PrimeSyncEnd(dmabuf_fd_.get());
92 }
49 93
50 void ClientNativePixmapDmaBuf::GetStride(int* stride) const { 94 void ClientNativePixmapDmaBuf::GetStride(int* stride) const {
51 *stride = stride_; 95 *stride = stride_;
52 } 96 }
53 97
54 } // namespace ui 98 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698