mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-05 07:41:01 +00:00
LibWeb: Allocate AnimationFrameCallbackDriver on the JS heap
This avoids needing to creating root handles for each heap-allocated object captured in the animation callback. An upcoming commit would add several of these.
This commit is contained in:
parent
144907f5bd
commit
d9e5ae66a7
Notes:
github-actions[bot]
2024-10-31 02:40:42 +00:00
Author: https://github.com/trflynn89
Commit: d9e5ae66a7
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2071
Reviewed-by: https://github.com/tcl3 ✅
7 changed files with 88 additions and 44 deletions
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
* Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/HTML/AnimationFrameCallbackDriver.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(AnimationFrameCallbackDriver);
|
||||
|
||||
void AnimationFrameCallbackDriver::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_callbacks);
|
||||
}
|
||||
|
||||
WebIDL::UnsignedLong AnimationFrameCallbackDriver::add(Callback handler)
|
||||
{
|
||||
auto id = ++m_animation_frame_callback_identifier;
|
||||
m_callbacks.set(id, handler);
|
||||
return id;
|
||||
}
|
||||
|
||||
bool AnimationFrameCallbackDriver::remove(WebIDL::UnsignedLong id)
|
||||
{
|
||||
return m_callbacks.remove(id);
|
||||
}
|
||||
|
||||
bool AnimationFrameCallbackDriver::has_callbacks() const
|
||||
{
|
||||
return !m_callbacks.is_empty();
|
||||
}
|
||||
|
||||
void AnimationFrameCallbackDriver::run(double now)
|
||||
{
|
||||
auto taken_callbacks = move(m_callbacks);
|
||||
for (auto& [id, callback] : taken_callbacks)
|
||||
callback->function()(now);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue