Fix PaintRenderingContext2D reset in highdpi

After resetting the canvas, the device pixel ratio scaling factor has
to be re-applied to the canvas, just like we do when first
instializing the context and when resetTransform is called.

Bug: 1484741
Change-Id: I13b772d68fff8e233d2a936e43b221f2419a4edd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4943195
Reviewed-by: Fernando Serboncini <fserb@chromium.org>
Commit-Queue: Jean-Philippe Gravel <jpgravel@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1226379}
diff --git a/css/css-paint-api/hidpi/canvas-reset-ref.html b/css/css-paint-api/hidpi/canvas-reset-ref.html
new file mode 100644
index 0000000..24cab5d
--- /dev/null
+++ b/css/css-paint-api/hidpi/canvas-reset-ref.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<body>
+<canvas id ="canvas"></canvas>
+<script>
+var canvas = document.getElementById('canvas');
+var ctx = canvas.getContext("2d");
+
+// Adjust the canvas to get highdpi rendering.
+canvas.style.width = '270px';
+canvas.style.height = '275px';
+canvas.width = 270 * devicePixelRatio;
+canvas.height = 275 * devicePixelRatio;
+ctx.scale(devicePixelRatio, devicePixelRatio);
+
+var fillW = 250;
+var fillH = 50;
+ctx.beginPath();
+ctx.rect(0, 0, fillW, fillH);
+ctx.closePath();
+ctx.clip();
+ctx.fillStyle = 'green';
+ctx.fillRect(0, 0, fillW, fillH);
+</script>
+</body>
+</html>
diff --git a/css/css-paint-api/hidpi/canvas-reset.https.html b/css/css-paint-api/hidpi/canvas-reset.https.html
new file mode 100644
index 0000000..d8073d6
--- /dev/null
+++ b/css/css-paint-api/hidpi/canvas-reset.https.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+<link rel="help" href="https://drafts.css-houdini.org/css-paint-api/">
+<link rel="match" href="canvas-reset-ref.html">
+<style>
+.container {
+  width: 270px;
+  height: 275px;
+}
+
+#canvas-geometry {
+  background-image: paint(geometry);
+}
+</style>
+<script src="/common/reftest-wait.js"></script>
+<script src="/common/worklet-reftest.js"></script>
+<body>
+<div id="canvas-geometry" class="container"></div>
+
+<script id="code" type="text/worklet">
+registerPaint('geometry', class {
+  paint(ctx, geom) {
+    // Set some transform then reset the canvas.
+    ctx.translate(20, 30);
+    ctx.scale(1.5, 2.5);
+    ctx.reset();
+
+    var fillW = 250;
+    var fillH = 50;
+    ctx.beginPath();
+    ctx.rect(0, 0, fillW, fillH);
+    ctx.closePath();
+    ctx.clip();
+    ctx.fillStyle = 'green';
+    ctx.fillRect(0, 0, fillW, fillH);
+  }
+});
+</script>
+
+<script>
+    importWorkletAndTerminateTestAfterAsyncPaint(CSS.paintWorklet, document.getElementById('code').textContent);
+</script>
+</body>
+</html>