Code cleanup
authorPaul Hunkin <paul@bieh.net>
Tue, 29 Jun 2010 01:30:11 +1200
changeset 4712 8319aa8fa4dc
parent 4711 ed040b480a9f
child 4713 ba38983b10c2
Code cleanup
android/testproject/AndroidManifest.xml
android/testproject/jni/Android.mk
android/testproject/jni/app-android.cpp
android/testproject/src/org/libsdl/android/SDLActivity.java
android/testproject/src/org/libsdl/android/TestActivity.java
--- a/android/testproject/AndroidManifest.xml	Tue Jun 29 00:40:12 2010 +1200
+++ b/android/testproject/AndroidManifest.xml	Tue Jun 29 01:30:11 2010 +1200
@@ -4,7 +4,7 @@
       android:versionCode="1"
       android:versionName="1.0">
     <application android:label="@string/app_name" android:icon="@drawable/icon">
-        <activity android:name="TestActivity"
+        <activity android:name="SDLActivity"
                   android:label="@string/app_name">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
--- a/android/testproject/jni/Android.mk	Tue Jun 29 00:40:12 2010 +1200
+++ b/android/testproject/jni/Android.mk	Tue Jun 29 01:30:11 2010 +1200
@@ -2,7 +2,7 @@
 
 include $(CLEAR_VARS)
 
-LOCAL_MODULE := sanangeles
+LOCAL_MODULE := sdltest
 
 SDL := /home/paul/Projects/gsoc/SDL-gsoc2010_android/
 
--- a/android/testproject/jni/app-android.cpp	Tue Jun 29 00:40:12 2010 +1200
+++ b/android/testproject/jni/app-android.cpp	Tue Jun 29 01:30:11 2010 +1200
@@ -41,7 +41,7 @@
                  Functions called by JNI
 *******************************************************************************/	
 
