Add new native-plasma sample code.

This shows direct drawing to an ANativeWindow's bits.

Update the NDK API, and fix a bug in the native-activity app where it
would hang while exiting.

Change-Id: I4fa98d083405eb0d1b22b10a73a2ef18d45fdb59
This commit is contained in:
Dianne Hackborn
2010-07-09 11:48:23 -07:00
parent 5ce45c93ad
commit 1aa3218800
19 changed files with 745 additions and 27 deletions

View File

@@ -148,26 +148,29 @@ static int engine_do_ui_event(struct engine* engine) {
return 1;
}
static void engine_do_main_cmd(struct engine* engine) {
static int32_t engine_do_main_cmd(struct engine* engine) {
int32_t res;
int8_t cmd = android_app_read_cmd(engine->app);
switch (cmd) {
case APP_CMD_WINDOW_CHANGED:
engine_term_display(engine);
android_app_exec_cmd(engine->app, cmd);
res = android_app_exec_cmd(engine->app, cmd);
if (engine->app->window != NULL) {
engine_init_display(engine);
engine_draw_frame(engine);
}
break;
case APP_CMD_LOST_FOCUS:
android_app_exec_cmd(engine->app, cmd);
res = android_app_exec_cmd(engine->app, cmd);
engine->animating = 0;
engine_draw_frame(engine);
break;
default:
android_app_exec_cmd(engine->app, cmd);
res = android_app_exec_cmd(engine->app, cmd);
break;
}
return res;
}
void android_main(struct android_app* state) {
@@ -185,10 +188,15 @@ void android_main(struct android_app* state) {
int events;
void* data;
while ((fd=ALooper_pollAll(engine.animating ? 0 : -1, &events, &data)) >= 0) {
LOGI("Poll returned: %d", (int)data);
switch ((int)data) {
case LOOPER_ID_MAIN:
engine_do_main_cmd(&engine);
if (!engine_do_main_cmd(&engine)) {
LOGI("Engine thread destroy requested!");
engine_term_display(&engine);
android_app_destroy(state);
// Can't touch android_app object after this.
return;
}
break;
case LOOPER_ID_EVENT:
engine_do_ui_event(&engine);
@@ -196,14 +204,6 @@ void android_main(struct android_app* state) {
}
}
if (state->destroyRequested) {
LOGI("Engine thread destroy requested!");
engine_term_display(&engine);
android_app_destroy(state);
// Can't touch android_app object after this.
return;
}
if (engine.animating) {
// Done with events; draw next animation frame.
engine.angle += .01f;