Skip to content

Commit 6db8770

Browse files
committed
patch to test activitymutex issues on SDL2
1 parent 518ae79 commit 6db8770

File tree

2 files changed

+168
-0
lines changed

2 files changed

+168
-0
lines changed

pythonforandroid/recipes/sdl2/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class LibSDL2Recipe(BootstrapNDKRecipe):
1414

1515
depends = ['sdl2_image', 'sdl2_mixer', 'sdl2_ttf']
1616

17+
patches = ['mutex.patch']
18+
1719
def get_recipe_env(self, arch=None, with_flags_in_cc=True, with_python=True):
1820
env = super().get_recipe_env(
1921
arch=arch, with_flags_in_cc=with_flags_in_cc, with_python=with_python)
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
diff -Naur SDL.orig/src/core/android/SDL_android.c SDL/src/core/android/SDL_android.c
2+
--- SDL.orig/src/core/android/SDL_android.c 2022-09-18 15:24:28.000000000 +0200
3+
+++ SDL/src/core/android/SDL_android.c 2022-09-18 15:31:20.000000000 +0200
4+
@@ -851,32 +851,35 @@
5+
jint surfaceWidth, jint surfaceHeight,
6+
jint deviceWidth, jint deviceHeight, jfloat rate)
7+
{
8+
- SDL_LockMutex(Android_ActivityMutex);
9+
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeSetScreenResolution()");
10+
+ SDL_LockMutex(Android_ActivityMutex);
11+
12+
Android_SetScreenResolution(surfaceWidth, surfaceHeight, deviceWidth, deviceHeight, rate);
13+
14+
- SDL_UnlockMutex(Android_ActivityMutex);
15+
+ SDL_UnlockMutex(Android_ActivityMutex);
16+
}
17+
18+
/* Resize */
19+
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
20+
JNIEnv *env, jclass jcls)
21+
{
22+
- SDL_LockMutex(Android_ActivityMutex);
23+
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "onNativeResize()");
24+
+ SDL_LockMutex(Android_ActivityMutex);
25+
26+
if (Android_Window)
27+
{
28+
Android_SendResize(Android_Window);
29+
}
30+
31+
- SDL_UnlockMutex(Android_ActivityMutex);
32+
+ SDL_UnlockMutex(Android_ActivityMutex);
33+
}
34+
35+
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeOrientationChanged)(
36+
JNIEnv *env, jclass jcls,
37+
jint orientation)
38+
{
39+
- SDL_LockMutex(Android_ActivityMutex);
40+
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "onNativeOrientationChanged()");
41+
+ SDL_LockMutex(Android_ActivityMutex);
42+
43+
displayOrientation = (SDL_DisplayOrientation)orientation;
44+
45+
@@ -886,7 +889,7 @@
46+
SDL_SendDisplayEvent(display, SDL_DISPLAYEVENT_ORIENTATION, orientation);
47+
}
48+
49+
- SDL_UnlockMutex(Android_ActivityMutex);
50+
+ SDL_UnlockMutex(Android_ActivityMutex);
51+
}
52+
53+
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeAddTouch)(
54+
@@ -988,7 +991,8 @@
55+
/* Called from surfaceCreated() */
56+
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceCreated)(JNIEnv *env, jclass jcls)
57+
{
58+
- SDL_LockMutex(Android_ActivityMutex);
59+
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "onNativeSurfaceCreated()");
60+
+ SDL_LockMutex(Android_ActivityMutex);
61+
62+
if (Android_Window)
63+
{
64+
@@ -1000,13 +1004,14 @@
65+
}
66+
}
67+
68+
- SDL_UnlockMutex(Android_ActivityMutex);
69+
+ SDL_UnlockMutex(Android_ActivityMutex);
70+
}
71+
72+
/* Called from surfaceChanged() */
73+
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv *env, jclass jcls)
74+
{
75+
- SDL_LockMutex(Android_ActivityMutex);
76+
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "onNativeSurfaceChanged()");
77+
+ SDL_LockMutex(Android_ActivityMutex);
78+
79+
#if SDL_VIDEO_OPENGL_EGL
80+
if (Android_Window)
81+
@@ -1023,7 +1028,7 @@
82+
}
83+
#endif
84+
85+
- SDL_UnlockMutex(Android_ActivityMutex);
86+
+ SDL_UnlockMutex(Android_ActivityMutex);
87+
}
88+
89+
/* Called from surfaceDestroyed() */
90+
@@ -1032,8 +1037,8 @@
91+
int nb_attempt = 50;
92+
93+
retry:
94+
-
95+
- SDL_LockMutex(Android_ActivityMutex);
96+
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "onNativeSurfaceDestroyed()");
97+
+ SDL_LockMutex(Android_ActivityMutex);
98+
99+
if (Android_Window)
100+
{
101+
@@ -1046,7 +1051,7 @@
102+
if (nb_attempt == 0) {
103+
SDL_SetError("Try to release egl_surface with context probably still active");
104+
} else {
105+
- SDL_UnlockMutex(Android_ActivityMutex);
106+
+ SDL_UnlockMutex(Android_ActivityMutex);
107+
SDL_Delay(10);
108+
goto retry;
109+
}
110+
@@ -1067,7 +1072,7 @@
111+
/* GL Context handling is done in the event loop because this function is run from the Java thread */
112+
}
113+
114+
- SDL_UnlockMutex(Android_ActivityMutex);
115+
+ SDL_UnlockMutex(Android_ActivityMutex);
116+
}
117+
118+
/* Keydown */
119+
@@ -1112,11 +1117,12 @@
120+
jint touch_device_id_in, jint pointer_finger_id_in,
121+
jint action, jfloat x, jfloat y, jfloat p)
122+
{
123+
- SDL_LockMutex(Android_ActivityMutex);
124+
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "onNativeTouch()");
125+
+ //SDL_LockMutex(Android_ActivityMutex);
126+
127+
Android_OnTouch(Android_Window, touch_device_id_in, pointer_finger_id_in, action, x, y, p);
128+
129+
- SDL_UnlockMutex(Android_ActivityMutex);
130+
+ //SDL_UnlockMutex(Android_ActivityMutex);
131+
}
132+
133+
/* Mouse */
134+
@@ -1124,11 +1130,12 @@
135+
JNIEnv *env, jclass jcls,
136+
jint button, jint action, jfloat x, jfloat y, jboolean relative)
137+
{
138+
- SDL_LockMutex(Android_ActivityMutex);
139+
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "onNativeMouse()");
140+
+ SDL_LockMutex(Android_ActivityMutex);
141+
142+
Android_OnMouse(Android_Window, button, action, x, y, relative);
143+
144+
- SDL_UnlockMutex(Android_ActivityMutex);
145+
+ SDL_UnlockMutex(Android_ActivityMutex);
146+
}
147+
148+
/* Accelerometer */
149+
@@ -1243,14 +1250,15 @@
150+
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeFocusChanged)(
151+
JNIEnv *env, jclass cls, jboolean hasFocus)
152+
{
153+
- SDL_LockMutex(Android_ActivityMutex);
154+
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeFocusChanged()");
155+
+ SDL_LockMutex(Android_ActivityMutex);
156+
157+
if (Android_Window) {
158+
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeFocusChanged()");
159+
SDL_SendWindowEvent(Android_Window, (hasFocus ? SDL_WINDOWEVENT_FOCUS_GAINED : SDL_WINDOWEVENT_FOCUS_LOST), 0, 0);
160+
}
161+
162+
- SDL_UnlockMutex(Android_ActivityMutex);
163+
+ SDL_UnlockMutex(Android_ActivityMutex);
164+
}
165+
166+
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeCommitText)(

0 commit comments

Comments
 (0)