SDL: migration: Fixes and additions to SDL_migration.cocci and README-migration.md.

From e5335f9a20bf3d06d099e9c90e4f14b7093a001f Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Mon, 5 Oct 2026 14:17:46 -0400
Subject: [PATCH] migration: Fixes and additions to SDL_migration.cocci and
 README-migration.md.

---
 build-scripts/SDL_migration.cocci | 66 ++++++++++++++++++++++++++-----
 docs/README-migration.md          |  2 +
 2 files changed, 59 insertions(+), 9 deletions(-)

diff --git a/build-scripts/SDL_migration.cocci b/build-scripts/SDL_migration.cocci
index abfc50551a23b..3ef994848810b 100644
--- a/build-scripts/SDL_migration.cocci
+++ b/build-scripts/SDL_migration.cocci
@@ -30,6 +30,27 @@
 //
 // So this file is a set of many semantic patches, mostly independent.
 
+@@
+@@
+- SDL_VideoInit()
++ SDL_InitSubSystem(SDL_INIT_VIDEO)
+
+@@
+@@
+- SDL_VideoQuit()
++ SDL_QuitSubSystem(SDL_INIT_VIDEO)
+
+@@
+@@
+- SDL_AudioInit()
++ SDL_InitSubSystem(SDL_INIT_AUDIO)
+
+@@
+@@
+- SDL_AudioQuit()
++ SDL_QuitSubSystem(SDL_INIT_AUDIO)
+
+
 @ rule_audio_open @
 expression e1, e2;
 @@
@@ -84,8 +105,6 @@ expression e1, e2;
 + SDL_QueueAudio(g_audio_id, e1, e2)
 
 
-
-
 // SDL_EventState() - replaced with SDL_SetEventEnabled()
 @@
 expression e1;
@@ -379,6 +398,14 @@ expression e;
 )
 
 
+@@
+// Add parameter to SDL_PremultiplyAlpha
+expression e1, e2, e3, e4, e5, e6, e7, e8;
+@@
+-SDL_PremultiplyAlpha(e1, e2, e3, e4, e5, e6, e7, e8)
++SDL_PremultiplyAlpha(e1, e2, e3, e4, e5, e6, e7, e8, false)
+
+
 @@
 // Remove parameter from SDL_ConvertSurface
 expression e1, e2, e3;
@@ -743,12 +770,12 @@ expression e1, e2, e3, e4, e5, e6, e7, e8, e9;
 |
 
 -SDL_CreateRGBSurface(e1, e2, e3, e4, e5, e6, e7, e8)
-+SDL_CreateSurface(e2, e3, SDL_MasksToPixelFormatEnum(e4, e5, e6, e7, e8))
++SDL_CreateSurface(e2, e3, SDL_GetPixelFormatForMasks(e4, e5, e6, e7, e8))
 
 |
 
 -SDL_CreateRGBSurfaceFrom(e1, e2, e3, e4, e5, e6, e7, e8, e9)
-+SDL_CreateSurfaceFrom(e1, e2, e3, e5, SDL_MasksToPixelFormatEnum(e4, e6, e7, e8, e9))
++SDL_CreateSurfaceFrom(e1, e2, e3, e5, SDL_GetPixelFormatForMasks(e4, e6, e7, e8, e9))
 
 )
 
@@ -2063,11 +2090,11 @@ expression e;
 @@
 @@
 - SDL_DISPLAYEVENT_CONNECTED
-+ SDL_EVENT_DISPLAY_CONNECTED
++ SDL_EVENT_DISPLAY_ADDED
 @@
 @@
 - SDL_DISPLAYEVENT_DISCONNECTED
-+ SDL_EVENT_DISPLAY_DISCONNECTED
++ SDL_EVENT_DISPLAY_REMOVED
 @@
 @@
 - SDL_DISPLAYEVENT_MOVED
@@ -3087,6 +3114,27 @@ expression e1, e2, e3, e4;
 + SDL_WindowHasSurface
   (...)
 @@
+@@
+- SDL_SetWindowGrab
++ SDL_SetWindowMouseGrab
+  (...)
+@@
+@@
+- SDL_ShowCursor(1)
++ SDL_ShowCursor()
+@@
+@@
+- SDL_ShowCursor(0)
++ SDL_HideCursor()
+@@
+@@
+- SDL_ShowCursor(SDL_TRUE)
++ SDL_ShowCursor()
+@@
+@@
+- SDL_ShowCursor(SDL_FALSE)
++ SDL_HideCursor()
+@@
 SDL_PixelFormat e1;
 @@
 - e1.BitsPerPixel
@@ -3337,10 +3385,10 @@ typedef SDL_Colour, SDL_Color;
 + SDL_MixAudio
   (...)
 @@
+expression e1, e2, e3, e4;
 @@
-- SDL_BlitScaled
-+ SDL_BlitSurfaceScaled
-  (...)
+- SDL_BlitScaled(e1, e2, e3, e4)
++ SDL_BlitSurfaceScaled(e1, e2, e3, e4, SDL_SCALEMODE_NEAREST)
 @@
 @@
 - SDL_SYSTEM_CURSOR_ARROW
diff --git a/docs/README-migration.md b/docs/README-migration.md
index 74b3bc488f4d5..ee07b7e0c900a 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -1859,6 +1859,8 @@ SDL_SetSurfaceColorKey() takes an bool to enable and disable colorkey. RLE accel
 
 SDL_SetSurfaceRLE() takes an bool to enable and disable RLE acceleration.
 
+SDL_PremultiplyAlpha() takes an extra bool parameter ("linear"). For SDL2 compatibility, pass false for this parameter.
+
 The following functions have been renamed:
 * SDL_BlitScaled() => SDL_BlitSurfaceScaled(), returns bool
 * SDL_ConvertSurfaceFormat() => SDL_ConvertSurface()