SDL  2.0
SDL_androidevents.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2018 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_internal.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 #if !SDL_AUDIO_DISABLED
33 /* Can't include sysaudio "../../audio/android/SDL_androidaudio.h"
34  * because of THIS redefinition */
35 extern void ANDROIDAUDIO_ResumeDevices(void);
36 extern void ANDROIDAUDIO_PauseDevices(void);
37 #else
38 static void ANDROIDAUDIO_ResumeDevices(void) {}
39 static void ANDROIDAUDIO_PauseDevices(void) {}
40 #endif
41 
42 static void
43 android_egl_context_restore()
44 {
48  /* The context is no longer valid, create a new one */
51  event.type = SDL_RENDER_DEVICE_RESET;
52  SDL_PushEvent(&event);
53  }
54 }
55 
56 static void
57 android_egl_context_backup()
58 {
59  /* Keep a copy of the EGL Context so we can try to restore it when we resume */
62  /* We need to do this so the EGLSurface can be freed */
64 }
65 
66 void
68 {
69  static int isPaused = 0;
70 #if SDL_ANDROID_BLOCK_ON_PAUSE
71  static int isPausing = 0;
72 #endif
73  /* No polling necessary */
74 
75  /*
76  * Android_ResumeSem and Android_PauseSem are signaled from Java_org_libsdl_app_SDLActivity_nativePause and Java_org_libsdl_app_SDLActivity_nativeResume
77  * 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.
78  */
79 
80 #if SDL_ANDROID_BLOCK_ON_PAUSE
81  if (isPaused && !isPausing) {
82  /* Make sure this is the last thing we do before pausing */
83  android_egl_context_backup();
85  if(SDL_SemWait(Android_ResumeSem) == 0) {
86 #else
87  if (isPaused) {
89 #endif
90  isPaused = 0;
92  /* Restore the GL Context from here, as this operation is thread dependent */
93  if (!SDL_HasEvent(SDL_QUIT)) {
94  android_egl_context_restore();
95  }
96  }
97  }
98  else {
99 #if SDL_ANDROID_BLOCK_ON_PAUSE
100  if( isPausing || SDL_SemTryWait(Android_PauseSem) == 0 ) {
101  /* We've been signaled to pause, but before we block ourselves,
102  we need to make sure that certain key events have reached the app */
104  isPausing = 1;
105  }
106  else {
107  isPausing = 0;
108  isPaused = 1;
109  }
110  }
111 #else
112  if(SDL_SemTryWait(Android_PauseSem) == 0) {
113  android_egl_context_backup();
115  isPaused = 1;
116  }
117 #endif
118  }
119 }
120 
121 #endif /* SDL_VIDEO_DRIVER_ANDROID */
122 
123 /* vi: set ts=4 sw=4 expandtab: */
#define SDL_GL_CreateContext
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld [DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp local skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
SDL_sem * Android_PauseSem
void * EGLContext
Definition: egl.h:60
#define SDL_SemTryWait
void * SDL_GLContext
An opaque handle to an OpenGL context.
Definition: SDL_video.h:193
EGLContext egl_context
#define _THIS
struct _cl_event * event
#define SDL_PushEvent
SDL_Window * Android_Window
void Android_PumpEvents(_THIS)
#define NULL
Definition: begin_code.h:164
#define SDL_GL_GetCurrentContext
void ANDROIDAUDIO_ResumeDevices(void)
#define SDL_GL_MakeCurrent
SDL_sem * Android_ResumeSem
#define SDL_HasEvent
#define SDL_SemWait
void ANDROIDAUDIO_PauseDevices(void)
General event structure.
Definition: SDL_events.h:557
void * driverdata
Definition: SDL_sysvideo.h:111