Add PVR On Screen Keyboard Support
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
diff --git a/src/video/vita/SDL_vitagl_pvr.c b/src/video/vita/SDL_vitagl_pvr.c
index e85b489..1cc3371 100644
--- a/src/video/vita/SDL_vitagl_pvr.c
+++ b/src/video/vita/SDL_vitagl_pvr.c
@@ -37,34 +37,34 @@
int
VITA_GL_LoadLibrary(_THIS, const char *path)
{
- PVRSRV_PSP2_APPHINT hint;
- char* override = SDL_getenv("VITA_MODULE_PATH");
- char* default_path = "app0:module";
- char target_path[MAX_PATH];
-
- if (override != NULL)
- {
- default_path = override;
- }
+ PVRSRV_PSP2_APPHINT hint;
+ char* override = SDL_getenv("VITA_MODULE_PATH");
+ char* default_path = "app0:module";
+ char target_path[MAX_PATH];
+
+ if (override != NULL)
+ {
+ default_path = override;
+ }
- sceKernelLoadStartModule("vs0:sys/external/libfios2.suprx", 0, NULL, 0, NULL, NULL);
- sceKernelLoadStartModule("vs0:sys/external/libc.suprx", 0, NULL, 0, NULL, NULL);
+ sceKernelLoadStartModule("vs0:sys/external/libfios2.suprx", 0, NULL, 0, NULL, NULL);
+ sceKernelLoadStartModule("vs0:sys/external/libc.suprx", 0, NULL, 0, NULL, NULL);
- SDL_snprintf(target_path, MAX_PATH, "%s/%s", default_path, "libgpu_es4_ext.suprx");
- sceKernelLoadStartModule(target_path, 0, NULL, 0, NULL, NULL);
+ SDL_snprintf(target_path, MAX_PATH, "%s/%s", default_path, "libgpu_es4_ext.suprx");
+ sceKernelLoadStartModule(target_path, 0, NULL, 0, NULL, NULL);
- SDL_snprintf(target_path, MAX_PATH, "%s/%s", default_path, "libIMGEGL.suprx");
- sceKernelLoadStartModule(target_path, 0, NULL, 0, NULL, NULL);
+ SDL_snprintf(target_path, MAX_PATH, "%s/%s", default_path, "libIMGEGL.suprx");
+ sceKernelLoadStartModule(target_path, 0, NULL, 0, NULL, NULL);
- PVRSRVInitializeAppHint(&hint);
+ PVRSRVInitializeAppHint(&hint);
- SDL_snprintf(hint.szGLES1, MAX_PATH, "%s/%s", default_path, "libGLESv1_CM.suprx");
- SDL_snprintf(hint.szGLES2, MAX_PATH, "%s/%s", default_path, "libGLESv2.suprx");
- SDL_snprintf(hint.szWindowSystem, MAX_PATH, "%s/%s", default_path, "libpvrPSP2_WSEGL.suprx");
+ SDL_snprintf(hint.szGLES1, MAX_PATH, "%s/%s", default_path, "libGLESv1_CM.suprx");
+ SDL_snprintf(hint.szGLES2, MAX_PATH, "%s/%s", default_path, "libGLESv2.suprx");
+ SDL_snprintf(hint.szWindowSystem, MAX_PATH, "%s/%s", default_path, "libpvrPSP2_WSEGL.suprx");
- PVRSRVCreateVirtualAppHint(&hint);
+ PVRSRVCreateVirtualAppHint(&hint);
- return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) 0, 0);
+ return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) 0, 0);
}
SDL_GLContext
@@ -86,6 +86,10 @@ VITA_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
int
VITA_GL_SwapWindow(_THIS, SDL_Window * window)
{
+ SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
+ if (videodata->ime_active) {
+ sceImeUpdate();
+ }
return SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
}
diff --git a/src/video/vita/SDL_vitakeyboard.c b/src/video/vita/SDL_vitakeyboard.c
index 2f6679b..a4e9e21 100644
--- a/src/video/vita/SDL_vitakeyboard.c
+++ b/src/video/vita/SDL_vitakeyboard.c
@@ -42,6 +42,9 @@ Uint8 lock_key_down = 0;
void
VITA_InitKeyboard(void)
{
+#if defined(SDL_VIDEO_VITA_PVR)
+ sceSysmoduleLoadModule(SCE_SYSMODULE_IME); /** For PVR OSK Support **/
+#endif
sceHidKeyboardEnumerate(&keyboard_hid_handle, 1);
}
diff --git a/src/video/vita/SDL_vitavideo.c b/src/video/vita/SDL_vitavideo.c
index b5ece3b..89966cb 100644
--- a/src/video/vita/SDL_vitavideo.c
+++ b/src/video/vita/SDL_vitavideo.c
@@ -51,8 +51,6 @@
#define VITA_GL_DeleteContext SDL_EGL_DeleteContext
#endif
-#include <psp2/ime_dialog.h>
-
SDL_Window *Vita_Window;
static void
@@ -176,11 +174,32 @@ VITA_VideoInit(_THIS)
{
SDL_VideoDisplay display;
SDL_DisplayMode current_mode;
-
+#if defined(SDL_VIDEO_VITA_PVR)
+ char* res = SDL_getenv("VITA_RESOLUTION");
+#endif
SDL_zero(current_mode);
- current_mode.w = 960;
- current_mode.h = 544;
+#if defined(SDL_VIDEO_VITA_PVR)
+ if (res) {
+ /* 1088i for PSTV (Or Sharpscale) */
+ if (!SDL_strncmp(res, "1080", 4)) {
+ current_mode.w = 1920;
+ current_mode.h = 1088;
+ }
+ /* 725p for PSTV (Or Sharpscale) */
+ else if (!SDL_strncmp(res, "720", 3)) {
+ current_mode.w = 1280;
+ current_mode.h = 725;
+ }
+ }
+ /* 544p */
+ else {
+#endif
+ current_mode.w = 960;
+ current_mode.h = 544;
+#if defined(SDL_VIDEO_VITA_PVR)
+ }
+#endif
current_mode.refresh_rate = 60;
/* 32 bpp for default */
@@ -223,6 +242,9 @@ int
VITA_CreateWindow(_THIS, SDL_Window * window)
{
SDL_WindowData *wdata;
+#if defined(SDL_VIDEO_VITA_PVR)
+ Psp2NativeWindow win;
+#endif
/* Allocate window internal data */
wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
@@ -243,8 +265,24 @@ VITA_CreateWindow(_THIS, SDL_Window * window)
Vita_Window = window;
#if defined(SDL_VIDEO_VITA_PVR)
+ win.type = PSP2_DRAWABLE_TYPE_WINDOW;
+ win.numFlipBuffers = 2;
+ win.flipChainThrdAffinity = 0x20000;
+
+ /* 1088i for PSTV (Or Sharpscale) */
+ if (window->w == 1920) {
+ win.windowSize = PSP2_WINDOW_1920X1088;
+ }
+ /* 725p for PSTV (Or Sharpscale) */
+ else if (window->w == 1280) {
+ win.windowSize = PSP2_WINDOW_1280X725;
+ }
+ /* 544p */
+ else {
+ win.windowSize = PSP2_WINDOW_960X544;
+ }
if ((window->flags & SDL_WINDOW_OPENGL) != 0) {
- wdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) 0);
+ wdata->egl_surface = SDL_EGL_CreateSurface(_this, &win);
if (wdata->egl_surface == EGL_NO_SURFACE) {
return SDL_SetError("Could not create GLES window surface");
@@ -353,13 +391,109 @@ SDL_bool VITA_HasScreenKeyboardSupport(_THIS)
#define SCE_IME_LANGUAGE_ENGLISH_US SCE_IME_LANGUAGE_ENGLISH
#endif
+static void utf16_to_utf8(const uint16_t *src, uint8_t *dst) {
+ int i;
+ for (i = 0; src[i]; i++) {
+ if ((src[i] & 0xFF80) == 0) {
+ *(dst++) = src[i] & 0xFF;
+ } else if((src[i] & 0xF800) == 0) {
+ *(dst++) = ((src[i] >> 6) & 0xFF) | 0xC0;
+ *(dst++) = (src[i] & 0x3F) | 0x80;
+ } else if((src[i] & 0xFC00) == 0xD800 && (src[i + 1] & 0xFC00) == 0xDC00) {
+ *(dst++) = (((src[i] + 64) >> 8) & 0x3) | 0xF0;
+ *(dst++) = (((src[i] >> 2) + 16) & 0x3F) | 0x80;
+ *(dst++) = ((src[i] >> 4) & 0x30) | 0x80 | ((src[i + 1] << 2) & 0xF);
+ *(dst++) = (src[i + 1] & 0x3F) | 0x80;
+ i += 1;
+ } else {
+ *(dst++) = ((src[i] >> 12) & 0xF) | 0xE0;
+ *(dst++) = ((src[i] >> 6) & 0x3F) | 0x80;
+ *(dst++) = (src[i] & 0x3F) | 0x80;
+ }
+ }
+
+ *dst = '\0';
+}
+
+#if defined (SDL_VIDEO_VITA_PVR)
+SceWChar16 libime_out[SCE_IME_MAX_PREEDIT_LENGTH + SCE_IME_MAX_TEXT_LENGTH + 1];
+char libime_initval[8] = { 1 };
+SceImeCaret caret_rev;
+
+void VITA_ImeEventHandler(void *arg, const SceImeEventData *e)
+{
+ SDL_VideoData *videodata = (SDL_VideoData *)arg;
+ SDL_Scancode scancode;
+ uint8_t utf8_buffer[SCE_IME_MAX_TEXT_LENGTH];
+ switch (e->id) {
+ case SCE_IME_EVENT_UPDATE_TEXT:
+ if (e->param.text.caretIndex == 0) {
+ scancode = SDL_GetScancodeFromKey(0x08);
+ SDL_SendKeyboardKeyAutoRelease(scancode);
+ sceImeSetText((SceWChar16 *)libime_initval, 4);
+ }
+ else {
+ scancode = SDL_GetScancodeFromKey(*(SceWChar16 *)&libime_out[1]);
+ if (scancode == SDL_SCANCODE_SPACE) {
+ SDL_SendKeyboardKeyAutoRelease(SDL_SCANCODE_SPACE);
+ }
+ else {
+ utf16_to_utf8((SceWChar16 *)&libime_out[1], utf8_buffer);
+ SDL_SendKeyboardText((const char*)utf8_buffer);
+ }
+ SDL_memset(&caret_rev, 0, sizeof(SceImeCaret));
+ SDL_memset(libime_out, 0, ((SCE_IME_MAX_PREEDIT_LENGTH + SCE_IME_MAX_TEXT_LENGTH + 1) * sizeof(SceWChar16)));
+ caret_rev.index = 1;
+ sceImeSetCaret(&caret_rev);
+ sceImeSetText((SceWChar16 *)libime_initval, 4);
+ }
+ break;
+ case SCE_IME_EVENT_PRESS_ENTER:
+ scancode = SDL_GetScancodeFromKey(0x0D);
+ SDL_SendKeyboardKeyAutoRelease(scancode);
+ case SCE_IME_EVENT_PRESS_CLOSE:
+ sceImeClose();
+ videodata->ime_active = SDL_FALSE;
+ break;
+ }
+}
+#endif
+
void VITA_ShowScreenKeyboard(_THIS, SDL_Window *window)
{
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
+ SceInt32 res;
+
+#if defined(SDL_VIDEO_VITA_PVR)
+
+ SceUInt32 libime_work[SCE_IME_WORK_BUFFER_SIZE / sizeof(SceInt32)];
+ SceImeParam param;
+ sceImeParamInit(¶m);
+
+ SDL_memset(libime_out, 0, ((SCE_IME_MAX_PREEDIT_LENGTH + SCE_IME_MAX_TEXT_LENGTH + 1) * sizeof(SceWChar16)));
+
+ param.supportedLanguages = SCE_IME_LANGUAGE_ENGLISH_US;
+ param.languagesForced = SCE_FALSE;
+ param.type = SCE_IME_TYPE_DEFAULT;
+ param.option = SCE_IME_OPTION_NO_ASSISTANCE;
+ param.inputTextBuffer = libime_out;
+ param.maxTextLength = SCE_IME_MAX_TEXT_LENGTH;
+ param.handler = VITA_ImeEventHandler;
+ param.filter = NULL;
+ param.initialText = (SceWChar16 *)libime_initval;
+ param.arg = videodata;
+ param.work = libime_work;
+
+ res = sceImeOpen(¶m);
+ if (res < 0) {
+ SDL_SetError("Failed to init IME");
+ return;
+ }
+
+#elif
SceWChar16 *title = u"";
SceWChar16 *text = u"";
- SceInt32 res;
SceImeDialogParam param;
sceImeDialogParamInit(¶m);
@@ -381,11 +515,14 @@ void VITA_ShowScreenKeyboard(_THIS, SDL_Window *window)
return;
}
+#endif
+
videodata->ime_active = SDL_TRUE;
}
void VITA_HideScreenKeyboard(_THIS, SDL_Window *window)
{
+#if !defined(SDL_VIDEO_VITA_PVR)
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
SceCommonDialogStatus dialogStatus = sceImeDialogGetStatus();
@@ -401,48 +538,30 @@ void VITA_HideScreenKeyboard(_THIS, SDL_Window *window)
}
videodata->ime_active = SDL_FALSE;
+#endif
}
SDL_bool VITA_IsScreenKeyboardShown(_THIS, SDL_Window *window)
{
+#if defined(SDL_VIDEO_VITA_PVR)
+ SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
+ return videodata->ime_active;
+#elif
SceCommonDialogStatus dialogStatus = sceImeDialogGetStatus();
return (dialogStatus == SCE_COMMON_DIALOG_STATUS_RUNNING);
-}
-
-
-static void utf16_to_utf8(const uint16_t *src, uint8_t *dst) {
- int i;
- for (i = 0; src[i]; i++) {
- if ((src[i] & 0xFF80) == 0) {
- *(dst++) = src[i] & 0xFF;
- } else if((src[i] & 0xF800) == 0) {
- *(dst++) = ((src[i] >> 6) & 0xFF) | 0xC0;
- *(dst++) = (src[i] & 0x3F) | 0x80;
- } else if((src[i] & 0xFC00) == 0xD800 && (src[i + 1] & 0xFC00) == 0xDC00) {
- *(dst++) = (((src[i] + 64) >> 8) & 0x3) | 0xF0;
- *(dst++) = (((src[i] >> 2) + 16) & 0x3F) | 0x80;
- *(dst++) = ((src[i] >> 4) & 0x30) | 0x80 | ((src[i + 1] << 2) & 0xF);
- *(dst++) = (src[i + 1] & 0x3F) | 0x80;
- i += 1;
- } else {
- *(dst++) = ((src[i] >> 12) & 0xF) | 0xE0;
- *(dst++) = ((src[i] >> 6) & 0x3F) | 0x80;
- *(dst++) = (src[i] & 0x3F) | 0x80;
- }
- }
-
- *dst = '\0';
+#endif
}
void VITA_PumpEvents(_THIS)
{
+#if !defined(SDL_VIDEO_VITA_PVR)
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
-
-
+#endif
VITA_PollTouch();
VITA_PollKeyboard();
VITA_PollMouse();
+#if !defined(SDL_VIDEO_VITA_PVR)
if (videodata->ime_active == SDL_TRUE) {
// update IME status. Terminate, if finished
SceCommonDialogStatus dialogStatus = sceImeDialogGetStatus();
@@ -469,6 +588,7 @@ void VITA_PumpEvents(_THIS)
}
}
+#endif
}
#endif /* SDL_VIDEO_DRIVER_VITA */
diff --git a/src/video/vita/SDL_vitavideo.h b/src/video/vita/SDL_vitavideo.h
index b63b1d8..b2c6029 100644
--- a/src/video/vita/SDL_vitavideo.h
+++ b/src/video/vita/SDL_vitavideo.h
@@ -29,6 +29,7 @@
#include <psp2/types.h>
#include <psp2/display.h>
#include <psp2/ime_dialog.h>
+#include <psp2/sysmodule.h>
typedef struct SDL_VideoData
{