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

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: 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 <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;
23
24 memset(&sync_start, 0, sizeof(sync_start));
dshwang 2016/03/29 13:23:40 we can change it to c++ style. struct dma_buf_sync
vignatti (out of this project) 2016/03/29 21:08:30 Done.
25 sync_start.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_READ;
26 if (drmIoctl(dmabuf_fd, DMA_BUF_IOCTL_SYNC, &sync_start))
27 LOG(ERROR) << "fail to sync start dma buf fd, errno: " << errno;
28 }
29
30 void PrimeSyncEnd(int dmabuf_fd) {
31 struct dma_buf_sync sync_end;
32
33 memset(&sync_end, 0, sizeof(sync_end));
34 sync_end.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_WRITE;
35 if (drmIoctl(dmabuf_fd, DMA_BUF_IOCTL_SYNC, &sync_end))
36 LOG(ERROR) << "fail to sync end dma buf fd, errno " << errno;
37 }
38 }
39
17 // static 40 // static
18 scoped_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf( 41 scoped_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf(
19 int dmabuf_fd, 42 int dmabuf_fd,
20 const gfx::Size& size, 43 const gfx::Size& size,
21 int stride) { 44 int stride) {
22 DCHECK_GE(dmabuf_fd, 0); 45 DCHECK_GE(dmabuf_fd, 0);
23 return make_scoped_ptr(new ClientNativePixmapDmaBuf(dmabuf_fd, size, stride)); 46 return make_scoped_ptr(new ClientNativePixmapDmaBuf(dmabuf_fd, size, stride));
24 } 47 }
25 48
26 ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd, 49 ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd,
27 const gfx::Size& size, 50 const gfx::Size& size,
28 int stride) 51 int stride)
29 : size_(size), stride_(stride) { 52 : dmabuf_fd_(dmabuf_fd), size_(size), stride_(stride) {
30 TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf"); 53 TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf");
31 size_t map_size = stride_ * size_.height(); 54 size_t map_size = stride_ * size_.height();
32 data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED, 55 data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED,
33 dmabuf_fd, 0); 56 dmabuf_fd, 0);
34 CHECK_NE(data_, MAP_FAILED); 57 CHECK_NE(data_, MAP_FAILED);
35 } 58 }
36 59
37 ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() { 60 ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() {
38 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf"); 61 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf");
62 close(dmabuf_fd_);
63
39 size_t size = stride_ * size_.height(); 64 size_t size = stride_ * size_.height();
40 int ret = munmap(data_, size); 65 int ret = munmap(data_, size);
41 DCHECK(!ret); 66 DCHECK(!ret);
42 } 67 }
43 68
44 void* ClientNativePixmapDmaBuf::Map() { 69 void* ClientNativePixmapDmaBuf::Map() {
70 TRACE_EVENT0("nativepixmap", "DmaBuf:Map");
71 PrimeSyncStart(dmabuf_fd_);
45 return data_; 72 return data_;
46 } 73 }
47 74
48 void ClientNativePixmapDmaBuf::Unmap() {} 75 void ClientNativePixmapDmaBuf::Unmap() {
76 TRACE_EVENT0("nativepixmap", "DmaBuf:Unmap");
77 PrimeSyncEnd(dmabuf_fd_);
78 }
49 79
50 void ClientNativePixmapDmaBuf::GetStride(int* stride) const { 80 void ClientNativePixmapDmaBuf::GetStride(int* stride) const {
51 *stride = stride_; 81 *stride = stride_;
52 } 82 }
53 83
54 } // namespace ui 84 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698