Преглед изворни кода

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.
Aliaksandr Kalenik пре 11 месеци
родитељ
комит
50ab5642cc

+ 1 - 1
Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp

@@ -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)
 {
-    Painting::DisplayList display_list;
+    auto display_list = Painting::DisplayList::create();
     Painting::DisplayListRecorder display_list_recorder(display_list);
 
     Gfx::IntRect bitmap_rect { {}, content_rect.size().to_type<int>() };

+ 8 - 1
Userland/Libraries/LibWeb/Painting/DisplayList.h

@@ -73,8 +73,13 @@ private:
     virtual bool would_be_fully_clipped_by_painter(Gfx::IntRect) const = 0;
 };
 
-class DisplayList {
+class DisplayList : public RefCounted<DisplayList> {
 public:
+    static NonnullRefPtr<DisplayList> create()
+    {
+        return adopt_ref(*new DisplayList());
+    }
+
     void append(Command&& command, Optional<i32> scroll_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; }
 
 private:
+    DisplayList() = default;
+
     AK::SegmentedVector<CommandListItem, 512> m_commands;
 };
 

+ 2 - 2
Userland/Libraries/LibWeb/Painting/SVGMaskable.cpp

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

+ 1 - 1
Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp

@@ -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->update_layout();
 
-    Painting::DisplayList display_list;
+    auto display_list = Painting::DisplayList::create();
     Painting::DisplayListRecorder display_list_recorder(display_list);
 
     m_document->navigable()->record_display_list(display_list_recorder, {});