annotate android/testproject/jni/app-android.cpp @ 4712:8319aa8fa4dc

Code cleanup
author Paul Hunkin <paul@bieh.net>
date Tue, 29 Jun 2010 01:30:11 +1200
parents ed040b480a9f
children ba38983b10c2
rev   line source
4711
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
1 /*******************************************************************************
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
2 Headers
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
3 *******************************************************************************/
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
4 #include <jni.h>
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
5 #include <sys/time.h>
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
6 #include <time.h>
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
7 #include <android/log.h>
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
8 #include <stdint.h>
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
9
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
10 #include <stdio.h>
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
11 #include <stdlib.h>
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
12 #include <math.h>
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
13
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
14 #include <pthread.h>
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
15
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
16 #include "importgl.h"
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
17 #include "egl.h"
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
18
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
19 /*******************************************************************************
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
20 Globals
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
21 *******************************************************************************/
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
22 static long _getTime(void){
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
23 struct timeval now;
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
24 gettimeofday(&now, NULL);
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
25 return (long)(now.tv_sec*1000 + now.tv_usec/1000);
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
26 }
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
27
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
28 JNIEnv* mEnv = NULL;
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
29 JavaVM* mVM = NULL;
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
30
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
31 //Main activity
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
32 jclass mActivityInstance;
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
33
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
34 //method signatures
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
35 jmethodID midCreateGLContext;
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
36 jmethodID midFlipBuffers;
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
37
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
38 extern "C" int SDL_main();
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
39
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
40 /*******************************************************************************
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
41 Functions called by JNI
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
42 *******************************************************************************/
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
43
4712
8319aa8fa4dc Code cleanup
Paul Hunkin <paul@bieh.net>
parents: 4711
diff changeset
44 extern "C" void Java_org_libsdl_android_SDLActivity_nativeInit( JNIEnv* env, jobject obj )
4711
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
45 {
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
46 __android_log_print(ANDROID_LOG_INFO, "SDL", "JNI: NativeInit");
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
47
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
48 mEnv = env;
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
49
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
50 SDL_main();
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
51 }
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
52
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
53 extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
54 {
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
55 JNIEnv* env = NULL;
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
56 jint result = -1;
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
57
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
58 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
59 return result;
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
60 }
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
61
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
62 mEnv = env;
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
63
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
64 __android_log_print(ANDROID_LOG_INFO, "SDL", "JNI: OnLoad");
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
65
4712
8319aa8fa4dc Code cleanup
Paul Hunkin <paul@bieh.net>
parents: 4711
diff changeset
66 jclass cls = mEnv->FindClass ("org/libsdl/android/SDLActivity");
4711
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
67 mActivityInstance = cls;
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
68 midCreateGLContext = mEnv->GetStaticMethodID(cls,"createGLContext","()V");
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
69 midFlipBuffers = mEnv->GetStaticMethodID(cls,"flipBuffers","()V");
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
70
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
71 if(!midCreateGLContext || !midFlipBuffers){
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
72 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Bad mids\n");
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
73 }else{
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
74 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Good mids\n");
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
75 }
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
76
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
77 return JNI_VERSION_1_4;
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
78 }
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
79
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
80
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
81
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
82 /*******************************************************************************
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
83 Functions called by SDL
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
84 *******************************************************************************/
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
85 extern "C" void sdl_create_context(){
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
86 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: sdl_create_context()\n");
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
87
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
88 mEnv->CallStaticVoidMethod(mActivityInstance, midCreateGLContext );
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
89 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: sdl_create_context() return\n");
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
90
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
91 // exit(1);
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
92 }
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
93
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
94 extern "C" void sdl_render(){
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
95
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
96 //When we get here, we've accumulated a full frame
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
97 //__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: sdl_render()");
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
98
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
99 mEnv->CallStaticVoidMethod(mActivityInstance, midFlipBuffers );
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
100 }
ed040b480a9f - Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
101