sdl2-compat: Remove all references to WinRT: SDL3 dropped support for it.

From 5bddab79233dcb53722b69aec0f0efb9100430ba Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Sat, 7 Sep 2024 00:37:04 +0300
Subject: [PATCH] Remove all references to WinRT: SDL3 dropped support for it.

---
 CMakeLists.txt                | 11 +-----
 cmake/test/CMakeLists.txt     |  4 +--
 src/dynapi/SDL_dynapi.h       |  4 ---
 src/dynapi/SDL_dynapi_procs.h |  8 -----
 src/sdl2_compat.c             | 55 ++++-------------------------
 src/sdl2_compat.h             |  4 +--
 src/sdl2_compat_winrt.cpp     | 66 -----------------------------------
 src/sdl2_mslibc.c             |  2 +-
 src/sdl2_protos.h             |  8 -----
 src/sdl3_syms.h               |  5 ---
 10 files changed, 12 insertions(+), 155 deletions(-)
 delete mode 100644 src/sdl2_compat_winrt.cpp

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 93f7b820..88c5c1b2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -176,12 +176,6 @@ if(APPLE)
   endif()
 endif()
 
-if(WINDOWS_STORE)
-  list(APPEND SDL2COMPAT_SRCS
-    "src/sdl2_compat_winrt.cpp"
-  )
-endif()
-
 if(WIN32)
   list(APPEND SDL2COMPAT_SRCS
     "src/sdl2_mslibc.c"
@@ -321,10 +315,7 @@ if(MINGW)
     set_property(TARGET SDL2 APPEND_STRING PROPERTY LINK_FALGS " -static-libgcc")
   endif()
 endif()
-if(WINDOWS_STORE)
-  set_target_properties(SDL2 PROPERTIES DEFINE_SYMBOL "SDL_BUILDING_WINRT=1")
-  target_compile_options(SDL2 PRIVATE "-ZW")
-elseif(MSVC)
+if(MSVC)
   # Don't try to link with the default set of libraries.
   target_compile_options(SDL2 PRIVATE "$<$<COMPILE_LANGUAGE:C>:/GS->")
   if(SDL_CPU_X86)  # don't emit SSE2 in x86 builds
diff --git a/cmake/test/CMakeLists.txt b/cmake/test/CMakeLists.txt
index 388e86c5..d4c838be 100644
--- a/cmake/test/CMakeLists.txt
+++ b/cmake/test/CMakeLists.txt
@@ -29,7 +29,7 @@ add_feature_info("TEST_STATIC" TEST_STATIC "Test linking with static library")
 
 if(TEST_SHARED)
     find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2)
-    if(EMSCRIPTEN OR (WIN32 AND NOT WINDOWS_STORE))
+    if(EMSCRIPTEN OR WIN32)
         find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main)
     endif()
     add_executable(gui-shared WIN32 main_gui.c)
@@ -79,7 +79,7 @@ endif()
 
 if(TEST_STATIC)
     find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2-static)
-    if(EMSCRIPTEN OR (WIN32 AND NOT WINDOWS_STORE))
+    if(EMSCRIPTEN OR WIN32)
         find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main)
     endif()
     add_executable(gui-static WIN32 main_gui.c)
diff --git a/src/dynapi/SDL_dynapi.h b/src/dynapi/SDL_dynapi.h
index 0f02e12b..e7a264f9 100644
--- a/src/dynapi/SDL_dynapi.h
+++ b/src/dynapi/SDL_dynapi.h
@@ -51,8 +51,6 @@
 #define SDL_DYNAMIC_API 0
 #elif defined(SDL_PLATFORM_EMSCRIPTEN) /* probably not useful on Emscripten. */
 #define SDL_DYNAMIC_API 0
-#elif defined(SDL_BUILDING_WINRT) && SDL_BUILDING_WINRT /* probably not useful on WinRT, given current .dll loading restrictions */
-#define SDL_DYNAMIC_API 0
 #elif defined(SDL_PLATFORM_PS2)
 #define SDL_DYNAMIC_API 0
 #elif defined(SDL_PLATFORM_PSP) && SDL_PLATFORM_PSP
@@ -77,5 +75,3 @@
 #endif
 
 #endif
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 9c4c3c05..888b6a3e 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -603,11 +603,6 @@ SDL_DYNAPI_PROC(SDL_AssertionHandler,SDL_GetAssertionHandler,(void **a),(a),retu
 SDL_DYNAPI_PROC(SDL2_bool,SDL_DXGIGetOutputInfo,(int a,int *b, int *c),(a,b,c),return)
 #endif
 SDL_DYNAPI_PROC(SDL2_bool,SDL_RenderIsClipEnabled,(SDL_Renderer *a),(a),return)
-#ifdef SDL_PLATFORM_WINRT
-SDL_DYNAPI_PROC(int,SDL_WinRTRunApp,(SDL_main_func a, void *b),(a,b),return)
-SDL_DYNAPI_PROC(const wchar_t*,SDL_WinRTGetFSPathUNICODE,(SDL_WinRT_Path a),(a),return)
-SDL_DYNAPI_PROC(const char*,SDL_WinRTGetFSPathUTF8,(SDL_WinRT_Path a),(a),return)
-#endif
 SDL_DYNAPI_PROC(int,SDL_WarpMouseGlobal,(int a, int b),(a,b),return)
 SDL_DYNAPI_PROC(float,SDL_sqrtf,(float a),(a),return)
 SDL_DYNAPI_PROC(double,SDL_tan,(double a),(a),return)
@@ -699,9 +694,6 @@ SDL_DYNAPI_PROC(SDL_YUV_CONVERSION_MODE,SDL_GetYUVConversionMode,(void),(),retur
 SDL_DYNAPI_PROC(SDL_YUV_CONVERSION_MODE,SDL_GetYUVConversionModeForResolution,(int a, int b),(a,b),return)
 SDL_DYNAPI_PROC(void*,SDL_RenderGetMetalLayer,(SDL_Renderer *a),(a),return)
 SDL_DYNAPI_PROC(void*,SDL_RenderGetMetalCommandEncoder,(SDL_Renderer *a),(a),return)
-#ifdef SDL_PLATFORM_WINRT
-SDL_DYNAPI_PROC(SDL_WinRT_DeviceFamily,SDL_WinRTGetDeviceFamily,(void),(),return)
-#endif
 #ifdef SDL_PLATFORM_ANDROID
 SDL_DYNAPI_PROC(SDL2_bool,SDL_IsAndroidTV,(void),(),return)
 #endif
diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index f369cd94..19d78e01 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -251,13 +251,8 @@ static char loaderror[256];
 #if defined(_WIN32)
     static HMODULE Loaded_SDL3 = NULL;
     #define DIRSEP "\\"
-    #ifdef SDL_BUILDING_WINRT
-    #define SDL3_LIBNAME L"SDL3.dll"
-    #define LoadSDL3Library() ((Loaded_SDL3 = LoadPackagedLibrary(SDL3_LIBNAME,0)) != NULL)
-    #else
     #define SDL3_LIBNAME "SDL3.dll"
     #define LoadSDL3Library() ((Loaded_SDL3 = LoadLibraryA(SDL3_LIBNAME)) != NULL)
-    #endif
     #define LookupSDL3Sym(sym) (void *)GetProcAddress(Loaded_SDL3, sym)
     #define CloseSDL3Library() { if (Loaded_SDL3) { FreeLibrary(Loaded_SDL3); Loaded_SDL3 = NULL; } }
 #elif defined(__APPLE__)
@@ -650,7 +645,7 @@ LoadSDL3(void)
     return okay;
 }
 
-#if defined(_MSC_VER) && !defined(SDL_BUILDING_WINRT)
+#if defined(_MSC_VER)
 
 /* NOLINTNEXTLINE(readability-redundant-declaration) */
 extern void *memcpy(void *dst, const void *src, size_t len);
@@ -674,7 +669,7 @@ void *memset(void *dst, int c, size_t len)
 {
     return SDL3_memset(dst, c, len);
 }
-#endif  /* MSVC && !WINRT */
+#endif  /* MSVC */
 
 #if defined(__ICL) && defined(_WIN32)
 /* The classic Intel compiler generates calls to _intel_fast_memcpy
@@ -690,9 +685,7 @@ void *_intel_fast_memset(void *dst, int c, size_t len)
 }
 #endif
 
-#ifdef SDL_BUILDING_WINRT
-EXTERN_C void error_dialog(const char *errorMsg);
-#elif defined(_WIN32)
+#if defined(_WIN32)
 static void error_dialog(const char *errorMsg)
 {
     MessageBoxA(NULL, errorMsg, "Error", MB_OK | MB_SETFOREGROUND | MB_ICONSTOP);
@@ -2094,7 +2087,7 @@ SDL_RWFromFile(const char *file, const char *mode)
         const SDL_PropertiesID props = SDL3_GetIOProperties(rwops2->hidden.sdl3.iostrm);
         if (props) {
             void *handle = NULL;
-            #if (defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)) && !defined(SDL_PLATFORM_WINRT)
+            #if defined(SDL_PLATFORM_WINDOWS)
             if (!handle) {
                 handle = SDL3_GetPointerProperty(props, SDL_PROP_IOSTREAM_WINDOWS_HANDLE_POINTER, NULL);
                 if (handle) {
@@ -3186,9 +3179,6 @@ SDL_DECLSPEC SDL2_bool SDLCALL SDL_GetWindowWMInfo(SDL_Window *window, SDL_SysWM
         info->info.win.window = SDL3_GetPointerProperty(props, SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
         info->info.win.hdc = SDL3_GetPointerProperty(props, SDL_PROP_WINDOW_WIN32_HDC_POINTER, NULL);
         info->info.win.hinstance = SDL3_GetPointerProperty(props, SDL_PROP_WINDOW_WIN32_INSTANCE_POINTER, NULL);
-    } else if (SDL_strcmp(driver, "winrt") == 0) {
-        info->subsystem = SDL2_SYSWM_WINRT;
-        info->info.winrt.window = SDL3_GetPointerProperty(props, SDL_PROP_WINDOW_WINRT_WINDOW_POINTER, NULL);
     } else if (SDL_strcmp(driver, "x11") == 0) {
         info->subsystem = SDL2_SYSWM_X11;
         info->info.x11.display = SDL3_GetPointerProperty(props, SDL_PROP_WINDOW_X11_DISPLAY_POINTER, NULL);
@@ -9263,7 +9253,7 @@ static SDL_Thread *SDL2_CreateThread(SDL_ThreadFunction fn, const char *name, vo
     return SDL2_CreateThreadWithStackSize(fn, name, stacksize, userdata, pfnBeginThread, pfnEndThread);
 }
 
-#if (defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)) && !defined(SDL_PLATFORM_WINRT)
+#if defined(SDL_PLATFORM_WINDOWS)
 
 SDL_DECLSPEC SDL_Thread *SDLCALL
 SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
@@ -9293,7 +9283,7 @@ SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const siz
     return SDL2_CreateThreadWithStackSize(fn, name, stacksize, data, NULL, NULL);
 }
 
-#endif /* (SDL_PLATFORM_WIN32 || SDL_PLATFORM_GDK) && !SDL_PLATFORM_WINRT */
+#endif /* SDL_PLATFORM_WINDOWS */
 
 SDL_DECLSPEC unsigned long SDLCALL
 SDL_ThreadID(void)
@@ -9362,14 +9352,6 @@ SDL_DECLSPEC ID3D12Device* SDLCALL SDL_RenderGetD3D12Device(SDL_Renderer *render
 }
 #endif
 
-#ifdef SDL_PLATFORM_WINRT
-SDL_DECLSPEC int SDLCALL
-SDL_WinRTRunApp(SDL_main_func mainFunction, void *reserved)
-{
-    return SDL3_RunApp(0, NULL, mainFunction, reserved);
-}
-#endif
-
 #if defined(SDL_PLATFORM_GDK)
 SDL_DECLSPEC int SDLCALL
 SDL_GDKRunApp(SDL_main_func mainFunction, void *reserved)
@@ -9423,31 +9405,6 @@ SDL_AndroidRequestPermission(const char *permission)
 }
 #endif
 
