SDL: Fix win32 windows with WS_EX_COMPOSITED style continuing to receive WM_PAINT messages after ValidateRect

From 05b701f12e55ae324425a5ed8e94d7e4184d7dcc Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 7 Apr 2023 06:20:28 -0700
Subject: [PATCH] Fix win32 windows with WS_EX_COMPOSITED style continuing to
 receive WM_PAINT messages after ValidateRect

- Composited windows seem to need to actually paint (or appear to paint) through calls to Begin/EndPaint to properly validate
  their update region. If not done they will continue to receive WM_PAINT messages for the same region.
---
 src/video/windows/SDL_windowsevents.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index 8133ed93cacf..a46e40001547 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -1358,6 +1358,16 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
     {
         RECT rect;
         if (GetUpdateRect(hwnd, &rect, FALSE)) {
+            const LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
+
+            /* Composited windows will continue to receive WM_PAINT messages for update
+               regions until the window is actually painted through Begin/EndPaint */
+            if (style & WS_EX_COMPOSITED) {
+                PAINTSTRUCT ps;
+                BeginPaint(hwnd, &ps);
+                EndPaint(hwnd, &ps);
+            }
+
             ValidateRect(hwnd, NULL);
             SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_EXPOSED, 0, 0);
         }