mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-16 05:51:55 +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
52
Libraries/LibWeb/HTML/RenderingThread.h
Normal file
52
Libraries/LibWeb/HTML/RenderingThread.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Noncopyable.h>
|
||||
#include <AK/Queue.h>
|
||||
#include <LibThreading/ConditionVariable.h>
|
||||
#include <LibThreading/Mutex.h>
|
||||
#include <LibThreading/Thread.h>
|
||||
#include <LibWeb/Painting/DisplayListPlayerSkia.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
class RenderingThread {
|
||||
AK_MAKE_NONCOPYABLE(RenderingThread);
|
||||
AK_MAKE_NONMOVABLE(RenderingThread);
|
||||
|
||||
public:
|
||||
RenderingThread();
|
||||
~RenderingThread();
|
||||
|
||||
void start();
|
||||
void set_skia_player(OwnPtr<Painting::DisplayListPlayerSkia>&& player) { m_skia_player = move(player); }
|
||||
void enqueue_rendering_task(RefPtr<Painting::DisplayList>, NonnullRefPtr<Gfx::PaintingSurface>, Function<void()>&& callback);
|
||||
|
||||
private:
|
||||
void rendering_thread_loop();
|
||||
|
||||
Core::EventLoop& m_main_thread_event_loop;
|
||||
|
||||
OwnPtr<Painting::DisplayListPlayerSkia> m_skia_player;
|
||||
|
||||
RefPtr<Threading::Thread> m_thread;
|
||||
Atomic<bool> m_exit { false };
|
||||
|
||||
struct Task {
|
||||
RefPtr<Painting::DisplayList> display_list;
|
||||
NonnullRefPtr<Gfx::PaintingSurface> painting_surface;
|
||||
Function<void()> callback;
|
||||
};
|
||||
// NOTE: Queue will only contain multiple items in case tasks were scheduled by screenshot requests.
|
||||
// Otherwise, it will contain only one item at a time.
|
||||
Queue<Task> m_rendering_tasks;
|
||||
Threading::Mutex m_rendering_task_mutex;
|
||||
Threading::ConditionVariable m_rendering_task_ready_wake_condition { m_rendering_task_mutex };
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue