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:
Aliaksandr Kalenik 2025-02-25 04:07:53 +01:00 committed by Alexander Kalenik
commit 24e2c402f5
Notes: github-actions[bot] 2025-03-31 14:59:11 +00:00
16 changed files with 180 additions and 42 deletions

View file

@ -9,12 +9,12 @@
#include <AK/Vector.h>
#include <LibWeb/HTML/Navigable.h>
#include <LibWeb/HTML/NavigationType.h>
#include <LibWeb/HTML/RenderingThread.h>
#include <LibWeb/HTML/SessionHistoryTraversalQueue.h>
#include <LibWeb/HTML/VisibilityState.h>
#include <LibWeb/Page/Page.h>
#include <LibWeb/Painting/DisplayListPlayerSkia.h>
#include <LibWeb/StorageAPI/StorageShed.h>
#include <WebContent/BackingStoreManager.h>
#ifdef AK_OS_MACOS
# include <LibGfx/MetalContext.h>
@ -97,7 +97,8 @@ public:
[[nodiscard]] GC::Ptr<DOM::Node> currently_focused_area();
void paint(Web::DevicePixelRect const&, Painting::BackingStore&, Web::PaintOptions);
RefPtr<Painting::DisplayList> record_display_list(DevicePixelRect const&, PaintOptions);
void start_display_list_rendering(RefPtr<Painting::DisplayList> display_list, NonnullRefPtr<Gfx::PaintingSurface> painting_surface, Function<void()>&& callback);
enum class CheckIfUnloadingIsCanceledResult {
CanceledByBeforeUnload,
@ -116,6 +117,8 @@ public:
bool needs_repaint() const { return m_needs_repaint; }
void set_needs_repaint() { m_needs_repaint = true; }
NonnullRefPtr<Gfx::PaintingSurface> painting_surface_for_backing_store(Painting::BackingStore&);
private:
TraversableNavigable(GC::Ref<Page>);
@ -137,8 +140,6 @@ private:
[[nodiscard]] bool can_go_forward() const;
NonnullRefPtr<Gfx::PaintingSurface> painting_surface_for_backing_store(Painting::BackingStore&);
// https://html.spec.whatwg.org/multipage/document-sequences.html#tn-current-session-history-step
int m_current_session_history_step { 0 };
@ -162,10 +163,11 @@ private:
String m_window_handle;
RefPtr<Gfx::SkiaBackendContext> m_skia_backend_context;
OwnPtr<Painting::DisplayListPlayerSkia> m_skia_player;
HashMap<Gfx::Bitmap*, NonnullRefPtr<Gfx::PaintingSurface>> m_bitmap_to_surface;
bool m_needs_repaint { true };
RenderingThread m_rendering_thread;
};
struct BrowsingContextAndDocument {