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

Support dithering gradients in the skia renderer #5482

Merged
merged 3 commits into from
Jun 26, 2024

Conversation

wbk
Copy link
Contributor

@wbk wbk commented Jun 26, 2024

Notes

This overcomplicates brush_to_shader() a bit more than necessary to avoid duplicating two lines of code, but it made sense to me to pair shader-specific paint settings with shader-instantiation. One consideration is that brush_to_paint() already exists and has several callers in the renderer, but produces a Paint object that isn't compatible with colorize_image(). brush_to_shader() only has these two callers(one being brush_to_paint(), the other being colorize_image() so the complexity is mostly tucked away from the rest of the module.

Also, when trying this out with the energy monitor example, it seems to have traded banding in the background radial gradient for jitter in the background radial gradient. This doesn't make sense to me because dithering in skia is deterministic, but still seems like an improvement to me, and doesn't seem to affect linear gradients. Unsure if that's something idiosyncratic to the energy monitor, or to radial gradients.

@CLAassistant
Copy link

CLAassistant commented Jun 26, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the patch!

The logic looks fine to me as far as i can see. Just made some style comments

@@ -117,6 +128,7 @@ impl<'a> SkiaItemRenderer<'a> {
}
_ => None,
}
.and_then(|shader| Some(func(paint, Some(shader))))
Copy link
Member

Choose a reason for hiding this comment

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

If i'm not mistaken, this could be written

Suggested change
.and_then(|shader| Some(func(paint, Some(shader))))
.map(|shader| func(paint, Some(shader)))

brush: Brush,
width: PhysicalLength,
height: PhysicalLength,
) -> Option<skia_safe::shader::Shader> {
func: impl FnOnce(skia_safe::Paint, Option<skia_safe::Shader>) -> T,
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit of a strangle pattern.
Why not having a function with this signature: brush_to_shader(...) -> Option(Paint, Shader) instead of taking a callback?
Then it can be used like so:

let (mut paint, shader) = Self::brush_to_shader(...)?;

Anyway it seems that the Shader cannot be None when the function is called, so no need to take an Option as argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just personal preference, I felt like colorize_image was 2% clearer with the closure argument over a tuple return value, but I've been living mostly outside of rust lately and that was probably my being overly accustomed to foreign idioms.

Adjusted to match your feedback.

Copy link
Contributor Author

@wbk wbk Jun 26, 2024

Choose a reason for hiding this comment

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

Edit: [disregard. you were right, this is better. fixup commit added]

Re: taking an Option as an argument, brush_to_paint() is more frequently referenced/called in the source and operates on an Option<shader>, so the cruft in colorize_ image(), to me, was simply picking favorites between the two callers (even though colorize suffers more than to_paint benefits). Happy to knock a ? from one and add a Some to the other if you find that preferable.

@wbk wbk force-pushed the feature/skia-dithered-gradients branch from dd50a43 to c7ddb4d Compare June 26, 2024 08:31
Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

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

Thanks!

@tronical tronical merged commit 56e6d7b into slint-ui:master Jun 26, 2024
36 checks passed
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.

Investigate color banding with gradient on what might be a 16bpp display
4 participants