-extern "C" void Java_org_libsdl_android_TestActivity_nativeInit( JNIEnv*  env, jobject obj )
+extern "C" void Java_org_libsdl_android_SDLActivity_nativeInit( JNIEnv*  env, jobject obj )
 {    
 	__android_log_print(ANDROID_LOG_INFO, "SDL", "JNI: NativeInit");
 
@@ -63,7 +63,7 @@
 
     __android_log_print(ANDROID_LOG_INFO, "SDL", "JNI: OnLoad");
 
-    jclass cls = mEnv->FindClass ("org/libsdl/android/TestActivity"); 
+    jclass cls = mEnv->FindClass ("org/libsdl/android/SDLActivity"); 
     mActivityInstance = cls;
     midCreateGLContext = mEnv->GetStaticMethodID(cls,"createGLContext","()V");
     midFlipBuffers = mEnv->GetStaticMethodID(cls,"flipBuffers","()V");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/android/testproject/src/org/libsdl/android/SDLActivity.java	Tue Jun 29 01:30:11 2010 +1200
@@ -0,0 +1,216 @@
+package org.libsdl.android;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+import javax.microedition.khronos.egl.*;
+
+import android.app.Activity;
+import android.content.Context;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+import android.os.Bundle;
+import android.view.MotionEvent;
+import android.util.Log;
+import android.graphics.*;
+
+import java.lang.*;
+
+
+/**
+    SDL Activity
+*/
+public class SDLActivity extends Activity {
+
+    //Main components
+    private static SDLActivity mSingleton;
+    private static SDLSurface mSurface;
+
+    //Load the .so
+    static {
+        System.loadLibrary("sdltest");
+    }
+
+    //Setup
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        
+        //So we can call stuff from static callbacks
+        mSingleton = this;
+
+        //Set up the surface
+        mSurface = new SDLSurface(getApplication());
+        setContentView(mSurface);
+        SurfaceHolder holder = mSurface.getHolder();
+        holder.setType(SurfaceHolder.SURFACE_TYPE_GPU); 
+
+        
+    }
+
+    //Events
+    protected void onPause() {
+        super.onPause();
+    }
+
+    protected void onResume() {
+        super.onResume();
+    }
+
+
+
+
+
+
+    //C functions we call
+    public static native void nativeInit();
+
+
+
+
+
+
+    //Java functions called from C
+    private static void createGLContext(){
+        mSurface.initEGL();
+    }
+
+    public static void flipBuffers(){
+        mSurface.flipEGL();
+    }
+
+
+
+
+
+
+
+    //EGL context creation
+    
+}
+
+/**
+    Simple nativeInit() runnable
+*/
+class SDLRunner implements Runnable{
+    public void run(){
+        //Runs SDL_main()
+        SDLActivity.nativeInit();
+    }
+}
+
+
+/**
+    SDLSurface. This is what we draw on, so we need to know when it's created
+    in order to do anything useful. 
+
+    Because of this, that's where we set up the SDL thread
+*/
+class SDLSurface extends SurfaceView implements SurfaceHolder.Callback{
+
+    //This is what SDL runs in. It invokes SDL_main(), eventually
+    private Thread mSDLThread;    
+    
+    //EGL private objects
+    private EGLContext  mEGLContext;
+    private EGLSurface  mEGLSurface;
+    private EGLDisplay  mEGLDisplay;
+
+    //Startup    
+    public SDLSurface(Context context) {
+        super(context);
+        getHolder().addCallback(this);      
+    }
+
+    //Called when we have a valid drawing surface
+    public void surfaceCreated(SurfaceHolder holder) {
+        Log.v("SDL","Surface created"); 
+
+        mSDLThread = new Thread(new SDLRunner(), "SDLThread"); 
+		mSDLThread.start();       
+    }
+
+    //Called when we lose the surface
+    public void surfaceDestroyed(SurfaceHolder holder) {
+        Log.v("SDL","Surface destroyed");
+    }
+
+    //Called when the surface is resized
+    public void surfaceChanged(SurfaceHolder holder, int format, 
+                                int width, int height) {
+        Log.v("SDL","Surface resized");
+    }
+
+    //unused
+    public void onDraw(Canvas canvas) {}
+
+    
+    //EGL functions
+    public boolean initEGL(){
+        Log.v("SDL","Starting up");
+
+        try{
+
+            EGL10 egl = (EGL10)EGLContext.getEGL();
+
+            EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
+
+            int[] version = new int[2];
+            egl.eglInitialize(dpy, version);
+
+            int[] configSpec = {
+                    //EGL10.EGL_DEPTH_SIZE,   16,
+                    EGL10.EGL_NONE
+            };
+            EGLConfig[] configs = new EGLConfig[1];
+            int[] num_config = new int[1];
+            egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config);
+            EGLConfig config = configs[0];
+
+            EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, null);
+
+            EGLSurface surface = egl.eglCreateWindowSurface(dpy, config, this, null);
+
+            egl.eglMakeCurrent(dpy, surface, surface, ctx);
+
+            mEGLContext = ctx;
+            mEGLDisplay = dpy;
+            mEGLSurface = surface;
+            
+        }catch(Exception e){
+            Log.v("SDL", e + "");
+            for(StackTraceElement s : e.getStackTrace()){
+                Log.v("SDL", s.toString());
+            }
+        }
+
+        Log.v("SDL","Done making!");
+
+        return true;
+    }
+
+    //EGL buffer flip
+    public void flipEGL(){      
+        try{
+        
+            EGL10 egl = (EGL10)EGLContext.getEGL();
+            GL10 gl = (GL10)mEGLContext.getGL();
+
+            egl.eglWaitNative(EGL10.EGL_NATIVE_RENDERABLE, null);
+
+            //drawing here
+
+            egl.eglWaitGL();
+
+            egl.eglSwapBuffers(mEGLDisplay, mEGLSurface);
+
+            
+        }catch(Exception e){
+            Log.v("SDL", "flipEGL(): " + e);
+
+            for(StackTraceElement s : e.getStackTrace()){
+                Log.v("SDL", s.toString());
+            }
+        }
+    }
+}
+
+
--- a/android/testproject/src/org/libsdl/android/TestActivity.java	Tue Jun 29 00:40:12 2010 +1200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,211 +0,0 @@
-package org.libsdl.android;
-
-import javax.microedition.khronos.egl.EGLConfig;
-import javax.microedition.khronos.opengles.GL10;
-import javax.microedition.khronos.egl.*;
-
-import android.app.Activity;
-import android.content.Context;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-import android.os.Bundle;
-import android.view.MotionEvent;
-import android.util.Log;
-import android.graphics.*;
-
-import java.lang.*;
-
-
-//http://www.mail-archive.com/android-beginners@googlegroups.com/msg01830.html
-
-/*
-In TestActivity::onResume() call SDL_Init
-SDL_GL_CreateContext call SDLSurface::createSDLGLContext()
-SDL_GL_FlipBuffers calls SDLSurface::flip()
-
-*/
-
-
-
-public class TestActivity extends Activity {
-
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        mSurface = new SDLSurface(getApplication());
-        setContentView(mSurface);
-        SurfaceHolder holder = mSurface.getHolder();
-        holder.setType(SurfaceHolder.SURFACE_TYPE_GPU); 
-    }
-
-    protected void onPause() {
-        super.onPause();
-    }
-
-    protected void onResume() {
-        super.onResume();
-
-        //All set up. Start up SDL
-       
-       
-    }
-
-    private static SDLSurface mSurface;
-
-    static {
-        System.loadLibrary("sanangeles");
-    }
-
-    //C functions we call
-    public static native void nativeInit();
-
-
-    //Java functions called from C
-    private static void createGLContext(){
-        mSurface.initEGL();
-    }
-
-    public static void flipBuffers(){
-        mSurface.flipBuffers();
-    }
-}
-
-class SDLThread implements Runnable{
-    public void run(){
-        TestActivity.nativeInit();
-    }
-}
-
-class SDLSurface extends SurfaceView implements SurfaceHolder.Callback{
-
-    private EGLContext  mEGLContext;
-    private EGLSurface  mEGLSurface;
-    private EGLDisplay  mEGLDisplay;
-
-    public void surfaceCreated(SurfaceHolder holder) {
-        Log.v("SDL","Surface created"); 
-
-        Thread runner = new Thread(new SDLThread(), "SDLThread"); // (1) Create a new thread.
-		runner.start(); // (2) Start the thread     
-        
-    }
-
-    public void surfaceDestroyed(SurfaceHolder holder) {
-        Log.v("SDL","Surface destroyed");
-    }
-
-    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
-       
-    }
-
-
-    boolean initEGL(){
-        Log.v("SDL","Starting up");
-
-        try{
-
-            // Get an EGL instance
-            EGL10 egl = (EGL10)EGLContext.getEGL();
-
-            // Get to the default display.
-            EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
-
-            // We can now initialize EGL for that display
-            int[] version = new int[2];
-            egl.eglInitialize(dpy, version);
-
-            // Specify a configuration for our opengl session
-            // and grab the first configuration that matches is
-            int[] configSpec = {
-                    //EGL10.EGL_DEPTH_SIZE,   16,
-                    EGL10.EGL_NONE
-            };
-            EGLConfig[] configs = new EGLConfig[1];
-            int[] num_config = new int[1];
-            egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config);
-            EGLConfig config = configs[0];
-
-            // Create an OpenGL ES context. This must be done only once
-            EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, null);
-
-            // Create an EGL surface we can render into.
-            EGLSurface surface = egl.eglCreateWindowSurface(dpy, config, this, null);
-
-            // Before we can issue GL commands, we need to make sure
-            // the context is current and bound to a surface.
-            egl.eglMakeCurrent(dpy, surface, surface, ctx);
-
-            mEGLContext = ctx;
-            mEGLDisplay = dpy;
-            mEGLSurface = surface;
-        }catch(Exception e){
-            Log.v("SDL", e + "");
-        }
-
-        Log.v("SDL","Done making!");
-
-        return true;
-    }
-
-    public SDLSurface(Context context) {
-        super(context);
-
-        getHolder().addCallback(this);
-      
-    }
-
-     public void onDraw(Canvas canvas) {
-
-        
-     }
-
-
-    public void flipBuffers(){
-        //Log.v("test","Draw!");
-
-        try{
-        
-            EGL10 egl = (EGL10)EGLContext.getEGL();
-            GL10 gl = (GL10)mEGLContext.getGL();
-
-            egl.eglWaitNative(EGL10.EGL_NATIVE_RENDERABLE, null);
-
-            //drawing here
-
-            egl.eglWaitGL();
-
-            egl.eglSwapBuffers(mEGLDisplay, mEGLSurface);
-
-            
-        }catch(Exception e){
-            Log.v("SDL", e + "");
-        }
-
-    }
-
-}
-
-
-/*
-class TestRenderer implements GLSurfaceView.Renderer {
-    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
-        nativeInit();
-    }
-
-    
-
-    public void onSurfaceChanged(GL10 gl, int w, int h) {
-        //gl.glViewport(0, 0, w, h);
-        nativeResize(w, h);
-    }
-
-    public void onDrawFrame(GL10 gl) {
-        nativeRender();
-    }
-
-    private static native void nativeInit();
-    private static native void nativeResize(int w, int h);
-    private static native void nativeRender();
-    private static native void nativeDone();
-
-}
-*/