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> |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 } | 53 } |
54 | 54 |
55 } // namespace | 55 } // namespace |
56 | 56 |
57 // static | 57 // static |
58 std::unique_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf( | 58 std::unique_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf( |
59 int dmabuf_fd, | 59 int dmabuf_fd, |
60 const gfx::Size& size, | 60 const gfx::Size& size, |
61 int stride) { | 61 int stride) { |
62 DCHECK_GE(dmabuf_fd, 0); | 62 DCHECK_GE(dmabuf_fd, 0); |
63 base::CheckedNumeric<size_t> map_size = stride; | |
64 map_size *= size.height(); | |
65 if (!map_size.IsValid()) | |
66 return nullptr; | |
63 return base::WrapUnique( | 67 return base::WrapUnique( |
64 new ClientNativePixmapDmaBuf(dmabuf_fd, size, stride)); | 68 new ClientNativePixmapDmaBuf(dmabuf_fd, stride, map_size.ValueOrDie())); |
65 } | 69 } |
66 | 70 |
67 ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd, | 71 ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd, |
68 const gfx::Size& size, | 72 int stride, |
69 int stride) | 73 size_t map_size) |
70 : dmabuf_fd_(dmabuf_fd), size_(size), stride_(stride) { | 74 : dmabuf_fd_(dmabuf_fd), map_size_(map_size), stride_(stride) { |
rjkroege
2016/09/02 19:02:03
Can you retain the gfx::size in the class? It migh
sadrul
2016/09/02 19:07:17
Done.
| |
71 TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf"); | 75 TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf"); |
72 size_t map_size = stride_ * size_.height(); | 76 data_ = mmap(nullptr, map_size_, (PROT_READ | PROT_WRITE), MAP_SHARED, |
73 data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED, | |
74 dmabuf_fd, 0); | 77 dmabuf_fd, 0); |
75 if (data_ == MAP_FAILED) { | 78 if (data_ == MAP_FAILED) { |
76 PLOG(ERROR) << "Failed mmap()."; | 79 PLOG(ERROR) << "Failed mmap()."; |
77 base::TerminateBecauseOutOfMemory(map_size); | 80 base::TerminateBecauseOutOfMemory(map_size_); |
78 } | 81 } |
79 } | 82 } |
80 | 83 |
81 ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() { | 84 ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() { |
82 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf"); | 85 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf"); |
83 size_t size = stride_ * size_.height(); | 86 int ret = munmap(data_, map_size_); |
84 int ret = munmap(data_, size); | |
85 DCHECK(!ret); | 87 DCHECK(!ret); |
86 } | 88 } |
87 | 89 |
88 void* ClientNativePixmapDmaBuf::Map() { | 90 void* ClientNativePixmapDmaBuf::Map() { |
89 TRACE_EVENT0("drm", "DmaBuf:Map"); | 91 TRACE_EVENT0("drm", "DmaBuf:Map"); |
90 PrimeSyncStart(dmabuf_fd_.get()); | 92 PrimeSyncStart(dmabuf_fd_.get()); |
91 return data_; | 93 return data_; |
92 } | 94 } |
93 | 95 |
94 void ClientNativePixmapDmaBuf::Unmap() { | 96 void ClientNativePixmapDmaBuf::Unmap() { |
95 TRACE_EVENT0("drm", "DmaBuf:Unmap"); | 97 TRACE_EVENT0("drm", "DmaBuf:Unmap"); |
96 PrimeSyncEnd(dmabuf_fd_.get()); | 98 PrimeSyncEnd(dmabuf_fd_.get()); |
97 } | 99 } |
98 | 100 |
99 void ClientNativePixmapDmaBuf::GetStride(int* stride) const { | 101 void ClientNativePixmapDmaBuf::GetStride(int* stride) const { |
100 *stride = stride_; | 102 *stride = stride_; |
101 } | 103 } |
102 | 104 |
103 } // namespace ui | 105 } // namespace ui |
OLD | NEW |