mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-10 10:09:14 +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:
parent
fa7f9b0f35
commit
426d1b7410
Notes:
sideshowbarker
2024-07-17 02:21:14 +09:00
Author: https://github.com/tomuta
Commit: 426d1b7410
Pull-request: https://github.com/SerenityOS/serenity/pull/18175
Reviewed-by: https://github.com/gmta
Reviewed-by: https://github.com/nico ✅
Reviewed-by: https://github.com/trflynn89
4 changed files with 36 additions and 26 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue