Chromium Code Reviews| Index: ui/ozone/platform/drm/gpu/client_native_pixmap_vgem.cc |
| diff --git a/ui/ozone/platform/drm/gpu/client_native_pixmap_vgem.cc b/ui/ozone/platform/drm/gpu/client_native_pixmap_vgem.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3997ff4f0a074e426d70245e7751fc8c26375187 |
| --- /dev/null |
| +++ b/ui/ozone/platform/drm/gpu/client_native_pixmap_vgem.cc |
| @@ -0,0 +1,104 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/ozone/platform/drm/gpu/client_native_pixmap_vgem.h" |
| + |
| +#include <fcntl.h> |
| +#include <sys/mman.h> |
| +#include <xf86drm.h> |
| + |
| +#include "base/trace_event/trace_event.h" |
| + |
| +#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
|
| +#include <vgem_drm.h> |
| +#endif |
| + |
| +namespace ui { |
| + |
| +ClientNativePixmapVgem::ClientNativePixmapVgem( |
| + const gfx::NativePixmapHandle& handle, |
| + const base::FileDescriptor& vgem_handle, |
| + const gfx::Size& size, |
| + gfx::BufferFormat format) |
| + : vgem_bo_handle_(0), |
| + dma_buf_(handle.fd.fd), |
| + vgem_fd_(vgem_handle), |
| + size_(size), |
| + format_(format), |
| + stride_(handle.stride), |
| + mmap_ptr_(nullptr) { |
| + DCHECK(vgem_fd_.fd >= 0); |
|
reveman
2015/08/06 12:08:35
DCHECK_GT
dshwang
2015/08/06 13:59:17
Done.
|
| + DCHECK(dma_buf_.get() >= 0); |
|
reveman
2015/08/06 12:08:35
DCHECK_GT
dshwang
2015/08/06 13:59:17
Done.
|
| +} |
| + |
| +bool ClientNativePixmapVgem::Initialize() { |
| + 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()
|
| + int ret = drmPrimeFDToHandle(vgem_fd_.fd, dma_buf_.get(), &vgem_bo_handle_); |
| + if (ret) { |
| + PLOG(ERROR) << "drmPrimeFDToHandle failed, handle:" << vgem_bo_handle_; |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +ClientNativePixmapVgem::~ClientNativePixmapVgem() { |
| + 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.
|
| + struct drm_gem_close close; |
| + 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 :)
|
| + close.handle = vgem_bo_handle_; |
| + int ret = drmIoctl(vgem_fd_.fd, DRM_IOCTL_GEM_CLOSE, &close); |
| + if (ret) |
| + PLOG(ERROR) << "fail to free a vgem buffer. error:" << ret; |
| + vgem_bo_handle_ = 0; |
| + } |
| +} |
| + |
| +bool ClientNativePixmapVgem::Map(void** data) { |
| +#if defined(OZONE_USE_VGEM_MAP) |
| + TRACE_EVENT0("gpu", "ClientNativePixmapVgem::Map"); |
| + DCHECK(!mmap_ptr_); |
| + DCHECK(vgem_bo_handle_); |
| + |
| + struct drm_mode_map_dumb mmap_arg; |
| + memset(&mmap_arg, 0, sizeof(mmap_arg)); |
| + mmap_arg.handle = vgem_bo_handle_; |
| + |
| + int ret = drmIoctl(vgem_fd_.fd, DRM_IOCTL_VGEM_MODE_MAP_DUMB, &mmap_arg); |
| + if (ret) { |
| + PLOG(ERROR) << "fail to map a vgem buffer. error:" << ret; |
| + return false; |
| + } |
| + DCHECK(mmap_arg.offset); |
| + |
| + size_t size = stride_ * size_.height(); |
| + 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
|
| + vgem_fd_.fd, mmap_arg.offset); |
| + DCHECK(mmap_ptr_ != MAP_FAILED); |
| + *data = mmap_ptr_; |
| + return true; |
| +#else |
| + NOTREACHED(); |
| + return false; |
| +#endif |
| +} |
| + |
| +void ClientNativePixmapVgem::Unmap() { |
| +#if defined(OZONE_USE_VGEM_MAP) |
| + TRACE_EVENT0("gpu", "ClientNativePixmapVgem::Unmap"); |
| + DCHECK(mmap_ptr_); |
| + DCHECK(vgem_bo_handle_); |
| + |
| + size_t size = stride_ * size_.height(); |
| + int ret = munmap(mmap_ptr_, size); |
| + DCHECK(!ret); |
| + mmap_ptr_ = nullptr; |
| +#else |
| + NOTREACHED(); |
| +#endif |
| +} |
| +void ClientNativePixmapVgem::GetStride(int* stride) const { |
| + *stride = stride_; |
| +} |
| + |
| +} // namespace ui |