-#ifdef SDL_PLATFORM_WINRT
-static wchar_t *winrt_getfspath_cached_strings[4];  // these need to be saved here, since we return a const string. These strings' memory leaks!
-
-SDL_DECLSPEC const wchar_t* SDLCALL
-SDL_WinRTGetFSPathUNICODE(int SDL_WinRT_Path pathType)
-{
-    wchar_t *wstr = NULL;
-
-    if ((int)pathType >= (int)SDL_arraysize(winrt_getfspath_cached_strings)) {  // in case something new is added in SDL3...
-        SDL3_SetError("Unsupported SDL_WinRT_Path %d", (int) pathType);
-    } else {
-        wstr = winrt_getfspath_cached_strings[pathType];
-        if (!wstr) {
-            const char *utf8 = SDL3_GetWinRTFSPath(pathType);
-            if (utf8) {
-                wstr = (wchar_t *) SDL3_iconv_string("UTF-16LE", "UTF-8", (const char *)(utf8), SDL3_strlen(utf8) + 1);
-                winrt_getfspath_cached_strings[pathType] = wstr;
-            }
-        }
-    }
-
-    return wstr;
-}
-#endif
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/sdl2_compat.h b/src/sdl2_compat.h
index 43dca7e2..80fb887b 100644
--- a/src/sdl2_compat.h
+++ b/src/sdl2_compat.h
@@ -180,7 +180,7 @@ typedef Sint64 SDL2_GestureID;
 #define SDL_RWOPS_MEMORY    4   /**< Memory stream */
 #define SDL_RWOPS_MEMORY_RO 5   /**< Read-Only memory stream */
 
