Skip to content

Truly independent web browser

LibGfx: Keep rotations about x, y or z exactly in their planes

Andreas Klingd410e9c79011
diff --git a/Libraries/LibGfx/Rust/src/matrix.rs b/Libraries/LibGfx/Rust/src/matrix.rs
index 2373820394b..d7176e6b892 100644
--- a/Libraries/LibGfx/Rust/src/matrix.rs
+++ b/Libraries/LibGfx/Rust/src/matrix.rs
@@ -304,15 +304,33 @@ impl<T: MatrixElement> Matrix4x4<T> {
if s.abs() < T::EPSILON {
s = T::ZERO;
}
- let t = T::ONE - c;
+ let (o, l) = (T::ZERO, T::ONE);
+ // NB: A rotation about x, y or z is built directly, since the general form below puts (1 - c) + c on the
+ // diagonal for the axis, which rounds to a neighbor of one for many angles. A rotation in the plane would
+ // then fail every check for an exact 2D affine matrix.
+ if axis == [o, o, l] {
+ return Self {
+ elements: [[c, o - s, o, o], [s, c, o, o], [o, o, l, o], [o, o, o, l]],
+ };
+ }
+ if axis == [l, o, o] {
+ return Self {
+ elements: [[l, o, o, o], [o, c, o - s, o], [o, s, c, o], [o, o, o, l]],
+ };
+ }
+ if axis == [o, l, o] {
+ return Self {
+ elements: [[c, o, s, o], [o, l, o, o], [o - s, o, c, o], [o, o, o, l]],
+ };
+ }
+ let t = l - c;
let [x, y, z] = axis;
- let o = T::ZERO;
Self {
elements: [
[t * x * x + c, t * x * y - z * s, t * x * z + y * s, o],
[t * x * y + z * s, t * y * y + c, t * y * z - x * s, o],
[t * x * z - y * s, t * y * z + x * s, t * z * z + c, o],
- [o, o, o, T::ONE],
+ [o, o, o, l],
],
}
}
diff --git a/Tests/LibWeb/Ref/expected/iframe-layers-of-compositor-animations-turned-past-a-right-angle-ref.html b/Tests/LibWeb/Ref/expected/iframe-layers-of-compositor-animations-turned-past-a-right-angle-ref.html
new file mode 100644
index 00000000000..ae5b87af169
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/iframe-layers-of-compositor-animations-turned-past-a-right-angle-ref.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<style>
+ iframe { display: block; width: 400px; height: 400px; border: 0; }
+</style>
+<iframe></iframe>
+<script>
+ let boxes = "";
+ for (let i = 0; i < 16; ++i) {
+ const angle = 100 + i * 10;
+ boxes += `<div style="position: absolute; left: ${20 + (i % 4) * 100}px; top: ${20 + Math.floor(i / 4) * 100}px; width: 60px; height: 60px; background: navy; transform: rotate(${angle}deg)"></div>`;
+ }
+ document.querySelector("iframe").srcdoc = `<!DOCTYPE html><style>body { margin: 0; }</style>${boxes}`;
+</script>
diff --git a/Tests/LibWeb/Ref/input/iframe-layers-of-compositor-animations-turned-past-a-right-angle.html b/Tests/LibWeb/Ref/input/iframe-layers-of-compositor-animations-turned-past-a-right-angle.html
new file mode 100644
index 00000000000..49a5adffa0c
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/iframe-layers-of-compositor-animations-turned-past-a-right-angle.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+<link rel="match" href="../expected/iframe-layers-of-compositor-animations-turned-past-a-right-angle-ref.html">
+<!-- The compositor resamples the rotated tiles bilinearly, which a direct raster of the rotated boxes does not. -->
+<meta name="fuzzy" content="maxDifference=0-80;totalPixels=0-6400">
+<style>
+ iframe { display: block; width: 400px; height: 400px; border: 0; }
+</style>
+<iframe></iframe>
+<script>
+ // Each box holds a third of its turn from 0 to three times its angle for the whole test: an angle past a right one,
+ // whose sampled rotation the compositor still composites as a 2D one.
+ let boxes = "";
+ for (let i = 0; i < 16; ++i) {
+ const angle = 100 + i * 10;
+ boxes += `<style>@keyframes turn-${i} { from { transform: rotate(0deg); } to { transform: rotate(${angle * 3}deg); } }</style>`;
+ boxes += `<div style="position: absolute; left: ${20 + (i % 4) * 100}px; top: ${20 + Math.floor(i / 4) * 100}px; width: 60px; height: 60px; background: navy; animation: turn-${i} 300s steps(2, jump-both) infinite"></div>`;
+ }
+ const iframe = document.querySelector("iframe");
+ iframe.srcdoc = `<!DOCTYPE html><style>body { margin: 0; }</style>${boxes}`;
+ const frame = () => new Promise(resolve => requestAnimationFrame(resolve));
+ window.onload = async () => {
+ for (let i = 0; i < 4; ++i)
+ await frame();
+ if (window.internals)
+ internals.signalTestIsDone("PASS");
+ else
+ document.documentElement.classList.remove("reftest-wait");
+ };
+</script>