Commit 2c810db3 authored by Andreas Hartmetz's avatar Andreas Hartmetz Committed by David Faure
Browse files

Fix pixmap leak when the tray icon changes (e.g. when it's animated).

This could easily leak 4KB/second of X pixmap memory.
All the actual difference comes from the QPixmap::ExplicitlyShared
argument, the rest is making some wonky-looking but working code look
less wonky.

BUG: 314919
(cherry picked from commit ec8e405c)
parent fbc7042a
......@@ -194,8 +194,7 @@ void X11EmbedContainer::paintEvent(QPaintEvent *event)
// Taking a detour via a QPixmap is unfortunately the only way we can get
// the window contents into Qt's backing store.
QPixmap pixmap(size());
pixmap = toX11Pixmap(pixmap);
QPixmap pixmap = toX11Pixmap(QPixmap(size()));
XRenderComposite(x11Info().display(), PictOpSrc, d->picture, None, pixmap.x11PictureHandle(),
0, 0, 0, 0, 0, 0, width(), height());
......@@ -232,16 +231,18 @@ void X11EmbedContainer::setBackgroundPixmap(QPixmap background)
// NOTE: The alpha-channel is not preserved if it exists, but for X pixmaps it generally should not be needed anyway.
QPixmap X11EmbedContainer::toX11Pixmap(const QPixmap& pix)
if(pix.handle() != 0) // X11 pixmap
if (pix.handle() != 0) // X11 pixmap
return pix;
QPixmap ret;
Pixmap xpix = XCreatePixmap(pix.x11Info().display(), RootWindow(pix.x11Info().display(), pix.x11Info().screen()),
pix.width(), pix.height(), QX11Info::appDepth());
QPixmap wrk = QPixmap::fromX11Pixmap(xpix);
QPainter paint(&wrk);
paint.drawPixmap(0, 0, pix);
QPixmap ret = wrk.copy();
wrk = QPixmap(); // reset, so that xpix can be freed (QPixmap does not own it)
QPixmap wrk = QPixmap::fromX11Pixmap(xpix, QPixmap::ExplicitlyShared);
QPainter paint(&wrk);
paint.drawPixmap(0, 0, pix);
ret = wrk.copy();
} // free resources so that xpix can be freed (QPixmap does not own it)
XFreePixmap(pix.x11Info().display(), xpix);
return ret;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment