diff options
| author | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
| commit | 5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch) | |
| tree | 8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/src/video/qnx | |
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/src/video/qnx')
| -rw-r--r-- | contrib/SDL-3.2.8/src/video/qnx/SDL_qnx.h | 48 | ||||
| -rw-r--r-- | contrib/SDL-3.2.8/src/video/qnx/SDL_qnxgl.c | 277 | ||||
| -rw-r--r-- | contrib/SDL-3.2.8/src/video/qnx/SDL_qnxkeyboard.c | 132 | ||||
| -rw-r--r-- | contrib/SDL-3.2.8/src/video/qnx/SDL_qnxvideo.c | 351 |
4 files changed, 808 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/video/qnx/SDL_qnx.h b/contrib/SDL-3.2.8/src/video/qnx/SDL_qnx.h new file mode 100644 index 0000000..f8a50cf --- /dev/null +++ b/contrib/SDL-3.2.8/src/video/qnx/SDL_qnx.h | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 2017 BlackBerry Limited | ||
| 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_QNX_H__ | ||
| 23 | #define __SDL_QNX_H__ | ||
| 24 | |||
| 25 | #include "../SDL_sysvideo.h" | ||
| 26 | #include <screen/screen.h> | ||
| 27 | #include <EGL/egl.h> | ||
| 28 | |||
| 29 | typedef struct | ||
| 30 | { | ||
| 31 | screen_window_t window; | ||
| 32 | EGLSurface surface; | ||
| 33 | EGLConfig conf; | ||
| 34 | } window_impl_t; | ||
| 35 | |||
| 36 | extern void handleKeyboardEvent(screen_event_t event); | ||
| 37 | |||
| 38 | extern bool glGetConfig(EGLConfig *pconf, int *pformat); | ||
| 39 | extern bool glLoadLibrary(SDL_VideoDevice *_this, const char *name); | ||
| 40 | extern SDL_FunctionPointer glGetProcAddress(SDL_VideoDevice *_this, const char *proc); | ||
| 41 | extern SDL_GLContext glCreateContext(SDL_VideoDevice *_this, SDL_Window *window); | ||
| 42 | extern bool glSetSwapInterval(SDL_VideoDevice *_this, int interval); | ||
| 43 | extern bool glSwapWindow(SDL_VideoDevice *_this, SDL_Window *window); | ||
| 44 | extern bool glMakeCurrent(SDL_VideoDevice *_this, SDL_Window * window, SDL_GLContext context); | ||
| 45 | extern void glDeleteContext(SDL_VideoDevice *_this, SDL_GLContext context); | ||
| 46 | extern void glUnloadLibrary(SDL_VideoDevice *_this); | ||
| 47 | |||
| 48 | #endif | ||
diff --git a/contrib/SDL-3.2.8/src/video/qnx/SDL_qnxgl.c b/contrib/SDL-3.2.8/src/video/qnx/SDL_qnxgl.c new file mode 100644 index 0000000..639e556 --- /dev/null +++ b/contrib/SDL-3.2.8/src/video/qnx/SDL_qnxgl.c | |||
| @@ -0,0 +1,277 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 2017 BlackBerry Limited | ||
| 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 | #include "SDL_qnx.h" | ||
| 24 | |||
| 25 | static EGLDisplay egl_disp; | ||
| 26 | |||
| 27 | /** | ||
| 28 | * Detertmines the pixel format to use based on the current display and EGL | ||
| 29 | * configuration. | ||
| 30 | * @param egl_conf EGL configuration to use | ||
| 31 | * @return A SCREEN_FORMAT* constant for the pixel format to use | ||
| 32 | */ | ||
| 33 | static int chooseFormat(EGLConfig egl_conf) | ||
| 34 | { | ||
| 35 | EGLint buffer_bit_depth; | ||
| 36 | EGLint alpha_bit_depth; | ||
| 37 | |||
| 38 | eglGetConfigAttrib(egl_disp, egl_conf, EGL_BUFFER_SIZE, &buffer_bit_depth); | ||
| 39 | eglGetConfigAttrib(egl_disp, egl_conf, EGL_ALPHA_SIZE, &alpha_bit_depth); | ||
| 40 | |||
| 41 | switch (buffer_bit_depth) { | ||
| 42 | case 32: | ||
| 43 | return SCREEN_FORMAT_RGBX8888; | ||
| 44 | case 24: | ||
| 45 | return SDL_PIXELFORMAT_RGB24; | ||
| 46 | case 16: | ||
| 47 | switch (alpha_bit_depth) { | ||
| 48 | case 4: | ||
| 49 | return SCREEN_FORMAT_RGBX4444; | ||
| 50 | case 1: | ||
| 51 | return SCREEN_FORMAT_RGBA5551; | ||
| 52 | default: | ||
| 53 | return SCREEN_FORMAT_RGB565; | ||
| 54 | } | ||
| 55 | default: | ||
| 56 | return 0; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | /** | ||
| 61 | * Enumerates the supported EGL configurations and chooses a suitable one. | ||
| 62 | * @param[out] pconf The chosen configuration | ||
| 63 | * @param[out] pformat The chosen pixel format | ||
| 64 | * @return true if successful, -1 on error | ||
| 65 | */ | ||
| 66 | bool glGetConfig(EGLConfig *pconf, int *pformat) | ||
| 67 | { | ||
| 68 | EGLConfig egl_conf = (EGLConfig)0; | ||
| 69 | EGLConfig *egl_configs; | ||
| 70 | EGLint egl_num_configs; | ||
| 71 | EGLint val; | ||
| 72 | EGLBoolean rc; | ||
| 73 | EGLint i; | ||
| 74 | |||
| 75 | // Determine the numbfer of configurations. | ||
| 76 | rc = eglGetConfigs(egl_disp, NULL, 0, &egl_num_configs); | ||
| 77 | if (rc != EGL_TRUE) { | ||
| 78 | return false; | ||
| 79 | } | ||
| 80 | |||
| 81 | if (egl_num_configs == 0) { | ||
| 82 | return false; | ||
| 83 | } | ||
| 84 | |||
| 85 | // Allocate enough memory for all configurations. | ||
| 86 | egl_configs = SDL_malloc(egl_num_configs * sizeof(*egl_configs)); | ||
| 87 | if (!egl_configs) { | ||
| 88 | return false; | ||
| 89 | } | ||
| 90 | |||
| 91 | // Get the list of configurations. | ||
| 92 | rc = eglGetConfigs(egl_disp, egl_configs, egl_num_configs, | ||
| 93 | &egl_num_configs); | ||
| 94 | if (rc != EGL_TRUE) { | ||
| 95 | SDL_free(egl_configs); | ||
| 96 | return false; | ||
| 97 | } | ||
| 98 | |||
| 99 | // Find a good configuration. | ||
| 100 | for (i = 0; i < egl_num_configs; i++) { | ||
| 101 | eglGetConfigAttrib(egl_disp, egl_configs[i], EGL_SURFACE_TYPE, &val); | ||
| 102 | if (!(val & EGL_WINDOW_BIT)) { | ||
| 103 | continue; | ||
| 104 | } | ||
| 105 | |||
| 106 | eglGetConfigAttrib(egl_disp, egl_configs[i], EGL_RENDERABLE_TYPE, &val); | ||
| 107 | if (!(val & EGL_OPENGL_ES2_BIT)) { | ||
| 108 | continue; | ||
| 109 | } | ||
| 110 | |||
| 111 | eglGetConfigAttrib(egl_disp, egl_configs[i], EGL_DEPTH_SIZE, &val); | ||
| 112 | if (val == 0) { | ||
| 113 | continue; | ||
| 114 | } | ||
| 115 | |||
| 116 | egl_conf = egl_configs[i]; | ||
| 117 | break; | ||
| 118 | } | ||
| 119 | |||
| 120 | SDL_free(egl_configs); | ||
| 121 | *pconf = egl_conf; | ||
| 122 | *pformat = chooseFormat(egl_conf); | ||
| 123 | |||
| 124 | return true; | ||
| 125 | } | ||
| 126 | |||
| 127 | /** | ||
| 128 | * Initializes the EGL library. | ||
| 129 | * @param SDL_VideoDevice *_this | ||
| 130 | * @param name unused | ||
| 131 | * @return 0 if successful, -1 on error | ||
| 132 | */ | ||
| 133 | bool glLoadLibrary(SDL_VideoDevice *_this, const char *name) | ||
| 134 | { | ||
| 135 | EGLNativeDisplayType disp_id = EGL_DEFAULT_DISPLAY; | ||
| 136 | |||
| 137 | egl_disp = eglGetDisplay(disp_id); | ||
| 138 | if (egl_disp == EGL_NO_DISPLAY) { | ||
| 139 | return false; | ||
| 140 | } | ||
| 141 | |||
| 142 | if (eglInitialize(egl_disp, NULL, NULL) == EGL_FALSE) { | ||
| 143 | return false; | ||
| 144 | } | ||
| 145 | |||
| 146 | return true; | ||
| 147 | } | ||
| 148 | |||
| 149 | /** | ||
| 150 | * Finds the address of an EGL extension function. | ||
| 151 | * @param proc Function name | ||
| 152 | * @return Function address | ||
| 153 | */ | ||
| 154 | SDL_FunctionPointer glGetProcAddress(SDL_VideoDevice *_this, const char *proc) | ||
| 155 | { | ||
| 156 | return eglGetProcAddress(proc); | ||
| 157 | } | ||
| 158 | |||
| 159 | /** | ||
| 160 | * Associates the given window with the necessary EGL structures for drawing and | ||
| 161 | * displaying content. | ||
| 162 | * @param SDL_VideoDevice *_this | ||
| 163 | * @param window The SDL window to create the context for | ||
| 164 | * @return A pointer to the created context, if successful, NULL on error | ||
| 165 | */ | ||
| 166 | SDL_GLContext glCreateContext(SDL_VideoDevice *_this, SDL_Window *window) | ||
| 167 | { | ||
| 168 | window_impl_t *impl = (window_impl_t *)window->internal; | ||
| 169 | EGLContext context; | ||
| 170 | EGLSurface surface; | ||
| 171 | |||
| 172 | struct { | ||
| 173 | EGLint client_version[2]; | ||
| 174 | EGLint none; | ||
| 175 | } egl_ctx_attr = { | ||
| 176 | .client_version = { EGL_CONTEXT_CLIENT_VERSION, 2 }, | ||
| 177 | .none = EGL_NONE | ||
| 178 | }; | ||
| 179 | |||
| 180 | struct { | ||
| 181 | EGLint render_buffer[2]; | ||
| 182 | EGLint none; | ||
| 183 | } egl_surf_attr = { | ||
| 184 | .render_buffer = { EGL_RENDER_BUFFER, EGL_BACK_BUFFER }, | ||
| 185 | .none = EGL_NONE | ||
| 186 | }; | ||
| 187 | |||
| 188 | context = eglCreateContext(egl_disp, impl->conf, EGL_NO_CONTEXT, | ||
| 189 | (EGLint *)&egl_ctx_attr); | ||
| 190 | if (context == EGL_NO_CONTEXT) { | ||
| 191 | return NULL; | ||
| 192 | } | ||
| 193 | |||
| 194 | surface = eglCreateWindowSurface(egl_disp, impl->conf, | ||
| 195 | (EGLNativeWindowType)impl->window, | ||
| 196 | (EGLint *)&egl_surf_attr); | ||
| 197 | if (surface == EGL_NO_SURFACE) { | ||
| 198 | return NULL; | ||
| 199 | } | ||
| 200 | |||
| 201 | eglMakeCurrent(egl_disp, surface, surface, context); | ||
| 202 | |||
| 203 | impl->surface = surface; | ||
| 204 | return context; | ||
| 205 | } | ||
| 206 | |||
| 207 | /** | ||
| 208 | * Sets a new value for the number of frames to display before swapping buffers. | ||
| 209 | * @param SDL_VideoDevice *_this | ||
| 210 | * @param interval New interval value | ||
| 211 | * @return 0 if successful, -1 on error | ||
| 212 | */ | ||
| 213 | bool glSetSwapInterval(SDL_VideoDevice *_this, int interval) | ||
| 214 | { | ||
| 215 | if (eglSwapInterval(egl_disp, interval) != EGL_TRUE) { | ||
| 216 | return false; | ||
| 217 | } | ||
| 218 | |||
| 219 | return true; | ||
| 220 | } | ||
| 221 | |||
| 222 | /** | ||
| 223 | * Swaps the EGL buffers associated with the given window | ||
| 224 | * @param SDL_VideoDevice *_this | ||
| 225 | * @param window Window to swap buffers for | ||
| 226 | * @return 0 if successful, -1 on error | ||
| 227 | */ | ||
| 228 | bool glSwapWindow(SDL_VideoDevice *_this, SDL_Window *window) | ||
| 229 | { | ||
| 230 | // !!! FIXME: should we migrate this all over to use SDL_egl.c? | ||
| 231 | window_impl_t *impl = (window_impl_t *)window->internal; | ||
| 232 | return eglSwapBuffers(egl_disp, impl->surface) == EGL_TRUE ? 0 : -1; | ||
| 233 | } | ||
| 234 | |||
| 235 | /** | ||
| 236 | * Makes the given context the current one for drawing operations. | ||
| 237 | * @param SDL_VideoDevice *_this | ||
| 238 | * @param window SDL window associated with the context (maybe NULL) | ||
| 239 | * @param context The context to activate | ||
| 240 | * @return 0 if successful, -1 on error | ||
| 241 | */ | ||
| 242 | bool glMakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) | ||
| 243 | { | ||
| 244 | window_impl_t *impl; | ||
| 245 | EGLSurface surface = NULL; | ||
| 246 | |||
| 247 | if (window) { | ||
| 248 | impl = (window_impl_t *)window->internal; | ||
| 249 | surface = impl->surface; | ||
| 250 | } | ||
| 251 | |||
| 252 | if (eglMakeCurrent(egl_disp, surface, surface, context) != EGL_TRUE) { | ||
| 253 | return false; | ||
| 254 | } | ||
| 255 | |||
| 256 | return true; | ||
| 257 | } | ||
| 258 | |||
| 259 | /** | ||
| 260 | * Destroys a context. | ||
| 261 | * @param SDL_VideoDevice *_this | ||
| 262 | * @param context The context to destroy | ||
| 263 | */ | ||
| 264 | bool glDeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) | ||
| 265 | { | ||
| 266 | eglDestroyContext(egl_disp, context); | ||
| 267 | return true; | ||
| 268 | } | ||
| 269 | |||
| 270 | /** | ||
| 271 | * Terminates access to the EGL library. | ||
| 272 | * @param SDL_VideoDevice *_this | ||
| 273 | */ | ||
| 274 | void glUnloadLibrary(SDL_VideoDevice *_this) | ||
| 275 | { | ||
| 276 | eglTerminate(egl_disp); | ||
| 277 | } | ||
diff --git a/contrib/SDL-3.2.8/src/video/qnx/SDL_qnxkeyboard.c b/contrib/SDL-3.2.8/src/video/qnx/SDL_qnxkeyboard.c new file mode 100644 index 0000000..b224caa --- /dev/null +++ b/contrib/SDL-3.2.8/src/video/qnx/SDL_qnxkeyboard.c | |||
| @@ -0,0 +1,132 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 2017 BlackBerry Limited | ||
| 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 | #include "../../events/SDL_keyboard_c.h" | ||
| 24 | #include "SDL3/SDL_scancode.h" | ||
| 25 | #include "SDL3/SDL_events.h" | ||
| 26 | #include "SDL_qnx.h" | ||
| 27 | #include <sys/keycodes.h> | ||
| 28 | |||
| 29 | /** | ||
| 30 | * A map that translates Screen key names to SDL scan codes. | ||
| 31 | * This map is incomplete, but should include most major keys. | ||
| 32 | */ | ||
| 33 | static int key_to_sdl[] = { | ||
| 34 | [KEYCODE_SPACE] = SDL_SCANCODE_SPACE, | ||
| 35 | [KEYCODE_APOSTROPHE] = SDL_SCANCODE_APOSTROPHE, | ||
| 36 | [KEYCODE_COMMA] = SDL_SCANCODE_COMMA, | ||
| 37 | [KEYCODE_MINUS] = SDL_SCANCODE_MINUS, | ||
| 38 | [KEYCODE_PERIOD] = SDL_SCANCODE_PERIOD, | ||
| 39 | [KEYCODE_SLASH] = SDL_SCANCODE_SLASH, | ||
| 40 | [KEYCODE_ZERO] = SDL_SCANCODE_0, | ||
| 41 | [KEYCODE_ONE] = SDL_SCANCODE_1, | ||
| 42 | [KEYCODE_TWO] = SDL_SCANCODE_2, | ||
| 43 | [KEYCODE_THREE] = SDL_SCANCODE_3, | ||
| 44 | [KEYCODE_FOUR] = SDL_SCANCODE_4, | ||
| 45 | [KEYCODE_FIVE] = SDL_SCANCODE_5, | ||
| 46 | [KEYCODE_SIX] = SDL_SCANCODE_6, | ||
| 47 | [KEYCODE_SEVEN] = SDL_SCANCODE_7, | ||
| 48 | [KEYCODE_EIGHT] = SDL_SCANCODE_8, | ||
| 49 | [KEYCODE_NINE] = SDL_SCANCODE_9, | ||
| 50 | [KEYCODE_SEMICOLON] = SDL_SCANCODE_SEMICOLON, | ||
| 51 | [KEYCODE_EQUAL] = SDL_SCANCODE_EQUALS, | ||
| 52 | [KEYCODE_LEFT_BRACKET] = SDL_SCANCODE_LEFTBRACKET, | ||
| 53 | [KEYCODE_BACK_SLASH] = SDL_SCANCODE_BACKSLASH, | ||
| 54 | [KEYCODE_RIGHT_BRACKET] = SDL_SCANCODE_RIGHTBRACKET, | ||
| 55 | [KEYCODE_GRAVE] = SDL_SCANCODE_GRAVE, | ||
| 56 | [KEYCODE_A] = SDL_SCANCODE_A, | ||
| 57 | [KEYCODE_B] = SDL_SCANCODE_B, | ||
| 58 | [KEYCODE_C] = SDL_SCANCODE_C, | ||
| 59 | [KEYCODE_D] = SDL_SCANCODE_D, | ||
| 60 | [KEYCODE_E] = SDL_SCANCODE_E, | ||
| 61 | [KEYCODE_F] = SDL_SCANCODE_F, | ||
| 62 | [KEYCODE_G] = SDL_SCANCODE_G, | ||
| 63 | [KEYCODE_H] = SDL_SCANCODE_H, | ||
| 64 | [KEYCODE_I] = SDL_SCANCODE_I, | ||
| 65 | [KEYCODE_J] = SDL_SCANCODE_J, | ||
| 66 | [KEYCODE_K] = SDL_SCANCODE_K, | ||
| 67 | [KEYCODE_L] = SDL_SCANCODE_L, | ||
| 68 | [KEYCODE_M] = SDL_SCANCODE_M, | ||
| 69 | [KEYCODE_N] = SDL_SCANCODE_N, | ||
| 70 | [KEYCODE_O] = SDL_SCANCODE_O, | ||
| 71 | [KEYCODE_P] = SDL_SCANCODE_P, | ||
| 72 | [KEYCODE_Q] = SDL_SCANCODE_Q, | ||
| 73 | [KEYCODE_R] = SDL_SCANCODE_R, | ||
| 74 | [KEYCODE_S] = SDL_SCANCODE_S, | ||
| 75 | [KEYCODE_T] = SDL_SCANCODE_T, | ||
| 76 | [KEYCODE_U] = SDL_SCANCODE_U, | ||
| 77 | [KEYCODE_V] = SDL_SCANCODE_V, | ||
| 78 | [KEYCODE_W] = SDL_SCANCODE_W, | ||
| 79 | [KEYCODE_X] = SDL_SCANCODE_X, | ||
| 80 | [KEYCODE_Y] = SDL_SCANCODE_Y, | ||
| 81 | [KEYCODE_Z] = SDL_SCANCODE_Z, | ||
| 82 | [KEYCODE_UP] = SDL_SCANCODE_UP, | ||
| 83 | [KEYCODE_DOWN] = SDL_SCANCODE_DOWN, | ||
| 84 | [KEYCODE_LEFT] = SDL_SCANCODE_LEFT, | ||
| 85 | [KEYCODE_PG_UP] = SDL_SCANCODE_PAGEUP, | ||
| 86 | [KEYCODE_PG_DOWN] = SDL_SCANCODE_PAGEDOWN, | ||
| 87 | [KEYCODE_RIGHT] = SDL_SCANCODE_RIGHT, | ||
| 88 | [KEYCODE_RETURN] = SDL_SCANCODE_RETURN, | ||
| 89 | [KEYCODE_TAB] = SDL_SCANCODE_TAB, | ||
| 90 | [KEYCODE_ESCAPE] = SDL_SCANCODE_ESCAPE, | ||
| 91 | }; | ||
| 92 | |||
| 93 | /** | ||
| 94 | * Called from the event dispatcher when a keyboard event is encountered. | ||
| 95 | * Translates the event such that it can be handled by SDL. | ||
| 96 | * @param event Screen keyboard event | ||
| 97 | */ | ||
| 98 | void handleKeyboardEvent(screen_event_t event) | ||
| 99 | { | ||
| 100 | int val; | ||
| 101 | SDL_Scancode scancode; | ||
| 102 | |||
| 103 | // Get the key value. | ||
| 104 | if (screen_get_event_property_iv(event, SCREEN_PROPERTY_SYM, &val) < 0) { | ||
| 105 | return; | ||
| 106 | } | ||
| 107 | |||
| 108 | // Skip unrecognized keys. | ||
| 109 | if ((val < 0) || (val >= SDL_arraysize(key_to_sdl))) { | ||
| 110 | return; | ||
| 111 | } | ||
| 112 | |||
| 113 | // Translate to an SDL scan code. | ||
| 114 | scancode = key_to_sdl[val]; | ||
| 115 | if (scancode == 0) { | ||
| 116 | return; | ||
| 117 | } | ||
| 118 | |||
| 119 | // Get event flags (key state). | ||
| 120 | if (screen_get_event_property_iv(event, SCREEN_PROPERTY_FLAGS, &val) < 0) { | ||
| 121 | return; | ||
| 122 | } | ||
| 123 | |||
| 124 | // Propagate the event to SDL. | ||
| 125 | // FIXME: | ||
| 126 | // Need to handle more key states (such as key combinations). | ||
| 127 | if (val & KEY_DOWN) { | ||
| 128 | SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, val, scancode, true); | ||
| 129 | } else { | ||
| 130 | SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, val, scancode, false); | ||
| 131 | } | ||
| 132 | } | ||
diff --git a/contrib/SDL-3.2.8/src/video/qnx/SDL_qnxvideo.c b/contrib/SDL-3.2.8/src/video/qnx/SDL_qnxvideo.c new file mode 100644 index 0000000..4192cdb --- /dev/null +++ b/contrib/SDL-3.2.8/src/video/qnx/SDL_qnxvideo.c | |||
| @@ -0,0 +1,351 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 2017 BlackBerry Limited | ||
| 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 | #include "../SDL_sysvideo.h" | ||
| 23 | #include "../../events/SDL_keyboard_c.h" | ||
| 24 | #include "../../events/SDL_mouse_c.h" | ||
| 25 | #include "SDL_qnx.h" | ||
| 26 | |||
| 27 | static screen_context_t context; | ||
| 28 | static screen_event_t event; | ||
| 29 | |||
| 30 | /** | ||
| 31 | * Initializes the QNX video plugin. | ||
| 32 | * Creates the Screen context and event handles used for all window operations | ||
| 33 | * by the plugin. | ||
| 34 | * @param SDL_VideoDevice *_this | ||
| 35 | * @return 0 if successful, -1 on error | ||
| 36 | */ | ||
| 37 | static bool videoInit(SDL_VideoDevice *_this) | ||
| 38 | { | ||
| 39 | SDL_VideoDisplay display; | ||
| 40 | |||
| 41 | if (screen_create_context(&context, 0) < 0) { | ||
| 42 | return false; | ||
| 43 | } | ||
| 44 | |||
| 45 | if (screen_create_event(&event) < 0) { | ||
| 46 | return false; | ||
| 47 | } | ||
| 48 | |||
| 49 | SDL_zero(display); | ||
| 50 | |||
| 51 | if (SDL_AddVideoDisplay(&display, false) == 0) { | ||
| 52 | return false; | ||
| 53 | } | ||
| 54 | |||
| 55 | // Assume we have a mouse and keyboard | ||
| 56 | SDL_AddKeyboard(SDL_DEFAULT_KEYBOARD_ID, NULL, false); | ||
| 57 | SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL, false); | ||
| 58 | |||
| 59 | return true; | ||
| 60 | } | ||
| 61 | |||
| 62 | static void videoQuit(SDL_VideoDevice *_this) | ||
| 63 | { | ||
| 64 | } | ||
| 65 | |||
| 66 | /** | ||
| 67 | * Creates a new native Screen window and associates it with the given SDL | ||
| 68 | * window. | ||
| 69 | * @param SDL_VideoDevice *_this | ||
| 70 | * @param window SDL window to initialize | ||
| 71 | * @return 0 if successful, -1 on error | ||
| 72 | */ | ||
| 73 | static bool createWindow(SDL_VideoDevice *_this, SDL_Window *window) | ||
| 74 | { | ||
| 75 | window_impl_t *impl; | ||
| 76 | int size[2]; | ||
| 77 | int numbufs; | ||
| 78 | int format; | ||
| 79 | int usage; | ||
| 80 | |||
| 81 | impl = SDL_calloc(1, sizeof(*impl)); | ||
| 82 | if (!impl) { | ||
| 83 | return false; | ||
| 84 | } | ||
| 85 | |||
| 86 | // Create a native window. | ||
| 87 | if (screen_create_window(&impl->window, context) < 0) { | ||
| 88 | goto fail; | ||
| 89 | } | ||
| 90 | |||
| 91 | // Set the native window's size to match the SDL window. | ||
| 92 | size[0] = window->w; | ||
| 93 | size[1] = window->h; | ||
| 94 | |||
| 95 | if (screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_SIZE, | ||
| 96 | size) < 0) { | ||
| 97 | goto fail; | ||
| 98 | } | ||
| 99 | |||
| 100 | if (screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_SOURCE_SIZE, | ||
| 101 | size) < 0) { | ||
| 102 | goto fail; | ||
| 103 | } | ||
| 104 | |||
| 105 | // Create window buffer(s). | ||
| 106 | if (window->flags & SDL_WINDOW_OPENGL) { | ||
| 107 | if (glGetConfig(&impl->conf, &format) < 0) { | ||
| 108 | goto fail; | ||
| 109 | } | ||
| 110 | numbufs = 2; | ||
| 111 | |||
| 112 | usage = SCREEN_USAGE_OPENGL_ES2; | ||
| 113 | if (screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_USAGE, | ||
| 114 | &usage) < 0) { | ||
| 115 | return false; | ||
| 116 | } | ||
| 117 | } else { | ||
| 118 | format = SCREEN_FORMAT_RGBX8888; | ||
| 119 | numbufs = 1; | ||
| 120 | } | ||
| 121 | |||
| 122 | // Set pixel format. | ||
| 123 | if (screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_FORMAT, | ||
| 124 | &format) < 0) { | ||
| 125 | goto fail; | ||
| 126 | } | ||
| 127 | |||
| 128 | // Create buffer(s). | ||
| 129 | if (screen_create_window_buffers(impl->window, numbufs) < 0) { | ||
| 130 | goto fail; | ||
| 131 | } | ||
| 132 | |||
| 133 | window->internal = impl; | ||
| 134 | return true; | ||
| 135 | |||
| 136 | fail: | ||
| 137 | if (impl->window) { | ||
| 138 | screen_destroy_window(impl->window); | ||
| 139 | } | ||
| 140 | |||
| 141 | SDL_free(impl); | ||
| 142 | return false; | ||
| 143 | } | ||
| 144 | |||
| 145 | /** | ||
| 146 | * Gets a pointer to the Screen buffer associated with the given window. Note | ||
| 147 | * that the buffer is actually created in createWindow(). | ||
| 148 | * @param SDL_VideoDevice *_this | ||
| 149 | * @param window SDL window to get the buffer for | ||
| 150 | * @param[out] pixles Holds a pointer to the window's buffer | ||
| 151 | * @param[out] format Holds the pixel format for the buffer | ||
| 152 | * @param[out] pitch Holds the number of bytes per line | ||
| 153 | * @return 0 if successful, -1 on error | ||
| 154 | */ | ||
| 155 | static bool createWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window, SDL_PixelFormat * format, | ||
| 156 | void ** pixels, int *pitch) | ||
| 157 | { | ||
| 158 | window_impl_t *impl = (window_impl_t *)window->internal; | ||
| 159 | screen_buffer_t buffer; | ||
| 160 | |||
| 161 | // Get a pointer to the buffer's memory. | ||
| 162 | if (screen_get_window_property_pv(impl->window, SCREEN_PROPERTY_BUFFERS, | ||
| 163 | (void **)&buffer) < 0) { | ||
| 164 | return false; | ||
| 165 | } | ||
| 166 | |||
| 167 | if (screen_get_buffer_property_pv(buffer, SCREEN_PROPERTY_POINTER, | ||
| 168 | pixels) < 0) { | ||
| 169 | return false; | ||
| 170 | } | ||
| 171 | |||
| 172 | // Set format and pitch. | ||
| 173 | if (screen_get_buffer_property_iv(buffer, SCREEN_PROPERTY_STRIDE, | ||
| 174 | pitch) < 0) { | ||
| 175 | return false; | ||
| 176 | } | ||
| 177 | |||
| 178 | *format = SDL_PIXELFORMAT_XRGB8888; | ||
| 179 | return true; | ||
| 180 | } | ||
| 181 | |||
| 182 | /** | ||
| 183 | * Informs the window manager that the window needs to be updated. | ||
| 184 | * @param SDL_VideoDevice *_this | ||
| 185 | * @param window The window to update | ||
| 186 | * @param rects An array of reectangular areas to update | ||
| 187 | * @param numrects Rect array length | ||
| 188 | * @return 0 if successful, -1 on error | ||
| 189 | */ | ||
| 190 | static bool updateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, | ||
| 191 | int numrects) | ||
| 192 | { | ||
| 193 | window_impl_t *impl = (window_impl_t *)window->internal; | ||
| 194 | screen_buffer_t buffer; | ||
| 195 | |||
| 196 | if (screen_get_window_property_pv(impl->window, SCREEN_PROPERTY_BUFFERS, | ||
| 197 | (void **)&buffer) < 0) { | ||
| 198 | return false; | ||
| 199 | } | ||
| 200 | |||
| 201 | screen_post_window(impl->window, buffer, numrects, (int *)rects, 0); | ||
| 202 | screen_flush_context(context, 0); | ||
| 203 | return true; | ||
| 204 | } | ||
| 205 | |||
| 206 | /** | ||
| 207 | * Runs the main event loop. | ||
| 208 | * @param SDL_VideoDevice *_this | ||
| 209 | */ | ||
| 210 | static void pumpEvents(SDL_VideoDevice *_this) | ||
| 211 | { | ||
| 212 | int type; | ||
| 213 | |||
| 214 | for (;;) { | ||
| 215 | if (screen_get_event(context, event, 0) < 0) { | ||
| 216 | break; | ||
| 217 | } | ||
| 218 | |||
| 219 | if (screen_get_event_property_iv(event, SCREEN_PROPERTY_TYPE, &type) | ||
| 220 | < 0) { | ||
| 221 | break; | ||
| 222 | } | ||
| 223 | |||
| 224 | if (type == SCREEN_EVENT_NONE) { | ||
| 225 | break; | ||
| 226 | } | ||
| 227 | |||
| 228 | switch (type) { | ||
| 229 | case SCREEN_EVENT_KEYBOARD: | ||
| 230 | handleKeyboardEvent(event); | ||
| 231 | break; | ||
| 232 | |||
| 233 | default: | ||
| 234 | break; | ||
| 235 | } | ||
| 236 | } | ||
| 237 | } | ||
| 238 | |||
| 239 | /** | ||
| 240 | * Updates the size of the native window using the geometry of the SDL window. | ||
| 241 | * @param SDL_VideoDevice *_this | ||
| 242 | * @param window SDL window to update | ||
| 243 | */ | ||
| 244 | static void setWindowSize(SDL_VideoDevice *_this, SDL_Window *window) | ||
| 245 | { | ||
| 246 | window_impl_t *impl = (window_impl_t *)window->internal; | ||
| 247 | int size[2]; | ||
| 248 | |||
| 249 | size[0] = window->pending.w; | ||
| 250 | size[1] = window->pending.h; | ||
| 251 | |||
| 252 | screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_SIZE, size); | ||
| 253 | screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_SOURCE_SIZE, size); | ||
| 254 | } | ||
| 255 | |||
| 256 | /** | ||
| 257 | * Makes the native window associated with the given SDL window visible. | ||
| 258 | * @param SDL_VideoDevice *_this | ||
| 259 | * @param window SDL window to update | ||
| 260 | */ | ||
| 261 | static void showWindow(SDL_VideoDevice *_this, SDL_Window *window) | ||
| 262 | { | ||
| 263 | window_impl_t *impl = (window_impl_t *)window->internal; | ||
| 264 | const int visible = 1; | ||
| 265 | |||
| 266 | screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_VISIBLE, | ||
| 267 | &visible); | ||
| 268 | } | ||
| 269 | |||
| 270 | /** | ||
| 271 | * Makes the native window associated with the given SDL window invisible. | ||
| 272 | * @param SDL_VideoDevice *_this | ||
| 273 | * @param window SDL window to update | ||
| 274 | */ | ||
| 275 | static void hideWindow(SDL_VideoDevice *_this, SDL_Window *window) | ||
| 276 | { | ||
| 277 | window_impl_t *impl = (window_impl_t *)window->internal; | ||
| 278 | const int visible = 0; | ||
| 279 | |||
| 280 | screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_VISIBLE, | ||
| 281 | &visible); | ||
| 282 | } | ||
| 283 | |||
| 284 | /** | ||
| 285 | * Destroys the native window associated with the given SDL window. | ||
| 286 | * @param SDL_VideoDevice *_this | ||
| 287 | * @param window SDL window that is being destroyed | ||
| 288 | */ | ||
| 289 | static void destroyWindow(SDL_VideoDevice *_this, SDL_Window *window) | ||
| 290 | { | ||
| 291 | window_impl_t *impl = (window_impl_t *)window->internal; | ||
| 292 | |||
| 293 | if (impl) { | ||
| 294 | screen_destroy_window(impl->window); | ||
| 295 | window->internal = NULL; | ||
| 296 | } | ||
| 297 | } | ||
| 298 | |||
| 299 | /** | ||
| 300 | * Frees the plugin object created by createDevice(). | ||
| 301 | * @param device Plugin object to free | ||
| 302 | */ | ||
| 303 | static void deleteDevice(SDL_VideoDevice *device) | ||
| 304 | { | ||
| 305 | SDL_free(device); | ||
| 306 | } | ||
| 307 | |||
| 308 | /** | ||
| 309 | * Creates the QNX video plugin used by SDL. | ||
| 310 | * @return Initialized device if successful, NULL otherwise | ||
| 311 | */ | ||
| 312 | static SDL_VideoDevice *createDevice(void) | ||
| 313 | { | ||
| 314 | SDL_VideoDevice *device; | ||
| 315 | |||
| 316 | device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); | ||
| 317 | if (!device) { | ||
| 318 | return NULL; | ||
| 319 | } | ||
| 320 | |||
| 321 | device->internal = NULL; | ||
| 322 | device->VideoInit = videoInit; | ||
| 323 | device->VideoQuit = videoQuit; | ||
| 324 | device->CreateSDLWindow = createWindow; | ||
| 325 | device->CreateWindowFramebuffer = createWindowFramebuffer; | ||
| 326 | device->UpdateWindowFramebuffer = updateWindowFramebuffer; | ||
| 327 | device->SetWindowSize = setWindowSize; | ||
| 328 | device->ShowWindow = showWindow; | ||
| 329 | device->HideWindow = hideWindow; | ||
| 330 | device->PumpEvents = pumpEvents; | ||
| 331 | device->DestroyWindow = destroyWindow; | ||
| 332 | |||
| 333 | device->GL_LoadLibrary = glLoadLibrary; | ||
| 334 | device->GL_GetProcAddress = glGetProcAddress; | ||
| 335 | device->GL_CreateContext = glCreateContext; | ||
| 336 | device->GL_SetSwapInterval = glSetSwapInterval; | ||
| 337 | device->GL_SwapWindow = glSwapWindow; | ||
| 338 | device->GL_MakeCurrent = glMakeCurrent; | ||
| 339 | device->GL_DestroyContext = glDeleteContext; | ||
| 340 | device->GL_UnloadLibrary = glUnloadLibrary; | ||
| 341 | |||
| 342 | device->free = deleteDevice; | ||
| 343 | return device; | ||
| 344 | } | ||
| 345 | |||
| 346 | VideoBootStrap QNX_bootstrap = { | ||
| 347 | "qnx", "QNX Screen", | ||
| 348 | createDevice, | ||
| 349 | NULL, // no ShowMessageBox implementation | ||
| 350 | false | ||
| 351 | }; | ||
