zenilib: zenilib/jni/external/sdl/src/video/android/SDL_androidevents.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_androidevents.c
Go to the documentation of this file.
1 /*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "SDL_config.h"
22
23 #if SDL_VIDEO_DRIVER_ANDROID
24
25 /* We're going to do this by default */
26 #define SDL_ANDROID_BLOCK_ON_PAUSE 1
27
28 #include "SDL_androidevents.h"
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 }
56
57 void
58 Android_PumpEvents(_THIS)
59 {
60 static int isPaused = 0;
61 #if SDL_ANDROID_BLOCK_ON_PAUSE
62 static int isPausing = 0;
63 #endif
64 /* No polling necessary */
65
66 /*
67 * Android_ResumeSem and Android_PauseSem are signaled from Java_org_libsdl_app_SDLActivity_nativePause and Java_org_libsdl_app_SDLActivity_nativeResume
68 * When the pause semaphore is signaled, if SDL_ANDROID_BLOCK_ON_PAUSE is defined the event loop will block until the resume signal is emitted.
69 * When the resume semaphore is signaled, SDL_GL_CreateContext is called which in turn calls Java code
70 * SDLActivity::createGLContext -> SDLActivity:: initEGL -> SDLActivity::createEGLSurface -> SDLActivity::createEGLContext
71 */
72
73 #if SDL_ANDROID_BLOCK_ON_PAUSE
74 if (isPaused && !isPausing) {
75 if(SDL_SemWait(Android_ResumeSem) == 0) {
76 #else
77 if (isPaused) {
78 if(SDL_SemTryWait(Android_ResumeSem) == 0) {
79 #endif
80 isPaused = 0;
81
82 /* Restore the GL Context from here, as this operation is thread dependent */
83 android_egl_context_restore();
84 }
85 }
86 else {
87 #if SDL_ANDROID_BLOCK_ON_PAUSE
88 if( isPausing || SDL_SemTryWait(Android_PauseSem) == 0 ) {
89 /* We've been signaled to pause, but before we block ourselves,
90 we need to make sure that certain key events have reached the app */
91 if (SDL_HasEvent(SDL_WINDOWEVENT) || SDL_HasEvent(SDL_APP_WILLENTERBACKGROUND) || SDL_HasEvent(SDL_APP_DIDENTERBACKGROUND) ) {
92 isPausing = 1;
93 }
94 else {
95 android_egl_context_backup();
96 isPausing = 0;
97 isPaused = 1;
98 }
99 }
100 #else
101 if(SDL_SemTryWait(Android_PauseSem) == 0) {
102 android_egl_context_backup();
103 isPaused = 1;
104 }
105 #endif
106 }
107 }
108
109 #endif /* SDL_VIDEO_DRIVER_ANDROID */
110
111 /* vi: set ts=4 sw=4 expandtab: */
SDL_androidwindow.h
SDL_SemTryWait
DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem *sem)
Definition: SDL_syssem.c:130
SDL_androidevents.h
NULL
#define NULL
Definition: ftobjs.h:61
SDL_GL_CreateContext
DECLSPEC SDL_GLContext SDLCALL SDL_GL_CreateContext(SDL_Window *window)
Create an OpenGL context for use with an OpenGL window, and make it current.
Definition: SDL_video.c:2758
SDL_SemWait
DECLSPEC int SDLCALL SDL_SemWait(SDL_sem *sem)
Definition: SDL_syssem.c:180
SDL_events.h
SDL_GLContext
void * SDL_GLContext
An opaque handle to an OpenGL context.
Definition: SDL_video.h:161
if
if(!yyg->yy_init)
Definition: glslang_lex.cpp:1037
SDL_config.h
SDL_WindowData
Definition: SDL_androidwindow.h:33
Android_PauseSem
SDL_sem * Android_PauseSem
EGLContext
void * EGLContext
Definition: egl.h:47
SDL_GL_MakeCurrent
DECLSPEC int SDLCALL SDL_GL_MakeCurrent(SDL_Window *window, SDL_GLContext context)
Set up an OpenGL context for rendering into an OpenGL window.
Definition: SDL_video.c:2781
SDL_WindowData::egl_context
EGLContext egl_context
Definition: SDL_androidwindow.h:36
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
Android_Window
SDL_Window * Android_Window
Android_PumpEvents
void Android_PumpEvents(_THIS)
SDL_WINDOWEVENT
Definition: SDL_events.h:89
SDL_HasEvent
DECLSPEC SDL_bool SDLCALL SDL_HasEvent(Uint32 type)
Definition: SDL_events.c:346
Android_ResumeSem
SDL_sem * Android_ResumeSem
SDL_APP_WILLENTERBACKGROUND
Definition: SDL_events.h:71
SDL_Window::driverdata
void * driverdata
Definition: SDL_sysvideo.h:99
SDL_APP_DIDENTERBACKGROUND
Definition: SDL_events.h:75
SDL_GL_GetCurrentContext
DECLSPEC SDL_GLContext SDLCALL SDL_GL_GetCurrentContext(void)
Get the currently active OpenGL context.
Definition: SDL_video.c:2822