[Scummvm-git-logs] scummvm branch-2-7 -> 6ca196d93267672cfa373fd01b52bb6052865b21

criezy noreply at scummvm.org
Mon Mar 6 22:18:42 UTC 2023


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
fabca2edd5 SDL: Fix shaking with SDL1 and negative offsets
6ca196d932 SDL: Fix incorrect handling of dirty rect with negative shake offset in SDL1


Commit: fabca2edd535a8b183d2e7a1aab56536d59ed202
    https://github.com/scummvm/scummvm/commit/fabca2edd535a8b183d2e7a1aab56536d59ed202
Author: Vladimir Serbinenko (phcoder at gmail.com)
Date: 2023-03-06T22:18:14Z

Commit Message:
SDL: Fix shaking with SDL1 and negative offsets

Current code results in a crash

Changed paths:
    backends/graphics/surfacesdl/surfacesdl-graphics.cpp


diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index 7d51aa11f3b..7953588ca02 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -1171,10 +1171,18 @@ void SurfaceSdlGraphicsManager::internUpdateScreen() {
 	// so this isn't needed there.
 	if (_currentShakeXOffset != _gameScreenShakeXOffset ||
 		(_cursorNeedsRedraw && _mouseLastRect.x <= _currentShakeXOffset)) {
-		SDL_Rect blackrect = {0, 0, (Uint16)(_gameScreenShakeXOffset * _videoMode.scaleFactor), (Uint16)(_videoMode.screenHeight * _videoMode.scaleFactor)};
+		SDL_Rect blackrect = {0, 0, (Uint16)(_videoMode.screenWidth * _videoMode.scaleFactor), (Uint16)(_videoMode.screenHeight * _videoMode.scaleFactor)};
 
-		if (_videoMode.aspectRatioCorrection && !_overlayInGUI)
+		if (_gameScreenShakeXOffset >= 0)
+			blackrect.w = (Uint16)(_gameScreenShakeXOffset * _videoMode.scaleFactor);
+		else {
+			blackrect.w = ((-_gameScreenShakeXOffset) * _videoMode.scaleFactor);
+			blackrect.x = ((_videoMode.screenWidth + _gameScreenShakeXOffset) * _videoMode.scaleFactor);
+		}
+
+		if (_videoMode.aspectRatioCorrection && !_overlayInGUI) {
 			blackrect.h = real2Aspect(blackrect.h - 1) + 1;
+		}
 
 		SDL_FillRect(_hwScreen, &blackrect, 0);
 
@@ -1184,10 +1192,19 @@ void SurfaceSdlGraphicsManager::internUpdateScreen() {
 	}
 	if (_currentShakeYOffset != _gameScreenShakeYOffset ||
 		(_cursorNeedsRedraw && _mouseLastRect.y <= _currentShakeYOffset)) {
-		SDL_Rect blackrect = {0, 0, (Uint16)(_videoMode.screenWidth * _videoMode.scaleFactor), (Uint16)(_gameScreenShakeYOffset * _videoMode.scaleFactor)};
+		SDL_Rect blackrect = {0, 0, (Uint16)(_videoMode.screenWidth * _videoMode.scaleFactor), (Uint16)(_videoMode.screenHeight * _videoMode.scaleFactor)};
 
-		if (_videoMode.aspectRatioCorrection && !_overlayInGUI)
-			blackrect.h = real2Aspect(blackrect.h - 1) + 1;
+		if (_gameScreenShakeYOffset >= 0)
+			blackrect.h = (Uint16)(_gameScreenShakeYOffset * _videoMode.scaleFactor);
+		else {
+			blackrect.h = ((-_gameScreenShakeYOffset) * _videoMode.scaleFactor);
+			blackrect.y = ((_videoMode.screenHeight + _gameScreenShakeYOffset) * _videoMode.scaleFactor);
+		}
+
+		if (_videoMode.aspectRatioCorrection && !_overlayInGUI) {
+			blackrect.y = real2Aspect(blackrect.y);
+			blackrect.h = real2Aspect(blackrect.h + blackrect.y - 1) - blackrect.y + 1;
+		}
 
 		SDL_FillRect(_hwScreen, &blackrect, 0);
 
@@ -1310,22 +1327,37 @@ void SurfaceSdlGraphicsManager::internUpdateScreen() {
 		dstPitch = _hwScreen->pitch;
 
 		for (r = _dirtyRectList; r != lastRect; ++r) {
-			int dst_x = r->x + _currentShakeXOffset;
-			int dst_y = r->y + _currentShakeYOffset;
+			int src_x = r->x;
+			int src_y = r->y;
+			int dst_x = r->x;
+			int dst_y = r->y;
 			int dst_w = 0;
 			int dst_h = 0;
 #ifdef USE_ASPECT
 			int orig_dst_y = 0;
 #endif
+			if (_currentShakeXOffset >= 0)
+				dst_x += _currentShakeXOffset;
+			else
+				src_x += -_currentShakeXOffset;
+
+			if (_currentShakeYOffset >= 0)
+				dst_y += _currentShakeYOffset;
+			else
+				src_y += -_currentShakeYOffset;
 
 			if (dst_x < width && dst_y < height) {
 				dst_w = r->w;
 				if (dst_w > width - dst_x)
 					dst_w = width - dst_x;
+				if (dst_w > width - src_x)
+					dst_w = width - src_x;
 
 				dst_h = r->h;
 				if (dst_h > height - dst_y)
 					dst_h = height - dst_y;
+				if (dst_h > height - src_y)
+					dst_h = height - src_y;
 
 #ifdef USE_ASPECT
 				orig_dst_y = dst_y;
@@ -1336,8 +1368,8 @@ void SurfaceSdlGraphicsManager::internUpdateScreen() {
 				if (_videoMode.aspectRatioCorrection && !_overlayInGUI)
 					dst_y = real2Aspect(dst_y);
 
-				_scaler->scale((byte *)srcSurf->pixels + (r->x + _maxExtraPixels) * bpp + (r->y + _maxExtraPixels) * srcPitch, srcPitch,
-					(byte *)_hwScreen->pixels + dst_x * bpp + dst_y * dstPitch, dstPitch, dst_w, dst_h, r->x, r->y);
+				_scaler->scale((byte *)srcSurf->pixels + (src_x + _maxExtraPixels) * bpp + (src_y + _maxExtraPixels) * srcPitch, srcPitch,
+					(byte *)_hwScreen->pixels + dst_x * bpp + dst_y * dstPitch, dstPitch, dst_w, dst_h, src_x, src_y);
 			}
 
 			r->x = dst_x;


Commit: 6ca196d93267672cfa373fd01b52bb6052865b21
    https://github.com/scummvm/scummvm/commit/6ca196d93267672cfa373fd01b52bb6052865b21
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2023-03-06T22:18:26Z

Commit Message:
SDL: Fix incorrect handling of dirty rect with negative shake offset in SDL1

Instead of shifting the destination to the left, if was moving the source to
the right, which had the effect of shifting the dirty rect. So part of the
surface that should have been copied to the screen was not, and instead it
was copying part of the surface that did not need to be copied.

Changed paths:
    backends/graphics/surfacesdl/surfacesdl-graphics.cpp


diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index 7953588ca02..0256b2d8436 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -1331,29 +1331,31 @@ void SurfaceSdlGraphicsManager::internUpdateScreen() {
 			int src_y = r->y;
 			int dst_x = r->x;
 			int dst_y = r->y;
-			int dst_w = 0;
-			int dst_h = 0;
+			int dst_w = r->w;
+			int dst_h = r->h;
 #ifdef USE_ASPECT
 			int orig_dst_y = 0;
 #endif
-			if (_currentShakeXOffset >= 0)
-				dst_x += _currentShakeXOffset;
-			else
-				src_x += -_currentShakeXOffset;
+			dst_x += _currentShakeXOffset;
+			if (dst_x < 0) {
+				src_x -= dst_x;
+				dst_w += dst_x;
+				dst_x = 0;
+			}
 
-			if (_currentShakeYOffset >= 0)
-				dst_y += _currentShakeYOffset;
-			else
-				src_y += -_currentShakeYOffset;
+			dst_y += _currentShakeYOffset;
+			if (dst_y < 0) {
+				src_y -= dst_y;
+				dst_h += dst_y;
+				dst_y = 0;
+			}
 
-			if (dst_x < width && dst_y < height) {
-				dst_w = r->w;
+			if (dst_x < width && dst_y < height && dst_w > 0 && dst_h > 0) {
 				if (dst_w > width - dst_x)
 					dst_w = width - dst_x;
 				if (dst_w > width - src_x)
 					dst_w = width - src_x;
 
-				dst_h = r->h;
 				if (dst_h > height - dst_y)
 					dst_h = height - dst_y;
 				if (dst_h > height - src_y)
@@ -1369,17 +1371,17 @@ void SurfaceSdlGraphicsManager::internUpdateScreen() {
 					dst_y = real2Aspect(dst_y);
 
 				_scaler->scale((byte *)srcSurf->pixels + (src_x + _maxExtraPixels) * bpp + (src_y + _maxExtraPixels) * srcPitch, srcPitch,
-					(byte *)_hwScreen->pixels + dst_x * bpp + dst_y * dstPitch, dstPitch, dst_w, dst_h, src_x, src_y);
-			}
+						(byte *)_hwScreen->pixels + dst_x * bpp + dst_y * dstPitch, dstPitch, dst_w, dst_h, src_x, src_y);
 
-			r->x = dst_x;
-			r->y = dst_y;
-			r->w = dst_w * scale1;
-			r->h = dst_h * scale1;
+				r->x = dst_x;
+				r->y = dst_y;
+				r->w = dst_w * scale1;
+				r->h = dst_h * scale1;
 
 #ifdef USE_ASPECT
-			if (_videoMode.aspectRatioCorrection && orig_dst_y < height && !_overlayInGUI)
-				r->h = stretch200To240((uint8 *) _hwScreen->pixels, dstPitch, r->w, r->h, r->x, r->y, orig_dst_y * scale1, _videoMode.filtering, convertSDLPixelFormat(_hwScreen->format));
+				if (_videoMode.aspectRatioCorrection && orig_dst_y < height && !_overlayInGUI)
+					r->h = stretch200To240((uint8 *) _hwScreen->pixels, dstPitch, r->w, r->h, r->x, r->y, orig_dst_y * scale1, _videoMode.filtering, 	convertSDLPixelFormat(_hwScreen->format));
+			}
 #endif
 		}
 		SDL_UnlockSurface(srcSurf);




More information about the Scummvm-git-logs mailing list