summaryrefslogtreecommitdiff
path: root/src/graphics.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-02-08 22:09:07 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-02-09 23:47:51 +0100
commit32996cee607c52ecef9be4638df554dd89b39c24 (patch)
treeb3c9987ea39b52e46e5969f938c3aa9002a4bd4c /src/graphics.cpp
parent8aeb42b16430c85e4bc4052d881b8335d4a2ff36 (diff)
downloadmana-client-32996cee607c52ecef9be4638df554dd89b39c24.tar.gz
mana-client-32996cee607c52ecef9be4638df554dd89b39c24.tar.bz2
mana-client-32996cee607c52ecef9be4638df554dd89b39c24.tar.xz
mana-client-32996cee607c52ecef9be4638df554dd89b39c24.zip
Fixed wallpaper prescaling issues
Image::SDLgetScaledImage was changed so that it tries to find an existing scaled version of the image first, and generates it when none exists. When it needs to generate one, this resource is added to the resource manager, partly to avoid duplicating the work later but mainly to keep memory management straightforward. This function also used to leak the scaled SDL_Surface since it wrongly assumed that Image::load would free it. To avoid filling up the memory with scaled wallpapers that are waiting 30 seconds until they will be deleted, the Resource::decRef function was extended with a parameter that allows telling it what to do with orphans. Calling decRef with Resource::DeleteImmediately will delete the resource immediately in case the resource is orphaned. Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/graphics.cpp')
-rw-r--r--src/graphics.cpp50
1 files changed, 33 insertions, 17 deletions
diff --git a/src/graphics.cpp b/src/graphics.cpp
index dfdef349..7b56d974 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -161,14 +161,16 @@ bool Graphics::drawRescaledImage(Image *image, int srcX, int srcY,
bool useColor)
{
// Check that preconditions for blitting are met.
- if (!mTarget || !image) return false;
- if (!image->mSDLSurface) return false;
+ if (!mTarget || !image)
+ return false;
+ if (!image->mSDLSurface)
+ return false;
Image *tmpImage = image->SDLgetScaledImage(desiredWidth, desiredHeight);
bool returnValue = false;
- if (!tmpImage) return false;
- if (!tmpImage->mSDLSurface) return false;
+ if (!tmpImage)
+ return false;
dstX += mClipStack.top().xOffset;
dstY += mClipStack.top().yOffset;
@@ -183,9 +185,10 @@ bool Graphics::drawRescaledImage(Image *image, int srcX, int srcY,
srcRect.w = width;
srcRect.h = height;
- returnValue = !(SDL_BlitSurface(tmpImage->mSDLSurface, &srcRect, mTarget, &dstRect) < 0);
+ returnValue = !(SDL_BlitSurface(tmpImage->mSDLSurface, &srcRect,
+ mTarget, &dstRect) < 0);
- delete tmpImage;
+ tmpImage->decRef(Resource::DeleteImmediately);
return returnValue;
}
@@ -228,13 +231,16 @@ void Graphics::drawImage(gcn::Image const *image, int srcX, int srcY,
void Graphics::drawImagePattern(Image *image, int x, int y, int w, int h)
{
// Check that preconditions for blitting are met.
- if (!mTarget || !image) return;
- if (!image->mSDLSurface) return;
+ if (!mTarget || !image)
+ return;
+ if (!image->mSDLSurface)
+ return;
const int iw = image->getWidth();
const int ih = image->getHeight();
- if (iw == 0 || ih == 0) return;
+ if (iw == 0 || ih == 0)
+ return;
for (int py = 0; py < h; py += ih) // Y position on pattern plane
{
@@ -259,22 +265,32 @@ void Graphics::drawImagePattern(Image *image, int x, int y, int w, int h)
}
}
-void Graphics::drawRescaledImagePattern(Image *image, int x, int y,
- int w, int h, int scaledWidth, int scaledHeight)
+void Graphics::drawRescaledImagePattern(Image *image,
+ int x, int y,
+ int w, int h,
+ int scaledWidth, int scaledHeight)
{
// Check that preconditions for blitting are met.
- if (!mTarget || !image) return;
- if (!image->mSDLSurface) return;
+ if (!mTarget || !image)
+ return;
+ if (!image->mSDLSurface)
+ return;
- if (scaledHeight == 0 || scaledWidth == 0) return;
+ if (scaledHeight == 0 || scaledWidth == 0)
+ return;
Image *tmpImage = image->SDLgetScaledImage(scaledWidth, scaledHeight);
- if (!tmpImage) return;
+ if (!tmpImage)
+ return;
const int iw = tmpImage->getWidth();
const int ih = tmpImage->getHeight();
- if (iw == 0 || ih == 0) return;
+ if (iw == 0 || ih == 0)
+ {
+ tmpImage->decRef(Resource::DeleteImmediately);
+ return;
+ }
for (int py = 0; py < h; py += ih) // Y position on pattern plane
{
@@ -298,7 +314,7 @@ void Graphics::drawRescaledImagePattern(Image *image, int x, int y,
}
}
- delete tmpImage;
+ tmpImage->decRef(Resource::DeleteImmediately);
}
void Graphics::drawImageRect(int x, int y, int w, int h,