Skip to content
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

Fix android low processor usage mode flicker 3.x #55604

28 changes: 20 additions & 8 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,7 @@ bool Main::start() {
uint64_t Main::last_ticks = 0;
uint32_t Main::frames = 0;
uint32_t Main::frame = 0;
bool Main::force_redraw_requested = false;
uint32_t Main::force_redraw_frames = 0;
int Main::iterating = 0;
bool Main::agile_input_event_flushing = false;

Expand Down Expand Up @@ -2178,6 +2178,8 @@ bool Main::iteration() {
uint64_t physics_process_ticks = 0;
uint64_t idle_process_ticks = 0;

bool draw = false;

frame += ticks_elapsed;

last_ticks = ticks;
Expand Down Expand Up @@ -2240,15 +2242,25 @@ bool Main::iteration() {
VisualServer::get_singleton()->sync(); //sync if still drawing from previous frames.

if (OS::get_singleton()->can_draw() && VisualServer::get_singleton()->is_render_loop_enabled()) {
if ((!force_redraw_requested) && OS::get_singleton()->is_in_low_processor_usage_mode()) {
draw = true;
if (OS::get_singleton()->is_in_low_processor_usage_mode()) {
if (VisualServer::get_singleton()->has_changed()) {
VisualServer::get_singleton()->draw(true, scaled_step); // flush visual commands
Engine::get_singleton()->frames_drawn++;
draw = true;
#ifdef ANDROID_ENABLED
// On Android in low_processor_usage_mode there can be horrible flickering when it stops drawing
// Fix by force drawing 2 more frames after last changed frame.
force_redraw_frames = 3; // needs to be 3 to draw 2 more after this frame
#endif
} else {
draw = false;
}
} else {
}

if (draw || force_redraw_frames > 0) {
VisualServer::get_singleton()->draw(true, scaled_step); // flush visual commands
Engine::get_singleton()->frames_drawn++;
force_redraw_requested = false;
if (force_redraw_frames > 0)
force_redraw_frames--;
}
}

Expand Down Expand Up @@ -2328,8 +2340,8 @@ bool Main::iteration() {
return exit || auto_quit;
}

void Main::force_redraw() {
force_redraw_requested = true;
void Main::force_redraw(uint32_t frames) {
force_redraw_frames = frames;
}

/* Engine deinitialization
Expand Down
4 changes: 2 additions & 2 deletions main/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Main {
static uint64_t last_ticks;
static uint32_t frames;
static uint32_t frame;
static bool force_redraw_requested;
static uint32_t force_redraw_frames;
static int iterating;
static bool agile_input_event_flushing;

Expand All @@ -52,7 +52,7 @@ class Main {
static bool start();

static bool iteration();
static void force_redraw();
static void force_redraw(uint32_t frames = 1);

static bool is_iterating();

Expand Down
1 change: 1 addition & 0 deletions platform/android/os_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ void OS_Android::init_video_mode(int p_video_width, int p_video_height) {
void OS_Android::set_display_size(Size2 p_size) {
default_videomode.width = p_size.x;
default_videomode.height = p_size.y;
Main::force_redraw(3); // fix flicker if in low_processor_mode
}

Error OS_Android::shell_open(String p_uri) {
Expand Down