diff options
Diffstat (limited to 'backends/platform')
| -rw-r--r-- | backends/platform/android/gfx.cpp | 6 | ||||
| -rw-r--r-- | backends/platform/android/jni.cpp | 54 | ||||
| -rw-r--r-- | backends/platform/android/jni.h | 21 | ||||
| -rw-r--r-- | backends/platform/android/org/inodes/gus/scummvm/ScummVM.java | 15 | 
4 files changed, 67 insertions, 29 deletions
diff --git a/backends/platform/android/gfx.cpp b/backends/platform/android/gfx.cpp index 7fbe896d82..96ba5e729a 100644 --- a/backends/platform/android/gfx.cpp +++ b/backends/platform/android/gfx.cpp @@ -288,10 +288,8 @@ void OSystem_Android::updateScreen() {  	GLCALL(glPopMatrix()); -	int res = JNI::swapBuffers(); - -	if (res) -		warning("swapBuffers returned 0x%x", res); +	if (!JNI::swapBuffers()) +		LOGW("swapBuffers failed: 0x%x", glGetError());  }  Graphics::Surface *OSystem_Android::lockScreen() { diff --git a/backends/platform/android/jni.cpp b/backends/platform/android/jni.cpp index 28a03d0555..3c2324dea1 100644 --- a/backends/platform/android/jni.cpp +++ b/backends/platform/android/jni.cpp @@ -40,6 +40,9 @@ jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {  JavaVM *JNI::_vm = 0;  jobject JNI::_jobj = 0;  jobject JNI::_jobj_audio_track = 0; +jobject JNI::_jobj_egl = 0; +jobject JNI::_jobj_egl_display = 0; +jobject JNI::_jobj_egl_surface = 0;  Common::Archive *JNI::_asset_archive = 0;  OSystem_Android *JNI::_system = 0; @@ -63,10 +66,11 @@ jmethodID JNI::_MID_setWindowCaption = 0;  jmethodID JNI::_MID_showVirtualKeyboard = 0;  jmethodID JNI::_MID_getSysArchives = 0;  jmethodID JNI::_MID_getPluginDirectories = 0; -jmethodID JNI::_MID_swapBuffers = 0;  jmethodID JNI::_MID_initSurface = 0;  jmethodID JNI::_MID_deinitSurface = 0; +jmethodID JNI::_MID_EGL10_eglSwapBuffers = 0; +  jmethodID JNI::_MID_AudioTrack_flush = 0;  jmethodID JNI::_MID_AudioTrack_pause = 0;  jmethodID JNI::_MID_AudioTrack_play = 0; @@ -75,6 +79,8 @@ jmethodID JNI::_MID_AudioTrack_write = 0;  const JNINativeMethod JNI::_natives[] = {  	{ "create", "(Landroid/content/res/AssetManager;" +				"Ljavax/microedition/khronos/egl/EGL10;" +				"Ljavax/microedition/khronos/egl/EGLDisplay;"  				"Landroid/media/AudioTrack;II)V",  		(void *)JNI::create },  	{ "destroy", "()V", @@ -318,17 +324,23 @@ void JNI::getPluginDirectories(Common::FSList &dirs) {  	}  } -void JNI::initSurface() { +bool JNI::initSurface() {  	JNIEnv *env = JNI::getEnv(); -	env->CallVoidMethod(_jobj, _MID_initSurface); +	jobject obj = env->CallObjectMethod(_jobj, _MID_initSurface); -	if (env->ExceptionCheck()) { +	if (!obj || env->ExceptionCheck()) {  		LOGE("initSurface failed");  		env->ExceptionDescribe();  		env->ExceptionClear(); + +		return false;  	} + +	_jobj_egl_surface = env->NewGlobalRef(obj); + +	return true;  }  void JNI::deinitSurface() { @@ -342,6 +354,9 @@ void JNI::deinitSurface() {  		env->ExceptionDescribe();  		env->ExceptionClear();  	} + +	env->DeleteGlobalRef(_jobj_egl_surface); +	_jobj_egl_surface = 0;  }  void JNI::setAudioPause() { @@ -394,11 +409,12 @@ void JNI::setAudioStop() {  // natives for the dark side -void JNI::create(JNIEnv *env, jobject self, jobject am, jobject at, -					jint audio_sample_rate, jint audio_buffer_size) { +void JNI::create(JNIEnv *env, jobject self, jobject asset_manager, +				jobject egl, jobject egl_display, +				jobject at, jint audio_sample_rate, jint audio_buffer_size) {  	assert(!_system); -	_asset_archive = new AndroidAssetArchive(am); +	_asset_archive = new AndroidAssetArchive(asset_manager);  	assert(_asset_archive);  	_system = new OSystem_Android(audio_sample_rate, audio_buffer_size); @@ -407,6 +423,7 @@ void JNI::create(JNIEnv *env, jobject self, jobject am, jobject at,  	// weak global ref to allow class to be unloaded  	// ... except dalvik implements NewWeakGlobalRef only on froyo  	//_jobj = env->NewWeakGlobalRef(self); +  	_jobj = env->NewGlobalRef(self);  	jclass cls = env->GetObjectClass(_jobj); @@ -422,12 +439,28 @@ void JNI::create(JNIEnv *env, jobject self, jobject am, jobject at,  	FIND_METHOD(showVirtualKeyboard, "(Z)V");  	FIND_METHOD(getSysArchives, "()[Ljava/lang/String;");  	FIND_METHOD(getPluginDirectories, "()[Ljava/lang/String;"); -	FIND_METHOD(swapBuffers, "()I"); -	FIND_METHOD(initSurface, "()V"); +	FIND_METHOD(initSurface, "()Ljavax/microedition/khronos/egl/EGLSurface;");  	FIND_METHOD(deinitSurface, "()V");  #undef FIND_METHOD +	_jobj_egl = env->NewGlobalRef(egl); +	_jobj_egl_display = env->NewGlobalRef(egl_display); + +	cls = env->GetObjectClass(_jobj_egl); + +#define FIND_METHOD(name, signature) do {									\ +		_MID_EGL10_ ## name = env->GetMethodID(cls, #name, signature);		\ +		if (_MID_EGL10_ ## name == 0)										\ +			return;															\ +	} while (0) + +	FIND_METHOD(eglSwapBuffers, "(Ljavax/microedition/khronos/egl/EGLDisplay;" +								"Ljavax/microedition/khronos/egl/EGLSurface;" +								")Z"); + +#undef FIND_METHOD +  	_jobj_audio_track = env->NewGlobalRef(at);  	cls = env->GetObjectClass(_jobj_audio_track); @@ -459,6 +492,9 @@ void JNI::destroy(JNIEnv *env, jobject self) {  	// see above  	//JNI::getEnv()->DeleteWeakGlobalRef(_jobj); + +	JNI::getEnv()->DeleteGlobalRef(_jobj_egl_display); +	JNI::getEnv()->DeleteGlobalRef(_jobj_egl);  	JNI::getEnv()->DeleteGlobalRef(_jobj_audio_track);  	JNI::getEnv()->DeleteGlobalRef(_jobj);  } diff --git a/backends/platform/android/jni.h b/backends/platform/android/jni.h index 0005136966..2a1405dfcc 100644 --- a/backends/platform/android/jni.h +++ b/backends/platform/android/jni.h @@ -60,8 +60,8 @@ public:  	static void showVirtualKeyboard(bool enable);  	static void addSysArchivesToSearchSet(Common::SearchSet &s, int priority); -	static inline int swapBuffers(); -	static void initSurface(); +	static inline bool swapBuffers(); +	static bool initSurface();  	static void deinitSurface();  	static void setAudioPause(); @@ -76,6 +76,9 @@ private:  	// back pointer to (java) peer instance  	static jobject _jobj;  	static jobject _jobj_audio_track; +	static jobject _jobj_egl; +	static jobject _jobj_egl_display; +	static jobject _jobj_egl_surface;  	static Common::Archive *_asset_archive;  	static OSystem_Android *_system; @@ -97,10 +100,11 @@ private:  	static jmethodID _MID_showVirtualKeyboard;  	static jmethodID _MID_getSysArchives;  	static jmethodID _MID_getPluginDirectories; -	static jmethodID _MID_swapBuffers;  	static jmethodID _MID_initSurface;  	static jmethodID _MID_deinitSurface; +	static jmethodID _MID_EGL10_eglSwapBuffers; +  	static jmethodID _MID_AudioTrack_flush;  	static jmethodID _MID_AudioTrack_pause;  	static jmethodID _MID_AudioTrack_play; @@ -113,8 +117,10 @@ private:  	static void throwRuntimeException(JNIEnv *env, const char *msg);  	// natives for the dark side -	static void create(JNIEnv *env, jobject self, jobject am, jobject at, -						jint sample_rate, jint buffer_size); +	static void create(JNIEnv *env, jobject self, jobject asset_manager, +						jobject egl, jobject egl_display, +						jobject at, jint audio_sample_rate, +						jint audio_buffer_size);  	static void destroy(JNIEnv *env, jobject self);  	static void setSurface(JNIEnv *env, jobject self, jint width, jint height); @@ -124,10 +130,11 @@ private:  	static void enableZoning(JNIEnv *env, jobject self, jboolean enable);  }; -inline int JNI::swapBuffers() { +inline bool JNI::swapBuffers() {  	JNIEnv *env = JNI::getEnv(); -	return env->CallIntMethod(_jobj, _MID_swapBuffers); +	return env->CallBooleanMethod(_jobj_egl, _MID_EGL10_eglSwapBuffers, +									_jobj_egl_display, _jobj_egl_surface);  }  inline int JNI::writeAudio(JNIEnv *env, jbyteArray &data, int offset, int size) { diff --git a/backends/platform/android/org/inodes/gus/scummvm/ScummVM.java b/backends/platform/android/org/inodes/gus/scummvm/ScummVM.java index db83303c7d..75407c66cc 100644 --- a/backends/platform/android/org/inodes/gus/scummvm/ScummVM.java +++ b/backends/platform/android/org/inodes/gus/scummvm/ScummVM.java @@ -38,6 +38,7 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable {  	private String[] args;  	final private native void create(AssetManager asset_manager, +										EGL10 egl, EGLDisplay eglDisplay,  										AudioTrack audio_track,  										int sample_rate, int buffer_size);  	final private native void destroy(); @@ -56,13 +57,6 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable {  	abstract protected void showVirtualKeyboard(boolean enable);  	abstract protected String[] getSysArchives(); -	final protected int swapBuffers() { -		if (!egl.eglSwapBuffers(eglDisplay, eglSurface)) -			return egl.eglGetError(); - -		return 0; -	} -  	public ScummVM(AssetManager asset_manager, SurfaceHolder holder) {  		this.asset_manager = asset_manager;  		sem_surface = new Object(); @@ -126,7 +120,8 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable {  			throw new RuntimeException("Error preparing the ScummVM thread", e);  		} -		create(asset_manager, audio_track, sample_rate, buffer_size); +		create(asset_manager, egl, eglDisplay, +				audio_track, sample_rate, buffer_size);  		int res = main(args); @@ -192,7 +187,7 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable {  	}  	// Callback from C++ peer instance -	final protected void initSurface() throws Exception { +	final protected EGLSurface initSurface() throws Exception {  		eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig,  												surface_holder, null); @@ -210,6 +205,8 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable {  						gl.glGetString(GL10.GL_VERSION),  						gl.glGetString(GL10.GL_RENDERER),  						gl.glGetString(GL10.GL_VENDOR))); + +		return eglSurface;  	}  	// Callback from C++ peer instance  | 
