[PATCH 1/3] glamor: Always destroy EGL image associated with destroyed pixmap

Keith Packard keithp at keithp.com
Mon Dec 8 13:38:43 PST 2014


There were three paths that called eglDestroyImageKHR:

 * The front buffer
 * The intel driver's flip buffer
 * pixmaps under DRI3

This patch unifies the second two by having glamor_destroy_pixmap
always destroy any associaged EGL image. This allows us to stop
storing the back_pixmap pointer in glamor as that was only used to
make sure that buffer was freed at server reset time.

Signed-off-by: Keith Packard <keithp at keithp.com>
---
 glamor/glamor.c               | 26 ++++++--------------------
 glamor/glamor.h               |  3 ++-
 glamor/glamor_egl.c           | 40 ++++++++--------------------------------
 glamor/glamor_egl_stubs.c     |  2 +-
 glamor/glamor_priv.h          |  1 -
 hw/xwayland/xwayland-glamor.c |  3 +--
 6 files changed, 18 insertions(+), 57 deletions(-)

diff --git a/glamor/glamor.c b/glamor/glamor.c
index d228e35..6cf9bdf 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -123,8 +123,6 @@ glamor_set_screen_pixmap(PixmapPtr screen_pixmap, PixmapPtr *back_pixmap)
 
     pixmap_priv->base.fbo->width = screen_pixmap->drawable.width;
     pixmap_priv->base.fbo->height = screen_pixmap->drawable.height;
-
-    glamor_priv->back_pixmap = back_pixmap;
 }
 
 uint32_t
@@ -218,27 +216,17 @@ 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) {
-        glamor_pixmap_private *pixmap_priv;
-
-        pixmap_priv = glamor_get_pixmap_private(pixmap);
+        glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
         if (pixmap_priv != NULL)
             glamor_pixmap_destroy_fbo(pixmap_priv);
+#if GLAMOR_HAS_GBM
+        glamor_egl_destroy_pixmap_image(pixmap);
+#endif
     }
-}
-
-Bool
-glamor_destroy_pixmap(PixmapPtr pixmap)
-{
-    glamor_screen_private
-        *glamor_priv = glamor_get_screen_private(pixmap->drawable.pScreen);
-    if (glamor_priv->dri3_enabled)
-        glamor_egl_destroy_textured_pixmap(pixmap);
-    else
-        glamor_destroy_textured_pixmap(pixmap);
     return fbDestroyPixmap(pixmap);
 }
 
@@ -619,8 +607,6 @@ glamor_close_screen(ScreenPtr screen)
 #endif
     screen_pixmap = screen->GetScreenPixmap(screen);
     glamor_set_pixmap_private(screen_pixmap, NULL);
-    if (glamor_priv->back_pixmap && *glamor_priv->back_pixmap)
-        glamor_set_pixmap_private(*glamor_priv->back_pixmap, NULL);
 
     glamor_release_screen_priv(screen);
 
