Fixed bug #964 - SDL_RenderCopy stretch loses proportion on viewport boundaries

This commit is contained in:
Sylvain 2022-01-28 17:24:59 +01:00
parent 7bf8c5a388
commit a988ce5544
No known key found for this signature in database
GPG Key ID: 5F87E02E5BC0939E
1 changed files with 18 additions and 1 deletions

View File

@ -823,8 +823,25 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
* to avoid potentially frequent RLE encoding/decoding. * to avoid potentially frequent RLE encoding/decoding.
*/ */
SDL_SetSurfaceRLE(surface, 0); SDL_SetSurfaceRLE(surface, 0);
/* Prevent to do scaling + clipping on viewport boundaries as it may lose proportion */
if (dstrect->x < 0 || dstrect->y < 0 || dstrect->x + dstrect->w > surface->w || dstrect->y + dstrect->h > surface->h) {
SDL_Surface *tmp = SDL_CreateRGBSurfaceWithFormat(0, dstrect->w, dstrect->h, 0, src->format->format);
/* Scale to an intermediate surface, then blit */
if (tmp) {
SDL_Rect r;
r.x = 0;
r.y = 0;
r.w = dstrect->w;
r.h = dstrect->h;
SDL_PrivateUpperBlitScaled(src, srcrect, tmp, &r, texture->scaleMode);
SDL_BlitSurface(tmp, NULL, surface, dstrect);
SDL_FreeSurface(tmp);
}
} else{
SDL_PrivateUpperBlitScaled(src, srcrect, surface, dstrect, texture->scaleMode); SDL_PrivateUpperBlitScaled(src, srcrect, surface, dstrect, texture->scaleMode);
} }
}
break; break;
} }