From f9b5f6cc0f4d486ab960b582d3b9fa802cb72c5e Mon Sep 17 00:00:00 2001 From: Sylvain Becker Date: Sun, 27 Dec 2020 20:28:24 +0100 Subject: [PATCH] Forward scale mode to SW renderer (Bug 5313) --- src/render/SDL_sysrender.h | 3 +++ src/render/software/SDL_render_sw.c | 4 ++-- src/video/SDL_surface.c | 25 +++++++++++++++++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h index 5bb98094e..0269a93ee 100644 --- a/src/render/SDL_sysrender.h +++ b/src/render/SDL_sysrender.h @@ -258,6 +258,9 @@ extern SDL_BlendOperation SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode the next call, because it might be in an array that gets realloc()'d. */ extern void *SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes, const size_t alignment, size_t *offset); +extern int SDL_PrivateLowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst, SDL_Rect * dstrect, SDL_ScaleMode scaleMode); +extern int SDL_PrivateUpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect, SDL_Surface * dst, SDL_Rect * dstrect, SDL_ScaleMode scaleMode); + #endif /* SDL_sysrender_h_ */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/software/SDL_render_sw.c b/src/render/software/SDL_render_sw.c index 18dc1808c..0f7ac57be 100644 --- a/src/render/software/SDL_render_sw.c +++ b/src/render/software/SDL_render_sw.c @@ -434,7 +434,7 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * tex retval = -1; } else { SDL_SetSurfaceBlendMode(src_clone, SDL_BLENDMODE_NONE); - retval = SDL_BlitScaled(src_clone, srcrect, src_scaled, &scale_rect); + retval = SDL_PrivateUpperBlitScaled(src_clone, srcrect, src_scaled, &scale_rect, texture->scaleMode); SDL_FreeSurface(src_clone); src_clone = src_scaled; src_scaled = NULL; @@ -720,7 +720,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic * to avoid potentially frequent RLE encoding/decoding. */ SDL_SetSurfaceRLE(surface, 0); - SDL_BlitScaled(src, srcrect, surface, dstrect); + SDL_PrivateUpperBlitScaled(src, srcrect, surface, dstrect, texture->scaleMode); } break; } diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index ade68bf34..dbb66aa88 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -26,6 +26,7 @@ #include "SDL_RLEaccel_c.h" #include "SDL_pixels_c.h" #include "SDL_yuv_c.h" +#include "../render/SDL_sysrender.h" /* Check to make sure we can safely check multiplication of surface w and pitch and it won't overflow size_t */ @@ -745,6 +746,14 @@ SDL_UpperBlit(SDL_Surface * src, const SDL_Rect * srcrect, int SDL_UpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect, SDL_Surface * dst, SDL_Rect * dstrect) +{ + return SDL_PrivateUpperBlitScaled(src, srcrect, dst, dstrect, SDL_ScaleModeNearest); +} + + +int +SDL_PrivateUpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect, + SDL_Surface * dst, SDL_Rect * dstrect, SDL_ScaleMode scaleMode) { double src_x0, src_y0, src_x1, src_y1; double dst_x0, dst_y0, dst_x1, dst_y1; @@ -889,7 +898,7 @@ SDL_UpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect, return 0; } - return SDL_LowerBlitScaled(src, &final_src, dst, &final_dst); + return SDL_PrivateLowerBlitScaled(src, &final_src, dst, &final_dst, scaleMode); } /** @@ -899,6 +908,13 @@ SDL_UpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect, int SDL_LowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst, SDL_Rect * dstrect) +{ + return SDL_PrivateLowerBlitScaled(src, srcrect, dst, dstrect, SDL_ScaleModeNearest); +} + +int +SDL_PrivateLowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect, + SDL_Surface * dst, SDL_Rect * dstrect, SDL_ScaleMode scaleMode) { static const Uint32 complex_copy_flags = ( SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | @@ -914,7 +930,12 @@ SDL_LowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect, if ( !(src->map->info.flags & complex_copy_flags) && src->format->format == dst->format->format && !SDL_ISPIXELFORMAT_INDEXED(src->format->format) ) { - return SDL_SoftStretch( src, srcrect, dst, dstrect ); + + if (scaleMode != SDL_ScaleModeNearest && src->format->BytesPerPixel == 4 && src->format->format != SDL_PIXELFORMAT_ARGB2101010) { + return SDL_SoftStretchLinear(src, srcrect, dst, dstrect); + } else { + return SDL_SoftStretch( src, srcrect, dst, dstrect ); + } } else { return SDL_LowerBlit( src, srcrect, dst, dstrect ); }