void StAndroidGlue::processCommand() { int8_t aCmd = -1; if(::read(myMsgRead, &aCmd, sizeof(aCmd)) == sizeof(aCmd)) { switch(aCmd) { case CommandId_SaveState: freeSavedState(); break; } } else { ST_ERROR_LOG("No data on command pipe!"); return; } // preprocessing switch(aCmd) { case CommandId_InputChanged: { pthread_mutex_lock(&myMutex); if(myInputQueue != NULL) { AInputQueue_detachLooper(myInputQueue); } myInputQueue = myInputQueuePending; if(myInputQueue != NULL) { AInputQueue_attachLooper(myInputQueue, myLooper, LooperId_INPUT, NULL, &myInputPollSource); } pthread_cond_broadcast(&myCond); pthread_mutex_unlock(&myMutex); break; } case CommandId_WindowChanged: case CommandId_WindowInit: { pthread_mutex_lock(&myMutex); myWindow = myWindowPending; pthread_cond_broadcast(&myCond); pthread_mutex_unlock(&myMutex); break; } case CommandId_WindowTerm: { pthread_cond_broadcast(&myCond); break; } case CommandId_Resume: case CommandId_Start: case CommandId_Pause: case CommandId_Stop: { pthread_mutex_lock(&myMutex); myActivityState = aCmd; pthread_cond_broadcast(&myCond); pthread_mutex_unlock(&myMutex); break; } case CommandId_ConfigChanged: { AConfiguration_fromAssetManager(myConfig, myActivity->assetManager); updateMonitors(); printConfig(); break; } case CommandId_Destroy: { myToDestroy = true; break; } } signals.onAppCmd(aCmd); // post-processing switch(aCmd) { case CommandId_WindowTerm: { pthread_mutex_lock(&myMutex); myWindow = NULL; pthread_cond_broadcast(&myCond); pthread_mutex_unlock(&myMutex); break; } case CommandId_WindowChanged: { pthread_mutex_lock(&myMutex); myWindowPending = NULL; pthread_cond_broadcast(&myCond); pthread_mutex_unlock(&myMutex); break; } case CommandId_SaveState: { pthread_mutex_lock(&myMutex); myIsStateSaved = true; pthread_cond_broadcast(&myCond); pthread_mutex_unlock(&myMutex); break; } case CommandId_Resume: { freeSavedState(); break; } } }
void StWindowImpl::onAndroidCommand(int32_t theCommand) { switch(theCommand) { case StAndroidGlue::CommandId_SaveState: { // the system has asked us to save our current state /*StSavedState* aState = (StSavedState* )malloc(sizeof(StSavedState)); *aState = state; myParentWin->setSavedState(aState, sizeof(StSavedState));*/ return; } case StAndroidGlue::CommandId_WindowInit: { // the window is being shown, get it ready onAndroidInitWindow(); return; } case StAndroidGlue::CommandId_BackPressed: { myStEvent.Key.Time = getEventTime(); myStEvent.Key.VKey = ST_VK_ESCAPE; myStEvent.Key.Char = 0; postKeyDown(myStEvent); postKeyUp (myStEvent); return; } case StAndroidGlue::CommandId_Resume: { myIsPaused = false; return; } case StAndroidGlue::CommandId_Pause: { myIsPaused = true; myStEvent.Type = stEvent_Pause; myStEvent.Pause.Time = getEventTime(); signals.onPause->emit(myStEvent.Pause); return; } case StAndroidGlue::CommandId_Stop: { if(myParentWin->getMemoryClass() < 50) { myStEvent.Type = stEvent_Close; myStEvent.Close.Time = getEventTime(); signals.onClose->emit(myStEvent.Close); } break; } case StAndroidGlue::CommandId_WindowChanged: case StAndroidGlue::CommandId_WindowTerm: { if(!myMaster.hRC.isNull()) { myMaster.hRC->makeCurrent(EGL_NO_SURFACE); if(myMaster.eglSurface != EGL_NO_SURFACE) { eglDestroySurface(myMaster.hRC->getDisplay(), myMaster.eglSurface); myMaster.eglSurface = EGL_NO_SURFACE; } } myMaster.hWindowGl = NULL; if(theCommand == StAndroidGlue::CommandId_WindowChanged) { onAndroidInitWindow(); } return; } case StAndroidGlue::CommandId_FocusGained: { // return; } case StAndroidGlue::CommandId_FocusLost: { myKeysState.reset(); return; } case StAndroidGlue::CommandId_ConfigChanged: { // do not handle resize event here - screen might be not yet resized updateMonitors(); myStEvent.Size.init(getEventTime(), myRectNorm.width(), myRectNorm.height(), myForcedAspect); myStEvent.Type = stEvent_NewMonitor; //myWinOnMonitorId = 0; signals.onAnotherMonitor->emit(myStEvent.Size); return; } } }
void StAndroidGlue::threadEntry() { if(myJavaVM->AttachCurrentThread(&myThJniEnv, NULL) < 0) { ST_ERROR_LOG("Failed to attach working thread to Java VM"); return; } THE_ANDROID_GLUE = this; StMessageBox::setCallback(msgBoxCallback); myConfig = AConfiguration_new(); AConfiguration_fromAssetManager(myConfig, myActivity->assetManager); updateMonitors(); printConfig(); ALooper* aLooper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); ALooper_addFd(aLooper, myMsgRead, LooperId_MAIN, ALOOPER_EVENT_INPUT, NULL, &myCmdPollSource); myLooper = aLooper; pthread_mutex_lock(&myMutex); myIsRunning = true; pthread_cond_broadcast(&myCond); pthread_mutex_unlock(&myMutex); // try to load stereo APIs /**jclass aJClass_Real3D = myThJniEnv->FindClass("com/lge/real3d/Real3D"); if(aJClass_Real3D != NULL) { jmethodID aJMet_isStereoDisplayAvailable = myThJniEnv->GetStaticMethodID(aJClass_Real3D, "isStereoDisplayAvailable", "(Landroid/content/Contex;)Z"); postMessage("com.lge.real3d.Real3D !!!"); } jclass aJClass_HTC = myThJniEnv->FindClass("com/htc/view/DisplaySetting"); if(aJClass_HTC != NULL) { jmethodID aJMet_isStereoDisplayAvailable = myThJniEnv->GetStaticMethodID(aJClass_HTC, "setStereoscopic3DFormat", "(Landroid/view/Surface;I)Z"); postMessage("com.htc.view.DisplaySetting !!!"); } jclass aJClass_Sharp = myThJniEnv->FindClass("jp/co/sharp/android/stereo3dlcd/SurfaceController"); if(aJClass_Sharp != NULL) { jmethodID aJMet_setStereoView = myThJniEnv->GetMethodID(aJClass_Sharp, "setStereoView", "(Z)V"); postMessage("jp.co.sharp.android.stereo3dlcd !!!"); }*/ createApplication(); if(!myApp.isNull()) { if(!myApp->open()) { stError("Error: application can not be executed!"); } myApp->exec(); } else { stError("Error: no application to execute!"); } myApp.nullify(); // application is done but we are waiting for destroying event... bool isFirstWait = true; for(; !myToDestroy; ) { if(isFirstWait) { postExit(); isFirstWait = false; } StAndroidPollSource* aSource = NULL; int aNbEvents = 0; ALooper_pollAll(-1, NULL, &aNbEvents, (void** )&aSource); if(aSource != NULL) { aSource->process(this, aSource); } } freeSavedState(); pthread_mutex_lock(&myMutex); if(myInputQueue != NULL) { AInputQueue_detachLooper(myInputQueue); } AConfiguration_delete(myConfig); pthread_cond_broadcast(&myCond); pthread_mutex_unlock(&myMutex); myThJniEnv = NULL; StMessageBox::setCallback(NULL); THE_ANDROID_GLUE = NULL; myJavaVM->DetachCurrentThread(); }