mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 10:07:15 +02:00
Integrate AccumulatedVisualContext with display list recording and playback. This is the main commit of the refactoring that delivers the architectural improvements enabled by AccumulatedVisualContext. Recording changes: Each display list command now stores a single RefPtr<AccumulatedVisualContext> instead of separate scroll_frame_id and ClipFrame. The recorder simply captures the current accumulated context when appending commands. The before_paint()/after_paint() hooks that pushed/popped scroll frame IDs are replaced by directly setting accumulated_visual_context on the recorder before painting each element. Playback changes: The display list player now uses LCA (Lowest Common Ancestor) based traversal to switch between visual contexts efficiently. When transitioning from context A to context B: 1. Find the LCA of A and B in the context tree 2. Pop (restore) states back to the LCA depth 3. Push (save + apply) states from LCA down to B This approach minimizes redundant save/restore operations. For example, when rendering siblings that share a common scroll container, the player keeps that scroll state applied and only switches the divergent parts of their context chains. Key deletions: - Remove translate_by() from all 45 display list commands - commands are now immutable - Remove transform/perspective fields from PushStackingContext - transforms are tracked via AccumulatedVisualContext - Remove push_scroll_frame_id()/pop_scroll_frame_id() from DisplayListRecorder - Remove before_paint()/after_paint() hooks from Paintable - Merge ApplyOpacity, ApplyCompositeAndBlendingOperator, ApplyFilter into single ApplyEffects command Stacking context painting changes: The StackingContext::paint() method is significantly simplified. Instead of building a PushStackingContextParams struct with transform matrices and pushing/popping stacking contexts, it now: 1. Sets the accumulated visual context (which already contains transforms) 2. Applies effects (opacity, blend mode, filters) if needed 3. Applies clip path if needed 4. Paints the content 5. Restores state The visual state management that was interleaved throughout the painting code is now handled uniformly by the context tree.
58 lines
1.6 KiB
C++
58 lines
1.6 KiB
C++
/*
|
|
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/RefCounted.h>
|
|
#include <LibGC/Weak.h>
|
|
#include <LibWeb/Forward.h>
|
|
#include <LibWeb/PixelUnits.h>
|
|
|
|
namespace Web::Painting {
|
|
|
|
class ScrollFrame : public RefCounted<ScrollFrame> {
|
|
public:
|
|
ScrollFrame(PaintableBox const& paintable_box, size_t id, bool sticky, RefPtr<ScrollFrame const> parent);
|
|
|
|
PaintableBox const& paintable_box() const { return *m_paintable_box; }
|
|
|
|
size_t id() const { return m_id; }
|
|
|
|
bool is_sticky() const { return m_sticky; }
|
|
|
|
CSSPixelPoint cumulative_offset() const
|
|
{
|
|
return m_cached_cumulative_offset.ensure([&] {
|
|
auto offset = m_own_offset;
|
|
if (m_parent)
|
|
offset += m_parent->cumulative_offset();
|
|
return offset;
|
|
});
|
|
}
|
|
|
|
CSSPixelPoint own_offset() const { return m_own_offset; }
|
|
void set_own_offset(CSSPixelPoint offset)
|
|
{
|
|
m_cached_cumulative_offset.clear();
|
|
m_own_offset = offset;
|
|
}
|
|
|
|
RefPtr<ScrollFrame const> parent() const { return m_parent; }
|
|
|
|
private:
|
|
GC::Weak<PaintableBox> m_paintable_box;
|
|
size_t m_id { 0 };
|
|
bool m_sticky { false };
|
|
RefPtr<ScrollFrame const> m_parent;
|
|
CSSPixelPoint m_own_offset;
|
|
|
|
// Caching here relies on the fact that offsets of all scroll frames are invalidated when any of them changes,
|
|
// so we don't need to worry about invalidating the cache when the parent's offset changes.
|
|
mutable Optional<CSSPixelPoint> m_cached_cumulative_offset;
|
|
};
|
|
|
|
}
|