ShaderWarmUp class Null safety
Interface for drawing an image to warm up Skia shader compilations.
When Skia first sees a certain type of draw operation on the GPU, it needs to compile the corresponding shader. The compilation can be slow (20ms- 200ms). Having that time as startup latency is often better than having jank in the middle of an animation.
Therefore, we use this during the PaintingBinding.initInstances call to move common shader compilations from animation time to startup time. If needed, app developers can create a custom ShaderWarmUp subclass and hand it to PaintingBinding.shaderWarmUp before PaintingBinding.initInstances is called. Usually, that can be done before calling runApp.
To determine whether a draw operation is useful for warming up shaders,
check whether it improves the slowest frame rasterization time. Also,
flutter run --profile --trace-skia may reveal whether there
is shader-compilation-related jank. If there is such jank, some long
GrGLProgramBuilder::finalize calls would appear in the middle of an
animation. Their parent calls, which look like
CircularRRectOp) would suggest Xyz draw operations are causing the shaders
to be compiled. A useful shader warm-up draw operation would eliminate such
long compilation calls in the animation. To double-check the warm-up, trace
flutter run --profile --trace-skia --start-paused. The
GrGLProgramBuilder with the associated
XyzOp should appear during
startup rather than in the middle of a later animation.
This warm-up needs to be run on each individual device because the shader compilation depends on the specific GPU hardware and driver a device has. It can't be pre-computed during the Flutter engine compilation as the engine is device-agnostic.
Abstract const constructor. This constructor enables subclasses to provide
const constructors so that they can be used in const expressions.
) → Future< void>
- Construct an offscreen image of size, and execute warmUpOnCanvas on a canvas associated with that image.
Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
) → String
A string representation of this object.
Canvas canvas) → Future< void>
- Trigger draw operations on a given canvas to warm up GPU shader compilation cache.