<div dir="ltr"><div>LGTM, pushed, thanks for your contribution.<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Dec 5, 2013 at 3:49 PM, Axel Davy <span dir="ltr"><<a href="mailto:axel.davy@ens.fr" target="_blank">axel.davy@ens.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This implements some DRI3 helpers to help the DDXs using<br>
glamor to support DRI3.<br>
<br>
Signed-off-by: Axel Davy <<a href="mailto:axel.davy@ens.fr">axel.davy@ens.fr</a>><br>
---<br>
v3: fix whitespace errors of v2<br>
<br>
 <a href="http://configure.ac" target="_blank">configure.ac</a>      |  13 ++++<br>
 src/glamor.c      |  76 +++++++++++++++++-<br>
 src/glamor.h      |  68 ++++++++++++++++-<br>
 src/glamor_egl.c  | 225 ++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>
 src/glamor_fbo.c  |  36 ++++++---<br>
 src/glamor_priv.h |   1 +<br>
 6 files changed, 405 insertions(+), 14 deletions(-)<br>
<br>
diff --git a/<a href="http://configure.ac" target="_blank">configure.ac</a> b/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
index b7b25d0..21bc794 100644<br>
--- a/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
+++ b/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
@@ -134,6 +134,19 @@ if test "x$EGL = xyes"; then<br>
    fi<br>
 fi<br>
<br>
+AC_MSG_CHECKING([Enable Glamor Dri3 helpers])<br>
+AC_ARG_ENABLE(glamor-dri3, AS_HELP_STRING([--enable-glamor-dri3], [Build glamor Dri3 helpers (default: yes if gbm is detected)]), [GLAMOR_DRI3_HELPERS="$enableval"], [GLAMOR_DRI3_HELPERS=yes])<br>
+<br>
+if test "x$GLAMOR_DRI3_HELPERS" = xyes -a "x$GLAMOR_HAS_GBM" = xno; then<br>
+   GLAMOR_DRI3_HELPERS=no<br>
+fi<br>
+<br>
+AC_MSG_RESULT([$GLAMOR_DRI3_HELPERS])<br>
+<br>
+if test "x$GLAMOR_DRI3_HELPERS" = xyes; then<br>
+    AC_DEFINE(GLAMOR_HAS_DRI3_SUPPORT, 1, [Enable Dri3 helpers])<br>
+fi<br>
+<br>
 dnl<br>
 dnl TLS detection<br>
 dnl<br>
diff --git a/src/glamor.c b/src/glamor.c<br>
index e8e68be..93d3c5e 100644<br>
--- a/src/glamor.c<br>
+++ b/src/glamor.c<br>
@@ -209,7 +209,12 @@ glamor_destroy_textured_pixmap(PixmapPtr pixmap)<br>
 Bool<br>
 glamor_destroy_pixmap(PixmapPtr pixmap)<br>
 {<br>
-       glamor_destroy_textured_pixmap(pixmap);<br>
+       glamor_screen_private<br>
+         *glamor_priv = glamor_get_screen_private(pixmap->drawable.pScreen);<br>
+       if (glamor_priv->dri3_enabled)<br>
+               glamor_egl_destroy_textured_pixmap(pixmap);<br>
+       else<br>
+               glamor_destroy_textured_pixmap(pixmap);<br>
        return fbDestroyPixmap(pixmap);<br>
 }<br>
<br>
@@ -552,3 +557,72 @@ glamor_fini(ScreenPtr screen)<br>
 {<br>
        /* Do nothing currently. */<br>
 }<br>
