2015-06-21 17:33:46 +02:00
|
|
|
/*
|
|
|
|
|
Simple DirectMedia Layer
|
2024-01-01 13:15:26 -08:00
|
|
|
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
2022-11-29 18:34:15 -08:00
|
|
|
#include "SDL_internal.h"
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifdef SDL_VIDEO_DRIVER_ANDROID
|
2015-06-21 17:33:46 +02:00
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Android SDL video driver implementation
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
#include "../SDL_sysvideo.h"
|
|
|
|
|
#include "../SDL_pixels_c.h"
|
|
|
|
|
#include "../../events/SDL_events_c.h"
|
|
|
|
|
#include "../../events/SDL_windowevents_c.h"
|
|
|
|
|
|
|
|
|
|
#include "SDL_androidvideo.h"
|
2016-12-02 02:25:12 -08:00
|
|
|
#include "SDL_androidgl.h"
|
2015-06-21 17:33:46 +02:00
|
|
|
#include "SDL_androidclipboard.h"
|
|
|
|
|
#include "SDL_androidevents.h"
|
|
|
|
|
#include "SDL_androidkeyboard.h"
|
2016-01-12 22:23:00 +01:00
|
|
|
#include "SDL_androidmouse.h"
|
2015-06-21 17:33:46 +02:00
|
|
|
#include "SDL_androidtouch.h"
|
|
|
|
|
#include "SDL_androidwindow.h"
|
2017-08-27 22:15:57 -04:00
|
|
|
#include "SDL_androidvulkan.h"
|
2024-01-22 18:04:14 -05:00
|
|
|
#include "SDL_androidmessagebox.h"
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2024-01-25 15:22:57 -05:00
|
|
|
#define ANDROID_VID_DRIVER_NAME "android"
|
2015-06-21 17:33:46 +02:00
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Initialization/Query functions
|
2024-08-22 17:33:49 -07:00
|
|
|
static bool Android_VideoInit(SDL_VideoDevice *_this);
|
2023-05-09 12:55:11 +02:00
|
|
|
static void Android_VideoQuit(SDL_VideoDevice *_this);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
#include "../SDL_egl_c.h"
|
2022-11-30 12:51:59 -08:00
|
|
|
#define Android_GLES_GetProcAddress SDL_EGL_GetProcAddressInternal
|
|
|
|
|
#define Android_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
|
2015-06-21 17:33:46 +02:00
|
|
|
#define Android_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
|
|
|
|
|
#define Android_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
|
2024-08-22 17:33:49 -07:00
|
|
|
#define Android_GLES_DestroyContext SDL_EGL_DestroyContext
|
2015-06-21 17:33:46 +02:00
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Android driver bootstrap functions
|
2015-06-21 17:33:46 +02:00
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// These are filled in with real values in Android_SetScreenResolution on init (before SDL_main())
|
2022-11-30 12:51:59 -08:00
|
|
|
int Android_SurfaceWidth = 0;
|
|
|
|
|
int Android_SurfaceHeight = 0;
|
|
|
|
|
static int Android_DeviceWidth = 0;
|
|
|
|
|
static int Android_DeviceHeight = 0;
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
static Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_RGB565; // Default SurfaceView format, in case this is queried before being filled
|
2023-01-25 10:22:43 -08:00
|
|
|
float Android_ScreenDensity = 1.0f;
|
2023-01-02 15:47:19 -08:00
|
|
|
static float Android_ScreenRate = 0.0f;
|
2023-03-07 00:01:34 -08:00
|
|
|
static SDL_SystemTheme Android_SystemTheme;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
static bool Android_SuspendScreenSaver(SDL_VideoDevice *_this)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
2023-02-09 15:34:43 +01:00
|
|
|
return Android_JNI_SuspendScreenSaver(_this->suspend_screensaver);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
static void Android_DeleteDevice(SDL_VideoDevice *device)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
2024-07-16 11:09:18 -07:00
|
|
|
SDL_free(device->internal);
|
2015-06-21 17:33:46 +02:00
|
|
|
SDL_free(device);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
static SDL_VideoDevice *Android_CreateDevice(void)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
|
|
|
|
SDL_VideoDevice *device;
|
|
|
|
|
SDL_VideoData *data;
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Initialize all variables that we clean on shutdown
|
2022-11-30 12:51:59 -08:00
|
|
|
device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice));
|
2023-11-09 22:29:15 +01:00
|
|
|
if (!device) {
|
2015-06-21 17:33:46 +02:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
data = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData));
|
2023-11-09 22:29:15 +01:00
|
|
|
if (!data) {
|
2015-06-21 17:33:46 +02:00
|
|
|
SDL_free(device);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 11:09:18 -07:00
|
|
|
device->internal = data;
|
2023-03-07 00:01:34 -08:00
|
|
|
device->system_theme = Android_SystemTheme;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Set the function pointers
|
2015-06-21 17:33:46 +02:00
|
|
|
device->VideoInit = Android_VideoInit;
|
|
|
|
|
device->VideoQuit = Android_VideoQuit;
|
|
|
|
|
|
2017-08-28 00:43:14 -07:00
|
|
|
device->CreateSDLWindow = Android_CreateWindow;
|
2015-06-21 17:33:46 +02:00
|
|
|
device->SetWindowTitle = Android_SetWindowTitle;
|
2018-02-11 18:23:37 -08:00
|
|
|
device->SetWindowFullscreen = Android_SetWindowFullscreen;
|
2019-06-10 21:58:03 +02:00
|
|
|
device->MinimizeWindow = Android_MinimizeWindow;
|
2022-03-23 10:13:56 +01:00
|
|
|
device->SetWindowResizable = Android_SetWindowResizable;
|
2015-06-21 17:33:46 +02:00
|
|
|
device->DestroyWindow = Android_DestroyWindow;
|
|
|
|
|
|
|
|
|
|
device->free = Android_DeleteDevice;
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// GL pointers
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifdef SDL_VIDEO_OPENGL_EGL
|
2015-06-21 17:33:46 +02:00
|
|
|
device->GL_LoadLibrary = Android_GLES_LoadLibrary;
|
|
|
|
|
device->GL_GetProcAddress = Android_GLES_GetProcAddress;
|
|
|
|
|
device->GL_UnloadLibrary = Android_GLES_UnloadLibrary;
|
|
|
|
|
device->GL_CreateContext = Android_GLES_CreateContext;
|
|
|
|
|
device->GL_MakeCurrent = Android_GLES_MakeCurrent;
|
|
|
|
|
device->GL_SetSwapInterval = Android_GLES_SetSwapInterval;
|
|
|
|
|
device->GL_GetSwapInterval = Android_GLES_GetSwapInterval;
|
|
|
|
|
device->GL_SwapWindow = Android_GLES_SwapWindow;
|
2024-08-22 17:33:49 -07:00
|
|
|
device->GL_DestroyContext = Android_GLES_DestroyContext;
|
2022-03-11 15:14:51 +01:00
|
|
|
#endif
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifdef SDL_VIDEO_VULKAN
|
2017-08-27 22:15:57 -04:00
|
|
|
device->Vulkan_LoadLibrary = Android_Vulkan_LoadLibrary;
|
|
|
|
|
device->Vulkan_UnloadLibrary = Android_Vulkan_UnloadLibrary;
|
|
|
|
|
device->Vulkan_GetInstanceExtensions = Android_Vulkan_GetInstanceExtensions;
|
|
|
|
|
device->Vulkan_CreateSurface = Android_Vulkan_CreateSurface;
|
2024-05-17 03:41:15 +03:00
|
|
|
device->Vulkan_DestroySurface = Android_Vulkan_DestroySurface;
|
2017-08-27 22:15:57 -04:00
|
|
|
#endif
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Screensaver
|
2015-06-21 17:33:46 +02:00
|
|
|
device->SuspendScreenSaver = Android_SuspendScreenSaver;
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Screen keyboard
|
2015-06-21 17:33:46 +02:00
|
|
|
device->HasScreenKeyboardSupport = Android_HasScreenKeyboardSupport;
|
2024-01-06 08:11:22 -08:00
|
|
|
device->ShowScreenKeyboard = Android_ShowScreenKeyboard;
|
|
|
|
|
device->HideScreenKeyboard = Android_HideScreenKeyboard;
|
2015-06-21 17:33:46 +02:00
|
|
|
device->IsScreenKeyboardShown = Android_IsScreenKeyboardShown;
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Clipboard
|
2015-06-21 17:33:46 +02:00
|
|
|
device->SetClipboardText = Android_SetClipboardText;
|
|
|
|
|
device->GetClipboardText = Android_GetClipboardText;
|
|
|
|
|
device->HasClipboardText = Android_HasClipboardText;
|
|
|
|
|
|
video: Implement asynchronous windowing
SDL window size, state, and position functions have been considered immediate, with their effects assuming to have taken effect upon successful return of the function. However, several windowing systems handle these requests asynchronously, resulting in the functions blocking until the changes have taken effect, potentially for long periods of time. Additionally, some windowing systems treat these as requests, and can potentially deny or fulfill the request in a manner differently than the application expects, such as not allowing a window to be positioned or sized beyond desktop borders, prohibiting fullscreen, and so on.
With these changes, applications can make requests of the window manager that do not block, with the understanding that an associated event will be sent if the request is fulfilled. Currently, size, position, maximize, minimize, and fullscreen calls are handled as asynchronous requests, with events being returned if the request is honored. If the application requires that the change take effect immediately, it can call the new SDL_SyncWindow function, which will attempt to block until the request is fulfilled, or some arbitrary timeout period elapses, the duration of which depends not only on the windowing system, but on the operation requested as well (e.g. a 100ms timeout is fine for most X11 events, but maximizing a window can take considerably longer for some reason). There is also a new hint 'SDL_VIDEO_SYNC_ALL_WINDOW_OPS' that will mimic the old behavior by synchronizing after every window operation with, again, the understanding that using this may result in the associated calls blocking for a relatively long period.
The deferred model also results in the window size and position getters not reporting false coordinates anymore, as they only forward what the window manager reports vs allowing applications to set arbitrary values, and fullscreen enter/leave events that were initiated via the window manager update the window state appropriately, where they didn't before.
Care was taken to ensure that order of operations is maintained, and that requests are not ignored or dropped. This does require some implicit internal synchronization in the various backends if many requests are made in a short period, as some state and behavior depends on other bits of state that need to be known at that particular point in time, but this isn't something that typical applications will hit, unless they are sending a lot of window state in a short time as the tests do.
The automated tests developed to test the previous behavior also resulted in previously undefined behavior being defined and normalized across platforms, particularly when it comes to the sizing and positioning of windows when they are in a fixed-size state, such as maximized or fullscreen. Size and position requests made when the window is not in a movable or resizable state will be deferred until it can be applied, so no requests are lost. These changes fix another long-standing issue with renderers recreating maximized windows, where the original non-maximized size was lost, resulting in the window being restored to the wrong size. All automated video tests pass across all platforms.
Overall, the "make a request/get an event" model better reflects how most windowing systems work, and some backends avoid spending significant time blocking while waiting for operations to complete.
2023-10-25 15:09:55 -04:00
|
|
|
device->device_caps = VIDEO_DEVICE_CAPS_SENDS_FULLSCREEN_DIMENSIONS;
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
return device;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VideoBootStrap Android_bootstrap = {
|
|
|
|
|
ANDROID_VID_DRIVER_NAME, "SDL Android video driver",
|
2024-01-22 18:04:14 -05:00
|
|
|
Android_CreateDevice,
|
|
|
|
|
Android_ShowMessageBox
|
2015-06-21 17:33:46 +02:00
|
|
|
};
|
|
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
bool Android_VideoInit(SDL_VideoDevice *_this)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
2024-07-16 11:09:18 -07:00
|
|
|
SDL_VideoData *videodata = _this->internal;
|
2023-01-29 13:30:55 -08:00
|
|
|
SDL_DisplayID displayID;
|
2019-03-12 14:44:25 -07:00
|
|
|
SDL_VideoDisplay *display;
|
|
|
|
|
SDL_DisplayMode mode;
|
2019-01-16 10:31:51 +01:00
|
|
|
|
2024-08-22 09:21:26 -07:00
|
|
|
videodata->isPaused = false;
|
|
|
|
|
videodata->isPausing = false;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2023-01-25 03:36:35 -08:00
|
|
|
SDL_zero(mode);
|
2022-11-30 12:51:59 -08:00
|
|
|
mode.format = Android_ScreenFormat;
|
2023-05-16 16:29:52 -07:00
|
|
|
mode.w = Android_DeviceWidth;
|
|
|
|
|
mode.h = Android_DeviceHeight;
|
2022-11-30 12:51:59 -08:00
|
|
|
mode.refresh_rate = Android_ScreenRate;
|
2019-01-17 11:05:05 +01:00
|
|
|
|
2023-01-29 13:30:55 -08:00
|
|
|
displayID = SDL_AddBasicVideoDisplay(&mode);
|
|
|
|
|
if (displayID == 0) {
|
2024-08-22 17:33:49 -07:00
|
|
|
return false;
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2023-01-29 13:30:55 -08:00
|
|
|
display = SDL_GetVideoDisplay(displayID);
|
2023-06-17 00:52:40 -07:00
|
|
|
display->natural_orientation = Android_JNI_GetDisplayNaturalOrientation();
|
|
|
|
|
display->current_orientation = Android_JNI_GetDisplayCurrentOrientation();
|
2023-05-16 16:29:52 -07:00
|
|
|
display->content_scale = Android_ScreenDensity;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
Android_InitTouch();
|
|
|
|
|
|
2016-01-12 22:23:00 +01:00
|
|
|
Android_InitMouse();
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// We're done!
|
2024-08-22 17:33:49 -07:00
|
|
|
return true;
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
2023-05-09 12:55:11 +02:00
|
|
|
void Android_VideoQuit(SDL_VideoDevice *_this)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
2018-06-18 13:14:04 -07:00
|
|
|
Android_QuitMouse();
|
2015-06-21 17:33:46 +02:00
|
|
|
Android_QuitTouch();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 14:55:50 +01:00
|
|
|
void Android_SetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, float density, float rate)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
2022-11-30 12:51:59 -08:00
|
|
|
Android_SurfaceWidth = surfaceWidth;
|
2018-06-07 17:07:03 -07:00
|
|
|
Android_SurfaceHeight = surfaceHeight;
|
2022-11-30 12:51:59 -08:00
|
|
|
Android_DeviceWidth = deviceWidth;
|
|
|
|
|
Android_DeviceHeight = deviceHeight;
|
2023-01-25 10:22:43 -08:00
|
|
|
Android_ScreenDensity = (density > 0.0f) ? density : 1.0f;
|
2023-01-02 15:47:19 -08:00
|
|
|
Android_ScreenRate = rate;
|
2019-01-17 11:05:05 +01:00
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
static Uint32 format_to_pixelFormat(int format)
|
|
|
|
|
{
|
2021-04-22 18:06:17 +02:00
|
|
|
Uint32 pf;
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
if (format == AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM) { // 1
|
2021-04-22 18:06:17 +02:00
|
|
|
pf = SDL_PIXELFORMAT_RGBA8888;
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
} else if (format == AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM) { // 2
|
2021-04-22 18:06:17 +02:00
|
|
|
pf = SDL_PIXELFORMAT_RGBX8888;
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
} else if (format == AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM) { // 3
|
2021-04-22 18:06:17 +02:00
|
|
|
pf = SDL_PIXELFORMAT_RGB24;
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
} else if (format == AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM) { // 4
|
2021-04-22 18:06:17 +02:00
|
|
|
pf = SDL_PIXELFORMAT_RGB565;
|
|
|
|
|
} else if (format == 5) {
|
|
|
|
|
pf = SDL_PIXELFORMAT_BGRA8888;
|
|
|
|
|
} else if (format == 6) {
|
|
|
|
|
pf = SDL_PIXELFORMAT_RGBA5551;
|
|
|
|
|
} else if (format == 7) {
|
|
|
|
|
pf = SDL_PIXELFORMAT_RGBA4444;
|
2022-09-03 23:40:14 +02:00
|
|
|
} else if (format == 0x115) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// HAL_PIXEL_FORMAT_BGR_565
|
2022-09-03 23:40:14 +02:00
|
|
|
pf = SDL_PIXELFORMAT_RGB565;
|
2021-04-22 18:06:17 +02:00
|
|
|
} else {
|
|
|
|
|
pf = SDL_PIXELFORMAT_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
return pf;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
void Android_SetFormat(int format_wanted, int format_got)
|
2021-04-22 18:06:17 +02:00
|
|
|
{
|
|
|
|
|
Uint32 pf_wanted;
|
|
|
|
|
Uint32 pf_got;
|
|
|
|
|
|
|
|
|
|
pf_wanted = format_to_pixelFormat(format_wanted);
|
|
|
|
|
pf_got = format_to_pixelFormat(format_got);
|
|
|
|
|
|
|
|
|
|
Android_ScreenFormat = pf_got;
|
|
|
|
|
|
|
|
|
|
SDL_Log("pixel format wanted %s (%d), got %s (%d)",
|
|
|
|
|
SDL_GetPixelFormatName(pf_wanted), format_wanted,
|
|
|
|
|
SDL_GetPixelFormatName(pf_got), format_got);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-17 11:05:05 +01:00
|
|
|
void Android_SendResize(SDL_Window *window)
|
|
|
|
|
{
|
2016-10-01 14:18:29 -07:00
|
|
|
/*
|
|
|
|
|
Update the resolution of the desktop mode, so that the window
|
|
|
|
|
can be properly resized. The screen resolution change can for
|
2018-02-11 18:23:37 -08:00
|
|
|
example happen when the Activity enters or exits immersive mode,
|
2016-10-01 14:18:29 -07:00
|
|
|
which can happen after VideoInit().
|
|
|
|
|
*/
|
2019-01-17 11:05:05 +01:00
|
|
|
SDL_VideoDevice *device = SDL_GetVideoDevice();
|
2022-11-27 17:38:43 +01:00
|
|
|
if (device && device->num_displays > 0) {
|
2023-08-01 18:48:35 -07:00
|
|
|
SDL_VideoDisplay *display = device->displays[0];
|
2023-01-27 10:46:51 -08:00
|
|
|
SDL_DisplayMode desktop_mode;
|
|
|
|
|
|
|
|
|
|
SDL_zero(desktop_mode);
|
|
|
|
|
desktop_mode.format = Android_ScreenFormat;
|
2023-05-16 16:29:52 -07:00
|
|
|
desktop_mode.w = Android_DeviceWidth;
|
|
|
|
|
desktop_mode.h = Android_DeviceHeight;
|
2023-01-27 10:46:51 -08:00
|
|
|
desktop_mode.refresh_rate = Android_ScreenRate;
|
|
|
|
|
SDL_SetDesktopDisplayMode(display, &desktop_mode);
|
2016-10-01 14:18:29 -07:00
|
|
|
}
|
|
|
|
|
|
2019-01-03 13:14:16 +01:00
|
|
|
if (window) {
|
2023-05-18 16:11:57 -07:00
|
|
|
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, Android_SurfaceWidth, Android_SurfaceHeight);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-22 09:21:26 -07:00
|
|
|
void Android_SetDarkMode(bool enabled)
|
2023-03-07 00:01:34 -08:00
|
|
|
{
|
|
|
|
|
SDL_VideoDevice *device = SDL_GetVideoDevice();
|
|
|
|
|
|
|
|
|
|
if (enabled) {
|
|
|
|
|
Android_SystemTheme = SDL_SYSTEM_THEME_DARK;
|
|
|
|
|
} else {
|
|
|
|
|
Android_SystemTheme = SDL_SYSTEM_THEME_LIGHT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (device) {
|
|
|
|
|
SDL_SetSystemTheme(Android_SystemTheme);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
#endif // SDL_VIDEO_DRIVER_ANDROID
|