xserver: Branch 'master' - 10 commits

Eric Anholt anholt at kemper.freedesktop.org
Wed Nov 18 12:26:07 PST 2015


 glamor/glamor.c                                  |   18 -
 glamor/glamor.h                                  |   20 -
 glamor/glamor_egl.c                              |  280 ++++++++---------------
 glamor/glamor_egl_stubs.c                        |   11 
 glamor/glamor_fbo.c                              |   39 +--
 hw/xfree86/drivers/modesetting/drmmode_display.c |    6 
 hw/xwayland/xwayland-glamor.c                    |   11 
 7 files changed, 131 insertions(+), 254 deletions(-)

New commits:
commit 51984dddfcc7133ed3c1f20d03514aa98c9a7831
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jun 18 11:14:41 2015 -0700

    glamor: Delay making pixmaps shareable until we need to.
    
    If a pixmap isn't getting exported as a dmabuf, then we don't need to
    make an EGLImage/GBM bo for it.  This should reduce normal pixmap
    allocation overhead, and also lets the driver choose non-scanout
    formats which may be much higher performance.
    
    On Raspberry Pi, where scanout isn't usable as a texture source, this
    improves x11perf -copypixwin100 from about 4300/sec to 5780/sec under
    xcompmgr -a, because we no longer need to upload our x11perf window to
    a tiled temporary in order to render it to the screen.
    
    v2: Just use pixmap->usage_hint instead of a new field.  Drop the
        changes that started storing gbm_bos in the pixmap priv due to
        lifetime issues.
    v3: Fix a missing gbm_bo_destroy() on the pixmap-from-fd success path.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/glamor/glamor.h b/glamor/glamor.h
index 12dff8e..a4e0655 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -140,11 +140,6 @@ extern _X_EXPORT void glamor_pixmap_exchange_fbos(PixmapPtr front,
 
 /* The DDX is not supposed to call these three functions */
 extern _X_EXPORT void glamor_enable_dri3(ScreenPtr screen);
-extern _X_EXPORT unsigned int glamor_egl_create_argb8888_based_texture(ScreenPtr
-                                                                       screen,
-                                                                       int w,
-                                                                       int h,
-                                                                       Bool linear);
 extern _X_EXPORT int glamor_egl_dri3_fd_name_from_tex(ScreenPtr, PixmapPtr,
                                                       unsigned int, Bool,
                                                       CARD16 *, CARD32 *);
diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index e68af18..ea0443d 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -187,49 +187,6 @@ glamor_egl_get_gbm_device(ScreenPtr screen)
 #endif
 }
 
