Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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/gpu/client_native_pixmap_vgem.h" | |
| 6 | |
| 7 #include <fcntl.h> | |
| 8 #include <sys/mman.h> | |
| 9 #include <xf86drm.h> | |
| 10 | |
| 11 #include "base/trace_event/trace_event.h" | |
| 12 | |
| 13 #if defined(OZONE_USE_VGEM_MAP) | |
|
reveman
2015/08/06 12:08:35
why would you be building this file if VGEM is not
dshwang
2015/08/06 13:59:17
Done. This file is compiled if only OZONE_USE_VGEM
| |
| 14 #include <vgem_drm.h> | |
| 15 #endif | |
| 16 | |
| 17 namespace ui { | |
| 18 | |
| 19 ClientNativePixmapVgem::ClientNativePixmapVgem( | |
| 20 const gfx::NativePixmapHandle& handle, | |
| 21 const base::FileDescriptor& vgem_handle, | |
| 22 const gfx::Size& size, | |
| 23 gfx::BufferFormat format) | |
| 24 : vgem_bo_handle_(0), | |
| 25 dma_buf_(handle.fd.fd), | |
| 26 vgem_fd_(vgem_handle), | |
| 27 size_(size), | |
| 28 format_(format), | |
| 29 stride_(handle.stride), | |
| 30 mmap_ptr_(nullptr) { | |
| 31 DCHECK(vgem_fd_.fd >= 0); | |
|
reveman
2015/08/06 12:08:35
DCHECK_GT
dshwang
2015/08/06 13:59:17
Done.
| |
| 32 DCHECK(dma_buf_.get() >= 0); | |
|
reveman
2015/08/06 12:08:35
DCHECK_GT
dshwang
2015/08/06 13:59:17
Done.
| |
| 33 } | |
| 34 | |
| 35 bool ClientNativePixmapVgem::Initialize() { | |
| 36 DCHECK(vgem_fd_.fd); | |
|
reveman
2015/08/06 12:08:35
why another dcheck here that is different from cto
dshwang
2015/08/06 13:59:17
Done. removed Initialize()
| |
| 37 int ret = drmPrimeFDToHandle(vgem_fd_.fd, dma_buf_.get(), &vgem_bo_handle_); | |
| 38 if (ret) { | |
| 39 PLOG(ERROR) << "drmPrimeFDToHandle failed, handle:" << vgem_bo_handle_; | |
| 40 return false; | |
| 41 } | |
| 42 return true; | |
| 43 } | |
| 44 | |
| 45 ClientNativePixmapVgem::~ClientNativePixmapVgem() { | |
| 46 if (vgem_bo_handle_) { | |
|
reveman
2015/08/06 12:08:35
note that this would be cleaner if you removed Ini
dshwang
2015/08/06 13:59:17
Got it. Resolve it via Create(). Done.
| |
| 47 struct drm_gem_close close; | |
| 48 memset(&close, 0, sizeof(close)); | |
|
reveman
2015/08/06 12:08:35
= { 0 } above instead?
dshwang
2015/08/06 13:59:17
good idea. I copied the code from linux :)
| |
| 49 close.handle = vgem_bo_handle_; | |
| 50 int ret = drmIoctl(vgem_fd_.fd, DRM_IOCTL_GEM_CLOSE, &close); | |
| 51 if (ret) | |
| 52 PLOG(ERROR) << "fail to free a vgem buffer. error:" << ret; | |
| 53 vgem_bo_handle_ = 0; | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 bool ClientNativePixmapVgem::Map(void** data) { | |
| 58 #if defined(OZONE_USE_VGEM_MAP) | |
| 59 TRACE_EVENT0("gpu", "ClientNativePixmapVgem::Map"); | |
| 60 DCHECK(!mmap_ptr_); | |
| 61 DCHECK(vgem_bo_handle_); | |
| 62 | |
| 63 struct drm_mode_map_dumb mmap_arg; | |
| 64 memset(&mmap_arg, 0, sizeof(mmap_arg)); | |
| 65 mmap_arg.handle = vgem_bo_handle_; | |
| 66 | |
| 67 int ret = drmIoctl(vgem_fd_.fd, DRM_IOCTL_VGEM_MODE_MAP_DUMB, &mmap_arg); | |
| 68 if (ret) { | |
| 69 PLOG(ERROR) << "fail to map a vgem buffer. error:" << ret; | |
| 70 return false; | |
| 71 } | |
| 72 DCHECK(mmap_arg.offset); | |
| 73 | |
| 74 size_t size = stride_ * size_.height(); | |
| 75 mmap_ptr_ = mmap(nullptr, size, (PROT_READ | PROT_WRITE), MAP_SHARED, | |
|
reveman
2015/08/06 12:08:35
can we keep it consistently mapped instead of doin
dshwang
2015/08/06 13:59:17
Good idea. It's possible at least in Intel Core ar
| |
| 76 vgem_fd_.fd, mmap_arg.offset); | |
| 77 DCHECK(mmap_ptr_ != MAP_FAILED); | |
| 78 *data = mmap_ptr_; | |
| 79 return true; | |
| 80 #else | |
| 81 NOTREACHED(); | |
| 82 return false; | |
| 83 #endif | |
| 84 } | |
| 85 | |
| 86 void ClientNativePixmapVgem::Unmap() { | |
| 87 #if defined(OZONE_USE_VGEM_MAP) | |
| 88 TRACE_EVENT0("gpu", "ClientNativePixmapVgem::Unmap"); | |
| 89 DCHECK(mmap_ptr_); | |
| 90 DCHECK(vgem_bo_handle_); | |
| 91 | |
| 92 size_t size = stride_ * size_.height(); | |
| 93 int ret = munmap(mmap_ptr_, size); | |
| 94 DCHECK(!ret); | |
| 95 mmap_ptr_ = nullptr; | |
| 96 #else | |
| 97 NOTREACHED(); | |
| 98 #endif | |
| 99 } | |
| 100 void ClientNativePixmapVgem::GetStride(int* stride) const { | |
| 101 *stride = stride_; | |
| 102 } | |
| 103 | |
| 104 } // namespace ui | |
| OLD | NEW |