Skip to content

Commit

Permalink
SVG: Increase hit-testing precision on strokes
Browse files Browse the repository at this point in the history
Skia takes a precision value when generating strokes as an optimization.
When rendering, we pass a value derived from the scale-factor in the
CTM, but when hit-testing we were passing a hard-coded value.  This
worked reasonably well for solid strokes at moderate scales.  However,
at sufficiently high scales and especially for dashed strokes, the
stroke generated for hit-testing was noticeably different from the
rendered stroke.

This change passes the CTM through to the hit-testing code, so that we
can use the same high precision for hit testing as rendering.

Bug: 964614
Change-Id: I8dfcb3ade86b9e7b63c7415baab5814ac2286ce8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2112955
Reviewed-by: Ian Prest <iapres@microsoft.com>
Reviewed-by: Philip Rogers <pdr@chromium.org>
Reviewed-by: Fernando Serboncini <fserb@chromium.org>
Reviewed-by: Fredrik Söderquist <fs@opera.com>
Commit-Queue: Ian Prest <iapres@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#759761}
  • Loading branch information
ijprest authored and chromium-wpt-export-bot committed Apr 16, 2020
1 parent 390b067 commit 6ac09a5
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
40 changes: 40 additions & 0 deletions 2dcontext/path-objects/2d.path.isPointInStroke.scaleddashes.html
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /2dcontext/tools/gentest.py. -->
<title>Canvas test: 2d.path.isPointInStroke.scaleddashes</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/2dcontext/resources/canvas-tests.js"></script>
<link rel="stylesheet" href="/2dcontext/resources/canvas-tests.css">
<body class="show_output">

<h1>2d.path.isPointInStroke.scaleddashes</h1>
<p class="desc">isPointInStroke() should return correct results on dashed paths at high scale factors</p>


<p class="output">Actual output:</p>
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>

<ul id="d"></ul>
<script>
var t = async_test("isPointInStroke() should return correct results on dashed paths at high scale factors");
_addTest(function(canvas, ctx) {

var scale = 20;
ctx.setLineDash([10, 21.4159]); // dash from t=0 to t=10 along the circle
ctx.scale(scale, scale);
ctx.ellipse(6, 10, 5, 5, 0, 2*Math.PI, false);
ctx.stroke();

// hit-test the beginning of the dash (t=0)
_assertSame(ctx.isPointInStroke(11*scale, 10*scale), true, "ctx.isPointInStroke(11*scale, 10*scale)", "true");
// hit-test the middle of the dash (t=5)
_assertSame(ctx.isPointInStroke(8.70*scale, 14.21*scale), true, "ctx.isPointInStroke(8.70*scale, 14.21*scale)", "true");
// hit-test the end of the dash (t=9.8)
_assertSame(ctx.isPointInStroke(4.10*scale, 14.63*scale), true, "ctx.isPointInStroke(4.10*scale, 14.63*scale)", "true");
// hit-test past the end of the dash (t=10.2)
_assertSame(ctx.isPointInStroke(3.74*scale, 14.46*scale), false, "ctx.isPointInStroke(3.74*scale, 14.46*scale)", "false");


});
</script>

21 changes: 21 additions & 0 deletions 2dcontext/tools/tests2d.yaml
Expand Up @@ -8646,6 +8646,27 @@
@assert ctx.isPointInPath(NaN, NaN) === false;
- name: 2d.path.isPointInStroke.scaleddashes
desc: isPointInStroke() should return correct results on dashed paths at high scale factors
testing:
- 2d.path.isPointInStroke
code: |
var scale = 20;
ctx.setLineDash([10, 21.4159]); // dash from t=0 to t=10 along the circle
ctx.scale(scale, scale);
ctx.ellipse(6, 10, 5, 5, 0, 2*Math.PI, false);
ctx.stroke();
// hit-test the beginning of the dash (t=0)
@assert ctx.isPointInStroke(11*scale, 10*scale) === true;
// hit-test the middle of the dash (t=5)
@assert ctx.isPointInStroke(8.70*scale, 14.21*scale) === true;
// hit-test the end of the dash (t=9.8)
@assert ctx.isPointInStroke(4.10*scale, 14.63*scale) === true;
// hit-test past the end of the dash (t=10.2)
@assert ctx.isPointInStroke(3.74*scale, 14.46*scale) === false;
- name: 2d.drawImage.3arg
testing:
- 2d.drawImage.defaultsource
Expand Down
27 changes: 27 additions & 0 deletions svg/shapes/scripted/stroke-dashes-hit-at-high-scale.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions svg/types/scripted/SVGGeometryElement.isPointInStroke-02.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6ac09a5

Please sign in to comment.