1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:47:44 +00:00

WindowServer: Only register animations when they're running

This allows us to keep Animation objects around, and the compositor
will only use them when the animation is actually running.
This commit is contained in:
Tom 2023-04-03 21:29:01 -06:00 committed by Linus Groh
parent fa7f9b0f35
commit 426d1b7410
4 changed files with 36 additions and 26 deletions

View file

@ -10,14 +10,9 @@
namespace WindowServer {
Animation::Animation()
{
Compositor::the().register_animation({}, *this);
}
Animation::~Animation()
{
if (!m_was_removed)
if (m_running)
Compositor::the().unregister_animation({}, *this);
}
@ -28,24 +23,36 @@ void Animation::set_duration(int duration_in_ms)
void Animation::start()
{
if (m_running)
return;
m_running = true;
m_timer.start();
Compositor::the().animation_started({});
Compositor::the().register_animation({}, *this);
}
void Animation::stop()
{
if (!m_running)
return;
m_running = false;
Compositor::the().unregister_animation({}, *this);
if (on_stop)
on_stop();
}
void Animation::call_stop_handler(Badge<Compositor>)
{
if (on_stop)
on_stop();
}
void Animation::was_removed(Badge<Compositor>)
{
m_was_removed = true;
m_running = false;
}
bool Animation::update(Badge<Compositor>, Gfx::Painter& painter, Screen& screen, Gfx::DisjointIntRectSet& flush_rects)
bool Animation::update(Gfx::Painter& painter, Screen& screen, Gfx::DisjointIntRectSet& flush_rects)
{
i64 const elapsed_ms = m_timer.elapsed();
float progress = min((float)elapsed_ms / (float)m_duration, 1.0f);