request frame change in notification

This commit is contained in:
David Kocik 2021-02-08 17:42:20 +01:00
parent 32dd1f6e7c
commit 80f0d305c1
2 changed files with 26 additions and 15 deletions

View file

@ -547,15 +547,17 @@ bool NotificationManager::PopNotification::compare_text(const std::string& text)
return false; return false;
} }
void NotificationManager::PopNotification::update_state(bool paused, const int64_t delta) bool NotificationManager::PopNotification::update_state(bool paused, const int64_t delta)
{ {
if (m_state == EState::Unknown) if (m_state == EState::Unknown) {
init(); init();
return true;
}
m_next_render = std::numeric_limits<int64_t>::max(); m_next_render = std::numeric_limits<int64_t>::max();
if (m_state == EState::Hidden) { if (m_state == EState::Hidden) {
return; return false;
} }
int64_t now = GLCanvas3D::timestamp_now(); int64_t now = GLCanvas3D::timestamp_now();
@ -581,22 +583,25 @@ void NotificationManager::PopNotification::update_state(bool paused, const int64
m_current_fade_opacity = std::clamp(1.0f - 0.001f * static_cast<float>(curr_time) / FADING_OUT_DURATION, 0.0f, 1.0f); m_current_fade_opacity = std::clamp(1.0f - 0.001f * static_cast<float>(curr_time) / FADING_OUT_DURATION, 0.0f, 1.0f);
if (m_current_fade_opacity <= 0.0f) if (m_current_fade_opacity <= 0.0f)
m_state = EState::Finished; m_state = EState::Finished;
else if (next_render < 0) else if (next_render <= 20) {
m_next_render = 0; m_next_render = FADING_OUT_TIMEOUT;
return true;
}
else else
m_next_render = next_render; m_next_render = next_render;
} }
if (m_state == EState::Finished) { if (m_state == EState::Finished) {
m_next_render = 0; //m_next_render = 0;
return; return true;
} }
if (m_state == EState::ClosePending) { if (m_state == EState::ClosePending) {
m_state = EState::Finished; m_state = EState::Finished;
m_next_render = 0; //m_next_render = 0;
return; return true;
} }
return false;
} }
NotificationManager::SlicingCompleteLargeNotification::SlicingCompleteLargeNotification(const NotificationData& n, NotificationIDProvider& id_provider, wxEvtHandler* evt_handler, bool large) : NotificationManager::SlicingCompleteLargeNotification::SlicingCompleteLargeNotification(const NotificationData& n, NotificationIDProvider& id_provider, wxEvtHandler* evt_handler, bool large) :
@ -1034,6 +1039,7 @@ void NotificationManager::render_notifications(GLCanvas3D& canvas, float overlay
} }
} }
BOOST_LOG_TRIVIAL(error) << "render " << GLCanvas3D::timestamp_now() - m_last_render;
m_last_render = GLCanvas3D::timestamp_now(); m_last_render = GLCanvas3D::timestamp_now();
} }
@ -1051,6 +1057,7 @@ bool NotificationManager::update_notifications(GLCanvas3D& canvas)
const int64_t max = std::numeric_limits<int64_t>::max(); const int64_t max = std::numeric_limits<int64_t>::max();
int64_t next_render = max; int64_t next_render = max;
const int64_t time_since_render = GLCanvas3D::timestamp_now() - m_last_render; const int64_t time_since_render = GLCanvas3D::timestamp_now() - m_last_render;
bool request_render = false;
// During render, each notification detects if its currently hovered and changes its state to EState::Hovered // During render, each notification detects if its currently hovered and changes its state to EState::Hovered
// If any notification is hovered, all restarts its countdown // If any notification is hovered, all restarts its countdown
bool hover = false; bool hover = false;
@ -1063,7 +1070,7 @@ bool NotificationManager::update_notifications(GLCanvas3D& canvas)
// update state of all notif and erase finished // update state of all notif and erase finished
for (auto it = m_pop_notifications.begin(); it != m_pop_notifications.end();) { for (auto it = m_pop_notifications.begin(); it != m_pop_notifications.end();) {
std::unique_ptr<PopNotification>& notification = *it; std::unique_ptr<PopNotification>& notification = *it;
notification->update_state(hover, time_since_render); request_render |= notification->update_state(hover, time_since_render);
next_render = std::min<int64_t>(next_render, notification->next_render()); next_render = std::min<int64_t>(next_render, notification->next_render());
if (notification->get_state() == PopNotification::EState::Finished) if (notification->get_state() == PopNotification::EState::Finished)
it = m_pop_notifications.erase(it); it = m_pop_notifications.erase(it);
@ -1071,16 +1078,19 @@ bool NotificationManager::update_notifications(GLCanvas3D& canvas)
++it; ++it;
} }
BOOST_LOG_TRIVIAL(error) << "update " << request_render << " : " << next_render <<" : " << GLCanvas3D::timestamp_now() - m_last_update;
m_last_update = GLCanvas3D::timestamp_now();
//BOOST_LOG_TRIVIAL(error) << time_since_render << ":" << next_render;
// render needed right now // render needed right now
if (next_render < 20) //if (next_render < 20)
return true; // request_render = true;
// request next frame // request next frame
if (next_render < max) if (next_render < max)
canvas.schedule_extra_frame(int(next_render)); canvas.schedule_extra_frame(int(next_render));
return false; return request_render;
} }
>>>>>>> 6df0d8ff81... Notifications management and rendering refactoring.
void NotificationManager::sort_notifications() void NotificationManager::sort_notifications()
{ {

View file

@ -222,7 +222,7 @@ private:
bool compare_text(const std::string& text); bool compare_text(const std::string& text);
void hide(bool h) { m_state = h ? EState::Hidden : EState::Unknown; } void hide(bool h) { m_state = h ? EState::Hidden : EState::Unknown; }
// sets m_next_render with time of next mandatory rendering. Delta is time since last render. // sets m_next_render with time of next mandatory rendering. Delta is time since last render.
void update_state(bool paused, const int64_t delta); bool update_state(bool paused, const int64_t delta);
int64_t next_render() const { return is_finished() ? 0 : m_next_render; } int64_t next_render() const { return is_finished() ? 0 : m_next_render; }
EState get_state() const { return m_state; } EState get_state() const { return m_state; }
bool is_hovered() const { return m_state == EState::Hovered; } bool is_hovered() const { return m_state == EState::Hovered; }
@ -413,6 +413,7 @@ private:
bool m_move_from_overlay { false }; bool m_move_from_overlay { false };
// Timestamp of last rendering // Timestamp of last rendering
int64_t m_last_render { 0LL }; int64_t m_last_render { 0LL };
int64_t m_last_update { 0LL };
//prepared (basic) notifications //prepared (basic) notifications
const std::vector<NotificationData> basic_notifications = { const std::vector<NotificationData> basic_notifications = {