Android application state handling (#97)
This commit is contained in:
parent
1288672fd9
commit
2ed3e946b1
2 changed files with 23 additions and 11 deletions
|
|
@ -355,29 +355,36 @@ void VulkanExampleBase::renderLoop()
|
|||
}
|
||||
}
|
||||
#elif defined(__ANDROID__)
|
||||
// todo : Application moved to background
|
||||
while (1)
|
||||
{
|
||||
// Read all pending events.
|
||||
int ident;
|
||||
int events;
|
||||
struct android_poll_source* source;
|
||||
bool destroy = false;
|
||||
|
||||
while ((ident = ALooper_pollAll(animating ? 0 : -1, NULL, &events, (void**)&source)) >= 0)
|
||||
focused = true;
|
||||
|
||||
while ((ident = ALooper_pollAll(focused ? 0 : -1, NULL, &events, (void**)&source)) >= 0)
|
||||
{
|
||||
if (source != NULL)
|
||||
{
|
||||
source->process(androidApp, source);
|
||||
}
|
||||
|
||||
if (androidApp->destroyRequested != 0)
|
||||
{
|
||||
// todo : free resources
|
||||
//delete(vulkanExample);
|
||||
return;
|
||||
LOGD("Android app destroy requested");
|
||||
destroy = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// App destruction requested
|
||||
// Exit loop, example will be destroyed in application main
|
||||
if (destroy)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// Render frame
|
||||
if (prepared)
|
||||
{
|
||||
|
|
@ -976,6 +983,7 @@ void VulkanExampleBase::handleAppCommand(android_app * app, int32_t cmd)
|
|||
switch (cmd)
|
||||
{
|
||||
case APP_CMD_SAVE_STATE:
|
||||
LOGD("APP_CMD_SAVE_STATE");
|
||||
/*
|
||||
vulkanExample->app->savedState = malloc(sizeof(struct saved_state));
|
||||
*((struct saved_state*)vulkanExample->app->savedState) = vulkanExample->state;
|
||||
|
|
@ -986,12 +994,10 @@ void VulkanExampleBase::handleAppCommand(android_app * app, int32_t cmd)
|
|||
LOGD("APP_CMD_INIT_WINDOW");
|
||||
if (vulkanExample->androidApp->window != NULL)
|
||||
{
|
||||
LOGI("Initializing Vulkan...");
|
||||
vulkanExample->initVulkan(false);
|
||||
vulkanExample->initSwapchain();
|
||||
vulkanExample->prepare();
|
||||
assert(vulkanExample->prepared);
|
||||
LOGI("Vulkan initialized");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -999,7 +1005,12 @@ void VulkanExampleBase::handleAppCommand(android_app * app, int32_t cmd)
|
|||
}
|
||||
break;
|
||||
case APP_CMD_LOST_FOCUS:
|
||||
//vulkanExample->animating = 0;
|
||||
LOGD("APP_CMD_LOST_FOCUS");
|
||||
vulkanExample->focused = false;
|
||||
break;
|
||||
case APP_CMD_GAINED_FOCUS:
|
||||
LOGD("APP_CMD_GAINED_FOCUS");
|
||||
vulkanExample->focused = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue