After watching this (rage bait) rant on Firefox gr...
# compose
s
After watching this (rage bait) rant on Firefox gradients not doing dithering, I was left wondering if Compose did that...

https://www.youtube.com/watch?v=mmjUlFIaNLE

A quick experiment (on desktop) showed that it doesn't (see image), but knowing Skia does support dithering, it wasn't all too hard to get it working 🧵
r
Yeah all it should take is enable dithering on the paint object. Although I must say I'm bummed Skia doesn't always dither gradients. I also haven't checked what dithering Skia is using nowadays but it used to be not great (we had better dithering in Android's custom rendering pipeline for a while)
s
I was just gonna do a whole writeup but.. yeah that's exactly it 😄
The only issue to making a nice workaround for now is that
ShaderBrush
is only a wrapper over a
Shader
, so we can't get hold of the
Paint
and set
isDither
to true.
r
(I implemented dithering in Android's rendering pipeline when we were not using Skia :)
❤️ 3
s
It would've been nice if there's was a subclass of
Brush
that works like
SolidColor
, with an
applyTo
function.
Haven't actually tried this on Android, just Skiko for now I think it would be similar? (
Paint().asFrameworkPaint()
then some property/function to enable dithering?)
r
Yeah. But again, it should just always be enabled for gradients. I forget if that's what we do in Compose for Android or just Android
s
Yeah exactly, as I was researching this, Flutter also enabled it by default (on both backends, Impeller and Skia) a couple years ago.
r
Anyway so I'd suggest filing bugs or sending PRs. Don't fix it in the app
1
s
I think API wise, that should part of the
ShaderBrush
class, so if somebody is doing a "gradient-like" thing with a custom brush, they could signal to whatever draws that shader into a paint that they want dithering enabled.
Yeah ofc, I was just experimenting (and I love that I can do this at all in compose :D) I'll fire file a feature request
r
ShaderBrush has an applyTo
s
ooh but it's final
It's just a default implementation that takes the shader from
createShader
and renders it
We can't actually override it
r
You could subclass and override that method
s
Oh wait shoot you're right
It didn't show up in the IDE suggestions so I thought it wasn't possible 🤦
So it is possible to workaround cleanly afterall
r
Hmm I can't find the talk where I discuss dithering in details
s
For submitting a PR, how should I go about that? Never contributed to Androidx before
s
Oh, I was right... 😅
that really shouldn't be final
@romainguy those instructions seem to be geared for GitHub contributions, which don't include Compose UI (only Compose Runtime)
Alright, found these onboarding instructions for Gerrit: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:docs/onboarding.md (would love Compose UI to be available on GitHub at some point; I feel so much friction to contributing already 😬)
r
It's really not more difficult than going through GitHub but you need to do it once to understand what to do.
👍 1