Android: add command mecanism to SDLActivity #14949
Conversation
but defers it to SDL main thread
|
PR is still as draft because I need to test it in production, |
| // Android event processing is independent of the video subsystem | ||
| Android_PumpEvents(0); | ||
| SDL_VideoDevice *_this = SDL_GetVideoDevice(); | ||
| SDL_Window *window = _this->windows; |
There was a problem hiding this comment.
Crash if video isn't initialized (also below)
| * FIXME: This is only suited for the case where we use a fixed number of buttons determined by ANDROID_MAX_NBUTTONS | ||
| */ | ||
| static int keycode_to_SDL(int keycode) | ||
| int android_keycode_to_SDL(int keycode) |
There was a problem hiding this comment.
| int android_keycode_to_SDL(int keycode) | |
| int Android_Keycode_to_SDL(int keycode) |
|
The joystick inputs are specifically designed to be thread-safe and low latency, so they should probably bypass the RPC queue. |
|
Updated with suggestion. maybe we can add hint define to have the 2 differents behaviors. handling with rpc shouldn't be that low |
| if (_this) { | ||
| SDL_Window *window = _this->windows; | ||
| if (window) { | ||
| Android_PumpEvents(window, 0); | ||
| } | ||
| } |
There was a problem hiding this comment.
We still need to pump events for lifecycle activity even if there's no window or video hasn't been initialized.
It still involves an extra thread context switch which could be delayed due to scheduling. We don't need a hint, we just need the gamepad events to be passed through immediately. |
|
ok, ? |
Yes, it would be all of the gamepad related functions. Really only the inputs are time sensitive, but we don't want input coming before nativeAddJoystick() has been processed, etc. |
…y (default) or C Thread
|
I've added a preprocessor define to toggle between gamepad under SDLActivity (now the default) or main C thread |
|
This branch was (accidentally) created on the libsdl-org/SDL repo. |
|
oops, sorry I didn't notice that. |
|
ok new PR is there ! thanks for catching |
Add some RPC commands so that SDLActivity defers most of SDL code internal execution it to the SDL main thread
see #14925
Most SDLActivity code is deferred to main SDL C thread with some command RPC.
except:
(SDL_Window *)Android_Window global variable is removed.
Android ActivityMutex is removed.
Android_LifecycleMutex, is used to lock the SDLActivity state. (Android_WaitActiveAndLockActivity()).
since it prevents the SDLActivity to add new lifecylce message, it prevents it to change state.
factorisation of EGLSurface/native_window handling. (use in surfaceChanged/Created/Destroy, and SDLCreate/DestroyWindow()
It seem to work quite nicely from my side. I tested various stuff, but not fully.
(onNativeFileDialog() was the less easy to update, and I really have to tested).
other functions are always simple. I guess, the ways it's written with named struct, prevent lot of type mistake.
Still a draft. please give a try.
I'll try it also in production maybe in a while
maybe 2 todo:
I didn't add the HID native functions .. I am not familiar with them. but then didn't rely on SDL and use no locking.
so maybe it makes not difference. (they could be added anyway afterwards).
we probably lose some event timestamp precision because event are sent from Main thread, and not SDLActivity thread. maybe it's not a big deal.
but if we need it for some command, we could add. (just enabled the timestamp, and then send it with the event).
maybe we wait to see, if this is really useful