ladybird/Libraries/LibWeb/Painting/ScrollState.cpp
Aliaksandr Kalenik 6507d23e29 LibWeb: Save ScrollState snapshot in DisplayList to avoid race condition
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
2025-04-12 02:55:18 +02:00

20 lines
572 B
C++

/*
* Copyright (c) 2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Painting/ScrollState.h>
namespace Web::Painting {
ScrollStateSnapshot ScrollStateSnapshot::create(Vector<NonnullRefPtr<ScrollFrame>> const& scroll_frames)
{
ScrollStateSnapshot snapshot;
snapshot.entries.ensure_capacity(scroll_frames.size());
for (auto const& scroll_frame : scroll_frames)
snapshot.entries.append({ scroll_frame->cumulative_offset(), scroll_frame->own_offset() });
return snapshot;
}
}