Skip to content

Truly independent web browser

LibWeb: Read a decode's images from its observers, not the style

Andreas Klingcad05485cfac
diff --git a/Libraries/LibWeb/Layout/Node.cpp b/Libraries/LibWeb/Layout/Node.cpp
index 822a5cedd39..522162477cb 100644
--- a/Libraries/LibWeb/Layout/Node.cpp
+++ b/Libraries/LibWeb/Layout/Node.cpp
@@ -327,6 +327,9 @@ void NodeWithStyle::rebuild_image_observers(Vector<RefPtr<CSS::CursorStyleValue
background_image_element = pseudo_element_generator().ptr();
auto new_observers = make<ImageObserverSlots>();
+ new_observers->background_images = Vector<RefPtr<CSS::AbstractImageStyleValue const>> { background_images() };
+ new_observers->mask_images = Vector<RefPtr<CSS::AbstractImageStyleValue const>> { mask_images() };
+ new_observers->border_image_source_value = border_image_source();
for (auto const& image : background_images()) {
auto observer = observer_for(image.ptr());
if (observer && background_image_element)
diff --git a/Libraries/LibWeb/Layout/Node.h b/Libraries/LibWeb/Layout/Node.h
index f38714c9648..be5d8dd3bf6 100644
--- a/Libraries/LibWeb/Layout/Node.h
+++ b/Libraries/LibWeb/Layout/Node.h
@@ -352,6 +352,11 @@ public:
AK_ALLOC_WITH_KMALLOC;
Vector<RefPtr<CSS::CursorStyleValue const>> cursor_style_values;
+ // NB: The images these observers paint with, which a decode beside a frame in flight reads, as the frame may
+ // have swept the style the node last read.
+ Vector<RefPtr<CSS::AbstractImageStyleValue const>> background_images;
+ Vector<RefPtr<CSS::AbstractImageStyleValue const>> mask_images;
+ RefPtr<CSS::AbstractImageStyleValue const> border_image_source_value;
Vector<OwnPtr<ImageObserver>> background_layers;
Vector<OwnPtr<ImageObserver>> mask_layers;
Vector<OwnPtr<ImageObserver>> cursors;
@@ -359,6 +364,7 @@ public:
OwnPtr<ImageObserver> list_style_image;
};
+ ImageObserverSlots const* image_observers() const;
ImageObserver const* background_image_observer(size_t layer_index) const;
ImageObserver const* mask_image_observer(size_t layer_index) const;
ImageObserver const* cursor_image_observer(size_t cursor_index) const;
@@ -548,7 +554,6 @@ private:
void did_update_style_record();
void rebuild_image_observers(Vector<RefPtr<CSS::CursorStyleValue const>>);
- ImageObserverSlots const* image_observers() const;
void const* m_style_record { nullptr };
// Whether the row holds a pin of its style record for C++'s readers, which only this layout node takes and drops.
bool m_style_record_pinned_for_cxx_consumers { false };
diff --git a/Libraries/LibWeb/Painting/PaintFacts.cpp b/Libraries/LibWeb/Painting/PaintFacts.cpp
index 077f509948c..b2ea7586cab 100644
--- a/Libraries/LibWeb/Painting/PaintFacts.cpp
+++ b/Libraries/LibWeb/Painting/PaintFacts.cpp
@@ -182,13 +182,16 @@ static GC::Ptr<HTML::DecodedImageData> decoded_image_data_of(Layout::NodeWithSty
return observer->decoded_image_data();
}
+// NB: This reads the images the node's observers hold rather than its style: it also runs as an image decodes beside a
+// frame in flight, which may have swept the record the node's style points to.
static void push_layer_image_paint_facts_onto(Layout::NodeWithStyle const& layout_node)
{
- auto background_images = layout_node.background_images();
- auto mask_images = layout_node.mask_images();
+ auto const* observers = layout_node.image_observers();
+ if (!observers)
+ return;
Vector<Layout::RustFFI::FfiLayerImagePaintFactsEntry> entries;
Vector<Optional<Gfx::DecodedImageFrame>> current_frames;
- current_frames.ensure_capacity(background_images.size() + mask_images.size() + 1);
+ current_frames.ensure_capacity(observers->background_images.size() + observers->mask_images.size() + 1);
auto append_entry = [&](Layout::RustFFI::FfiLayerImageList list, size_t computed_index, CSS::AbstractImageStyleValue const* image, Layout::NodeWithStyle::ImageObserver const* observer) {
if (!image)
return;
@@ -199,11 +202,11 @@ static void push_layer_image_paint_facts_onto(Layout::NodeWithStyle const& layou
.facts = layer_image_paint_facts_for(*image, decoded_image_data_of(observer), current_frames.last()),
});
};
- for (size_t layer_index = 0; layer_index < background_images.size(); ++layer_index)
- append_entry(Layout::RustFFI::FfiLayerImageList::Background, layer_index, background_images[layer_index].ptr(), layout_node.background_image_observer(layer_index));
- for (size_t layer_index = 0; layer_index < mask_images.size(); ++layer_index)
- append_entry(Layout::RustFFI::FfiLayerImageList::Mask, layer_index, mask_images[layer_index].ptr(), layout_node.mask_image_observer(layer_index));
- append_entry(Layout::RustFFI::FfiLayerImageList::BorderImageSource, 0, layout_node.border_image_source(), layout_node.border_image_source_observer());
+ for (size_t layer_index = 0; layer_index < observers->background_images.size(); ++layer_index)
+ append_entry(Layout::RustFFI::FfiLayerImageList::Background, layer_index, observers->background_images[layer_index].ptr(), observers->background_layers[layer_index].ptr());
+ for (size_t layer_index = 0; layer_index < observers->mask_images.size(); ++layer_index)
+ append_entry(Layout::RustFFI::FfiLayerImageList::Mask, layer_index, observers->mask_images[layer_index].ptr(), observers->mask_layers[layer_index].ptr());
+ append_entry(Layout::RustFFI::FfiLayerImageList::BorderImageSource, 0, observers->border_image_source_value.ptr(), observers->border_image_source.ptr());
Layout::RustFFI::render_state_set_layer_image_paint_facts(layout_node.document_host(), Layout::Node::slot_id(&layout_node), entries.data(), entries.size());
}