Commit f7d3abddba774b775d6285e1dfb131a578900549

Sylvain 2022-01-29T10:19:08

Fixed bug #964 - SDL_RenderCopy stretch loses proportion on viewport. Handle the case when there is blending

diff --git a/src/render/software/SDL_render_sw.c b/src/render/software/SDL_render_sw.c
index 5afa4fa..b44d523 100644
--- a/src/render/software/SDL_render_sw.c
+++ b/src/render/software/SDL_render_sw.c
@@ -829,13 +829,31 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
                         /* Scale to an intermediate surface, then blit */
                         if (tmp) {
                             SDL_Rect r;
+                            SDL_BlendMode blendmode;
+                            Uint8 alphaMod, rMod, gMod, bMod;
+
+                            SDL_GetSurfaceBlendMode(src, &blendmode);
+                            SDL_GetSurfaceAlphaMod(src, &alphaMod);
+                            SDL_GetSurfaceColorMod(src, &rMod, &gMod, &bMod);
+
                             r.x = 0;
                             r.y = 0;
                             r.w = dstrect->w;
                             r.h = dstrect->h;
+
+                            SDL_SetSurfaceBlendMode(src, SDL_BLENDMODE_NONE);
+                            SDL_SetSurfaceColorMod(src, 255, 255, 255);
+                            SDL_SetSurfaceAlphaMod(src, 255);
+
                             SDL_PrivateUpperBlitScaled(src, srcrect, tmp, &r, texture->scaleMode);
+
+                            SDL_SetSurfaceColorMod(tmp, rMod, gMod, bMod);
+                            SDL_SetSurfaceAlphaMod(tmp, alphaMod);
+                            SDL_SetSurfaceBlendMode(tmp, blendmode);
+
                             SDL_BlitSurface(tmp, NULL, surface, dstrect);
                             SDL_FreeSurface(tmp);
+                            /* No need to set back r/g/b/a/blendmode to 'src' since it's done in PrepTextureForCopy() */
                         }
                     } else{
                         SDL_PrivateUpperBlitScaled(src, srcrect, surface, dstrect, texture->scaleMode);