ShaderProgram
Android's own runtime shaders, which arrived in version 33.
The language is the same one Skia uses, with a smaller set of built in functions, so a program written for the desktop usually runs here unchanged. Below version 33 there is no way to run one at all: available is false and a drawing that needs one has to fall back to shapes or be left out of the list on that device.
A small program that runs once for every pixel, compiled from source at runtime.
This is the one thing that changes what the library can draw rather than how well. Everything else here builds a picture out of lines and circles, which means the cost grows with how much detail is wanted and a full screen of swirling colour costs a full screen of shapes. A shader is handed a pixel and asked what colour it should be, and the graphics card asks a few million times at once. Plasma, flowing noise, fractals and raymarched tunnels all become one draw call.
The language is SkSL, which is close enough to GLSL to read. Write a main that takes a position and returns a colour:
uniform float2 uResolution;
half4 main(float2 position) {
float2 uv = position / uResolution;
return half4(uv.x, uv.y, 0.5, 1.0);
}The source declares every value it reads, as uResolution is declared here; nothing is added to it. Set those values with uniform and child, then hand brush to any Compose draw call. Values persist between frames, so only what changed has to be set again.
Not every device can run one. Android gained the ability in version 33, and anything older reports available as false, so a drawing that needs a shader has to say what it does instead.
Desktop and iOS both draw through Skia, so both get this one.
The compiled program and the builder holding its values are made once and reused. Compiling on every frame would be far more expensive than the drawing.
Properties
Functions
Hands the shader a picture to read, declared as uniform shader name.
Hands the shader a picture to read, declared as uniform shader name.
Hands the shader a picture to read, declared as uniform shader name.
Sets an array of values, for anything declared as uniform float3 name[8] or similar.
Sets an array of values, for anything declared as uniform float3 name[8] or similar.
Sets an array of values, for anything declared as uniform float3 name[8] or similar.