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

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 missing semicolon 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 #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/process/memory.h" 12 #include "base/process/memory.h"
13 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.h"
14 14
15 #if defined(OS_CHROMEOS)
16 // TODO(vignatti): replace the local definitions below with #include
17 // <linux/dma-buf.h> once kernel version 4.6 becomes widely used.
18 #include <linux/types.h>
19
20 struct local_dma_buf_sync {
21 __u64 flags;
22 };
23
24 #define LOCAL_DMA_BUF_SYNC_READ (1 << 0)
25 #define LOCAL_DMA_BUF_SYNC_WRITE (2 << 0)
26 #define LOCAL_DMA_BUF_SYNC_START (0 << 2)
27 #define LOCAL_DMA_BUF_SYNC_END (1 << 2)
28
29 #define LOCAL_DMA_BUF_BASE 'b'
30 #define LOCAL_DMA_BUF_IOCTL_SYNC _IOW(LOCAL_DMA_BUF_BASE, 0, struct local_d ma_buf_sync)
31 #endif
32
15 namespace ui { 33 namespace ui {
16 34
35 namespace {
36
37 void PrimeSyncStart(int dmabuf_fd) {
38 struct local_dma_buf_sync sync_start = {0};
39
40 sync_start.flags = LOCAL_DMA_BUF_SYNC_START | LOCAL_DMA_BUF_SYNC_READ;
41 if (drmIoctl(dmabuf_fd, LOCAL_DMA_BUF_IOCTL_SYNC, &sync_start))
42 PLOG(ERROR) << "Failed DMA_BUF_SYNC_START";
43 }
44
45 void PrimeSyncEnd(int dmabuf_fd) {
46 struct local_dma_buf_sync sync_end = {0};
47
48 sync_end.flags = LOCAL_DMA_BUF_SYNC_END | LOCAL_DMA_BUF_SYNC_WRITE;
49 if (drmIoctl(dmabuf_fd, LOCAL_DMA_BUF_IOCTL_SYNC, &sync_end))
50 PLOG(ERROR) << "Failed DMA_BUF_SYNC_END";
51 }
52
53 } // namespace
54
17 // static 55 // static
18 scoped_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf( 56 scoped_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf(
19 int dmabuf_fd, 57 int dmabuf_fd,
20 const gfx::Size& size, 58 const gfx::Size& size,
21 int stride) { 59 int stride) {
22 DCHECK_GE(dmabuf_fd, 0); 60 DCHECK_GE(dmabuf_fd, 0);
23 return make_scoped_ptr(new ClientNativePixmapDmaBuf(dmabuf_fd, size, stride)); 61 return make_scoped_ptr(new ClientNativePixmapDmaBuf(dmabuf_fd, size, stride));
24 } 62 }
25 63
26 ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd, 64 ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd,
27 const gfx::Size& size, 65 const gfx::Size& size,
28 int stride) 66 int stride)
29 : size_(size), stride_(stride) { 67 : dmabuf_fd_(dmabuf_fd), size_(size), stride_(stride) {
30 TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf"); 68 TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf");
31 size_t map_size = stride_ * size_.height(); 69 size_t map_size = stride_ * size_.height();
32 data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED, 70 data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED,
33 dmabuf_fd, 0); 71 dmabuf_fd, 0);
34 CHECK_NE(data_, MAP_FAILED); 72 CHECK_NE(data_, MAP_FAILED);
35 } 73 }
36 74
37 ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() { 75 ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() {
38 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf"); 76 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf");
39 size_t size = stride_ * size_.height(); 77 size_t size = stride_ * size_.height();
40 int ret = munmap(data_, size); 78 int ret = munmap(data_, size);
41 DCHECK(!ret); 79 DCHECK(!ret);
42 } 80 }
43 81
44 void* ClientNativePixmapDmaBuf::Map() { 82 void* ClientNativePixmapDmaBuf::Map() {
83 TRACE_EVENT0("drm", "DmaBuf:Map");
84 PrimeSyncStart(dmabuf_fd_.get());
45 return data_; 85 return data_;
46 } 86 }
47 87
48 void ClientNativePixmapDmaBuf::Unmap() {} 88 void ClientNativePixmapDmaBuf::Unmap() {
89 TRACE_EVENT0("drm", "DmaBuf:Unmap");
90 PrimeSyncEnd(dmabuf_fd_.get());
91 }
49 92
50 void ClientNativePixmapDmaBuf::GetStride(int* stride) const { 93 void ClientNativePixmapDmaBuf::GetStride(int* stride) const {
51 *stride = stride_; 94 *stride = stride_;
52 } 95 }
53 96
54 } // namespace ui 97 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698