Closed Bug 803124 Opened 8 years ago Closed 8 years ago

Implement isPointInStroke

Categories

(Core :: Canvas: 2D, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla19
Tracking Status
firefox17 --- unaffected
firefox18 --- unaffected
firefox19 --- fixed
firefox20 --- fixed

People

(Reporter: tschneider, Assigned: tschneider)

References

Details

(Keywords: dev-doc-complete)

Attachments

(2 files, 6 obsolete files)

Attached patch Implement mozIsPointInStroke (obsolete) — Splinter Review
In addition to isPointInPath, the Canvas API should also provide isPointInStroke for hit testing. Right now there is no efficient way to test if a point lies inside the filled AND stroked region of a path. (except of checking for nontransparend pixels using getImageData, which is awful slow if 2D rendering is hw accelerated).
Attachment #672798 - Attachment filename: patch.diff → 803124-mozIsPointInStroke.patch
Attachment #672798 - Attachment is patch: true
Attached patch Patch v2 (obsolete) — Splinter Review
Attachment #672798 - Attachment is obsolete: true
Attachment #672886 - Attachment description: Implement mozIsPointInStroke → Remove whitespace changes
Attached patch Patch v3 (obsolete) — Splinter Review
Attachment #672886 - Attachment is obsolete: true
Attached patch Patch v4 (obsolete) — Splinter Review
Attachment #672894 - Attachment is obsolete: true
Attachment #672886 - Attachment description: Remove whitespace changes → Patch v2
Attachment #672894 - Attachment description: Add test, change IDL UUID → Patch v3
Attachment #672928 - Attachment description: Fix syntax error → Patch v4
Attached patch Patch v5 (obsolete) — Splinter Review
Attachment #672928 - Attachment is obsolete: true
Attachment #672886 - Attachment filename: 803124-mozIsPointInStroke.diff → 803124-mozIsPointInStroke.patch
Attachment #672894 - Attachment filename: 803124-mozIsPointInStroke.diff → 803124-mozIsPointInStroke.patch
Attachment #672928 - Attachment filename: 803124-mozIsPointInStroke.diff → 803124-mozIsPointInStroke.patch
Attachment #673128 - Attachment filename: 803124-mozIsPointInStroke.diff → 803124-mozIsPointInStroke.patch
Comment on attachment 673128 [details] [diff] [review]
Patch v5

Review of attachment 673128 [details] [diff] [review]:
-----------------------------------------------------------------

::: content/canvas/test/test_mozIsPointInStroke.html
@@ +33,5 @@
> +
> +ok(ctx.mozIsPointInStroke(20, 20) === false);
> +ok(ctx.mozIsPointInStroke(80, 20) === false);
> +ok(ctx.mozIsPointInStroke(80, 30) === false);
> +ok(ctx.mozIsPointInStroke(20, 30) === false);

This test should include curves and transformed paths/transformed userspace. It might also be worth testing different cap modes.
Attached patch Patch v6 (obsolete) — Splinter Review
Attachment #673128 - Attachment is obsolete: true
Attachment #675015 - Flags: review?(jmuizelaar)
Comment on attachment 675015 [details] [diff] [review]
Patch v6

Review of attachment 675015 [details] [diff] [review]:
-----------------------------------------------------------------

::: content/canvas/test/test_mozIsPointInStroke.html
@@ +191,5 @@
> +ok(ctx.mozIsPointInStroke(14, 15) === true, 'ctx.mozIsPointInStroke(14, 15) === true');
> +ok(ctx.mozIsPointInStroke(81, 15) === true, 'ctx.mozIsPointInStroke(81, 15) === true');
> +ok(ctx.mozIsPointInStroke(79, 41) === true, 'ctx.mozIsPointInStroke(79, 41) === true');
> +ok(ctx.mozIsPointInStroke(73, 21) === true, 'ctx.mozIsPointInStroke(73, 21) === true');
> +

How about a final test that does a curve scaled by 3x?

Also you should test changing the scale during path construction.

::: gfx/2d/PathSkia.cpp
@@ +184,5 @@
> +                    int32_t(SkFloatToScalar(transformed.y + 1)));
> +
> +  SkRegion pathRegion;
> +
> +  return pathRegion.setPath(strokePath, pointRect);

