Make SDL_VIDEO_OPENGL_EGL optional on Android
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index c3815d1..dba9e5f 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -1009,6 +1009,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv *env, j
{
SDL_LockMutex(Android_ActivityMutex);
+#if SDL_VIDEO_OPENGL_EGL
if (Android_Window)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
@@ -1021,6 +1022,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv *env, j
/* GL Context handling is done in the event loop because this function is run from the Java thread */
}
+#endif
SDL_UnlockMutex(Android_ActivityMutex);
}
@@ -1051,10 +1053,12 @@ retry:
}
}
+#if SDL_VIDEO_OPENGL_EGL
if (data->egl_surface != EGL_NO_SURFACE) {
SDL_EGL_DestroySurface(_this, data->egl_surface);
data->egl_surface = EGL_NO_SURFACE;
}
+#endif
if (data->native_window) {
ANativeWindow_release(data->native_window);
diff --git a/src/video/android/SDL_androidevents.c b/src/video/android/SDL_androidevents.c
index 23a5bf5..3424a82 100644
--- a/src/video/android/SDL_androidevents.c
+++ b/src/video/android/SDL_androidevents.c
@@ -67,6 +67,7 @@ SDL_NumberOfEvents(Uint32 type)
return SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, type, type);
}
+#if SDL_VIDEO_OPENGL_EGL
static void
android_egl_context_restore(SDL_Window *window)
{
@@ -96,7 +97,7 @@ android_egl_context_backup(SDL_Window *window)
data->backup_done = 1;
}
}
-
+#endif
/*
* Android_ResumeSem and Android_PauseSem are signaled from Java_org_libsdl_app_SDLActivity_nativePause and Java_org_libsdl_app_SDLActivity_nativeResume
@@ -113,12 +114,14 @@ Android_PumpEvents_Blocking(_THIS)
if (videodata->isPaused) {
SDL_bool isContextExternal = SDL_IsVideoContextExternal();
+#if SDL_VIDEO_OPENGL_EGL
/* Make sure this is the last thing we do before pausing */
if (!isContextExternal) {
SDL_LockMutex(Android_ActivityMutex);
android_egl_context_backup(Android_Window);
SDL_UnlockMutex(Android_ActivityMutex);
}
+#endif
ANDROIDAUDIO_PauseDevices();
openslES_PauseDevices();
@@ -138,11 +141,13 @@ Android_PumpEvents_Blocking(_THIS)
aaudio_ResumeDevices();
/* Restore the GL Context from here, as this operation is thread dependent */
+#if SDL_VIDEO_OPENGL_EGL
if (!isContextExternal && !SDL_HasEvent(SDL_QUIT)) {
SDL_LockMutex(Android_ActivityMutex);
android_egl_context_restore(Android_Window);
SDL_UnlockMutex(Android_ActivityMutex);
}
+#endif
/* Make sure SW Keyboard is restored when an app becomes foreground */
if (SDL_IsTextInputActive()) {
@@ -188,11 +193,13 @@ Android_PumpEvents_NonBlocking(_THIS)
SDL_bool isContextExternal = SDL_IsVideoContextExternal();
if (backup_context) {
+#if SDL_VIDEO_OPENGL_EGL
if (!isContextExternal) {
SDL_LockMutex(Android_ActivityMutex);
android_egl_context_backup(Android_Window);
SDL_UnlockMutex(Android_ActivityMutex);
}
+#endif
if (videodata->pauseAudio) {
ANDROIDAUDIO_PauseDevices();
@@ -219,12 +226,14 @@ Android_PumpEvents_NonBlocking(_THIS)
aaudio_ResumeDevices();
}
+#if SDL_VIDEO_OPENGL_EGL
/* Restore the GL Context from here, as this operation is thread dependent */
if (!isContextExternal && !SDL_HasEvent(SDL_QUIT)) {
SDL_LockMutex(Android_ActivityMutex);
android_egl_context_restore(Android_Window);
SDL_UnlockMutex(Android_ActivityMutex);
}
+#endif
/* Make sure SW Keyboard is restored when an app becomes foreground */
if (SDL_IsTextInputActive()) {
diff --git a/src/video/android/SDL_androidgl.c b/src/video/android/SDL_androidgl.c
index 698b871..fe1b17b 100644
--- a/src/video/android/SDL_androidgl.c
+++ b/src/video/android/SDL_androidgl.c
@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
-#if SDL_VIDEO_DRIVER_ANDROID
+#if SDL_VIDEO_DRIVER_ANDROID && SDL_VIDEO_OPENGL_EGL
/* Android SDL video driver implementation */
diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c
index 3301929..61b9a87 100644
--- a/src/video/android/SDL_androidvideo.c
+++ b/src/video/android/SDL_androidvideo.c
@@ -128,6 +128,7 @@ Android_CreateDevice(int devindex)
device->free = Android_DeleteDevice;
/* GL pointers */
+#if SDL_VIDEO_OPENGL_EGL
device->GL_LoadLibrary = Android_GLES_LoadLibrary;
device->GL_GetProcAddress = Android_GLES_GetProcAddress;
device->GL_UnloadLibrary = Android_GLES_UnloadLibrary;
@@ -137,6 +138,7 @@ Android_CreateDevice(int devindex)
device->GL_GetSwapInterval = Android_GLES_GetSwapInterval;
device->GL_SwapWindow = Android_GLES_SwapWindow;
device->GL_DeleteContext = Android_GLES_DeleteContext;
+#endif
#if SDL_VIDEO_VULKAN
device->Vulkan_LoadLibrary = Android_Vulkan_LoadLibrary;
diff --git a/src/video/android/SDL_androidwindow.c b/src/video/android/SDL_androidwindow.c
index c8e4533..c5f8919 100644
--- a/src/video/android/SDL_androidwindow.c
+++ b/src/video/android/SDL_androidwindow.c
@@ -81,6 +81,7 @@ Android_CreateWindow(_THIS, SDL_Window * window)
/* Do not create EGLSurface for Vulkan window since it will then make the window
incompatible with vkCreateAndroidSurfaceKHR */
+#if SDL_VIDEO_OPENGL_EGL
if ((window->flags & SDL_WINDOW_OPENGL) != 0) {
data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);
@@ -91,6 +92,7 @@ Android_CreateWindow(_THIS, SDL_Window * window)
goto endfunction;
}
}
+#endif
window->driverdata = data;
Android_Window = window;
@@ -175,9 +177,13 @@ Android_DestroyWindow(_THIS, SDL_Window *window)
if (window->driverdata) {
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+
+#if SDL_VIDEO_OPENGL_EGL
if (data->egl_surface != EGL_NO_SURFACE) {
SDL_EGL_DestroySurface(_this, data->egl_surface);
}
+#endif
+
if (data->native_window) {
ANativeWindow_release(data->native_window);
}
@@ -198,7 +204,11 @@ Android_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
info->version.minor == SDL_MINOR_VERSION) {
info->subsystem = SDL_SYSWM_ANDROID;
info->info.android.window = data->native_window;
+
+#if SDL_VIDEO_OPENGL_EGL
info->info.android.surface = data->egl_surface;
+#endif
+
return SDL_TRUE;
} else {
SDL_SetError("Application not compiled with SDL %d.%d",
diff --git a/src/video/android/SDL_androidwindow.h b/src/video/android/SDL_androidwindow.h
index efda303..e78d506 100644
--- a/src/video/android/SDL_androidwindow.h
+++ b/src/video/android/SDL_androidwindow.h
@@ -37,8 +37,10 @@ extern SDL_Window *Android_Window;
typedef struct
{
+#if SDL_VIDEO_OPENGL_EGL
EGLSurface egl_surface;
EGLContext egl_context; /* We use this to preserve the context when losing focus */
+#endif
SDL_bool backup_done;
ANativeWindow *native_window;