Index: content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.cc |
diff --git a/content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.cc b/content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.cc |
index d3e0576124a9be60c8f6e67f2dddfbc0ca0f63d8..990d0e2dc9d3f15f6482d394d7aac5a334c1e88d 100644 |
--- a/content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.cc |
+++ b/content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.cc |
@@ -4,6 +4,7 @@ |
#include "content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.h" |
+#include "base/posix/eintr_wrapper.h" |
#include "ui/gl/gl_image_ozone_native_pixmap.h" |
#include "ui/ozone/public/client_native_pixmap_factory.h" |
#include "ui/ozone/public/ozone_platform.h" |
@@ -24,6 +25,18 @@ void GetSupportedConfigurations( |
} |
} |
+bool ShareToClientProcess(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 |
GpuMemoryBufferFactoryOzoneNativePixmap:: |
@@ -79,6 +92,14 @@ GpuMemoryBufferFactoryOzoneNativePixmap::CreateGpuMemoryBuffer( |
gfx::GpuMemoryBufferHandle handle; |
handle.type = gfx::OZONE_NATIVE_PIXMAP; |
handle.id = id; |
+ if (usage == gfx::BufferUsage::MAP) { |
+ base::FileDescriptor dma_buf; |
+ if (!ShareToClientProcess(pixmap->GetDmaBufFd(), &dma_buf)) { |
+ DLOG(ERROR) << "Fail to duplicate a DMA-BUF file descriptor"; |
+ return gfx::GpuMemoryBufferHandle(); |
+ } |
+ handle.handle = dma_buf; |
+ } |
return handle; |
} |