pushClipPath method

ClipPathLayer pushClipPath (
  1. bool needsCompositing,
  2. Offset offset,
  3. Rect bounds,
  4. Path clipPath,
  5. PaintingContextCallback painter,
  6. {Clip clipBehavior: Clip.antiAlias,
  7. ClipPathLayer oldLayer}
)

Clip further painting using a path.

The needsCompositing argument specifies whether the child needs compositing. Typically this matches the value of RenderObject.needsCompositing for the caller. If false, this method returns null, indicating that a layer is no longer necessary. If a render object calling this method stores the oldLayer in its RenderObject.layer field, it should set that field to null.

When needsCompositing is false, this method will use a more efficient way to apply the layer effect than actually creating a layer.

The offset argument is the offset from the origin of the canvas' coordinate system to the origin of the caller's coordinate system.

The bounds argument is used to specify the region of the canvas (in the caller's coordinate system) into which painter will paint.

The clipPath argument specifies the Path (in the caller's coordinate system) to use to clip the painting done by painter. It should not include the offset.

The painter callback will be called while the clipPath is applied. It is called synchronously during the call to pushClipPath.

The clipBehavior argument controls how the path is clipped.

For the oldLayer argument, specify the layer created in the previous frame. This gives the engine more information for performance optimizations. Typically this is the value of RenderObject.layer that a render object creates once, then reuses for all subsequent frames until a layer is no longer needed (e.g. the render object no longer needs compositing) or until the render object changes the type of the layer (e.g. from opacity layer to a clip rect layer).

Implementation

ClipPathLayer pushClipPath(bool needsCompositing, Offset offset, Rect bounds, Path clipPath, PaintingContextCallback painter, { Clip clipBehavior = Clip.antiAlias, ClipPathLayer oldLayer }) {
  assert(clipBehavior != null);
  final Rect offsetBounds = bounds.shift(offset);
  final Path offsetClipPath = clipPath.shift(offset);
  if (needsCompositing) {
    final ClipPathLayer layer = oldLayer ?? ClipPathLayer();
    layer
      ..clipPath = offsetClipPath
      ..clipBehavior = clipBehavior;
    pushLayer(layer, painter, offset, childPaintBounds: offsetBounds);
    return layer;
  } else {
    clipPathAndPaint(offsetClipPath, clipBehavior, offsetBounds, () => painter(this, offset));
    return null;
  }
}