KDesktop: No pointers to background images-pixmaps

Signed-off-by: Roman Savochenko <roman@home.home>
feat/kdesktop
Roman Savochenko 6 months ago
parent a99f7a16ff
commit b0cbb44580

@ -93,7 +93,7 @@ KBackgroundManager::KBackgroundManager(TQWidget *desktop, KWinModule* twinModule
for (unsigned i=0; i<m_Renderer.size(); i++) for (unsigned i=0; i<m_Renderer.size(); i++)
{ {
m_Cache.insert(i, new KBackgroundCacheEntry); m_Cache.insert(i, new KBackgroundCacheEntry);
m_Cache[i]->pixmap = 0L; m_Cache[i]->pixmap = KPixmap();
m_Cache[i]->hash = 0; m_Cache[i]->hash = 0;
m_Cache[i]->exp_from = -1; m_Cache[i]->exp_from = -1;
m_Renderer.insert (i, new KVirtualBGRenderer(i,m_pConfig)); m_Renderer.insert (i, new KVirtualBGRenderer(i,m_pConfig));
@ -102,8 +102,8 @@ KBackgroundManager::KBackgroundManager(TQWidget *desktop, KWinModule* twinModule
} }
#ifdef COMPOSITE #ifdef COMPOSITE
m_tPixmap = new KPixmap(kapp->desktop()->size()); m_tPixmap = KPixmap(kapp->desktop()->size());
m_tPixmap->fill(TQColor(0, 0x0)); m_tPixmap.fill(TQColor(0, 0x0));
connect(myApp, TQT_SIGNAL(cmBackgroundChanged( bool )), connect(myApp, TQT_SIGNAL(cmBackgroundChanged( bool )),
TQT_SLOT(slotCmBackgroundChanged( bool ))); TQT_SLOT(slotCmBackgroundChanged( bool )));
#endif #endif
@ -175,10 +175,7 @@ KBackgroundManager::~KBackgroundManager()
return; return;
for (unsigned i=0; i<m_Cache.size(); i++) for (unsigned i=0; i<m_Cache.size(); i++)
{
delete m_Cache[i]->pixmap;
delete m_Cache[i]; delete m_Cache[i];
}
} }
@ -334,7 +331,7 @@ void KBackgroundManager::slotChangeNumberOfDesktops(int num)
for (int i=oldsz; i<num; i++) for (int i=oldsz; i<num; i++)
{ {
m_Cache.insert(i, new KBackgroundCacheEntry); m_Cache.insert(i, new KBackgroundCacheEntry);
m_Cache[i]->pixmap = 0L; m_Cache[i]->pixmap = KPixmap();
m_Cache[i]->hash = 0; m_Cache[i]->hash = 0;
m_Cache[i]->exp_from = -1; m_Cache[i]->exp_from = -1;
m_Renderer.insert(i, new KVirtualBGRenderer(i,m_pConfig)); m_Renderer.insert(i, new KVirtualBGRenderer(i,m_pConfig));
@ -382,7 +379,7 @@ void KBackgroundManager::slotChangeDesktop(int desk)
// If we have the background already rendered: set it // If we have the background already rendered: set it
for (unsigned i=0; i<m_Cache.size(); i++) for (unsigned i=0; i<m_Cache.size(); i++)
{ {
if (!m_Cache[i]->pixmap) if (m_Cache[i]->pixmap.isNull())
continue; continue;
if (m_Cache[i]->hash != m_Renderer[edesk]->hash()) if (m_Cache[i]->hash != m_Renderer[edesk]->hash())
continue; continue;
@ -392,6 +389,7 @@ void KBackgroundManager::slotChangeDesktop(int desk)
setPixmap(m_Cache[i]->pixmap, m_Cache[i]->hash, i); setPixmap(m_Cache[i]->pixmap, m_Cache[i]->hash, i);
m_Cache[i]->atime = m_Serial; m_Cache[i]->atime = m_Serial;
exportBackground(i, desk); exportBackground(i, desk);
return; return;
} }
@ -443,7 +441,7 @@ void KBackgroundManager::slotChangeViewport(int desk, const TQPoint& viewport)
// If we have the background already rendered: set it // If we have the background already rendered: set it
for (unsigned i=0; i<m_Cache.size(); i++) for (unsigned i=0; i<m_Cache.size(); i++)
{ {
if (!m_Cache[i]->pixmap) if (m_Cache[i]->pixmap.isNull())
continue; continue;
if (m_Cache[i]->hash != m_Renderer[edesk]->hash()) if (m_Cache[i]->hash != m_Renderer[edesk]->hash())
continue; continue;
@ -490,16 +488,16 @@ void KBackgroundManager::exportBackground(int pixmap, int desk)
/* /*
* Paint the pixmap to the root window. * Paint the pixmap to the root window.
*/ */
void KBackgroundManager::setPixmap(KPixmap *pm, int hash, int desk) void KBackgroundManager::setPixmap(const KPixmap &pm, int hash, int desk)
{ {
KPixmap *ep = pm; KPixmap ep = pm;
#ifdef COMPOSITE #ifdef COMPOSITE
if (argb_visual && (KDesktopSettings::backgroundOpacity() < 100 if (argb_visual && (KDesktopSettings::backgroundOpacity() < 100
|| myApp->cmBackground())) || myApp->cmBackground()))
{ {
ep = m_tPixmap; ep = m_tPixmap;
if (KDesktopSettings::backgroundOpacity() > 0 && pm if (KDesktopSettings::backgroundOpacity() > 0 && !pm.isNull()
&& !myApp->cmBackground()) && !myApp->cmBackground())
{ {
XRenderPictFormat *format; XRenderPictFormat *format;
@ -514,13 +512,13 @@ void KBackgroundManager::setPixmap(KPixmap *pm, int hash, int desk)
fillColor.alpha = color; fillColor.alpha = color;
Picture fill = XRenderCreateSolidFill (tqt_xdisplay(), &fillColor); Picture fill = XRenderCreateSolidFill (tqt_xdisplay(), &fillColor);
Picture src = XRenderCreatePicture(tqt_xdisplay(), pm->handle(), Picture src = XRenderCreatePicture(tqt_xdisplay(), pm.handle(),
format, 0, NULL); format, 0, NULL);
Picture dst = XRenderCreatePicture(tqt_xdisplay(), ep->handle(), Picture dst = XRenderCreatePicture(tqt_xdisplay(), ep.handle(),
format, 0, NULL); format, 0, NULL);
XRenderComposite (tqt_xdisplay(), PictOpSrc, src, fill, dst, 0, 0, 0, XRenderComposite (tqt_xdisplay(), PictOpSrc, src, fill, dst, 0, 0, 0,
0, 0, 0, pm->width(), pm->height()); 0, 0, 0, pm.width(), pm.height());
XRenderFreePicture (tqt_xdisplay(), fill); XRenderFreePicture (tqt_xdisplay(), fill);
XRenderFreePicture (tqt_xdisplay(), src); XRenderFreePicture (tqt_xdisplay(), src);
@ -536,7 +534,7 @@ void KBackgroundManager::setPixmap(KPixmap *pm, int hash, int desk)
// Qt eats repaint events in this case :-(( // Qt eats repaint events in this case :-((
sv->viewport()->update(); sv->viewport()->update();
} }
m_pDesktop->setErasePixmap(*ep); m_pDesktop->setErasePixmap(ep);
m_pDesktop->repaint(); m_pDesktop->repaint();
static bool root_cleared = false; static bool root_cleared = false;
if( !root_cleared ) if( !root_cleared )
@ -544,18 +542,18 @@ void KBackgroundManager::setPixmap(KPixmap *pm, int hash, int desk)
root_cleared = true; root_cleared = true;
TQTimer::singleShot( 0, this, TQT_SLOT( clearRoot())); TQTimer::singleShot( 0, this, TQT_SLOT( clearRoot()));
// but make the pixmap visible until m_pDesktop is visible // but make the pixmap visible until m_pDesktop is visible
TQT_TQWIDGET(TDEApplication::desktop()->screen())->setErasePixmap(*ep); TQT_TQWIDGET(TDEApplication::desktop()->screen())->setErasePixmap(ep);
TQT_TQWIDGET(TDEApplication::desktop()->screen())->erase(); TQT_TQWIDGET(TDEApplication::desktop()->screen())->erase();
} }
} }
else else
{ {
TQT_TQWIDGET(TDEApplication::desktop()->screen())->setErasePixmap(*ep); TQT_TQWIDGET(TDEApplication::desktop()->screen())->setErasePixmap(ep);
TQT_TQWIDGET(TDEApplication::desktop()->screen())->erase(); TQT_TQWIDGET(TDEApplication::desktop()->screen())->erase();
} }
// and export it via Esetroot-style for gnome/GTK apps to share in the pretties // and export it via Esetroot-style for gnome/GTK apps to share in the pretties
Pixmap bgPm = pm->handle(); // fetch the actual X handle to it Pixmap bgPm = pm.handle(); // fetch the actual X handle to it
//kdDebug() << "Esetroot compat: setting pixmap to " << bgPm << endl; //kdDebug() << "Esetroot compat: setting pixmap to " << bgPm << endl;
// don't set the ESETROOT_PMAP_ID property - that would result in possible XKillClient() // don't set the ESETROOT_PMAP_ID property - that would result in possible XKillClient()
@ -605,15 +603,15 @@ void KBackgroundManager::slotCrossFadeTimeout()
mAlpha = 1; mAlpha = 1;
m_crossTimer->stop(); m_crossTimer->stop();
KPixmap pixm(mNextScreen); KPixmap pixm(mNextScreen);
setPixmap(&pixm, r->hash(), fadeDesk); setPixmap(pixm, r->hash(), fadeDesk);
return; return;
} }
// Reset Timer // Reset Timer
mBenchmark.start(); mBenchmark.start();
TQPixmap dst = crossFade(*mOldScreen, mNextScreen, mAlpha, crossInit); TQPixmap dst = crossFade(mOldScreen, mNextScreen, mAlpha, crossInit);
KPixmap pixm(dst); KPixmap pixm(dst);
setPixmap(&pixm, r->hash(), fadeDesk); setPixmap(pixm, r->hash(), fadeDesk);
mAlpha -=0.03; mAlpha -=0.03;
crossInit = false; crossInit = false;
@ -631,7 +629,7 @@ void KBackgroundManager::slotImageDone(int desk)
m_numberOfViewports = 1; m_numberOfViewports = 1;
} }
KPixmap *pm = new KPixmap(); KPixmap pm = KPixmap();
KVirtualBGRenderer *r = m_Renderer[desk]; KVirtualBGRenderer *r = m_Renderer[desk];
bool do_cleanup = true; bool do_cleanup = true;
fadeDesk = desk; fadeDesk = desk;
@ -639,7 +637,7 @@ void KBackgroundManager::slotImageDone(int desk)
int width,height; int width,height;
*pm = r->pixmap(); pm = r->pixmap();
// If current: paint it // If current: paint it
bool current = (r->hash() == m_Renderer[effectiveDesktop()]->hash()); bool current = (r->hash() == m_Renderer[effectiveDesktop()]->hash());
if (current) if (current)
@ -653,20 +651,22 @@ void KBackgroundManager::slotImageDone(int desk)
if (mode == KBackgroundSettings::NoWallpaper || mode == KBackgroundSettings::Tiled || mode == KBackgroundSettings::CenterTiled ){ if (mode == KBackgroundSettings::NoWallpaper || mode == KBackgroundSettings::Tiled || mode == KBackgroundSettings::CenterTiled ){
mNextScreen = TQPixmap(width,height); mNextScreen = TQPixmap(width,height);
TQPainter p (&mNextScreen); TQPainter p (&mNextScreen);
p.drawTiledPixmap(0,0,width,height,*pm); p.drawTiledPixmap(0,0,width,height,pm);
} else { } else {
mNextScreen = TQPixmap(*pm); mNextScreen = TQPixmap(pm);
} }
TQPixmap *mOldScreen_ = NULL;
if (m_pDesktop){ if (m_pDesktop){
mOldScreen = const_cast<TQPixmap *>( m_pDesktop->backgroundPixmap() ); mOldScreen_ = const_cast<TQPixmap *>( m_pDesktop->backgroundPixmap() );
}else{ }else{
mOldScreen = const_cast<TQPixmap *>( mOldScreen_ = const_cast<TQPixmap *>(
TQApplication::desktop()->screen()->backgroundPixmap() ); TQApplication::desktop()->screen()->backgroundPixmap() );
} }
//TODO Find a way to discover if CrossFade effect needs to run //TODO Find a way to discover if CrossFade effect needs to run
if (mOldScreen){ if (mOldScreen_){
mOldScreen = *mOldScreen_;
crossInit = true; crossInit = true;
m_crossTimer->start(70); m_crossTimer->start(70);
} else{ } else{
@ -688,9 +688,6 @@ void KBackgroundManager::slotImageDone(int desk)
if (m_bExport || !m_bCommon) { if (m_bExport || !m_bCommon) {
addCache(pm, r->hash(), desk); addCache(pm, r->hash(), desk);
} }
else {
delete pm;
}
if (current) { if (current) {
exportBackground(desk, realDesktop()); exportBackground(desk, realDesktop());
@ -717,9 +714,9 @@ void KBackgroundManager::saveImages()
/* /*
* Size in bytes of a TQPixmap. For use in the pixmap cache. * Size in bytes of a TQPixmap. For use in the pixmap cache.
*/ */
int KBackgroundManager::pixmapSize(TQPixmap *pm) int KBackgroundManager::pixmapSize(const TQPixmap &pm)
{ {
return (pm->width() * pm->height()) * ((pm->depth() + 7) / 8); return (pm.width() * pm.height()) * ((pm.depth() + 7) / 8);
} }
@ -731,7 +728,7 @@ int KBackgroundManager::cacheSize()
int total = 0; int total = 0;
for (unsigned i=0; i<m_Cache.size(); i++) for (unsigned i=0; i<m_Cache.size(); i++)
{ {
if (m_Cache[i]->pixmap) if (!m_Cache[i]->pixmap.isNull())
total += pixmapSize(m_Cache[i]->pixmap); total += pixmapSize(m_Cache[i]->pixmap);
} }
return total; return total;
@ -745,9 +742,7 @@ void KBackgroundManager::removeCache(int desk)
{ {
if (m_bExport) if (m_bExport)
m_pPixmapServer->remove(KRootPixmap::pixmapName(desk+1)); m_pPixmapServer->remove(KRootPixmap::pixmapName(desk+1));
else m_Cache[desk]->pixmap = KPixmap();
delete m_Cache[desk]->pixmap;
m_Cache[desk]->pixmap = 0L;
m_Cache[desk]->hash = 0; m_Cache[desk]->hash = 0;
m_Cache[desk]->exp_from = -1; m_Cache[desk]->exp_from = -1;
m_Cache[desk]->atime = 0; m_Cache[desk]->atime = 0;
@ -784,7 +779,7 @@ bool KBackgroundManager::freeCache(int size)
min = m_Serial+1; j = 0; min = m_Serial+1; j = 0;
for (unsigned i=0; i<m_Cache.size(); i++) for (unsigned i=0; i<m_Cache.size(); i++)
{ {
if (m_Cache[i]->pixmap && (m_Cache[i]->atime < min)) if (!m_Cache[i]->pixmap.isNull() && (m_Cache[i]->atime < min))
{ {
min = m_Cache[i]->atime; min = m_Cache[i]->atime;
j = i; j = i;
@ -800,15 +795,14 @@ bool KBackgroundManager::freeCache(int size)
* Try to add a pixmap to the pixmap cache. We don't use TQPixmapCache here * Try to add a pixmap to the pixmap cache. We don't use TQPixmapCache here
* because if we're exporting pixmaps, this needs special care. * because if we're exporting pixmaps, this needs special care.
*/ */
void KBackgroundManager::addCache(KPixmap *pm, int hash, int desk) void KBackgroundManager::addCache(const KPixmap &pm, int hash, int desk)
{ {
if (m_Cache[desk]->pixmap) if (!m_Cache[desk]->pixmap.isNull())
removeCache(desk); removeCache(desk);
if (m_bLimitCache && !m_bExport && !freeCache(pixmapSize(pm))) if (m_bLimitCache && !m_bExport && !freeCache(pixmapSize(pm)))
{ {
// pixmap does not fit in cache // pixmap does not fit in cache
delete pm;
return; return;
} }
@ -1024,10 +1018,8 @@ void KBackgroundManager::desktopResized()
} }
#ifdef COMPOSITE #ifdef COMPOSITE
if (m_tPixmap) m_tPixmap = KPixmap(kapp->desktop()->size());
delete m_tPixmap; m_tPixmap.fill(TQColor(0, 0x0));
m_tPixmap = new KPixmap(kapp->desktop()->size());
m_tPixmap->fill(TQColor(0, 0x0));
#endif #endif
m_Hash = 0; m_Hash = 0;
@ -1100,7 +1092,7 @@ void KBackgroundManager::setBackgroundEnabled( const bool enable )
#ifdef COMPOSITE #ifdef COMPOSITE
void KBackgroundManager::slotCmBackgroundChanged( bool ) void KBackgroundManager::slotCmBackgroundChanged( bool )
{ {
m_tPixmap->fill(TQColor(0, 0x0)); m_tPixmap.fill(TQColor(0, 0x0));
m_Hash = 0; m_Hash = 0;
slotChangeDesktop(0); slotChangeDesktop(0);
} }

@ -12,6 +12,7 @@
#include <tqstring.h> #include <tqstring.h>
#include <tqptrvector.h> #include <tqptrvector.h>
#include <kpixmap.h>
#include <tqdatetime.h> #include <tqdatetime.h>
#include <KBackgroundIface.h> #include <KBackgroundIface.h>
@ -37,7 +38,7 @@ struct KBackgroundCacheEntry
int hash; int hash;
int atime; int atime;
int exp_from; int exp_from;
KPixmap *pixmap; KPixmap pixmap;
}; };
@ -105,12 +106,12 @@ private:
void renderBackground(int desk); void renderBackground(int desk);
void exportBackground(int pixmap, int desk); void exportBackground(int pixmap, int desk);
int pixmapSize(TQPixmap *pm); int pixmapSize(const TQPixmap &pm);
int cacheSize(); int cacheSize();
void removeCache(int desk); void removeCache(int desk);
bool freeCache(int size); bool freeCache(int size);
void addCache(KPixmap *pm, int hash, int desk); void addCache(const KPixmap &pm, int hash, int desk);
void setPixmap(KPixmap *pm, int hash, int desk); void setPixmap(const KPixmap &pm, int hash, int desk);
bool m_bExport, m_bCommon; bool m_bExport, m_bCommon;
bool m_bLimitCache, m_bInit; bool m_bLimitCache, m_bInit;
@ -124,7 +125,7 @@ private:
TQWidget *m_pDesktop; TQWidget *m_pDesktop;
TQTimer *m_pTimer; TQTimer *m_pTimer;
KPixmap *m_tPixmap; KPixmap m_tPixmap;
TQPtrVector<KVirtualBGRenderer> m_Renderer; TQPtrVector<KVirtualBGRenderer> m_Renderer;
TQPtrVector<KBackgroundCacheEntry> m_Cache; TQPtrVector<KBackgroundCacheEntry> m_Cache;
@ -138,7 +139,7 @@ private:
TQTimer * m_crossTimer; TQTimer * m_crossTimer;
double mAlpha; double mAlpha;
TQPixmap mNextScreen; TQPixmap mNextScreen;
TQPixmap * mOldScreen; TQPixmap mOldScreen;
int fadeDesk; int fadeDesk;
TQTime mBenchmark; TQTime mBenchmark;
bool crossInit; bool crossInit;

@ -49,14 +49,10 @@ KPixmapServer::~KPixmapServer()
SelectionIterator it; SelectionIterator it;
for (it=m_Selections.begin(); it!=m_Selections.end(); it++) for (it=m_Selections.begin(); it!=m_Selections.end(); it++)
XSetSelectionOwner(tqt_xdisplay(), it.key(), None, CurrentTime); XSetSelectionOwner(tqt_xdisplay(), it.key(), None, CurrentTime);
DataIterator it2;
for (it2=m_Data.begin(); it2!=m_Data.end(); it2++)
delete it2.data().pixmap;
} }
void KPixmapServer::add(TQString name, TQPixmap *pm, bool overwrite) void KPixmapServer::add(TQString name, const TQPixmap &pm, bool overwrite)
{ {
if (m_Names.contains(name)) if (m_Names.contains(name))
{ {
@ -68,23 +64,23 @@ void KPixmapServer::add(TQString name, TQPixmap *pm, bool overwrite)
TQString str = TQString("KDESHPIXMAP:%1").arg(name); TQString str = TQString("KDESHPIXMAP:%1").arg(name);
Atom sel = XInternAtom(tqt_xdisplay(), str.latin1(), false); Atom sel = XInternAtom(tqt_xdisplay(), str.latin1(), false);
KPixmapInode pi; KPixmapInode pi;
pi.handle = pm->handle(); pi.handle = pm.handle();
pi.selection = sel; pi.selection = sel;
m_Names[name] = pi; m_Names[name] = pi;
TDESelectionInode si; TDESelectionInode si;
si.name = name; si.name = name;
si.handle = pm->handle(); si.handle = pm.handle();
m_Selections[sel] = si; m_Selections[sel] = si;
DataIterator it = m_Data.find(pm->handle()); DataIterator it = m_Data.find(pm.handle());
if (it == m_Data.end()) if (it == m_Data.end())
{ {
KPixmapData data; KPixmapData data;
data.pixmap = pm; data.pixmap = pm;
data.usecount = 0; data.usecount = 0;
data.refcount = 1; data.refcount = 1;
m_Data[pm->handle()] = data; m_Data[pm.handle()] = data;
} else } else
it.data().refcount++; it.data().refcount++;
@ -111,11 +107,8 @@ void KPixmapServer::remove(TQString name)
DataIterator it3 = m_Data.find(pi.handle); DataIterator it3 = m_Data.find(pi.handle);
assert(it3 != m_Data.end()); assert(it3 != m_Data.end());
it3.data().refcount--; it3.data().refcount--;
if (!it3.data().refcount && !it3.data().usecount) if (!it3.data().refcount && !it3.data().usecount)
{
delete it3.data().pixmap;
m_Data.remove(it3); m_Data.remove(it3);
}
} }
@ -226,10 +219,7 @@ bool KPixmapServer::x11Event(XEvent *event)
assert(it2 != m_Data.end()); assert(it2 != m_Data.end());
it2.data().usecount--; it2.data().usecount--;
if (!it2.data().usecount && !it2.data().refcount) if (!it2.data().usecount && !it2.data().refcount)
{
delete it2.data().pixmap;
m_Data.remove(it2); m_Data.remove(it2);
}
return true; return true;
} }

@ -30,7 +30,7 @@ struct KPixmapInode
struct KPixmapData struct KPixmapData
{ {
TQPixmap *pixmap; TQPixmap pixmap;
int usecount; int usecount;
int refcount; int refcount;
}; };
@ -70,7 +70,7 @@ public:
* @param pm A pointer to the pixmap. * @param pm A pointer to the pixmap.
* @param overwrite Should an pixmap with the same name be overwritten? * @param overwrite Should an pixmap with the same name be overwritten?
*/ */
void add(TQString name, TQPixmap *pm, bool overwrite=true); void add(TQString name, const TQPixmap &pm, bool overwrite=true);
/** /**
* Remove a pixmap from the server. This will delete the pixmap after * Remove a pixmap from the server. This will delete the pixmap after

Loading…
Cancel
Save