annotate android/testproject/jni/app-android.c @ 4706:12c9d4532b49

Testing out pthread support in android. Appears to work.
author Paul Hunkin <paul@bieh.net>
date Fri, 18 Jun 2010 00:02:13 +1200
parents 190f043af37d
children f3f65cb6a382
rev   line source
4704
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
1 /*******************************************************************************
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
2 Headers
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
3 *******************************************************************************/
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
4 #include <jni.h>
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
5 #include <sys/time.h>
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
6 #include <time.h>
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
7 #include <android/log.h>
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
8 #include <stdint.h>
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
9
4705
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
10 #include <stdio.h>
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
11 #include <stdlib.h>
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
12 #include <math.h>
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
13
4706
12c9d4532b49 Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents: 4705
diff changeset
14 #include <pthread.h>
12c9d4532b49 Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents: 4705
diff changeset
15
4705
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
16 #include "importgl.h"
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
17
4704
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
18 /*******************************************************************************
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
19 Globals
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
20 *******************************************************************************/
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
21 int gAppAlive = 1;
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
22
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
23 static int sWindowWidth = 320;
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
24 static int sWindowHeight = 480;
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
25 static int sDemoStopped = 0;
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
26
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
27 static long _getTime(void){
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
28 struct timeval now;
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
29 gettimeofday(&now, NULL);
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
30 return (long)(now.tv_sec*1000 + now.tv_usec/1000);
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
31 }
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
32
4705
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
33
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
34
4706
12c9d4532b49 Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents: 4705
diff changeset
35 /*******************************************************************************
12c9d4532b49 Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents: 4705
diff changeset
36 SDL thread
12c9d4532b49 Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents: 4705
diff changeset
37 *******************************************************************************/
12c9d4532b49 Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents: 4705
diff changeset
38 pthread_t mSDLThread = 0;
12c9d4532b49 Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents: 4705
diff changeset
39
12c9d4532b49 Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents: 4705
diff changeset
40 void* sdlThreadProc(void* args){
12c9d4532b49 Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents: 4705
diff changeset
41 __android_log_print(ANDROID_LOG_INFO, "SDL", "Thread Entry");
12c9d4532b49 Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents: 4705
diff changeset
42 return 0;
4705
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
43 }
4706
12c9d4532b49 Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents: 4705
diff changeset
44
4704
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
45 /*******************************************************************************
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
46 Initialize the graphics state
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
47 *******************************************************************************/
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
48 void Java_org_libsdl_android_TestRenderer_nativeInit( JNIEnv* env )
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
49 {
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
50 importGLInit();
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
51
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
52 gAppAlive = 1;
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
53 sDemoStopped = 0;
4705
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
54
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
55 __android_log_print(ANDROID_LOG_INFO, "SDL", "Entry point");
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
56
4706
12c9d4532b49 Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents: 4705
diff changeset
57 //Spin up the SDL thread
12c9d4532b49 Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents: 4705
diff changeset
58 int r = pthread_create(&mSDLThread, NULL, sdlThreadProc, NULL);
4705
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
59
4706
12c9d4532b49 Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents: 4705
diff changeset
60 if(r != 0){
12c9d4532b49 Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents: 4705
diff changeset
61 __android_log_print(ANDROID_LOG_INFO, "SDL", "Couldn't spawn thread: %d", r);
12c9d4532b49 Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents: 4705
diff changeset
62 }else{
12c9d4532b49 Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents: 4705
diff changeset
63 __android_log_print(ANDROID_LOG_INFO, "SDL", "Started SDL thread");
12c9d4532b49 Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents: 4705
diff changeset
64 }
4705
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
65
4704
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
66 }
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
67
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
68 /*******************************************************************************
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
69 Resize
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
70 *******************************************************************************/
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
71 void Java_org_libsdl_android_TestRenderer_nativeResize( JNIEnv* env,
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
72 jobject thiz,
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
73 jint w,
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
74 jint h )
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
75 {
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
76 sWindowWidth = w;
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
77 sWindowHeight = h;
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
78 __android_log_print(ANDROID_LOG_INFO, "SDL", "resize w=%d h=%d", w, h);
4705
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
79
4704
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
80 }
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
81
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
82 /*******************************************************************************
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
83 Finalize (ie: shutdown)
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
84 *******************************************************************************/
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
85 void Java_org_libsdl_android_TestRenderer_nativeDone( JNIEnv* env )
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
86 {
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
87
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
88 //shut down the app
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
89
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
90 importGLDeinit();
4705
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
91
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
92 __android_log_print(ANDROID_LOG_INFO, "SDL", "Finalize");
4704
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
93 }
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
94
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
95 /*******************************************************************************
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
96 Pause (ie: stop as soon as possible)
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
97 *******************************************************************************/
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
98 void Java_org_libsdl_android_TestGLSurfaceView_nativePause( JNIEnv* env )
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
99 {
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
100 sDemoStopped = !sDemoStopped;
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
101 if (sDemoStopped) {
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
102 //we paused
4705
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
103 __android_log_print(ANDROID_LOG_INFO, "SDL", "Pause");
4704
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
104 } else {
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
105 //we resumed
4705
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
106 __android_log_print(ANDROID_LOG_INFO, "SDL", "Resume");
4704
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
107 }
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
108 }
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
109
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
110 /*******************************************************************************
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
111 Render the next frame
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
112 *******************************************************************************/
4705
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
113
4704
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
114 void Java_org_libsdl_android_TestRenderer_nativeRender( JNIEnv* env )
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
115 {
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
116 //TODO: Render here
4705
190f043af37d Rotating pyramid!
Paul Hunkin <paul@bieh.net>
parents: 4704
diff changeset
117
4704
611d39792201 Added minimal test project
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
118 }