Open Bug 1175958 (conic-gradients) Opened 5 years ago Updated 18 days ago

Implement conic gradients from CSS Image Values Level 4

Categories

(Core :: CSS Parsing and Computation, enhancement, P1)

enhancement

Tracking

()

People

(Reporter: lea, Unassigned)

References

(Depends on 5 open bugs, Blocks 2 open bugs, )

Details

(Keywords: dev-doc-needed, parity-chrome, parity-safari, Whiteboard: gfx-noted [layout:backlog:2020])

Attachments

(2 obsolete files)

Conic gradients [1] are useful for a number of effects on the Web that cannot be emulated in any other way (see [2]). They can be implemented in Cairo via mesh gradients. Please implement them.

[1]: http://www.w3.org/TR/css4-images/#conic-gradients
[2]: http://leaverou.github.io/conic-gradient
(In reply to Lea Verou from comment #0)
> Conic gradients [1] are useful for a number of effects on the Web that
> cannot be emulated in any other way (see [2]). They can be implemented in
> Cairo via mesh gradients. Please implement them.
> 
> [1]: http://www.w3.org/TR/css4-images/#conic-gradients
> [2]: http://leaverou.github.io/conic-gradient

Conic gradients are not natively supported by Direct2D, CoreGraphics and Cairo which means this is a bunch of work and without an implementation in other browsers not a high priority right now.
Whiteboard: gfx-noted
(In reply to Jeff Muizelaar [:jrmuizel] from comment #2)

> Conic gradients are not natively supported by Direct2D, CoreGraphics and
> Cairo which means this is a bunch of work and without an implementation in
> other browsers not a high priority right now.


1. Re:Cairo, see above. See also [1], where conical gradients are actually mentioned as an example of a use case.
2. Have you investigated how much work it would be? Of course you can’t draw much from one instance, but the complexity seems manageable, based on my brief experience implementing a (partial) polyfill [2]. All it requires is an arc command, which all three (Direct2D, CoreGraphics, Cairo) do provide. The rest (color interpolation, compositing) are there already.

[1]: http://libregraphicsworld.org/blog/entry/mesh-gradients-in-cairo-now-official
[2]: http://leaverou.github.io/conic-gradient/
(In reply to Lea Verou from comment #3)
> (In reply to Jeff Muizelaar [:jrmuizel] from comment #2)
> 
> > Conic gradients are not natively supported by Direct2D, CoreGraphics and
> > Cairo which means this is a bunch of work and without an implementation in
> > other browsers not a high priority right now.
> 
> 
> 1. Re:Cairo, see above. See also [1], where conical gradients are actually
> mentioned as an example of a use case.

Our in-tree version of cairo doesn't support mesh gradients. Updating cairo is currently blocked
on switching away from cairo to Skia for rendering on Windows.

> 2. Have you investigated how much work it would be? Of course you can’t draw
> much from one instance, but the complexity seems manageable, based on my
> brief experience implementing a (partial) polyfill [2]. All it requires is
> an arc command, which all three (Direct2D, CoreGraphics, Cairo) do provide.
> The rest (color interpolation, compositing) are there already.

I haven't investigated how much work it would be. Can you describe how the polyfill works?
Conic gradients are quite powerful in creating cool looking effects.
Definitely, it is a useful in the toolkit of a web developer.
This is needed to be implemented in all all the browsers: Chrome, Opera, Firefox, IE, Safari.
Status: UNCONFIRMED → NEW
Ever confirmed: true
(In reply to vinci from comment #6)
> +1. This would be very useful for static pie charts.

Do you have an example of what you have in mind?
(In reply to Jeff Muizelaar [:jrmuizel] from comment #7)
> Do you have an example of what you have in mind?

See http://www.smashingmagazine.com/2015/07/designing-simple-pie-charts-with-css/#future-pie-charts and the rest of the article.
For another description of the pie chart thing, view https://air.mozilla.org/view-source-tuesday-pm-session/ starting at 1:03 (or starting at 1:32 is you are only interested in conic gradients).

Oh and even animated ones and pie charts with multiple slices work fine with conic gradients, not just static ones as mentioned in comment #6. And yes, if you look at who presented that talk and who filed this bug, you will find some similarity. ;-)
(In reply to vinci from comment #6)
> +1. This would be very useful for static pie charts.

Not just static. Once gradient interpolation is implemented, this would be animatable too.

@Jeff: Direct2D 1.1 does support mesh gradients, so this should be easy(ish) to implement on Windows. From my discussions with other Mozilla graphics guys it seems that the main roadblock here is Core Graphics, though I've heard from Apple guys that they have requested something similar from the CG team. When it will be implemented, who knows. But it should be noted that Microsoft has put conical gradients on the backlog for Edge [1].

[1]: https://wpdev.uservoice.com/forums/257854-microsoft-edge-developer/suggestions/8471413-implement-conic-gradients-from-css-image-values-le
Alias: conic-gradients
Keywords: dev-doc-needed
Other browsers have started to implement conic gradients:

In development for blink (and useable in Chrome stable behind "Experimental Web Platform Features" flag):
https://www.chromestatus.com/features/5706155347148800

In development for webkit: 
https://webkit.org/status/#feature-conic-gradients
Chrome intents to ship conic-gradient now:

https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/ySuNvyaB8jY
Latest Safari Technical Preview supports conical gradients: https://webkit.org/blog/8414/release-notes-for-safari-technology-preview-66/
(In reply to captlid from comment #19)
> I would like conic gradients implemented too. 
> 
> I am writing a script where a pie chart will change each color's size based
> on form oninput typed in by the user that calculates percentages.

I'd recommend just using SVG for this. Using conical gradients will be much more expensive to draw than solid slices of a pie.
https://developer.mozilla.org/en-US/docs/Web/CSS/conic-gradient (BCD and Interactive examples need to be merged, but complete)
Very detailed description, Estelle! As far as I know (and please correct me if that info is not valid anymore), dev-doc-needed is kept until a feature is implemented in Gecko to signal that the compatibility data needs to be adjusted and the feature mentioned in the release notes. So I'm resetting it.

Sebastian
> I'd recommend just using SVG for this. Using conical gradients will be much
> more expensive to draw than solid slices of a pie.

What features of svg would be the best for this then?

Desktop Chrome finally enabled conic gradients!!!

I finally got this working, works in firefox, my friend's iphone 6. Had no other devices to test on. 
https://codepen.io/captlid/pen/BvZybM

Uses css clip and runs calculations and logic for slices bigger than 50%.

Seems to work fast enough without lag issues.
Whiteboard: gfx-noted → gfx-noted [layout:backlog]
Type: defect → enhancement

In addition to pie charts, conic gradients can be used to cool effect with border image.

https://developer.mozilla.org/en-US/docs/Web/CSS/border-image

Border image might not be the best bet as it is incompatible with border-radius. But setting a conic-gradient as a background of a wrapping div with the padding the width of the intended border might work.

Example of conic gradient used for a gradient border:
https://codepen.io/hyvyys/pen/pXxvGO

I am working on a gradient tool that combines all three gradients into one tool. http://preview.thewebkid.com/gradients

My hope is you will open chrome (http://preview.thewebkid.com/gradients), explore my tool, see the value, and implement this. I am going to write an animation engine next and take this public in the coming weeks. I really do not want to have to write a convoluted polyfill for this, but I will if you guys don't prioritize this.

Chrome nailed this a year ago. Edge gave up and will by default support it when they adopt webkit.

Will you? Or will you be forced to adopt webkit eventually also?

Hope not...

Flags: needinfo?(jbonisteel)

(In reply to thewebkid from comment #27)

Chrome nailed this a year ago. Edge gave up and will by default support it when they adopt webkit.

Will you? Or will you be forced to adopt webkit eventually also?

As much as I'd like to see this feature implemented, this bug report is not for "I'd also like to have this" comments nor for forcing Mozilla to implement it, see points 2 and 4 of the Bugzilla Etiquette. Keep in mind that the implementation of features always depends on resources and priorities.

So, I suggest, instead of writing comments here, just vote for it, ask in the forums, and/or on IRC to keep the noise here down.

I really do not want to have to write a convoluted polyfill for this, but I will if you guys don't prioritize this.

Please note that there are already some polyfills like the one from Lea, the reporter of this feature request.

As Jessie didn't respond to the needinfo request, I remove it now.

Sebastian

Flags: needinfo?(jbonisteel)
Keywords: parity-safari
Whiteboard: gfx-noted [layout:backlog] → gfx-noted [layout:backlog:2020]
Assignee: nobody → ntim.bugs
Status: NEW → ASSIGNED
Version: 34 Branch → unspecified
Component: Graphics → CSS Parsing and Computation
Depends on: 1614160
Depends on: 1614202
No longer depends on: 1614160

Comment on attachment 9125284 [details]
Bug 1175958 - Implement parsing for conic-gradient in style system.

Revision D62148 was moved to bug 1614202. Setting attachment 9125284 [details] to obsolete.

Attachment #9125284 - Attachment is obsolete: true
Depends on: 1614890

Comment on attachment 9125269 [details]
Bug 1175958 - Implement conic-gradient for WebRender graphics backend.

Revision D61599 was moved to bug 1614890. Setting attachment 9125269 [details] to obsolete.

Attachment #9125269 - Attachment is obsolete: true
Depends on: 1614160
Depends on: 1614648
Depends on: 1615489
Depends on: 1615862
Depends on: 1615876
Depends on: 1616106
Depends on: 1615614
Depends on: 1616255
Depends on: 1616559
Depends on: 1616587
No longer depends on: 1616559
Depends on: 1616986
Depends on: 1617039
Depends on: 1617396
Depends on: 1617397
Depends on: 1618997
Depends on: 1619006
Depends on: 1620328
Depends on: 1620951

If you're on Nightly, there's an implementation you can try out behind the layout.css.conic-gradient.enabled preference. It should be available on Beta either today or tomorrow.

If you're using Windows, you also have to enable gfx.webrender.all since it's not implemented for Direct2D yet (see bug 1617396).

Depends on: 1621794
Depends on: 1625917
Depends on: 1627014
Depends on: 1632351
Assignee: ntim.bugs → nobody
Status: ASSIGNED → NEW
Depends on: 1635818
Depends on: 1638348

Now that we triage by severity, setting priority to P1 to reflect backlog prioritization on this bug as either in-progress, or planned development in the near term. See https://wiki.mozilla.org/Platform/Layout#Backlog_Tracking_in_Bugzilla

Priority: P3 → P1
Depends on: 1652751

If everything goes well, this should be available to everyone from Firefox 83 without any preference to enable, see bug 1632351. 🎉

You need to log in before you can comment on or make changes to this bug.