From bb52181bc594db44699cd42428289f2522d7ce3f Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Fri, 18 Aug 2017 08:46:41 +0200 Subject: [PATCH] menu_view: fix frame dropping after sleep When idle, menu_view de-schedules timer events to save processing time. Once reactivated by a dialog update, it computes the passed time and applies the result to the animator. However, the animation was most likely started by the update not during the sleep. So the passed time must not be applied to the animation in this case. Otherwise, many animation steps are computed at once within a single visible frame. Furthermore, the patch adjusts the REDRAW_PERIOD to 2, which is a better value for geometric movements as opposed to mere color-blending effects where the frame rate does not matter so much. It also refines the nitpicker-buffer relocation in a way that extends the buffer but does not shrink it. This lowers the interaction with nitpicker in situations where the dialog size changes a lot. --- repos/gems/src/app/menu_view/main.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/repos/gems/src/app/menu_view/main.cc b/repos/gems/src/app/menu_view/main.cc index 3ffc4e7dc6..2341be99e1 100644 --- a/repos/gems/src/app/menu_view/main.cc +++ b/repos/gems/src/app/menu_view/main.cc @@ -129,7 +129,7 @@ struct Menu_view::Main /** * Number of frames between two redraws */ - enum { REDRAW_PERIOD = 4 }; + enum { REDRAW_PERIOD = 2 }; /** * Counter used for triggering redraws. Incremented in each frame-timer @@ -177,10 +177,16 @@ void Menu_view::Main::_handle_dialog_update() * processing immediately. This way, we avoid latencies when the dialog * model is updated sporadically. */ - if (_timer.curr_frame() != _last_frame) + unsigned const curr_frame = _timer.curr_frame(); + if (curr_frame != _last_frame) { + + if (curr_frame - _last_frame > 10) + _last_frame = curr_frame; + _handle_frame_timer(); - else + } else { _timer.schedule(); + } } @@ -243,7 +249,7 @@ void Menu_view::Main::_handle_frame_timer() if (_animator.active()) { - unsigned const passed_frames = curr_frame - _last_frame; + unsigned const passed_frames = max(curr_frame - _last_frame, 4U); if (passed_frames > 0) { @@ -263,7 +269,7 @@ void Menu_view::Main::_handle_frame_timer() Area const old_size = _buffer.constructed() ? _buffer->size() : Area(); Area const size = _root_widget.min_size(); - if (!_buffer.constructed() || size != old_size) + if (!_buffer.constructed() || size.w() > old_size.w() || size.h() > old_size.h()) _buffer.construct(_nitpicker, size, _env.ram(), _env.rm()); else _buffer->reset_surface();