Added a way to get the native Android window and EGL context
authorSam Lantinga <slouken@libsdl.org>
Mon, 02 Jun 2014 09:01:26 -0700
changeset 8799 e2fd743d84ea
parent 8798 2703c0c19f45
child 8800 0d406d07509b
Added a way to get the native Android window and EGL context
include/SDL_syswm.h
src/video/android/SDL_androidvideo.c
src/video/android/SDL_androidwindow.c
src/video/android/SDL_androidwindow.h
--- a/include/SDL_syswm.h	Mon Jun 02 09:01:10 2014 -0700
+++ b/include/SDL_syswm.h	Mon Jun 02 09:01:26 2014 -0700
@@ -98,6 +98,11 @@
 #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 @@
     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 @@
         } mir;
 #endif
 
+#if defined(SDL_VIDEO_DRIVER_ANDROID)
+        struct
+        {
+            ANativeWindow *window;
+            EGLSurface surface;
+        } android;
+#endif
+
         /* Can't have an empty union */
         int dummy;
     } info;
--- a/src/video/android/SDL_androidvideo.c	Mon Jun 02 09:01:10 2014 -0700
+++ b/src/video/android/SDL_androidvideo.c	Mon Jun 02 09:01:26 2014 -0700
@@ -111,6 +111,7 @@
     device->CreateWindow = Android_CreateWindow;
     device->SetWindowTitle = Android_SetWindowTitle;
     device->DestroyWindow = Android_DestroyWindow;
+    device->GetWindowWMInfo = Android_GetWindowWMInfo;
 
     device->free = Android_DeleteDevice;
 
--- a/src/video/android/SDL_androidwindow.c	Mon Jun 02 09:01:10 2014 -0700
+++ b/src/video/android/SDL_androidwindow.c	Mon Jun 02 09:01:26 2014 -0700
@@ -106,7 +106,7 @@
             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 @@
     }
 }
 
+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: */
--- a/src/video/android/SDL_androidwindow.h	Mon Jun 02 09:01:10 2014 -0700
+++ b/src/video/android/SDL_androidwindow.h	Mon Jun 02 09:01:26 2014 -0700
@@ -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
 {