mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-01 00:38:48 +00:00
LibWeb+WebContent: Move display list rasterization off the main thread
The display list is an immutable data structure, so once it's created, rasterization can be moved to a separate thread. This allows more room for performing other tasks between processing HTML rendering tasks. This change makes PaintingSurface, ImmutableBitmap, and GlyphRun atomic ref-counted, as they are shared between the main and rendering threads by being included in the display list.
This commit is contained in:
parent
86b831750d
commit
24e2c402f5
Notes:
github-actions[bot]
2025-03-31 14:59:11 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: 24e2c402f5
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4152
16 changed files with 180 additions and 42 deletions
67
Libraries/LibWeb/HTML/RenderingThread.cpp
Normal file
67
Libraries/LibWeb/HTML/RenderingThread.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibWeb/HTML/RenderingThread.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
RenderingThread::RenderingThread()
|
||||
: m_main_thread_event_loop(Core::EventLoop::current())
|
||||
{
|
||||
}
|
||||
|
||||
RenderingThread::~RenderingThread()
|
||||
{
|
||||
m_exit = true;
|
||||
m_rendering_task_ready_wake_condition.signal();
|
||||
(void)m_thread->join();
|
||||
}
|
||||
|
||||
void RenderingThread::start()
|
||||
{
|
||||
VERIFY(m_skia_player);
|
||||
m_thread = Threading::Thread::construct([this] {
|
||||
rendering_thread_loop();
|
||||
return static_cast<intptr_t>(0);
|
||||
});
|
||||
m_thread->start();
|
||||
}
|
||||
|
||||
void RenderingThread::rendering_thread_loop()
|
||||
{
|
||||
while (true) {
|
||||
auto task = [this]() -> Optional<Task> {
|
||||
Threading::MutexLocker const locker { m_rendering_task_mutex };
|
||||
while (m_rendering_tasks.is_empty() && !m_exit) {
|
||||
m_rendering_task_ready_wake_condition.wait();
|
||||
}
|
||||
if (m_exit)
|
||||
return {};
|
||||
return m_rendering_tasks.dequeue();
|
||||
}();
|
||||
|
||||
if (!task.has_value()) {
|
||||
VERIFY(m_exit);
|
||||
break;
|
||||
}
|
||||
|
||||
m_skia_player->set_surface(task->painting_surface);
|
||||
m_skia_player->execute(*task->display_list);
|
||||
m_main_thread_event_loop.deferred_invoke([callback = move(task->callback)] {
|
||||
callback();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void RenderingThread::enqueue_rendering_task(RefPtr<Painting::DisplayList> display_list, NonnullRefPtr<Gfx::PaintingSurface> painting_surface, Function<void()>&& callback)
|
||||
{
|
||||
Threading::MutexLocker const locker { m_rendering_task_mutex };
|
||||
m_rendering_tasks.enqueue(Task { move(display_list), move(painting_surface), move(callback) });
|
||||
m_rendering_task_ready_wake_condition.signal();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue