[PATCH 3/5] glamor: Add a new glamor_gbm_bo_from_pixmap() function.

Kenneth Graunke kenneth at whitecape.org
Tue Apr 21 17:58:42 PDT 2015


From: Jason Ekstrand <jason.ekstrand at intel.com>

v2: Rebase on commit e0788a03144 (drop "base").
---
 glamor/glamor.h     | 15 +++++++++++++
 glamor/glamor_egl.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 70 insertions(+), 8 deletions(-)

diff --git a/glamor/glamor.h b/glamor/glamor.h
index d07182d..bc85e74 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -199,6 +199,21 @@ extern _X_EXPORT int glamor_fd_from_pixmap(ScreenPtr screen,
 extern _X_EXPORT int glamor_name_from_pixmap(PixmapPtr pixmap,
                                              CARD16 *stride, CARD32 *size);
 
+/* @glamor_gbm_bo_from_pixmap: Get a GBM bo from a pixmap.
+ *
+ * @screen: Current screen pointer.
+ * @pixmap: The pixmap from which we want the fd.
+ * @stride, @size: Pointers to fill the stride and size of the
+ * 		   buffer associated to the fd.
+ *
+ * the pixmap and the buffer represented by the gbm_bo will share the same
+ * content.
+ *
+ * Returns the gbm_bo on success, NULL on error.
+ * */
+extern _X_EXPORT void *glamor_gbm_bo_from_pixmap(ScreenPtr screen,
+                                                 PixmapPtr pixmap);
+
 /* @glamor_pixmap_from_fd: Creates a pixmap to wrap a dma-buf fd.
  *
  * @screen: Current screen pointer.
diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index 6033780..610c698 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -392,13 +392,10 @@ glamor_get_name_from_bo(int gbm_fd, struct gbm_bo *bo, int *name)
 }
 #endif
 
-int
-glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
-                                 PixmapPtr pixmap,
-                                 unsigned int tex,
-                                 Bool want_name, CARD16 *stride, CARD32 *size)
-{
 #ifdef GLAMOR_HAS_GBM
+static void *
+_get_gbm_bo_from_pixmap(ScreenPtr screen, PixmapPtr pixmap, unsigned int tex)
+{
     ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
     struct glamor_pixmap_private *pixmap_priv =
         glamor_get_pixmap_private(pixmap);
@@ -407,7 +404,6 @@ glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
     struct glamor_egl_screen_private *glamor_egl;
     EGLImageKHR image;
     struct gbm_bo *bo;
-    int fd = -1;
 
     EGLint attribs[] = {
         EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
@@ -427,7 +423,7 @@ glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
                                   (EGLClientBuffer) (uintptr_t)
                                   tex, attribs);
         if (image == EGL_NO_IMAGE_KHR)
-            goto failure;
+            return NULL;
 
         glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM);
         glamor_egl_set_pixmap_image(pixmap, image);
@@ -435,6 +431,57 @@ glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
 
     bo = gbm_bo_import(glamor_egl->gbm, GBM_BO_IMPORT_EGL_IMAGE, image, 0);
     if (!bo)
+        return NULL;
+
+    pixmap->devKind = gbm_bo_get_stride(bo);
+
+    return bo;
+}
+#endif
+
+void *
+glamor_gbm_bo_from_pixmap(ScreenPtr screen, PixmapPtr pixmap)
+{
+#ifdef GLAMOR_HAS_GBM
+    glamor_screen_private *glamor_priv =
+        glamor_get_screen_private(pixmap->drawable.pScreen);
+    glamor_pixmap_private *pixmap_priv =
+        glamor_get_pixmap_private(pixmap);
+
+    pixmap_priv = glamor_get_pixmap_private(pixmap);
+    if (pixmap_priv == NULL || !glamor_priv->dri3_enabled)
+        return NULL;
+    switch (pixmap_priv->type) {
+    case GLAMOR_TEXTURE_DRM:
+    case GLAMOR_TEXTURE_ONLY:
+        if (!glamor_pixmap_ensure_fbo(pixmap, GL_RGBA, 0))
+            return NULL;
+        return _get_gbm_bo_from_pixmap(screen, pixmap,
+                                       pixmap_priv->fbo->tex);
+    default:
+        break;
+    }
+    return NULL;
+#else
+    return NULL;
+#endif
+}
+
+int
+glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
+                                 PixmapPtr pixmap,
+                                 unsigned int tex,
+                                 Bool want_name, CARD16 *stride, CARD32 *size)
+{
+#ifdef GLAMOR_HAS_GBM
+    struct glamor_egl_screen_private *glamor_egl;
+    struct gbm_bo *bo;
+    int fd = -1;
+
+    glamor_egl = glamor_egl_get_screen_private(xf86ScreenToScrn(screen));
+
+    bo = _get_gbm_bo_from_pixmap(screen, pixmap, tex);
+    if (!bo)
         goto failure;
 
     pixmap->devKind = gbm_bo_get_stride(bo);
-- 
2.3.5



More information about the xorg-devel mailing list