From a97dadf7793c6b720861020b0545b8deca73369b Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 3 Aug 2024 10:52:58 -0700
Subject: [PATCH] Added hints to replace environment variables on the
PlayStation Vita
---
docs/README-migration.md | 6 +++
include/SDL3/SDL_hints.h | 80 +++++++++++++++++++++++++++++++
src/video/vita/SDL_vitagl_pvr.c | 8 ++--
src/video/vita/SDL_vitagles_pvr.c | 7 ++-
src/video/vita/SDL_vitatouch.c | 10 ++--
src/video/vita/SDL_vitavideo.c | 13 ++---
6 files changed, 105 insertions(+), 19 deletions(-)
diff --git a/docs/README-migration.md b/docs/README-migration.md
index 1de129e0dd7f7..b0f432b14920c 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -812,6 +812,12 @@ The following environment variables have been removed:
* SDL_DISKAUDIOFILE - replaced with the hint SDL_HINT_AUDIO_DISK_OUTPUT_FILE
* SDL_DISKAUDIOFILEIN - replaced with the hint SDL_HINT_AUDIO_DISK_INPUT_FILE
* SDL_DUMMYAUDIODELAY - replaced with the hint SDL_HINT_AUDIO_DUMMY_TIMESCALE which allows scaling the audio time rather than specifying an absolute delay.
+* VITA_DISABLE_TOUCH_BACK - replaced with the hint SDL_HINT_VITA_ENABLE_BACK_TOUCH
+* VITA_DISABLE_TOUCH_FRONT - replaced with the hint SDL_HINT_VITA_ENABLE_FRONT_TOUCH
+* VITA_MODULE_PATH - replaced with the hint SDL_HINT_VITA_MODULE_PATH
+* VITA_PVR_OGL - replaced with the hint SDL_HINT_VITA_PVR_OPENGL
+* VITA_PVR_SKIP_INIT - replaced with the hint SDL_HINT_VITA_PVR_INIT
+* VITA_RESOLUTION - replaced with the hint SDL_HINT_VITA_RESOLUTION
The following functions have been removed:
* SDL_ClearHints() - replaced with SDL_ResetHints()
diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h
index 84682c8b8e475..4da310ce76d03 100644
--- a/include/SDL3/SDL_hints.h
+++ b/include/SDL3/SDL_hints.h
@@ -3357,6 +3357,86 @@ extern "C" {
*/
#define SDL_HINT_VIDEO_X11_XRANDR "SDL_VIDEO_X11_XRANDR"
+/**
+ * A variable controlling whether touch should be enabled on the back panel of the PlayStation Vita.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": Disable touch on the back panel.
+ * - "1": Enable touch on the back panel. (default)
+ *
+ * This hint should be set before SDL is initialized.
+ *
+ * \since This hint is available since SDL 3.0.0.
+ */
+#define SDL_HINT_VITA_ENABLE_BACK_TOUCH "SDL_VITA_ENABLE_BACK_TOUCH"
+
+/**
+ * A variable controlling whether touch should be enabled on the front panel of the PlayStation Vita.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": Disable touch on the front panel.
+ * - "1": Enable touch on the front panel. (default)
+ *
+ * This hint should be set before SDL is initialized.
+ *
+ * \since This hint is available since SDL 3.0.0.
+ */
+#define SDL_HINT_VITA_ENABLE_FRONT_TOUCH "SDL_VITA_ENABLE_FRONT_TOUCH"
+
+/**
+ * A variable controlling the module path on the PlayStation Vita.
+ *
+ * This hint defaults to "app0:module"
+ *
+ * This hint should be set before SDL is initialized.
+ *
+ * \since This hint is available since SDL 3.0.0.
+ */
+#define SDL_HINT_VITA_MODULE_PATH "SDL_VITA_MODULE_PATH"
+
+/**
+ * A variable controlling whether to perform PVR initialization on the PlayStation Vita.
+ *
+ * - "0": Skip PVR initialization.
+ * - "1": Perform the normal PVR initialization. (default)
+ *
+ * This hint should be set before SDL is initialized.
+ *
+ * \since This hint is available since SDL 3.0.0.
+ */
+#define SDL_HINT_VITA_PVR_INIT "SDL_VITA_PVR_INIT"
+
+/**
+ * A variable overriding the resolution reported on the PlayStation Vita.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "544": 544p (default)
+ * - "720": 725p for PSTV
+ * - "1080": 1088i for PSTV
+ *
+ * This hint should be set before SDL is initialized.
+ *
+ * \since This hint is available since SDL 3.0.0.
+ */
+#define SDL_HINT_VITA_RESOLUTION "SDL_VITA_RESOLUTION"
+
+/**
+ * A variable controlling whether OpenGL should be used instead of OpenGL ES on the PlayStation Vita.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": Use OpenGL ES. (default)
+ * - "1": Use OpenGL.
+ *
+ * This hint should be set before SDL is initialized.
+ *
+ * \since This hint is available since SDL 3.0.0.
+ */
+#define SDL_HINT_VITA_PVR_OPENGL "SDL_VITA_PVR_OPENGL"
+
/**
* A variable controlling which touchpad should generate synthetic mouse
* events.
diff --git a/src/video/vita/SDL_vitagl_pvr.c b/src/video/vita/SDL_vitagl_pvr.c
index a8c6b03fab187..886a0a0f3c815 100644
--- a/src/video/vita/SDL_vitagl_pvr.c
+++ b/src/video/vita/SDL_vitagl_pvr.c
@@ -46,13 +46,13 @@ static void getFBSize(int *width, int *height)
int VITA_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
{
PVRSRV_PSP2_APPHINT hint;
- const char *override = SDL_getenv("VITA_MODULE_PATH");
- const char *skip_init = SDL_getenv("VITA_PVR_SKIP_INIT");
char *default_path = "app0:module";
char target_path[MAX_PATH];
- if (!skip_init) { // we don't care about actual value
- if (override) {
+ if (SDL_GetHintBoolean(SDL_HINT_VITA_PVR_INIT, SDL_TRUE)) {
+ const char *override = SDL_GetHint(SDL_HINT_VITA_MODULE_PATH);
+
+ if (override && *override) {
default_path = override;
}
diff --git a/src/video/vita/SDL_vitagles_pvr.c b/src/video/vita/SDL_vitagles_pvr.c
index 0e7d407458984..acc9ba8f3d24b 100644
--- a/src/video/vita/SDL_vitagles_pvr.c
+++ b/src/video/vita/SDL_vitagles_pvr.c
@@ -35,14 +35,13 @@
int VITA_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
{
PVRSRV_PSP2_APPHINT hint;
- const char *override = SDL_getenv("VITA_MODULE_PATH");
- const char *skip_init = SDL_getenv("VITA_PVR_SKIP_INIT");
const char *default_path = "app0:module";
char target_path[MAX_PATH];
- if (!skip_init) { // we don't care about actual value
+ if (SDL_GetHintBoolean(SDL_HINT_VITA_PVR_INIT, SDL_TRUE)) {
+ const char *override = SDL_GetHint(SDL_HINT_VITA_MODULE_PATH);
- if (override) {
+ if (override && *override) {
default_path = override;
}
diff --git a/src/video/vita/SDL_vitatouch.c b/src/video/vita/SDL_vitatouch.c
index 0520b8b99ea12..aab16cc5dc4de 100644
--- a/src/video/vita/SDL_vitatouch.c
+++ b/src/video/vita/SDL_vitatouch.c
@@ -41,13 +41,13 @@ struct
float range;
} force_info[SCE_TOUCH_PORT_MAX_NUM];
-const char *disableFrontPoll = NULL;
-const char *disableBackPoll = NULL;
+static SDL_bool disableFrontPoll;
+static SDL_bool disableBackPoll;
void VITA_InitTouch(void)
{
- disableFrontPoll = SDL_getenv("VITA_DISABLE_TOUCH_FRONT");
- disableBackPoll = SDL_getenv("VITA_DISABLE_TOUCH_BACK");
+ disableFrontPoll = !SDL_GetHintBoolean(SDL_HINT_VITA_ENABLE_FRONT_TOUCH, SDL_TRUE);
+ disableBackPoll = !SDL_GetHintBoolean(SDL_HINT_VITA_ENABLE_BACK_TOUCH, SDL_TRUE);
sceTouchSetSamplingState(SCE_TOUCH_PORT_FRONT, SCE_TOUCH_SAMPLING_STATE_START);
sceTouchSetSamplingState(SCE_TOUCH_PORT_BACK, SCE_TOUCH_SAMPLING_STATE_START);
@@ -92,7 +92,7 @@ void VITA_PollTouch(void)
SDL_memcpy(touch_old, touch, sizeof(touch_old));
for (port = 0; port < SCE_TOUCH_PORT_MAX_NUM; port++) {
- /** Skip polling of Touch Device if environment variable is set **/
+ /** Skip polling of Touch Device if hint is set **/
if (((port == 0) && disableFrontPoll) || ((port == 1) && disableBackPoll)) {
continue;
}
diff --git a/src/video/vita/SDL_vitavideo.c b/src/video/vita/SDL_vitavideo.c
index c5ced23e3461b..3c6654c9b12d6 100644
--- a/src/video/vita/SDL_vitavideo.c
+++ b/src/video/vita/SDL_vitavideo.c
@@ -125,7 +125,7 @@ static SDL_VideoDevice *VITA_Create(void)
#if defined(SDL_VIDEO_VITA_PIB) || defined(SDL_VIDEO_VITA_PVR)
#ifdef SDL_VIDEO_VITA_PVR_OGL
- if (SDL_getenv("VITA_PVR_OGL") != NULL) {
+ if (SDL_GetHintBoolean(SDL_HINT_VITA_PVR_OPENGL, SDL_FALSE)) {
device->GL_LoadLibrary = VITA_GL_LoadLibrary;
device->GL_CreateContext = VITA_GL_CreateContext;
device->GL_GetProcAddress = VITA_GL_GetProcAddress;
@@ -170,19 +170,19 @@ int VITA_VideoInit(SDL_VideoDevice *_this)
{
SDL_DisplayMode mode;
#ifdef SDL_VIDEO_VITA_PVR
- const char *res = SDL_getenv("VITA_RESOLUTION");
+ const char *res = SDL_GetHint(SDL_HINT_VITA_RESOLUTION);
#endif
SDL_zero(mode);
#ifdef SDL_VIDEO_VITA_PVR
if (res) {
/* 1088i for PSTV (Or Sharpscale) */
- if (!SDL_strncmp(res, "1080", 4)) {
+ if (SDL_strncmp(res, "1080", 4) == 0) {
mode.w = 1920;
mode.h = 1088;
}
/* 725p for PSTV (Or Sharpscale) */
- else if (!SDL_strncmp(res, "720", 3)) {
+ else if (SDL_strncmp(res, "720", 3) == 0) {
mode.w = 1280;
mode.h = 725;
}
@@ -261,7 +261,8 @@ int VITA_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properties
win.windowSize = PSP2_WINDOW_960X544;
}
if (window->flags & SDL_WINDOW_OPENGL) {
- if (SDL_getenv("VITA_PVR_OGL") != NULL) {
+ SDL_bool use_opengl = SDL_GetHintBoolean(SDL_HINT_VITA_PVR_OPENGL, SDL_FALSE);
+ if (use_opengl) {
/* Set version to 2.1 and PROFILE to ES */
temp_major = _this->gl_config.major_version;
temp_minor = _this->gl_config.minor_version;
@@ -275,7 +276,7 @@ int VITA_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properties
if (wdata->egl_surface == EGL_NO_SURFACE) {
return SDL_SetError("Could not create GLES window surface");
}
- if (SDL_getenv("VITA_PVR_OGL") != NULL) {
+ if (use_opengl) {
/* Revert */
_this->gl_config.major_version = temp_major;
_this->gl_config.minor_version = temp_minor;