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

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: make content_unittests (GpuMemoryBuffer*) pass 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..a9a3c0976594e74d6d8af8b1a6bbf52a4d2b8ce0
--- /dev/null
+++ b/ui/ozone/platform/drm/gpu/client_native_pixmap_vgem.cc
@@ -0,0 +1,94 @@
+// 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 <vgem_drm.h>
+#include <xf86drm.h>
+
+#include "base/trace_event/trace_event.h"
+
+namespace ui {
+
+// static
+scoped_ptr<ClientNativePixmap> ClientNativePixmapVgem::Create(
+ const gfx::NativePixmapHandle& handle,
+ const base::FileDescriptor& vgem_handle,
+ const gfx::Size& size) {
+ DCHECK_GE(vgem_handle.fd, 0);
+ DCHECK_GE(handle.fd.fd, 0);
+ uint32_t vgem_bo_handle = 0;
+ int ret = drmPrimeFDToHandle(vgem_handle.fd, handle.fd.fd, &vgem_bo_handle);
+ if (ret) {
+ PLOG(ERROR) << "drmPrimeFDToHandle failed, handle:" << vgem_bo_handle;
+ return nullptr;
+ }
+ return make_scoped_ptr(
+ new ClientNativePixmapVgem(handle, vgem_handle, size, vgem_bo_handle));
+}
+
+ClientNativePixmapVgem::ClientNativePixmapVgem(
+ const gfx::NativePixmapHandle& handle,
+ const base::FileDescriptor& vgem_handle,
+ const gfx::Size& size,
+ uint32_t vgem_bo_handle)
+ : dma_buf_(handle.fd.fd),
+ vgem_fd_(vgem_handle),
+ size_(size),
+ vgem_bo_handle_(vgem_bo_handle),
+ stride_(handle.stride),
+ data_(nullptr) {
+ DCHECK(vgem_bo_handle_);
+}
+
+ClientNativePixmapVgem::~ClientNativePixmapVgem() {
+ DCHECK(!data_);
+ struct drm_gem_close close = {0};
+ 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) {
+ TRACE_EVENT0("gpu", "ClientNativePixmapVgem::Map");
+ DCHECK(!data_);
+ struct drm_mode_map_dumb mmap_arg = {0};
+ 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();
+ data_ = mmap(nullptr, size, (PROT_READ | PROT_WRITE), MAP_SHARED, vgem_fd_.fd,
+ mmap_arg.offset);
+ DCHECK_NE(data_, MAP_FAILED);
+ *data = data_;
+ return true;
+}
+
+void ClientNativePixmapVgem::Unmap() {
+ TRACE_EVENT0("gpu", "ClientNativePixmapVgem::Unmap");
+ DCHECK(data_);
+
+ // TODO(dshwang): keep it consistently mapped, and unmap it in dtor.
+ size_t size = stride_ * size_.height();
+ int ret = munmap(data_, size);
+ if (ret)
+ PLOG(ERROR) << "fail to munmap a vgem buffer. error:" << ret;
+ data_ = nullptr;
+}
+
+void ClientNativePixmapVgem::GetStride(int* stride) const {
+ *stride = stride_;
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698