Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1255)

Unified Diff: ui/ozone/platform/drm/gpu/client_native_pixmap_vgem.cc

Issue 1134993003: ozone: Implement zero/one-copy texture for Ozone GBM. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: open VGEM device in renderer in ad-hoc manner Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..7a219620cfb22f1f062305960d7a784d274e186f
--- /dev/null
+++ b/ui/ozone/platform/drm/gpu/client_native_pixmap_vgem.cc
@@ -0,0 +1,130 @@
+// 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)
+#include <vgem_drm.h>
+#endif
+
+namespace ui {
+
+namespace {
+
+// TODO(dshwang): stride depends on driver, so plumb it from gpu process.
+int StrideInBytes(size_t width, gfx::BufferFormat format) {
+ switch (format) {
+ case gfx::BufferFormat::BGRA_8888:
+ case gfx::BufferFormat::RGBX_8888:
+ return width * 4;
+ case gfx::BufferFormat::ATC:
+ case gfx::BufferFormat::ATCIA:
+ case gfx::BufferFormat::DXT1:
+ case gfx::BufferFormat::DXT5:
+ case gfx::BufferFormat::ETC1:
+ case gfx::BufferFormat::R_8:
+ case gfx::BufferFormat::RGBA_4444:
+ case gfx::BufferFormat::RGBA_8888:
+ case gfx::BufferFormat::YUV_420:
+ NOTREACHED();
+ break;
+ }
+ return 0;
+}
+
+} // namespace
+
+ClientNativePixmapVgem::ClientNativePixmapVgem(base::FileDescriptor handle,
+ base::FileDescriptor vgem_handle,
+ gfx::Size size,
+ gfx::BufferFormat format,
+ gfx::BufferUsage usage)
+ : vgem_bo_handle_(0),
+ dma_buf_(handle.fd),
+ vgem_fd_(vgem_handle),
+ size_(size),
+ format_(format),
+ stride_(StrideInBytes(size_.width(), format_)),
+ mmap_ptr_(nullptr) {
+ DCHECK(usage == gfx::BufferUsage::MAP);
+ DCHECK(vgem_fd_.fd >= 0);
+ DCHECK(dma_buf_.get() >= 0);
+}
+
+bool ClientNativePixmapVgem::Initialize() {
+ DCHECK(vgem_fd_.fd);
+ int ret = drmPrimeFDToHandle(vgem_fd_.fd, dma_buf_.get(), &vgem_bo_handle_);
+ if (ret) {
+ LOG(ERROR) << "drmPrimeFDToHandle failed, handle:" << vgem_bo_handle_;
+ return false;
+ }
+ return true;
+}
+
+ClientNativePixmapVgem::~ClientNativePixmapVgem() {
+ if (vgem_bo_handle_) {
+ struct drm_gem_close close;
+ memset(&close, 0, sizeof(close));
+ close.handle = vgem_bo_handle_;
+ int ret = drmIoctl(vgem_fd_.fd, DRM_IOCTL_GEM_CLOSE, &close);
+ if (ret)
+ LOG(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) {
+ LOG(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,
+ 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

Powered by Google App Engine
This is Rietveld 408576698