maskGeometryOf function
Same as maskGeometryFromGlobalKey for an already resolved render object.
Implementation
MaskGeometry? maskGeometryOf(RenderObject? renderObject) {
if (renderObject == null || !renderObject.attached) {
return null;
}
if (renderObject is RenderBox && !renderObject.hasSize) {
return null;
}
final Rect bounds = MatrixUtils.transformRect(
renderObject.getTransformTo(null),
renderObject.paintBounds,
);
Rect clip = Rect.largest;
RenderObject child = renderObject;
while (true) {
// Not typed on purpose: `parent` is AbstractNode? on older Flutter and
// RenderObject? on newer ones.
final parent = child.parent;
if (parent is! RenderObject) {
// `child` is the root render object; nothing paints outside of it.
// RenderView.paintBounds is in physical pixels, hence `size`.
final Rect rootBounds = child is RenderView
? Offset.zero & child.size
: child.paintBounds;
clip = clip.intersect(MatrixUtils.transformRect(
child.getTransformTo(null),
rootBounds,
));
break;
}
if (parent is RenderOffstage && parent.offstage) {
return null;
}
final Rect? localClip = parent.describeApproximatePaintClip(child);
if (localClip != null) {
clip = clip.intersect(MatrixUtils.transformRect(
parent.getTransformTo(null),
localClip,
));
}
child = parent;
}
return MaskGeometry(bounds, clip);
}