https://github.com/libsdl-org/SDL/commit/4bb3c2a1c7c5426d57849a0d9a7ea511c90f35b0
From 4bb3c2a1c7c5426d57849a0d9a7ea511c90f35b0 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Wed, 8 Jan 2025 14:57:47 -0500
Subject: [PATCH] render: Some cleanups.
Mostly setting NULL pointers to a local struct instead of copying non-NULL
pointers' contents into the local struct.
---
src/render/SDL_render.c | 48 ++++++++++++++++++++---------------------
1 file changed, 23 insertions(+), 25 deletions(-)
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index e2ebf6b79aaf1..06c0381ca89b2 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -3869,9 +3869,6 @@ static bool SDL_RenderTextureInternal(SDL_Renderer *renderer, SDL_Texture *textu
bool SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect)
{
- SDL_FRect real_srcrect;
- SDL_FRect real_dstrect;
-
CHECK_RENDERER_MAGIC(renderer, false);
CHECK_TEXTURE_MAGIC(texture, false);
@@ -3886,6 +3883,7 @@ bool SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_F
}
#endif
+ SDL_FRect real_srcrect;
real_srcrect.x = 0.0f;
real_srcrect.y = 0.0f;
real_srcrect.w = (float)texture->w;
@@ -3896,9 +3894,10 @@ bool SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_F
}
}
- GetRenderViewportSize(renderer, &real_dstrect);
- if (dstrect) {
- real_dstrect = *dstrect;
+ SDL_FRect full_dstrect;
+ if (!dstrect) {
+ GetRenderViewportSize(renderer, &full_dstrect);
+ dstrect = &full_dstrect;
}
if (texture->native) {
@@ -3907,7 +3906,7 @@ bool SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_F
texture->last_command_generation = renderer->render_command_generation;
- return SDL_RenderTextureInternal(renderer, texture, &real_srcrect, &real_dstrect);
+ return SDL_RenderTextureInternal(renderer, texture, &real_srcrect, dstrect);
}
bool SDL_RenderTextureAffine(SDL_Renderer *renderer, SDL_Texture *texture,
@@ -4032,7 +4031,6 @@ bool SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
const double angle, const SDL_FPoint *center, const SDL_FlipMode flip)
{
SDL_FRect real_srcrect;
- SDL_FRect real_dstrect;
SDL_FPoint real_center;
bool result;
@@ -4068,10 +4066,10 @@ bool SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
}
// We don't intersect the dstrect with the viewport as RenderCopy does because of potential rotation clipping issues... TODO: should we?
- if (dstrect) {
- real_dstrect = *dstrect;
- } else {
- GetRenderViewportSize(renderer, &real_dstrect);
+ SDL_FRect full_dstrect;
+ if (!dstrect) {
+ GetRenderViewportSize(renderer, &full_dstrect);
+ dstrect = &full_dstrect;
}
if (texture->native) {
@@ -4081,8 +4079,8 @@ bool SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
if (center) {
real_center = *center;
} else {
- real_center.x = real_dstrect.w / 2.0f;
- real_center.y = real_dstrect.h / 2.0f;
+ real_center.x = dstrect->w / 2.0f;
+ real_center.y = dstrect->h / 2.0f;
}
texture->last_command_generation = renderer->render_command_generation;
@@ -4116,23 +4114,23 @@ bool SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
maxu = (real_srcrect.x + real_srcrect.w) / texture->w;
maxv = (real_srcrect.y + real_srcrect.h) / texture->h;
- centerx = real_center.x + real_dstrect.x;
- centery = real_center.y + real_dstrect.y;
+ centerx = real_center.x + dstrect->x;
+ centery = real_center.y + dstrect->y;
if (flip & SDL_FLIP_HORIZONTAL) {
- minx = real_dstrect.x + real_dstrect.w;
- maxx = real_dstrect.x;
+ minx = dstrect->x + dstrect->w;
+ maxx = dstrect->x;
} else {
- minx = real_dstrect.x;
- maxx = real_dstrect.x + real_dstrect.w;
+ minx = dstrect->x;
+ maxx = dstrect->x + dstrect->w;
}
if (flip & SDL_FLIP_VERTICAL) {
- miny = real_dstrect.y + real_dstrect.h;
- maxy = real_dstrect.y;
+ miny = dstrect->y + dstrect->h;
+ maxy = dstrect->y;
} else {
- miny = real_dstrect.y;
- maxy = real_dstrect.y + real_dstrect.h;
+ miny = dstrect->y;
+ maxy = dstrect->y + dstrect->h;
}
uv[0] = minu;
@@ -4173,7 +4171,7 @@ bool SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
num_vertices, indices, num_indices, size_indices,
scale_x, scale_y, SDL_TEXTURE_ADDRESS_CLAMP);
} else {
- result = QueueCmdCopyEx(renderer, texture, &real_srcrect, &real_dstrect, angle, &real_center, flip, scale_x, scale_y);
+ result = QueueCmdCopyEx(renderer, texture, &real_srcrect, dstrect, angle, &real_center, flip, scale_x, scale_y);
}
return result;
}