+<br>
+void glamor_enable_dri3(ScreenPtr screen)<br>
+{<br>
+       glamor_screen_private *glamor_priv =<br>
+           glamor_get_screen_private(screen);<br>
+       glamor_priv->dri3_enabled = TRUE;<br>
+}<br>
+<br>
+Bool glamor_is_dri3_support_enabled(ScreenPtr screen)<br>
+{<br>
+       glamor_screen_private *glamor_priv =<br>
+           glamor_get_screen_private(screen);<br>
+       return glamor_priv->dri3_enabled;<br>
+}<br>
+<br>
+int<br>
+glamor_dri3_fd_from_pixmap (ScreenPtr screen,<br>
+                            PixmapPtr pixmap,<br>
+                            CARD16 *stride,<br>
+                            CARD32 *size)<br>
+{<br>
+       glamor_pixmap_private *pixmap_priv;<br>
+       glamor_screen_private *glamor_priv =<br>
+           glamor_get_screen_private(pixmap->drawable.pScreen);<br>
+<br>
+       pixmap_priv = glamor_get_pixmap_private(pixmap);<br>
+       if (pixmap_priv == NULL || !glamor_priv->dri3_enabled)<br>
+               return -1;<br>
+       switch (pixmap_priv->type)<br>
+       {<br>
+               case GLAMOR_TEXTURE_DRM:<br>
+               case GLAMOR_TEXTURE_ONLY:<br>
+                       glamor_pixmap_ensure_fbo(pixmap, GL_RGBA, 0);<br>
+                       return glamor_egl_dri3_fd_name_from_tex(screen,<br>
+                                                               pixmap,<br>
+                                                               pixmap_priv->base.fbo->tex,<br>
+                                                               FALSE,<br>
+                                                               stride,<br>
+                                                               size);<br>
+               default: break;<br>
+       }<br>
+       return -1;<br>
+}<br>
+<br>
+int<br>
+glamor_dri3_name_from_pixmap (PixmapPtr pixmap)<br>
+{<br>
+       glamor_pixmap_private *pixmap_priv;<br>
+       glamor_screen_private *glamor_priv =<br>
+           glamor_get_screen_private(pixmap->drawable.pScreen);<br>
+<br>
+       pixmap_priv = glamor_get_pixmap_private(pixmap);<br>
+       if (pixmap_priv == NULL || !glamor_priv->dri3_enabled)<br>
+               return -1;<br>
+       switch (pixmap_priv->type)<br>
+       {<br>
+               case GLAMOR_TEXTURE_DRM:<br>
+               case GLAMOR_TEXTURE_ONLY:<br>
+                       glamor_pixmap_ensure_fbo(pixmap, GL_RGBA, 0);<br>
+                       return glamor_egl_dri3_fd_name_from_tex(pixmap->drawable.pScreen,<br>
+                                                               pixmap,<br>
+                                                               pixmap_priv->base.fbo->tex,<br>
+                                                               TRUE,<br>
+                                                               NULL,<br>
+                                                               NULL);<br>
+               default: break;<br>
+       }<br>
+       return -1;<br>
+}<br>
diff --git a/src/glamor.h b/src/glamor.h<br>
index 927892f..1bb48ed 100644<br>
--- a/src/glamor.h<br>
+++ b/src/glamor.h<br>
@@ -164,6 +164,71 @@ extern _X_EXPORT void glamor_egl_exchange_buffers(PixmapPtr front, PixmapPtr bac<br>
<br>
 extern _X_EXPORT void glamor_pixmap_exchange_fbos(PixmapPtr front, PixmapPtr back);<br>
<br>
+/* The DDX is not supposed to call these three functions */<br>
+extern _X_EXPORT void glamor_enable_dri3(ScreenPtr screen);<br>
+extern _X_EXPORT unsigned int glamor_egl_create_argb8888_based_texture(ScreenPtr screen, int w, int h);<br>
+extern _X_EXPORT int glamor_egl_dri3_fd_name_from_tex(ScreenPtr, PixmapPtr, unsigned int, Bool, CARD16*, CARD32*);<br>
+<br>
+/* @glamor_is_dri3_support_enabled: Returns if DRI3 support is enabled.<br>
+ *<br>
+ * @screen: Current screen pointer.<br>
+ *<br>
+ * To have DRI3 support enabled, glamor and glamor_egl need to be initialized,<br>
+ * and glamor_egl_init_textured_pixmap need to be called. glamor also<br>
+ * has to be compiled with gbm support.<br>
+ * The EGL layer need to have the following extensions working:<br>
+ * .EGL_KHR_gl_texture_2D_image<br>
+ * .EGL_EXT_image_dma_buf_import<br>
+ * If DRI3 support is not enabled, the following helpers will return an error.<br>
+ * */<br>
+extern _X_EXPORT Bool glamor_is_dri3_support_enabled(ScreenPtr screen);<br>
+<br>
+/* @glamor_dri3_fd_from_pixmap: DRI3 helper to get a dma-buf fd from a pixmap.<br>
+ *<br>
+ * @screen: Current screen pointer.<br>
+ * @pixmap: The pixmap from which we want the fd.<br>
+ * @stride, @size: Pointers to fill the stride and size of the<br>
+ *                buffer associated to the fd.<br>
+ *<br>
+ * the pixmap and the buffer associated by the fd will share the same<br>
+ * content.<br>
+ * Returns the fd on success, -1 on error.<br>
+ * */<br>
+extern _X_EXPORT int glamor_dri3_fd_from_pixmap (ScreenPtr screen,<br>
+                                                PixmapPtr pixmap,<br>
+                                                CARD16 *stride,<br>
+                                                CARD32 *size);<br>
+<br>
+/* @glamor_dri3_name_from_pixmap: helper to get an gem name from a pixmap.<br>
+ *<br>
+ * @pixmap: The pixmap from which we want the gem name.<br>
+ *<br>
+ * the pixmap and the buffer associated by the gem name will share the same<br>
+ * content. This function can be used by the DDX to support DRI2, but needs<br>
+ * glamor DRI3 support to be activated.<br>
+ * Returns the name on success, -1 on error.<br>
+ * */<br>
+extern _X_EXPORT int glamor_dri3_name_from_pixmap (PixmapPtr pixmap);<br>
+<br>
+/* @glamor_egl_dri3_pixmap_from_fd: DRI3 helper to get a pixmap from a dma-buf fd.<br>
+ *<br>
+ * @screen: Current screen pointer.<br>
+ * @fd: The dma-buf fd to import.<br>
+ * @width: The width of the buffer.<br>
+ * @height: The height of the buffer.<br>
+ * @stride: The stride of the buffer.<br>
+ * @depth: The depth of the buffer.<br>
+ * @bpp: The number of bpp of the buffer.<br>
+ *<br>
+ * Returns a valid pixmap if the import succeeded, else NULL.<br>
+ * */<br>
+extern _X_EXPORT PixmapPtr glamor_egl_dri3_pixmap_from_fd (ScreenPtr screen,<br>
+                                                          int fd,<br>
+                                                          CARD16 width,<br>
+                                                          CARD16 height,<br>
+                                                          CARD16 stride,<br>
+                                                          CARD8 depth,<br>
+                                                          CARD8 bpp);<br>
<br>
 #ifdef GLAMOR_FOR_XORG<br>
<br>
@@ -243,9 +308,10 @@ extern _X_EXPORT Bool<br>
        glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap,<br>
                                                      void *bo);<br>
<br>
-extern _X_EXPORT void glamor_egl_destroy_textured_pixmap(PixmapPtr pixmap);<br>
 #endif<br>
<br>
+extern _X_EXPORT void glamor_egl_destroy_textured_pixmap(PixmapPtr pixmap);<br>
+<br>
 extern _X_EXPORT int glamor_create_gc(GCPtr gc);<br>
<br>
 extern _X_EXPORT void glamor_validate_gc(GCPtr gc, unsigned long changes, DrawablePtr drawable);<br>
diff --git a/src/glamor_egl.c b/src/glamor_egl.c<br>
index 13b7f44..bf0db3a 100644<br>
--- a/src/glamor_egl.c<br>
+++ b/src/glamor_egl.c<br>
@@ -45,6 +45,7 @@<br>
<br>
 #ifdef GLAMOR_HAS_GBM<br>
 #include <gbm.h><br>
+#include <drm_fourcc.h><br>
 #endif<br>
<br>
 #if GLAMOR_GLES2<br>
@@ -95,6 +96,7 @@ struct glamor_egl_screen_private {<br>
        void *glamor_context;<br>
        void *current_context;<br>
        int gl_context_depth;<br>
+       int dri3_capable;<br>
<br>
        PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr;<br>
        PFNEGLDESTROYIMAGEKHRPROC egl_destroy_image_khr;<br>
@@ -218,6 +220,47 @@ glamor_create_texture_from_image(struct glamor_egl_screen_private<br>
        return TRUE;<br>
 }<br>
<br>
+unsigned int<br>
+glamor_egl_create_argb8888_based_texture(ScreenPtr screen,<br>
+                                        int w,<br>
+                                        int h)<br>
+{<br>
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);<br>
+       struct glamor_egl_screen_private *glamor_egl;<br>
+       EGLImageKHR image;<br>
+       GLuint texture;<br>
+#ifdef GLAMOR_HAS_DRI3_SUPPORT<br>
+       struct gbm_bo *bo;<br>
+       EGLNativePixmapType native_pixmap;<br>
+       glamor_egl = glamor_egl_get_screen_private(scrn);<br>
+       bo = gbm_bo_create (glamor_egl->gbm, w, h, GBM_FORMAT_ARGB8888,<br>
+                                     GBM_BO_USE_RENDERING |<br>
+                                     GBM_BO_USE_SCANOUT);<br>
+       if (!bo)<br>
+               return 0;<br>
+<br>
+       /* If the following assignment raises an error or a warning<br>
+        * then that means EGLNativePixmapType is not struct gbm_bo *<br>
+        * on your platform: This code won't work and you should not<br>
+        * compile with dri3 support enabled */<br>
+       native_pixmap = bo;<br>
+<br>
+       image = glamor_egl->egl_create_image_khr(glamor_egl->display,<br>
+                                                EGL_NO_CONTEXT,<br>
+                                                EGL_NATIVE_PIXMAP_KHR,<br>
+                                                native_pixmap, NULL);<br>
+       gbm_bo_destroy(bo);<br>
+       if (image == EGL_NO_IMAGE_KHR)<br>
+               return 0;<br>
+       glamor_create_texture_from_image(glamor_egl, image, &texture);<br>
+       glamor_egl->egl_destroy_image_khr(glamor_egl->display, image);<br>
+<br>
+       return texture;<br>
+#else<br>
+       return 0; /* this path should never happen */<br>
+#endif<br>
+}<br>
+<br>
 Bool<br>
 glamor_egl_create_textured_screen(ScreenPtr screen, int handle, int stride)<br>
 {<br>
@@ -349,6 +392,178 @@ done:<br>
        return ret;<br>
 }<br>
