Added a way to get the native Android window and EGL context
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
diff --git a/include/SDL_syswm.h b/include/SDL_syswm.h
index 08ce7ad..7da78b8 100644
--- a/include/SDL_syswm.h
+++ b/include/SDL_syswm.h
@@ -98,6 +98,11 @@ typedef struct _UIViewController UIViewController;
#endif
#endif
+#if defined(SDL_VIDEO_DRIVER_ANDROID)
+typedef struct ANativeWindow ANativeWindow;
+typedef void *EGLSurface;
+#endif
+
/**
* These are the various supported windowing subsystems
*/
@@ -111,7 +116,8 @@ typedef enum
SDL_SYSWM_UIKIT,
SDL_SYSWM_WAYLAND,
SDL_SYSWM_MIR,
- SDL_SYSWM_WINRT
+ SDL_SYSWM_WINRT,
+ SDL_SYSWM_ANDROID
} SDL_SYSWM_TYPE;
/**
@@ -225,6 +231,14 @@ struct SDL_SysWMinfo
} mir;
#endif
+#if defined(SDL_VIDEO_DRIVER_ANDROID)
+ struct
+ {
+ ANativeWindow *window;
+ EGLSurface surface;
+ } android;
+#endif
+
/* Can't have an empty union */
int dummy;
} info;
diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c
index f1cf185..0ff6717 100644
--- a/src/video/android/SDL_androidvideo.c
+++ b/src/video/android/SDL_androidvideo.c
@@ -111,6 +111,7 @@ Android_CreateDevice(int devindex)
device->CreateWindow = Android_CreateWindow;
device->SetWindowTitle = Android_SetWindowTitle;
device->DestroyWindow = Android_DestroyWindow;
+ device->GetWindowWMInfo = Android_GetWindowWMInfo;
device->free = Android_DeleteDevice;
diff --git a/src/video/android/SDL_androidwindow.c b/src/video/android/SDL_androidwindow.c
index acbb582..73387fc 100644
--- a/src/video/android/SDL_androidwindow.c
+++ b/src/video/android/SDL_androidwindow.c
@@ -106,7 +106,7 @@ Android_DestroyWindow(_THIS, SDL_Window * window)
if (data->egl_surface != EGL_NO_SURFACE) {
SDL_EGL_DestroySurface(_this, data->egl_surface);
}
- if(data->native_window) {
+ if (data->native_window) {
ANativeWindow_release(data->native_window);
}
SDL_free(window->driverdata);
@@ -115,6 +115,24 @@ Android_DestroyWindow(_THIS, SDL_Window * window)
}
}
+SDL_bool
+Android_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+
+ if (info->version.major == SDL_MAJOR_VERSION &&
+ info->version.minor == SDL_MINOR_VERSION) {
+ info->subsystem = SDL_SYSWM_ANDROID;
+ info->info.android.window = data->native_window;
+ info->info.android.surface = data->egl_surface;
+ return SDL_TRUE;
+ } else {
+ SDL_SetError("Application not compiled with SDL %d.%d\n",
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+ return SDL_FALSE;
+ }
+}
+
#endif /* SDL_VIDEO_DRIVER_ANDROID */
/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/android/SDL_androidwindow.h b/src/video/android/SDL_androidwindow.h
index 8de223a..3ab8c13 100644
--- a/src/video/android/SDL_androidwindow.h
+++ b/src/video/android/SDL_androidwindow.h
@@ -29,6 +29,7 @@
extern int Android_CreateWindow(_THIS, SDL_Window * window);
extern void Android_SetWindowTitle(_THIS, SDL_Window * window);
extern void Android_DestroyWindow(_THIS, SDL_Window * window);
+extern SDL_bool Android_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
typedef struct
{