LibGfx: Add a method to reset a Painter to its initial state

This commit is contained in:
Tim Ledbetter 2025-10-21 17:47:15 +01:00 committed by Jelle Raaijmakers
parent dbf041aa98
commit 017e8a5b8d
Notes: github-actions[bot] 2025-10-23 16:53:48 +00:00
3 changed files with 14 additions and 0 deletions

View file

@ -43,6 +43,8 @@ public:
virtual void restore() = 0;
virtual void clip(Gfx::Path const&, Gfx::WindingRule) = 0;
virtual void reset() = 0;
};
}

View file

@ -134,6 +134,9 @@ static SkPaint to_skia_paint(Gfx::PaintStyle const& style, Optional<Gfx::Filter
PainterSkia::PainterSkia(NonnullRefPtr<Gfx::PaintingSurface> painting_surface)
: m_impl(adopt_own(*new Impl { move(painting_surface) }))
{
m_impl->with_canvas([this](auto& canvas) {
m_initial_save_count = canvas.save();
});
}
PainterSkia::~PainterSkia() = default;
@ -335,4 +338,11 @@ void PainterSkia::clip(Gfx::Path const& path, Gfx::WindingRule winding_rule)
});
}
void PainterSkia::reset()
{
impl().with_canvas([&](auto& canvas) {
canvas.restoreToCount(m_initial_save_count);
});
}
}

View file

@ -32,11 +32,13 @@ public:
virtual void save() override;
virtual void restore() override;
virtual void clip(Gfx::Path const&, Gfx::WindingRule) override;
virtual void reset() override;
private:
struct Impl;
Impl& impl() { return *m_impl; }
NonnullOwnPtr<Impl> m_impl;
u32 m_initial_save_count { 0 };
};
}