Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,869 changes: 1,425 additions & 444 deletions src/core/android/SDL_android.c

Large diffs are not rendered by default.

23 changes: 7 additions & 16 deletions src/core/android/SDL_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,8 @@ extern "C" {
// this appears to be broken right now (on Android, not SDL, I think...?).
#define ALLOW_MULTIPLE_ANDROID_AUDIO_DEVICES 0

// Life cycle
typedef enum
{
SDL_ANDROID_LIFECYCLE_WAKE,
SDL_ANDROID_LIFECYCLE_PAUSE,
SDL_ANDROID_LIFECYCLE_RESUME,
SDL_ANDROID_LIFECYCLE_LOWMEMORY,
SDL_ANDROID_LIFECYCLE_DESTROY,
SDL_NUM_ANDROID_LIFECYCLE_EVENTS
} SDL_AndroidLifecycleEvent;

void Android_SendLifecycleEvent(SDL_AndroidLifecycleEvent event);
bool Android_WaitLifecycleEvent(SDL_AndroidLifecycleEvent *event, Sint64 timeoutNS);

void Android_LockActivityMutex(void);
void Android_UnlockActivityMutex(void);
void Android_LockActivityState(void);
void Android_UnlockActivityState(void);

void Android_SetAllowRecreateActivity(bool enabled);

Expand Down Expand Up @@ -158,6 +144,11 @@ bool Android_JNI_ShowFileDialog(SDL_DialogFileCallback callback, void *userdata,
const SDL_DialogFileFilter *filters, int nfilters, SDL_FileDialogType type,
bool multiple, const char *initialPath);

// Pump RPC commands
void Android_PumpRPC(SDL_Window *window);
void Android_WaitForResume(void);


// Ends C function definitions when using C++
#ifdef __cplusplus
/* *INDENT-OFF* */
Expand Down
18 changes: 11 additions & 7 deletions src/events/SDL_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include "../video/SDL_sysvideo.h"

#ifdef SDL_PLATFORM_ANDROID
#include "../core/android/SDL_android.h"
#include "../video/android/SDL_androidevents.h"
#endif

Expand Down Expand Up @@ -1130,7 +1129,7 @@ static void SDL_CutEvent(SDL_EventEntry *entry)
static void SDL_SendWakeupEvent(void)
{
#ifdef SDL_PLATFORM_ANDROID
Android_SendLifecycleEvent(SDL_ANDROID_LIFECYCLE_WAKE);
Android_WakeUp();
#else
SDL_VideoDevice *_this = SDL_GetVideoDevice();
if (_this == NULL || !_this->SendWakeupEvent) {
Expand Down Expand Up @@ -1516,7 +1515,7 @@ static void SDL_PumpEventsInternal(bool push_sentinel)

#ifdef SDL_PLATFORM_ANDROID
// Android event processing is independent of the video subsystem
Android_PumpEvents(0);
Android_PumpEvents();
#else
// Get events from the video subsystem
SDL_VideoDevice *_this = SDL_GetVideoDevice();
Expand Down Expand Up @@ -1550,7 +1549,12 @@ void SDL_PumpEvents(void)

bool SDL_PollEvent(SDL_Event *event)
{
return SDL_WaitEventTimeoutNS(event, 0);
bool ret = SDL_WaitEventTimeoutNS(event, 0);
#ifdef SDL_PLATFORM_ANDROID
Android_BlockEventLoop();
#endif
return ret;

}

#ifndef SDL_PLATFORM_ANDROID
Expand Down Expand Up @@ -1740,16 +1744,16 @@ bool SDL_WaitEventTimeoutNS(SDL_Event *event, Sint64 timeoutNS)
return true;
}

Uint64 delay = -1;
Uint64 delay = SDL_MS_TO_NS(10);
if (timeoutNS > 0) {
Uint64 now = SDL_GetTicksNS();
if (now >= expiration) {
// Timeout expired and no events
return false;
}
delay = (expiration - now);
delay = SDL_min((expiration - now), delay);
}
Android_PumpEvents(delay);
SDL_DelayNS(delay);
}
#else
SDL_VideoDevice *_this = SDL_GetVideoDevice();
Expand Down
12 changes: 6 additions & 6 deletions src/joystick/android/SDL_sysjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static int numjoysticks = 0;
* This code manipulation is done to get a sequential list of codes.
* 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)
{
// FIXME: If this function gets too unwieldy in the future, replace with a lookup table
int button = 0;
Expand Down Expand Up @@ -172,7 +172,7 @@ static int keycode_to_SDL(int keycode)
return button;
}