This should use SkPathContainsPoint if possible.
Attachment #675015 - Flags: review?(jmuizelaar) → review+
(In reply to Jeff Muizelaar [:jrmuizel] from comment #7)
> 
> How about a final test that does a curve scaled by 3x?
>
> Also you should test changing the scale during path construction.

Sounds reasonable, will add those tests.

> > +  return pathRegion.setPath(strokePath, pointRect);
> 
> This should use SkPathContainsPoint if possible.

Don't think SkPathContainsPoint is a standard Skia API, is it? Seems to be an internal helper defined and used in Chromium (http://code.google.com/p/chromium/source/search?q=SkPathContainsPoint&origq=SkPathContainsPoint&btnG=Search+Trunk) and itself uses setPath().
Flags: needinfo?
(In reply to Tobias Schneider from comment #8)
> (In reply to Jeff Muizelaar [:jrmuizel] from comment #7)
>
> Don't think SkPathContainsPoint is a standard Skia API, is it? Seems to be
> an internal helper defined and used in Chromium
> (http://code.google.com/p/chromium/source/
> search?q=SkPathContainsPoint&origq=SkPathContainsPoint&btnG=Search+Trunk)
> and itself uses setPath().

True. I thought they had fixed this in Skia.
Flags: needinfo?
(In reply to Jeff Muizelaar [:jrmuizel] from comment #9)
> (In reply to Tobias Schneider from comment #8)
> > (In reply to Jeff Muizelaar [:jrmuizel] from comment #7)
> >
> > Don't think SkPathContainsPoint is a standard Skia API, is it? Seems to be
> > an internal helper defined and used in Chromium
> > (http://code.google.com/p/chromium/source/
> > search?q=SkPathContainsPoint&origq=SkPathContainsPoint&btnG=Search+Trunk)
> > and itself uses setPath().
> 
> True. I thought they had fixed this in Skia.

Actually, the function is SkPath::contains(x,y)
Attached patch Patch v7Splinter Review
Attachment #675015 - Attachment is obsolete: true
Attachment #676169 - Flags: review?(jmuizelaar)
Attachment #676169 - Flags: review?(jmuizelaar) → review+
Keywords: checkin-needed
Pushed to Try since I don't see any results posted here.
https://tbpl.mozilla.org/?tree=Try&rev=079dc1ebac54
Unfortunately, this causes hangs in android armv6 builds.
https://tbpl.mozilla.org/?tree=Try&rev=7f236ae2ee94
Keywords: checkin-needed
I wonder if it still hangs on armv6 without the test changes. I find it pretty unlikely that this would cause all the mochitests to fail...
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/69c7ee7683e0
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla19
Was this ever even suggested on a standards list?
(In reply to :Ms2ger from comment #18)
> Was this ever even suggested on a standards list?

I don't believe it was. Would you be willing to do so?
I have no idea what this API is good for; it's probably better to let someone who does suggest it.
Depends on: 812039
There's no need for this to be prefixed, by the way. It'll either be added, in which case I'll ensure it's compatible and so it won't conflict, or it won't, in which case nothing with this name will be added and it still won't conflict.

The idea seems pretty sound, the main thing that would stop me from adding it to the spec right now is lack of interest from other vendors. I'll ask around, but if you can convince another vendor to indicate an interest that would certainly help.
Can this be unprefixed, please? As Hixie says, the prefix is useless and unprefixing later will cause breakage later.
Attachment #684393 - Flags: review?(jmuizelaar)
Attachment #684393 - Flags: review?(jmuizelaar) → review+
Keywords: checkin-needed
Assignee: nobody → schneider
Comment on attachment 684393 [details] [diff] [review]
Patch to remove prefix

[Approval Request Comment]
Bug caused by (feature/regressing bug #): N/A
User impact if declined: proliferating more -moz prefixes
Testing completed (on m-c, etc.): on m-c
Risk to taking this patch (and alternatives if risky): maybe low, simple renaming
String or UUID changes made by this patch: none
Attachment #684393 - Flags: approval-mozilla-aurora?
Comment on attachment 684393 [details] [diff] [review]
Patch to remove prefix

Approving based on the m-c testing.
Attachment #684393 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
Summary: Implement mozIsPointInStroke → Implement isPointInStroke
You need to log in before you can comment on or make changes to this bug.