diff android/testproject/jni/app-android.c @ 4708:f3f65cb6a382

Added egl headers so we can use eglMakeCurrent()
author Paul Hunkin <paul@bieh.net>
date Fri, 18 Jun 2010 01:28:39 +1200
parents 12c9d4532b49
children aeac51289991
line wrap: on
line diff
--- a/android/testproject/jni/app-android.c	Fri Jun 18 00:03:09 2010 +1200
+++ b/android/testproject/jni/app-android.c	Fri Jun 18 01:28:39 2010 +1200
@@ -14,6 +14,7 @@
 #include <pthread.h>
 
 #include "importgl.h"
+#include "egl.h"
 
 /*******************************************************************************
                                Globals
@@ -31,7 +32,17 @@
 }
 
 
+/*******************************************************************************
+                               Things used by libsdl
+*******************************************************************************/
+pthread_mutex_t mSDLRenderMutex;
+pthread_cond_t mSDLRenderCondition;
 
+EGLContext mContext;
+EGLDisplay mDisplay;
+EGLSurface mRead;
+EGLSurface mDraw;
+	
 /*******************************************************************************
                       SDL thread
 *******************************************************************************/
@@ -39,7 +50,13 @@
 
 void* sdlThreadProc(void* args){
 	__android_log_print(ANDROID_LOG_INFO, "SDL", "Thread Entry");
-	return 0;
+
+	if(!eglMakeCurrent(mDisplay, mDraw, mRead, mContext)){
+		__android_log_print(ANDROID_LOG_INFO, "SDL", "Couldn't make current: 0x%x", eglGetError());
+		return NULL;
+	}
+	
+	return (void *)SDL_main();
 }
    
 /*******************************************************************************
@@ -54,6 +71,21 @@
 
 	__android_log_print(ANDROID_LOG_INFO, "SDL", "Entry point");
 
+	pthread_mutex_init(&mSDLRenderMutex, NULL);
+	pthread_cond_init (&mSDLRenderCondition, NULL);
+
+	//Get some egl stuff we need
+	mContext = eglGetCurrentContext();
+	mDisplay = eglGetCurrentDisplay();
+	mRead = eglGetCurrentSurface(EGL_READ);
+	mDraw = eglGetCurrentSurface(EGL_DRAW);
+
+	//We need to abandon our context so SDL can have it
+	if(!eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)){
+		__android_log_print(ANDROID_LOG_INFO, "SDL", "Couldn't abandon context: 0x%x", eglGetError());
+		return NULL;
+	}
+
 	//Spin up the SDL thread
 	int r = pthread_create(&mSDLThread, NULL, sdlThreadProc, NULL);
 
@@ -115,4 +147,10 @@
 {    
 	//TODO: Render here
 
+	pthread_mutex_lock(&mSDLRenderMutex);
+	pthread_cond_signal(&mSDLRenderCondition); //wake up the SDL thread
+	pthread_mutex_unlock(&mSDLRenderMutex);
+
+	//__android_log_print(ANDROID_LOG_INFO, "SDL", "Unlocked");
+
 }