aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Snover2017-10-16 00:20:39 -0500
committerColin Snover2017-10-16 00:27:34 -0500
commit4307156e1c384c4dd4f3c237f252be398061cb4d (patch)
treed0aa2b3e16a28dd1962f631473e28fba27c6b507
parent2e96e4d3df66fc0cd9dfa6f481bf4e31f1efc8e5 (diff)
downloadscummvm-rg350-4307156e1c384c4dd4f3c237f252be398061cb4d.tar.gz
scummvm-rg350-4307156e1c384c4dd4f3c237f252be398061cb4d.tar.bz2
scummvm-rg350-4307156e1c384c4dd4f3c237f252be398061cb4d.zip
SDL: Fix 32bpp cursor scaling in SDL1
The SDL1 loop is not very optimal. Unfortunately all our existing scalers only work in 16bpp and I don't have time to fix that right now, so this is fine.
-rw-r--r--backends/graphics/surfacesdl/surfacesdl-graphics.cpp53
1 files changed, 45 insertions, 8 deletions
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index bfc3f0f045..56579de74d 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -1968,8 +1968,50 @@ void SurfaceSdlGraphicsManager::blitCursor() {
sizeChanged = true;
}
- // 32bpp always blits directly, so no need to do any more work here
if (_cursorFormat.bytesPerPixel == 4) {
+ if (_mouseSurface != _mouseOrigSurface) {
+ SDL_FreeSurface(_mouseSurface);
+ }
+
+ if (cursorScale == 1) {
+ _mouseSurface = _mouseOrigSurface;
+ return;
+ }
+
+ SDL_PixelFormat *format = _mouseOrigSurface->format;
+ _mouseSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA,
+ rW, rH,
+ format->BitsPerPixel,
+ format->Rmask,
+ format->Gmask,
+ format->Bmask,
+ format->Amask);
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ SDL_BlitScaled(_mouseOrigSurface, nullptr, _mouseSurface, nullptr);
+#else
+ SDL_LockSurface(_mouseOrigSurface);
+ SDL_LockSurface(_mouseSurface);
+
+ const byte *src = (const byte *)_mouseOrigSurface->pixels;
+ byte *dst = (byte *)_mouseSurface->pixels;
+ for (int y = 0; y < _mouseOrigSurface->h; ++y) {
+ uint32 *rowDst = (uint32 *)dst;
+ for (int scaleY = 0; scaleY < cursorScale; ++scaleY) {
+ const uint32 *rowSrc = (const uint32 *)src;
+ for (int x = 0; x < _mouseOrigSurface->w; ++x) {
+ for (int scaleX = 0; scaleX < cursorScale; ++scaleX) {
+ *rowDst++ = *rowSrc;
+ }
+ ++rowSrc;
+ }
+ dst += _mouseSurface->pitch;
+ }
+ src += _mouseOrigSurface->pitch;
+ }
+
+ SDL_UnlockSurface(_mouseSurface);
+ SDL_UnlockSurface(_mouseOrigSurface);
+#endif
return;
}
@@ -2159,13 +2201,8 @@ void SurfaceSdlGraphicsManager::drawMouse() {
// Note that SDL_BlitSurface() and addDirtyRect() will both perform any
// clipping necessary
- if (_cursorFormat.bytesPerPixel == 4 && scale != 1) {
- if (SDL_BlitScaled(_mouseSurface, nullptr, _hwScreen, &dst) != 0)
- error("SDL_BlitScaled failed: %s", SDL_GetError());
- } else {
- if (SDL_BlitSurface(_mouseSurface, nullptr, _hwScreen, &dst) != 0)
- error("SDL_BlitSurface failed: %s", SDL_GetError());
- }
+ if (SDL_BlitSurface(_mouseSurface, nullptr, _hwScreen, &dst) != 0)
+ error("SDL_BlitSurface failed: %s", SDL_GetError());
// The screen will be updated using real surface coordinates, i.e.
// they will not be scaled or aspect-ratio corrected.