summaryrefslogtreecommitdiff
path: root/contrib/SDL-3.2.8/src/video/vita
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/SDL-3.2.8/src/video/vita')
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitaframebuffer.c116
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitaframebuffer.h25
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitagl_pvr.c122
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitagl_pvr_c.h31
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitagles.c217
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitagles_c.h53
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitagles_pvr.c92
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitagles_pvr_c.h32
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitakeyboard.c190
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitakeyboard.h31
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitamessagebox.c125
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitamessagebox.h31
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitamouse.c105
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitamouse_c.h31
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitatouch.c186
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitatouch.h33
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitavideo.c592
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitavideo.h106
18 files changed, 2118 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitaframebuffer.c b/contrib/SDL-3.2.8/src/video/vita/SDL_vitaframebuffer.c
new file mode 100644
index 0000000..b9bfb50
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitaframebuffer.c
@@ -0,0 +1,116 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21#include "SDL_internal.h"
22
23#ifdef SDL_VIDEO_DRIVER_VITA
24
25#include "SDL_vitavideo.h"
26
27#include <psp2/kernel/sysmem.h>
28
29#define SCREEN_W 960
30#define SCREEN_H 544
31#define ALIGN(x, a) (((x) + ((a)-1)) & ~((a)-1))
32#define DISPLAY_PIXEL_FORMAT SCE_DISPLAY_PIXELFORMAT_A8B8G8R8
33
34void *vita_gpu_alloc(unsigned int type, unsigned int size, SceUID *uid)
35{
36 void *mem;
37
38 if (type == SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW) {
39 size = ALIGN(size, 256 * 1024);
40 } else {
41 size = ALIGN(size, 4 * 1024);
42 }
43
44 *uid = sceKernelAllocMemBlock("gpu_mem", type, size, NULL);
45
46 if (*uid < 0) {
47 return NULL;
48 }
49
50 if (sceKernelGetMemBlockBase(*uid, &mem) < 0) {
51 return NULL;
52 }
53
54 return mem;
55}
56
57void vita_gpu_free(SceUID uid)
58{
59 void *mem = NULL;
60 if (sceKernelGetMemBlockBase(uid, &mem) < 0) {
61 return;
62 }
63 sceKernelFreeMemBlock(uid);
64}
65
66bool VITA_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch)
67{
68 SDL_WindowData *data = window->internal;
69 SceDisplayFrameBuf framebuf;
70
71 *format = SDL_PIXELFORMAT_ABGR8888;
72 *pitch = SCREEN_W * 4;
73
74 data->buffer = vita_gpu_alloc(
75 SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW,
76 4 * SCREEN_W * SCREEN_H,
77 &data->buffer_uid);
78
79 // SDL_memset the buffer to black
80 SDL_memset(data->buffer, 0x0, SCREEN_W * SCREEN_H * 4);
81
82 SDL_memset(&framebuf, 0x00, sizeof(SceDisplayFrameBuf));
83 framebuf.size = sizeof(SceDisplayFrameBuf);
84 framebuf.base = data->buffer;
85 framebuf.pitch = SCREEN_W;
86 framebuf.pixelformat = DISPLAY_PIXEL_FORMAT;
87 framebuf.width = SCREEN_W;
88 framebuf.height = SCREEN_H;
89 sceDisplaySetFrameBuf(&framebuf, SCE_DISPLAY_SETBUF_NEXTFRAME);
90
91 *pixels = data->buffer;
92
93 return true;
94}
95
96bool VITA_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects)
97{
98 // do nothing
99 return true;
100}
101
102void VITA_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window)
103{
104 SDL_WindowData *data = window->internal;
105
106 if (!data) {
107 // The window wasn't fully initialized
108 return;
109 }
110
111 vita_gpu_free(data->buffer_uid);
112 data->buffer = NULL;
113 return;
114}
115
116#endif // SDL_VIDEO_DRIVER_VITA
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitaframebuffer.h b/contrib/SDL-3.2.8/src/video/vita/SDL_vitaframebuffer.h
new file mode 100644
index 0000000..b85e9c3
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitaframebuffer.h
@@ -0,0 +1,25 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21#include "SDL_internal.h"
22
23extern bool VITA_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch);
24extern bool VITA_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects);
25extern void VITA_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window);
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitagl_pvr.c b/contrib/SDL-3.2.8/src/video/vita/SDL_vitagl_pvr.c
new file mode 100644
index 0000000..1255e4e
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitagl_pvr.c
@@ -0,0 +1,122 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21#include "SDL_internal.h"
22
23#if defined(SDL_VIDEO_DRIVER_VITA) && defined(SDL_VIDEO_VITA_PVR) && defined(SDL_VIDEO_VITA_PVR_OGL)
24#include <stdlib.h>
25#include <string.h>
26#include <psp2/kernel/modulemgr.h>
27#include <gpu_es4/psp2_pvr_hint.h>
28#include <gl4esinit.h>
29
30#include "SDL_vitavideo.h"
31#include "../SDL_egl_c.h"
32#include "SDL_vitagl_pvr_c.h"
33
34#define MAX_PATH 256 // vita limits are somehow wrong
35
36// Defaults
37static int FB_WIDTH = 960;
38static int FB_HEIGHT = 544;
39
40static void getFBSize(int *width, int *height)
41{
42 *width = FB_WIDTH;
43 *height = FB_HEIGHT;
44}
45
46bool VITA_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
47{
48 PVRSRV_PSP2_APPHINT hint;
49 char *default_path = "app0:module";
50 char target_path[MAX_PATH];
51
52 if (SDL_GetHintBoolean(SDL_HINT_VITA_PVR_INIT, true)) {
53 const char *override = SDL_GetHint(SDL_HINT_VITA_MODULE_PATH);
54
55 if (override && *override) {
56 default_path = override;
57 }
58
59 sceKernelLoadStartModule("vs0:sys/external/libfios2.suprx", 0, NULL, 0, NULL, NULL);
60 sceKernelLoadStartModule("vs0:sys/external/libc.suprx", 0, NULL, 0, NULL, NULL);
61
62 SDL_snprintf(target_path, MAX_PATH, "%s/%s", default_path, "libGL.suprx");
63 sceKernelLoadStartModule(target_path, 0, NULL, 0, NULL, NULL);
64
65 SDL_snprintf(target_path, MAX_PATH, "%s/%s", default_path, "libgpu_es4_ext.suprx");
66 sceKernelLoadStartModule(target_path, 0, NULL, 0, NULL, NULL);
67
68 SDL_snprintf(target_path, MAX_PATH, "%s/%s", default_path, "libIMGEGL.suprx");
69 sceKernelLoadStartModule(target_path, 0, NULL, 0, NULL, NULL);
70
71 PVRSRVInitializeAppHint(&hint);
72
73 SDL_snprintf(hint.szGLES1, MAX_PATH, "%s/%s", default_path, "libGLESv1_CM.suprx");
74 SDL_snprintf(hint.szGLES2, MAX_PATH, "%s/%s", default_path, "libGLESv2.suprx");
75 SDL_snprintf(hint.szWindowSystem, MAX_PATH, "%s/%s", default_path, "libpvrPSP2_WSEGL.suprx");
76
77 PVRSRVCreateVirtualAppHint(&hint);
78 }
79
80 return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)0, 0);
81}
82
83SDL_GLContext VITA_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
84{
85 char gl_version[3];
86 SDL_GLContext context = NULL;
87 int temp_major = _this->gl_config.major_version;
88 int temp_minor = _this->gl_config.minor_version;
89 int temp_profile = _this->gl_config.profile_mask;
90
91 // Set version to 2.0 and PROFILE to ES
92 _this->gl_config.major_version = 2;
93 _this->gl_config.minor_version = 0;
94 _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
95
96 context = SDL_EGL_CreateContext(_this, window->internal->egl_surface);
97
98 if (context != NULL) {
99 FB_WIDTH = window->w;
100 FB_HEIGHT = window->h;
101 set_getprocaddress((void *(*)(const char *))eglGetProcAddress);
102 set_getmainfbsize(getFBSize);
103 SDL_snprintf(gl_version, 3, "%d%d", temp_major, temp_minor);
104 gl4es_setenv("LIBGL_NOTEXRECT", "1", 1); // Currently broken in driver
105 gl4es_setenv("LIBGL_GL", gl_version, 1);
106 initialize_gl4es();
107 }
108
109 // Restore gl_config
110 _this->gl_config.major_version = temp_major;
111 _this->gl_config.minor_version = temp_minor;
112 _this->gl_config.profile_mask = temp_profile;
113
114 return context;
115}
116
117SDL_FunctionPointer VITA_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc)
118{
119 return gl4es_GetProcAddress(proc);
120}
121
122#endif // SDL_VIDEO_DRIVER_VITA && SDL_VIDEO_VITA_PVR
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitagl_pvr_c.h b/contrib/SDL-3.2.8/src/video/vita/SDL_vitagl_pvr_c.h
new file mode 100644
index 0000000..118602d
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitagl_pvr_c.h
@@ -0,0 +1,31 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#ifndef SDL_vitagl_pvr_c_h_
23#define SDL_vitagl_pvr_c_h_
24
25#include "SDL_vitavideo.h"
26
27extern SDL_GLContext VITA_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window);
28extern int VITA_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path);
29extern SDL_FunctionPointer VITA_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc);
30
31#endif // SDL_vitagl_pvr_c_h_
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitagles.c b/contrib/SDL-3.2.8/src/video/vita/SDL_vitagles.c
new file mode 100644
index 0000000..2c74447
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitagles.c
@@ -0,0 +1,217 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21#include "SDL_internal.h"
22
23#if defined(SDL_VIDEO_DRIVER_VITA) && defined(SDL_VIDEO_VITA_PIB)
24#include <stdlib.h>
25#include <string.h>
26
27#include "SDL_vitavideo.h"
28#include "SDL_vitagles_c.h"
29
30/*****************************************************************************/
31// SDL OpenGL/OpenGL ES functions
32/*****************************************************************************/
33#define EGLCHK(stmt) \
34 do { \
35 EGLint err; \
36 \
37 stmt; \
38 err = eglGetError(); \
39 if (err != EGL_SUCCESS) { \
40 SDL_SetError("EGL error %d", err); \
41 return NULL; \
42 } \
43 } while (0)
44
45void VITA_GLES_KeyboardCallback(ScePigletPreSwapData *data)
46{
47 SceCommonDialogUpdateParam commonDialogParam;
48 SDL_zero(commonDialogParam);
49 commonDialogParam.renderTarget.colorFormat = data->colorFormat;
50 commonDialogParam.renderTarget.surfaceType = data->surfaceType;
51 commonDialogParam.renderTarget.colorSurfaceData = data->colorSurfaceData;
52 commonDialogParam.renderTarget.depthSurfaceData = data->depthSurfaceData;
53 commonDialogParam.renderTarget.width = data->width;
54 commonDialogParam.renderTarget.height = data->height;
55 commonDialogParam.renderTarget.strideInPixels = data->strideInPixels;
56 commonDialogParam.displaySyncObject = data->displaySyncObject;
57
58 sceCommonDialogUpdate(&commonDialogParam);
59}
60
61bool VITA_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
62{
63 pibInit(PIB_SHACCCG | PIB_GET_PROC_ADDR_CORE);
64 return true;
65}
66
67SDL_FunctionPointer VITA_GLES_GetProcAddress(SDL_VideoDevice *_this, const char *proc)
68{
69 return eglGetProcAddress(proc);
70}
71
72void VITA_GLES_UnloadLibrary(SDL_VideoDevice *_this)
73{
74 eglTerminate(_this->gl_data->display);
75}
76
77static EGLint width = 960;
78static EGLint height = 544;
79
80SDL_GLContext VITA_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
81{
82
83 SDL_WindowData *wdata = window->internal;
84
85 EGLint attribs[32];
86 EGLDisplay display;
87 EGLContext context;
88 EGLSurface surface;
89 EGLConfig config;
90 EGLint num_configs;
91 PFNEGLPIGLETVITASETPRESWAPCALLBACKSCEPROC preSwapCallback;
92 int i;
93
94 const EGLint contextAttribs[] = {
95 EGL_CONTEXT_CLIENT_VERSION, 2,
96 EGL_NONE
97 };
98
99 EGLCHK(display = eglGetDisplay(0));
100
101 EGLCHK(eglInitialize(display, NULL, NULL));
102 wdata->uses_gles = true;
103 window->flags |= SDL_WINDOW_FULLSCREEN;
104
105 EGLCHK(eglBindAPI(EGL_OPENGL_ES_API));
106
107 i = 0;
108 attribs[i++] = EGL_RED_SIZE;
109 attribs[i++] = 8;
110 attribs[i++] = EGL_GREEN_SIZE;
111 attribs[i++] = 8;
112 attribs[i++] = EGL_BLUE_SIZE;
113 attribs[i++] = 8;
114 attribs[i++] = EGL_DEPTH_SIZE;
115 attribs[i++] = 0;
116 attribs[i++] = EGL_ALPHA_SIZE;
117 attribs[i++] = 8;
118 attribs[i++] = EGL_STENCIL_SIZE;
119 attribs[i++] = 0;
120
121 attribs[i++] = EGL_SURFACE_TYPE;
122 attribs[i++] = 5;
123
124 attribs[i++] = EGL_RENDERABLE_TYPE;
125 attribs[i++] = EGL_OPENGL_ES2_BIT;
126
127 attribs[i++] = EGL_CONFORMANT;
128 attribs[i++] = EGL_OPENGL_ES2_BIT;
129
130 attribs[i++] = EGL_NONE;
131
132 EGLCHK(eglChooseConfig(display, attribs, &config, 1, &num_configs));
133
134 if (num_configs == 0) {
135 SDL_SetError("No valid EGL configs for requested mode");
136 return NULL;
137 }
138
139 EGLCHK(surface = eglCreateWindowSurface(display, config, VITA_WINDOW_960X544, NULL));
140
141 EGLCHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs));
142
143 EGLCHK(eglMakeCurrent(display, surface, surface, context));
144
145 EGLCHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
146 EGLCHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));
147
148 _this->gl_data->display = display;
149 _this->gl_data->context = context;
150 _this->gl_data->surface = surface;
151
152 preSwapCallback = (PFNEGLPIGLETVITASETPRESWAPCALLBACKSCEPROC)eglGetProcAddress("eglPigletVitaSetPreSwapCallbackSCE");
153 preSwapCallback(VITA_GLES_KeyboardCallback);
154
155 return context;
156}
157
158bool VITA_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context)
159{
160 if (!eglMakeCurrent(_this->gl_data->display, _this->gl_data->surface,
161 _this->gl_data->surface, _this->gl_data->context)) {
162 return SDL_SetError("Unable to make EGL context current");
163 }
164 return true;
165}
166
167bool VITA_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval)
168{
169 EGLBoolean status;
170 status = eglSwapInterval(_this->gl_data->display, interval);
171 if (status == EGL_TRUE) {
172 // Return success to upper level
173 _this->gl_data->swapinterval = interval;
174 return true;
175 }
176 // Failed to set swap interval
177 return SDL_SetError("Unable to set the EGL swap interval");
178}
179
180bool VITA_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval)
181{
182 *interval = _this->gl_data->swapinterval;
183 return true;
184}
185
186bool VITA_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
187{
188 if (!eglSwapBuffers(_this->gl_data->display, _this->gl_data->surface)) {
189 return SDL_SetError("eglSwapBuffers() failed");
190 }
191 return true;
192}
193
194bool VITA_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context)
195{
196 SDL_VideoData *phdata = _this->internal;
197 EGLBoolean status;
198
199 if (phdata->egl_initialized != true) {
200 return SDL_SetError("VITA: GLES initialization failed, no OpenGL ES support");
201 }
202
203 // Check if OpenGL ES connection has been initialized
204 if (_this->gl_data->display != EGL_NO_DISPLAY) {
205 if (context != EGL_NO_CONTEXT) {
206 status = eglDestroyContext(_this->gl_data->display, context);
207 if (status != EGL_TRUE) {
208 // Error during OpenGL ES context destroying
209 return SDL_SetError("VITA: OpenGL ES context destroy error");
210 }
211 }
212 }
213
214 return true;
215}
216
217#endif // SDL_VIDEO_DRIVER_VITA
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitagles_c.h b/contrib/SDL-3.2.8/src/video/vita/SDL_vitagles_c.h
new file mode 100644
index 0000000..44cb14d
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitagles_c.h
@@ -0,0 +1,53 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#ifndef SDL_vitagles_c_h_
23#define SDL_vitagles_c_h_
24
25#include <pib.h>
26#include <EGL/egl.h>
27#include <EGL/eglext.h>
28#include <GLES2/gl2.h>
29#include <GLES2/gl2ext.h>
30
31#include "SDL_vitavideo.h"
32
33typedef struct SDL_GLDriverData
34{
35 EGLDisplay display;
36 EGLContext context;
37 EGLSurface surface;
38 uint32_t swapinterval;
39} SDL_GLDriverData;
40
41extern SDL_FunctionPointer VITA_GLES_GetProcAddress(SDL_VideoDevice *_this, const char *proc);
42extern bool VITA_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context);
43extern void VITA_GLES_SwapBuffers(SDL_VideoDevice *_this);
44
45extern bool VITA_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
46extern SDL_GLContext VITA_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window);
47
48extern bool VITA_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path);
49extern void VITA_GLES_UnloadLibrary(SDL_VideoDevice *_this);
50extern bool VITA_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval);
51extern bool VITA_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval);
52
53#endif // SDL_vitagles_c_h_
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitagles_pvr.c b/contrib/SDL-3.2.8/src/video/vita/SDL_vitagles_pvr.c
new file mode 100644
index 0000000..4ba0573
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitagles_pvr.c
@@ -0,0 +1,92 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21#include "SDL_internal.h"
22
23#if defined(SDL_VIDEO_DRIVER_VITA) && defined(SDL_VIDEO_VITA_PVR)
24#include <stdlib.h>
25#include <string.h>
26#include <psp2/kernel/modulemgr.h>
27#include <gpu_es4/psp2_pvr_hint.h>
28
29#include "SDL_vitavideo.h"
30#include "../SDL_egl_c.h"
31#include "SDL_vitagles_pvr_c.h"
32
33#define MAX_PATH 256 // vita limits are somehow wrong
34
35bool VITA_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
36{
37 PVRSRV_PSP2_APPHINT hint;
38 const char *default_path = "app0:module";
39 char target_path[MAX_PATH];
40
41 if (SDL_GetHintBoolean(SDL_HINT_VITA_PVR_INIT, true)) {
42 const char *override = SDL_GetHint(SDL_HINT_VITA_MODULE_PATH);
43
44 if (override && *override) {
45 default_path = override;
46 }
47
48 sceKernelLoadStartModule("vs0:sys/external/libfios2.suprx", 0, NULL, 0, NULL, NULL);
49 sceKernelLoadStartModule("vs0:sys/external/libc.suprx", 0, NULL, 0, NULL, NULL);
50
51 SDL_snprintf(target_path, MAX_PATH, "%s/%s", default_path, "libgpu_es4_ext.suprx");
52 sceKernelLoadStartModule(target_path, 0, NULL, 0, NULL, NULL);
53
54 SDL_snprintf(target_path, MAX_PATH, "%s/%s", default_path, "libIMGEGL.suprx");
55 sceKernelLoadStartModule(target_path, 0, NULL, 0, NULL, NULL);
56
57 PVRSRVInitializeAppHint(&hint);
58
59 SDL_snprintf(hint.szGLES1, MAX_PATH, "%s/%s", default_path, "libGLESv1_CM.suprx");
60 SDL_snprintf(hint.szGLES2, MAX_PATH, "%s/%s", default_path, "libGLESv2.suprx");
61 SDL_snprintf(hint.szWindowSystem, MAX_PATH, "%s/%s", default_path, "libpvrPSP2_WSEGL.suprx");
62
63 PVRSRVCreateVirtualAppHint(&hint);
64 }
65
66 return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)0, 0);
67}
68
69SDL_GLContext VITA_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
70{
71 return SDL_EGL_CreateContext(_this, window->internal->egl_surface);
72}
73
74bool VITA_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context)
75{
76 if (window && context) {
77 return SDL_EGL_MakeCurrent(_this, window->internal->egl_surface, context);
78 } else {
79 return SDL_EGL_MakeCurrent(_this, NULL, NULL);
80 }
81}
82
83bool VITA_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
84{
85 SDL_VideoData *videodata = _this->internal;
86 if (videodata->ime_active) {
87 sceImeUpdate();
88 }
89 return SDL_EGL_SwapBuffers(_this, window->internal->egl_surface);
90}
91
92#endif // SDL_VIDEO_DRIVER_VITA && SDL_VIDEO_VITA_PVR
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitagles_pvr_c.h b/contrib/SDL-3.2.8/src/video/vita/SDL_vitagles_pvr_c.h
new file mode 100644
index 0000000..ad87212
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitagles_pvr_c.h
@@ -0,0 +1,32 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#ifndef SDL_vitagles_pvr_c_h_
23#define SDL_vitagles_pvr_c_h_
24
25#include "SDL_vitavideo.h"
26
27extern bool VITA_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context);
28extern bool VITA_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
29extern SDL_GLContext VITA_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window);
30extern bool VITA_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path);
31
32#endif // SDL_vitagles_pvr_c_h_
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitakeyboard.c b/contrib/SDL-3.2.8/src/video/vita/SDL_vitakeyboard.c
new file mode 100644
index 0000000..9967756
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitakeyboard.c
@@ -0,0 +1,190 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21#include "SDL_internal.h"
22
23#ifdef SDL_VIDEO_DRIVER_VITA
24
25#include <psp2/kernel/processmgr.h>
26#include <psp2/ctrl.h>
27#include <psp2/hid.h>
28
29#include "SDL_vitavideo.h"
30#include "SDL_vitakeyboard.h"
31#include "../../events/SDL_keyboard_c.h"
32
33SceHidKeyboardReport k_reports[SCE_HID_MAX_REPORT];
34int keyboard_hid_handle = 0;
35Uint8 prev_keys[6] = { 0 };
36Uint8 prev_modifiers = 0;
37Uint8 locks = 0;
38Uint8 lock_key_down = 0;
39
40void VITA_InitKeyboard(void)
41{
42#ifdef SDL_VIDEO_VITA_PVR
43 sceSysmoduleLoadModule(SCE_SYSMODULE_IME); /** For PVR OSK Support **/
44#endif
45 sceHidKeyboardEnumerate(&keyboard_hid_handle, 1);
46
47 if (keyboard_hid_handle > 0) {
48 SDL_AddKeyboard((SDL_KeyboardID)keyboard_hid_handle, NULL, false);
49 }
50}
51
52void VITA_PollKeyboard(void)
53{
54 // We skip polling keyboard if no window is created
55 if (!Vita_Window) {
56 return;
57 }
58
59 if (keyboard_hid_handle > 0) {
60 SDL_KeyboardID keyboardID = (SDL_KeyboardID)keyboard_hid_handle;
61 int numReports = sceHidKeyboardRead(keyboard_hid_handle, (SceHidKeyboardReport **)&k_reports, SCE_HID_MAX_REPORT);
62
63 if (numReports < 0) {
64 keyboard_hid_handle = 0;
65 } else if (numReports) {
66 // Numlock and Capslock state changes only on a pressed event
67 // The k_report only reports the state of the LED
68 if (k_reports[numReports - 1].modifiers[1] & 0x1) {
69 if (!(locks & 0x1)) {
70 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_NUMLOCKCLEAR, true);
71 locks |= 0x1;
72 }
73 } else {
74 if (locks & 0x1) {
75 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_NUMLOCKCLEAR, false);
76 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_NUMLOCKCLEAR, true);
77 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_NUMLOCKCLEAR, false);
78 locks &= ~0x1;
79 }
80 }
81
82 if (k_reports[numReports - 1].modifiers[1] & 0x2) {
83 if (!(locks & 0x2)) {
84 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_CAPSLOCK, true);
85 locks |= 0x2;
86 }
87 } else {
88 if (locks & 0x2) {
89 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_CAPSLOCK, false);
90 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_CAPSLOCK, true);
91 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_CAPSLOCK, false);
92 locks &= ~0x2;
93 }
94 }
95
96 if (k_reports[numReports - 1].modifiers[1] & 0x4) {
97 if (!(locks & 0x4)) {
98 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_SCROLLLOCK, true);
99 locks |= 0x4;
100 }
101 } else {
102 if (locks & 0x4) {
103 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_SCROLLLOCK, false);
104 locks &= ~0x4;
105 }
106 }
107
108 {
109 Uint8 changed_modifiers = k_reports[numReports - 1].modifiers[0] ^ prev_modifiers;
110
111 if (changed_modifiers & 0x01) {
112 if (prev_modifiers & 0x01) {
113 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LCTRL, false);
114 } else {
115 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LCTRL, true);
116 }
117 }
118 if (changed_modifiers & 0x02) {
119 if (prev_modifiers & 0x02) {
120 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LSHIFT, false);
121 } else {
122 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LSHIFT, true);
123 }
124 }
125 if (changed_modifiers & 0x04) {
126 if (prev_modifiers & 0x04) {
127 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LALT, false);
128 } else {
129 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LALT, true);
130 }
131 }
132 if (changed_modifiers & 0x08) {
133 if (prev_modifiers & 0x08) {
134 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LGUI, false);
135 } else {
136 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LGUI, true);
137 }
138 }
139 if (changed_modifiers & 0x10) {
140 if (prev_modifiers & 0x10) {
141 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RCTRL, false);
142 } else {
143 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RCTRL, true);
144 }
145 }
146 if (changed_modifiers & 0x20) {
147 if (prev_modifiers & 0x20) {
148 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RSHIFT, false);
149 } else {
150 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RSHIFT, true);
151 }
152 }
153 if (changed_modifiers & 0x40) {
154 if (prev_modifiers & 0x40) {
155 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RALT, false);
156 } else {
157 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RALT, true);
158 }
159 }
160 if (changed_modifiers & 0x80) {
161 if (prev_modifiers & 0x80) {
162 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RGUI, false);
163 } else {
164 SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RGUI, true);
165 }
166 }
167 }
168
169 prev_modifiers = k_reports[numReports - 1].modifiers[0];
170
171 for (int i = 0; i < 6; i++) {
172
173 int keyCode = k_reports[numReports - 1].keycodes[i];
174
175 if (keyCode != prev_keys[i]) {
176
177 if (prev_keys[i]) {
178 SDL_SendKeyboardKey(0, keyboardID, 0, prev_keys[i], false);
179 }
180 if (keyCode) {
181 SDL_SendKeyboardKey(0, keyboardID, 0, keyCode, true);
182 }
183 prev_keys[i] = keyCode;
184 }
185 }
186 }
187 }
188}
189
190#endif // SDL_VIDEO_DRIVER_VITA
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitakeyboard.h b/contrib/SDL-3.2.8/src/video/vita/SDL_vitakeyboard.h
new file mode 100644
index 0000000..4b52864
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitakeyboard.h
@@ -0,0 +1,31 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#ifndef SDL_vitakeyboard_h
23#define SDL_vitakeyboard_h
24
25#include "SDL_internal.h"
26
27// Keyboard functions
28extern void VITA_InitKeyboard(void);
29extern void VITA_PollKeyboard(void);
30
31#endif // SDL_vitakeyboard_h
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitamessagebox.c b/contrib/SDL-3.2.8/src/video/vita/SDL_vitamessagebox.c
new file mode 100644
index 0000000..a63e156
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitamessagebox.c
@@ -0,0 +1,125 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21#include "SDL_internal.h"
22
23#ifdef SDL_VIDEO_DRIVER_VITA
24
25#include "SDL_vitavideo.h"
26#include "SDL_vitamessagebox.h"
27#include <psp2/message_dialog.h>
28
29#ifdef SDL_VIDEO_RENDER_VITA_GXM
30#include "../../render/vitagxm/SDL_render_vita_gxm_tools.h"
31#endif // SDL_VIDEO_RENDER_VITA_GXM
32
33bool VITA_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID)
34{
35#ifdef SDL_VIDEO_RENDER_VITA_GXM
36 SceMsgDialogParam param;
37 SceMsgDialogUserMessageParam msgParam;
38 SceMsgDialogButtonsParam buttonParam;
39 SceDisplayFrameBuf dispparam;
40 char message[512];
41
42 SceMsgDialogResult dialog_result;
43 SceCommonDialogErrorCode init_result;
44 bool setup_minimal_gxm = false;
45
46 if (messageboxdata->numbuttons > 3) {
47 return false;
48 }
49
50 SDL_zero(param);
51 sceMsgDialogParamInit(&param);
52 param.mode = SCE_MSG_DIALOG_MODE_USER_MSG;
53
54 SDL_zero(msgParam);
55 SDL_snprintf(message, sizeof(message), "%s\r\n\r\n%s", messageboxdata->title, messageboxdata->message);
56
57 msgParam.msg = (const SceChar8 *)message;
58 SDL_zero(buttonParam);
59
60 if (messageboxdata->numbuttons == 3) {
61 msgParam.buttonType = SCE_MSG_DIALOG_BUTTON_TYPE_3BUTTONS;
62 msgParam.buttonParam = &buttonParam;
63 buttonParam.msg1 = messageboxdata->buttons[0].text;
64 buttonParam.msg2 = messageboxdata->buttons[1].text;
65 buttonParam.msg3 = messageboxdata->buttons[2].text;
66 } else if (messageboxdata->numbuttons == 2) {
67 msgParam.buttonType = SCE_MSG_DIALOG_BUTTON_TYPE_YESNO;
68 } else if (messageboxdata->numbuttons == 1) {
69 msgParam.buttonType = SCE_MSG_DIALOG_BUTTON_TYPE_OK;
70 }
71 param.userMsgParam = &msgParam;
72
73 dispparam.size = sizeof(dispparam);
74
75 init_result = sceMsgDialogInit(&param);
76
77 // Setup display if it hasn't been initialized before
78 if (init_result == SCE_COMMON_DIALOG_ERROR_GXM_IS_UNINITIALIZED) {
79 gxm_minimal_init_for_common_dialog();
80 init_result = sceMsgDialogInit(&param);
81 setup_minimal_gxm = true;
82 }
83
84 gxm_init_for_common_dialog();
85
86 if (init_result >= 0) {
87 while (sceMsgDialogGetStatus() == SCE_COMMON_DIALOG_STATUS_RUNNING) {
88 gxm_swap_for_common_dialog();
89 }
90 SDL_zero(dialog_result);
91 sceMsgDialogGetResult(&dialog_result);
92
93 if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_BUTTON1) {
94 *buttonID = messageboxdata->buttons[0].buttonID;
95 } else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_BUTTON2) {
96 *buttonID = messageboxdata->buttons[1].buttonID;
97 } else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_BUTTON3) {
98 *buttonID = messageboxdata->buttons[2].buttonID;
99 } else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_YES) {
100 *buttonID = messageboxdata->buttons[0].buttonID;
101 } else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_NO) {
102 *buttonID = messageboxdata->buttons[1].buttonID;
103 } else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_OK) {
104 *buttonID = messageboxdata->buttons[0].buttonID;
105 }
106 sceMsgDialogTerm();
107 } else {
108 return false;
109 }
110
111 gxm_term_for_common_dialog();
112
113 if (setup_minimal_gxm) {
114 gxm_minimal_term_for_common_dialog();
115 }
116
117 return true;
118#else
119 (void)messageboxdata;
120 (void)buttonID;
121 return SDL_Unsupported();
122#endif // SDL_VIDEO_RENDER_VITA_GXM
123}
124
125#endif // SDL_VIDEO_DRIVER_VITA
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitamessagebox.h b/contrib/SDL-3.2.8/src/video/vita/SDL_vitamessagebox.h
new file mode 100644
index 0000000..7e4148d
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitamessagebox.h
@@ -0,0 +1,31 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#ifndef SDL_vitamessagebox_h_
23#define SDL_vitamessagebox_h_
24
25#ifdef SDL_VIDEO_DRIVER_VITA
26
27extern bool VITA_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID);
28
29#endif // SDL_VIDEO_DRIVER_VITA
30
31#endif // SDL_vitamessagebox_h_
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitamouse.c b/contrib/SDL-3.2.8/src/video/vita/SDL_vitamouse.c
new file mode 100644
index 0000000..7181023
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitamouse.c
@@ -0,0 +1,105 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21#include "SDL_internal.h"
22
23#ifdef SDL_VIDEO_DRIVER_VITA
24
25#include <psp2/kernel/processmgr.h>
26#include <psp2/ctrl.h>
27#include <psp2/hid.h>
28
29#include "SDL_vitavideo.h"
30#include "SDL_vitamouse_c.h"
31#include "../../events/SDL_mouse_c.h"
32
33SceHidMouseReport m_reports[SCE_HID_MAX_REPORT];
34int mouse_hid_handle = 0;
35Uint8 prev_buttons = 0;
36
37void VITA_InitMouse(void)
38{
39 sceHidMouseEnumerate(&mouse_hid_handle, 1);
40
41 if (mouse_hid_handle > 0) {
42 SDL_AddMouse((SDL_MouseID)mouse_hid_handle, NULL, false);
43 }
44}
45
46void VITA_PollMouse(void)
47{
48 // We skip polling mouse if no window is created
49 if (!Vita_Window) {
50 return;
51 }
52
53 if (mouse_hid_handle > 0) {
54 SDL_MouseID mouseID = (SDL_MouseID)mouse_hid_handle;
55 int numReports = sceHidMouseRead(mouse_hid_handle, (SceHidMouseReport **)&m_reports, SCE_HID_MAX_REPORT);
56 if (numReports > 0) {
57 for (int i = 0; i <= numReports - 1; i++) {
58 Uint8 changed_buttons = m_reports[i].buttons ^ prev_buttons;
59
60 if (changed_buttons & 0x1) {
61 if (prev_buttons & 0x1)
62 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_LEFT, false);
63 else
64 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_LEFT, true);
65 }
66 if (changed_buttons & 0x2) {
67 if (prev_buttons & 0x2)
68 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_RIGHT, false);
69 else
70 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_RIGHT, true);
71 }
72 if (changed_buttons & 0x4) {
73 if (prev_buttons & 0x4)
74 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_MIDDLE, false);
75 else
76 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_MIDDLE, true);
77 }
78 if (changed_buttons & 0x8) {
79 if (prev_buttons & 0x8)
80 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_X1, false);
81 else
82 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_X1, true);
83 }
84 if (changed_buttons & 0x10) {
85 if (prev_buttons & 0x10)
86 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_X2, false);
87 else
88 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_X2, true);
89 }
90
91 prev_buttons = m_reports[i].buttons;
92
93 if (m_reports[i].rel_x || m_reports[i].rel_y) {
94 SDL_SendMouseMotion(0, Vita_Window, mouseID, true, (float)m_reports[i].rel_x, (float)m_reports[i].rel_y);
95 }
96
97 if (m_reports[i].tilt != 0 || m_reports[i].wheel != 0) {
98 SDL_SendMouseWheel(0, Vita_Window, mouseID, m_reports[i].tilt, m_reports[i].wheel, SDL_MOUSEWHEEL_NORMAL);
99 }
100 }
101 }
102 }
103}
104
105#endif // SDL_VIDEO_DRIVER_VITA
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitamouse_c.h b/contrib/SDL-3.2.8/src/video/vita/SDL_vitamouse_c.h
new file mode 100644
index 0000000..ef6a7c9
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitamouse_c.h
@@ -0,0 +1,31 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#ifndef SDL_vitamouse_h
23#define SDL_vitamouse_h
24
25#include "SDL_internal.h"
26
27// mouse functions
28extern void VITA_InitMouse(void);
29extern void VITA_PollMouse(void);
30
31#endif // SDL_vitamouse_h
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitatouch.c b/contrib/SDL-3.2.8/src/video/vita/SDL_vitatouch.c
new file mode 100644
index 0000000..ac6f764
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitatouch.c
@@ -0,0 +1,186 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21#include "SDL_internal.h"
22
23#ifdef SDL_VIDEO_DRIVER_VITA
24
25#include <psp2/kernel/processmgr.h>
26#include <psp2/touch.h>
27
28#include "SDL_vitavideo.h"
29#include "SDL_vitatouch.h"
30#include "../../events/SDL_mouse_c.h"
31#include "../../events/SDL_touch_c.h"
32
33SceTouchData touch_old[SCE_TOUCH_PORT_MAX_NUM];
34SceTouchData touch[SCE_TOUCH_PORT_MAX_NUM];
35
36SDL_FRect area_info[SCE_TOUCH_PORT_MAX_NUM];
37
38struct
39{
40 float min;
41 float range;
42} force_info[SCE_TOUCH_PORT_MAX_NUM];
43
44static bool disableFrontPoll;
45static bool disableBackPoll;
46
47void VITA_InitTouch(void)
48{
49 disableFrontPoll = !SDL_GetHintBoolean(SDL_HINT_VITA_ENABLE_FRONT_TOUCH, true);
50 disableBackPoll = !SDL_GetHintBoolean(SDL_HINT_VITA_ENABLE_BACK_TOUCH, true);
51
52 sceTouchSetSamplingState(SCE_TOUCH_PORT_FRONT, SCE_TOUCH_SAMPLING_STATE_START);
53 sceTouchSetSamplingState(SCE_TOUCH_PORT_BACK, SCE_TOUCH_SAMPLING_STATE_START);
54 sceTouchEnableTouchForce(SCE_TOUCH_PORT_FRONT);
55 sceTouchEnableTouchForce(SCE_TOUCH_PORT_BACK);
56
57 for (int port = 0; port < SCE_TOUCH_PORT_MAX_NUM; port++) {
58 SceTouchPanelInfo panelinfo;
59 sceTouchGetPanelInfo(port, &panelinfo);
60
61 area_info[port].x = (float)panelinfo.minAaX;
62 area_info[port].y = (float)panelinfo.minAaY;
63 area_info[port].w = (float)(panelinfo.maxAaX - panelinfo.minAaX);
64 area_info[port].h = (float)(panelinfo.maxAaY - panelinfo.minAaY);
65
66 force_info[port].min = (float)panelinfo.minForce;
67 force_info[port].range = (float)(panelinfo.maxForce - panelinfo.minForce);
68 }
69
70 // Support passing both front and back touch devices in events
71 SDL_AddTouch(1, SDL_TOUCH_DEVICE_DIRECT, "Front");
72 SDL_AddTouch(2, SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE, "Back");
73}
74
75void VITA_QuitTouch(void)
76{
77 sceTouchDisableTouchForce(SCE_TOUCH_PORT_FRONT);
78 sceTouchDisableTouchForce(SCE_TOUCH_PORT_BACK);
79}
80
81void VITA_PollTouch(void)
82{
83 SDL_TouchID touch_id;
84 SDL_FingerID finger_id;
85 int port;
86
87 // We skip polling touch if no window is created
88 if (!Vita_Window) {
89 return;
90 }
91
92 SDL_memcpy(touch_old, touch, sizeof(touch_old));
93
94 for (port = 0; port < SCE_TOUCH_PORT_MAX_NUM; port++) {
95 /** Skip polling of Touch Device if hint is set **/
96 if (((port == 0) && disableFrontPoll) || ((port == 1) && disableBackPoll)) {
97 continue;
98 }
99 sceTouchPeek(port, &touch[port], 1);
100
101 touch_id = (SDL_TouchID)(port + 1);
102
103 if (touch[port].reportNum > 0) {
104 for (int i = 0; i < touch[port].reportNum; i++) {
105 // adjust coordinates and forces to return normalized values
106 // for the front, screen area is used as a reference (for direct touch)
107 // e.g. touch_x = 1.0 corresponds to screen_x = 960
108 // for the back panel, the active touch area is used as reference
109 float x = 0;
110 float y = 0;
111 float force = (touch[port].report[i].force - force_info[port].min) / force_info[port].range;
112 int finger_down = 0;
113
114 if (touch_old[port].reportNum > 0) {
115 for (int j = 0; j < touch_old[port].reportNum; j++) {
116 if (touch[port].report[i].id == touch_old[port].report[j].id) {
117 finger_down = 1;
118 }
119 }
120 }
121
122 VITA_ConvertTouchXYToSDLXY(&x, &y, touch[port].report[i].x, touch[port].report[i].y, port);
123 finger_id = (SDL_FingerID)(touch[port].report[i].id + 1);
124
125 // Skip if finger was already previously down
126 if (!finger_down) {
127 // Send an initial touch
128 SDL_SendTouch(0, touch_id, finger_id, Vita_Window, SDL_EVENT_FINGER_DOWN, x, y, force);
129 }
130
131 // Always send the motion
132 SDL_SendTouchMotion(0, touch_id, finger_id, Vita_Window, x, y, force);
133 }
134 }
135
136 // some fingers might have been let go
137 if (touch_old[port].reportNum > 0) {
138 for (int i = 0; i < touch_old[port].reportNum; i++) {
139 int finger_up = 1;
140 if (touch[port].reportNum > 0) {
141 for (int j = 0; j < touch[port].reportNum; j++) {
142 if (touch[port].report[j].id == touch_old[port].report[i].id) {
143 finger_up = 0;
144 }
145 }
146 }
147 if (finger_up == 1) {
148 float x = 0;
149 float y = 0;
150 float force = (touch_old[port].report[i].force - force_info[port].min) / force_info[port].range;
151 VITA_ConvertTouchXYToSDLXY(&x, &y, touch_old[port].report[i].x, touch_old[port].report[i].y, port);
152 finger_id = (SDL_FingerID)(touch_old[port].report[i].id + 1);
153 // Finger released from screen
154 SDL_SendTouch(0, touch_id, finger_id, Vita_Window, SDL_EVENT_FINGER_UP, x, y, force);
155 }
156 }
157 }
158 }
159}
160
161void VITA_ConvertTouchXYToSDLXY(float *sdl_x, float *sdl_y, int vita_x, int vita_y, int port)
162{
163 float x, y;
164
165 if (area_info[port].w <= 1) {
166 x = 0.5f;
167 } else {
168 x = (vita_x - area_info[port].x) / (area_info[port].w - 1);
169 }
170 if (area_info[port].h <= 1) {
171 y = 0.5f;
172 } else {
173 y = (vita_y - area_info[port].y) / (area_info[port].h - 1);
174 }
175
176 x = SDL_max(x, 0.0f);
177 x = SDL_min(x, 1.0f);
178
179 y = SDL_max(y, 0.0f);
180 y = SDL_min(y, 1.0f);
181
182 *sdl_x = x;
183 *sdl_y = y;
184}
185
186#endif // SDL_VIDEO_DRIVER_VITA
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitatouch.h b/contrib/SDL-3.2.8/src/video/vita/SDL_vitatouch.h
new file mode 100644
index 0000000..b94051a
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitatouch.h
@@ -0,0 +1,33 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#ifndef SDL_vitatouch_h
23#define SDL_vitatouch_h
24
25#include "SDL_internal.h"
26
27// Touch functions
28extern void VITA_InitTouch(void);
29extern void VITA_QuitTouch(void);
30extern void VITA_PollTouch(void);
31void VITA_ConvertTouchXYToSDLXY(float *sdl_x, float *sdl_y, int vita_x, int vita_y, int port);
32
33#endif // SDL_vitatouch_h
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitavideo.c b/contrib/SDL-3.2.8/src/video/vita/SDL_vitavideo.c
new file mode 100644
index 0000000..6b5dbd7
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitavideo.c
@@ -0,0 +1,592 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#include "SDL_internal.h"
23
24#ifdef SDL_VIDEO_DRIVER_VITA
25
26// SDL internals
27#include "../SDL_sysvideo.h"
28#include "../../events/SDL_mouse_c.h"
29#include "../../events/SDL_keyboard_c.h"
30
31// VITA declarations
32#include <psp2/kernel/processmgr.h>
33#include "SDL_vitavideo.h"
34#include "SDL_vitatouch.h"
35#include "SDL_vitakeyboard.h"
36#include "SDL_vitamouse_c.h"
37#include "SDL_vitaframebuffer.h"
38#include "SDL_vitamessagebox.h"
39
40#ifdef SDL_VIDEO_VITA_PIB
41#include "SDL_vitagles_c.h"
42#elif defined(SDL_VIDEO_VITA_PVR)
43#include "SDL_vitagles_pvr_c.h"
44#ifdef SDL_VIDEO_VITA_PVR_OGL
45#include "SDL_vitagl_pvr_c.h"
46#endif
47#define VITA_GLES_GetProcAddress SDL_EGL_GetProcAddressInternal
48#define VITA_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
49#define VITA_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
50#define VITA_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
51#define VITA_GLES_DestroyContext SDL_EGL_DestroyContext
52#endif
53
54SDL_Window *Vita_Window;
55
56static void VITA_Destroy(SDL_VideoDevice *device)
57{
58 SDL_free(device->internal);
59 SDL_free(device);
60}
61
62static SDL_VideoDevice *VITA_Create(void)
63{
64 SDL_VideoDevice *device;
65 SDL_VideoData *phdata;
66#ifdef SDL_VIDEO_VITA_PIB
67 SDL_GLDriverData *gldata;
68#endif
69 // Initialize SDL_VideoDevice structure
70 device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice));
71 if (!device) {
72 return NULL;
73 }
74
75 // Initialize internal VITA specific data
76 phdata = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData));
77 if (!phdata) {
78 SDL_free(device);
79 return NULL;
80 }
81#ifdef SDL_VIDEO_VITA_PIB
82
83 gldata = (SDL_GLDriverData *)SDL_calloc(1, sizeof(SDL_GLDriverData));
84 if (!gldata) {
85 SDL_free(device);
86 SDL_free(phdata);
87 return NULL;
88 }
89 device->gl_data = gldata;
90 phdata->egl_initialized = true;
91#endif
92 phdata->ime_active = false;
93
94 device->internal = phdata;
95
96 // Setup amount of available displays and current display
97 device->num_displays = 0;
98
99 // Set device free function
100 device->free = VITA_Destroy;
101
102 // Setup all functions which we can handle
103 device->VideoInit = VITA_VideoInit;
104 device->VideoQuit = VITA_VideoQuit;
105 device->CreateSDLWindow = VITA_CreateWindow;
106 device->SetWindowTitle = VITA_SetWindowTitle;
107 device->SetWindowPosition = VITA_SetWindowPosition;
108 device->SetWindowSize = VITA_SetWindowSize;
109 device->ShowWindow = VITA_ShowWindow;
110 device->HideWindow = VITA_HideWindow;
111 device->RaiseWindow = VITA_RaiseWindow;
112 device->MaximizeWindow = VITA_MaximizeWindow;
113 device->MinimizeWindow = VITA_MinimizeWindow;
114 device->RestoreWindow = VITA_RestoreWindow;
115 device->SetWindowMouseGrab = VITA_SetWindowGrab;
116 device->SetWindowKeyboardGrab = VITA_SetWindowGrab;
117 device->DestroyWindow = VITA_DestroyWindow;
118
119 /*
120 // Disabled, causes issues on high-framerate updates. SDL still emulates this.
121 device->CreateWindowFramebuffer = VITA_CreateWindowFramebuffer;
122 device->UpdateWindowFramebuffer = VITA_UpdateWindowFramebuffer;
123 device->DestroyWindowFramebuffer = VITA_DestroyWindowFramebuffer;
124 */
125
126#if defined(SDL_VIDEO_VITA_PIB) || defined(SDL_VIDEO_VITA_PVR)
127#ifdef SDL_VIDEO_VITA_PVR_OGL
128 if (SDL_GetHintBoolean(SDL_HINT_VITA_PVR_OPENGL, false)) {
129 device->GL_LoadLibrary = VITA_GL_LoadLibrary;
130 device->GL_CreateContext = VITA_GL_CreateContext;
131 device->GL_GetProcAddress = VITA_GL_GetProcAddress;
132 } else {
133#endif
134 device->GL_LoadLibrary = VITA_GLES_LoadLibrary;
135 device->GL_CreateContext = VITA_GLES_CreateContext;
136 device->GL_GetProcAddress = VITA_GLES_GetProcAddress;
137#ifdef SDL_VIDEO_VITA_PVR_OGL
138 }
139#endif
140
141 device->GL_UnloadLibrary = VITA_GLES_UnloadLibrary;
142 device->GL_MakeCurrent = VITA_GLES_MakeCurrent;
143 device->GL_SetSwapInterval = VITA_GLES_SetSwapInterval;
144 device->GL_GetSwapInterval = VITA_GLES_GetSwapInterval;
145 device->GL_SwapWindow = VITA_GLES_SwapWindow;
146 device->GL_DestroyContext = VITA_GLES_DestroyContext;
147#endif
148
149 device->HasScreenKeyboardSupport = VITA_HasScreenKeyboardSupport;
150 device->ShowScreenKeyboard = VITA_ShowScreenKeyboard;
151 device->HideScreenKeyboard = VITA_HideScreenKeyboard;
152 device->IsScreenKeyboardShown = VITA_IsScreenKeyboardShown;
153
154 device->PumpEvents = VITA_PumpEvents;
155
156 return device;
157}
158
159VideoBootStrap VITA_bootstrap = {
160 "vita",
161 "VITA Video Driver",
162 VITA_Create,
163 VITA_ShowMessageBox,
164 false
165};
166
167/*****************************************************************************/
168// SDL Video and Display initialization/handling functions
169/*****************************************************************************/
170bool VITA_VideoInit(SDL_VideoDevice *_this)
171{
172 SDL_DisplayMode mode;
173#ifdef SDL_VIDEO_VITA_PVR
174 const char *res = SDL_GetHint(SDL_HINT_VITA_RESOLUTION);
175#endif
176 SDL_zero(mode);
177
178#ifdef SDL_VIDEO_VITA_PVR
179 if (res) {
180 // 1088i for PSTV (Or Sharpscale)
181 if (SDL_strncmp(res, "1080", 4) == 0) {
182 mode.w = 1920;
183 mode.h = 1088;
184 }
185 // 725p for PSTV (Or Sharpscale)
186 else if (SDL_strncmp(res, "720", 3) == 0) {
187 mode.w = 1280;
188 mode.h = 725;
189 }
190 }
191 // 544p
192 else {
193#endif
194 mode.w = 960;
195 mode.h = 544;
196#ifdef SDL_VIDEO_VITA_PVR
197 }
198#endif
199
200 mode.refresh_rate = 60.0f;
201
202 // 32 bpp for default
203 mode.format = SDL_PIXELFORMAT_ABGR8888;
204
205 if (SDL_AddBasicVideoDisplay(&mode) == 0) {
206 return false;
207 }
208
209 VITA_InitTouch();
210 VITA_InitKeyboard();
211 VITA_InitMouse();
212
213 return true;
214}
215
216void VITA_VideoQuit(SDL_VideoDevice *_this)
217{
218 VITA_QuitTouch();
219}
220
221bool VITA_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
222{
223 SDL_WindowData *wdata;
224#ifdef SDL_VIDEO_VITA_PVR
225 Psp2NativeWindow win;
226 int temp_major = 2;
227 int temp_minor = 1;
228 int temp_profile = 0;
229#endif
230
231 // Allocate window internal data
232 wdata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData));
233 if (!wdata) {
234 return false;
235 }
236
237 // Setup driver data for this window
238 window->internal = wdata;
239
240 // Vita can only have one window
241 if (Vita_Window) {
242 return SDL_SetError("Only one window supported");
243 }
244
245 Vita_Window = window;
246
247#ifdef SDL_VIDEO_VITA_PVR
248 win.type = PSP2_DRAWABLE_TYPE_WINDOW;
249 win.numFlipBuffers = 2;
250 win.flipChainThrdAffinity = 0x20000;
251
252 // 1088i for PSTV (Or Sharpscale)
253 if (window->w == 1920) {
254 win.windowSize = PSP2_WINDOW_1920X1088;
255 }
256 // 725p for PSTV (Or Sharpscale)
257 else if (window->w == 1280) {
258 win.windowSize = PSP2_WINDOW_1280X725;
259 }
260 // 544p
261 else {
262 win.windowSize = PSP2_WINDOW_960X544;
263 }
264 if (window->flags & SDL_WINDOW_OPENGL) {
265 bool use_opengl = SDL_GetHintBoolean(SDL_HINT_VITA_PVR_OPENGL, false);
266 if (use_opengl) {
267 // Set version to 2.1 and PROFILE to ES
268 temp_major = _this->gl_config.major_version;
269 temp_minor = _this->gl_config.minor_version;
270 temp_profile = _this->gl_config.profile_mask;
271
272 _this->gl_config.major_version = 2;
273 _this->gl_config.minor_version = 1;
274 _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
275 }
276 wdata->egl_surface = SDL_EGL_CreateSurface(_this, window, &win);
277 if (wdata->egl_surface == EGL_NO_SURFACE) {
278 return SDL_SetError("Could not create GLES window surface");
279 }
280 if (use_opengl) {
281 // Revert
282 _this->gl_config.major_version = temp_major;
283 _this->gl_config.minor_version = temp_minor;
284 _this->gl_config.profile_mask = temp_profile;
285 }
286 }
287#endif
288
289 // fix input, we need to find a better way
290 SDL_SetKeyboardFocus(window);
291
292 // Window has been successfully created
293 return true;
294}
295
296void VITA_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window)
297{
298}
299bool VITA_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
300{
301 return SDL_Unsupported();
302}
303void VITA_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window)
304{
305}
306void VITA_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
307{
308}
309void VITA_HideWindow(SDL_VideoDevice *_this, SDL_Window *window)
310{
311}
312void VITA_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window)
313{
314}
315void VITA_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window *window)
316{
317}
318void VITA_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window)
319{
320}
321void VITA_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window)
322{
323}
324bool VITA_SetWindowGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed)
325{
326 return true;
327}
328
329void VITA_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
330{
331 SDL_WindowData *data;
332
333 data = window->internal;
334 if (data) {
335 // TODO: should we destroy egl context? No one sane should recreate ogl window as non-ogl
336 SDL_free(data);
337 }
338
339 window->internal = NULL;
340 Vita_Window = NULL;
341}
342
343bool VITA_HasScreenKeyboardSupport(SDL_VideoDevice *_this)
344{
345 return true;
346}
347
348#ifndef SCE_IME_LANGUAGE_ENGLISH_US
349#define SCE_IME_LANGUAGE_ENGLISH_US SCE_IME_LANGUAGE_ENGLISH
350#endif
351
352static void utf16_to_utf8(const uint16_t *src, uint8_t *dst)
353{
354 int i;
355 for (i = 0; src[i]; i++) {
356 if (!(src[i] & 0xFF80)) {
357 *(dst++) = src[i] & 0xFF;
358 } else if (!(src[i] & 0xF800)) {
359 *(dst++) = ((src[i] >> 6) & 0xFF) | 0xC0;
360 *(dst++) = (src[i] & 0x3F) | 0x80;
361 } else if ((src[i] & 0xFC00) == 0xD800 && (src[i + 1] & 0xFC00) == 0xDC00) {
362 *(dst++) = (((src[i] + 64) >> 8) & 0x3) | 0xF0;
363 *(dst++) = (((src[i] >> 2) + 16) & 0x3F) | 0x80;
364 *(dst++) = ((src[i] >> 4) & 0x30) | 0x80 | ((src[i + 1] << 2) & 0xF);
365 *(dst++) = (src[i + 1] & 0x3F) | 0x80;
366 i += 1;
367 } else {
368 *(dst++) = ((src[i] >> 12) & 0xF) | 0xE0;
369 *(dst++) = ((src[i] >> 6) & 0x3F) | 0x80;
370 *(dst++) = (src[i] & 0x3F) | 0x80;
371 }
372 }
373
374 *dst = '\0';
375}
376
377#ifdef SDL_VIDEO_VITA_PVR
378SceWChar16 libime_out[SCE_IME_MAX_PREEDIT_LENGTH + SCE_IME_MAX_TEXT_LENGTH + 1];
379char libime_initval[8] = { 1 };
380SceImeCaret caret_rev;
381
382void VITA_ImeEventHandler(void *arg, const SceImeEventData *e)
383{
384 SDL_VideoData *videodata = (SDL_VideoData *)arg;
385 uint8_t utf8_buffer[SCE_IME_MAX_TEXT_LENGTH];
386 switch (e->id) {
387 case SCE_IME_EVENT_UPDATE_TEXT:
388 if (e->param.text.caretIndex == 0) {
389 SDL_SendKeyboardKeyAutoRelease(0, SDL_SCANCODE_BACKSPACE);
390 sceImeSetText((SceWChar16 *)libime_initval, 4);
391 } else {
392 utf16_to_utf8((SceWChar16 *)&libime_out[1], utf8_buffer);
393 if (utf8_buffer[0] == ' ') {
394 SDL_SendKeyboardKeyAutoRelease(0, SDL_SCANCODE_SPACE);
395 } else {
396 SDL_SendKeyboardText((const char *)utf8_buffer);
397 }
398 SDL_memset(&caret_rev, 0, sizeof(SceImeCaret));
399 SDL_memset(libime_out, 0, ((SCE_IME_MAX_PREEDIT_LENGTH + SCE_IME_MAX_TEXT_LENGTH + 1) * sizeof(SceWChar16)));
400 caret_rev.index = 1;
401 sceImeSetCaret(&caret_rev);
402 sceImeSetText((SceWChar16 *)libime_initval, 4);
403 }
404 break;
405 case SCE_IME_EVENT_PRESS_ENTER:
406 SDL_SendKeyboardKeyAutoRelease(0, SDL_SCANCODE_RETURN);
407 break;
408 case SCE_IME_EVENT_PRESS_CLOSE:
409 sceImeClose();
410 videodata->ime_active = false;
411 break;
412 }
413}
414#endif
415
416void VITA_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props)
417{
418 SDL_VideoData *videodata = _this->internal;
419 SceInt32 res;
420
421#ifdef SDL_VIDEO_VITA_PVR
422
423 SceUInt32 libime_work[SCE_IME_WORK_BUFFER_SIZE / sizeof(SceInt32)];
424 SceImeParam param;
425
426 sceImeParamInit(&param);
427
428 SDL_memset(libime_out, 0, ((SCE_IME_MAX_PREEDIT_LENGTH + SCE_IME_MAX_TEXT_LENGTH + 1) * sizeof(SceWChar16)));
429
430 param.supportedLanguages = SCE_IME_LANGUAGE_ENGLISH_US;
431 param.languagesForced = SCE_FALSE;
432 switch (SDL_GetTextInputType(props)) {
433 default:
434 case SDL_TEXTINPUT_TYPE_TEXT:
435 param.type = SCE_IME_TYPE_DEFAULT;
436 break;
437 case SDL_TEXTINPUT_TYPE_TEXT_NAME:
438 param.type = SCE_IME_TYPE_DEFAULT;
439 break;
440 case SDL_TEXTINPUT_TYPE_TEXT_EMAIL:
441 param.type = SCE_IME_TYPE_MAIL;
442 break;
443 case SDL_TEXTINPUT_TYPE_TEXT_USERNAME:
444 param.type = SCE_IME_TYPE_DEFAULT;
445 break;
446 case SDL_TEXTINPUT_TYPE_TEXT_PASSWORD_HIDDEN:
447 param.type = SCE_IME_TYPE_DEFAULT;
448 break;
449 case SDL_TEXTINPUT_TYPE_TEXT_PASSWORD_VISIBLE:
450 param.type = SCE_IME_TYPE_DEFAULT;
451 break;
452 case SDL_TEXTINPUT_TYPE_NUMBER:
453 param.type = SCE_IME_TYPE_NUMBER;
454 break;
455 case SDL_TEXTINPUT_TYPE_NUMBER_PASSWORD_HIDDEN:
456 param.type = SCE_IME_TYPE_NUMBER;
457 break;
458 case SDL_TEXTINPUT_TYPE_NUMBER_PASSWORD_VISIBLE:
459 param.type = SCE_IME_TYPE_NUMBER;
460 break;
461 }
462 param.option = 0;
463 if (SDL_GetTextInputCapitalization(props) != SDL_CAPITALIZE_SENTENCES) {
464 param.option |= SCE_IME_OPTION_NO_AUTO_CAPITALIZATION;
465 }
466 if (!SDL_GetTextInputAutocorrect(props)) {
467 param.option |= SCE_IME_OPTION_NO_ASSISTANCE;
468 }
469 if (SDL_GetTextInputMultiline(props)) {
470 param.option |= SCE_IME_OPTION_MULTILINE;
471 }
472 param.inputTextBuffer = libime_out;
473 param.maxTextLength = SCE_IME_MAX_TEXT_LENGTH;
474 param.handler = VITA_ImeEventHandler;
475 param.filter = NULL;
476 param.initialText = (SceWChar16 *)libime_initval;
477 param.arg = videodata;
478 param.work = libime_work;
479
480 res = sceImeOpen(&param);
481 if (res < 0) {
482 SDL_SetError("Failed to init IME");
483 return;
484 }
485
486#else
487 SceWChar16 *title = u"";
488 SceWChar16 *text = u"";
489
490 SceImeDialogParam param;
491 sceImeDialogParamInit(&param);
492
493 param.supportedLanguages = 0;
494 param.languagesForced = SCE_FALSE;
495 param.type = SCE_IME_TYPE_DEFAULT;
496 param.option = 0;
497 param.textBoxMode = SCE_IME_DIALOG_TEXTBOX_MODE_WITH_CLEAR;
498 param.maxTextLength = SCE_IME_DIALOG_MAX_TEXT_LENGTH;
499
500 param.title = title;
501 param.initialText = text;
502 param.inputTextBuffer = videodata->ime_buffer;
503
504 res = sceImeDialogInit(&param);
505 if (res < 0) {
506 SDL_SetError("Failed to init IME dialog");
507 return;
508 }
509
510#endif
511
512 videodata->ime_active = true;
513}
514
515void VITA_HideScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window)
516{
517#ifndef SDL_VIDEO_VITA_PVR
518 SDL_VideoData *videodata = _this->internal;
519
520 SceCommonDialogStatus dialogStatus = sceImeDialogGetStatus();
521
522 switch (dialogStatus) {
523 default:
524 case SCE_COMMON_DIALOG_STATUS_NONE:
525 case SCE_COMMON_DIALOG_STATUS_RUNNING:
526 break;
527 case SCE_COMMON_DIALOG_STATUS_FINISHED:
528 sceImeDialogTerm();
529 break;
530 }
531
532 videodata->ime_active = false;
533#endif
534}
535
536bool VITA_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window *window)
537{
538#ifdef SDL_VIDEO_VITA_PVR
539 SDL_VideoData *videodata = _this->internal;
540 return videodata->ime_active;
541#else
542 SceCommonDialogStatus dialogStatus = sceImeDialogGetStatus();
543 return dialogStatus == SCE_COMMON_DIALOG_STATUS_RUNNING;
544#endif
545}
546
547void VITA_PumpEvents(SDL_VideoDevice *_this)
548{
549#ifndef SDL_VIDEO_VITA_PVR
550 SDL_VideoData *videodata = _this->internal;
551#endif
552
553 if (_this->suspend_screensaver) {
554 // cancel all idle timers to prevent vita going to sleep
555 sceKernelPowerTick(SCE_KERNEL_POWER_TICK_DEFAULT);
556 }
557
558 VITA_PollTouch();
559 VITA_PollKeyboard();
560 VITA_PollMouse();
561
562#ifndef SDL_VIDEO_VITA_PVR
563 if (videodata->ime_active == true) {
564 // update IME status. Terminate, if finished
565 SceCommonDialogStatus dialogStatus = sceImeDialogGetStatus();
566 if (dialogStatus == SCE_COMMON_DIALOG_STATUS_FINISHED) {
567 uint8_t utf8_buffer[SCE_IME_DIALOG_MAX_TEXT_LENGTH];
568
569 SceImeDialogResult result;
570 SDL_memset(&result, 0, sizeof(SceImeDialogResult));
571 sceImeDialogGetResult(&result);
572
573 // Convert UTF16 to UTF8
574 utf16_to_utf8(videodata->ime_buffer, utf8_buffer);
575
576 // Send SDL event
577 SDL_SendKeyboardText((const char *)utf8_buffer);
578
579 // Send enter key only on enter
580 if (result.button == SCE_IME_DIALOG_BUTTON_ENTER) {
581 SDL_SendKeyboardKeyAutoRelease(0, SDL_SCANCODE_RETURN);
582 }
583
584 sceImeDialogTerm();
585
586 videodata->ime_active = false;
587 }
588 }
589#endif
590}
591
592#endif // SDL_VIDEO_DRIVER_VITA
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitavideo.h b/contrib/SDL-3.2.8/src/video/vita/SDL_vitavideo.h
new file mode 100644
index 0000000..268bed8
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitavideo.h
@@ -0,0 +1,106 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#ifndef SDL_vitavideo_h
23#define SDL_vitavideo_h
24
25#include "SDL_internal.h"
26#include "../SDL_sysvideo.h"
27#include "../SDL_egl_c.h"
28
29#include <psp2/types.h>
30#include <psp2/display.h>
31#include <psp2/ime_dialog.h>
32#include <psp2/sysmodule.h>
33
34struct SDL_VideoData
35{
36 bool egl_initialized; // OpenGL device initialization status
37 uint32_t egl_refcount; // OpenGL reference count
38
39 SceWChar16 ime_buffer[SCE_IME_DIALOG_MAX_TEXT_LENGTH];
40 bool ime_active;
41};
42
43struct SDL_WindowData
44{
45 bool uses_gles;
46 SceUID buffer_uid;
47 void *buffer;
48#ifdef SDL_VIDEO_VITA_PVR
49 EGLSurface egl_surface;
50 EGLContext egl_context;
51#endif
52};
53
54extern SDL_Window *Vita_Window;
55
56/****************************************************************************/
57// SDL_VideoDevice functions declaration
58/****************************************************************************/
59
60// Display and window functions
61extern bool VITA_VideoInit(SDL_VideoDevice *_this);
62extern void VITA_VideoQuit(SDL_VideoDevice *_this);
63extern bool VITA_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
64extern bool VITA_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
65extern bool VITA_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
66extern void VITA_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
67extern bool VITA_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window);
68extern void VITA_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);
69extern void VITA_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window);
70extern void VITA_HideWindow(SDL_VideoDevice *_this, SDL_Window *window);
71extern void VITA_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window);
72extern void VITA_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window *window);
73extern void VITA_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window);
74extern void VITA_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window);
75extern bool VITA_SetWindowGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed);
76extern void VITA_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window);
77
78#ifdef SDL_VIDEO_DRIVER_VITA
79#ifdef SDL_VIDEO_VITA_PVR_OGL
80// OpenGL functions
81extern bool VITA_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path);
82extern SDL_GLContext VITA_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window);
83extern SDL_FunctionPointer VITA_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc);
84#endif
85
86// OpenGLES functions
87extern bool VITA_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path);
88extern SDL_FunctionPointer VITA_GLES_GetProcAddress(SDL_VideoDevice *_this, const char *proc);
89extern void VITA_GLES_UnloadLibrary(SDL_VideoDevice *_this);
90extern SDL_GLContext VITA_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window);
91extern bool VITA_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context);
92extern bool VITA_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval);
93extern bool VITA_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval);
94extern bool VITA_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
95extern bool VITA_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context);
96#endif
97
98// VITA on screen keyboard
99extern bool VITA_HasScreenKeyboardSupport(SDL_VideoDevice *_this);
100extern void VITA_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props);
101extern void VITA_HideScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window);
102extern bool VITA_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window *window);
103
104extern void VITA_PumpEvents(SDL_VideoDevice *_this);
105
106#endif // SDL_pspvideo_h