mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2025-01-17 14:47:19 +01:00
Android: prevent concurrency in Android_SetScreenResolution() when exiting
by checking Android_Window validity - SDLThread: user application is exiting: SDL_VideoQuit() and clearing SDL_GetVideoDevice() - ActivityThread is changing orientation/size surfaceChanged() > Android_SetScreenResolution() > SDL_GetVideoDevice() - Separate function into Android_SetScreenResolution() and Android_SendResize(), formating, and mark Android_DeviceWidth/Heigh as static
This commit is contained in:
parent
6690a46941
commit
e5f8801f55
@ -723,7 +723,8 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|||||||
public static native void nativePause();
|
public static native void nativePause();
|
||||||
public static native void nativeResume();
|
public static native void nativeResume();
|
||||||
public static native void onNativeDropFile(String filename);
|
public static native void onNativeDropFile(String filename);
|
||||||
public static native void onNativeResize(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, int format, float rate);
|
public static native void nativeSetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, int format, float rate);
|
||||||
|
public static native void onNativeResize();
|
||||||
public static native void onNativeKeyDown(int keycode);
|
public static native void onNativeKeyDown(int keycode);
|
||||||
public static native void onNativeKeyUp(int keycode);
|
public static native void onNativeKeyUp(int keycode);
|
||||||
public static native void onNativeKeyboardFocusLost();
|
public static native void onNativeKeyboardFocusLost();
|
||||||
@ -1652,7 +1653,8 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|||||||
|
|
||||||
Log.v("SDL", "Window size: " + width + "x" + height);
|
Log.v("SDL", "Window size: " + width + "x" + height);
|
||||||
Log.v("SDL", "Device size: " + nDeviceWidth + "x" + nDeviceHeight);
|
Log.v("SDL", "Device size: " + nDeviceWidth + "x" + nDeviceHeight);
|
||||||
SDLActivity.onNativeResize(width, height, nDeviceWidth, nDeviceHeight, sdlFormat, mDisplay.getRefreshRate());
|
SDLActivity.nativeSetScreenResolution(width, height, nDeviceWidth, nDeviceHeight, sdlFormat, mDisplay.getRefreshRate());
|
||||||
|
SDLActivity.onNativeResize();
|
||||||
|
|
||||||
boolean skip = false;
|
boolean skip = false;
|
||||||
int requestedOrientation = SDLActivity.mSingleton.getRequestedOrientation();
|
int requestedOrientation = SDLActivity.mSingleton.getRequestedOrientation();
|
||||||
|
@ -72,11 +72,14 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeDropFile)(
|
|||||||
JNIEnv *env, jclass jcls,
|
JNIEnv *env, jclass jcls,
|
||||||
jstring filename);
|
jstring filename);
|
||||||
|
|
||||||
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
|
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetScreenResolution)(
|
||||||
JNIEnv *env, jclass jcls,
|
JNIEnv *env, jclass jcls,
|
||||||
jint surfaceWidth, jint surfaceHeight,
|
jint surfaceWidth, jint surfaceHeight,
|
||||||
jint deviceWidth, jint deviceHeight, jint format, jfloat rate);
|
jint deviceWidth, jint deviceHeight, jint format, jfloat rate);
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
|
||||||
|
JNIEnv *env, jclass cls);
|
||||||
|
|
||||||
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceCreated)(
|
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceCreated)(
|
||||||
JNIEnv *env, jclass jcls);
|
JNIEnv *env, jclass jcls);
|
||||||
|
|
||||||
@ -683,15 +686,29 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeDropFile)(
|
|||||||
SDL_SendDropComplete(NULL);
|
SDL_SendDropComplete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Resize */
|
/* Set screen resolution */
|
||||||
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
|
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetScreenResolution)(
|
||||||
JNIEnv *env, jclass jcls,
|
JNIEnv *env, jclass jcls,
|
||||||
jint surfaceWidth, jint surfaceHeight,
|
jint surfaceWidth, jint surfaceHeight,
|
||||||
jint deviceWidth, jint deviceHeight, jint format, jfloat rate)
|
jint deviceWidth, jint deviceHeight, jint format, jfloat rate)
|
||||||
{
|
{
|
||||||
SDL_LockMutex(Android_ActivityMutex);
|
SDL_LockMutex(Android_ActivityMutex);
|
||||||
|
|
||||||
Android_SetScreenResolution(Android_Window, surfaceWidth, surfaceHeight, deviceWidth, deviceHeight, format, rate);
|
Android_SetScreenResolution(surfaceWidth, surfaceHeight, deviceWidth, deviceHeight, format, rate);
|
||||||
|
|
||||||
|
SDL_UnlockMutex(Android_ActivityMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Resize */
|
||||||
|
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
|
||||||
|
JNIEnv *env, jclass jcls)
|
||||||
|
{
|
||||||
|
SDL_LockMutex(Android_ActivityMutex);
|
||||||
|
|
||||||
|
if (Android_Window)
|
||||||
|
{
|
||||||
|
Android_SendResize(Android_Window);
|
||||||
|
}
|
||||||
|
|
||||||
SDL_UnlockMutex(Android_ActivityMutex);
|
SDL_UnlockMutex(Android_ActivityMutex);
|
||||||
}
|
}
|
||||||
|
@ -59,15 +59,15 @@ int Android_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *
|
|||||||
|
|
||||||
|
|
||||||
/* These are filled in with real values in Android_SetScreenResolution on init (before SDL_main()) */
|
/* These are filled in with real values in Android_SetScreenResolution on init (before SDL_main()) */
|
||||||
int Android_SurfaceWidth = 0;
|
int Android_SurfaceWidth = 0;
|
||||||
int Android_SurfaceHeight = 0;
|
int Android_SurfaceHeight = 0;
|
||||||
int Android_DeviceWidth = 0;
|
static int Android_DeviceWidth = 0;
|
||||||
int Android_DeviceHeight = 0;
|
static int Android_DeviceHeight = 0;
|
||||||
static Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
|
static Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
|
||||||
static int Android_ScreenRate = 0;
|
static int Android_ScreenRate = 0;
|
||||||
|
SDL_sem *Android_PauseSem = NULL;
|
||||||
SDL_sem *Android_PauseSem = NULL, *Android_ResumeSem = NULL;
|
SDL_sem *Android_ResumeSem = NULL;
|
||||||
SDL_mutex *Android_ActivityMutex = NULL;
|
SDL_mutex *Android_ActivityMutex = NULL;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
Android_Available(void)
|
Android_Available(void)
|
||||||
@ -178,11 +178,12 @@ Android_VideoInit(_THIS)
|
|||||||
videodata->isPaused = SDL_FALSE;
|
videodata->isPaused = SDL_FALSE;
|
||||||
videodata->isPausing = SDL_FALSE;
|
videodata->isPausing = SDL_FALSE;
|
||||||
|
|
||||||
mode.format = Android_ScreenFormat;
|
mode.format = Android_ScreenFormat;
|
||||||
mode.w = Android_DeviceWidth;
|
mode.w = Android_DeviceWidth;
|
||||||
mode.h = Android_DeviceHeight;
|
mode.h = Android_DeviceHeight;
|
||||||
mode.refresh_rate = Android_ScreenRate;
|
mode.refresh_rate = Android_ScreenRate;
|
||||||
mode.driverdata = NULL;
|
mode.driverdata = NULL;
|
||||||
|
|
||||||
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
|
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -213,45 +214,45 @@ Android_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Android_SetScreenResolution(SDL_Window *window, int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, Uint32 format, float rate)
|
Android_SetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, Uint32 format, float rate)
|
||||||
{
|
{
|
||||||
SDL_VideoDevice *device;
|
Android_SurfaceWidth = surfaceWidth;
|
||||||
SDL_VideoDisplay *display;
|
|
||||||
Android_SurfaceWidth = surfaceWidth;
|
|
||||||
Android_SurfaceHeight = surfaceHeight;
|
Android_SurfaceHeight = surfaceHeight;
|
||||||
Android_DeviceWidth = deviceWidth;
|
Android_DeviceWidth = deviceWidth;
|
||||||
Android_DeviceHeight = deviceHeight;
|
Android_DeviceHeight = deviceHeight;
|
||||||
Android_ScreenFormat = format;
|
Android_ScreenFormat = format;
|
||||||
Android_ScreenRate = (int)rate;
|
Android_ScreenRate = (int)rate;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Android_SendResize(SDL_Window *window)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
Update the resolution of the desktop mode, so that the window
|
Update the resolution of the desktop mode, so that the window
|
||||||
can be properly resized. The screen resolution change can for
|
can be properly resized. The screen resolution change can for
|
||||||
example happen when the Activity enters or exits immersive mode,
|
example happen when the Activity enters or exits immersive mode,
|
||||||
which can happen after VideoInit().
|
which can happen after VideoInit().
|
||||||
*/
|
*/
|
||||||
device = SDL_GetVideoDevice();
|
SDL_VideoDevice *device = SDL_GetVideoDevice();
|
||||||
if (device && device->num_displays > 0)
|
if (device && device->num_displays > 0)
|
||||||
{
|
{
|
||||||
display = &device->displays[0];
|
SDL_VideoDisplay *display = &device->displays[0];
|
||||||
display->desktop_mode.format = Android_ScreenFormat;
|
display->desktop_mode.format = Android_ScreenFormat;
|
||||||
display->desktop_mode.w = Android_DeviceWidth;
|
display->desktop_mode.w = Android_DeviceWidth;
|
||||||
display->desktop_mode.h = Android_DeviceHeight;
|
display->desktop_mode.h = Android_DeviceHeight;
|
||||||
display->desktop_mode.refresh_rate = Android_ScreenRate;
|
display->desktop_mode.refresh_rate = Android_ScreenRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window) {
|
if (window) {
|
||||||
/* Force the current mode to match the resize otherwise the SDL_WINDOWEVENT_RESTORED event
|
/* Force the current mode to match the resize otherwise the SDL_WINDOWEVENT_RESTORED event
|
||||||
* will fall back to the old mode */
|
* will fall back to the old mode */
|
||||||
display = SDL_GetDisplayForWindow(window);
|
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
||||||
|
display->display_modes[0].format = Android_ScreenFormat;
|
||||||
|
display->display_modes[0].w = Android_DeviceWidth;
|
||||||
|
display->display_modes[0].h = Android_DeviceHeight;
|
||||||
|
display->display_modes[0].refresh_rate = Android_ScreenRate;
|
||||||
|
display->current_mode = display->display_modes[0];
|
||||||
|
|
||||||
display->display_modes[0].format = format;
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, Android_SurfaceWidth, Android_SurfaceHeight);
|
||||||
display->display_modes[0].w = Android_DeviceWidth;
|
|
||||||
display->display_modes[0].h = Android_DeviceHeight;
|
|
||||||
display->display_modes[0].refresh_rate = (int)rate;
|
|
||||||
display->current_mode = display->display_modes[0];
|
|
||||||
|
|
||||||
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, surfaceWidth, surfaceHeight);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,8 @@
|
|||||||
#include "../SDL_sysvideo.h"
|
#include "../SDL_sysvideo.h"
|
||||||
|
|
||||||
/* Called by the JNI layer when the screen changes size or format */
|
/* Called by the JNI layer when the screen changes size or format */
|
||||||
extern void Android_SetScreenResolution(SDL_Window *window, int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, Uint32 format, float rate);
|
extern void Android_SetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, Uint32 format, float rate);
|
||||||
|
extern void Android_SendResize(SDL_Window *window);
|
||||||
|
|
||||||
/* Private display data */
|
/* Private display data */
|
||||||
|
|
||||||
@ -41,8 +42,6 @@ typedef struct SDL_VideoData
|
|||||||
|
|
||||||
extern int Android_SurfaceWidth;
|
extern int Android_SurfaceWidth;
|
||||||
extern int Android_SurfaceHeight;
|
extern int Android_SurfaceHeight;
|
||||||
extern int Android_DeviceWidth;
|
|
||||||
extern int Android_DeviceHeight;
|
|
||||||
extern SDL_sem *Android_PauseSem, *Android_ResumeSem;
|
extern SDL_sem *Android_PauseSem, *Android_ResumeSem;
|
||||||
extern SDL_mutex *Android_ActivityMutex;
|
extern SDL_mutex *Android_ActivityMutex;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user