SDL: render: Only update size/scale/viewport when moving to a new display, rather than all window movement.

From a28f426acbdbb9c301f47fc3960cc9d510dada08 Mon Sep 17 00:00:00 2001
From: Ethan Lee <[EMAIL REDACTED]>
Date: Fri, 12 Aug 2022 16:13:24 -0400
Subject: [PATCH] render: Only update size/scale/viewport when moving to a new
 display, rather than all window movement.

We really only care about DPI changes here, so this both reduces work and also avoids weird cases where viewport state can be corrupted by trivial window events. This doesn't _completely_ get rid of the issue but this is somewhat intentional, since apps will definitely want to do a full reset when changing displays anyhow (otherwise DPI/adapter changes will screw things up, and that's out of our control as long as both window size and drawable size are exposed at the same time.

Note that OpenGL still captures window events because of weird platform-specific issues like macOS and viewport stretching!

Fixes #5949
---
 src/render/SDL_render.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 0220387bd15..58931012a10 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -705,16 +705,11 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
             }
 
             /* In addition to size changes, we also want to do this block for
-             * moves as well, for two reasons:
-             *
-             * 1. The window could be moved to a new display, which has a new
-             *    DPI and therefore a new window/drawable ratio
-             * 2. For whatever reason, the viewport can get messed up during
-             *    window movement (this has been observed on macOS), so this is
-             *    also a good opportunity to force viewport updates
+             * window display changes as well! If the new display has a new DPI,
+             * we need to update the viewport for the new window/drawable ratio.
              */
             if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED ||
-                event->window.event == SDL_WINDOWEVENT_MOVED) {
+                event->window.event == SDL_WINDOWEVENT_DISPLAY_CHANGED) {
                 /* Make sure we're operating on the default render target */
                 SDL_Texture *saved_target = SDL_GetRenderTarget(renderer);
                 if (saved_target) {