android/testproject/jni/app-android.cpp
changeset 4711 ed040b480a9f
child 4712 8319aa8fa4dc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/android/testproject/jni/app-android.cpp	Tue Jun 29 00:40:12 2010 +1200
     1.3 @@ -0,0 +1,101 @@
     1.4 +/*******************************************************************************
     1.5 +                               Headers
     1.6 +*******************************************************************************/
     1.7 +#include <jni.h>
     1.8 +#include <sys/time.h>
     1.9 +#include <time.h>
    1.10 +#include <android/log.h>
    1.11 +#include <stdint.h>
    1.12 +
    1.13 +#include <stdio.h>
    1.14 +#include <stdlib.h>
    1.15 +#include <math.h>
    1.16 +
    1.17 +#include <pthread.h>
    1.18 +
    1.19 +#include "importgl.h"
    1.20 +#include "egl.h"
    1.21 +
    1.22 +/*******************************************************************************
    1.23 +                               Globals
    1.24 +*******************************************************************************/
    1.25 +static long _getTime(void){
    1.26 +	struct timeval  now;
    1.27 +	gettimeofday(&now, NULL);
    1.28 +	return (long)(now.tv_sec*1000 + now.tv_usec/1000);
    1.29 +}
    1.30 +
    1.31 +JNIEnv* mEnv = NULL;
    1.32 +JavaVM* mVM = NULL;
    1.33 +
    1.34 +//Main activity
    1.35 +jclass mActivityInstance;
    1.36 +
    1.37 +//method signatures
    1.38 +jmethodID midCreateGLContext;
    1.39 +jmethodID midFlipBuffers;
    1.40 +
    1.41 +extern "C" int SDL_main();
    1.42 +
    1.43 +/*******************************************************************************
    1.44 +                 Functions called by JNI
    1.45 +*******************************************************************************/	
    1.46 +
    1.47 +extern "C" void Java_org_libsdl_android_TestActivity_nativeInit( JNIEnv*  env, jobject obj )
    1.48 +{    
    1.49 +	__android_log_print(ANDROID_LOG_INFO, "SDL", "JNI: NativeInit");
    1.50 +
    1.51 +	mEnv = env;
    1.52 +
    1.53 +    SDL_main();
    1.54 +}
    1.55 +
    1.56 +extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
    1.57 +{
    1.58 +    JNIEnv* env = NULL;
    1.59 +    jint result = -1;
    1.60 +
    1.61 +    if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
    1.62 +        return result;
    1.63 +    }
    1.64 +
    1.65 +    mEnv = env;
    1.66 +
    1.67 +    __android_log_print(ANDROID_LOG_INFO, "SDL", "JNI: OnLoad");
    1.68 +
    1.69 +    jclass cls = mEnv->FindClass ("org/libsdl/android/TestActivity"); 
    1.70 +    mActivityInstance = cls;
    1.71 +    midCreateGLContext = mEnv->GetStaticMethodID(cls,"createGLContext","()V");
    1.72 +    midFlipBuffers = mEnv->GetStaticMethodID(cls,"flipBuffers","()V");
    1.73 +
    1.74 +    if(!midCreateGLContext || !midFlipBuffers){
    1.75 +        __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Bad mids\n");
    1.76 +    }else{
    1.77 +        __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Good mids\n");
    1.78 +    }
    1.79 +    
    1.80 +    return JNI_VERSION_1_4;
    1.81 +}
    1.82 +
    1.83 +
    1.84 +
    1.85 +/*******************************************************************************
    1.86 +                 Functions called by SDL
    1.87 +*******************************************************************************/
    1.88 +extern "C" void sdl_create_context(){
    1.89 +	__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: sdl_create_context()\n");
    1.90 +
    1.91 +    mEnv->CallStaticVoidMethod(mActivityInstance, midCreateGLContext ); 
    1.92 +    __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: sdl_create_context() return\n");
    1.93 +
    1.94 +   // exit(1);
    1.95 +}
    1.96 +
    1.97 +extern "C" void sdl_render(){
    1.98 +
    1.99 +    //When we get here, we've accumulated a full frame
   1.100 +   //__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: sdl_render()");
   1.101 +    
   1.102 +    mEnv->CallStaticVoidMethod(mActivityInstance, midFlipBuffers ); 
   1.103 +}
   1.104 +