[PATCH 3/6] glamor: egl: add function to back a pixmap with a dma-buf.

Dave Airlie airlied at gmail.com
Sun Jun 14 16:24:58 PDT 2015


Rather than create the pixmap, this uses the file descriptor
to change an existing pixmaps backing store.

This is required for reverse prime slaves, where we create
the slave pixmap, then set the backing store.

Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 glamor/glamor.h     | 19 +++++++++++++++++++
 glamor/glamor_egl.c | 52 +++++++++++++++++++++++++++++++++++-----------------
 2 files changed, 54 insertions(+), 17 deletions(-)

diff --git a/glamor/glamor.h b/glamor/glamor.h
index 657354d..f402d7d 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -218,6 +218,25 @@ extern _X_EXPORT PixmapPtr glamor_pixmap_from_fd(ScreenPtr screen,
                                                  CARD8 depth,
                                                  CARD8 bpp);
 
+/* @glamor_back_pixmap_from_fd: Backs an existing pixmap with a dma-buf fd.
+ *
+ * @pixmap: Pixmap to change backing for
+ * @fd: The dma-buf fd to import.
+ * @width: The width of the buffer.
+ * @height: The height of the buffer.
+ * @stride: The stride of the buffer.
+ * @depth: The depth of the buffer.
+ * @bpp: The number of bpp of the buffer.
+ *
+ * Returns TRUE if successful, FALSE on failure.
+ * */
+extern _X_EXPORT Bool glamor_back_pixmap_from_fd(PixmapPtr pixmap,
+                                                 int fd,
+                                                 CARD16 width,
+                                                 CARD16 height,
+                                                 CARD16 stride,
+                                                 CARD8 depth,
+                                                 CARD8 bpp);
 #ifdef GLAMOR_FOR_XORG
 
 #define GLAMOR_EGL_MODULE_NAME  "glamoregl"
diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index 4c0db6a..994dbd2 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -461,19 +461,18 @@ glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
 #endif
 }
 
-_X_EXPORT PixmapPtr
-glamor_pixmap_from_fd(ScreenPtr screen,
-                      int fd,
-                      CARD16 width,
-                      CARD16 height,
-                      CARD16 stride, CARD8 depth, CARD8 bpp)
+_X_EXPORT Bool
+glamor_back_pixmap_from_fd(PixmapPtr pixmap,
+                           int fd,
+                           CARD16 width,
+                           CARD16 height,
+                           CARD16 stride, CARD8 depth, CARD8 bpp)
 {
 #ifdef GLAMOR_HAS_GBM
-    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+    ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
     struct glamor_egl_screen_private *glamor_egl;
     struct gbm_bo *bo;
     EGLImageKHR image;
-    PixmapPtr pixmap;
     Bool ret = FALSE;
 
     EGLint attribs[] = {
@@ -489,10 +488,10 @@ glamor_pixmap_from_fd(ScreenPtr screen,
     glamor_egl = glamor_egl_get_screen_private(scrn);
 
     if (!glamor_egl->dri3_capable)
-        return NULL;
+        return FALSE;
 
     if (bpp != 32 || !(depth == 24 || depth == 32) || width == 0 || height == 0)
-        return NULL;
+        return FALSE;
 
     attribs[1] = width;
     attribs[3] = height;
@@ -504,29 +503,48 @@ glamor_pixmap_from_fd(ScreenPtr screen,
                               NULL, attribs);
 
     if (image == EGL_NO_IMAGE_KHR)
-        return NULL;
+        return FALSE;
 
     /* EGL_EXT_image_dma_buf_import can impose restrictions on the
      * usage of the image. Use gbm_bo to bypass the limitations. */
-
     bo = gbm_bo_import(glamor_egl->gbm, GBM_BO_IMPORT_EGL_IMAGE, image, 0);
     eglDestroyImageKHR(glamor_egl->display, image);
 
     if (!bo)
-        return NULL;
+        return FALSE;
 
-    pixmap = screen->CreatePixmap(screen, 0, 0, depth, 0);
-    screen->ModifyPixmapHeader(pixmap, width, height, 0, 0, stride, NULL);
+    pixmap->drawable.pScreen->ModifyPixmapHeader(pixmap, width, height, 0, 0, stride, NULL);
 
     ret = glamor_egl_create_textured_pixmap_from_gbm_bo(pixmap, bo);
     gbm_bo_destroy(bo);
 
     if (ret)
-        return pixmap;
-    else {
+        return TRUE;
+    return FALSE;
+#else
+    return FALSE;
+#endif
+}
+
+_X_EXPORT PixmapPtr
+glamor_pixmap_from_fd(ScreenPtr screen,
+                      int fd,
+                      CARD16 width,
+                      CARD16 height,
+                      CARD16 stride, CARD8 depth, CARD8 bpp)
+{
+#ifdef GLAMOR_HAS_GBM
+    PixmapPtr pixmap;
+    Bool ret;
+
+    pixmap = screen->CreatePixmap(screen, 0, 0, depth, 0);
+    ret = glamor_back_pixmap_from_fd(pixmap, fd, width, height,
+                                     stride, depth, bpp);
+    if (ret == FALSE) {
         screen->DestroyPixmap(pixmap);
         return NULL;
     }
+    return pixmap;
 #else
     return NULL;
 #endif
-- 
2.4.2



More information about the xorg-devel mailing list