SDL: SDL_windowsevents: minimize white screen flash on window creation

From 053b5f85f164dd2f730a6500096a666001dc9d5b Mon Sep 17 00:00:00 2001
From: Steven Noonan <[EMAIL REDACTED]>
Date: Thu, 25 Aug 2022 20:18:03 -0700
Subject: [PATCH] SDL_windowsevents: minimize white screen flash on window
 creation

Clear the window to black on the initial window draw, to avoid a really
obnoxious white flash. This doesn't always eliminate it, but it
definitely minimizes it.
---
 src/video/windows/SDL_windowsevents.c | 8 ++++++++
 src/video/windows/SDL_windowsvideo.h  | 1 +
 2 files changed, 9 insertions(+)

diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index e5903fdd33b7..7370f9e5ca8c 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -1271,7 +1271,15 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
         /* We'll do our own drawing, prevent flicker */
     case WM_ERASEBKGND:
+        if (!data->videodata->cleared)
         {
+            RECT client_rect;
+            HBRUSH brush;
+            data->videodata->cleared = SDL_TRUE;
+            GetClientRect(hwnd, &client_rect);
+            brush = CreateSolidBrush(0);
+            FillRect(GetDC(hwnd), &client_rect, brush);
+            DeleteObject(brush);
         }
         return (1);
 
diff --git a/src/video/windows/SDL_windowsvideo.h b/src/video/windows/SDL_windowsvideo.h
index e07c34443012..cdebb4cfa918 100644
--- a/src/video/windows/SDL_windowsvideo.h
+++ b/src/video/windows/SDL_windowsvideo.h
@@ -394,6 +394,7 @@ typedef struct SDL_VideoData
 #endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
 
     SDL_bool dpi_scaling_enabled;
+    SDL_bool cleared;
 
  #ifndef SDL_DISABLE_WINDOWS_IME
     SDL_bool ime_com_initialized;