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

Unified Diff: ui/ozone/platform/drm/gpu/gbm_surface_factory.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: rebase to ToT Created 5 years, 5 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/gbm_surface_factory.cc
diff --git a/ui/ozone/platform/drm/gpu/gbm_surface_factory.cc b/ui/ozone/platform/drm/gpu/gbm_surface_factory.cc
index 2c0563df8fd6d9b7672168e0ed71498a4665e72f..8b00f3fa22847a350775c769437929dcac4e3092 100644
--- a/ui/ozone/platform/drm/gpu/gbm_surface_factory.cc
+++ b/ui/ozone/platform/drm/gpu/gbm_surface_factory.cc
@@ -7,6 +7,7 @@
#include <gbm.h>
#include "base/files/file_path.h"
+#include "base/posix/eintr_wrapper.h"
#include "third_party/khronos/EGL/egl.h"
#include "ui/ozone/common/egl_util.h"
#include "ui/ozone/platform/drm/gpu/drm_device_manager.h"
@@ -23,8 +24,26 @@
namespace ui {
+namespace {
+
+bool ShareToRenderProcess(int fd, base::FileDescriptor* new_handle) {
+ int duped_handle = HANDLE_EINTR(dup(fd));
+ if (duped_handle < 0) {
+ DPLOG(ERROR) << "dup() failed.";
+ *new_handle = base::FileDescriptor();
+ return false;
+ }
+
+ *new_handle = base::FileDescriptor(duped_handle, true);
+ return true;
+}
+
+} // namespace
+
GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless)
- : DrmSurfaceFactory(NULL), allow_surfaceless_(allow_surfaceless) {
+ : DrmSurfaceFactory(NULL),
+ allow_surfaceless_(allow_surfaceless),
+ drm_device_manager_(nullptr) {
}
GbmSurfaceFactory::~GbmSurfaceFactory() {
@@ -108,14 +127,11 @@ scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap(
gfx::Size size,
BufferFormat format,
BufferUsage usage) {
- if (usage == MAP)
- return nullptr;
-
scoped_refptr<GbmDevice> gbm = GetGbmDevice(widget);
DCHECK(gbm);
scoped_refptr<GbmBuffer> buffer =
- GbmBuffer::CreateBuffer(gbm, format, size, true);
+ GbmBuffer::CreateBuffer(gbm, format, size, usage == SCANOUT);
if (!buffer.get())
return nullptr;
@@ -126,6 +142,22 @@ scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap(
return pixmap;
}
+base::FileDescriptor GbmSurfaceFactory::ExportDmaBuf(
+ gfx::AcceleratedWidget widget,
+ scoped_refptr<NativePixmap> pixmap) {
+ scoped_refptr<GbmDevice> gbm = GetGbmDevice(widget);
+ DCHECK(gbm);
+ DCHECK(pixmap->GetBufferUsage() == NativePixmap::MAP);
+
+ base::FileDescriptor dma_buf;
+ if (!ShareToRenderProcess(pixmap->GetDmaBufFd(), &dma_buf)) {
+ DLOG(ERROR) << "Fail to duplicate a DMA-BUF file descriptor";
+ return base::FileDescriptor();
+ }
+
+ return dma_buf;
+}
+
bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() {
DCHECK(thread_checker_.CalledOnValidThread());
return allow_surfaceless_;

Powered by Google App Engine
This is Rietveld 408576698