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