Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IConicGradientBrush and a drawing implemention for Skia. #4745

Merged
merged 8 commits into from
Oct 25, 2020
Merged

Add IConicGradientBrush and a drawing implemention for Skia. #4745

merged 8 commits into from
Oct 25, 2020

Conversation

olliholliday
Copy link
Contributor

@olliholliday olliholliday commented Sep 26, 2020

Add render tests and expected results graphics.

What does the pull request do?

Currently supported gradient brushes are Linear and Radial. Skia and CSS both have support for so called Conic Gradient (CSS) and Sweep Gradient (Skia).

This type of gradient has equal colours for each angle around the center point - whereas a radial gradient has equal colours for each distance from the centerpoint - an example graphic can be seen here: https://css-tricks.com/snippets/css/css-conic-gradient/.

What is the updated/expected behavior with this PR?

This PR adds ISweepGradient IConicGradient and a Skia drawing implementation.

I have added rendering tests with expected results.

How was the solution implemented (if it's not obvious)?

The implementation closely matches existing gradient implementations. It passes through rendering straight to Skia via SKShader.

I added an additional property for Angle which allows you to set the angle that the gradient should start at, in Skia this is achieved via a rotation matrix.

I chose to specify the angle in degrees rather than radians, and I chose the default rotation value of 0 to conform to the Skia standard of the gradient stop at offset 0 runs horizontally from the center point to the right hand side. In CSS the default is for the first gradient stop to be vertical.

I chose to specify the angle in degrees rather than radians, and I chose the default rotation value of 0 to conform to the CSS standard of the gradient stop at offset 0 runs vertically from the center point.

Checklist

Sorry, something went wrong.

@dnfadmin
Copy link

dnfadmin commented Sep 26, 2020

CLA assistant check
All CLA requirements met.

@olliholliday
Copy link
Contributor Author

olliholliday commented Sep 26, 2020

I've refactored to name the brush ConicGradient to match the CSS name, and to default to angle 0 as being 12 on the clockface, again like CSS.

@olliholliday olliholliday changed the title Add ISweepGradientBrush and a drawing implementing for Skia. Add IConicGradientBrush and a drawing implementing for Skia. Sep 26, 2020
@olliholliday olliholliday changed the title Add IConicGradientBrush and a drawing implementing for Skia. Add IConicGradientBrush and a drawing implemention for Skia. Sep 26, 2020
@olliholliday
Copy link
Contributor Author

I've looked at how to implement this for Direct2D but it's not a simple thing, the Mozilla Direct2D renderer has an implementation that uses a pixel shader which might be usable? I'm unsure of how to make this work.

https://bugzilla.mozilla.org/show_bug.cgi?id=1617396

@Gillibald
Copy link
Contributor

You could disable the test for the Direct2D1 backend. Still, it should not crash when the brush is being used in combination with the Direct2D1 backend. You can use a fallback for the Direct2D1 backend.

@olliholliday
Copy link
Contributor Author

I've added a D2D rendering implementation which is just a copy of the RadialGradientImpl - not sure how else to do this?

[email protected] and others added 8 commits October 7, 2020 20:04
…on for Direct2D using SolidColorBrushImpl.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Copy link
Collaborator

@MarchingCube MarchingCube left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Sorry for the delay.

@danwalmsley danwalmsley merged commit 157ef81 into AvaloniaUI:master Oct 25, 2020
@olliholliday olliholliday deleted the feature/sweepgradientbrush branch October 25, 2020 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants