-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add getTransform function to offscreen canvases (#20037)
* Add getTransform function to offscreen canvases It seems like maybe this was just overlooked? The fix is as easy as adding it to the idl file. It seems like this is already in the spec as: https://html.spec.whatwg.org/multipage/canvas.html#offscreencanvasrenderingcontext2d contains the line OffscreenCanvasRenderingContext2D includes CanvasTransform; And https://html.spec.whatwg.org/multipage/canvas.html#canvastransform lists the getTransform() function. Bug: 1016454 Change-Id: Icb5405d716524e2a0b6935db81b18ff53cd31d4f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872562 Reviewed-by: Chris Harrelson <[email protected]> Reviewed-by: Fernando Serboncini <[email protected]> Reviewed-by: Juanmi Huertas <[email protected]> Commit-Queue: Aaron Krajeski <[email protected]> Cr-Commit-Position: refs/heads/master@{#713886} * Remove setTransform() from tests2d.yaml
- Loading branch information
1 parent
8e6b2e4
commit 0869400
Showing
5 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
2dcontext/transformations/2d.transformation.getTransform.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
<script> | ||
// Ensure that context2d.getTransform works | ||
const epsilon = 1e-5; | ||
const canvas = document.createElement('canvas'); | ||
const ctx = canvas.getContext('2d'); | ||
|
||
test(function(t) { | ||
assert_array_equals(ctx.getTransform().toFloat32Array(), | ||
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], | ||
"Assert that an untransformed matrix is identity"); | ||
|
||
ctx.scale(2, 3); | ||
transform = ctx.getTransform(); | ||
assert_array_equals(ctx.getTransform().toFloat32Array(), | ||
[2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], | ||
"Assert that context2d scaling works"); | ||
|
||
ctx.rotate(Math.PI/2); | ||
transform = ctx.getTransform(); | ||
assert_array_approx_equals(ctx.getTransform().toFloat32Array(), | ||
[0, 3, 0, 0, -2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], epsilon, | ||
"Assert that context2d rotate works"); | ||
|
||
ctx.translate(1, -1); | ||
transform = ctx.getTransform(); | ||
assert_array_approx_equals(ctx.getTransform().toFloat32Array(), | ||
[0, 3, 0, 0, -2, 0, 0, 0, 0, 0, 1, 0, 2, 3, 0, 1], epsilon, | ||
"Assert context2d translate works."); | ||
|
||
ctx.resetTransform(); | ||
assert_array_equals(ctx.getTransform().toFloat32Array(), | ||
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], | ||
"Assert that a reset matrix is identity"); | ||
}, 'This test ensures that getTransform works correctly.'); | ||
</script> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
offscreen-canvas/transformations/2d.transformation.getTransform.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
<script> | ||
// Ensure that context2d.getTransform works | ||
const epsilon = 1e-5; | ||
const canvas = new OffscreenCanvas(300, 150); | ||
const ctx = canvas.getContext('2d'); | ||
|
||
test(function(t) { | ||
|
||
assert_array_equals(ctx.getTransform().toFloat32Array(), | ||
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], | ||
"Assert that an untransformed matrix is identity"); | ||
|
||
ctx.scale(2, 3); | ||
transform = ctx.getTransform(); | ||
assert_array_equals(ctx.getTransform().toFloat32Array(), | ||
[2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], | ||
"Assert that context2d scaling works"); | ||
|
||
ctx.rotate(Math.PI/2); | ||
transform = ctx.getTransform(); | ||
assert_array_approx_equals(ctx.getTransform().toFloat32Array(), | ||
[0, 3, 0, 0, -2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], epsilon, | ||
"Assert that context2d rotate works"); | ||
|
||
ctx.translate(1, -1); | ||
transform = ctx.getTransform(); | ||
assert_array_approx_equals(ctx.getTransform().toFloat32Array(), | ||
[0, 3, 0, 0, -2, 0, 0, 0, 0, 0, 1, 0, 2, 3, 0, 1], epsilon, | ||
"Assert context2d translate works."); | ||
|
||
ctx.resetTransform(); | ||
assert_array_equals(ctx.getTransform().toFloat32Array(), | ||
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], | ||
"Assert that a reset matrix is identity"); | ||
}, 'This test ensures that getTransform works correctly.'); | ||
</script> | ||
</body> |