mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibWeb: Make 2D canvas save/restore perform save/restore on painter
This ensures that any internal state maintained by the painter gets synchronized appropriately.
This commit is contained in:
parent
8540954bf8
commit
0d57de4236
Notes:
github-actions[bot]
2024-08-20 07:37:26 +00:00
Author: https://github.com/awesomekling
Commit: 0d57de4236
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1024
3 changed files with 13 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibGfx/Painter.h>
|
||||||
#include <LibWeb/HTML/Canvas/CanvasState.h>
|
#include <LibWeb/HTML/Canvas/CanvasState.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
@ -15,6 +16,9 @@ void CanvasState::save()
|
||||||
{
|
{
|
||||||
// The save() method steps are to push a copy of the current drawing state onto the drawing state stack.
|
// The save() method steps are to push a copy of the current drawing state onto the drawing state stack.
|
||||||
m_drawing_state_stack.append(m_drawing_state);
|
m_drawing_state_stack.append(m_drawing_state);
|
||||||
|
|
||||||
|
if (auto* painter = painter_for_canvas_state())
|
||||||
|
painter->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-restore
|
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-restore
|
||||||
|
@ -24,6 +28,9 @@ void CanvasState::restore()
|
||||||
if (m_drawing_state_stack.is_empty())
|
if (m_drawing_state_stack.is_empty())
|
||||||
return;
|
return;
|
||||||
m_drawing_state = m_drawing_state_stack.take_last();
|
m_drawing_state = m_drawing_state_stack.take_last();
|
||||||
|
|
||||||
|
if (auto* painter = painter_for_canvas_state())
|
||||||
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-reset
|
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-reset
|
||||||
|
|
|
@ -26,6 +26,9 @@ class CanvasState {
|
||||||
public:
|
public:
|
||||||
virtual ~CanvasState() = default;
|
virtual ~CanvasState() = default;
|
||||||
|
|
||||||
|
virtual Gfx::Painter* painter_for_canvas_state() = 0;
|
||||||
|
virtual Gfx::Path& path_for_canvas_state() = 0;
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
void restore();
|
void restore();
|
||||||
void reset();
|
void reset();
|
||||||
|
|
|
@ -106,6 +106,9 @@ private:
|
||||||
virtual void initialize(JS::Realm&) override;
|
virtual void initialize(JS::Realm&) override;
|
||||||
virtual void visit_edges(Cell::Visitor&) override;
|
virtual void visit_edges(Cell::Visitor&) override;
|
||||||
|
|
||||||
|
virtual Gfx::Painter* painter_for_canvas_state() override { return painter(); }
|
||||||
|
virtual Gfx::Path& path_for_canvas_state() override { return path(); }
|
||||||
|
|
||||||
struct PreparedTextGlyph {
|
struct PreparedTextGlyph {
|
||||||
String glyph;
|
String glyph;
|
||||||
Gfx::IntPoint position;
|
Gfx::IntPoint position;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue