pub fn optimize_radial_gradient(
    prim_rect: &mut LayoutRect,
    stretch_size: &mut LayoutSize,
    center: &mut LayoutPoint,
    tile_spacing: &mut LayoutSize,
    clip_rect: &LayoutRect,
    radius: LayoutSize,
    end_offset: f32,
    extend_mode: ExtendMode,
    stops: &[GradientStopKey],
    solid_parts: &mut dyn FnMut(&LayoutRect, ColorU)
)
Expand description

Avoid invoking the radial gradient shader on large areas where the color is constant.

If the extend mode is set to clamp, the “interesting” part of the gradient is only in the bounds of the gradient’s ellipse, and the rest is the color of the last gradient stop.

Sometimes we run into radial gradient with a small radius compared to the primitive bounds, which means a large area of the primitive is a constant color This function tries to detect that, potentially shrink the gradient primitive to only the useful part and if needed insert solid color primitives around the gradient where parts of it have been removed.