[PATCH 3/3] glamor: Avoid generating GEM flink names for BOs shared via DRI3 v2

Michel Dänzer michel at daenzer.net
Thu Mar 19 00:21:44 PDT 2015


From: Michel Dänzer <michel.daenzer at amd.com>

We can't create our own struct radeon_bo representation in this case
because destroying that would make the GEM handle inaccessible to glamor
as well. So just get the handle directly via dma-buf.

v2: Close dma-buf file descriptor, pointed out by Axel Davy.
Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
---
 src/radeon.h         |  4 ++++
 src/radeon_dri3.c    | 10 ++++++++++
 src/radeon_glamor.h  |  1 +
 src/radeon_present.c | 34 ++++++++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+)

diff --git a/src/radeon.h b/src/radeon.h
index 6084cfe..6a60bd3 100644
--- a/src/radeon.h
+++ b/src/radeon.h
@@ -252,6 +252,10 @@ struct radeon_pixmap {
 
 	uint32_t tiling_flags;
 	int stride;
+
+	/* GEM handle for glamor-only pixmaps shared via DRI3 */
+	Bool handle_valid;
+	uint32_t handle;
 };
 
 #if HAS_DEVPRIVATEKEYREC
diff --git a/src/radeon_dri3.c b/src/radeon_dri3.c
index 993c7a7..3a7322e 100644
--- a/src/radeon_dri3.c
+++ b/src/radeon_dri3.c
@@ -96,6 +96,16 @@ static PixmapPtr radeon_dri3_pixmap_from_fd(ScreenPtr screen,
 {
 	PixmapPtr pixmap;
 
+#ifdef USE_GLAMOR
+	/* Avoid generating a GEM flink name if possible */
+	if (RADEONPTR(xf86ScreenToScrn(screen))->use_glamor) {
+		pixmap = glamor_pixmap_from_fd(screen, fd, width, height,
+					       stride, depth, bpp);
+		if (pixmap)
+			return pixmap;
+	}
+#endif
+
 	if (depth < 8)
 		return NULL;
 
diff --git a/src/radeon_glamor.h b/src/radeon_glamor.h
index f450f0e..7cef1a9 100644
--- a/src/radeon_glamor.h
+++ b/src/radeon_glamor.h
@@ -37,6 +37,7 @@
 
 #ifndef GLAMOR_NO_DRI3
 #define glamor_fd_from_pixmap glamor_dri3_fd_from_pixmap
+#define glamor_pixmap_from_fd glamor_egl_dri3_pixmap_from_fd
 #endif
 
 Bool radeon_glamor_pre_init(ScrnInfoPtr scrn);
diff --git a/src/radeon_present.c b/src/radeon_present.c
index 85f1bfc..6782513 100644
--- a/src/radeon_present.c
+++ b/src/radeon_present.c
@@ -42,6 +42,7 @@
 #include <time.h>
 #include <errno.h>
 
+#include "radeon_glamor.h"
 #include "radeon_video.h"
 
 #include "present.h"
@@ -220,12 +221,45 @@ static Bool
 radeon_present_get_pixmap_handle(PixmapPtr pixmap, uint32_t *handle)
 {
     struct radeon_bo *bo = radeon_get_pixmap_bo(pixmap);
+#ifdef USE_GLAMOR
+    ScreenPtr screen = pixmap->drawable.pScreen;
+    RADEONInfoPtr info = RADEONPTR(xf86ScreenToScrn(screen));
+#endif
 
     if (bo) {
 	*handle = bo->handle;
 	return TRUE;
     }
 
+#ifdef USE_GLAMOR
+    if (info->use_glamor) {
+	struct radeon_pixmap *priv = radeon_get_pixmap_private(pixmap);
+	CARD16 stride;
+	CARD32 size;
+	int fd;
+
+	if (!priv) {
+	    priv = calloc(1, sizeof(*priv));
+	    radeon_set_pixmap_private(pixmap, priv);
+	}
+
+	if (priv->handle_valid) {
+	    *handle = priv->handle;
+	    return TRUE;
+	}
+
+	fd = glamor_fd_from_pixmap(screen, pixmap, &stride, &size);
+	if (fd < 0)
+	    return FALSE;
+
+	if (drmPrimeFDToHandle(info->dri2.drm_fd, fd, &priv->handle) == 0) {
+	    priv->handle_valid = TRUE;
+	    *handle = priv->handle;
+	    return TRUE;
+	}
+    }
+#endif
+
     return FALSE;
 }
 
-- 
2.1.4



More information about the xorg-driver-ati mailing list