-unsigned int
-glamor_egl_create_argb8888_based_texture(ScreenPtr screen, int w, int h, Bool linear)
-{
-    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
-    struct glamor_egl_screen_private *glamor_egl;
-    EGLImageKHR image;
-    GLuint texture;
-
-#ifdef GLAMOR_HAS_GBM
-    struct gbm_bo *bo;
-    EGLNativePixmapType native_pixmap;
-
-    glamor_egl = glamor_egl_get_screen_private(scrn);
-    bo = gbm_bo_create(glamor_egl->gbm, w, h, GBM_FORMAT_ARGB8888,
-#ifdef GLAMOR_HAS_GBM_LINEAR
-                       (linear ? GBM_BO_USE_LINEAR : 0) |
-#endif
-                       GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
-    if (!bo)
-        return 0;
-
-    /* If the following assignment raises an error or a warning
-     * then that means EGLNativePixmapType is not struct gbm_bo *
-     * on your platform: This code won't work and you should not
-     * compile with dri3 support enabled */
-    native_pixmap = bo;
-
-    image = eglCreateImageKHR(glamor_egl->display,
-                              EGL_NO_CONTEXT,
-                              EGL_NATIVE_PIXMAP_KHR,
-                              native_pixmap, NULL);
-    gbm_bo_destroy(bo);
-    if (image == EGL_NO_IMAGE_KHR)
-        return 0;
-    glamor_create_texture_from_image(screen, image, &texture);
-    eglDestroyImageKHR(glamor_egl->display, image);
-
-    return texture;
-#else
-    return 0;                   /* this path should never happen */
-#endif
-}
-
 Bool
 glamor_egl_create_textured_screen(ScreenPtr screen, int handle, int stride)
 {
@@ -380,79 +337,92 @@ glamor_get_name_from_bo(int gbm_fd, struct gbm_bo *bo, int *name)
 }
 #endif
 
-#ifdef GLAMOR_HAS_GBM
-static void *
-_get_gbm_bo_from_pixmap(ScreenPtr screen, PixmapPtr pixmap, unsigned int tex)
+static Bool
+glamor_make_pixmap_exportable(PixmapPtr pixmap)
 {
+#ifdef GLAMOR_HAS_GBM
+    ScreenPtr screen = pixmap->drawable.pScreen;
     ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+    struct glamor_egl_screen_private *glamor_egl =
+        glamor_egl_get_screen_private(scrn);
     struct glamor_pixmap_private *pixmap_priv =
         glamor_get_pixmap_private(pixmap);
-    struct glamor_screen_private *glamor_priv =
-        glamor_get_screen_private(screen);
-    struct glamor_egl_screen_private *glamor_egl;
-    EGLImageKHR image;
+    unsigned width = pixmap->drawable.width;
+    unsigned height = pixmap->drawable.height;
     struct gbm_bo *bo;
+    PixmapPtr exported;
+    GCPtr scratch_gc;
 
-    EGLint attribs[] = {
-        EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
-        EGL_GL_TEXTURE_LEVEL_KHR, 0,
-        EGL_NONE
-    };
+    if (pixmap_priv->image)
+        return TRUE;
 
-    glamor_egl = glamor_egl_get_screen_private(scrn);
+    if (pixmap->drawable.bitsPerPixel != 32) {
+        xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                   "Failed to make %dbpp pixmap exportable\n",
+                   pixmap->drawable.bitsPerPixel);
+        return FALSE;
+    }
 
-    glamor_make_current(glamor_priv);
+    bo = gbm_bo_create(glamor_egl->gbm, width, height,
+                       GBM_FORMAT_ARGB8888,
+#ifdef GLAMOR_HAS_GBM_LINEAR
+                       (pixmap->usage_hint == CREATE_PIXMAP_USAGE_SHARED ?
+                        GBM_BO_USE_LINEAR : 0) |
+#endif
+                       GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
+    if (!bo) {
+        xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                   "Failed to make %dx%dx%dbpp GBM bo\n",
+                   width, height, pixmap->drawable.bitsPerPixel);
+        return FALSE;
+    }
 
-    image = pixmap_priv->image;
-    if (!image) {
-        image = eglCreateImageKHR(glamor_egl->display,
-                                  glamor_egl->context,
-                                  EGL_GL_TEXTURE_2D_KHR,
-                                  (EGLClientBuffer) (uintptr_t)
-                                  tex, attribs);
-        if (image == EGL_NO_IMAGE_KHR)
-            return NULL;
-
-        glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM);
-        glamor_egl_set_pixmap_image(pixmap, image);
+    exported = screen->CreatePixmap(screen, 0, 0, pixmap->drawable.depth, 0);
+    screen->ModifyPixmapHeader(exported, width, height, 0, 0,
+                               gbm_bo_get_stride(bo), NULL);
+    if (!glamor_egl_create_textured_pixmap_from_gbm_bo(exported, bo)) {
+        xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                   "Failed to make %dx%dx%dbpp pixmap from GBM bo\n",
+                   width, height, pixmap->drawable.bitsPerPixel);
+        screen->DestroyPixmap(exported);
+        gbm_bo_destroy(bo);
+        return FALSE;
     }
+    gbm_bo_destroy(bo);
 
-    bo = gbm_bo_import(glamor_egl->gbm, GBM_BO_IMPORT_EGL_IMAGE, image, 0);
-    if (!bo)
-        return NULL;
+    scratch_gc = GetScratchGC(pixmap->drawable.depth, screen);
+    ValidateGC(&pixmap->drawable, scratch_gc);
+    scratch_gc->ops->CopyArea(&pixmap->drawable, &exported->drawable,
+                              scratch_gc,
+                              0, 0, width, height, 0, 0);
+    FreeScratchGC(scratch_gc);
 
-    pixmap->devKind = gbm_bo_get_stride(bo);
+    /* Now, swap the tex/gbm/EGLImage/etc. of the exported pixmap into
+     * the original pixmap struct.
+     */
+    glamor_egl_exchange_buffers(pixmap, exported);
 
