Skip to content

Commit

Permalink
Add getTransform function to offscreen canvases (web-platform-tests#2…
Browse files Browse the repository at this point in the history
…0037)

* 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 <chrishtr@chromium.org>
Reviewed-by: Fernando Serboncini <fserb@chromium.org>
Reviewed-by: Juanmi Huertas <juanmihd@chromium.org>
Commit-Queue: Aaron Krajeski <aaronhk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713886}

* Remove setTransform() from tests2d.yaml
  • Loading branch information
chromium-wpt-export-bot authored and stephenmcgruer committed Nov 11, 2019
1 parent 8e6b2e4 commit 0869400
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 3 deletions.
39 changes: 39 additions & 0 deletions 2dcontext/transformations/2d.transformation.getTransform.html
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>
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ <h1>2d.missingargs</h1>
assert_throws(new TypeError(), function() { ctx.transform(1, 0, 0, 1, 0); });
}
if (ctx.setTransform) {
assert_throws(new TypeError(), function() { ctx.setTransform(); });
assert_throws(new TypeError(), function() { ctx.setTransform(1); });
assert_throws(new TypeError(), function() { ctx.setTransform(1, 0); });
assert_throws(new TypeError(), function() { ctx.setTransform(1, 0, 0); });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ if (ctx.transform) { // (avoid spurious failures, since the aim here is not to t
assert_throws(new TypeError(), function() { ctx.transform(1, 0, 0, 1, 0); });
}
if (ctx.setTransform) {
assert_throws(new TypeError(), function() { ctx.setTransform(); });
assert_throws(new TypeError(), function() { ctx.setTransform(1); });
assert_throws(new TypeError(), function() { ctx.setTransform(1, 0); });
assert_throws(new TypeError(), function() { ctx.setTransform(1, 0, 0); });
Expand Down
1 change: 0 additions & 1 deletion offscreen-canvas/tools/tests2d.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8800,7 +8800,6 @@
@assert throws TypeError ctx.transform(1, 0, 0, 1, 0);
}
if (ctx.setTransform) {
@assert throws TypeError ctx.setTransform();
@assert throws TypeError ctx.setTransform(1);
@assert throws TypeError ctx.setTransform(1, 0);
@assert throws TypeError ctx.setTransform(1, 0, 0);
Expand Down
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>

0 comments on commit 0869400

Please sign in to comment.