-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixes edge cases in Android Native App rendering #32
base: master
Are you sure you want to change the base?
Conversation
@@ -81,15 +84,39 @@ class AndroidAppBase : public AppBase | |||
android_app* app_ = nullptr; | |||
std::string native_activity_class_name_; | |||
|
|||
pthread_mutex_t mutex; | |||
pthread_cond_t cond; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for? Nothing waits on this conditional
@@ -81,15 +84,39 @@ class AndroidAppBase : public AppBase | |||
android_app* app_ = nullptr; | |||
std::string native_activity_class_name_; | |||
|
|||
pthread_mutex_t mutex; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to use std::mutex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, though i think std::mutex is slightly slower than pthread_mutex in terms of overhead, but i will switch to std::mutex
{ | ||
// Android lifecycle status flags. Not app-specific | ||
// Set between onCreate and onDestroy | ||
NV_APP_STATUS_RUNNING = 0x00000001, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for NV_ prefix
NV_APP_STATUS_INTERACTABLE = 0x0000000f | ||
}; | ||
|
||
unsigned int lifecycleFlags = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lifecycle_flags_ to be consistent with the rest
}; | ||
|
||
unsigned int lifecycleFlags = 0; | ||
int32_t window_width = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
window_width_
namespace Diligent | ||
{ | ||
|
||
AndroidAppBase::AndroidAppBase() { | ||
pthread_mutex_init(&mutex, NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to initialize if you use std::mutex
case APP_CMD_SAVE_STATE: | ||
case APP_CMD_INPUT_CHANGED: | ||
#if(LOG_NATIVE_APPLICATION) | ||
LOG_ERROR_MESSAGE("APP_CMD_INPUT_CHANGED"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to make it stand out in the log as it is important for seeing what is going on with the state of the native app internally when debugging the state, since errors have red text in logcat
//pthread_mutex_lock(&android_app->mutex); | ||
//if (android_app->inputQueue != NULL) { | ||
// AInputQueue_detachLooper(android_app->inputQueue); | ||
//} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this?
{ | ||
pthread_mutex_lock(&android_app->mutex); | ||
#if(LOG_NATIVE_APPLICATION) | ||
LOG_ERROR_MESSAGE("APP_CMD_INIT_WINDOW"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to make it stand out in the log as it is important for seeing what is going on with the state of the native app internally when debugging the state, since errors have red text in logcat
// The window is being shown, get it ready. | ||
if (app->window != NULL) | ||
{ | ||
pthread_mutex_lock(&android_app->mutex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::lock_guard lock{mutex};
here and in similar places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are 11 commits in this branch already. Please squash them into one.
APP_STATUS_HAS_REAL_SURFACE = 0x00000008, | ||
}; | ||
|
||
unsigned int lifecycleFlags_ = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
APP_STATUS_FLAGS app_status_ = APP_STATUS_FLAG_NONE
@@ -30,8 +30,12 @@ | |||
//#include <android/log.h> | |||
//#include <android_native_app_glue.h> | |||
#include <android/native_window_jni.h> | |||
#include <Errors.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Errors.hpp"
, this is not a system header
#if (LOG_NATIVE_APPLICATION) | ||
LOG_INFO_MESSAGE("HAS SURFACE"); | ||
#endif | ||
std::lock_guard<std::mutex> give_me_a_name(eng->mutex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lock{eng->mutex}
@@ -89,7 +91,24 @@ class AndroidAppBase : public AppBase | |||
void UpdateFPS(float fFPS); | |||
|
|||
bool initialized_resources_ = false; | |||
bool has_focus_ = false; | |||
|
|||
enum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest give it a name (e.g. APP_STATUS_FLAGS
) and use DEFINE_FLAG_ENUM_OPERATORS(APP_STATUS_FLAGS)
case APP_CMD_LOST_FOCUS: | ||
#if (LOG_NATIVE_APPLICATION) | ||
LOG_INFO_MESSAGE("APP_CMD_LOST_FOCUS"); | ||
LOG_INFO_MESSAGE("LOST FOCUS"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why extra message?
case APP_CMD_RESUME: | ||
#if (LOG_NATIVE_APPLICATION) | ||
LOG_INFO_MESSAGE("APP_CMD_RESUME"); | ||
LOG_INFO_MESSAGE("IS ACTIVE"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why extra message?
eng->has_focus_ = false; | ||
#if (LOG_NATIVE_APPLICATION) | ||
LOG_INFO_MESSAGE("APP_CMD_PAUSE"); | ||
LOG_INFO_MESSAGE("IS NOT ACTIVE"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why extra message?
case APP_CMD_DESTROY: | ||
#if (LOG_NATIVE_APPLICATION) | ||
LOG_INFO_MESSAGE("APP_CMD_DESTROY"); | ||
LOG_INFO_MESSAGE("IS NOT RUNNING"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why extra message?
|
||
return false; | ||
std::lock_guard<std::mutex> give_me_a_name(mutex); | ||
return lifecycleFlags_ & APP_STATUS_ACTIVE && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not look pretty.
(app_status_ & APP_STATUS_FLAG_ACTIVE) != APP_STATUS_FLAG_NONE
Would be clearer
is it possible to do this via github.com or would i manually need to do some |
You can force-push to the PR branch |
ok |
be09133
to
96ead7d
Compare
apparently force pushing a branch with no changes closes the pull request... |
58a9e7e
to
2d43095
Compare
case APP_CMD_INIT_WINDOW: | ||
// The window is being shown, get it ready. | ||
if (app->window != NULL) | ||
#if (DILIGENT_DEVLOPMENT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think it makes sense to always log this - there is really no reason not to...
Same for other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this?
case APP_CMD_INIT_WINDOW:
LOG_INFO_MESSAGE("APP_CMD_INIT_WINDOW");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logging of all events
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is this? 60f08d8
60f08d8
to
3d76fb8
Compare
is this better? |
67c0830
to
e09d30c
Compare
|
||
std::atomic<APP_STATUS_FLAGS> app_status_{APP_STATUS_FLAG_NONE}; | ||
|
||
int32_t window_width_ = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this variable is unused, i need to remove it when i have time
std::atomic<APP_STATUS_FLAGS> app_status_{APP_STATUS_FLAG_NONE}; | ||
|
||
int32_t window_width_ = 0; | ||
int32_t window_height_ = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this variable is unused, i need to remove it when i have time
Squashed commit of the following: commit ba7271f Author: mgood7123 <[email protected]> Date: Sat Jul 3 03:12:45 2021 +1000 use std::atomic instead of std::mutex commit 54e3973 Author: mgood7123 <[email protected]> Date: Tue Jun 29 07:52:35 2021 +1000 fixes edge cases in Android Native App rendering Revert "fix possible rendering edge cases" This reverts commit 3d76fb8. fix possible rendering edge cases Update AndroidMain.cpp add functions for app status apply validator suggestions Update AndroidAppBase.hpp Update AndroidAppBase.cpp remove unused variables
adapted from https://github.com/151706061/OpenGLSamples/blob/1e871c0c7fe0d8d30825f467bfdc8de50961b6f9/extensions/src/NvAppBase/NvAndroidNativeAppGlue.c#L128
this fixes possible rendering edge cases mentioned in https://developer.nvidia.com/fixing-common-android-lifecycle-issues-games