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

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 new crrev.com/1128113011 Created 5 years, 6 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 bb3aff7bba610640781eb940a507a1aac75a5f37..0249d26ce12d0448848f51982a265bdee1992119 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::ScheduleOverlayPlane(
gfx::AcceleratedWidget widget,
int plane_z_order,

Powered by Google App Engine
This is Rietveld 408576698