From d9f9e9e7648f286fe177e8a2e47bb205924a0991 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 3 Aug 2024 11:13:33 -0700
Subject: [PATCH] Added SDL_HINT_VIDEO_DUMMY_SAVE_FRAMES and
SDL_HINT_VIDEO_OFFSCREEN_SAVE_FRAMES
---
include/SDL3/SDL_hints.h | 26 +++++++++++++++++++
src/video/dummy/SDL_nullframebuffer.c | 2 +-
.../offscreen/SDL_offscreenframebuffer.c | 2 +-
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h
index 4da310ce76d03..dedc8a9b58bba 100644
--- a/include/SDL3/SDL_hints.h
+++ b/include/SDL3/SDL_hints.h
@@ -3037,6 +3037,18 @@ extern "C" {
*/
#define SDL_HINT_VIDEO_DRIVER "SDL_VIDEO_DRIVER"
+/**
+ * A variable controlling whether the dummy video driver saves output frames.
+ *
+ * - "0": Video frames are not saved to disk. (default)
+ * - "1": Video frames are saved to files in the format "SDL_windowX-Y.bmp", where X is the window ID, and Y is the frame number.
+ *
+ * This hint can be set anytime.
+ *
+ * \since This hint is available since SDL 3.0.0.
+ */
+#define SDL_HINT_VIDEO_DUMMY_SAVE_FRAMES "SDL_VIDEO_DUMMY_SAVE_FRAMES"
+
/**
* If eglGetPlatformDisplay fails, fall back to calling eglGetDisplay.
*
@@ -3101,6 +3113,20 @@ extern "C" {
*/
#define SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS"
+/**
+ * A variable controlling whether the offscreen video driver saves output frames.
+ *
+ * This only saves frames that are generated using software rendering, not accelerated OpenGL rendering.
+ *
+ * - "0": Video frames are not saved to disk. (default)
+ * - "1": Video frames are saved to files in the format "SDL_windowX-Y.bmp", where X is the window ID, and Y is the frame number.
+ *
+ * This hint can be set anytime.
+ *
+ * \since This hint is available since SDL 3.0.0.
+ */
+#define SDL_HINT_VIDEO_OFFSCREEN_SAVE_FRAMES "SDL_VIDEO_OFFSCREEN_SAVE_FRAMES"
+
/**
* A variable controlling whether all window operations will block until
* complete.
diff --git a/src/video/dummy/SDL_nullframebuffer.c b/src/video/dummy/SDL_nullframebuffer.c
index f1311cfbe4a95..b1c19ac48a245 100644
--- a/src/video/dummy/SDL_nullframebuffer.c
+++ b/src/video/dummy/SDL_nullframebuffer.c
@@ -61,7 +61,7 @@ int SDL_DUMMY_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window
}
/* Send the data to the display */
- if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
+ if (SDL_GetHintBoolean(SDL_HINT_VIDEO_DUMMY_SAVE_FRAMES, SDL_FALSE)) {
char file[128];
(void)SDL_snprintf(file, sizeof(file), "SDL_window%" SDL_PRIu32 "-%8.8d.bmp",
SDL_GetWindowID(window), ++frame_number);
diff --git a/src/video/offscreen/SDL_offscreenframebuffer.c b/src/video/offscreen/SDL_offscreenframebuffer.c
index 82bb536d8ae51..e64a2452512e2 100644
--- a/src/video/offscreen/SDL_offscreenframebuffer.c
+++ b/src/video/offscreen/SDL_offscreenframebuffer.c
@@ -62,7 +62,7 @@ int SDL_OFFSCREEN_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *wi
}
/* Send the data to the display */
- if (SDL_getenv("SDL_VIDEO_OFFSCREEN_SAVE_FRAMES")) {
+ if (SDL_GetHintBoolean(SDL_HINT_VIDEO_OFFSCREEN_SAVE_FRAMES, SDL_FALSE)) {
char file[128];
(void)SDL_snprintf(file, sizeof(file), "SDL_window%" SDL_PRIu32 "-%8.8d.bmp",
SDL_GetWindowID(window), ++frame_number);