mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 20:29:18 +00:00
LibWeb: Flush 2D canvas transformation matrix after making changes to it
This commit is contained in:
parent
5aeb8ebebc
commit
feae36f218
Notes:
github-actions[bot]
2024-08-20 07:37:41 +00:00
Author: https://github.com/awesomekling
Commit: feae36f218
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1024
1 changed files with 12 additions and 5 deletions
|
@ -26,18 +26,21 @@ public:
|
|||
dbgln_if(CANVAS_RENDERING_CONTEXT_2D_DEBUG, "CanvasTransform::scale({}, {})", sx, sy);
|
||||
|
||||
my_drawing_state().transform.scale(sx, sy);
|
||||
flush_transform();
|
||||
}
|
||||
|
||||
void translate(float tx, float ty)
|
||||
{
|
||||
dbgln_if(CANVAS_RENDERING_CONTEXT_2D_DEBUG, "CanvasTransform::translate({}, {})", tx, ty);
|
||||
my_drawing_state().transform.translate(tx, ty);
|
||||
flush_transform();
|
||||
}
|
||||
|
||||
void rotate(float radians)
|
||||
{
|
||||
dbgln_if(CANVAS_RENDERING_CONTEXT_2D_DEBUG, "CanvasTransform::rotate({})", radians);
|
||||
my_drawing_state().transform.rotate_radians(radians);
|
||||
flush_transform();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-transform
|
||||
|
@ -52,6 +55,7 @@ public:
|
|||
// b d f
|
||||
// 0 0 1
|
||||
my_drawing_state().transform.multiply({ static_cast<float>(a), static_cast<float>(b), static_cast<float>(c), static_cast<float>(d), static_cast<float>(e), static_cast<float>(f) });
|
||||
flush_transform();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-gettransform
|
||||
|
@ -72,8 +76,7 @@ public:
|
|||
|
||||
// 2. Reset the current transformation matrix to the identity matrix.
|
||||
my_drawing_state().transform = {};
|
||||
if (auto* painter = static_cast<IncludingClass&>(*this).painter())
|
||||
painter->set_transform({});
|
||||
flush_transform();
|
||||
|
||||
// 3. Invoke the transform(a, b, c, d, e, f) method with the same arguments.
|
||||
transform(a, b, c, d, e, f);
|
||||
|
@ -93,8 +96,7 @@ public:
|
|||
// 3. Reset the current transformation matrix to matrix.
|
||||
auto transform = Gfx::AffineTransform { static_cast<float>(matrix->a()), static_cast<float>(matrix->b()), static_cast<float>(matrix->c()), static_cast<float>(matrix->d()), static_cast<float>(matrix->e()), static_cast<float>(matrix->f()) };
|
||||
my_drawing_state().transform = transform;
|
||||
if (auto* painter = static_cast<IncludingClass&>(*this).painter())
|
||||
painter->set_transform(transform);
|
||||
flush_transform();
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -103,8 +105,13 @@ public:
|
|||
{
|
||||
// The resetTransform() method, when invoked, must reset the current transformation matrix to the identity matrix.
|
||||
my_drawing_state().transform = {};
|
||||
flush_transform();
|
||||
}
|
||||
|
||||
void flush_transform()
|
||||
{
|
||||
if (auto* painter = static_cast<IncludingClass&>(*this).painter())
|
||||
painter->set_transform({});
|
||||
painter->set_transform(my_drawing_state().transform);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue