Index: ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.cc |
diff --git a/ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.cc b/ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1586a17a011e5e72828dfdcc38d2b189c7dba008 |
--- /dev/null |
+++ b/ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.cc |
@@ -0,0 +1,54 @@ |
+// Copyright 2016 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/common/client_native_pixmap_dmabuf.h" |
+ |
+#include <fcntl.h> |
+#include <stddef.h> |
+#include <sys/mman.h> |
+#include <xf86drm.h> |
+ |
+#include "base/process/memory.h" |
+#include "base/trace_event/trace_event.h" |
+ |
+namespace ui { |
+ |
+// static |
+scoped_ptr<ClientNativePixmap> ClientNativePixmapDmaBuf::ImportFromDmabuf( |
+ int dmabuf_fd, |
+ const gfx::Size& size, |
+ int stride) { |
+ DCHECK_GE(dmabuf_fd, 0); |
+ return make_scoped_ptr(new ClientNativePixmapDmaBuf(dmabuf_fd, size, stride)); |
+} |
+ |
+ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd, |
+ const gfx::Size& size, |
+ int stride) |
+ : size_(size), stride_(stride), data_(nullptr) { |
spang
2016/03/21 23:24:20
You don't need to initialize data_ here and in the
vignatti (out of this project)
2016/03/22 20:24:29
Done.
|
+ TRACE_EVENT0("nativepixmap", "ClientNativePixmapDmaBuf"); |
spang
2016/03/21 23:24:20
Please use the "drm" category.
vignatti (out of this project)
2016/03/22 20:24:29
Done.
|
+ size_t map_size = stride_ * size_.height(); |
+ data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED, |
+ dmabuf_fd, 0); |
+ DCHECK_NE(data_, MAP_FAILED); |
+} |
+ |
+ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() { |
+ TRACE_EVENT0("nativepixmap", "~ClientNativePixmapDmaBuf"); |
spang
2016/03/21 23:24:20
Also here
vignatti (out of this project)
2016/03/22 20:24:29
Done.
|
+ size_t size = stride_ * size_.height(); |
+ int ret = munmap(data_, size); |
+ DCHECK(!ret) << "fail to munmap a dmabuf."; |
spang
2016/03/21 23:24:20
DPCHECK(!ret);
Don't really need a message for DC
vignatti (out of this project)
2016/03/22 20:24:29
Done.
|
+} |
+ |
+void* ClientNativePixmapDmaBuf::Map() { |
+ return data_; |
+} |
+ |
+void ClientNativePixmapDmaBuf::Unmap() {} |
+ |
+void ClientNativePixmapDmaBuf::GetStride(int* stride) const { |
+ *stride = stride_; |
+} |
+ |
+} // namespace ui |