-    return bo;
-}
+    screen->DestroyPixmap(exported);
+
+    return TRUE;
+#else
+    return FALSE;
 #endif
+}
 
 struct gbm_bo *
 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 =
+    struct glamor_egl_screen_private *glamor_egl =
+        glamor_egl_get_screen_private(xf86ScreenToScrn(screen));
+    struct glamor_pixmap_private *pixmap_priv =
         glamor_get_pixmap_private(pixmap);
 
-    pixmap_priv = glamor_get_pixmap_private(pixmap);
-    if (!glamor_priv->dri3_enabled)
+    if (!glamor_make_pixmap_exportable(pixmap))
         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
+
+    return gbm_bo_import(glamor_egl->gbm, GBM_BO_IMPORT_EGL_IMAGE,
+                         pixmap_priv->image, 0);
 }
 
 int
@@ -468,7 +438,7 @@ glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
 
     glamor_egl = glamor_egl_get_screen_private(xf86ScreenToScrn(screen));
 
-    bo = _get_gbm_bo_from_pixmap(screen, pixmap, tex);
+    bo = glamor_gbm_bo_from_pixmap(screen, pixmap);
     if (!bo)
         goto failure;
 
@@ -504,8 +474,8 @@ glamor_back_pixmap_from_fd(PixmapPtr pixmap,
     ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
     struct glamor_egl_screen_private *glamor_egl;
     struct gbm_bo *bo;
-    Bool ret = FALSE;
     struct gbm_import_fd_data import_data = { 0 };
+    Bool ret;
 
     glamor_egl = glamor_egl_get_screen_private(scrn);
 
@@ -528,10 +498,7 @@ glamor_back_pixmap_from_fd(PixmapPtr pixmap,
 
     ret = glamor_egl_create_textured_pixmap_from_gbm_bo(pixmap, bo);
     gbm_bo_destroy(bo);
-
-    if (ret)
-        return TRUE;
-    return FALSE;
+    return ret;
 #else
     return FALSE;
 #endif
diff --git a/glamor/glamor_egl_stubs.c b/glamor/glamor_egl_stubs.c
index 35944c8..40f7fcc 100644
--- a/glamor/glamor_egl_stubs.c
+++ b/glamor/glamor_egl_stubs.c
@@ -43,9 +43,3 @@ glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
 {
     return 0;
 }
-
-unsigned int
-glamor_egl_create_argb8888_based_texture(ScreenPtr screen, int w, int h, Bool linear)
-{
-    return 0;
-}
diff --git a/glamor/glamor_fbo.c b/glamor/glamor_fbo.c
index 545f89f..b1b584d 100644
--- a/glamor/glamor_fbo.c
+++ b/glamor/glamor_fbo.c
@@ -329,30 +329,19 @@ glamor_destroy_fbo(glamor_screen_private *glamor_priv,
 
 static int
 _glamor_create_tex(glamor_screen_private *glamor_priv,
-                   int w, int h, GLenum format, Bool linear)
+                   int w, int h, GLenum format)
 {
-    unsigned int tex = 0;
-
-    /* With dri3, we want to allocate ARGB8888 pixmaps only.
-     * Depending on the implementation, GL_RGBA might not
-     * give us ARGB8888. We ask glamor_egl to use get
-     * an ARGB8888 based texture for us. */
-    if (glamor_priv->dri3_enabled && format == GL_RGBA) {
-        tex = glamor_egl_create_argb8888_based_texture(glamor_priv->screen,
-                                                       w, h, linear);
-    }
-    if (!tex) {
-        glamor_make_current(glamor_priv);
-        glGenTextures(1, &tex);
-        glBindTexture(GL_TEXTURE_2D, tex);
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
-        glamor_priv->suppress_gl_out_of_memory_logging = true;
-        glTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0,
-                     format, GL_UNSIGNED_BYTE, NULL);
-        glamor_priv->suppress_gl_out_of_memory_logging = false;
-    }
+    unsigned int tex;
+
+    glamor_make_current(glamor_priv);
+    glGenTextures(1, &tex);
+    glBindTexture(GL_TEXTURE_2D, tex);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+    glamor_priv->suppress_gl_out_of_memory_logging = true;
+    glTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0,
+                 format, GL_UNSIGNED_BYTE, NULL);
+    glamor_priv->suppress_gl_out_of_memory_logging = false;
 
     if (glGetError() == GL_OUT_OF_MEMORY) {
         if (!glamor_priv->logged_any_fbo_allocation_failure) {
@@ -383,7 +372,7 @@ glamor_create_fbo(glamor_screen_private *glamor_priv,
     if (fbo)
         return fbo;
  new_fbo:
-    tex = _glamor_create_tex(glamor_priv, w, h, format, flag == CREATE_PIXMAP_USAGE_SHARED);
+    tex = _glamor_create_tex(glamor_priv, w, h, format);
     if (!tex)
         return NULL;
     fbo = glamor_create_fbo_from_tex(glamor_priv, w, h, format, tex, flag);
@@ -548,7 +537,7 @@ glamor_pixmap_ensure_fbo(PixmapPtr pixmap, GLenum format, int flag)
         if (!pixmap_priv->fbo->tex)
             pixmap_priv->fbo->tex =
                 _glamor_create_tex(glamor_priv, pixmap->drawable.width,
-                                   pixmap->drawable.height, format, FALSE);
+                                   pixmap->drawable.height, format);
 
         if (flag != GLAMOR_CREATE_FBO_NO_FBO && pixmap_priv->fbo->fb == 0)
             if (glamor_pixmap_ensure_fb(glamor_priv, pixmap_priv->fbo) != 0)
diff --git a/hw/xwayland/xwayland-glamor.c b/hw/xwayland/xwayland-glamor.c
index dedefdc..ebaf05a 100644
--- a/hw/xwayland/xwayland-glamor.c
+++ b/hw/xwayland/xwayland-glamor.c
@@ -409,12 +409,6 @@ glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
     return 0;
 }
 
-unsigned int
-glamor_egl_create_argb8888_based_texture(ScreenPtr screen, int w, int h, Bool linear)
-{
-    return 0;
-}
-
 struct xwl_auth_state {
     int fd;
     ClientPtr client;
commit 7cd495a88807698b4ebaf9c1fb3db6edf31dd7e6
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Oct 15 13:25:12 2015 -0700

    glamor: Make glamor_get_name_from_bo static.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index fde7688..e68af18 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -369,9 +369,7 @@ glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap,
 }
 
 #ifdef GLAMOR_HAS_GBM
-void glamor_get_name_from_bo(int gbm_fd, struct gbm_bo *bo, int *name);
-
-void
+static void
 glamor_get_name_from_bo(int gbm_fd, struct gbm_bo *bo, int *name)
 {
     union gbm_bo_handle handle;
commit 6be33fd044949330e0b2b4185882c9664d2f90b4
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jun 18 11:26:46 2015 -0700

    glamor: Simplify DRI3 pixmap-from-fd, using GBM.
    
    This GBM import path was introduced in 10.2, which we already require.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index f3650b7..fde7688 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -506,18 +506,8 @@ glamor_back_pixmap_from_fd(PixmapPtr pixmap,
     ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
     struct glamor_egl_screen_private *glamor_egl;
     struct gbm_bo *bo;
-    EGLImageKHR image;
     Bool ret = FALSE;
-
-    EGLint attribs[] = {
-        EGL_WIDTH, 0,
-        EGL_HEIGHT, 0,
-        EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
-        EGL_DMA_BUF_PLANE0_FD_EXT, 0,
-        EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
-        EGL_DMA_BUF_PLANE0_PITCH_EXT, 0,
-        EGL_NONE
-    };
+    struct gbm_import_fd_data import_data = { 0 };
 
     glamor_egl = glamor_egl_get_screen_private(scrn);
 
@@ -527,23 +517,12 @@ glamor_back_pixmap_from_fd(PixmapPtr pixmap,
     if (bpp != 32 || !(depth == 24 || depth == 32) || width == 0 || height == 0)
         return FALSE;
 
-    attribs[1] = width;
-    attribs[3] = height;
-    attribs[7] = fd;
-    attribs[11] = stride;
-    image = eglCreateImageKHR(glamor_egl->display,
-                              EGL_NO_CONTEXT,
-                              EGL_LINUX_DMA_BUF_EXT,
-                              NULL, attribs);
-
-    if (image == EGL_NO_IMAGE_KHR)
-        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);
-
+    import_data.fd = fd;
+    import_data.width = width;
+    import_data.height = height;
+    import_data.stride = stride;
+    import_data.format = GBM_FORMAT_ARGB8888;
+    bo = gbm_bo_import(glamor_egl->gbm, GBM_BO_IMPORT_FD, &import_data, 0);
     if (!bo)
         return FALSE;
 
@@ -871,8 +850,6 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd)
 #ifdef GLAMOR_HAS_GBM
     if (epoxy_has_egl_extension(glamor_egl->display,
                                 "EGL_KHR_gl_texture_2D_image") &&
-        epoxy_has_egl_extension(glamor_egl->display,
-                                "EGL_EXT_image_dma_buf_import") &&
         epoxy_has_gl_extension("GL_OES_EGL_image"))
         glamor_egl->dri3_capable = TRUE;
 #endif
commit 1b8f16d8e659fb483453e1123a9fa876adb758ff
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jun 18 11:21:10 2015 -0700

    glamor: Use real types for glamor_egl's public gbm functions.
    
    I think void * was just used to avoid needing to #include gbm.h, but
    we can just forward-declare the structs and be fine.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/glamor/glamor.h b/glamor/glamor.h
index 4459fa4..12dff8e 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -40,6 +40,8 @@
 #endif
 
 struct glamor_context;
+struct gbm_bo;
+struct gbm_device;
 
 /*
  * glamor_pixmap_type : glamor pixmap's type.
@@ -147,7 +149,7 @@ extern _X_EXPORT int glamor_egl_dri3_fd_name_from_tex(ScreenPtr, PixmapPtr,
                                                       unsigned int, Bool,
                                                       CARD16 *, CARD32 *);
 
-extern _X_EXPORT void *glamor_egl_get_gbm_device(ScreenPtr screen);
+extern _X_EXPORT struct gbm_device *glamor_egl_get_gbm_device(ScreenPtr screen);
 
 /* @glamor_supports_pixmap_import_export: Returns whether
  * glamor_fd_from_pixmap(), glamor_name_from_pixmap(), and
@@ -207,8 +209,8 @@ extern _X_EXPORT int glamor_name_from_pixmap(PixmapPtr pixmap,
  *
  * Returns the gbm_bo on success, NULL on error.
  * */
-extern _X_EXPORT void *glamor_gbm_bo_from_pixmap(ScreenPtr screen,
-                                                 PixmapPtr pixmap);
+extern _X_EXPORT struct gbm_bo *glamor_gbm_bo_from_pixmap(ScreenPtr screen,
+                                                          PixmapPtr pixmap);
 
 /* @glamor_pixmap_from_fd: Creates a pixmap to wrap a dma-buf fd.
  *
@@ -315,7 +317,8 @@ extern _X_EXPORT Bool glamor_egl_create_textured_pixmap(PixmapPtr pixmap,
  * 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);
+ glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap,
+                                               struct gbm_bo *bo);
 
 #endif
 
diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index 6580141..f3650b7 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -175,7 +175,7 @@ glamor_create_texture_from_image(ScreenPtr screen,
     return TRUE;
 }
 
-void *
+struct gbm_device *
 glamor_egl_get_gbm_device(ScreenPtr screen)
 {
 #ifdef GLAMOR_HAS_GBM
@@ -335,7 +335,8 @@ glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride)
 }
 
 Bool
-glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap, void *bo)
+glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap,
+                                              struct gbm_bo *bo)
 {
     ScreenPtr screen = pixmap->drawable.pScreen;
     ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
@@ -428,7 +429,7 @@ _get_gbm_bo_from_pixmap(ScreenPtr screen, PixmapPtr pixmap, unsigned int tex)
 }
 #endif
 
-void *
+struct gbm_bo *
 glamor_gbm_bo_from_pixmap(ScreenPtr screen, PixmapPtr pixmap)
 {
 #ifdef GLAMOR_HAS_GBM
commit f80758f32a7b922baf8fbf3ac6d8c9aae5fea1c4
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jun 18 11:15:40 2015 -0700

    glamor: Use the GBM function for getting an FD from a GBM BO.
    
    We were rolling ioctl calls ourselves, when there's a nice interface
    for it.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index 761874f..6580141 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -368,22 +368,7 @@ glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap, void *bo)
 }
 
 #ifdef GLAMOR_HAS_GBM
-int glamor_get_fd_from_bo(int gbm_fd, struct gbm_bo *bo, int *fd);
 void glamor_get_name_from_bo(int gbm_fd, struct gbm_bo *bo, int *name);
-int
-glamor_get_fd_from_bo(int gbm_fd, struct gbm_bo *bo, int *fd)
-{
-    union gbm_bo_handle handle;
-    struct drm_prime_handle args;
-
-    handle = gbm_bo_get_handle(bo);
-    args.handle = handle.u32;
-    args.flags = DRM_CLOEXEC;
-    if (ioctl(gbm_fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args))
-        return FALSE;
-    *fd = args.fd;
-    return TRUE;
-}
 
 void
 glamor_get_name_from_bo(int gbm_fd, struct gbm_bo *bo, int *name)
@@ -495,8 +480,7 @@ glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
             glamor_get_name_from_bo(glamor_egl->fd, bo, &fd);
     }
     else {
-        if (glamor_get_fd_from_bo(glamor_egl->fd, bo, &fd)) {
-        }
+        fd = gbm_bo_get_fd(bo);
     }
     *stride = pixmap->devKind;
     *size = pixmap->devKind * gbm_bo_get_height(bo);
commit ff2850424c99652506d0d6bc43506b4c16bf2ad5
Author: Eric Anholt <eric at anholt.net>
Date:   Sun Oct 18 19:26:14 2015 -0700

    glamor: Hook up EGL DestroyPixmap through the normal wrap chain.
    
    One less layering violation (EGL should call glamor, if anything, not
    the other way around).
    
    v2: Move glamor.c's DestroyPixmap wrapping up above the
        glamor_egl_screen_init() call, since glamor.c's DestroyPixmap
        needs to be the bottom of the stack (it calls fb directly and
        doesn't wrap).  Caught by Michel.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index 4cd98c4..116d10c 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -206,9 +206,6 @@ Bool
 glamor_destroy_pixmap(PixmapPtr pixmap)
 {
     if (pixmap->refcnt == 1) {
-#if GLAMOR_HAS_GBM
-        glamor_egl_destroy_pixmap_image(pixmap);
-#endif
         glamor_pixmap_destroy_fbo(pixmap);
     }
 
@@ -461,6 +458,9 @@ glamor_init(ScreenPtr screen, unsigned int flags)
     glamor_priv->saved_procs.close_screen = screen->CloseScreen;
     screen->CloseScreen = glamor_close_screen;
 
+    glamor_priv->saved_procs.destroy_pixmap = screen->DestroyPixmap;
+    screen->DestroyPixmap = glamor_destroy_pixmap;
+
     /* If we are using egl screen, call egl screen init to
      * register correct close screen function. */
     if (flags & GLAMOR_USE_EGL_SCREEN) {
@@ -615,9 +615,6 @@ glamor_init(ScreenPtr screen, unsigned int flags)
     glamor_priv->saved_procs.create_pixmap = screen->CreatePixmap;
     screen->CreatePixmap = glamor_create_pixmap;
 
-    glamor_priv->saved_procs.destroy_pixmap = screen->DestroyPixmap;
-    screen->DestroyPixmap = glamor_destroy_pixmap;
-
     glamor_priv->saved_procs.get_spans = screen->GetSpans;
     screen->GetSpans = glamor_get_spans;
 
diff --git a/glamor/glamor.h b/glamor/glamor.h
index 6d135df..4459fa4 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -147,8 +147,6 @@ extern _X_EXPORT int glamor_egl_dri3_fd_name_from_tex(ScreenPtr, PixmapPtr,
                                                       unsigned int, Bool,
                                                       CARD16 *, CARD32 *);
 
-extern void glamor_egl_destroy_pixmap_image(PixmapPtr pixmap);
-
 extern _X_EXPORT void *glamor_egl_get_gbm_device(ScreenPtr screen);
 
 /* @glamor_supports_pixmap_import_export: Returns whether
diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index 24d5586..761874f 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -78,6 +78,7 @@ struct glamor_egl_screen_private {
     int dri3_capable;
 
     CloseScreenProcPtr saved_close_screen;
+    DestroyPixmapProcPtr saved_destroy_pixmap;
     xf86FreeScreenProc *saved_free_screen;
 };
 
@@ -598,20 +599,29 @@ glamor_pixmap_from_fd(ScreenPtr screen,
 #endif
 }
 
-void
-glamor_egl_destroy_pixmap_image(PixmapPtr pixmap)
+static Bool
+glamor_egl_destroy_pixmap(PixmapPtr pixmap)
 {
-    struct glamor_pixmap_private *pixmap_priv =
-        glamor_get_pixmap_private(pixmap);
+    ScreenPtr screen = pixmap->drawable.pScreen;
+    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+    struct glamor_egl_screen_private *glamor_egl =
+        glamor_egl_get_screen_private(scrn);
+    Bool ret;
 
-    if (pixmap_priv->image) {
-        ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
-        struct glamor_egl_screen_private *glamor_egl =
-            glamor_egl_get_screen_private(scrn);
+    if (pixmap->refcnt == 1) {
+        struct glamor_pixmap_private *pixmap_priv =
+            glamor_get_pixmap_private(pixmap);
 
-        eglDestroyImageKHR(glamor_egl->display, pixmap_priv->image);
-        pixmap_priv->image = NULL;
+        if (pixmap_priv->image)
+            eglDestroyImageKHR(glamor_egl->display, pixmap_priv->image);
     }
+
+    screen->DestroyPixmap = glamor_egl->saved_destroy_pixmap;
+    ret = screen->DestroyPixmap(pixmap);
+    glamor_egl->saved_destroy_pixmap = screen->DestroyPixmap;
+    screen->DestroyPixmap = glamor_egl_destroy_pixmap;
+
+    return ret;
 }
 
 _X_EXPORT void
@@ -723,6 +733,9 @@ glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx)
     glamor_egl->saved_close_screen = screen->CloseScreen;
     screen->CloseScreen = glamor_egl_close_screen;
 
+    glamor_egl->saved_destroy_pixmap = screen->DestroyPixmap;
+    screen->DestroyPixmap = glamor_egl_destroy_pixmap;
+
     glamor_ctx->ctx = glamor_egl->context;
     glamor_ctx->display = glamor_egl->display;
 
diff --git a/glamor/glamor_egl_stubs.c b/glamor/glamor_egl_stubs.c
index c11e6d5..35944c8 100644
--- a/glamor/glamor_egl_stubs.c
+++ b/glamor/glamor_egl_stubs.c
@@ -35,11 +35,6 @@ glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx)
 {
 }
 
-void
-glamor_egl_destroy_pixmap_image(PixmapPtr pixmap)
-{
-}
-
 int
 glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
                                  PixmapPtr pixmap,
diff --git a/hw/xwayland/xwayland-glamor.c b/hw/xwayland/xwayland-glamor.c
index ece7dbe..dedefdc 100644
--- a/hw/xwayland/xwayland-glamor.c
+++ b/hw/xwayland/xwayland-glamor.c
@@ -400,11 +400,6 @@ xwl_screen_init_glamor(struct xwl_screen *xwl_screen,
     return TRUE;
 }
 
-void
-glamor_egl_destroy_pixmap_image(PixmapPtr pixmap)
-{
-}
-
 int
 glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
                                  PixmapPtr pixmap,
commit e91fd30049ba9ebfb6ee8aded74eebe006af3f57
Author: Eric Anholt <eric at anholt.net>
Date:   Sun Oct 18 21:34:45 2015 -0700

    glamor: Unexport glamor_destroy_textured_pixmap().
    
    This is just a bit of the DestroyPixmap chain.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index e69f83d..4cd98c4 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -202,8 +202,8 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
     return pixmap;
 }
 
-void
-glamor_destroy_textured_pixmap(PixmapPtr pixmap)
+Bool
+glamor_destroy_pixmap(PixmapPtr pixmap)
 {
     if (pixmap->refcnt == 1) {
 #if GLAMOR_HAS_GBM
@@ -211,12 +211,7 @@ glamor_destroy_textured_pixmap(PixmapPtr pixmap)
 #endif
         glamor_pixmap_destroy_fbo(pixmap);
     }
-}
 
-Bool
-glamor_destroy_pixmap(PixmapPtr pixmap)
-{
-    glamor_destroy_textured_pixmap(pixmap);
     return fbDestroyPixmap(pixmap);
 }
 
diff --git a/glamor/glamor.h b/glamor/glamor.h
index 54fec1d..6d135df 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -110,7 +110,6 @@ extern _X_EXPORT void glamor_set_pixmap_texture(PixmapPtr pixmap,
 
 extern _X_EXPORT void glamor_set_pixmap_type(PixmapPtr pixmap,
                                              glamor_pixmap_type_t type);
-extern _X_EXPORT void glamor_destroy_textured_pixmap(PixmapPtr pixmap);
 extern _X_EXPORT void glamor_block_handler(ScreenPtr screen);
 
 extern _X_EXPORT PixmapPtr glamor_create_pixmap(ScreenPtr screen, int w, int h,
commit 3dd202933fd94615aeeaec7e4cfd05a68954a3f3
Author: Eric Anholt <eric at anholt.net>
Date:   Sun Oct 18 21:28:19 2015 -0700

    glamor: Remove glamor_egl_destroy_textured_pixmap().
    
    The DestroyPixmap chain and CloseScreen chain all do pixmap teardown
    already, and calling it manually would be redundant.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/glamor/glamor.h b/glamor/glamor.h
index 4be8800..54fec1d 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -324,7 +324,6 @@ extern _X_EXPORT Bool
 
 extern _X_EXPORT void glamor_egl_screen_init(ScreenPtr screen,
                                              struct glamor_context *glamor_ctx);
-extern _X_EXPORT void glamor_egl_destroy_textured_pixmap(PixmapPtr pixmap);
 
 extern _X_EXPORT int glamor_create_gc(GCPtr gc);
 
diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index cc16b0a..24d5586 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -633,12 +633,6 @@ glamor_egl_exchange_buffers(PixmapPtr front, PixmapPtr back)
     glamor_set_pixmap_type(back, GLAMOR_TEXTURE_DRM);
 }
 
-void
-glamor_egl_destroy_textured_pixmap(PixmapPtr pixmap)
-{
-    glamor_destroy_textured_pixmap(pixmap);
-}
-
 static Bool
 glamor_egl_close_screen(ScreenPtr screen)
 {
commit 9d2b76652f0bca5680b9e3ae2aacd508d5525684
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Jun 19 15:56:13 2015 -0700

    modesetting: No need to free the EGLImage just before freeing the pixmap.
    
    DestroyPixmap handles that just fine.  This also lets us drop our use
    of the manual image destruction function (Note that the radeon driver
    still uses it in a similar fashion, though).
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 4421578..0d34ca1 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -780,7 +780,6 @@ drmmode_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
     drmmode_ptr drmmode = drmmode_crtc->drmmode;
 
     if (rotate_pixmap) {
-        drmmode_set_pixmap_bo(drmmode, rotate_pixmap, NULL);
         rotate_pixmap->drawable.pScreen->DestroyPixmap(rotate_pixmap);
     }
 
@@ -1588,11 +1587,6 @@ drmmode_set_pixmap_bo(drmmode_ptr drmmode, PixmapPtr pixmap, drmmode_bo *bo)
     if (!drmmode->glamor)
         return TRUE;
 
-    if (bo == NULL) {
-        glamor_egl_destroy_textured_pixmap(pixmap);
-        return TRUE;
-    }
-
 #ifdef GLAMOR_HAS_GBM
     if (!glamor_egl_create_textured_pixmap_from_gbm_bo(pixmap, bo->gbm)) {
         xf86DrvMsg(scrn->scrnIndex, X_ERROR, "Failed");
commit 98a1993536add730b7ec29a9e37f62b1cd70ad31
Author: Eric Anholt <eric at anholt.net>
Date:   Sun Oct 18 19:16:20 2015 -0700

    glamor: No need to glFlush before destroying a pixmap.
    
    I assume this was a workaround for an old, broken, closed driver.  The
    driver doesn't get to throw away rendering just because the rendering
    context's shared-across-processes render target is getting freed from
    the local address space.  If the rendering isn't to a shared render
    target, then we *do* want to throw away the rendering to it.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index 2e6c7bd..cc16b0a 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -609,10 +609,6 @@ glamor_egl_destroy_pixmap_image(PixmapPtr pixmap)
         struct glamor_egl_screen_private *glamor_egl =
             glamor_egl_get_screen_private(scrn);
 
-        /* Before destroy an image which was attached to
-         * a texture. we must call glFlush to make sure the
-         * operation on that texture has been done.*/
-        glamor_block_handler(pixmap->drawable.pScreen);
         eglDestroyImageKHR(glamor_egl->display, pixmap_priv->image);
         pixmap_priv->image = NULL;
     }


More information about the xorg-commit mailing list