/* * Opens a window. Requires a SFG_Window object created and attached * to the freeglut structure. OpenGL context is created here. */ void fgPlatformOpenWindow( SFG_Window* window, const char* title, GLboolean positionUse, int x, int y, GLboolean sizeUse, int w, int h, GLboolean gameMode, GLboolean isSubWindow ) { /* TODO: only one full-screen window possible? */ if (fgDisplay.pDisplay.single_native_window && *fgDisplay.pDisplay.single_native_window != NULL) { fgWarning("You can't have more than one window on Android"); return; } /* First, wait until Activity surface is available */ /* Normally events are processed through glutMainLoop(), but the user didn't call it yet, and the Android may not have initialized the View yet. So we need to wait for that to happen. */ /* We can't return from this function before the OpenGL context is properly made current with a valid surface. So we wait for the surface. */ while (fgDisplay.pDisplay.single_native_window == NULL || *fgDisplay.pDisplay.single_native_window == NULL) { /* APP_CMD_INIT_WINDOW will do the job */ int ident; int events; struct android_poll_source* source; if ((ident=ALooper_pollOnce(0, NULL, &events, (void**)&source)) >= 0) if (source != NULL) source->process(source->app, source); /* fgPlatformProcessSingleEvent(); */ } window->Window.Handle = fgDisplay.pDisplay.single_native_window; fgAndroidTryCreateContextAndSurface(window); }
void handleAndroidActivityEvents() { int ident; int events; struct android_poll_source *source; while ( (ident = ALooper_pollOnce(0, NULL, &events, (void**)&source)) >= 0) if (source) source->process(porting::app_global, source); }
static bool android_run_events (void *data) { int id = ALooper_pollOnce(-1, NULL, NULL, NULL); if (id == LOOPER_ID_MAIN) engine_handle_cmd(driver.input_data); // Check if we are exiting. if (g_extern.system.shutdown) return false; return true; }
static bool android_run_events (void *data) { int id = ALooper_pollOnce(-1, NULL, NULL, NULL); if (id == LOOPER_ID_MAIN) engine_handle_cmd(); // Check if we are exiting. if (g_extern.lifecycle_state & (1ULL << RARCH_QUIT_KEY)) return false; return true; }
void android_main(struct android_app* app) { // Make sure glue isn't stripped. app_dummy(); int dummyData = 111; app->userData = &dummyData; app->onAppCmd = handle_activity_lifecycle_events; while (1) { int ident, events; struct android_poll_source* source; // if ((ident=ALooper_pollAll(-1, NULL, &events, (void**)&source)) >= 0) { if ((ident=ALooper_pollOnce(-1, NULL, &events, (void**)&source)) >= 0) { source->process(app, source); } } }
event_result message_dispatcher::dispatch_message(app& the_app) { if (true) { scoped_lock lock(m_mutex); if (!m_iqueue || !m_looper) return event_result::unhandled; } int fd, events, ident; void *data; ident = ALooper_pollOnce(m_ticker.paused() ? -1 : 0, &fd, &events, &data); if (ident == MSG_ID_SYSTEM) { system_event se; read(fd, &se, sizeof(se)); if (se & system_event::synchronous) { return fire_on_syncevent(the_app, se); } else { return fire_on_asyncevent(the_app, se); } } else if (ident == MSG_ID_INPUT) { scoped_lock lock(m_mutex); AInputEvent *ie = NULL; if (AInputQueue_getEvent(m_iqueue, &ie) < 0) return event_result::unhandled; if (AInputQueue_preDispatchEvent(m_iqueue, ie)) return event_result::handled; event_result result = event_result::unhandled; if (is_key_message(ie)) { result = fire_on_key(the_app, ie); } else if (is_motion_message(ie)) { result = fire_on_motion(the_app, ie); } else if (is_dpad_message(ie)) { result = fire_on_dpad(the_app, ie); } else if (is_external_event(ie)) { result = fire_on_external(the_app, ie); } AInputQueue_finishEvent(m_iqueue, ie, result == event_result::handled ? 1 : 0); return result; } return event_result::unhandled; }
static void gfx_ctx_check_window(bool *quit, bool *resize, unsigned *width, unsigned *height, unsigned frame_count) { (void)width; (void)height; (void)frame_count; int id; struct android_app* android_app = g_android.app; *quit = false; *resize = false; RARCH_PERFORMANCE_INIT(alooper_pollonce); RARCH_PERFORMANCE_START(alooper_pollonce); id = ALooper_pollOnce(0, NULL, 0, NULL); if(id == LOOPER_ID_MAIN) { int8_t cmd; if (read(android_app->msgread, &cmd, sizeof(cmd)) == sizeof(cmd)) { if(cmd == APP_CMD_SAVE_STATE) free_saved_state(android_app); } else cmd = -1; engine_handle_cmd(android_app, cmd); } RARCH_PERFORMANCE_STOP(alooper_pollonce); // Check if we are exiting. if (g_extern.lifecycle_state & (1ULL << RARCH_QUIT_KEY)) *quit = true; }
void android_main(struct android_app* app) { // Make sure glue isn't stripped. app_dummy(); USERDATA userData; userData.xMove = 0; userData.prevWst = -1; app->userData = &userData; app->onAppCmd = handle_activity_lifecycle_events; app->onInputEvent = handle_input_events; while (1) { int ident, events; struct android_poll_source* source; if ((ident=ALooper_pollOnce(app->redrawNeeded?0:-1, NULL, &events, (void**)&source)) >= 0) { if (NULL!=source) { source->process(app, source); } if (app->redrawNeeded) { drawSomething(app); } } } }
static void gfx_ctx_check_window(bool *quit, bool *resize, unsigned *width, unsigned *height, unsigned frame_count) { (void)frame_count; struct android_app *android_app = (struct android_app*)g_android; *quit = false; unsigned new_width, new_height; gfx_ctx_get_video_size(&new_width, &new_height); if (new_width != *width || new_height != *height) { *width = new_width; *height = new_height; *resize = true; } RARCH_PERFORMANCE_INIT(alooper_pollonce); RARCH_PERFORMANCE_START(alooper_pollonce); while (ALooper_pollOnce(0, NULL, NULL, NULL) == LOOPER_ID_MAIN) { int8_t cmd; if (read(android_app->msgread, &cmd, sizeof(cmd)) != sizeof(cmd)) cmd = -1; engine_handle_cmd(android_app, cmd); } RARCH_PERFORMANCE_STOP(alooper_pollonce); // Check if we are exiting. if (g_extern.lifecycle_state & (1ULL << RARCH_QUIT_KEY)) *quit = true; }
JNIEXPORT jboolean JNICALL Java_edu_ucla_nesl_sigma_base_SigmaJNI_waitForMessage (JNIEnv *env, jclass _class, jint fd) { ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); ALOGD("waitForMessage: pollOnce looper@%d fd@%d", (int)looper, fd); ALooper_addFd(looper, fd, fd, ALOOPER_EVENT_INPUT, NULL, NULL); int events; int result = ALooper_pollOnce(-1, NULL, &events, NULL); if (result == ALOOPER_POLL_ERROR) { ALOGE("waitForMessage error (errno=%d)", errno); result = -1337; // unknown error, so we make up one return JNI_FALSE; } if (events & ALOOPER_EVENT_HANGUP) { // the other-side has died ALOGE("waitForMessage error HANGUP"); result = -1337; // unknown error, so we make up one return JNI_FALSE; } return JNI_TRUE; ALOGD("waitForMessage: got something."); }