Commit graph

7 commits

Author SHA1 Message Date
MacDue
63b11030f0 Everywhere: Use ReadonlySpan<T> instead of Span<T const> 2023-02-08 19:15:45 +00:00
MacDue
d11baf48ae LibGfx: Fix constructor initialisation style in GradientPainting 2023-01-29 13:49:35 +00:00
MacDue
285bd7a37a LibGfx: Stop passing color stop spans by const reference
No idea why I did this, possibly because these were once vectors?
Anyway, the const reference is pointless here.
2023-01-29 13:49:35 +00:00
MacDue
a43d892c4e LibGfx: Use the first/last color for positions before/after a gradient
This fixes a few rendering bugs especially where the first or last
color stop had a zero alpha value. Note we can't just set the first
and last values on the gradient line to the first/last colors since
that might not be correct (e.g. have a transition hint).
2023-01-23 10:03:54 +00:00
MacDue
1a89d77688 LibGfx: Implement paint styles required for HTML canvas gradients
This implements the gradients for:

- CanvasRenderingContext2D.createLinearGradient()
- CanvasRenderingContext2D.createConicGradient()
- CanvasRenderingContext2D.createRadialGradient()

As loosely defined in: https://html.spec.whatwg.org/multipage/canvas.html#fill-and-stroke-styles
(It's really not very well defined for radial gradients)

Actual implementation (for radial gradients) was done with a lot
of trial and error, then visually comparing to other browsers.
2023-01-22 18:15:52 +01:00
MacDue
b31d768e95 LibGfx: Add paint styles and allow gradients to be used as them
Also while here add option to disable pre-multiplied alpha for gradients
(this will be handy later).
2023-01-22 18:15:52 +01:00
MacDue
c8c065b6b0 LibWeb+LibGfx: Migrate (most of) the CSS gradient painting to LibGfx
This moves the CSS gradient painting to the painter creating:

 - Painter::fill_rect_with_linear_gradient()
 - Painter::fill_rect_with_conic_gradient()
 - Painter::fill_rect_with_radial_gradient()

This has a few benefits:
 - The gradients can now easily respect the painter scale
 - The Painter::fill_pixels() escape hatch can be removed
 - We can remove the old fixed color stop gradient code
    - The old functions are  now just a shim
 - Anywhere can now easily use this gradient painting code!

This only leaves the color stop resolution in LibWeb (which is fine).
Just means in LibGfx you have to actually specify color stop positions.

(Also while here add a small optimization to avoid generating
excessively long gradient lines)
2023-01-10 10:25:58 +01:00