28
28
#include "SDL_androidevents.h"
29
29
#include "SDL_events.h"
30
#include "SDL_androidwindow.h"
32
void android_egl_context_backup();
33
void android_egl_context_restore();
36
android_egl_context_restore()
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);
48
android_egl_context_backup()
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);
32
58
Android_PumpEvents(_THIS)
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) {
52
80
if(SDL_SemTryWait(Android_ResumeSem) == 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)
61
SDL_GL_CreateContext(Android_Window);
84
/* Restore the GL Context from here, as this operation is thread dependent */
85
android_egl_context_restore();
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) ) {