<br>
+#ifdef GLAMOR_HAS_DRI3_SUPPORT<br>
+int glamor_get_fd_from_bo (int gbm_fd, struct gbm_bo *bo, int *fd);<br>
+void glamor_get_name_from_bo (int gbm_fd, struct gbm_bo *bo, int *name);<br>
+int<br>
+glamor_get_fd_from_bo (int gbm_fd, struct gbm_bo *bo, int *fd)<br>
+{<br>
+       union gbm_bo_handle handle;<br>
+       struct drm_prime_handle args;<br>
+<br>
+       handle = gbm_bo_get_handle(bo);<br>
+       args.handle = handle.u32;<br>
+       args.flags = DRM_CLOEXEC;<br>
+       if (ioctl (gbm_fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args))<br>
+               return FALSE;<br>
+       *fd = args.fd;<br>
+       return TRUE;<br>
+}<br>
+<br>
+void<br>
+glamor_get_name_from_bo (int gbm_fd, struct gbm_bo *bo, int *name)<br>
+{<br>
+       union gbm_bo_handle handle;<br>
+<br>
+       handle = gbm_bo_get_handle(bo);<br>
+       if (!glamor_get_flink_name(gbm_fd, handle.u32, name))<br>
+               *name = -1;<br>
+}<br>
+#endif<br>
+<br>
+int glamor_egl_dri3_fd_name_from_tex (ScreenPtr screen,<br>
+                                     PixmapPtr pixmap,<br>
+                                     unsigned int tex,<br>
+                                     Bool want_name,<br>
+                                     CARD16 *stride,<br>
+                                     CARD32 *size)<br>
+{<br>
+#ifdef GLAMOR_HAS_DRI3_SUPPORT<br>
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);<br>
+       struct glamor_egl_screen_private *glamor_egl;<br>
+       EGLImageKHR image;<br>
+       struct gbm_bo* bo;<br>
+       int fd = -1;<br>
+<br>
+       EGLint attribs[] = {<br>
+               EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,<br>
+               EGL_GL_TEXTURE_LEVEL_KHR, 0,<br>
+               EGL_NONE<br>
+       };<br>
+<br>
+       glamor_egl = glamor_egl_get_screen_private(scrn);<br>
+<br>
+       glamor_egl_make_current(screen);<br>
+<br>
+       image = dixLookupPrivate(&pixmap->devPrivates,<br>
+                                glamor_egl_pixmap_private_key);<br>
+<br>
+       if (image == EGL_NO_IMAGE_KHR || image == NULL)<br>
+       {<br>
+               image = glamor_egl->egl_create_image_khr(glamor_egl->display,<br>
+                                                        glamor_egl->context,<br>
+                                                        EGL_GL_TEXTURE_2D_KHR,<br>
+                                                        tex, attribs);<br>
+               if (image == EGL_NO_IMAGE_KHR)<br>
+                       goto failure;<br>
+<br>
+               dixSetPrivate(&pixmap->devPrivates,<br>
+                             glamor_egl_pixmap_private_key,<br>
+                             image);<br>
+               glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM);<br>
+       }<br>
+<br>
+       bo = gbm_bo_import(glamor_egl->gbm, GBM_BO_IMPORT_EGL_IMAGE, image, 0);<br>
+       if (!bo)<br>
+               goto failure;<br>
+<br>
+       pixmap->devKind = gbm_bo_get_stride(bo);<br>
+<br>
+       if (want_name)<br>
+       {<br>
+               if (glamor_egl->has_gem)<br>
+                       glamor_get_name_from_bo(glamor_egl->fd, bo, &fd);<br>
+       }<br>
+       else<br>
+       {<br>
+               if (glamor_get_fd_from_bo(glamor_egl->fd, bo, &fd))<br>
+               {<br>
+                       *stride = pixmap->devKind;<br>
+                       *size = pixmap->devKind * gbm_bo_get_height(bo);<br>
+               }<br>
+       }<br>
+<br>
+       gbm_bo_destroy(bo);<br>
+failure:<br>
+       glamor_egl_restore_context(screen);<br>
+       return fd;<br>
+#else<br>
+       return -1;<br>
+#endif<br>
+}<br>
+<br>
+PixmapPtr glamor_egl_dri3_pixmap_from_fd (ScreenPtr screen,<br>
+                                         int fd,<br>
+                                         CARD16 width,<br>
+                                         CARD16 height,<br>
+                                         CARD16 stride,<br>
+                                         CARD8 depth,<br>
+                                         CARD8 bpp)<br>
+{<br>
+#ifdef GLAMOR_HAS_DRI3_SUPPORT<br>
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);<br>
+       struct glamor_egl_screen_private *glamor_egl;<br>
+       struct gbm_bo* bo;<br>
+       EGLImageKHR image;<br>
+       PixmapPtr pixmap;<br>
+       Bool ret = FALSE;<br>
+       EGLint attribs[] = {<br>
+               EGL_WIDTH, 0,<br>
+               EGL_HEIGHT, 0,<br>
+               EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,<br>
+               EGL_DMA_BUF_PLANE0_FD_EXT, 0,<br>
+               EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,<br>
+               EGL_DMA_BUF_PLANE0_PITCH_EXT, 0,<br>
+               EGL_NONE<br>
+       };<br>
+<br>
+       glamor_egl = glamor_egl_get_screen_private(scrn);<br>
+<br>
+       if (!glamor_egl->dri3_capable)<br>
+               return NULL;<br>
+<br>
+       if (bpp != 32 || !(depth == 24 || depth == 32) || width == 0 || height == 0)<br>
+               return NULL;<br>
+<br>
+       attribs[1] = width;<br>
+       attribs[3] = height;<br>
+       attribs[7] = fd;<br>
+       attribs[11] = stride;<br>
+       image = glamor_egl->egl_create_image_khr(glamor_egl->display,<br>
+                                                EGL_NO_CONTEXT,<br>
+                                                EGL_LINUX_DMA_BUF_EXT,<br>
+                                                NULL, attribs);<br>
+<br>
+       if (image == EGL_NO_IMAGE_KHR)<br>
+               return NULL;<br>
+<br>
+       /* EGL_EXT_image_dma_buf_import can impose restrictions on the<br>
+        * usage of the image. Use gbm_bo to bypass the limitations. */<br>
+<br>
+       bo = gbm_bo_import(glamor_egl->gbm, GBM_BO_IMPORT_EGL_IMAGE, image, 0);<br>
+       glamor_egl->egl_destroy_image_khr(glamor_egl->display, image);<br>
+<br>
+       if (!bo)<br>
+               return NULL;<br>
+<br>
+       pixmap = screen->CreatePixmap(screen, 0, 0, depth, 0);<br>
+       screen->ModifyPixmapHeader (pixmap, width, height, 0, 0, stride, NULL);<br>
+<br>
+       ret = glamor_egl_create_textured_pixmap_from_gbm_bo(pixmap, bo);<br>
+       gbm_bo_destroy(bo);<br>
+<br>
+       if (ret)<br>
+               return pixmap;<br>
+       else<br>
+       {<br>
+               screen->DestroyPixmap(pixmap);<br>
+               return NULL;<br>
+       }<br>
+#else<br>
+       return NULL;<br>
+#endif<br>
+}<br>
+<br>
 static void<br>
 _glamor_egl_destroy_pixmap_image(PixmapPtr pixmap)<br>
 {<br>
@@ -558,6 +773,11 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd)<br>
        GLAMOR_CHECK_EGL_EXTENSIONS(KHR_surfaceless_context, KHR_surfaceless_opengl);<br>
 #endif<br>
