Commit 7935a1ac authored by Xida Chen's avatar Xida Chen Committed by Commit Bot

[PW] Scale canvas when PaintRecorder is created

Right now in PaintRenderingContext2D, the canvas is scaled after the
InitializePaintRecorder. This is too late because we already do
canvas->save() at the InitializePaintRecorder. Trying to scale the
canvas after save operation doesn't apply the scale. This can be
seem by zoom in a paint worklet page and seeing that the drawing
isn't zoomed in.

This CL fixes the problem and added a layout test.

Bug: 970783
Change-Id: Ic0c8a84cc22c8cef9b325e134925e482bee1e65d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1670439Reviewed-by: default avatarYi Gu <yigu@chromium.org>
Commit-Queue: Xida Chen <xidachen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#671735}
parent 9bb00ca2
...@@ -26,7 +26,6 @@ PaintRenderingContext2D::PaintRenderingContext2D( ...@@ -26,7 +26,6 @@ PaintRenderingContext2D::PaintRenderingContext2D(
Canvas()->clear(context_settings->alpha() ? SK_ColorTRANSPARENT Canvas()->clear(context_settings->alpha() ? SK_ColorTRANSPARENT
: SK_ColorBLACK); : SK_ColorBLACK);
did_record_draw_commands_in_paint_recorder_ = true; did_record_draw_commands_in_paint_recorder_ = true;
Canvas()->scale(zoom, zoom);
} }
void PaintRenderingContext2D::InitializePaintRecorder() { void PaintRenderingContext2D::InitializePaintRecorder() {
...@@ -37,6 +36,7 @@ void PaintRenderingContext2D::InitializePaintRecorder() { ...@@ -37,6 +36,7 @@ void PaintRenderingContext2D::InitializePaintRecorder() {
// Always save an initial frame, to support resetting the top level matrix // Always save an initial frame, to support resetting the top level matrix
// and clip. // and clip.
canvas->scale(effective_zoom_, effective_zoom_);
canvas->save(); canvas->save();
did_record_draw_commands_in_paint_recorder_ = false; did_record_draw_commands_in_paint_recorder_ = false;
......
<!DOCTYPE html>
<html>
<style>
html, body { margin: 0; padding: 0; }
</style>
<body>
<div>
<canvas id="output" width="200" height="200"></canvas>
</div>
<script>
var canvas = document.getElementById('output');
var ctx = canvas.getContext('2d');
ctx.fillStyle = 'green';
ctx.fillRect(0, 0, 200, 200);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<script src="./resources/test-runner-paint-worklet.js"></script>
<style>
html, body { margin: 0; padding: 0; }
#output {
width: 100px;
height: 100px;
background-image: paint(worklet);
}
</style>
<body>
<div id="output"></div>
<script id="code" type="text/worklet">
registerPaint('worklet', class {
paint(ctx, geom) {
ctx.fillStyle = 'green';
ctx.fillRect(0, 0, geom.width, geom.height);
}
});
</script>
<script>
document.body.style.zoom = "200%";
importPaintWorkletThenEndTest(document.getElementById('code').textContent);
</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