mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 22:08:59 +00:00
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
With this change we save a copy of of scroll state at the time of recording a display list, instead of actual ScrollState pointer that could be modifed by the main thread while display list is beings rasterized on the rendering thread, which leads to a frame painted with inconsistent scroll state. Fixes https://github.com/LadybirdBrowser/ladybird/issues/4288
63 lines
2.2 KiB
C++
63 lines
2.2 KiB
C++
/*
|
|
* 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/Forward.h>
|
|
#include <LibWeb/Page/Page.h>
|
|
#include <LibWeb/Painting/DisplayListPlayerSkia.h>
|
|
|
|
namespace Web::HTML {
|
|
|
|
class RenderingThread {
|
|
AK_MAKE_NONCOPYABLE(RenderingThread);
|
|
AK_MAKE_NONMOVABLE(RenderingThread);
|
|
|
|
public:
|
|
RenderingThread();
|
|
~RenderingThread();
|
|
|
|
void start(DisplayListPlayerType);
|
|
void set_skia_player(OwnPtr<Painting::DisplayListPlayerSkia>&& player) { m_skia_player = move(player); }
|
|
void set_skia_backend_context(RefPtr<Gfx::SkiaBackendContext> context) { m_skia_backend_context = move(context); }
|
|
void enqueue_rendering_task(NonnullRefPtr<Painting::DisplayList>, Painting::ScrollStateSnapshot&&, NonnullRefPtr<Painting::BackingStore>, Function<void()>&& callback);
|
|
void clear_bitmap_to_surface_cache();
|
|
|
|
private:
|
|
void rendering_thread_loop();
|
|
NonnullRefPtr<Gfx::PaintingSurface> painting_surface_for_backing_store(Painting::BackingStore& backing_store);
|
|
|
|
Core::EventLoop& m_main_thread_event_loop;
|
|
DisplayListPlayerType m_display_list_player_type;
|
|
|
|
OwnPtr<Painting::DisplayListPlayerSkia> m_skia_player;
|
|
RefPtr<Gfx::SkiaBackendContext> m_skia_backend_context;
|
|
|
|
RefPtr<Threading::Thread> m_thread;
|
|
Atomic<bool> m_exit { false };
|
|
|
|
struct Task {
|
|
NonnullRefPtr<Painting::DisplayList> display_list;
|
|
Painting::ScrollStateSnapshot scroll_state_snapshot;
|
|
NonnullRefPtr<Painting::BackingStore> backing_store;
|
|
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 };
|
|
|
|
HashMap<Gfx::Bitmap*, NonnullRefPtr<Gfx::PaintingSurface>> m_bitmap_to_surface;
|
|
bool m_needs_to_clear_bitmap_to_surface_cache { false };
|
|
};
|
|
|
|
}
|