Android: move static variable isPaused/isPausing to SDL_VideoData structure
authorSylvain Becker <sylvain.becker@gmail.com>
Wed, 16 Jan 2019 10:31:51 +0100
changeset 125526bc8c73ab0fe
parent 12551 90d2f58dcf0a
child 12553 faaec3975dbd
Android: move static variable isPaused/isPausing to SDL_VideoData structure

- remove unneed check to Android_Window->driverdata
- add window check into context_backup/restore
src/core/android/SDL_android.c
src/video/android/SDL_androidevents.c
src/video/android/SDL_androidvideo.c
src/video/android/SDL_androidvideo.h
     1.1 --- a/src/core/android/SDL_android.c	Wed Jan 16 09:22:20 2019 +0100
     1.2 +++ b/src/core/android/SDL_android.c	Wed Jan 16 10:31:51 2019 +0100
     1.3 @@ -800,7 +800,7 @@
     1.4  {
     1.5      SDL_LockMutex(Android_ActivityMutex);
     1.6  
     1.7 -    if (Android_Window && Android_Window->driverdata)
     1.8 +    if (Android_Window)
     1.9      {
    1.10          SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
    1.11  
    1.12 @@ -818,7 +818,7 @@
    1.13  {
    1.14      SDL_LockMutex(Android_ActivityMutex);
    1.15  
    1.16 -    if (Android_Window && Android_Window->driverdata)
    1.17 +    if (Android_Window)
    1.18      {
    1.19          SDL_VideoDevice *_this = SDL_GetVideoDevice();
    1.20          SDL_WindowData  *data  = (SDL_WindowData *) Android_Window->driverdata;
    1.21 @@ -839,7 +839,7 @@
    1.22  {
    1.23      SDL_LockMutex(Android_ActivityMutex);
    1.24  
    1.25 -    if (Android_Window && Android_Window->driverdata)
    1.26 +    if (Android_Window)
    1.27      {
    1.28          SDL_VideoDevice *_this = SDL_GetVideoDevice();
    1.29          SDL_WindowData  *data  = (SDL_WindowData *) Android_Window->driverdata;
     2.1 --- a/src/video/android/SDL_androidevents.c	Wed Jan 16 09:22:20 2019 +0100
     2.2 +++ b/src/video/android/SDL_androidevents.c	Wed Jan 16 10:31:51 2019 +0100
     2.3 @@ -59,25 +59,29 @@
     2.4  static void
     2.5  android_egl_context_restore(SDL_Window *window)
     2.6  {
     2.7 -    SDL_Event event;
     2.8 -    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     2.9 -    if (SDL_GL_MakeCurrent(window, (SDL_GLContext) data->egl_context) < 0) {
    2.10 -        /* The context is no longer valid, create a new one */
    2.11 -        data->egl_context = (EGLContext) SDL_GL_CreateContext(window);
    2.12 -        SDL_GL_MakeCurrent(window, (SDL_GLContext) data->egl_context);
    2.13 -        event.type = SDL_RENDER_DEVICE_RESET;
    2.14 -        SDL_PushEvent(&event);
    2.15 +    if (window) {
    2.16 +        SDL_Event event;
    2.17 +        SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    2.18 +        if (SDL_GL_MakeCurrent(window, (SDL_GLContext) data->egl_context) < 0) {
    2.19 +            /* The context is no longer valid, create a new one */
    2.20 +            data->egl_context = (EGLContext) SDL_GL_CreateContext(window);
    2.21 +            SDL_GL_MakeCurrent(window, (SDL_GLContext) data->egl_context);
    2.22 +            event.type = SDL_RENDER_DEVICE_RESET;
    2.23 +            SDL_PushEvent(&event);
    2.24 +        }
    2.25      }
    2.26  }
    2.27  
    2.28  static void
    2.29  android_egl_context_backup(SDL_Window *window)
    2.30  {
    2.31 -    /* Keep a copy of the EGL Context so we can try to restore it when we resume */
    2.32 -    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    2.33 -    data->egl_context = SDL_GL_GetCurrentContext();
    2.34 -    /* We need to do this so the EGLSurface can be freed */
    2.35 -    SDL_GL_MakeCurrent(window, NULL);
    2.36 +    if (window) {
    2.37 +        /* Keep a copy of the EGL Context so we can try to restore it when we resume */
    2.38 +        SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    2.39 +        data->egl_context = SDL_GL_GetCurrentContext();
    2.40 +        /* We need to do this so the EGLSurface can be freed */
    2.41 +        SDL_GL_MakeCurrent(window, NULL);
    2.42 +    }
    2.43  }
    2.44  
    2.45  
    2.46 @@ -93,10 +97,9 @@
    2.47  void
    2.48  Android_PumpEvents(_THIS)
    2.49  {
    2.50 -    static int isPaused = 0;
    2.51 -    static int isPausing = 0;
    2.52 +    SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
    2.53  
    2.54 -    if (isPaused) {
    2.55 +    if (videodata->isPaused) {
    2.56  
    2.57          /* Make sure this is the last thing we do before pausing */
    2.58          SDL_LockMutex(Android_ActivityMutex);
    2.59 @@ -108,7 +111,7 @@
    2.60  
    2.61          if (SDL_SemWait(Android_ResumeSem) == 0) {
    2.62  
    2.63 -            isPaused = 0;
    2.64 +            videodata->isPaused = 0;
    2.65  
    2.66              ANDROIDAUDIO_ResumeDevices();
    2.67              openslES_ResumeDevices();
    2.68 @@ -126,16 +129,16 @@
    2.69              }
    2.70          }
    2.71      } else {
    2.72 -        if (isPausing || SDL_SemTryWait(Android_PauseSem) == 0) {
    2.73 +        if (videodata->isPausing || SDL_SemTryWait(Android_PauseSem) == 0) {
    2.74              /* We've been signaled to pause (potentially several times), but before we block ourselves,
    2.75               * we need to make sure that the very last event (of the first pause sequence, if several)
    2.76               * has reached the app */
    2.77              if (SDL_NumberOfEvents(SDL_APP_DIDENTERBACKGROUND) > SDL_SemValue(Android_PauseSem)) {
    2.78 -                isPausing = 1;
    2.79 +                videodata->isPausing = 1;
    2.80              }
    2.81              else {
    2.82 -                isPausing = 0;
    2.83 -                isPaused = 1;
    2.84 +                videodata->isPausing = 0;
    2.85 +                videodata->isPaused = 1;
    2.86              }
    2.87          }
    2.88      }
    2.89 @@ -146,12 +149,12 @@
    2.90  void
    2.91  Android_PumpEvents(_THIS)
    2.92  {
    2.93 -    static int isPaused = 0;
    2.94 +    SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
    2.95  
    2.96 -    if (isPaused) {
    2.97 +    if (videodata->isPaused) {
    2.98          if (SDL_SemTryWait(Android_ResumeSem) == 0) {
    2.99  
   2.100 -            isPaused = 0;
   2.101 +            videodata->isPaused = 0;
   2.102  
   2.103              ANDROIDAUDIO_ResumeDevices();
   2.104              openslES_ResumeDevices();
   2.105 @@ -178,7 +181,7 @@
   2.106              ANDROIDAUDIO_PauseDevices();
   2.107              openslES_PauseDevices();
   2.108  
   2.109 -            isPaused = 1;
   2.110 +            videodata->isPaused = 1;
   2.111          }
   2.112      }
   2.113  }
     3.1 --- a/src/video/android/SDL_androidvideo.c	Wed Jan 16 09:22:20 2019 +0100
     3.2 +++ b/src/video/android/SDL_androidvideo.c	Wed Jan 16 10:31:51 2019 +0100
     3.3 @@ -172,7 +172,11 @@
     3.4  int
     3.5  Android_VideoInit(_THIS)
     3.6  {
     3.7 -    SDL_DisplayMode mode;
     3.8 +    SDL_VideoData   *videodata = (SDL_VideoData *)_this->driverdata;
     3.9 +    SDL_DisplayMode  mode;
    3.10 +
    3.11 +    videodata->isPaused  = SDL_FALSE;
    3.12 +    videodata->isPausing = SDL_FALSE;
    3.13  
    3.14      mode.format = Android_ScreenFormat;
    3.15      mode.w = Android_DeviceWidth;
     4.1 --- a/src/video/android/SDL_androidvideo.h	Wed Jan 16 09:22:20 2019 +0100
     4.2 +++ b/src/video/android/SDL_androidvideo.h	Wed Jan 16 10:31:51 2019 +0100
     4.3 @@ -34,7 +34,9 @@
     4.4  
     4.5  typedef struct SDL_VideoData
     4.6  {
     4.7 -    SDL_Rect        textRect;
     4.8 +    SDL_Rect textRect;
     4.9 +    int      isPaused;
    4.10 +    int      isPausing;
    4.11  } SDL_VideoData;
    4.12  
    4.13  extern int Android_SurfaceWidth;