From 0e45b824e34f342f656044e9a8a58d2af0467e58 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 29 Sep 2024 05:22:28 -0700
Subject: [PATCH] renderer: always update the output pixel size at startup
Fixes https://github.com/libsdl-org/SDL/issues/10990
---
src/render/SDL_render.c | 15 +++++----------
src/render/SDL_sysrender.h | 4 ++--
src/render/gpu/SDL_render_gpu.c | 8 ++++----
3 files changed, 11 insertions(+), 16 deletions(-)
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index e345c50705371..e8f6e79c37463 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -735,7 +735,9 @@ static void UpdateMainViewDimensions(SDL_Renderer *renderer)
if (renderer->window) {
SDL_GetWindowSize(renderer->window, &window_w, &window_h);
}
- SDL_GetRenderOutputSize(renderer, &renderer->main_view.pixel_w, &renderer->main_view.pixel_h);
+ SDL_GetRenderOutputSize(renderer, &renderer->output_pixel_w, &renderer->output_pixel_h);
+ renderer->main_view.pixel_w = renderer->output_pixel_w;
+ renderer->main_view.pixel_h = renderer->output_pixel_h;
if (window_w > 0 && window_h > 0) {
renderer->dpi_scale.x = (float)renderer->main_view.pixel_w / window_w;
renderer->dpi_scale.y = (float)renderer->main_view.pixel_h / window_h;
@@ -2565,9 +2567,6 @@ static void UpdateLogicalPresentation(SDL_Renderer *renderer)
int iwidth, iheight;
SDL_GetRenderOutputSize(renderer, &iwidth, &iheight);
- renderer->window_pixel_w = iwidth;
- renderer->window_pixel_h = iheight;
-
const float output_w = (float)iwidth;
const float output_h = (float)iheight;
const float logical_w = renderer->logical_w;
@@ -2702,14 +2701,10 @@ bool SDL_GetRenderLogicalPresentationRect(SDL_Renderer *renderer, SDL_FRect *rec
if (renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED) {
int output_w = 0, output_h = 0;
- if (!SDL_GetRenderOutputSize(renderer, &output_w, &output_h)) {
- return false;
- }
-
rect->x = 0.0f;
rect->y = 0.0f;
- rect->w = (float)output_w;
- rect->h = (float)output_h;
+ rect->w = (float)renderer->output_pixel_w;
+ rect->h = (float)renderer->output_pixel_h;
} else {
SDL_copyp(rect, &renderer->logical_dst_rect);
}
diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h
index 9ec0d1b89bf89..19abe336f774d 100644
--- a/src/render/SDL_sysrender.h
+++ b/src/render/SDL_sysrender.h
@@ -250,8 +250,8 @@ struct SDL_Renderer
SDL_RenderViewState *view;
SDL_RenderViewState main_view;
- // Cache the window size in pixels
- int window_pixel_w, window_pixel_h;
+ // Cache the output size in pixels
+ int output_pixel_w, output_pixel_h;
// The window pixel to point coordinate scale
SDL_FPoint dpi_scale;
diff --git a/src/render/gpu/SDL_render_gpu.c b/src/render/gpu/SDL_render_gpu.c
index 183824a41f780..e735d1e304362 100644
--- a/src/render/gpu/SDL_render_gpu.c
+++ b/src/render/gpu/SDL_render_gpu.c
@@ -976,16 +976,16 @@ static bool GPU_RenderPresent(SDL_Renderer *renderer)
blit_info.source.w = data->backbuffer.width;
blit_info.source.h = data->backbuffer.height;
blit_info.destination.texture = swapchain;
- blit_info.destination.w = renderer->window_pixel_w;
- blit_info.destination.h = renderer->window_pixel_h;
+ blit_info.destination.w = renderer->output_pixel_w;
+ blit_info.destination.h = renderer->output_pixel_h;
blit_info.load_op = SDL_GPU_LOADOP_DONT_CARE;
blit_info.filter = SDL_GPU_FILTER_LINEAR;
SDL_BlitGPUTexture(data->state.command_buffer, &blit_info);
- if (renderer->window_pixel_w != data->backbuffer.width || renderer->window_pixel_h != data->backbuffer.height || swapchain_fmt != data->backbuffer.format) {
+ if (renderer->output_pixel_w != data->backbuffer.width || renderer->output_pixel_h != data->backbuffer.height || swapchain_fmt != data->backbuffer.format) {
SDL_ReleaseGPUTexture(data->device, data->backbuffer.texture);
- CreateBackbuffer(data, renderer->window_pixel_w, renderer->window_pixel_h, swapchain_fmt);
+ CreateBackbuffer(data, renderer->output_pixel_w, renderer->output_pixel_h, swapchain_fmt);
}
// *** FIXME ***