OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.h" |
| 6 |
| 7 #include <fcntl.h> |
| 8 #include <stddef.h> |
| 9 #include <sys/mman.h> |
| 10 #include <xf86drm.h> |
| 11 |
| 12 #include "base/process/memory.h" |
| 13 #include "base/trace_event/trace_event.h" |
| 14 |
| 15 namespace ui { |
| 16 |
| 17 // static |
| 18 scoped_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf( |
| 19 int dmabuf_fd, |
| 20 const gfx::Size& size, |
| 21 int stride) { |
| 22 DCHECK_GE(dmabuf_fd, 0); |
| 23 return make_scoped_ptr(new ClientNativePixmapDmaBuf(dmabuf_fd, size, stride)); |
| 24 } |
| 25 |
| 26 ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd, |
| 27 const gfx::Size& size, |
| 28 int stride) |
| 29 : size_(size), stride_(stride) { |
| 30 TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf"); |
| 31 size_t map_size = stride_ * size_.height(); |
| 32 data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED, |
| 33 dmabuf_fd, 0); |
| 34 CHECK_NE(data_, MAP_FAILED); |
| 35 } |
| 36 |
| 37 ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() { |
| 38 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf"); |
| 39 size_t size = stride_ * size_.height(); |
| 40 int ret = munmap(data_, size); |
| 41 DCHECK(!ret); |
| 42 } |
| 43 |
| 44 void* ClientNativePixmapDmaBuf::Map() { |
| 45 return data_; |
| 46 } |
| 47 |
| 48 void ClientNativePixmapDmaBuf::Unmap() {} |
| 49 |
| 50 void ClientNativePixmapDmaBuf::GetStride(int* stride) const { |
| 51 *stride = stride_; |
| 52 } |
| 53 |
| 54 } // namespace ui |
OLD | NEW |