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. By default, a DefaultShaderWarmUp is used. If needed, app developers can create a custom ShaderWarmUp subclass and hand it to PaintingBinding.shaderWarmUp (so it replaces DefaultShaderWarmUp) 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 GPU frame. Also, tracing with
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 with
flutter run --profile --trace-skia --start-paused.
GrGLProgramBuilder with the associated
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.
Allow const constructors for subclasses.
) → Future< void>
- Construct an offscreen image of size, and execute warmUpOnCanvas on a canvas associated with that image.
Canvas canvas ) → Future< void>
Trigger draw operations on a given canvas to warm up GPU shader
compilation cache. [...]
Invocation invocation ) → dynamic
Invoked when a non-existent method or property is accessed. [...]
) → String
Returns a string representation of this object.