From cd929604a1e1aa2137cc56c44030ed70d06e0525 Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Wed, 13 Aug 2008 17:55:16 +0000 Subject: [PATCH] Introduce imlib_context_disconnect_display(). imlib_context_disconnect_display() should be called when a display connection is closed but the application continues using imlib2 with a different display connection. This is required to avoid to attempt to free cached GCs (in __imlib_RenderImage) after the associated display connection has been closed. It is not unlikely that similar cleanups should be performed elsewhere in this situation, but the __imlib_RenderImage GCs is the only case I have found to cause trouble so far. SVN revision: 35463 --- src/lib/Imlib2.h | 1 + src/lib/api.c | 20 ++++++++++++++++++-- src/lib/rend.c | 19 +++++++++++++++---- src/lib/rend.h | 3 +++ 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/lib/Imlib2.h b/src/lib/Imlib2.h index 8f5a338..e4008df 100644 --- a/src/lib/Imlib2.h +++ b/src/lib/Imlib2.h @@ -131,6 +131,7 @@ extern "C" /* context setting */ # ifndef X_DISPLAY_MISSING EAPI void imlib_context_set_display(Display * display); + EAPI void imlib_context_disconnect_display(void); EAPI void imlib_context_set_visual(Visual * visual); EAPI void imlib_context_set_colormap(Colormap colormap); EAPI void imlib_context_set_drawable(Drawable drawable); diff --git a/src/lib/api.c b/src/lib/api.c index ed03ed4..43ad21b 100644 --- a/src/lib/api.c +++ b/src/lib/api.c @@ -314,8 +314,8 @@ imlib_context_get_cliprect(int *x, int *y, int *w, int *h) } #ifdef BUILD_X11 -/** - * @param display Current display to bu used. +/** + * @param display Current display to be used. * * Sets the current X display to be used for rendering of images to * drawables. You do not need to set this if you do not intend to @@ -345,6 +345,22 @@ imlib_context_get_display(void) return ctx->display; } +/** + * Tell Imlib2 that the current display connection has been closed. + * + * Call when (and only when) you close a display connection but continue + * using Imlib2 on a different connection. + */ +EAPI void +imlib_context_disconnect_display(void) +{ + CHECK_CONTEXT(ctx); + if (!ctx->display) + return; + __imlib_RenderDisconnect(ctx->display); + ctx->display = NULL; +} + /** * @param visual Current visual to use. * diff --git a/src/lib/rend.c b/src/lib/rend.c index 7379973..dc6edf5 100644 --- a/src/lib/rend.c +++ b/src/lib/rend.c @@ -235,6 +235,21 @@ __imlib_generic_render(DATA32 * src, int jump, int w, int h, int dx, int dy, } } +static Display *disp = NULL; +static GC gc = NULL; +static GC gcm = NULL; +static int last_depth = 0; + +void +__imlib_RenderDisconnect(Display * d) +{ + if (d != disp) + return; + disp = NULL; + gc = gcm = NULL; + last_depth = 0; +} + void __imlib_RenderImage(Display * d, ImlibImage * im, Drawable w, Drawable m, @@ -248,10 +263,6 @@ __imlib_RenderImage(Display * d, ImlibImage * im, Context *ct; DATA32 *buf = NULL, *pointer = NULL, *back = NULL; int y, h, hh, jump; - static Display *disp = NULL; - static int last_depth = 0; - static GC gc = 0; - static GC gcm = 0; XGCValues gcv; ImlibScaleInfo *scaleinfo = NULL; int psx, psy, psw, psh; diff --git a/src/lib/rend.h b/src/lib/rend.h index 061555f..c16fd46 100644 --- a/src/lib/rend.h +++ b/src/lib/rend.h @@ -6,6 +6,9 @@ __hidden DATA32 __imlib_RenderGetPixel(Display *d, Drawable w, Visual *v, Colormap cm, int depth, DATA8 r, DATA8 g, DATA8 b); +__hidden void +__imlib_RenderDisconnect(Display *d); + __hidden void __imlib_RenderImage(Display *d, ImlibImage *im, Drawable w, Drawable m,