[PATCH xserver 11/11] glamor: Stop holding on to the EGLImage for textures.

Eric Anholt eric at anholt.net
Fri Nov 6 12:52:05 PST 2015


We used to cache the EGLImage to be able to return an fd again faster,
but now we keep the gbm bo on hand to do so.

One concern might be if the early destruction of the EGLImage meant
orphaning. However, the EGL_KHR_image_base spec text says:

    Once destroyed, <image> may not be used to create any additional
    EGLImage target resources within any client API contexts, although
    existing EGLImage siblings may continue to be used.

and, even more clearly in the issues section:

    Note that the EGLImage source and any EGLImage target resources
    will still be EGLImage siblings, even if the EGLImage object is
    destroyed by a call to DestroyImageKHR.

Signed-off-by: Eric Anholt <eric at anholt.net>
---
 glamor/glamor_egl.c  | 37 ++++++-------------------------------
 glamor/glamor_priv.h |  5 -----
 2 files changed, 6 insertions(+), 36 deletions(-)

diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index 8638063..6eeb7f2 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -225,24 +225,6 @@ glamor_egl_check_has_gem(int fd)
     return FALSE;
 }
 
-static void
-glamor_egl_set_pixmap_image(PixmapPtr pixmap, EGLImageKHR image)
-{
-    struct glamor_pixmap_private *pixmap_priv =
-        glamor_get_pixmap_private(pixmap);
-    EGLImageKHR old;
-
-    old = pixmap_priv->image;
-    if (old) {
-        ScreenPtr                               screen = pixmap->drawable.pScreen;
-        ScrnInfoPtr                             scrn = xf86ScreenToScrn(screen);
-        struct glamor_egl_screen_private        *glamor_egl = glamor_egl_get_screen_private(scrn);
-
-        eglDestroyImageKHR(glamor_egl->display, old);
-    }
-    pixmap_priv->image = image;
-}
-
 Bool
 glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride)
 {
@@ -284,7 +266,7 @@ glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride)
     glamor_create_texture_from_image(screen, image, &texture);
     glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM);
     glamor_set_pixmap_texture(pixmap, texture);
-    glamor_egl_set_pixmap_image(pixmap, image);
+    eglDestroyImageKHR(glamor_egl->display, image);
     ret = TRUE;
 
  done:
@@ -321,7 +303,6 @@ glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap,
     glamor_create_texture_from_image(screen, image, &texture);
     glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM);
     glamor_set_pixmap_texture(pixmap, texture);
-    glamor_egl_set_pixmap_image(pixmap, image);
     if (pixmap_priv->gbm)
         gbm_bo_destroy(pixmap_priv->gbm);
     pixmap_priv->gbm = bo;
@@ -532,13 +513,10 @@ glamor_egl_destroy_pixmap(PixmapPtr pixmap)
     Bool ret;
 
     if (pixmap->refcnt == 1) {
+#ifdef GLAMOR_HAS_GBM
         struct glamor_pixmap_private *pixmap_priv =
             glamor_get_pixmap_private(pixmap);
 
-        if (pixmap_priv->image)
-            eglDestroyImageKHR(glamor_egl->display, pixmap_priv->image);
-
-#ifdef GLAMOR_HAS_GBM
         if (pixmap_priv->gbm) {
             gbm_bo_destroy(pixmap_priv->gbm);
             pixmap_priv->gbm = NULL;
@@ -557,7 +535,6 @@ glamor_egl_destroy_pixmap(PixmapPtr pixmap)
 _X_EXPORT void
 glamor_egl_exchange_buffers(PixmapPtr front, PixmapPtr back)
 {
-    EGLImageKHR temp_image;
     struct gbm_bo *temp_bo;
     struct glamor_pixmap_private *front_priv =
         glamor_get_pixmap_private(front);
@@ -566,10 +543,6 @@ glamor_egl_exchange_buffers(PixmapPtr front, PixmapPtr back)
 
     glamor_pixmap_exchange_fbos(front, back);
 
-    temp_image = back_priv->image;
-    back_priv->image = front_priv->image;
-    front_priv->image = temp_image;
-
     temp_bo = back_priv->gbm;
     back_priv->gbm = front_priv->gbm;
     front_priv->gbm = temp_bo;
@@ -591,8 +564,10 @@ glamor_egl_close_screen(ScreenPtr screen)
     screen_pixmap = screen->GetScreenPixmap(screen);
     pixmap_priv = glamor_get_pixmap_private(screen_pixmap);
 
-    eglDestroyImageKHR(glamor_egl->display, pixmap_priv->image);
-    pixmap_priv->image = NULL;
+    if (pixmap_priv->gbm) {
+        gbm_bo_destroy(pixmap_priv->gbm);
+        pixmap_priv->gbm = NULL;
+    }
 
     screen->CloseScreen = glamor_egl->saved_close_screen;
 
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index df6a02a..dd01aeb 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -38,10 +38,6 @@
 #endif
 
 #include <epoxy/gl.h>
-#if GLAMOR_HAS_GBM
-#define MESA_EGL_NO_X11_HEADERS
-#include <epoxy/egl.h>
-#endif
 
 #define GLAMOR_DEFAULT_PRECISION  \
     "#ifdef GL_ES\n"              \
@@ -355,7 +351,6 @@ typedef struct glamor_pixmap_private {
     Bool prepared;
     Bool usage_shared;
 #if GLAMOR_HAS_GBM
-    EGLImageKHR image;
     struct gbm_bo *gbm;
 #endif
     /** block width of this large pixmap. */
-- 
2.6.2



More information about the xorg-devel mailing list