[Glamor] [PATCH] Allow to create textured pixmaps from gbm_bo without using gem names

Axel Davy axel.davy at ens.fr
Mon Nov 18 13:52:22 PST 2013


This implements glamor_egl_create_textured_pixmap_from_gbm_bo,
which is similar to glamor_egl_create_textured_pixmap, except
it takes a gbm_bo as argument.

Signed-off-by: Axel Davy <axel.davy at ens.fr>
---
The goal of this patch is to enable create textured pixmaps
from bo without using gem names, which are forbidden on
render-nodes. Since wlglamor xwayland DDX can potentially
run under a render-node, it is required (and wlglamor uses
gbm_bo). 
A gbm_bo can be created from an EGLImage, so this function
can be used to implement dri3 support (and avoiding gem
names): the DDX would use the Mesa extension to create
an EGLImage from an fd, then import it as a gbm_bo, and 
pass it to glamor. Converting a gbm_bo to EGLImage and
vice-versa is quite straightforward for Mesa.

If it is planned that glamor would give functions to
implement dri3 (get fd from pixmap, get pixmap from fd),
then this patch is useless.

The patch doesn't use 'struct gbm_bo *' but 'void *' to
avoid compilation issues if glamor doesn't have gbm
support.

I've tested this patch on wlglamor with an intel card
and a radeon card. The intel card produces correctly
the image, but has an issue when rendering. I reported the 
bug. I have no issues with my radeon card.

 src/glamor.h     | 13 +++++++++++++
 src/glamor_egl.c | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)

diff --git a/src/glamor.h b/src/glamor.h
index c143c4d..927892f 100644
--- a/src/glamor.h
+++ b/src/glamor.h
@@ -230,6 +230,19 @@ extern _X_EXPORT Bool glamor_egl_create_textured_pixmap(PixmapPtr pixmap,
 							int handle,
 							int stride);
 
+/*
+ * @glamor_egl_create_textured_pixmap_from_bo: Try to create a textured pixmap
+ * 					       from a gbm_bo.
+ *
+ * @pixmap: The pixmap need to be processed.
+ * @bo: a pointer on a gbm_bo structure attached to this pixmap at DDX layer.
+ *
+ * This function is similar to glamor_egl_create_textured_pixmap.
+ */
+extern _X_EXPORT Bool
+	glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap,
+						      void *bo);
+
 extern _X_EXPORT void glamor_egl_destroy_textured_pixmap(PixmapPtr pixmap);
 #endif
 
diff --git a/src/glamor_egl.c b/src/glamor_egl.c
index cd0bdc0..50b764b 100644
--- a/src/glamor_egl.c
+++ b/src/glamor_egl.c
@@ -315,6 +315,40 @@ done:
 	return ret;
 }
 
+Bool
+glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap, void *bo)
+{
+	ScreenPtr screen = pixmap->drawable.pScreen;
+	ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+	struct glamor_egl_screen_private *glamor_egl;
+	EGLImageKHR image;
+	GLuint texture;
+	Bool ret = FALSE;
+
+	glamor_egl = glamor_egl_get_screen_private(scrn);
+
+	glamor_egl_make_current(screen);
+
+	image = glamor_egl->egl_create_image_khr(glamor_egl->display,
+						 glamor_egl->context,
+						 EGL_NATIVE_PIXMAP_KHR,
+						 bo, NULL);
+	if (image == EGL_NO_IMAGE_KHR) {
+		glamor_set_pixmap_type(pixmap, GLAMOR_DRM_ONLY);
+		goto done;
+	}
+	glamor_create_texture_from_image(glamor_egl, image, &texture);
+	glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM);
+	glamor_set_pixmap_texture(pixmap, texture);
+	dixSetPrivate(&pixmap->devPrivates, glamor_egl_pixmap_private_key,
+		      image);
+	ret = TRUE;
+
+done:
+	glamor_egl_restore_context(screen);
+	return ret;
+}
+
 static void
 _glamor_egl_destroy_pixmap_image(PixmapPtr pixmap)
 {
-- 
1.8.1.2



More information about the Glamor mailing list