src/video/android/SDL_androidevents.c
changeset 6469 ce84310d85ef
parent 6330 0fa55ca2efdd
child 6664 2deb17aefbaf
equal deleted inserted replaced
6468:6af2a8db95d0 6469:ce84310d85ef
    21 #include "SDL_config.h"
    21 #include "SDL_config.h"
    22 
    22 
    23 #if SDL_VIDEO_DRIVER_ANDROID
    23 #if SDL_VIDEO_DRIVER_ANDROID
    24 
    24 
    25 #include "SDL_androidevents.h"
    25 #include "SDL_androidevents.h"
       
    26 #include "SDL_events.h"
    26 
    27 
    27 void
    28 void
    28 Android_PumpEvents(_THIS)
    29 Android_PumpEvents(_THIS)
    29 {
    30 {
    30     static int isPaused = 0;
    31     static int isPaused = 0;
       
    32 #if SDL_ANDROID_BLOCK_ON_PAUSE
       
    33     static int isPausing = 0;
       
    34 #endif
    31     /* No polling necessary */
    35     /* No polling necessary */
    32 
    36 
    33     /*
    37     /*
    34      * Android_ResumeSem and Android_PauseSem are signaled from Java_org_libsdl_app_SDLActivity_nativePause and Java_org_libsdl_app_SDLActivity_nativeResume
    38      * Android_ResumeSem and Android_PauseSem are signaled from Java_org_libsdl_app_SDLActivity_nativePause and Java_org_libsdl_app_SDLActivity_nativeResume
    35      * When the pause semaphoe is signaled, if SDL_ANDROID_BLOCK_ON_PAUSE is defined the event loop will block until the resume signal is emitted.
    39      * When the pause semaphoe is signaled, if SDL_ANDROID_BLOCK_ON_PAUSE is defined the event loop will block until the resume signal is emitted.
    36      * When the resume semaphore is signaled, SDL_GL_CreateContext is called which in turn calls Java code
    40      * When the resume semaphore is signaled, SDL_GL_CreateContext is called which in turn calls Java code
    37      * SDLActivity::createGLContext -> SDLActivity:: initEGL -> SDLActivity::createEGLSurface -> SDLActivity::createEGLContext
    41      * SDLActivity::createGLContext -> SDLActivity:: initEGL -> SDLActivity::createEGLSurface -> SDLActivity::createEGLContext
    38      */
    42      */
    39     if (isPaused) {
    43 
    40 #if SDL_ANDROID_BLOCK_ON_PAUSE
    44 #if SDL_ANDROID_BLOCK_ON_PAUSE
       
    45     if (isPaused && !isPausing) {
    41         if(SDL_SemWait(Android_ResumeSem) == 0) {
    46         if(SDL_SemWait(Android_ResumeSem) == 0) {
    42 #else
    47 #else
       
    48     if (isPaused) {
    43         if(SDL_SemTryWait(Android_ResumeSem) == 0) {
    49         if(SDL_SemTryWait(Android_ResumeSem) == 0) {
    44 #endif
    50 #endif
    45             isPaused = 0;
    51             isPaused = 0;
    46             /* TODO: Should we double check if we are on the same thread as the one that made the original GL context?
    52             /* TODO: Should we double check if we are on the same thread as the one that made the original GL context?
    47              * This call will go through the following chain of calls in Java:
    53              * This call will go through the following chain of calls in Java:
    51              */
    57              */
    52             SDL_GL_CreateContext(Android_Window);
    58             SDL_GL_CreateContext(Android_Window);
    53         }
    59         }
    54     }
    60     }
    55     else {
    61     else {
       
    62 #if SDL_ANDROID_BLOCK_ON_PAUSE
       
    63         if( isPausing || SDL_SemTryWait(Android_PauseSem) == 0 ) {
       
    64             /* We've been signaled to pause, but before we block ourselves, we need to make sure that
       
    65             SDL_WINDOWEVENT_FOCUS_LOST and SDL_WINDOWEVENT_MINIMIZED have reached the app */
       
    66             if (SDL_HasEvent(SDL_WINDOWEVENT)) {
       
    67                 isPausing = 1;
       
    68             }
       
    69             else {
       
    70                 isPausing = 0;
       
    71                 isPaused = 1;
       
    72             }
       
    73         }
       
    74 #else
    56         if(SDL_SemTryWait(Android_PauseSem) == 0) {
    75         if(SDL_SemTryWait(Android_PauseSem) == 0) {
    57             /* If we fall in here, the system is/was paused */
    76             /* If we fall in here, the system is/was paused */
    58             isPaused = 1;
    77             isPaused = 1;
    59         }
    78         }
       
    79 #endif
       
    80 
    60     }
    81     }
    61 }
    82 }
    62 
    83 
    63 #endif /* SDL_VIDEO_DRIVER_ANDROID */
    84 #endif /* SDL_VIDEO_DRIVER_ANDROID */
    64 
    85