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.
This commit is contained in:
Le Philousophe 2023-07-14 11:17:34 +02:00
parent 5964c36ab4
commit a58bac8ccb
5 changed files with 9 additions and 8 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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);

View File

@ -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) {

View File

@ -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() {