~ubuntu-branches/ubuntu/trusty/libsdl2/trusty-proposed

« back to all changes in this revision

Viewing changes to src/video/android/SDL_androidevents.c

  • Committer: Package Import Robot
  • Author(s): Manuel A. Fernandez Montecelo
  • Date: 2013-12-28 12:31:19 UTC
  • mto: (7.1.3 sid)
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: package-import@ubuntu.com-20131228123119-wehupm72qsjvh6vz
Tags: upstream-2.0.1+dfsg1
ImportĀ upstreamĀ versionĀ 2.0.1+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
#include "SDL_androidevents.h"
29
29
#include "SDL_events.h"
 
30
#include "SDL_androidwindow.h"
 
31
 
 
32
void android_egl_context_backup();
 
33
void android_egl_context_restore();
 
34
 
 
35
void 
 
36
android_egl_context_restore() 
 
37
{
 
38
    SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
 
39
    if (SDL_GL_MakeCurrent(Android_Window, (SDL_GLContext) data->egl_context) < 0) {
 
40
        /* The context is no longer valid, create a new one */
 
41
        /* FIXME: Notify the user that the context changed and textures need to be re created */
 
42
        data->egl_context = (EGLContext) SDL_GL_CreateContext(Android_Window);
 
43
        SDL_GL_MakeCurrent(Android_Window, (SDL_GLContext) data->egl_context);
 
44
    }
 
45
}
 
46
 
 
47
void 
 
48
android_egl_context_backup() 
 
49
{
 
50
    /* Keep a copy of the EGL Context so we can try to restore it when we resume */
 
51
    SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
 
52
    data->egl_context = SDL_GL_GetCurrentContext();
 
53
    /* We need to do this so the EGLSurface can be freed */
 
54
    SDL_GL_MakeCurrent(Android_Window, NULL);
 
55
}
30
56
 
31
57
void
32
58
Android_PumpEvents(_THIS)
46
72
 
47
73
#if SDL_ANDROID_BLOCK_ON_PAUSE
48
74
    if (isPaused && !isPausing) {
 
75
        /* Make sure this is the last thing we do before pausing */
 
76
        android_egl_context_backup();
49
77
        if(SDL_SemWait(Android_ResumeSem) == 0) {
50
78
#else
51
79
    if (isPaused) {
52
80
        if(SDL_SemTryWait(Android_ResumeSem) == 0) {
53
81
#endif
54
82
            isPaused = 0;
55
 
            /* TODO: Should we double check if we are on the same thread as the one that made the original GL context?
56
 
             * This call will go through the following chain of calls in Java:
57
 
             * SDLActivity::createGLContext -> SDLActivity:: initEGL -> SDLActivity::createEGLSurface -> SDLActivity::createEGLContext
58
 
             * SDLActivity::createEGLContext will attempt to restore the GL context first, and if that fails it will create a new one
59
 
             * If a new GL context is created, the user needs to restore the textures manually (TODO: notify the user that this happened with a message)
60
 
             */
61
 
            SDL_GL_CreateContext(Android_Window);
 
83
            
 
84
            /* Restore the GL Context from here, as this operation is thread dependent */
 
85
            android_egl_context_restore();
62
86
        }
63
87
    }
64
88
    else {
65
89
#if SDL_ANDROID_BLOCK_ON_PAUSE
66
90
        if( isPausing || SDL_SemTryWait(Android_PauseSem) == 0 ) {
67
 
            /* We've been signaled to pause, but before we block ourselves, we need to make sure that
68
 
            SDL_WINDOWEVENT_FOCUS_LOST and SDL_WINDOWEVENT_MINIMIZED have reached the app */
69
 
            if (SDL_HasEvent(SDL_WINDOWEVENT)) {
 
91
            /* We've been signaled to pause, but before we block ourselves, 
 
92
            we need to make sure that certain key events have reached the app */
 
93
            if (SDL_HasEvent(SDL_WINDOWEVENT) || SDL_HasEvent(SDL_APP_WILLENTERBACKGROUND) || SDL_HasEvent(SDL_APP_DIDENTERBACKGROUND) ) {
70
94
                isPausing = 1;
71
95
            }
72
96
            else {
76
100
        }
77
101
#else
78
102
        if(SDL_SemTryWait(Android_PauseSem) == 0) {
79
 
            /* If we fall in here, the system is/was paused */
 
103
            android_egl_context_backup();
80
104
            isPaused = 1;
81
105
        }
82
106
#endif