-#if (defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)) && !defined(SDL_PLATFORM_WINRT)
+#if defined(SDL_PLATFORM_WINDOWS)
 #define SDL_RWOPS_PLATFORM_FILE SDL_RWOPS_WINFILE
 #elif defined(SDL_PLATFORM_ANDROID)
 #define SDL_RWOPS_PLATFORM_FILE SDL_RWOPS_JNIFILE
@@ -1174,7 +1174,7 @@ typedef struct ID3D12Device ID3D12Device;
 typedef void (SDLCALL * SDL2_WindowsMessageHook)(void *userdata, void *hWnd, unsigned int message, Uint64 wParam, Sint64 lParam);
 #endif
 
-#if (defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)) && !defined(SDL_PLATFORM_WINRT)
+#if defined(SDL_PLATFORM_WINDOWS)
 typedef uintptr_t (__cdecl * pfnSDL_CurrentBeginThread)
                         (void *, unsigned, unsigned (__stdcall *func)(void *), void *, unsigned, unsigned *);
 typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned);
diff --git a/src/sdl2_compat_winrt.cpp b/src/sdl2_compat_winrt.cpp
deleted file mode 100644
index b82269cf..00000000
--- a/src/sdl2_compat_winrt.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
-  Simple DirectMedia Layer
-  Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-*/
-
-/* This file contains some WinRT-specific support code */
-
-#include <windows.h>
-
-#include <windows.ui.popups.h>
-using namespace Platform;
-using namespace Windows::Foundation;
-using namespace Windows::UI::Popups;
-
-static String ^ WINRT_PlatformString(const WCHAR *wstr)
-{
-    String ^ rtstr = ref new String(wstr);
-    return rtstr;
-}
-
-static String ^ WINRT_UTF8ToPlatformString(const char *str)
-{
-    WCHAR wstr[256];
-    unsigned int i;
-    for (i = 0; i < (ARRAYSIZE(wstr) - 1) && str[i]; i++) {
-        wstr[i] = (WCHAR) str[i]; /* low-ASCII maps to WCHAR directly. */
-    }
-    wstr[i] = 0;
-    return WINRT_PlatformString(wstr);
-}
-
-extern "C"
-void error_dialog(const char *errorMsg)
-{
-    /* Build a MessageDialog object and its buttons */
-    MessageDialog ^ dialog = ref new MessageDialog(WINRT_UTF8ToPlatformString(errorMsg));
-    dialog->Title = WINRT_PlatformString(L"Error");
-    UICommand ^ button = ref new UICommand(WINRT_PlatformString(L"OK"));
-    button->Id = IntPtr(0);
-    dialog->Commands->Append(button);
-    dialog->CancelCommandIndex = 0;
-    dialog->DefaultCommandIndex = 0;
-    /* Display the MessageDialog, then wait for it to be closed */
-    auto operation = dialog->ShowAsync();
-    while (operation->Status == Windows::Foundation::AsyncStatus::Started) {
-      /* do anything here? */ ;
-    }
-}
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/sdl2_mslibc.c b/src/sdl2_mslibc.c
index bfd4b219..0ec093e4 100644
--- a/src/sdl2_mslibc.c
+++ b/src/sdl2_mslibc.c
@@ -21,7 +21,7 @@
 
 /* taken from SDL_mslibc.c of SDL3 */
 
