Commit d1886d3c authored by Xida Chen's avatar Xida Chen Committed by Commit Bot

[PW] Implement setTransform with DOMMatrix

Right now the PaintRenderingContext2D::setTransform that takes a
DOMMatrix would crash because it is NOTREACHED().

This CL implements that and add a layout test.

Bug: 1029362
Change-Id: I1038dbe1bfcee14e128c46f73606fabcf3923caf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1951566
Commit-Queue: Xida Chen <xidachen@chromium.org>
Reviewed-by: default avatarYi Gu <yigu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#723549}
parent a59b979e
...@@ -155,9 +155,13 @@ void PaintRenderingContext2D::setTransform(double m11, ...@@ -155,9 +155,13 @@ void PaintRenderingContext2D::setTransform(double m11,
void PaintRenderingContext2D::setTransform(DOMMatrix2DInit* transform, void PaintRenderingContext2D::setTransform(DOMMatrix2DInit* transform,
ExceptionState& exception_state) { ExceptionState& exception_state) {
// The PaintRenderingContext2D APIs are running on worklet thread, therefore DOMMatrixReadOnly* m =
// it is not possible to construct a DOMMatrix. DOMMatrixReadOnly::fromMatrix2D(transform, exception_state);
NOTREACHED();
if (!m)
return;
setTransform(m->m11(), m->m12(), m->m21(), m->m22(), m->m41(), m->m42());
} }
sk_sp<PaintRecord> PaintRenderingContext2D::GetRecord() { sk_sp<PaintRecord> PaintRenderingContext2D::GetRecord() {
......
<!DOCTYPE html>
<title>setTransform with DOMMatrix behaves correctly</title>
<html class="reftest-wait">
<link rel="help" href="https://drafts.css-houdini.org/css-paint-api/">
<link rel="match" href="setTransform-ref.html">
<style>
.container {
width: 200px;
height: 200px;
}
#foo {
background: paint(foo);
}
</style>
<script src="/common/reftest-wait.js"></script>
<script src="/common/worklet-reftest.js"></script>
<body>
<div id="foo" class="container"></div>
<script id="code" type="text/worklet">
registerPaint('foo', class {
paint(ctx, geom) {
ctx.fillStyle = 'green';
let m = ctx.getTransform();
m.a = 2;
m.d = 2;
ctx.setTransform(m);
ctx.fillRect(0, 0, 50, 50);
}
});
</script>
<script>
importWorkletAndTerminateTestAfterAsyncPaint(CSS.paintWorklet, document.getElementById('code').textContent);
</script>
</body>
</html>
<!DOCTYPE html>
<title>setTransform with DOMMatrix behaves correctly</title>
<html class="reftest-wait">
<link rel="help" href="https://drafts.css-houdini.org/css-paint-api/">
<link rel="match" href="setTransform-ref.html">
<style>
.container {
width: 200px;
height: 200px;
}
#foo {
background: paint(foo);
}
</style>
<script src="/common/reftest-wait.js"></script>
<script src="/common/worklet-reftest.js"></script>
<body>
<div id="foo" class="container"></div>
<script id="code" type="text/worklet">
registerPaint('foo', class {
paint(ctx, geom) {
ctx.fillStyle = 'green';
ctx.setTransform({a: 2, d: 2});
ctx.fillRect(0, 0, 50, 50);
}
});
</script>
<script>
importWorkletAndTerminateTestAfterAsyncPaint(CSS.paintWorklet, document.getElementById('code').textContent);
</script>
</body>
</html>
<!DOCTYPE html>
<title>setTransform with NaN should be ignored</title>
<html class="reftest-wait">
<link rel="help" href="https://drafts.css-houdini.org/css-paint-api/">
<link rel="match" href="setTransform-ref.html">
<style>
.container {
width: 200px;
height: 200px;
}
#foo {
background: paint(foo);
}
</style>
<script src="/common/reftest-wait.js"></script>
<script src="/common/worklet-reftest.js"></script>
<body>
<div id="foo" class="container"></div>
<script id="code" type="text/worklet">
registerPaint('foo', class {
paint(ctx, geom) {
ctx.fillStyle = 'green';
// Set to a NaN should be ignored.
ctx.setTransform({a: NaN, d:2});
ctx.fillRect(0, 0, 100, 100);
}
});
</script>
<script>
importWorkletAndTerminateTestAfterAsyncPaint(CSS.paintWorklet, document.getElementById('code').textContent);
</script>
</body>
</html>
<!DOCTYPE html>
<title>setTransform with Infinity should be ignored</title>
<html class="reftest-wait">
<link rel="help" href="https://drafts.css-houdini.org/css-paint-api/">
<link rel="match" href="setTransform-ref.html">
<style>
.container {
width: 200px;
height: 200px;
}
#foo {
background: paint(foo);
}
</style>
<script src="/common/reftest-wait.js"></script>
<script src="/common/worklet-reftest.js"></script>
<body>
<div id="foo" class="container"></div>
<script id="code" type="text/worklet">
registerPaint('foo', class {
paint(ctx, geom) {
ctx.fillStyle = 'green';
// Set to Infinity should be ignored.
ctx.setTransform({a: Infinity, d:2});
ctx.fillRect(0, 0, 100, 100);
}
});
</script>
<script>
importWorkletAndTerminateTestAfterAsyncPaint(CSS.paintWorklet, document.getElementById('code').textContent);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<canvas id ="canvas" width="200" height="200"></canvas>
<script>
var ctx = document.getElementById('canvas').getContext('2d');
ctx.fillStyle = 'green';
let m = ctx.getTransform();
m.a = 2;
m.d = 2;
ctx.setTransform(m);
ctx.fillRect(0, 0, 50, 50);
</script>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment