LibWeb: Make DisplayList ref-counted

This change is a preparation for the upcoming changes where display
list will be nested and the same display could be owned by multiple
display list items.
This commit is contained in:
Aliaksandr Kalenik 2024-07-24 18:48:14 +03:00 committed by Andreas Kling
commit 50ab5642cc
Notes: github-actions[bot] 2024-07-25 12:34:42 +00:00
4 changed files with 12 additions and 5 deletions

View file

@ -1190,7 +1190,7 @@ JS::GCPtr<DOM::Node> TraversableNavigable::currently_focused_area()
void TraversableNavigable::paint(DevicePixelRect const& content_rect, Painting::BackingStore& target, PaintOptions paint_options) void TraversableNavigable::paint(DevicePixelRect const& content_rect, Painting::BackingStore& target, PaintOptions paint_options)
{ {
Painting::DisplayList display_list; auto display_list = Painting::DisplayList::create();
Painting::DisplayListRecorder display_list_recorder(display_list); Painting::DisplayListRecorder display_list_recorder(display_list);
Gfx::IntRect bitmap_rect { {}, content_rect.size().to_type<int>() }; Gfx::IntRect bitmap_rect { {}, content_rect.size().to_type<int>() };

View file

@ -73,8 +73,13 @@ private:
virtual bool would_be_fully_clipped_by_painter(Gfx::IntRect) const = 0; virtual bool would_be_fully_clipped_by_painter(Gfx::IntRect) const = 0;
}; };
class DisplayList { class DisplayList : public RefCounted<DisplayList> {
public: public:
static NonnullRefPtr<DisplayList> create()
{
return adopt_ref(*new DisplayList());
}
void append(Command&& command, Optional<i32> scroll_frame_id); void append(Command&& command, Optional<i32> scroll_frame_id);
void apply_scroll_offsets(Vector<Gfx::IntPoint> const& offsets_by_frame_id); void apply_scroll_offsets(Vector<Gfx::IntPoint> const& offsets_by_frame_id);
@ -89,6 +94,8 @@ public:
AK::SegmentedVector<CommandListItem, 512> const& commands() const { return m_commands; } AK::SegmentedVector<CommandListItem, 512> const& commands() const { return m_commands; }
private: private:
DisplayList() = default;
AK::SegmentedVector<CommandListItem, 512> m_commands; AK::SegmentedVector<CommandListItem, 512> m_commands;
}; };

View file

@ -81,8 +81,8 @@ RefPtr<Gfx::Bitmap> SVGMaskable::calculate_mask_of_svg(PaintContext& context, CS
if (mask_bitmap_or_error.is_error()) if (mask_bitmap_or_error.is_error())
return {}; return {};
mask_bitmap = mask_bitmap_or_error.release_value(); mask_bitmap = mask_bitmap_or_error.release_value();
DisplayList display_list; auto display_list = DisplayList::create();
DisplayListRecorder display_list_recorder(display_list); DisplayListRecorder display_list_recorder(*display_list);
display_list_recorder.translate(-mask_rect.location().to_type<int>()); display_list_recorder.translate(-mask_rect.location().to_type<int>());
auto paint_context = context.clone(display_list_recorder); auto paint_context = context.clone(display_list_recorder);
paint_context.set_svg_transform(graphics_element.get_transform()); paint_context.set_svg_transform(graphics_element.get_transform());

View file

@ -92,7 +92,7 @@ RefPtr<Gfx::Bitmap> SVGDecodedImageData::render(Gfx::IntSize size) const
m_document->navigable()->set_viewport_size(size.to_type<CSSPixels>()); m_document->navigable()->set_viewport_size(size.to_type<CSSPixels>());
m_document->update_layout(); m_document->update_layout();
Painting::DisplayList display_list; auto display_list = Painting::DisplayList::create();
Painting::DisplayListRecorder display_list_recorder(display_list); Painting::DisplayListRecorder display_list_recorder(display_list);
m_document->navigable()->record_display_list(display_list_recorder, {}); m_document->navigable()->record_display_list(display_list_recorder, {});