[Scummvm-git-logs] scummvm master -> a58bac8ccb2363b5d3cdf276aa1678ef38543d74

lephilousophe noreply at scummvm.org
Fri Jul 14 09:22:15 UTC 2023


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
a58bac8ccb ANDROID: Avoid calling native code from UI thread


Commit: a58bac8ccb2363b5d3cdf276aa1678ef38543d74
    https://github.com/scummvm/scummvm/commit/a58bac8ccb2363b5d3cdf276aa1678ef38543d74
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-07-14T11:22:06+02:00

Commit Message:
ANDROID: Avoid calling native code from UI thread

This can lead to race conditions.
When synchronizing virtual keyboard state, just set a variable in UI
thread.
The variable will be read in worker thread during event polling, this
will ensure that graphics code is configured at a proper time.

Changed paths:
    backends/platform/android/android.cpp
    backends/platform/android/android.h
    backends/platform/android/events.cpp
    backends/platform/android/jni-android.cpp
    backends/platform/android/jni-android.h


diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp
index 8a3c4982fcd..ecc4caa84dc 100644
--- a/backends/platform/android/android.cpp
+++ b/backends/platform/android/android.cpp
@@ -951,11 +951,6 @@ int OSystem_Android::getGraphicsMode() const {
 	return 0;
 }
 
-void OSystem_Android::syncVirtkeyboardState(bool virtkeybd_on) {
-	_virtkeybd_on = virtkeybd_on;
-	dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->syncVirtkeyboardState(virtkeybd_on);
-}
-
 #if defined(USE_OPENGL) && defined(USE_GLAD)
 void *OSystem_Android::getOpenGLProcAddress(const char *name) const {
 	// eglGetProcAddress exists since Android 2.3 (API Level 9)
diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h
index 19cfefa2a40..af18643028f 100644
--- a/backends/platform/android/android.h
+++ b/backends/platform/android/android.h
@@ -188,8 +188,6 @@ public:
 	void applyTouchSettings(bool _3dMode, bool overlayShown);
 	void setupTouchMode(int oldValue, int newValue);
 
-	void syncVirtkeyboardState(bool virtkeybd_on);
-
 	void applyOrientationSettings();
 
 	bool pollEvent(Common::Event &event) override;
diff --git a/backends/platform/android/events.cpp b/backends/platform/android/events.cpp
index 12d738d8a02..9b6d85cd676 100644
--- a/backends/platform/android/events.cpp
+++ b/backends/platform/android/events.cpp
@@ -1439,6 +1439,11 @@ bool OSystem_Android::pollEvent(Common::Event &event) {
 			}
 		}
 
+		if (_virtkeybd_on != JNI::virt_keyboard_state) {
+			_virtkeybd_on = JNI::virt_keyboard_state;
+			dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->syncVirtkeyboardState(_virtkeybd_on);
+		}
+
 		if (JNI::pause) {
 			LOGD("main thread going to sleep");
 			sem_wait(&JNI::pause_sem);
diff --git a/backends/platform/android/jni-android.cpp b/backends/platform/android/jni-android.cpp
index 6af997571a0..7b8120d7a37 100644
--- a/backends/platform/android/jni-android.cpp
+++ b/backends/platform/android/jni-android.cpp
@@ -79,6 +79,7 @@ int JNI::egl_surface_width = 0;
 int JNI::egl_surface_height = 0;
 int JNI::egl_bits_per_pixel = 0;
 bool JNI::_ready_for_events = 0;
+bool JNI::virt_keyboard_state = false;
 
 jmethodID JNI::_MID_getDPI = 0;
 jmethodID JNI::_MID_displayMessageOnOSD = 0;
@@ -969,7 +970,7 @@ void JNI::syncVirtkeyboardState(JNIEnv *env, jobject self, jboolean newState) {
 	if (!_system)
 		return;
 
-	_system->syncVirtkeyboardState(newState);
+	JNI::virt_keyboard_state = newState;
 }
 
 void JNI::setPause(JNIEnv *env, jobject self, jboolean value) {
diff --git a/backends/platform/android/jni-android.h b/backends/platform/android/jni-android.h
index 13538e5d8a2..3f21dbeba7a 100644
--- a/backends/platform/android/jni-android.h
+++ b/backends/platform/android/jni-android.h
@@ -58,6 +58,8 @@ public:
 	static int egl_surface_height;
 	static int egl_bits_per_pixel;
 
+	static bool virt_keyboard_state;
+
 	static jint onLoad(JavaVM *vm);
 
 	static inline JNIEnv *getEnv() {




More information about the Scummvm-git-logs mailing list