pushClipRRect method

ClipRRectLayer? pushClipRRect(
  1. bool needsCompositing,
  2. Offset offset,
  3. Rect bounds,
  4. RRect clipRRect,
  5. PaintingContextCallback painter,
  6. {Clip clipBehavior = Clip.antiAlias,
  7. ClipRRectLayer? oldLayer}
)

Clip further painting using a rounded rectangle.

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 clipRRect argument specifies the rounded-rectangle (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 clipRRect is applied. It is called synchronously during the call to pushClipRRect.

The clipBehavior argument controls how the rounded rectangle 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

ClipRRectLayer? pushClipRRect(bool needsCompositing, Offset offset, Rect bounds, RRect clipRRect, PaintingContextCallback painter, { Clip clipBehavior = Clip.antiAlias, ClipRRectLayer? oldLayer }) {
  if (clipBehavior == Clip.none) {
    painter(this, offset);
    return null;
  }
  final Rect offsetBounds = bounds.shift(offset);
  final RRect offsetClipRRect = clipRRect.shift(offset);
  if (needsCompositing) {
    final ClipRRectLayer layer = oldLayer ?? ClipRRectLayer();
    layer
      ..clipRRect = offsetClipRRect
      ..clipBehavior = clipBehavior;
    pushLayer(layer, painter, offset, childPaintBounds: offsetBounds);
    return layer;
  } else {
    clipRRectAndPaint(offsetClipRRect, clipBehavior, offsetBounds, () => painter(this, offset));
    return null;
  }
}