Add support for message box
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
diff --git a/src/render/vitagxm/SDL_render_vita_gxm_tools.c b/src/render/vitagxm/SDL_render_vita_gxm_tools.c
index f410f08..e98d826 100644
--- a/src/render/vitagxm/SDL_render_vita_gxm_tools.c
+++ b/src/render/vitagxm/SDL_render_vita_gxm_tools.c
@@ -32,6 +32,7 @@
#include <psp2/gxm.h>
#include <psp2/types.h>
#include <psp2/kernel/sysmem.h>
+#include <psp2/message_dialog.h>
#include <stdio.h>
#include <string.h>
@@ -1178,6 +1179,91 @@ gxm_texture_set_filters(gxm_texture *texture, SceGxmTextureFilter min_filter, Sc
sceGxmTextureSetMagFilter(&texture->gxm_tex, mag_filter);
}
+static unsigned int back_buffer_index_for_common_dialog = 0;
+static unsigned int front_buffer_index_for_common_dialog = 0;
+struct
+{
+ VITA_GXM_DisplayData displayData;
+ SceGxmSyncObject* sync;
+ SceGxmColorSurface surf;
+ SceUID uid;
+} buffer_for_common_dialog[VITA_GXM_BUFFERS];
+
+void gxm_minimal_init_for_common_dialog(void)
+{
+ SceGxmInitializeParams initializeParams;
+ SDL_zero(initializeParams);
+ initializeParams.flags = 0;
+ initializeParams.displayQueueMaxPendingCount = VITA_GXM_PENDING_SWAPS;
+ initializeParams.displayQueueCallback = display_callback;
+ initializeParams.displayQueueCallbackDataSize = sizeof(VITA_GXM_DisplayData);
+ initializeParams.parameterBufferSize = SCE_GXM_DEFAULT_PARAMETER_BUFFER_SIZE;
+ sceGxmInitialize(&initializeParams);
+}
+
+void gxm_minimal_term_for_common_dialog(void)
+{
+ sceGxmTerminate();
+}
+
+void gxm_init_for_common_dialog(void)
+{
+ for (int i = 0; i < VITA_GXM_BUFFERS; i += 1)
+ {
+ buffer_for_common_dialog[i].displayData.wait_vblank = SDL_TRUE;
+ buffer_for_common_dialog[i].displayData.address = mem_gpu_alloc(
+ SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW,
+ 4 * VITA_GXM_SCREEN_STRIDE * VITA_GXM_SCREEN_HEIGHT,
+ SCE_GXM_COLOR_SURFACE_ALIGNMENT,
+ SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE,
+ &buffer_for_common_dialog[i].uid);
+ sceGxmColorSurfaceInit(
+ &buffer_for_common_dialog[i].surf,
+ VITA_GXM_PIXEL_FORMAT,
+ SCE_GXM_COLOR_SURFACE_LINEAR,
+ SCE_GXM_COLOR_SURFACE_SCALE_NONE,
+ SCE_GXM_OUTPUT_REGISTER_SIZE_32BIT,
+ VITA_GXM_SCREEN_WIDTH,
+ VITA_GXM_SCREEN_HEIGHT,
+ VITA_GXM_SCREEN_STRIDE,
+ buffer_for_common_dialog[i].displayData.address
+ );
+ sceGxmSyncObjectCreate(&buffer_for_common_dialog[i].sync);
+ }
+ sceGxmDisplayQueueFinish();
+}
+
+void gxm_swap_for_common_dialog(void)
+{
+ SceCommonDialogUpdateParam updateParam;
+ SDL_zero(updateParam);
+ updateParam.renderTarget.colorFormat = VITA_GXM_PIXEL_FORMAT;
+ updateParam.renderTarget.surfaceType = SCE_GXM_COLOR_SURFACE_LINEAR;
+ updateParam.renderTarget.width = VITA_GXM_SCREEN_WIDTH;
+ updateParam.renderTarget.height = VITA_GXM_SCREEN_HEIGHT;
+ updateParam.renderTarget.strideInPixels = VITA_GXM_SCREEN_STRIDE;
+
+ updateParam.renderTarget.colorSurfaceData = buffer_for_common_dialog[back_buffer_index_for_common_dialog].displayData.address;
+
+ updateParam.displaySyncObject = buffer_for_common_dialog[back_buffer_index_for_common_dialog].sync;
+ SDL_memset(buffer_for_common_dialog[back_buffer_index_for_common_dialog].displayData.address, 0, 4 * VITA_GXM_SCREEN_STRIDE * VITA_GXM_SCREEN_HEIGHT);
+ sceCommonDialogUpdate(&updateParam);
+
+ sceGxmDisplayQueueAddEntry(buffer_for_common_dialog[front_buffer_index_for_common_dialog].sync, buffer_for_common_dialog[back_buffer_index_for_common_dialog].sync, &buffer_for_common_dialog[back_buffer_index_for_common_dialog].displayData);
+ front_buffer_index_for_common_dialog = back_buffer_index_for_common_dialog;
+ back_buffer_index_for_common_dialog = (back_buffer_index_for_common_dialog + 1) % VITA_GXM_BUFFERS;
+}
+
+void gxm_term_for_common_dialog(void)
+{
+ sceGxmDisplayQueueFinish();
+ for (int i = 0; i < VITA_GXM_BUFFERS; i += 1)
+ {
+ mem_gpu_free(buffer_for_common_dialog[i].uid);
+ sceGxmSyncObjectDestroy(buffer_for_common_dialog[i].sync);
+ }
+}
+
#endif /* SDL_VIDEO_RENDER_VITA_GXM */
/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/render/vitagxm/SDL_render_vita_gxm_tools.h b/src/render/vitagxm/SDL_render_vita_gxm_tools.h
index c1dfc6c..c103b00 100644
--- a/src/render/vitagxm/SDL_render_vita_gxm_tools.h
+++ b/src/render/vitagxm/SDL_render_vita_gxm_tools.h
@@ -59,6 +59,12 @@ unsigned int gxm_texture_get_height(const gxm_texture *texture);
unsigned int gxm_texture_get_stride(const gxm_texture *texture);
void *gxm_texture_get_datap(const gxm_texture *texture);
+void gxm_minimal_init_for_common_dialog(void);
+void gxm_minimal_term_for_common_dialog(void);
+void gxm_init_for_common_dialog(void);
+void gxm_swap_for_common_dialog(void);
+void gxm_term_for_common_dialog(void);
+
#endif /* SDL_RENDER_VITA_GXM_TOOLS_H */
/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index e262a19..62da102 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -4048,6 +4048,9 @@ SDL_IsScreenKeyboardShown(SDL_Window *window)
#if SDL_VIDEO_DRIVER_OS2
#include "os2/SDL_os2messagebox.h"
#endif
+#if SDL_VIDEO_DRIVER_VITA
+#include "vita/SDL_vitamessagebox.h"
+#endif
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT || SDL_VIDEO_DRIVER_COCOA || SDL_VIDEO_DRIVER_UIKIT || SDL_VIDEO_DRIVER_X11 || SDL_VIDEO_DRIVER_HAIKU || SDL_VIDEO_DRIVER_OS2
static SDL_bool SDL_MessageboxValidForDriver(const SDL_MessageBoxData *messageboxdata, SDL_SYSWM_TYPE drivertype)
@@ -4162,6 +4165,12 @@ SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
retval = 0;
}
#endif
+#if SDL_VIDEO_DRIVER_VITA
+ if (retval == -1 &&
+ VITA_ShowMessageBox(messageboxdata, buttonid) == 0) {
+ retval = 0;
+ }
+#endif
if (retval == -1) {
SDL_SetError("No message system available");
}
diff --git a/src/video/vita/SDL_vitamessagebox.c b/src/video/vita/SDL_vitamessagebox.c
new file mode 100644
index 0000000..65d4bad
--- /dev/null
+++ b/src/video/vita/SDL_vitamessagebox.c
@@ -0,0 +1,147 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_VITA
+
+#include "SDL_vitavideo.h"
+#include "SDL_vitamessagebox.h"
+#include <psp2/message_dialog.h>
+
+#if SDL_VIDEO_RENDER_VITA_GXM
+#include "../../render/vitagxm/SDL_render_vita_gxm_tools.h"
+#endif /* SDL_VIDEO_RENDER_VITA_GXM */
+
+int VITA_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
+{
+ SceCommonDialogConfigParam commonDialogConfigParam;
+ SceMsgDialogParam param;
+ SceMsgDialogUserMessageParam msgParam;
+ SceMsgDialogButtonsParam buttonParam;
+ SceDisplayFrameBuf dispparam;
+
+ SceMsgDialogResult dialog_result;
+ SceCommonDialogErrorCode init_result;
+ SDL_bool setup_minimal_gxm = SDL_FALSE;
+#if !SDL_VIDEO_RENDER_VITA_GXM
+ {
+ return -1;
+ }
+#endif
+#if SDL_VIDEO_RENDER_VITA_GXM
+ if (messageboxdata->numbuttons > 3)
+ {
+ return -1;
+ }
+ SDL_zero(commonDialogConfigParam);
+ sceCommonDialogSetConfigParam(&commonDialogConfigParam);
+ SDL_zero(param);
+ sceMsgDialogParamInit(¶m);
+ param.mode = SCE_MSG_DIALOG_MODE_USER_MSG;
+ SDL_zero(msgParam);
+ msgParam.msg = (const SceChar8*)messageboxdata->message;
+ SDL_zero(buttonParam);
+ if (messageboxdata->numbuttons == 3)
+ {
+ msgParam.buttonType = SCE_MSG_DIALOG_BUTTON_TYPE_3BUTTONS;
+ msgParam.buttonParam = &buttonParam;
+ buttonParam.msg1 = messageboxdata->buttons[0].text;
+ buttonParam.msg2 = messageboxdata->buttons[1].text;
+ buttonParam.msg3 = messageboxdata->buttons[2].text;
+ }
+ else if (messageboxdata->numbuttons == 2)
+ {
+ msgParam.buttonType = SCE_MSG_DIALOG_BUTTON_TYPE_YESNO;
+ }
+ else if (messageboxdata->numbuttons == 1)
+ {
+ msgParam.buttonType = SCE_MSG_DIALOG_BUTTON_TYPE_OK;
+ }
+ param.userMsgParam = &msgParam;
+
+ dispparam.size = sizeof(dispparam);
+
+ init_result = sceMsgDialogInit(¶m);
+
+ // Setup display if it hasn't been initialized before
+ if (init_result == SCE_COMMON_DIALOG_ERROR_GXM_IS_UNINITIALIZED)
+ {
+ gxm_minimal_init_for_common_dialog();
+ init_result = sceMsgDialogInit(¶m);
+ setup_minimal_gxm = SDL_TRUE;
+ }
+
+ gxm_init_for_common_dialog();
+
+ if (init_result >= 0)
+ {
+ while (sceMsgDialogGetStatus() == SCE_COMMON_DIALOG_STATUS_RUNNING)
+ {
+ gxm_swap_for_common_dialog();
+ }
+ SDL_zero(dialog_result);
+ sceMsgDialogGetResult(&dialog_result);
+
+ if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_BUTTON1)
+ {
+ *buttonid = messageboxdata->buttons[0].buttonid;
+ }
+ else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_BUTTON2)
+ {
+ *buttonid = messageboxdata->buttons[1].buttonid;
+ }
+ else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_BUTTON3)
+ {
+ *buttonid = messageboxdata->buttons[2].buttonid;
+ }
+ else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_YES)
+ {
+ *buttonid = messageboxdata->buttons[0].buttonid;
+ }
+ else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_NO)
+ {
+ *buttonid = messageboxdata->buttons[1].buttonid;
+ }
+ else if (dialog_result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_OK)
+ {
+ *buttonid = messageboxdata->buttons[0].buttonid;
+ }
+ sceMsgDialogTerm();
+ }
+ else
+ {
+ return -1;
+ }
+
+ gxm_term_for_common_dialog();
+
+ if (setup_minimal_gxm)
+ {
+ gxm_minimal_term_for_common_dialog();
+ }
+
+ return 0;
+#endif
+}
+
+#endif /* SDL_VIDEO_DRIVER_VITA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/vita/SDL_vitamessagebox.h b/src/video/vita/SDL_vitamessagebox.h
new file mode 100644
index 0000000..65ce73b
--- /dev/null
+++ b/src/video/vita/SDL_vitamessagebox.h
@@ -0,0 +1,33 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_vitamessagebox_h_
+#define SDL_vitamessagebox_h_
+
+#if SDL_VIDEO_DRIVER_VITA
+
+extern int VITA_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
+
+#endif /* SDL_VIDEO_DRIVER_VITA */
+
+#endif /* SDL_vitamessagebox_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */