Skip to content

Commit 8f1a04d

Browse files
committed
Update patch
1 parent 806f468 commit 8f1a04d

File tree

2 files changed

+216
-74
lines changed

2 files changed

+216
-74
lines changed

pythonforandroid/recipes/sdl2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class LibSDL2Recipe(BootstrapNDKRecipe):
1414

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

17-
patches = ['mutex.patch']
17+
patches = ['mutex3.patch']
1818

1919
def get_recipe_env(self, arch=None, with_flags_in_cc=True, with_python=True):
2020
env = super().get_recipe_env(
Lines changed: 215 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,166 +1,308 @@
11
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 @@
2+
--- SDL.orig/src/core/android/SDL_android.c 2022-08-13 05:48:10.000000000 +0200
3+
+++ SDL/src/core/android/SDL_android.c 2022-09-25 15:20:13.000000000 +0200
4+
@@ -819,11 +819,13 @@
5+
6+
/* Lock / Unlock Mutex */
7+
void Android_ActivityMutex_Lock() {
8+
+ __android_log_print(2, "SDL", "Android_ActivityMutex_Lock()");
9+
SDL_LockMutex(Android_ActivityMutex);
10+
}
11+
12+
void Android_ActivityMutex_Unlock() {
13+
SDL_UnlockMutex(Android_ActivityMutex);
14+
+ __android_log_print(2, "SDL", "Android_ActivityMutex_Unlock()");
15+
}
16+
17+
/* Lock the Mutex when the Activity is in its 'Running' state */
18+
@@ -832,7 +834,7 @@
19+
int resumeSignaled = 0;
20+
21+
retry:
22+
-
23+
+ __android_log_print(2, "SDL", "Android_ActivityMutex_Lock_Running()-Lock");
24+
SDL_LockMutex(Android_ActivityMutex);
25+
26+
pauseSignaled = SDL_SemValue(Android_PauseSem);
27+
@@ -840,6 +842,7 @@
28+
29+
if (pauseSignaled > resumeSignaled) {
30+
SDL_UnlockMutex(Android_ActivityMutex);
31+
+ __android_log_print(2, "SDL", "Android_ActivityMutex_Lock_Running()-Unlock");
32+
SDL_Delay(50);
33+
goto retry;
34+
}
35+
@@ -851,17 +854,20 @@
536
jint surfaceWidth, jint surfaceHeight,
637
jint deviceWidth, jint deviceHeight, jfloat rate)
738
{
8-
- SDL_LockMutex(Android_ActivityMutex);
9-
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeSetScreenResolution()");
10-
+ //SDL_LockMutex(Android_ActivityMutex);
39+
+ __android_log_print(2, "SDL", "nativeSetScreenResolution()-Lock");
40+
SDL_LockMutex(Android_ActivityMutex);
1141

1242
Android_SetScreenResolution(surfaceWidth, surfaceHeight, deviceWidth, deviceHeight, rate);
1343

14-
- SDL_UnlockMutex(Android_ActivityMutex);
15-
+ //SDL_UnlockMutex(Android_ActivityMutex);
44+
SDL_UnlockMutex(Android_ActivityMutex);
45+
+ __android_log_print(2, "SDL", "nativeSetScreenResolution()-Unlock");
1646
}
1747

1848
/* Resize */
1949
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
2050
JNIEnv *env, jclass jcls)
2151
{
22-
- SDL_LockMutex(Android_ActivityMutex);
23-
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "onNativeResize()");
24-
+ //SDL_LockMutex(Android_ActivityMutex);
52+
+ __android_log_print(2, "SDL", "onNativeResize()-Lock");
53+
SDL_LockMutex(Android_ActivityMutex);
2554

2655
if (Android_Window)
27-
{
28-
Android_SendResize(Android_Window);
56+
@@ -870,12 +876,14 @@
2957
}
3058

31-
- SDL_UnlockMutex(Android_ActivityMutex);
32-
+ //SDL_UnlockMutex(Android_ActivityMutex);
59+
SDL_UnlockMutex(Android_ActivityMutex);
60+
+ __android_log_print(2, "SDL", "onNativeResize()-Unlock");
3361
}
3462

3563
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeOrientationChanged)(
3664
JNIEnv *env, jclass jcls,
3765
jint orientation)
3866
{
39-
- SDL_LockMutex(Android_ActivityMutex);
40-
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "onNativeOrientationChanged()");
41-
+ //SDL_LockMutex(Android_ActivityMutex);
67+
+ __android_log_print(2, "SDL", "onNativeOrientationChanged()-Lock");
68+
SDL_LockMutex(Android_ActivityMutex);
4269

4370
displayOrientation = (SDL_DisplayOrientation)orientation;
44-
45-
@@ -886,7 +889,7 @@
46-
SDL_SendDisplayEvent(display, SDL_DISPLAYEVENT_ORIENTATION, orientation);
71+
@@ -887,6 +895,7 @@
4772
}
4873

49-
- SDL_UnlockMutex(Android_ActivityMutex);
50-
+ //SDL_UnlockMutex(Android_ActivityMutex);
74+
SDL_UnlockMutex(Android_ActivityMutex);
75+
+ __android_log_print(2, "SDL", "onNativeOrientationChanged()-Unlock");
5176
}
5277

5378
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeAddTouch)(
54-
@@ -988,7 +991,8 @@
79+
@@ -988,6 +997,7 @@
5580
/* Called from surfaceCreated() */
5681
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceCreated)(JNIEnv *env, jclass jcls)
5782
{
58-
- SDL_LockMutex(Android_ActivityMutex);
59-
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "onNativeSurfaceCreated()");
60-
+ //SDL_LockMutex(Android_ActivityMutex);
83+
+ __android_log_print(2, "SDL", "onNativeSurfaceCreated()-Lock");
84+
SDL_LockMutex(Android_ActivityMutex);
6185

6286
if (Android_Window)
63-
{
64-
@@ -1000,13 +1004,14 @@
65-
}
87+
@@ -1001,11 +1011,13 @@
6688
}
6789

68-
- SDL_UnlockMutex(Android_ActivityMutex);
69-
+ //SDL_UnlockMutex(Android_ActivityMutex);
90+
SDL_UnlockMutex(Android_ActivityMutex);
91+
+ __android_log_print(2, "SDL", "onNativeSurfaceCreated()-Unlock");
7092
}
7193

7294
/* Called from surfaceChanged() */
7395
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv *env, jclass jcls)
7496
{
75-
- SDL_LockMutex(Android_ActivityMutex);
76-
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "onNativeSurfaceChanged()");
77-
+ //SDL_LockMutex(Android_ActivityMutex);
97+
+ __android_log_print(2, "SDL", "onNativeSurfaceChanged()-Lock");
98+
SDL_LockMutex(Android_ActivityMutex);
7899

79100
#if SDL_VIDEO_OPENGL_EGL
80-
if (Android_Window)
81-
@@ -1023,7 +1028,7 @@
82-
}
101+
@@ -1024,6 +1036,7 @@
83102
#endif
84103

85-
- SDL_UnlockMutex(Android_ActivityMutex);
86-
+ //SDL_UnlockMutex(Android_ActivityMutex);
104+
SDL_UnlockMutex(Android_ActivityMutex);
105+
+ __android_log_print(2, "SDL", "onNativeSurfaceChanged()-Unlock");
87106
}
88107

89108
/* Called from surfaceDestroyed() */
90-
@@ -1032,8 +1037,8 @@
109+
@@ -1032,7 +1045,7 @@
91110
int nb_attempt = 50;
92111

93112
retry:
94113
-
95-
- SDL_LockMutex(Android_ActivityMutex);
96-
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "onNativeSurfaceDestroyed()");
97-
+ //SDL_LockMutex(Android_ActivityMutex);
114+
+ __android_log_print(2, "SDL", "onNativeSurfaceDestroyed()-Lock");
115+
SDL_LockMutex(Android_ActivityMutex);
98116

99117
if (Android_Window)
100-
{
101-
@@ -1046,7 +1051,7 @@
102-
if (nb_attempt == 0) {
118+
@@ -1047,6 +1060,7 @@
103119
SDL_SetError("Try to release egl_surface with context probably still active");
104120
} else {
105-
- SDL_UnlockMutex(Android_ActivityMutex);
106-
+ //SDL_UnlockMutex(Android_ActivityMutex);
121+
SDL_UnlockMutex(Android_ActivityMutex);
122+
+ __android_log_print(2, "SDL", "onNativeSurfaceDestroyed()-Unlock");
107123
SDL_Delay(10);
108124
goto retry;
109125
}
110-
@@ -1067,7 +1072,7 @@
111-
/* GL Context handling is done in the event loop because this function is run from the Java thread */
126+
@@ -1068,6 +1082,7 @@
112127
}
113128

114-
- SDL_UnlockMutex(Android_ActivityMutex);
115-
+ //SDL_UnlockMutex(Android_ActivityMutex);
129+
SDL_UnlockMutex(Android_ActivityMutex);
130+
+ __android_log_print(2, "SDL", "onNativeSurfaceDestroyed2()-Unlock");
116131
}
117132

118133
/* Keydown */
119-
@@ -1112,11 +1117,12 @@
134+
@@ -1112,11 +1127,13 @@
120135
jint touch_device_id_in, jint pointer_finger_id_in,
121136
jint action, jfloat x, jfloat y, jfloat p)
122137
{
123-
- SDL_LockMutex(Android_ActivityMutex);
124-
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "onNativeTouch()");
125-
+ SDL_LockMutex(Android_ActivityMutex);
138+
+ __android_log_print(2, "SDL", "onNativeTouch()-Lock");
139+
SDL_LockMutex(Android_ActivityMutex);
126140

127141
Android_OnTouch(Android_Window, touch_device_id_in, pointer_finger_id_in, action, x, y, p);
128142

129-
- SDL_UnlockMutex(Android_ActivityMutex);
130-
+ SDL_UnlockMutex(Android_ActivityMutex);
143+
SDL_UnlockMutex(Android_ActivityMutex);
144+
+ __android_log_print(2, "SDL", "onNativeTouch()-Unlock");
131145
}
132146

133147
/* Mouse */
134-
@@ -1124,11 +1130,12 @@
148+
@@ -1124,11 +1141,13 @@
135149
JNIEnv *env, jclass jcls,
136150
jint button, jint action, jfloat x, jfloat y, jboolean relative)
137151
{
138-
- SDL_LockMutex(Android_ActivityMutex);
139-
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "onNativeMouse()");
140-
+ //SDL_LockMutex(Android_ActivityMutex);
152+
+ __android_log_print(2, "SDL", "onNativeMouse()-Lock");
153+
SDL_LockMutex(Android_ActivityMutex);
141154

142155
Android_OnMouse(Android_Window, button, action, x, y, relative);
143156

144-
- SDL_UnlockMutex(Android_ActivityMutex);
145-
+ //SDL_UnlockMutex(Android_ActivityMutex);
157+
SDL_UnlockMutex(Android_ActivityMutex);
158+
+ __android_log_print(2, "SDL", "onNativeMouse()-Unlock");
146159
}
147160

148161
/* Accelerometer */
149-
@@ -1243,14 +1250,15 @@
162+
@@ -1243,6 +1262,7 @@
150163
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeFocusChanged)(
151164
JNIEnv *env, jclass cls, jboolean hasFocus)
152165
{
153-
- SDL_LockMutex(Android_ActivityMutex);
154-
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeFocusChanged()");
155-
+ SDL_LockMutex(Android_ActivityMutex);
166+
+ __android_log_print(2, "SDL", "nativeFocusChanged()-Lock");
167+
SDL_LockMutex(Android_ActivityMutex);
156168

157169
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);
170+
@@ -1251,6 +1271,7 @@
160171
}
161172

162-
- SDL_UnlockMutex(Android_ActivityMutex);
163-
+ SDL_UnlockMutex(Android_ActivityMutex);
173+
SDL_UnlockMutex(Android_ActivityMutex);
174+
+ __android_log_print(2, "SDL", "nativeFocusChanged()-Unlock");
164175
}
165176

