Open Bug 926258 Opened 6 years ago Updated 6 years ago

Compute path lengths with Moz2D

Categories

(Core :: Graphics, defect)

x86
macOS
defect
Not set

Tracking

()

People

(Reporter: mattwoodrow, Assigned: bas.schouten)

References

(Depends on 1 open bug)

Details

(Whiteboard: [leave open])

Attachments

(4 files)

SVG curently uses gfxFlattened path to compute lengths of paths, and coordinates along the path.

We need a way to implement this with Moz2D.
This merges the gfxPath and gfxFlattenedPath API's.

I don't think we want to have a separate 'flattened path' object before we can do measurements, since D2D at least provides an API for doing directly on any path.

This is going to be a bit slower than what we currently have (a few extra path copies), but we should be able to improve it again as we switch to moz2d. I also doubt it's called enough to matter.
Attachment #816406 - Flags: review?(roc)
Comment on attachment 816407 [details] [diff] [review]
Part 2: Implement a Moz2D version of gfxPath

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

::: gfx/2d/2D.h
@@ +451,5 @@
> +
> +  virtual double ComputeLength() { return 0; }
> +
> +  virtual Point ComputePointAtLength(double aLength,
> +                                     Point* aTangent) { return Point(); }

These should become pure virtual of course, once we have actual implementations.
Refactoring (not actually using moz2d for anything): https://tbpl.mozilla.org/?tree=Try&rev=aaadf3b32b9e

Enabled Moz2D path measurement for d2d (some bugs left): https://tbpl.mozilla.org/?tree=Try&rev=2de0895f0884
Bas had ideas for doing path measurements of curved path segments without flattening.

I have some in-progress patches for refactoring the iteration of cairo paths and moving that into PathHelpers.h so that we can do an implementation for Moz2d/cairo.

I'll let him weight in here before continuing on that too much to avoid potentially wasting work.
Comment on attachment 816407 [details] [diff] [review]
Part 2: Implement a Moz2D version of gfxPath

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

::: gfx/2d/2D.h
@@ +450,5 @@
>    virtual FillRule GetFillRule() const = 0;
> +
> +  virtual double ComputeLength() { return 0; }
> +
> +  virtual Point ComputePointAtLength(double aLength,

We probably want this to be 'Float' as that's what we generally use in Moz2D.

::: gfx/thebes/gfxPath.cpp
@@ +113,5 @@
> +        // The y value of aOffset is the offset along the normal vector to apply
> +        Point normal(-tangent.y, tangent.x);
> +        result += normal * aOffset.y;
> +
> +        if (aAngle)

nit: { }
Attachment #816407 - Flags: review?(bas) → review+
Comment on attachment 816409 [details] [diff] [review]
Part 3a: D2D implementation of path measurement

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

::: gfx/2d/PathD2D.h
@@ +87,5 @@
>  
>    virtual FillRule GetFillRule() const { return mFillRule; }
>  
>    ID2D1Geometry *GetGeometry() { return mGeometry; }
> +  

nit: whitespace
Attachment #816409 - Flags: review?(bas) → review+
Assigning to Bas since he's looking at the other implementations.
Assignee: nobody → bas
Attachment #816406 - Flags: checkin+
Attachment #816407 - Flags: checkin+
This blocks landing of the patch in bug 930468.
Blocks: 930468
Make that bug 930577.
Blocks: 930577
No longer blocks: 930468
A suggestion from Andreas on IRC:

gal	I would add a helper for that using skia
gal	instead of trying to add that to every backend
gal	at least as a fallback
jwatt	gal: how does skia fit in here - does that mean calling skia API from gecko code, or calling a Moz2D helper that uses skia regardless of platform?
jwatt	the Moz2D helper taking a mozilla::Path
gal	one way of doing it is adding a Factory::CreateDefaultSoftwareDrawTarget()
gal	and then have skia be that
gal	and then your helper can go there, get a DT, create a path, and do the math
gal	you implement it for the actual skia backend, the rest fall into this path
I don't think the skia path API implements what we need here. SkPathHelpers has a getLength function, but I don't see any ComputePointAtLength equivalent.

I was thinking we'd probably have to do the same sort of thing with a cairo path. Unsupported backends replay their Path object into a cairo path object, and then do the computations using that.
It would certainly be helpful if the same DT backend can be used to get PathBuilders to create paths for painting, measuring, etc. That way we can cache the one path and reuse it for everything, rather than having to cache more than one path, or regularly recreate paths.

What's the current status of the various backends in regards to this bug? Which support what we need, and which do not?
I will do the required work here on the very short term, sorry I haven't gotten to it yet.
Using Cairo here seems counter-intuitive. We are trying to kill cairo.
Depends on: 935049
No longer blocks: 930577
Depends on: 930577, 934305
Depends on: 938388
Depends on: 937994
Depends on: 939534
Comment on attachment 816410 [details] [diff] [review]
Part 4: Start using Moz2D gfxContext's when measuring paths

This has been obsoleted.
Attachment #816410 - Flags: checkin-
You need to log in before you can comment on or make changes to this bug.