src/video/android/SDL_androidwindow.c
changeset 7659 ac4ce59c40e7
parent 7254 497b83000293
child 7986 ffb7bf531644
--- a/src/video/android/SDL_androidwindow.c	Mon Aug 19 11:02:44 2013 -0400
+++ b/src/video/android/SDL_androidwindow.c	Mon Aug 19 16:29:46 2013 -0300
@@ -29,15 +29,15 @@
 #include "SDL_androidvideo.h"
 #include "SDL_androidwindow.h"
 
-#include "../../core/android/SDL_android.h"
-
 int
 Android_CreateWindow(_THIS, SDL_Window * window)
 {
+    SDL_WindowData *data;
+    
     if (Android_Window) {
         return SDL_SetError("Android only supports one window");
     }
-    Android_Window = window;
+    
     Android_PauseSem = SDL_CreateSemaphore(0);
     Android_ResumeSem = SDL_CreateSemaphore(0);
 
@@ -56,7 +56,29 @@
     /* One window, it always has focus */
     SDL_SetMouseFocus(window);
     SDL_SetKeyboardFocus(window);
+    
+    data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
+    if (!data) {
+        return SDL_OutOfMemory();
+    }
+    
+    data->native_window = Android_JNI_GetNativeWindow();
+    
+    if (!data->native_window) {
+        SDL_free(data);
+        return SDL_SetError("Could not fetch native window");
+    }
+    
+    data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);
 
+    if (data->egl_surface == EGL_NO_SURFACE) {
+        SDL_free(data);
+        return SDL_SetError("Could not create GLES window surface");
+    }
+
+    window->driverdata = data;
+    Android_Window = window;
+    
     return 0;
 }
 
@@ -69,12 +91,23 @@
 void
 Android_DestroyWindow(_THIS, SDL_Window * window)
 {
+    SDL_WindowData *data;
+    
     if (window == Android_Window) {
         Android_Window = NULL;
         if (Android_PauseSem) SDL_DestroySemaphore(Android_PauseSem);
         if (Android_ResumeSem) SDL_DestroySemaphore(Android_ResumeSem);
         Android_PauseSem = NULL;
         Android_ResumeSem = NULL;
+        
+        if(window->driverdata) {
+            data = (SDL_WindowData *) window->driverdata;
+            if(data->native_window) {
+                ANativeWindow_release(data->native_window);
+            }
+            SDL_free(window->driverdata);
+            window->driverdata = NULL;
+        }
     }
 }