166177
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeCommitText)(
178+
diff -Naur SDL.orig/src/video/android/SDL_androidevents.c SDL/src/video/android/SDL_androidevents.c
179+
--- SDL.orig/src/video/android/SDL_androidevents.c 2022-04-09 03:19:19.000000000 +0200
180+
+++ SDL/src/video/android/SDL_androidevents.c 2022-09-25 15:20:57.000000000 +0200
181+
@@ -117,9 +117,11 @@
182+
#if SDL_VIDEO_OPENGL_EGL
183+
/* Make sure this is the last thing we do before pausing */
184+
if (!isContextExternal) {
185+
+ __android_log_print(2, "SDL", "Android_PumpEvents_Blocking()-Lock");
186+
SDL_LockMutex(Android_ActivityMutex);
187+
android_egl_context_backup(Android_Window);
188+
SDL_UnlockMutex(Android_ActivityMutex);
189+
+ __android_log_print(2, "SDL", "Android_PumpEvents_Blocking()-Unlock");
190+
}
191+
#endif
192+
193+
@@ -143,9 +145,11 @@
194+
/* Restore the GL Context from here, as this operation is thread dependent */
195+
#if SDL_VIDEO_OPENGL_EGL
196+
if (!isContextExternal && !SDL_HasEvent(SDL_QUIT)) {
197+
+ __android_log_print(2, "SDL", "Android_PumpEvents_Blocking-2()-Lock");
198+
SDL_LockMutex(Android_ActivityMutex);
199+
android_egl_context_restore(Android_Window);
200+
SDL_UnlockMutex(Android_ActivityMutex);
201+
+ __android_log_print(2, "SDL", "Android_PumpEvents_Blocking-2()-Unlock");
202+
}
203+
#endif
204+
205+
@@ -195,9 +199,11 @@
206+
207+
#if SDL_VIDEO_OPENGL_EGL
208+
if (!isContextExternal) {
209+
+ __android_log_print(2, "SDL", "AndroidPumpEvents_NonBlocking()-Lock");
210+
SDL_LockMutex(Android_ActivityMutex);
211+
android_egl_context_backup(Android_Window);
212+
SDL_UnlockMutex(Android_ActivityMutex);
213+
+ __android_log_print(2, "SDL", "AndroidPumpEvents_NonBlocking()-Unlock");
214+
}
215+
#endif
216+
217+
@@ -229,9 +235,11 @@
218+
#if SDL_VIDEO_OPENGL_EGL
219+
/* Restore the GL Context from here, as this operation is thread dependent */
220+
if (!isContextExternal && !SDL_HasEvent(SDL_QUIT)) {
221+
+ __android_log_print(2, "SDL", "Android_PumpEvents_NonBlocking-2()-Lock");
222+
SDL_LockMutex(Android_ActivityMutex);
223+
android_egl_context_restore(Android_Window);
224+
SDL_UnlockMutex(Android_ActivityMutex);
225+
+ __android_log_print(2, "SDL", "Android_PumpEvents_NonBlocking-2()-Unlock");
226+
}
227+
#endif
228+
229+
diff -Naur SDL.orig/src/video/android/SDL_androidgl.c SDL/src/video/android/SDL_androidgl.c
230+
--- SDL.orig/src/video/android/SDL_androidgl.c 2022-04-09 03:19:19.000000000 +0200
231+
+++ SDL/src/video/android/SDL_androidgl.c 2022-09-25 15:21:55.000000000 +0200
232+
@@ -56,6 +56,7 @@
233+
ret = SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
234+
235+
SDL_UnlockMutex(Android_ActivityMutex);
236+
+ __android_log_print(2, "SDL", "Android_GLES_CreateContext()-Unlock");
237+
238+
return ret;
239+
}
240+
@@ -64,8 +65,8 @@
241+
Android_GLES_SwapWindow(_THIS, SDL_Window * window)
242+
{
243+
int retval;
244+
-
245+
- SDL_LockMutex(Android_ActivityMutex);
246+
+ __android_log_print(2, "SDL", "Android_GLES_SwapWindow()-Lock");
247+
+ // SDL_LockMutex(Android_ActivityMutex);
248+
249+
/* The following two calls existed in the original Java code
250+
* If you happen to have a device that's affected by their removal,
251+
@@ -74,9 +75,10 @@
252+
253+
/*_this->egl_data->eglWaitNative(EGL_CORE_NATIVE_ENGINE);
254+
_this->egl_data->eglWaitGL();*/
255+
- retval = SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
256+
+ retval = SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface); //
257+
258+
- SDL_UnlockMutex(Android_ActivityMutex);
259+
+ // SDL_UnlockMutex(Android_ActivityMutex);
260+
+ __android_log_print(2, "SDL", "Android_GLES_SwapWindow()-Unlock");
261+
262+
return retval;
263+
}
264+
diff -Naur SDL.orig/src/video/android/SDL_androidwindow.c SDL/src/video/android/SDL_androidwindow.c
265+
--- SDL.orig/src/video/android/SDL_androidwindow.c 2022-06-02 04:01:57.000000000 +0200
266+
+++ SDL/src/video/android/SDL_androidwindow.c 2022-09-25 15:23:00.000000000 +0200
267+
@@ -100,6 +100,7 @@
268+
endfunction:
269+
270+
SDL_UnlockMutex(Android_ActivityMutex);
271+
+ __android_log_print(2, "SDL", "Android_CreateWindow()-Unlock");
272+
273+
return retval;
274+
}
275+
@@ -112,7 +113,8 @@
276+
277+
void
278+
Android_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
279+
-{
280+
+{
281+
+ __android_log_print(2, "SDL", "Android_SetWindowFullscreen()-Lock");
282+
SDL_LockMutex(Android_ActivityMutex);
283+
284+
if (window == Android_Window) {
285+
@@ -160,6 +162,7 @@
286+
endfunction:
287+
288+
SDL_UnlockMutex(Android_ActivityMutex);
289+
+ __android_log_print(2, "SDL", "Android_SetWindowFullscreen()-Unlock");
290+
}
291+
292+
void
293+
@@ -177,6 +180,7 @@
294+
void
295+
Android_DestroyWindow(_THIS, SDL_Window *window)
296+
{
297+
+ __android_log_print(2, "SDL", "Android_DestroyWindow()-Lock");
298+
SDL_LockMutex(Android_ActivityMutex);
299+
300+
if (window == Android_Window) {
301+
@@ -200,6 +204,7 @@
302+
}
303+
304+
SDL_UnlockMutex(Android_ActivityMutex);
305+
+ __android_log_print(2, "SDL", "Android_DestroyWindow()-Unlock");
306+
}
307+
308+
SDL_bool

0 commit comments

Comments
 (0)