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 8799e2fd743d84ea
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
     1.1 --- a/include/SDL_syswm.h	Mon Jun 02 09:01:10 2014 -0700
     1.2 +++ b/include/SDL_syswm.h	Mon Jun 02 09:01:26 2014 -0700
     1.3 @@ -98,6 +98,11 @@
     1.4  #endif
     1.5  #endif
     1.6  
     1.7 +#if defined(SDL_VIDEO_DRIVER_ANDROID)
     1.8 +typedef struct ANativeWindow ANativeWindow;
     1.9 +typedef void *EGLSurface;
    1.10 +#endif
    1.11 +
    1.12  /**
    1.13   *  These are the various supported windowing subsystems
    1.14   */
    1.15 @@ -111,7 +116,8 @@
    1.16      SDL_SYSWM_UIKIT,
    1.17      SDL_SYSWM_WAYLAND,
    1.18      SDL_SYSWM_MIR,
    1.19 -    SDL_SYSWM_WINRT
    1.20 +    SDL_SYSWM_WINRT,
    1.21 +    SDL_SYSWM_ANDROID
    1.22  } SDL_SYSWM_TYPE;
    1.23  
    1.24  /**
    1.25 @@ -225,6 +231,14 @@
    1.26          } mir;
    1.27  #endif
    1.28  
    1.29 +#if defined(SDL_VIDEO_DRIVER_ANDROID)
    1.30 +        struct
    1.31 +        {
    1.32 +            ANativeWindow *window;
    1.33 +            EGLSurface surface;
    1.34 +        } android;
    1.35 +#endif
    1.36 +
    1.37          /* Can't have an empty union */
    1.38          int dummy;
    1.39      } info;
     2.1 --- a/src/video/android/SDL_androidvideo.c	Mon Jun 02 09:01:10 2014 -0700
     2.2 +++ b/src/video/android/SDL_androidvideo.c	Mon Jun 02 09:01:26 2014 -0700
     2.3 @@ -111,6 +111,7 @@
     2.4      device->CreateWindow = Android_CreateWindow;
     2.5      device->SetWindowTitle = Android_SetWindowTitle;
     2.6      device->DestroyWindow = Android_DestroyWindow;
     2.7 +    device->GetWindowWMInfo = Android_GetWindowWMInfo;
     2.8  
     2.9      device->free = Android_DeleteDevice;
    2.10  
     3.1 --- a/src/video/android/SDL_androidwindow.c	Mon Jun 02 09:01:10 2014 -0700
     3.2 +++ b/src/video/android/SDL_androidwindow.c	Mon Jun 02 09:01:26 2014 -0700
     3.3 @@ -106,7 +106,7 @@
     3.4              if (data->egl_surface != EGL_NO_SURFACE) {
     3.5                  SDL_EGL_DestroySurface(_this, data->egl_surface);
     3.6              }
     3.7 -            if(data->native_window) {
     3.8 +            if (data->native_window) {
     3.9                  ANativeWindow_release(data->native_window);
    3.10              }
    3.11              SDL_free(window->driverdata);
    3.12 @@ -115,6 +115,24 @@
    3.13      }
    3.14  }
    3.15  
    3.16 +SDL_bool
    3.17 +Android_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
    3.18 +{
    3.19 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    3.20 +
    3.21 +    if (info->version.major == SDL_MAJOR_VERSION &&
    3.22 +        info->version.minor == SDL_MINOR_VERSION) {
    3.23 +        info->subsystem = SDL_SYSWM_ANDROID;
    3.24 +        info->info.android.window = data->native_window;
    3.25 +        info->info.android.surface = data->egl_surface;
    3.26 +        return SDL_TRUE;
    3.27 +    } else {
    3.28 +        SDL_SetError("Application not compiled with SDL %d.%d\n",
    3.29 +                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
    3.30 +        return SDL_FALSE;
    3.31 +    }
    3.32 +}
    3.33 +
    3.34  #endif /* SDL_VIDEO_DRIVER_ANDROID */
    3.35  
    3.36  /* vi: set ts=4 sw=4 expandtab: */
     4.1 --- a/src/video/android/SDL_androidwindow.h	Mon Jun 02 09:01:10 2014 -0700
     4.2 +++ b/src/video/android/SDL_androidwindow.h	Mon Jun 02 09:01:26 2014 -0700
     4.3 @@ -29,6 +29,7 @@
     4.4  extern int Android_CreateWindow(_THIS, SDL_Window * window);
     4.5  extern void Android_SetWindowTitle(_THIS, SDL_Window * window);
     4.6  extern void Android_DestroyWindow(_THIS, SDL_Window * window);
     4.7 +extern SDL_bool Android_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
     4.8  
     4.9  typedef struct
    4.10  {