Esempio n. 1
0
void *cxAndroid::AndroidEntry(void *data)
{
    cxAndroid *app = (cxAndroid *)data;
    AConfiguration_fromAssetManager(app->config, app->activity->assetManager);
    
    app->cmd.id = LOOPER_ID_MAIN;
    app->cmd.app = app;
    app->cmd.process = cxAndroid::cxAndroidExec;
    
    app->input.id = LOOPER_ID_INPUT;
    app->input.app = app;
    app->input.process = cxAndroid::cxAndroidInputExec;
    
    app->looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
    ALooper_addFd(app->looper, app->msgread, LOOPER_ID_MAIN, ALOOPER_EVENT_INPUT, NULL,&app->cmd);
    
    pthread_mutex_lock(&app->mutex);
    app->running = true;
    pthread_cond_broadcast(&app->cond);
    pthread_mutex_unlock(&app->mutex);
    
    app->cxAndroidMain();
    
    pthread_mutex_lock(&app->mutex);
    if (app->inputQueue != NULL) {
        AInputQueue_detachLooper(app->inputQueue);
        app->inputQueue = NULL;
    }
    AConfiguration_delete(app->config);
    app->config = NULL;
    app->destroyed = true;
    pthread_cond_broadcast(&app->cond);
    pthread_mutex_unlock(&app->mutex);
    return data;
}
Esempio n. 2
0
cxAndroid::~cxAndroid()
{
    close(msgread);
    close(msgwrite);
    pthread_cond_destroy(&cond);
    pthread_mutex_destroy(&mutex);
    AConfiguration_delete(config);
    free(state);
}
Esempio n. 3
0
int TBSystem::GetDPI()
{
	AConfiguration *config = AConfiguration_new();
	AConfiguration_fromAssetManager(config, g_pManager);
	int32_t density = AConfiguration_getDensity(config);
	AConfiguration_delete(config);
	if (density == 0 || density == ACONFIGURATION_DENSITY_NONE)
		return 120;
	return density;
}
Esempio n. 4
0
int PlatformUtils::getDPI()
{
    AConfiguration *config = AConfiguration_new();
    AConfiguration_fromAssetManager(config, AndroidServices::getAAssetManager());
    int32_t density = AConfiguration_getDensity(config);
    AConfiguration_delete(config);

    if (density == 0 || density == ACONFIGURATION_DENSITY_NONE)
        return 120;

    return density;
}
static void android_app_destroy(struct android_app* android_app) {
    free_saved_state(android_app);
    pthread_mutex_lock(&android_app->mutex);
    if (android_app->inputQueue != NULL) {
        AInputQueue_detachLooper(android_app->inputQueue);
    }
    AConfiguration_delete(android_app->config);
    android_app->destroyed = 1;
    pthread_cond_broadcast(&android_app->cond);
    pthread_mutex_unlock(&android_app->mutex);
    // Can't touch android_app object after this.
}
static void android_app_destroy ( struct android_app* android_app ) {
	LOGV ( "android_app_destroy!" );
	free_saved_state ( android_app );
	pthread_mutex_lock ( &android_app->mutex );
	if ( android_app->inputQueue != NULL ) {
		AInputQueue_detachLooper ( android_app->inputQueue );
	}
	AConfiguration_delete ( android_app->config );
	android_app->destroyed = 1;
	pthread_cond_broadcast ( &android_app->cond );
	pthread_mutex_unlock ( &android_app->mutex );
	// 이후에 android_app 개체를 터치할 수 없습니다.
}
Esempio n. 7
0
// ==== デストラクタ
ANAS::Activity::~Activity()
{

	Log::i("Activity Destructor", "Start Destruction");

	// アクティビティの終了宣言
	ANativeActivity_finish(pActivity);

	AConfiguration_delete(pConfig);
	
	// Wait "onDestroy" Callback is called.
	DestroyFuture.get();

	Log::i("Activity Destructor", "End Destruction");
}
Esempio n. 8
0
static void handleCmd(struct android_app* app, int32_t cmd)
{
    switch (cmd) 
    {
        case APP_CMD_SAVE_STATE:
        	// http://developer.android.com/reference/android/app/NativeActivity.html
            break;
        case APP_CMD_INIT_WINDOW:
            if(app->window && gRoot)
            {
                AConfiguration* config = AConfiguration_new();
                AConfiguration_fromAssetManager(config, app->activity->assetManager);
                gAssetMgr = app->activity->assetManager;
				
                if(!gRenderWnd)
                {
				    Ogre::ArchiveManager::getSingleton().addArchiveFactory( new Ogre::APKFileSystemArchiveFactory(app->activity->assetManager) );
					Ogre::ArchiveManager::getSingleton().addArchiveFactory( new Ogre::APKZipArchiveFactory(app->activity->assetManager) );
				
                    Ogre::NameValuePairList opt;
                    opt["externalWindowHandle"] = Ogre::StringConverter::toString((int)app->window);
                    opt["androidConfig"] = Ogre::StringConverter::toString((int)config);
                           
					gRenderWnd = gRoot->createRenderWindow("OgreWindow", 0, 0, false, &opt); 
		
					InitStartScene();
                }
                else
                {
					static_cast<Ogre::AndroidEGLWindow*>(gRenderWnd)->_createInternalResources(app->window, config);
                }
                AConfiguration_delete(config);
            }
            break;
        case APP_CMD_TERM_WINDOW:
            if(gRoot && gRenderWnd)
				static_cast<Ogre::AndroidEGLWindow*>(gRenderWnd)->_destroyInternalResources();
            break;
        case APP_CMD_GAINED_FOCUS:
        	// When our app gains focus, we start monitoring the accelerometer.

            break;
        case APP_CMD_LOST_FOCUS:
			// Also stop animating.
            break;
    }
}
Esempio n. 9
0
void ApplicationContext::shutdown()
{
    if (Ogre::GpuProgramManager::getSingleton().isCacheDirty())
    {
        Ogre::String path = mFSLayer->getWritablePath(SHADER_CACHE_FILENAME);
        std::fstream outFile(path.c_str(), std::ios::out | std::ios::binary);

        if (outFile.is_open())
        {
            Ogre::LogManager::getSingleton().logMessage("Writing shader cache to "+path);
            Ogre::DataStreamPtr ostream(new Ogre::FileStreamDataStream(path, &outFile, false));
            Ogre::GpuProgramManager::getSingleton().saveMicrocodeCache(ostream);
        }
    }

#ifdef OGRE_BUILD_COMPONENT_RTSHADERSYSTEM
    // Destroy the RT Shader System.
    destroyRTShaderSystem();
#endif

    // remove window event listener before destroying it
    if(mWindow) {
        Ogre::WindowEventUtilities::removeWindowEventListener(mWindow, this);
        mRoot->destroyRenderTarget(mWindow);
        mWindow = NULL;
    }

    if (mOverlaySystem)
    {
        OGRE_DELETE mOverlaySystem;
    }

#if OGRE_BITES_HAVE_SDL
    if(mSDLWindow) {
        SDL_DestroyWindow(mSDLWindow);
        SDL_QuitSubSystem(SDL_INIT_VIDEO);
        mSDLWindow = NULL;
    }
#endif

#if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
    AConfiguration_delete(mAConfig);
#endif
}
Esempio n. 10
0
static void initWindow()
{
	LOGI("------->initWindow() >>>>>>>>");

	LOGI("Calling AConfiguration_new()");

	AConfiguration* config = AConfiguration_new();

	LOGI("AConfiguration_new() %p", config);

	AConfiguration_fromAssetManager(config, gAssetManager);

	LOGI("AConfiguration_fromAssetManager(config, gAssetManager) %p", config);

	if (!gRenderWnd)
	{
		Ogre::ArchiveManager::getSingleton().addArchiveFactory( new Ogre::APKFileSystemArchiveFactory(gAssetManager) );
		Ogre::ArchiveManager::getSingleton().addArchiveFactory( new Ogre::APKZipArchiveFactory(gAssetManager) );

		Ogre::NameValuePairList opt;

		LOGI("Ogre::StringConverter::toString((int)mRendereWindow) %s",
				Ogre::StringConverter::toString((int )mRendereWindow).c_str());
		LOGI("Ogre::StringConverter::toString((int)config) %s", Ogre::StringConverter::toString((int )config).c_str());

		opt["externalWindowHandle"] = Ogre::StringConverter::toString((int) mRendereWindow);
		opt["androidConfig"] = Ogre::StringConverter::toString((int) config);

		gRenderWnd = gRoot->createRenderWindow("OgreWindow", 0, 0, false, &opt);

		setupScene();
	}
	else
	{
		static_cast<Ogre::AndroidEGLWindow*>(gRenderWnd)->_createInternalResources(mRendereWindow, config);
	}
	AConfiguration_delete(config);

	LOGI("<-------initWindow()");
}
//----------------------------------------------------------------------------//
void AndroidAppHelper::handleCmd (struct android_app* app, int32_t cmd)
{
    switch (cmd)
    {
    case APP_CMD_SAVE_STATE:
        break;
    case APP_CMD_INIT_WINDOW:
        if (app->window && Ogre::Root::getSingletonPtr())
        {
            AConfiguration* config = AConfiguration_new();
            AConfiguration_fromAssetManager (config, app->activity->assetManager);

            if (!mRenderWnd)
            {
                Ogre::NameValuePairList opt;
                opt["externalWindowHandle"] = Ogre::StringConverter::toString ((int)app->window);
                opt["androidConfig"] = Ogre::StringConverter::toString ((int)config);
                mRenderWnd = Ogre::Root::getSingleton().createRenderWindow (
                                 "OgreWindow", 0, 0, false, &opt);
                setWindowCreated (true);
            }
            else
            {
                static_cast<Ogre::AndroidEGLWindow*> (mRenderWnd)->_createInternalResources ( app->window, config);
            }
            AConfiguration_delete (config);
        }
        break;
    case APP_CMD_TERM_WINDOW:
        if (Ogre::Root::getSingletonPtr() && mRenderWnd)
            static_cast<Ogre::AndroidEGLWindow*> (mRenderWnd)->_destroyInternalResources();
        break;
    case APP_CMD_GAINED_FOCUS:
        break;
    case APP_CMD_LOST_FOCUS:
        break;
    case APP_CMD_CONFIG_CHANGED:
        break;
    }
}
Esempio n. 12
0
int main(void)
{
	std::string out_text;
	out_text = "Hello Android World 2";
	std::cout << std::endl;
	std::cout << "start" << std::endl;
	int index = 100;
	while(index) {
		std::cout << index << " - " << out_text.c_str() << std::endl;
		index--;
	}
	std::cout << "end" << std::endl;
	__android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "do you see me %d", 55);

	AConfiguration* config = AConfiguration_new();
	int32_t screen_size = AConfiguration_getScreenSize(config);
	AConfiguration_delete(config);
	switch(screen_size) {
		case ACONFIGURATION_SCREENSIZE_ANY:
			std::cout << "screen_size ANY" << std::endl;
			break;
		case ACONFIGURATION_SCREENSIZE_SMALL:
			std::cout << "screen_size SMALL" << std::endl;
			break;
		case ACONFIGURATION_SCREENSIZE_NORMAL:
			std::cout << "screen_size NORMAL" << std::endl;
			break;
		case ACONFIGURATION_SCREENSIZE_LARGE:
			std::cout << "screen_size LARGE" << std::endl;
			break;
		case ACONFIGURATION_SCREENSIZE_XLARGE:
			std::cout << "screen_size XLARGE" << std::endl;
			break;
	};

	return 0;
}
Esempio n. 13
0
	static void handleCmd(struct android_app* app, int32_t cmd)
	{
		switch (cmd) 
		{
		case APP_CMD_SAVE_STATE:
			break;

		case APP_CMD_INIT_WINDOW:
			if (app->window) // && mRoot)
			{
				AConfiguration* config = AConfiguration_new();
				AConfiguration_fromAssetManager(config, app->activity->assetManager);

				if (!okit.isInited())
				{					
					LOG_FOOT;

					//okit.getPrefs().winsize.x = drawWidth;
					//okit.getPrefs().winsize.y = drawHeight;
					
					okit.assetMgr = app->activity->assetManager;

					okit.getPrefs().extWinhandle  = Ogre::StringConverter::toString((int)app->window);
					okit.getPrefs().androidConfig = Ogre::StringConverter::toString((int)config);
					okit.getPrefs().verbose = true;

					//gkLogger::enable("OgreKitDemo.log", true);
					//Ogre::LogManager::getSingleton().getDefaultLog()->addListener(&gLogListener);

					
					if (okit.init(""))
					{
						LOG_FOOT;
						m_window = gkWindowSystem::getSingleton().getMainWindow();
						LOG_FOOT;
						okit.m_input = static_cast<OIS::AndroidInputManager*>(m_window->getInputManager());

						okit.sensorManager = ASensorManager_getInstance();
						okit.accelerometerSensor = ASensorManager_getDefaultSensor(okit.sensorManager,
								ASENSOR_TYPE_ACCELEROMETER);
						okit.sensorEventQueue = ASensorManager_createEventQueue(okit.sensorManager,
								okit.state->looper, LOOPER_ID_USER, NULL, NULL);

						gkEngine::getSingleton().initializeStepLoop();
						
						LOGI("inited");

						//okit.setWindowSize(drawWidth, drawHeight);			
					}
				}
				else
				{
					LOG_FOOT;
					Ogre::RenderWindow* rwnd = gkWindowSystem::getSingleton().getMainRenderWindow();
					if (rwnd)
						static_cast<Ogre::AndroidEGLWindow*>(rwnd)->_createInternalResources(app->window, config);
				}

				LOG_FOOT;

				AConfiguration_delete(config);
			}				
			break;

		case APP_CMD_TERM_WINDOW:
			if (okit.isInited())
			{
				Ogre::RenderWindow* rwnd = gkWindowSystem::getSingleton().getMainRenderWindow();
				if (rwnd)
					static_cast<Ogre::AndroidEGLWindow*>(rwnd)->_destroyInternalResources();
			}
			LOGI("terminiate.");
			break;

		case APP_CMD_GAINED_FOCUS:
			// When our app gains focus, we start monitoring the accelerometer.
            if (okit.accelerometerSensor != NULL) 
			{
                ASensorEventQueue_enableSensor(okit.sensorEventQueue,
                        okit.accelerometerSensor);
                // We'd like to get 60 events per second (in us).
                ASensorEventQueue_setEventRate(okit.sensorEventQueue,
                        okit.accelerometerSensor, (1000L/60)*1000);
            }
			break;

		case APP_CMD_LOST_FOCUS:
			// When our app loses focus, we stop monitoring the accelerometer.
            // This is to avoid consuming battery while not being used.
            if (okit.accelerometerSensor != NULL) 
			{
                ASensorEventQueue_disableSensor(okit.sensorEventQueue,
                        okit.accelerometerSensor);
            }
			break;

		case APP_CMD_CONFIG_CHANGED:
			break;
		}
	}