<br>
+#ifdef GLAMOR_HAS_DRI3_SUPPORT<br>
+       if (glamor_egl_has_extension(glamor_egl, "EGL_KHR_gl_texture_2D_image") &&<br>
+           glamor_egl_has_extension(glamor_egl, "EGL_EXT_image_dma_buf_import") )<br>
+           glamor_egl->dri3_capable = TRUE;<br>
+#endif<br>
        glamor_egl->egl_create_image_khr = (PFNEGLCREATEIMAGEKHRPROC)<br>
            eglGetProcAddress("eglCreateImageKHR");<br>
<br>
@@ -609,6 +829,9 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd)<br>
 Bool<br>
 glamor_egl_init_textured_pixmap(ScreenPtr screen)<br>
 {<br>
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);<br>
+       struct glamor_egl_screen_private *glamor_egl =<br>
+           glamor_egl_get_screen_private(scrn);<br>
        if (!dixRegisterPrivateKey<br>
            (glamor_egl_pixmap_private_key, PRIVATE_PIXMAP, 0)) {<br>
                LogMessage(X_WARNING,<br>
@@ -616,6 +839,8 @@ glamor_egl_init_textured_pixmap(ScreenPtr screen)<br>
                           screen->myNum);<br>
                return FALSE;<br>
        }<br>