-#if defined(_MSC_VER) && !defined(SDL_BUILDING_WINRT)
+#if defined(_MSC_VER)
 
 #ifndef __FLTUSED__
 #define __FLTUSED__
diff --git a/src/sdl2_protos.h b/src/sdl2_protos.h
index e59ad86f..8d939d9e 100644
--- a/src/sdl2_protos.h
+++ b/src/sdl2_protos.h
@@ -601,11 +601,6 @@ SDL2_PROTO(SDL_AssertionHandler,GetAssertionHandler,(void **a))
 SDL2_PROTO(SDL2_bool,DXGIGetOutputInfo,(int a,int *b, int *c))
 #endif
 SDL2_PROTO(SDL2_bool,RenderIsClipEnabled,(SDL_Renderer *a))
-#ifdef SDL_PLATFORM_WINRT
-SDL2_PROTO(int,WinRTRunApp,(SDL_main_func a, void *b))
-SDL2_PROTO(const wchar_t*,WinRTGetFSPathUNICODE,(SDL_WinRT_Path a))
-SDL2_PROTO(const char*,WinRTGetFSPathUTF8,(SDL_WinRT_Path a))
-#endif
 SDL2_PROTO(int,WarpMouseGlobal,(int a, int b))
 SDL2_PROTO(float,sqrtf,(float a))
 SDL2_PROTO(double,tan,(double a))
@@ -697,9 +692,6 @@ SDL2_PROTO(SDL_YUV_CONVERSION_MODE,GetYUVConversionMode,(void))
 SDL2_PROTO(SDL_YUV_CONVERSION_MODE,GetYUVConversionModeForResolution,(int a, int b))
 SDL2_PROTO(void*,RenderGetMetalLayer,(SDL_Renderer *a))
 SDL2_PROTO(void*,RenderGetMetalCommandEncoder,(SDL_Renderer *a))
-#ifdef SDL_PLATFORM_WINRT
-SDL2_PROTO(SDL_WinRT_DeviceFamily,WinRTGetDeviceFamily,(void))
-#endif
 #ifdef SDL_PLATFORM_ANDROID
 SDL2_PROTO(SDL2_bool,IsAndroidTV,(void))
 #endif
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 3b7873d9..12b89727 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -75,11 +75,6 @@ SDL3_SYM_RENAMED_RETCODE(SDL_bool,GDKGetTaskQueue,GetGDKTaskQueue,(XTaskQueueHan
 SDL3_SYM_RENAMED_RETCODE(SDL_bool,GDKGetDefaultUser,GetGDKDefaultUser,(XUserHandle *a),(a),return)
 #endif
 
-#ifdef SDL_PLATFORM_WINRT
-SDL3_SYM_RENAMED(const char*,WinRTGetFSPathUTF8,GetWinRTFSPath,(SDL_WinRT_Path a),(a),return)
-SDL3_SYM_RENAMED(SDL_WinRT_DeviceFamily,WinRTGetDeviceFamily,GetWinRTDeviceFamily,(void),(),return)
-#endif
-
 #ifdef SDL_PLATFORM_IOS
 SDL3_SYM_RENAMED_RETCODE(SDL_bool,iPhoneSetAnimationCallback,SetiOSAnimationCallback,(SDL_Window *a, int b, SDL_iOSAnimationCallback c, void *d),(a,b,c,d),return)
 SDL3_SYM(void,iPhoneSetEventPump,SetiOSEventPump,(SDL_bool a),(a),)