Esempio n. 14
0
void gkAndroidApp::handleCmd(int32_t cmd) {
    switch (cmd) {
        case APP_CMD_SAVE_STATE:
            LOG_FOOT
            break;

        case APP_CMD_INIT_WINDOW:
            LOG_FOOT
            // The window is being shown, get it ready.
            if (m_state->window) {
                AConfiguration* config = AConfiguration_new();

                if(!m_window) {
                    AConfiguration_fromAssetManager(config, m_state->activity->assetManager);

                    init(config, "momo_ogre_i.blend");

                    m_window = gkWindowSystem::getSingleton().getMainWindow();
                } else {
                    static_cast<Ogre::AndroidEGLWindow*>(m_window->getRenderWindow())->
                            _createInternalResources(m_state->window, config);
                }

                AConfiguration_delete(config);
            }
            break;

        case APP_CMD_TERM_WINDOW: {
            LOG_FOOT
            if(m_window) {
                static_cast<Ogre::AndroidEGLWindow*>(m_window->getRenderWindow())->
                        _destroyInternalResources();
            }
            break;
        }

        case APP_CMD_GAINED_FOCUS:
            LOG_FOOT
            // When our app gains focus, we start monitoring the accelerometer.
            if (m_accelerometerSensor) {
                ASensorEventQueue_enableSensor(m_sensorEventQueue,
                        m_accelerometerSensor);
                // We'd like to get 60 events per second (in us).
                ASensorEventQueue_setEventRate(m_sensorEventQueue,
                        m_accelerometerSensor, (1000L/60)*1000);
            }
            break;

        case APP_CMD_LOST_FOCUS:
            LOG_FOOT
            // When our app loses focus, we stop monitoring the accelerometer.
            // This is to avoid consuming battery while not being used.
            if (m_accelerometerSensor) {
                ASensorEventQueue_disableSensor(m_sensorEventQueue,
                        m_accelerometerSensor);
            }
            break;

        case APP_CMD_CONFIG_CHANGED:
            LOG_FOOT
            break;
    }
}
Esempio n. 15
0
static void *android_app_entry(void *data)
{
   struct android_app* android_app = (struct android_app*)data;

   android_app->config = AConfiguration_new();
   AConfiguration_fromAssetManager(android_app->config, android_app->activity->assetManager);

   print_cur_config(android_app);

   ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
   ALooper_addFd(looper, android_app->msgread, LOOPER_ID_MAIN, ALOOPER_EVENT_INPUT, NULL, NULL);
   android_app->looper = looper;

   pthread_mutex_lock(&android_app->mutex);
   android_app->running = 1;
   pthread_cond_broadcast(&android_app->cond);
   pthread_mutex_unlock(&android_app->mutex);

   memset(&g_android, 0, sizeof(g_android));
   g_android = android_app;

   RARCH_LOG("Native Activity started.\n");
   rarch_main_clear_state();

   while (!android_app->window)
   {
      if (!android_run_events(android_app))
         goto exit;
   }

   rarch_init_msg_queue();

   if (!android_app_start_main(android_app))
   {
      g_settings.input.overlay[0] = 0;
      // threaded video doesn't work right for just displaying one frame
      g_settings.video.threaded = false;
      init_drivers();
      driver.video_poke->set_aspect_ratio(driver.video_data, ASPECT_RATIO_SQUARE);
      rarch_render_cached_frame();
      sleep(2);
      goto exit;
   }

   if (!g_extern.libretro_dummy)
      menu_rom_history_push_current();

   for (;;)
   {
      if (g_extern.system.shutdown)
         break;
      else if (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME))
      {
         load_menu_game_prepare();

         // If ROM load fails, we exit RetroArch. On console it might make more sense to go back to menu though ...
         if (load_menu_game())
            g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME);
         else
         {
#ifdef RARCH_CONSOLE
            g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU);
#else
            return NULL;
#endif
         }

         g_extern.lifecycle_mode_state &= ~(1ULL << MODE_LOAD_GAME);
      }
      else if (g_extern.lifecycle_mode_state & (1ULL << MODE_GAME))
      {
         driver.input->poll(NULL);

         if (driver.video_poke->set_aspect_ratio)
            driver.video_poke->set_aspect_ratio(driver.video_data, g_settings.video.aspect_ratio_idx);

         if (g_extern.lifecycle_mode_state & (1ULL << MODE_VIDEO_THROTTLE_ENABLE))
            audio_start_func();

         // Main loop
         while (rarch_main_iterate());

         if (g_extern.lifecycle_mode_state & (1ULL << MODE_VIDEO_THROTTLE_ENABLE))
            audio_stop_func();
         g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME);
      }
      else if(g_extern.lifecycle_mode_state & (1ULL << MODE_MENU))
      {
         g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU_PREINIT);
         while((input_key_pressed_func(RARCH_PAUSE_TOGGLE)) ?
               android_run_events(android_app) : menu_iterate());

         g_extern.lifecycle_mode_state &= ~(1ULL << MODE_MENU);
      }
      else
         break;
   }

exit:
   android_app->activityState = APP_CMD_DEAD;
   RARCH_LOG("Deinitializing RetroArch...\n");

   menu_free();

   if (g_extern.config_save_on_exit && *g_extern.config_path)
      config_save_file(g_extern.config_path);

   if (g_extern.main_is_init)
      rarch_main_deinit();

   rarch_deinit_msg_queue();
#ifdef PERF_TEST
   rarch_perf_log();
#endif
   rarch_main_clear_state();

   RARCH_LOG("android_app_destroy!");
   if (android_app->inputQueue != NULL)
      AInputQueue_detachLooper(android_app->inputQueue);
   AConfiguration_delete(android_app->config);

   // exit() here is nasty.
   // pthread_exit(NULL) or return NULL; causes hanging ...
   // Should probably called ANativeActivity_finsih(), but it's bugged, it will hang our app.
   exit(0);
}
Esempio n. 16
0
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();
}
void ApplicationContextAndroid::shutdown()
{
    ApplicationContextBase::shutdown();
    mWindows.clear();
    AConfiguration_delete(mAConfig);
}