Chromium Code Reviews| 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> |
| 11 #include <xf86drm.h> | 11 #include <xf86drm.h> |
| 12 | 12 |
| 13 #include "base/debug/crash_logging.h" | |
| 13 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/process/memory.h" | 15 #include "base/process/memory.h" |
| 16 #include "base/strings/stringprintf.h" | |
| 15 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
| 16 | 18 |
| 17 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0) | 19 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0) |
| 18 #include <linux/types.h> | 20 #include <linux/types.h> |
| 19 | 21 |
| 20 struct local_dma_buf_sync { | 22 struct local_dma_buf_sync { |
| 21 __u64 flags; | 23 __u64 flags; |
| 22 }; | 24 }; |
| 23 | 25 |
| 24 #define LOCAL_DMA_BUF_SYNC_READ (1 << 0) | 26 #define LOCAL_DMA_BUF_SYNC_READ (1 << 0) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 // TODO(dcastagna): support multiple fds. | 75 // TODO(dcastagna): support multiple fds. |
| 74 DCHECK_EQ(1u, handle.fds.size()); | 76 DCHECK_EQ(1u, handle.fds.size()); |
| 75 DCHECK_GE(handle.fds.front().fd, 0); | 77 DCHECK_GE(handle.fds.front().fd, 0); |
| 76 dmabuf_fd_.reset(handle.fds.front().fd); | 78 dmabuf_fd_.reset(handle.fds.front().fd); |
| 77 | 79 |
| 78 DCHECK_GE(handle.planes.back().size, 0u); | 80 DCHECK_GE(handle.planes.back().size, 0u); |
| 79 size_t map_size = handle.planes.back().offset + handle.planes.back().size; | 81 size_t map_size = handle.planes.back().offset + handle.planes.back().size; |
| 80 data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED, | 82 data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED, |
| 81 dmabuf_fd_.get(), 0); | 83 dmabuf_fd_.get(), 0); |
| 82 if (data_ == MAP_FAILED) { | 84 if (data_ == MAP_FAILED) { |
| 83 PLOG(ERROR) << "Failed mmap()."; | 85 logging::SystemErrorCode mmap_error = logging::GetLastSystemErrorCode(); |
|
reveman
2017/02/24 00:46:18
nit: please add a TODO comment with a bug referenc
Daniele Castagna
2017/02/24 01:18:21
Done.
| |
| 84 base::TerminateBecauseOutOfMemory(map_size); | 86 bool fd_valid = fcntl(dmabuf_fd_.get(), F_GETFD) != -1 || |
| 87 logging::GetLastSystemErrorCode() != EBADF; | |
| 88 std::string mmap_params = base::StringPrintf( | |
| 89 "(addr=nullptr, length=%zu, prot=(PROT_READ | PROT_WRITE), " | |
| 90 "flags=MAP_SHARED, fd=%d[valid=%d], offset=0)", | |
| 91 map_size, dmabuf_fd_.get(), fd_valid); | |
| 92 base::debug::ScopedCrashKey params_crash_key("mmap_params", mmap_params); | |
| 93 base::debug::ScopedCrashKey size_crash_key("buffer_size", size.ToString()); | |
| 94 base::debug::ScopedCrashKey errno_crash_key( | |
| 95 "errno", logging::SystemErrorCodeToString(mmap_error)); | |
| 96 if (mmap_error == ENOMEM) { | |
| 97 base::TerminateBecauseOutOfMemory(map_size); | |
| 98 } else { | |
|
reveman
2017/02/24 00:46:18
nit: remove else as base::TerminateBecauseOutOfMem
Daniele Castagna
2017/02/24 01:18:21
Done.
| |
| 99 CHECK(false) << "Failed to mmap dmabuf."; | |
| 100 } | |
| 85 } | 101 } |
| 86 } | 102 } |
| 87 | 103 |
| 88 ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() { | 104 ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() { |
| 89 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf"); | 105 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf"); |
| 90 size_t map_size = | 106 size_t map_size = |
| 91 pixmap_handle_.planes.back().offset + pixmap_handle_.planes.back().size; | 107 pixmap_handle_.planes.back().offset + pixmap_handle_.planes.back().size; |
| 92 int ret = munmap(data_, map_size); | 108 int ret = munmap(data_, map_size); |
| 93 DCHECK(!ret); | 109 DCHECK(!ret); |
| 94 } | 110 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 112 uint8_t* address = reinterpret_cast<uint8_t*>(data_); | 128 uint8_t* address = reinterpret_cast<uint8_t*>(data_); |
| 113 return address + pixmap_handle_.planes[plane].offset; | 129 return address + pixmap_handle_.planes[plane].offset; |
| 114 } | 130 } |
| 115 | 131 |
| 116 int ClientNativePixmapDmaBuf::GetStride(size_t plane) const { | 132 int ClientNativePixmapDmaBuf::GetStride(size_t plane) const { |
| 117 DCHECK_LT(plane, pixmap_handle_.planes.size()); | 133 DCHECK_LT(plane, pixmap_handle_.planes.size()); |
| 118 return pixmap_handle_.planes[plane].stride; | 134 return pixmap_handle_.planes[plane].stride; |
| 119 } | 135 } |
| 120 | 136 |
| 121 } // namespace ui | 137 } // namespace ui |
| OLD | NEW |