src/video/android/SDL_androidevents.c
changeset 12703 f6c7e5e03f60
parent 12693 d311fcb8066a
child 12712 66a50635b3e8
equal deleted inserted replaced
12702:0ff5bbe35bf5 12703:f6c7e5e03f60
   128             /* We've been signaled to pause (potentially several times), but before we block ourselves,
   128             /* We've been signaled to pause (potentially several times), but before we block ourselves,
   129              * we need to make sure that the very last event (of the first pause sequence, if several)
   129              * we need to make sure that the very last event (of the first pause sequence, if several)
   130              * has reached the app */
   130              * has reached the app */
   131             if (SDL_NumberOfEvents(SDL_APP_DIDENTERBACKGROUND) > SDL_SemValue(Android_PauseSem)) {
   131             if (SDL_NumberOfEvents(SDL_APP_DIDENTERBACKGROUND) > SDL_SemValue(Android_PauseSem)) {
   132                 videodata->isPausing = 1;
   132                 videodata->isPausing = 1;
   133             }
   133             } else {
   134             else {
       
   135                 videodata->isPausing = 0;
   134                 videodata->isPausing = 0;
   136                 videodata->isPaused = 1;
   135                 videodata->isPaused = 1;
   137             }
   136             }
   138         }
   137         }
   139     }
   138     }
   141 
   140 
   142 void
   141 void
   143 Android_PumpEvents_NonBlocking(_THIS)
   142 Android_PumpEvents_NonBlocking(_THIS)
   144 {
   143 {
   145     SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
   144     SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
       
   145     static int backup_context;
   146 
   146 
   147     if (videodata->isPaused) {
   147     if (videodata->isPaused) {
       
   148 
       
   149         if (backup_context) {
       
   150 
       
   151             SDL_LockMutex(Android_ActivityMutex);
       
   152             android_egl_context_backup(Android_Window);
       
   153             SDL_UnlockMutex(Android_ActivityMutex);
       
   154 
       
   155             ANDROIDAUDIO_PauseDevices();
       
   156             openslES_PauseDevices();
       
   157 
       
   158             backup_context = 0;
       
   159         }
       
   160 
       
   161 
   148         if (SDL_SemTryWait(Android_ResumeSem) == 0) {
   162         if (SDL_SemTryWait(Android_ResumeSem) == 0) {
   149 
   163 
   150             videodata->isPaused = 0;
   164             videodata->isPaused = 0;
   151 
   165 
   152             ANDROIDAUDIO_ResumeDevices();
   166             ANDROIDAUDIO_ResumeDevices();
   163             if (SDL_IsTextInputActive()) {
   177             if (SDL_IsTextInputActive()) {
   164                 Android_StartTextInput(_this); /* Only showTextInput */
   178                 Android_StartTextInput(_this); /* Only showTextInput */
   165             }
   179             }
   166         }
   180         }
   167     } else {
   181     } else {
   168         if (SDL_SemTryWait(Android_PauseSem) == 0) {
   182         if (videodata->isPausing || SDL_SemTryWait(Android_PauseSem) == 0) {
   169 
   183             /* We've been signaled to pause (potentially several times), but before we block ourselves,
   170             SDL_LockMutex(Android_ActivityMutex);
   184              * we need to make sure that the very last event (of the first pause sequence, if several)
   171             android_egl_context_backup(Android_Window);
   185              * has reached the app */
   172             SDL_UnlockMutex(Android_ActivityMutex);
   186             if (SDL_NumberOfEvents(SDL_APP_DIDENTERBACKGROUND) > SDL_SemValue(Android_PauseSem)) {
   173 
   187                 videodata->isPausing = 1;
   174             ANDROIDAUDIO_PauseDevices();
   188             } else {
   175             openslES_PauseDevices();
   189                 videodata->isPausing = 0;
   176 
   190                 videodata->isPaused = 1;
   177             videodata->isPaused = 1;
   191                 backup_context = 1;
       
   192             }
   178         }
   193         }
   179     }
   194     }
   180 }
   195 }
   181 
   196 
   182 #endif /* SDL_VIDEO_DRIVER_ANDROID */
   197 #endif /* SDL_VIDEO_DRIVER_ANDROID */