diff --git a/glamor/glamor.h b/glamor/glamor.h
index 405dbe8..1683414 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -132,7 +132,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,
@@ -170,6 +169,8 @@ 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);
+
 /* @glamor_supports_pixmap_import_export: Returns whether
  * glamor_fd_from_pixmap(), glamor_name_from_pixmap(), and
  * glamor_pixmap_from_fd() are supported.
diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index 182e2e8..904becf 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -70,7 +70,6 @@ struct glamor_egl_screen_private {
     CloseScreenProcPtr CloseScreen;
     int fd;
     EGLImageKHR front_image;
-    PixmapPtr *back_pixmap;
     int cpp;
 #ifdef GLAMOR_HAS_GBM
     struct gbm_device *gbm;
@@ -235,7 +234,7 @@ glamor_egl_create_textured_screen(ScreenPtr screen, int handle, int stride)
     }
 
     glamor_egl->front_image = pixmap_priv->base.image;
-    glamor_set_screen_pixmap(screen_pixmap, glamor_egl->back_pixmap);
+    glamor_set_screen_pixmap(screen_pixmap, NULL);
     return TRUE;
 }
 
@@ -244,15 +243,7 @@ glamor_egl_create_textured_screen_ext(ScreenPtr screen,
                                       int handle,
                                       int stride, PixmapPtr *back_pixmap)
 {
-    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
-    struct glamor_egl_screen_private *glamor_egl;
-
-    glamor_egl = glamor_egl_get_screen_private(scrn);
-
-    glamor_egl->back_pixmap = back_pixmap;
-    if (!glamor_egl_create_textured_screen(screen, handle, stride))
-        return FALSE;
-    return TRUE;
+    return glamor_egl_create_textured_screen(screen, handle, stride);
 }
 
 static Bool
@@ -519,16 +510,17 @@ glamor_pixmap_from_fd(ScreenPtr screen,
 #endif
 }
 
-static void
-_glamor_egl_destroy_pixmap_image(PixmapPtr pixmap)
+void
+glamor_egl_destroy_pixmap_image(PixmapPtr pixmap)
 {
-    ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
-    struct glamor_egl_screen_private *glamor_egl =
-        glamor_egl_get_screen_private(scrn);
     struct glamor_pixmap_private *pixmap_priv =
         glamor_get_pixmap_private(pixmap);
 
     if (pixmap_priv->base.image) {
+        ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
+        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.*/
@@ -562,14 +554,6 @@ glamor_egl_exchange_buffers(PixmapPtr front, PixmapPtr back)
 
 }
 
-void
-glamor_egl_destroy_textured_pixmap(PixmapPtr pixmap)
-{
-    if (pixmap->refcnt == 1)
-        _glamor_egl_destroy_pixmap_image(pixmap);
-    glamor_destroy_textured_pixmap(pixmap);
-}
-
 static Bool
 glamor_egl_close_screen(ScreenPtr screen)
 {
@@ -587,14 +571,6 @@ glamor_egl_close_screen(ScreenPtr screen)
     pixmap_priv->base.image = NULL;
     glamor_egl->front_image = NULL;
 
-    if (glamor_egl->back_pixmap && *glamor_egl->back_pixmap) {
-        pixmap_priv = glamor_get_pixmap_private(*glamor_egl->back_pixmap);
-        if (pixmap_priv->base.image) {
-            eglDestroyImageKHR(glamor_egl->display, pixmap_priv->base.image);
-            pixmap_priv->base.image = NULL;
-        }
-    }
-
     screen->CloseScreen = glamor_egl->saved_close_screen;
 
     return screen->CloseScreen(screen);
diff --git a/glamor/glamor_egl_stubs.c b/glamor/glamor_egl_stubs.c
index 028d1cc..a93f62d 100644
--- a/glamor/glamor_egl_stubs.c
+++ b/glamor/glamor_egl_stubs.c
@@ -36,7 +36,7 @@ glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx)
 }
 
 void
-glamor_egl_destroy_textured_pixmap(PixmapPtr pixmap)
+glamor_egl_destroy_pixmap_image(PixmapPtr pixmap)
 {
 }
 
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 885f12a..ffd327e 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -306,7 +306,6 @@ typedef struct glamor_screen_private {
     int linear_max_nstops;
     int radial_max_nstops;
 
-    PixmapPtr *back_pixmap;
     int screen_fbo;
     struct glamor_saved_procs saved_procs;
     char delayed_fallback_string[GLAMOR_DELAYED_STRING_MAX + 1];
diff --git a/hw/xwayland/xwayland-glamor.c b/hw/xwayland/xwayland-glamor.c
index 4be883f..09b454f 100644
--- a/hw/xwayland/xwayland-glamor.c
+++ b/hw/xwayland/xwayland-glamor.c
@@ -398,9 +398,8 @@ xwl_screen_init_glamor(struct xwl_screen *xwl_screen,
 }
 
 void
-glamor_egl_destroy_textured_pixmap(PixmapPtr pixmap)
+glamor_egl_destroy_pixmap_image(PixmapPtr pixmap)
 {
-    glamor_destroy_textured_pixmap(pixmap);
 }
 
 int
-- 
2.1.3



More information about the xorg-devel mailing list