summaryrefslogtreecommitdiff
path: root/src/gui/widgets/desktop.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets/desktop.cpp')
-rw-r--r--src/gui/widgets/desktop.cpp43
1 files changed, 26 insertions, 17 deletions
diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp
index bf833898..baf3e951 100644
--- a/src/gui/widgets/desktop.cpp
+++ b/src/gui/widgets/desktop.cpp
@@ -105,30 +105,39 @@ void Desktop::draw(gcn::Graphics *graphics)
void Desktop::setBestFittingWallpaper()
{
- const std::string wallpaperName =
- Wallpaper::getWallpaper(getWidth(), getHeight());
+ const int width = getWidth();
+ const int height = getHeight();
- Image *nWallPaper = ResourceManager::getInstance()->getImage(wallpaperName);
+ if (width == 0 || height == 0)
+ return;
- if (nWallPaper)
+ const std::string wallpaperName = Wallpaper::getWallpaper(width, height);
+
+ if (wallpaperName.empty())
+ return;
+
+ ResourceManager *resman = ResourceManager::getInstance();
+ Image *wallpaper = resman->getImage(wallpaperName);
+
+ if (wallpaper)
{
if (mWallpaper)
- mWallpaper->decRef();
+ mWallpaper->decRef(Resource::DeleteImmediately);
+
+ mWallpaper = wallpaper;
- if (!nWallPaper->useOpenGL() && (nWallPaper->getWidth() != getWidth()
- || nWallPaper->getHeight() != getHeight()))
+ // In software mode we try to prescale the image for performance
+ if (!wallpaper->useOpenGL() &&
+ (wallpaper->getWidth() != width ||
+ wallpaper->getHeight() != height))
{
- // We rescale to obtain a fullscreen wallpaper...
- Image *newRsclWlPpr = nWallPaper->SDLgetScaledImage(getWidth(), getHeight());
- std::string idPath = nWallPaper->getIdPath();
-
- // We replace the resource in the resource manager
- nWallPaper->decRef();
- ResourceManager::getInstance()->addResource(idPath, newRsclWlPpr);
- mWallpaper = newRsclWlPpr;
+ if (Image *prescaled = wallpaper->SDLgetScaledImage(width, height))
+ {
+ // Make sure the original can be freed
+ wallpaper->decRef();
+ mWallpaper = prescaled;
+ }
}
- else
- mWallpaper = nWallPaper;
}
else
{