[Scummvm-git-logs] scummvm master -> ee38b13fd32a3804513ece43fdb77ac5844e60fa

sev- noreply at scummvm.org
Sat Nov 18 23:02:02 UTC 2023


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

Summary:
ee38b13fd3 AGS: Disable optimized blit stretching and flipping


Commit: ee38b13fd32a3804513ece43fdb77ac5844e60fa
    https://github.com/scummvm/scummvm/commit/ee38b13fd32a3804513ece43fdb77ac5844e60fa
Author: Kaloyan Chehlarski (strahy at outlook.com)
Date: 2023-11-19T00:01:58+01:00

Commit Message:
AGS: Disable optimized blit stretching and flipping

The CPU extension optimized paths do not work properly
when scaling or flipping the image. Fixing this needs a lot
of work, so for now we pre-stretch and pre-flip as a
workaround.

Changed paths:
    engines/ags/lib/allegro/surface.cpp


diff --git a/engines/ags/lib/allegro/surface.cpp b/engines/ags/lib/allegro/surface.cpp
index 3e8fb3aedae..57b189b6083 100644
--- a/engines/ags/lib/allegro/surface.cpp
+++ b/engines/ags/lib/allegro/surface.cpp
@@ -174,7 +174,24 @@ void BITMAP::draw(const BITMAP *srcBitmap, const Common::Rect &srcRect,
 	assert(format.bytesPerPixel == 2 || format.bytesPerPixel == 4 ||
 	       (format.bytesPerPixel == 1 && srcBitmap->format.bytesPerPixel == 1));
 
-	auto args = DrawInnerArgs(this, srcBitmap, srcRect, Common::Rect(dstX, dstY, dstX+1, dstY+1), skipTrans, srcAlpha, horizFlip, vertFlip, tintRed, tintGreen, tintBlue, false);
+	Graphics::ManagedSurface flipped;
+	if (horizFlip || vertFlip) {
+		// Horizontal flipping produces errors in the optimized paths, while vertical
+		// may result in crashes. For now, we pre-flip to a temporary surface
+		Graphics::ManagedSurface cropped(const_cast<BITMAP *>(srcBitmap)->getSurface(), srcRect);
+		flipped.copyFrom(cropped);
+
+		if (horizFlip) {
+			flipped.surfacePtr()->flipHorizontal(flipped.getBounds());
+		}
+
+		if (vertFlip) {
+			flipped.surfacePtr()->flipVertical(flipped.getBounds());
+		}
+	}
+	BITMAP temp(&flipped);
+
+	auto args = DrawInnerArgs(this, (horizFlip || vertFlip) ? &temp : srcBitmap, srcRect, Common::Rect(dstX, dstY, dstX+1, dstY+1), skipTrans, srcAlpha, false, false, tintRed, tintGreen, tintBlue, false);
 	if (!args.shouldDraw) return;
 	if (!args.sameFormat && args.src.format.bytesPerPixel == 1) {
 		if (format.bytesPerPixel == 4)
@@ -217,25 +234,34 @@ void BITMAP::stretchDraw(const BITMAP *srcBitmap, const Common::Rect &srcRect,
 			drawInnerGeneric<2, 1, true>(args);
 		return;
 	}
+
+	// Stretching at the same time as blitting produces errors when
+	// using the optimized paths; for now, we pre-stretch to a temporary surface
+	Graphics::ManagedSurface cropped(const_cast<BITMAP *>(srcBitmap)->getSurface(), srcRect);
+	// We need to use Surface::scale, since ManagedSurface _always_ respects the source alpha, and thus skips transparent pixels
+	Graphics::ManagedSurface stretched(cropped.rawSurface().scale(dstRect.width(), dstRect.height()), DisposeAfterUse::YES);
+	BITMAP temp(&stretched);
+	auto optimizedArgs = DrawInnerArgs(this, &temp, srcRect, dstRect, skipTrans, srcAlpha, false, false, -1, -1, -1, true);
+	
 #ifdef SCUMMVM_NEON
 	if (_G(simd_flags) & AGS3::Globals::SIMD_NEON) {
-		drawNEON<true>(args);
+		drawNEON<false>(optimizedArgs);
 		return;
 	}
 #endif
 #ifdef SCUMMVM_AVX2
 	if (_G(simd_flags) & AGS3::Globals::SIMD_AVX2) {
-		drawAVX2<true>(args);
+		drawAVX2<false>(optimizedArgs);
 		return;
 	}
 #endif
 #ifdef SCUMMVM_SSE2
 	if (_G(simd_flags) & AGS3::Globals::SIMD_SSE2) {
-		drawSSE2<true>(args);
+		drawSSE2<false>(optimizedArgs);
 		return;
 	}
 #endif
-	drawGeneric<true>(args);
+	drawGeneric<true>(optimizedArgs);
 }
 void BITMAP::blendPixel(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha, bool useTint, byte *destVal) const {
 	switch (_G(_blender_mode)) {




More information about the Scummvm-git-logs mailing list