(Android) native glue code - fix indenting and remove savestate
leftovers
This commit is contained in:
parent
4d99d93df0
commit
5240f2d9f1
|
@ -23,21 +23,6 @@
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
|
|
||||||
#include "android_native_app_glue.h"
|
#include "android_native_app_glue.h"
|
||||||
#include <android/log.h>
|
|
||||||
|
|
||||||
static void free_saved_state(struct android_app* android_app)
|
|
||||||
{
|
|
||||||
pthread_mutex_lock(&android_app->mutex);
|
|
||||||
|
|
||||||
if (android_app->savedState != NULL)
|
|
||||||
{
|
|
||||||
free(android_app->savedState);
|
|
||||||
android_app->savedState = NULL;
|
|
||||||
android_app->savedStateSize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&android_app->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
int8_t android_app_read_cmd(struct android_app* android_app)
|
int8_t android_app_read_cmd(struct android_app* android_app)
|
||||||
{
|
{
|
||||||
|
@ -48,7 +33,6 @@ int8_t android_app_read_cmd(struct android_app* android_app)
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case APP_CMD_SAVE_STATE:
|
case APP_CMD_SAVE_STATE:
|
||||||
free_saved_state(android_app);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return cmd;
|
return cmd;
|
||||||
|
@ -142,13 +126,8 @@ void android_app_post_exec_cmd(struct android_app* android_app, int8_t cmd)
|
||||||
pthread_mutex_unlock(&android_app->mutex);
|
pthread_mutex_unlock(&android_app->mutex);
|
||||||
break;
|
break;
|
||||||
case APP_CMD_SAVE_STATE:
|
case APP_CMD_SAVE_STATE:
|
||||||
pthread_mutex_lock(&android_app->mutex);
|
|
||||||
android_app->stateSaved = 1;
|
|
||||||
pthread_cond_broadcast(&android_app->cond);
|
|
||||||
pthread_mutex_unlock(&android_app->mutex);
|
|
||||||
break;
|
break;
|
||||||
case APP_CMD_RESUME:
|
case APP_CMD_RESUME:
|
||||||
free_saved_state(android_app);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,8 +138,6 @@ void app_dummy()
|
||||||
|
|
||||||
static void android_app_destroy(struct android_app* android_app)
|
static void android_app_destroy(struct android_app* android_app)
|
||||||
{
|
{
|
||||||
free_saved_state(android_app);
|
|
||||||
|
|
||||||
pthread_mutex_lock(&android_app->mutex);
|
pthread_mutex_lock(&android_app->mutex);
|
||||||
|
|
||||||
if (android_app->inputQueue != NULL)
|
if (android_app->inputQueue != NULL)
|
||||||
|
@ -173,7 +150,7 @@ static void android_app_destroy(struct android_app* android_app)
|
||||||
// Can't touch android_app object after this.
|
// Can't touch android_app object after this.
|
||||||
}
|
}
|
||||||
|
|
||||||
static void process_input(struct android_app* app, struct android_poll_source* source)
|
void process_input(struct android_app* app, struct android_poll_source* source)
|
||||||
{
|
{
|
||||||
AInputEvent* event = NULL;
|
AInputEvent* event = NULL;
|
||||||
|
|
||||||
|
@ -249,13 +226,6 @@ static struct android_app* android_app_create(ANativeActivity* activity,
|
||||||
pthread_mutex_init(&android_app->mutex, NULL);
|
pthread_mutex_init(&android_app->mutex, NULL);
|
||||||
pthread_cond_init(&android_app->cond, NULL);
|
pthread_cond_init(&android_app->cond, NULL);
|
||||||
|
|
||||||
if (savedState != NULL)
|
|
||||||
{
|
|
||||||
android_app->savedState = malloc(savedStateSize);
|
|
||||||
android_app->savedStateSize = savedStateSize;
|
|
||||||
memcpy(android_app->savedState, savedState, savedStateSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
int msgpipe[2];
|
int msgpipe[2];
|
||||||
if (pipe(msgpipe))
|
if (pipe(msgpipe))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -360,26 +330,7 @@ static void onResume(ANativeActivity* activity)
|
||||||
|
|
||||||
static void* onSaveInstanceState(ANativeActivity* activity, size_t* outLen)
|
static void* onSaveInstanceState(ANativeActivity* activity, size_t* outLen)
|
||||||
{
|
{
|
||||||
struct android_app* android_app = (struct android_app*)activity->instance;
|
return NULL;
|
||||||
void* savedState = NULL;
|
|
||||||
|
|
||||||
pthread_mutex_lock(&android_app->mutex);
|
|
||||||
android_app->stateSaved = 0;
|
|
||||||
android_app_write_cmd(android_app, APP_CMD_SAVE_STATE);
|
|
||||||
while (!android_app->stateSaved)
|
|
||||||
pthread_cond_wait(&android_app->cond, &android_app->mutex);
|
|
||||||
|
|
||||||
if (android_app->savedState != NULL)
|
|
||||||
{
|
|
||||||
savedState = android_app->savedState;
|
|
||||||
*outLen = android_app->savedStateSize;
|
|
||||||
android_app->savedState = NULL;
|
|
||||||
android_app->savedStateSize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&android_app->mutex);
|
|
||||||
|
|
||||||
return savedState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onPause(ANativeActivity* activity)
|
static void onPause(ANativeActivity* activity)
|
||||||
|
@ -436,7 +387,6 @@ size_t savedStateSize)
|
||||||
activity->callbacks->onDestroy = onDestroy;
|
activity->callbacks->onDestroy = onDestroy;
|
||||||
activity->callbacks->onStart = onStart;
|
activity->callbacks->onStart = onStart;
|
||||||
activity->callbacks->onResume = onResume;
|
activity->callbacks->onResume = onResume;
|
||||||
activity->callbacks->onSaveInstanceState = onSaveInstanceState;
|
|
||||||
activity->callbacks->onPause = onPause;
|
activity->callbacks->onPause = onPause;
|
||||||
activity->callbacks->onStop = onStop;
|
activity->callbacks->onStop = onStop;
|
||||||
activity->callbacks->onConfigurationChanged = onConfigurationChanged;
|
activity->callbacks->onConfigurationChanged = onConfigurationChanged;
|
||||||
|
|
|
@ -109,10 +109,6 @@ struct android_poll_source {
|
||||||
* Java objects.
|
* Java objects.
|
||||||
*/
|
*/
|
||||||
struct android_app {
|
struct android_app {
|
||||||
// The application can place a pointer to its own state object
|
|
||||||
// here if it likes.
|
|
||||||
void* userData;
|
|
||||||
|
|
||||||
// Fill this in with the function to process main app commands (APP_CMD_*)
|
// Fill this in with the function to process main app commands (APP_CMD_*)
|
||||||
void (*onAppCmd)(struct android_app* app, int32_t cmd);
|
void (*onAppCmd)(struct android_app* app, int32_t cmd);
|
||||||
|
|
||||||
|
@ -128,17 +124,6 @@ struct android_app {
|
||||||
// The current configuration the app is running in.
|
// The current configuration the app is running in.
|
||||||
AConfiguration* config;
|
AConfiguration* config;
|
||||||
|
|
||||||
// This is the last instance's saved state, as provided at creation time.
|
|
||||||
// It is NULL if there was no state. You can use this as you need; the
|
|
||||||
// memory will remain around until you call android_app_exec_cmd() for
|
|
||||||
// APP_CMD_RESUME, at which point it will be freed and savedState set to NULL.
|
|
||||||
// These variables should only be changed when processing a APP_CMD_SAVE_STATE,
|
|
||||||
// at which point they will be initialized to NULL and you can malloc your
|
|
||||||
// state and place the information here. In that case the memory will be
|
|
||||||
// freed for you later.
|
|
||||||
void* savedState;
|
|
||||||
size_t savedStateSize;
|
|
||||||
|
|
||||||
// The ALooper associated with the app's thread.
|
// The ALooper associated with the app's thread.
|
||||||
ALooper* looper;
|
ALooper* looper;
|
||||||
|
|
||||||
|
@ -176,7 +161,6 @@ struct android_app {
|
||||||
struct android_poll_source inputPollSource;
|
struct android_poll_source inputPollSource;
|
||||||
|
|
||||||
int running;
|
int running;
|
||||||
int stateSaved;
|
|
||||||
int destroyed;
|
int destroyed;
|
||||||
int redrawNeeded;
|
int redrawNeeded;
|
||||||
AInputQueue* pendingInputQueue;
|
AInputQueue* pendingInputQueue;
|
||||||
|
|
Loading…
Reference in New Issue