+       if (glamor_egl->dri3_capable)<br>
+               glamor_enable_dri3(screen);<br>
        return TRUE;<br>
 }<br>
<br>
diff --git a/src/glamor_fbo.c b/src/glamor_fbo.c<br>
index 4838a27..d1b087e 100644<br>
--- a/src/glamor_fbo.c<br>
+++ b/src/glamor_fbo.c<br>
@@ -328,18 +328,30 @@ _glamor_create_tex(glamor_screen_private *glamor_priv,<br>
                   int w, int h, GLenum format)<br>
 {<br>
        glamor_gl_dispatch *dispatch;<br>
-       unsigned int tex;<br>
-<br>
-       dispatch = glamor_get_dispatch(glamor_priv);<br>
-       dispatch->glGenTextures(1, &tex);<br>
-       dispatch->glBindTexture(GL_TEXTURE_2D, tex);<br>
-       dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,<br>
-                                 GL_NEAREST);<br>
-       dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,<br>
-                                 GL_NEAREST);<br>
-       dispatch->glTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0, format,<br>
-                              GL_UNSIGNED_BYTE, NULL);<br>
-       glamor_put_dispatch(glamor_priv);<br>
+       unsigned int tex = 0;<br>
+<br>
+       /* With dri3, we want to allocate ARGB8888 pixmaps only.<br>
+        * Depending on the implementation, GL_RGBA might not<br>
+        * give us ARGB8888. We ask glamor_egl to use get<br>
+        * an ARGB8888 based texture for us. */<br>
+       if (glamor_priv->dri3_enabled && format == GL_RGBA)<br>
+       {<br>
+               tex = glamor_egl_create_argb8888_based_texture(glamor_priv->screen,<br>
+                                                               w, h);<br>
+       }<br>
+       if (!tex)<br>
+       {<br>
+               dispatch = glamor_get_dispatch(glamor_priv);<br>
+               dispatch->glGenTextures(1, &tex);<br>
+               dispatch->glBindTexture(GL_TEXTURE_2D, tex);<br>
+               dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,<br>
+                                         GL_NEAREST);<br>
+               dispatch->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,<br>
+                                         GL_NEAREST);<br>
+               dispatch->glTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0,<br>
+                                      format, GL_UNSIGNED_BYTE, NULL);<br>
+               glamor_put_dispatch(glamor_priv);<br>
+       }<br>
        return tex;<br>
 }<br>
<br>
diff --git a/src/glamor_priv.h b/src/glamor_priv.h<br>
index b6a1075..7b8f762 100644<br>
--- a/src/glamor_priv.h<br>
+++ b/src/glamor_priv.h<br>
@@ -305,6 +305,7 @@ typedef struct glamor_screen_private {<br>
        int state;<br>
        unsigned int render_idle_cnt;<br>
        ScreenPtr screen;<br>
+       int dri3_enabled;<br>
<br>
        /* xv */<br>
        GLint xv_prog;<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.1.2<br>
<br>
_______________________________________________<br>
Glamor mailing list<br>
<a href="mailto:Glamor@lists.freedesktop.org">Glamor@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/glamor" target="_blank">http://lists.freedesktop.org/mailman/listinfo/glamor</a><br>
</font></span></blockquote></div><br></div>