static int scancode_to_SDL(int scancode)
int Android_scancode_to_SDL(int scancode)
{
int button = 0;
switch (scancode) {
Expand Down Expand Up @@ -226,9 +226,9 @@ bool Android_OnPadDown(int device_id, int keycode, int scancode)
{
Uint64 timestamp = SDL_GetTicksNS();
SDL_joylist_item *item;
int button = keycode_to_SDL(keycode);
int button = Android_keycode_to_SDL(keycode);
if (button < 0) {
button = scancode_to_SDL(scancode);
button = Android_scancode_to_SDL(scancode);
}
if (button >= 0) {
SDL_LockJoysticks();
Expand All @@ -249,9 +249,9 @@ bool Android_OnPadUp(int device_id, int keycode, int scancode)
{
Uint64 timestamp = SDL_GetTicksNS();
SDL_joylist_item *item;
int button = keycode_to_SDL(keycode);
int button = Android_keycode_to_SDL(keycode);
if (button < 0) {
button = scancode_to_SDL(scancode);
button = Android_scancode_to_SDL(scancode);
}
if (button >= 0) {
SDL_LockJoysticks();
Expand Down
2 changes: 2 additions & 0 deletions src/joystick/android/SDL_sysjoystick_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include "../SDL_sysjoystick.h"

extern int Android_keycode_to_SDL(int keycode);
extern int Android_scancode_to_SDL(int scancode);
extern bool Android_OnPadDown(int device_id, int keycode, int scancode);
extern bool Android_OnPadUp(int device_id, int keycode, int scancode);
extern bool Android_OnJoy(int device_id, int axisnum, float value);
Expand Down
9 changes: 9 additions & 0 deletions src/main/SDL_main_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include "SDL_internal.h"
#include "SDL_main_callbacks.h"

#ifdef SDL_PLATFORM_ANDROID
#include "../video/android/SDL_androidevents.h"
#endif

static SDL_AppEvent_func SDL_main_event_callback;
static SDL_AppIterate_func SDL_main_iteration_callback;
static SDL_AppQuit_func SDL_main_quit_callback;
Expand Down Expand Up @@ -123,6 +127,11 @@ SDL_AppResult SDL_IterateMainCallbacks(bool pump_events)
if (pump_events) {
SDL_PumpEvents();
}

#ifdef SDL_PLATFORM_ANDROID
Android_BlockEventLoop();
#endif

SDL_DispatchMainCallbackEvents();

SDL_AppResult rc = (SDL_AppResult)SDL_GetAtomicInt(&apprc);
Expand Down
6 changes: 3 additions & 3 deletions src/render/SDL_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props)
}

#ifdef SDL_PLATFORM_ANDROID
if (!Android_WaitActiveAndLockActivity()) {
if (!Android_WaitActiveAndLockActivity(window)) {
return NULL;
}
#endif
Expand Down Expand Up @@ -1260,7 +1260,7 @@ SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props)
SDL_renderers = renderer;

#ifdef SDL_PLATFORM_ANDROID
Android_UnlockActivityMutex();
Android_UnlockActivityState();
#endif

SDL_ClearError();
Expand All @@ -1269,7 +1269,7 @@ SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props)

error:
#ifdef SDL_PLATFORM_ANDROID
Android_UnlockActivityMutex();
Android_UnlockActivityState();
#endif

if (renderer) {
Expand Down
Loading
Loading