SDL: Add SDL_GetRenderVSync (see #6495) (#6965)

From 851b0e16beacb5dcf322d5af2d0df569cf306395 Mon Sep 17 00:00:00 2001
From: Sylvain Becker <[EMAIL REDACTED]>
Date: Mon, 2 Jan 2023 20:21:02 +0100
Subject: [PATCH] Add SDL_GetRenderVSync (see #6495) (#6965)

---
 WhatsNew.txt                      |  1 +
 include/SDL3/SDL_render.h         | 11 +++++++++++
 src/dynapi/SDL_dynapi.sym         |  1 +
 src/dynapi/SDL_dynapi_overrides.h |  1 +
 src/dynapi/SDL_dynapi_procs.h     |  1 +
 src/render/SDL_render.c           | 10 ++++++++++
 6 files changed, 25 insertions(+)

diff --git a/WhatsNew.txt b/WhatsNew.txt
index e6befaaa4005..56172f41ba20 100644
--- a/WhatsNew.txt
+++ b/WhatsNew.txt
@@ -20,3 +20,4 @@ General:
 * Added SDL_DelayNS() to specify a delay in nanoseconds, to the highest precision the system will support
 * The timestamp member of the SDL_Event structure is now in nanoseconds, filled in with the time the event was generated, or the time it was queued if that's not available
 * Added SDL_modf() and SDL_modff() to separate the whole and fractional portions of a floating point number
+* Added SDL_GetRenderVSync() to get vsync of the given renderer
diff --git a/include/SDL3/SDL_render.h b/include/SDL3/SDL_render.h
index 3eda734b1242..c772c4759422 100644
--- a/include/SDL3/SDL_render.h
+++ b/include/SDL3/SDL_render.h
@@ -1925,6 +1925,17 @@ extern DECLSPEC void *SDLCALL SDL_GetRenderMetalCommandEncoder(SDL_Renderer * re
  */
 extern DECLSPEC int SDLCALL SDL_SetRenderVSync(SDL_Renderer* renderer, int vsync);
 
+/**
+ * Get VSync of the given renderer.
+ *
+ * \param renderer The renderer to toggle
+ * \param set output vsync 1 for on, 0 for off. All other values are reserved
+ * \returns a 0 int on success, or non-zero on failure
+ *
+ * \since This function is available since SDL 3.0.0.
+ */
+extern DECLSPEC int SDLCALL SDL_GetRenderVSync(SDL_Renderer *renderer, int *vsync);
+
 /* Ends C function definitions when using C++ */
 #ifdef __cplusplus
 }
diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym
index 0d22987c4936..ac9ab4da8d8c 100644
--- a/src/dynapi/SDL_dynapi.sym
+++ b/src/dynapi/SDL_dynapi.sym
@@ -856,6 +856,7 @@ SDL3_0.0.0 {
     SDL_wcsstr;
     SDL_modf;
     SDL_modff;
+    SDL_GetRenderVSync;
     # extra symbols go here (don't modify this line)
   local: *;
 };
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index b88702ce8082..39f822710cdd 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -884,3 +884,4 @@
 /* New API symbols are added at the end */
 #define SDL_modf SDL_modf_REAL
 #define SDL_modff SDL_modff_REAL
+#define SDL_GetRenderVSync SDL_GetRenderVSync_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 069178d22a0c..79517f8ac516 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -929,3 +929,4 @@ SDL_DYNAPI_PROC(wchar_t*,SDL_wcsstr,(const wchar_t *a, const wchar_t *b),(a,b),r
 /* New API symbols are added at the end */
 SDL_DYNAPI_PROC(double,SDL_modf,(double a, double *b),(a,b),return)
 SDL_DYNAPI_PROC(float,SDL_modff,(float a, float *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GetRenderVSync,(SDL_Renderer *a, int *b),(a,b),return)
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 204b7d399c0a..81edcf32499a 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -4492,3 +4492,13 @@ int SDL_SetRenderVSync(SDL_Renderer *renderer, int vsync)
     }
     return 0;
 }
+
+int SDL_GetRenderVSync(SDL_Renderer *renderer, int *vsync)
+{
+    CHECK_RENDERER_MAGIC(renderer, -1);
+    if (vsync == NULL) {
+        return SDL_InvalidParamError("vsync");
+    }
+    *vsync = renderer->wanted_vsync;
+    return 0;
+}