From b0cbb44580c5b15f9d388f77ddd0c944b56ec417 Mon Sep 17 00:00:00 2001 From: Roman Savochenko Date: Sat, 18 Nov 2023 21:50:44 +0200 Subject: [PATCH] KDesktop: No pointers to background images-pixmaps Signed-off-by: Roman Savochenko --- kdesktop/bgmanager.cpp | 86 ++++++++++++++++++--------------------- kdesktop/bgmanager.h | 13 +++--- kdesktop/pixmapserver.cpp | 22 +++------- kdesktop/pixmapserver.h | 4 +- 4 files changed, 54 insertions(+), 71 deletions(-) diff --git a/kdesktop/bgmanager.cpp b/kdesktop/bgmanager.cpp index 7e90e8fca..4299669c2 100644 --- a/kdesktop/bgmanager.cpp +++ b/kdesktop/bgmanager.cpp @@ -93,7 +93,7 @@ KBackgroundManager::KBackgroundManager(TQWidget *desktop, KWinModule* twinModule for (unsigned i=0; ipixmap = 0L; + m_Cache[i]->pixmap = KPixmap(); m_Cache[i]->hash = 0; m_Cache[i]->exp_from = -1; m_Renderer.insert (i, new KVirtualBGRenderer(i,m_pConfig)); @@ -102,8 +102,8 @@ KBackgroundManager::KBackgroundManager(TQWidget *desktop, KWinModule* twinModule } #ifdef COMPOSITE - m_tPixmap = new KPixmap(kapp->desktop()->size()); - m_tPixmap->fill(TQColor(0, 0x0)); + m_tPixmap = KPixmap(kapp->desktop()->size()); + m_tPixmap.fill(TQColor(0, 0x0)); connect(myApp, TQT_SIGNAL(cmBackgroundChanged( bool )), TQT_SLOT(slotCmBackgroundChanged( bool ))); #endif @@ -175,10 +175,7 @@ KBackgroundManager::~KBackgroundManager() return; for (unsigned i=0; ipixmap; delete m_Cache[i]; - } } @@ -334,7 +331,7 @@ void KBackgroundManager::slotChangeNumberOfDesktops(int num) for (int i=oldsz; ipixmap = 0L; + m_Cache[i]->pixmap = KPixmap(); m_Cache[i]->hash = 0; m_Cache[i]->exp_from = -1; 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 for (unsigned i=0; ipixmap) + if (m_Cache[i]->pixmap.isNull()) continue; if (m_Cache[i]->hash != m_Renderer[edesk]->hash()) continue; @@ -392,6 +389,7 @@ void KBackgroundManager::slotChangeDesktop(int desk) setPixmap(m_Cache[i]->pixmap, m_Cache[i]->hash, i); m_Cache[i]->atime = m_Serial; exportBackground(i, desk); + return; } @@ -443,7 +441,7 @@ void KBackgroundManager::slotChangeViewport(int desk, const TQPoint& viewport) // If we have the background already rendered: set it for (unsigned i=0; ipixmap) + if (m_Cache[i]->pixmap.isNull()) continue; if (m_Cache[i]->hash != m_Renderer[edesk]->hash()) continue; @@ -490,16 +488,16 @@ void KBackgroundManager::exportBackground(int pixmap, int desk) /* * 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 if (argb_visual && (KDesktopSettings::backgroundOpacity() < 100 || myApp->cmBackground())) { ep = m_tPixmap; - if (KDesktopSettings::backgroundOpacity() > 0 && pm + if (KDesktopSettings::backgroundOpacity() > 0 && !pm.isNull() && !myApp->cmBackground()) { XRenderPictFormat *format; @@ -514,13 +512,13 @@ void KBackgroundManager::setPixmap(KPixmap *pm, int hash, int desk) fillColor.alpha = color; Picture fill = XRenderCreateSolidFill (tqt_xdisplay(), &fillColor); - Picture src = XRenderCreatePicture(tqt_xdisplay(), pm->handle(), + Picture src = XRenderCreatePicture(tqt_xdisplay(), pm.handle(), format, 0, NULL); - Picture dst = XRenderCreatePicture(tqt_xdisplay(), ep->handle(), + Picture dst = XRenderCreatePicture(tqt_xdisplay(), ep.handle(), format, 0, NULL); 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(), src); @@ -536,7 +534,7 @@ void KBackgroundManager::setPixmap(KPixmap *pm, int hash, int desk) // Qt eats repaint events in this case :-(( sv->viewport()->update(); } - m_pDesktop->setErasePixmap(*ep); + m_pDesktop->setErasePixmap(ep); m_pDesktop->repaint(); static bool root_cleared = false; if( !root_cleared ) @@ -544,18 +542,18 @@ void KBackgroundManager::setPixmap(KPixmap *pm, int hash, int desk) root_cleared = true; TQTimer::singleShot( 0, this, TQT_SLOT( clearRoot())); // 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(); } } else { - TQT_TQWIDGET(TDEApplication::desktop()->screen())->setErasePixmap(*ep); + TQT_TQWIDGET(TDEApplication::desktop()->screen())->setErasePixmap(ep); TQT_TQWIDGET(TDEApplication::desktop()->screen())->erase(); } // 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; // don't set the ESETROOT_PMAP_ID property - that would result in possible XKillClient() @@ -605,15 +603,15 @@ void KBackgroundManager::slotCrossFadeTimeout() mAlpha = 1; m_crossTimer->stop(); KPixmap pixm(mNextScreen); - setPixmap(&pixm, r->hash(), fadeDesk); + setPixmap(pixm, r->hash(), fadeDesk); return; } // Reset Timer mBenchmark.start(); - TQPixmap dst = crossFade(*mOldScreen, mNextScreen, mAlpha, crossInit); + TQPixmap dst = crossFade(mOldScreen, mNextScreen, mAlpha, crossInit); KPixmap pixm(dst); - setPixmap(&pixm, r->hash(), fadeDesk); + setPixmap(pixm, r->hash(), fadeDesk); mAlpha -=0.03; crossInit = false; @@ -631,7 +629,7 @@ void KBackgroundManager::slotImageDone(int desk) m_numberOfViewports = 1; } - KPixmap *pm = new KPixmap(); + KPixmap pm = KPixmap(); KVirtualBGRenderer *r = m_Renderer[desk]; bool do_cleanup = true; fadeDesk = desk; @@ -639,7 +637,7 @@ void KBackgroundManager::slotImageDone(int desk) int width,height; - *pm = r->pixmap(); + pm = r->pixmap(); // If current: paint it bool current = (r->hash() == m_Renderer[effectiveDesktop()]->hash()); if (current) @@ -653,20 +651,22 @@ void KBackgroundManager::slotImageDone(int desk) if (mode == KBackgroundSettings::NoWallpaper || mode == KBackgroundSettings::Tiled || mode == KBackgroundSettings::CenterTiled ){ mNextScreen = TQPixmap(width,height); TQPainter p (&mNextScreen); - p.drawTiledPixmap(0,0,width,height,*pm); + p.drawTiledPixmap(0,0,width,height,pm); } else { - mNextScreen = TQPixmap(*pm); + mNextScreen = TQPixmap(pm); } + TQPixmap *mOldScreen_ = NULL; if (m_pDesktop){ - mOldScreen = const_cast( m_pDesktop->backgroundPixmap() ); + mOldScreen_ = const_cast( m_pDesktop->backgroundPixmap() ); }else{ - mOldScreen = const_cast( + mOldScreen_ = const_cast( TQApplication::desktop()->screen()->backgroundPixmap() ); } //TODO Find a way to discover if CrossFade effect needs to run - if (mOldScreen){ + if (mOldScreen_){ + mOldScreen = *mOldScreen_; crossInit = true; m_crossTimer->start(70); } else{ @@ -688,9 +688,6 @@ void KBackgroundManager::slotImageDone(int desk) if (m_bExport || !m_bCommon) { addCache(pm, r->hash(), desk); } - else { - delete pm; - } if (current) { exportBackground(desk, realDesktop()); @@ -717,9 +714,9 @@ void KBackgroundManager::saveImages() /* * 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; for (unsigned i=0; ipixmap) + if (!m_Cache[i]->pixmap.isNull()) total += pixmapSize(m_Cache[i]->pixmap); } return total; @@ -745,9 +742,7 @@ void KBackgroundManager::removeCache(int desk) { if (m_bExport) m_pPixmapServer->remove(KRootPixmap::pixmapName(desk+1)); - else - delete m_Cache[desk]->pixmap; - m_Cache[desk]->pixmap = 0L; + m_Cache[desk]->pixmap = KPixmap(); m_Cache[desk]->hash = 0; m_Cache[desk]->exp_from = -1; m_Cache[desk]->atime = 0; @@ -784,7 +779,7 @@ bool KBackgroundManager::freeCache(int size) min = m_Serial+1; j = 0; for (unsigned i=0; ipixmap && (m_Cache[i]->atime < min)) + if (!m_Cache[i]->pixmap.isNull() && (m_Cache[i]->atime < min)) { min = m_Cache[i]->atime; 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 * 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); if (m_bLimitCache && !m_bExport && !freeCache(pixmapSize(pm))) { // pixmap does not fit in cache - delete pm; return; } @@ -1024,10 +1018,8 @@ void KBackgroundManager::desktopResized() } #ifdef COMPOSITE - if (m_tPixmap) - delete m_tPixmap; - m_tPixmap = new KPixmap(kapp->desktop()->size()); - m_tPixmap->fill(TQColor(0, 0x0)); + m_tPixmap = KPixmap(kapp->desktop()->size()); + m_tPixmap.fill(TQColor(0, 0x0)); #endif m_Hash = 0; @@ -1100,7 +1092,7 @@ void KBackgroundManager::setBackgroundEnabled( const bool enable ) #ifdef COMPOSITE void KBackgroundManager::slotCmBackgroundChanged( bool ) { - m_tPixmap->fill(TQColor(0, 0x0)); + m_tPixmap.fill(TQColor(0, 0x0)); m_Hash = 0; slotChangeDesktop(0); } diff --git a/kdesktop/bgmanager.h b/kdesktop/bgmanager.h index 99d30a7bd..eeef1896f 100644 --- a/kdesktop/bgmanager.h +++ b/kdesktop/bgmanager.h @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -37,7 +38,7 @@ struct KBackgroundCacheEntry int hash; int atime; int exp_from; - KPixmap *pixmap; + KPixmap pixmap; }; @@ -105,12 +106,12 @@ private: void renderBackground(int desk); void exportBackground(int pixmap, int desk); - int pixmapSize(TQPixmap *pm); + int pixmapSize(const TQPixmap &pm); int cacheSize(); void removeCache(int desk); bool freeCache(int size); - void addCache(KPixmap *pm, int hash, int desk); - void setPixmap(KPixmap *pm, int hash, int desk); + void addCache(const KPixmap &pm, int hash, int desk); + void setPixmap(const KPixmap &pm, int hash, int desk); bool m_bExport, m_bCommon; bool m_bLimitCache, m_bInit; @@ -124,7 +125,7 @@ private: TQWidget *m_pDesktop; TQTimer *m_pTimer; - KPixmap *m_tPixmap; + KPixmap m_tPixmap; TQPtrVector m_Renderer; TQPtrVector m_Cache; @@ -138,7 +139,7 @@ private: TQTimer * m_crossTimer; double mAlpha; TQPixmap mNextScreen; - TQPixmap * mOldScreen; + TQPixmap mOldScreen; int fadeDesk; TQTime mBenchmark; bool crossInit; diff --git a/kdesktop/pixmapserver.cpp b/kdesktop/pixmapserver.cpp index 56224f37a..708c49129 100644 --- a/kdesktop/pixmapserver.cpp +++ b/kdesktop/pixmapserver.cpp @@ -49,14 +49,10 @@ KPixmapServer::~KPixmapServer() SelectionIterator it; for (it=m_Selections.begin(); it!=m_Selections.end(); it++) 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)) { @@ -68,23 +64,23 @@ void KPixmapServer::add(TQString name, TQPixmap *pm, bool overwrite) TQString str = TQString("KDESHPIXMAP:%1").arg(name); Atom sel = XInternAtom(tqt_xdisplay(), str.latin1(), false); KPixmapInode pi; - pi.handle = pm->handle(); + pi.handle = pm.handle(); pi.selection = sel; m_Names[name] = pi; TDESelectionInode si; si.name = name; - si.handle = pm->handle(); + si.handle = pm.handle(); m_Selections[sel] = si; - DataIterator it = m_Data.find(pm->handle()); + DataIterator it = m_Data.find(pm.handle()); if (it == m_Data.end()) { KPixmapData data; data.pixmap = pm; data.usecount = 0; data.refcount = 1; - m_Data[pm->handle()] = data; + m_Data[pm.handle()] = data; } else it.data().refcount++; @@ -111,11 +107,8 @@ void KPixmapServer::remove(TQString name) DataIterator it3 = m_Data.find(pi.handle); assert(it3 != m_Data.end()); it3.data().refcount--; - if (!it3.data().refcount && !it3.data().usecount) - { - delete it3.data().pixmap; + if (!it3.data().refcount && !it3.data().usecount) m_Data.remove(it3); - } } @@ -226,10 +219,7 @@ bool KPixmapServer::x11Event(XEvent *event) assert(it2 != m_Data.end()); it2.data().usecount--; if (!it2.data().usecount && !it2.data().refcount) - { - delete it2.data().pixmap; m_Data.remove(it2); - } return true; } diff --git a/kdesktop/pixmapserver.h b/kdesktop/pixmapserver.h index 661d531ad..6e5f03ffe 100644 --- a/kdesktop/pixmapserver.h +++ b/kdesktop/pixmapserver.h @@ -30,7 +30,7 @@ struct KPixmapInode struct KPixmapData { - TQPixmap *pixmap; + TQPixmap pixmap; int usecount; int refcount; }; @@ -70,7 +70,7 @@ public: * @param pm A pointer to the pixmap. * @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