1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 14:57:35 +00:00

LibGfx+LibWeb: Use ref-counted object to store glyph run

...to avoid allocating a copy of glyph run for painting commands. We
can't simply save pointers to a glyph run in layout/paintable tree
because it should be safe to deallocate layout and paintable trees
after painting commands are recorded, if in the future we decide to
move command execution to a separate thread.
This commit is contained in:
Aliaksandr Kalenik 2024-03-01 16:37:44 +01:00 committed by Andreas Kling
parent cf6999f5f3
commit 06c176bbfb
9 changed files with 32 additions and 15 deletions

View file

@ -26,7 +26,7 @@ void LineBox::add_fragment(Node const& layout_node, int start, int length, CSSPi
m_fragments.last().set_width(m_fragments.last().width() + content_width);
for (auto glyph : glyph_run) {
glyph.visit([&](auto& glyph) { glyph.position.translate_by(fragment_width.to_float(), 0); });
m_fragments.last().m_glyph_run.append(glyph);
m_fragments.last().m_glyph_run->append(glyph);
}
} else {
Vector<Gfx::DrawGlyphOrEmoji> glyph_run_copy { glyph_run };

View file

@ -19,7 +19,7 @@ class LineBoxFragment {
friend class LineBox;
public:
LineBoxFragment(Node const& layout_node, int start, int length, CSSPixelPoint offset, CSSPixelSize size, CSSPixels border_box_top, CSSPixels border_box_bottom, Vector<Gfx::DrawGlyphOrEmoji> glyph_run = {})
LineBoxFragment(Node const& layout_node, int start, int length, CSSPixelPoint offset, CSSPixelSize size, CSSPixels border_box_top, CSSPixels border_box_bottom, Vector<Gfx::DrawGlyphOrEmoji> glyphs)
: m_layout_node(layout_node)
, m_start(start)
, m_length(length)
@ -27,7 +27,7 @@ public:
, m_size(size)
, m_border_box_top(border_box_top)
, m_border_box_bottom(border_box_bottom)
, m_glyph_run(move(glyph_run))
, m_glyph_run(adopt_ref(*new Gfx::GlyphRun(move(glyphs))))
{
}
@ -60,7 +60,7 @@ public:
bool is_atomic_inline() const;
Vector<Gfx::DrawGlyphOrEmoji> const& glyph_run() const { return m_glyph_run; }
Gfx::GlyphRun const& glyph_run() const { return *m_glyph_run; }
private:
JS::NonnullGCPtr<Node const> m_layout_node;
@ -71,7 +71,7 @@ private:
CSSPixels m_border_box_top { 0 };
CSSPixels m_border_box_bottom { 0 };
CSSPixels m_baseline { 0 };
Vector<Gfx::DrawGlyphOrEmoji> m_glyph_run;
NonnullRefPtr<Gfx::GlyphRun> m_glyph_run;
};
}