Unverified Commit 24abe59f authored by Matej Knopp's avatar Matej Knopp Committed by GitHub

Provide oldLayer where possible (#67320)

parent cba84d51
...@@ -524,11 +524,13 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox { ...@@ -524,11 +524,13 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox {
thumbCenterY + CupertinoThumbPainter.radius, thumbCenterY + CupertinoThumbPainter.radius,
); );
context.pushClipRRect(needsCompositing, Offset.zero, thumbBounds, trackRRect, (PaintingContext innerContext, Offset offset) { _clipRRectLayer = context.pushClipRRect(needsCompositing, Offset.zero, thumbBounds, trackRRect, (PaintingContext innerContext, Offset offset) {
const CupertinoThumbPainter.switchThumb().paint(innerContext.canvas, thumbBounds); const CupertinoThumbPainter.switchThumb().paint(innerContext.canvas, thumbBounds);
}); }, oldLayer: _clipRRectLayer);
} }
ClipRRectLayer? _clipRRectLayer;
@override @override
void debugFillProperties(DiagnosticPropertiesBuilder description) { void debugFillProperties(DiagnosticPropertiesBuilder description) {
super.debugFillProperties(description); super.debugFillProperties(description);
......
...@@ -371,15 +371,17 @@ class _ToolbarRenderBox extends RenderShiftedBox { ...@@ -371,15 +371,17 @@ class _ToolbarRenderBox extends RenderShiftedBox {
} }
final _ToolbarParentData childParentData = child!.parentData! as _ToolbarParentData; final _ToolbarParentData childParentData = child!.parentData! as _ToolbarParentData;
context.pushClipPath( _clipPathLayer = context.pushClipPath(
needsCompositing, needsCompositing,
offset + childParentData.offset, offset + childParentData.offset,
Offset.zero & child!.size, Offset.zero & child!.size,
_clipPath(), _clipPath(),
(PaintingContext innerContext, Offset innerOffset) => innerContext.paintChild(child!, innerOffset), (PaintingContext innerContext, Offset innerOffset) => innerContext.paintChild(child!, innerOffset),
oldLayer: _clipPathLayer
); );
} }
ClipPathLayer? _clipPathLayer;
Paint? _debugPaint; Paint? _debugPaint;
@override @override
......
...@@ -1474,7 +1474,10 @@ class _RenderDecoration extends RenderBox { ...@@ -1474,7 +1474,10 @@ class _RenderDecoration extends RenderBox {
_labelTransform = Matrix4.identity() _labelTransform = Matrix4.identity()
..translate(dx, labelOffset.dy + dy) ..translate(dx, labelOffset.dy + dy)
..scale(scale); ..scale(scale);
context.pushTransform(needsCompositing, offset, _labelTransform!, _paintLabel); _transformLayer = context.pushTransform(needsCompositing, offset, _labelTransform!, _paintLabel,
oldLayer: _transformLayer);
} else {
_transformLayer = null;
} }
doPaint(icon); doPaint(icon);
...@@ -1488,6 +1491,8 @@ class _RenderDecoration extends RenderBox { ...@@ -1488,6 +1491,8 @@ class _RenderDecoration extends RenderBox {
doPaint(counter); doPaint(counter);
} }
TransformLayer? _transformLayer;
@override @override
bool hitTestSelf(Offset position) => true; bool hitTestSelf(Offset position) => true;
......
...@@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart'; ...@@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
import 'box.dart'; import 'box.dart';
import 'layer.dart';
import 'object.dart'; import 'object.dart';
import 'shifted_box.dart'; import 'shifted_box.dart';
...@@ -294,9 +295,13 @@ class RenderAnimatedSize extends RenderAligningShiftedBox { ...@@ -294,9 +295,13 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
if (child != null && _hasVisualOverflow && clipBehavior != Clip.none) { if (child != null && _hasVisualOverflow && clipBehavior != Clip.none) {
final Rect rect = Offset.zero & size; final Rect rect = Offset.zero & size;
context.pushClipRect(needsCompositing, offset, rect, super.paint, clipBehavior: clipBehavior); _clipRectLayer = context.pushClipRect(needsCompositing, offset, rect, super.paint,
clipBehavior: clipBehavior, oldLayer: _clipRectLayer);
} else { } else {
_clipRectLayer = null;
super.paint(context, offset); super.paint(context, offset);
} }
} }
ClipRectLayer? _clipRectLayer;
} }
...@@ -2287,13 +2287,18 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin { ...@@ -2287,13 +2287,18 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
@override @override
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
_layoutText(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth); _layoutText(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth);
if (_hasVisualOverflow && clipBehavior != Clip.none) if (_hasVisualOverflow && clipBehavior != Clip.none) {
context.pushClipRect(needsCompositing, offset, Offset.zero & size, _paintContents, clipBehavior: clipBehavior); _clipRectLayer = context.pushClipRect(needsCompositing, offset, Offset.zero & size, _paintContents,
else clipBehavior: clipBehavior, oldLayer: _clipRectLayer);
} else {
_clipRectLayer = null;
_paintContents(context, offset); _paintContents(context, offset);
}
_paintHandleLayers(context, getEndpointsForSelection(selection!)); _paintHandleLayers(context, getEndpointsForSelection(selection!));
} }
ClipRectLayer? _clipRectLayer;
@override @override
Rect? describeApproximatePaintClip(RenderObject child) => _hasVisualOverflow ? Offset.zero & size : null; Rect? describeApproximatePaintClip(RenderObject child) => _hasVisualOverflow ? Offset.zero & size : null;
......
...@@ -8,6 +8,7 @@ import 'package:flutter/foundation.dart'; ...@@ -8,6 +8,7 @@ import 'package:flutter/foundation.dart';
import 'box.dart'; import 'box.dart';
import 'debug_overflow_indicator.dart'; import 'debug_overflow_indicator.dart';
import 'layer.dart';
import 'object.dart'; import 'object.dart';
/// How the child is inscribed into the available space. /// How the child is inscribed into the available space.
...@@ -977,10 +978,12 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl ...@@ -977,10 +978,12 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
return; return;
if (clipBehavior == Clip.none) { if (clipBehavior == Clip.none) {
_clipRectLayer = null;
defaultPaint(context, offset); defaultPaint(context, offset);
} else { } else {
// We have overflow and the clipBehavior isn't none. Clip it. // We have overflow and the clipBehavior isn't none. Clip it.
context.pushClipRect(needsCompositing, offset, Offset.zero & size, defaultPaint, clipBehavior: clipBehavior); _clipRectLayer = context.pushClipRect(needsCompositing, offset, Offset.zero & size, defaultPaint,
clipBehavior: clipBehavior, oldLayer: _clipRectLayer);
} }
assert(() { assert(() {
...@@ -1026,6 +1029,8 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl ...@@ -1026,6 +1029,8 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
}()); }());
} }
ClipRectLayer? _clipRectLayer;
@override @override
Rect? describeApproximatePaintClip(RenderObject child) => _hasOverflow ? Offset.zero & size : null; Rect? describeApproximatePaintClip(RenderObject child) => _hasOverflow ? Offset.zero & size : null;
......
...@@ -8,6 +8,7 @@ import 'package:flutter/foundation.dart'; ...@@ -8,6 +8,7 @@ import 'package:flutter/foundation.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
import 'box.dart'; import 'box.dart';
import 'layer.dart';
import 'object.dart'; import 'object.dart';
/// A context in which a [FlowDelegate] paints. /// A context in which a [FlowDelegate] paints.
...@@ -383,12 +384,16 @@ class RenderFlow extends RenderBox ...@@ -383,12 +384,16 @@ class RenderFlow extends RenderBox
@override @override
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
if (clipBehavior == Clip.none) { if (clipBehavior == Clip.none) {
_clipRectLayer = null;
_paintWithDelegate(context, offset); _paintWithDelegate(context, offset);
} else { } else {
context.pushClipRect(needsCompositing, offset, Offset.zero & size, _paintWithDelegate, clipBehavior: clipBehavior); _clipRectLayer = context.pushClipRect(needsCompositing, offset, Offset.zero & size, _paintWithDelegate,
clipBehavior: clipBehavior, oldLayer: _clipRectLayer);
} }
} }
ClipRectLayer? _clipRectLayer;
@override @override
bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { bool hitTestChildren(BoxHitTestResult result, { required Offset position }) {
final List<RenderBox> children = getChildrenAsList(); final List<RenderBox> children = getChildrenAsList();
......
...@@ -8,6 +8,7 @@ import 'package:flutter/animation.dart'; ...@@ -8,6 +8,7 @@ import 'package:flutter/animation.dart';
import 'package:vector_math/vector_math_64.dart' show Matrix4; import 'package:vector_math/vector_math_64.dart' show Matrix4;
import 'box.dart'; import 'box.dart';
import 'layer.dart';
import 'object.dart'; import 'object.dart';
import 'viewport.dart'; import 'viewport.dart';
import 'viewport_offset.dart'; import 'viewport_offset.dart';
...@@ -784,19 +785,23 @@ class RenderListWheelViewport ...@@ -784,19 +785,23 @@ class RenderListWheelViewport
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
if (childCount > 0) { if (childCount > 0) {
if (_shouldClipAtCurrentOffset() && clipBehavior != Clip.none) { if (_shouldClipAtCurrentOffset() && clipBehavior != Clip.none) {
context.pushClipRect( _clipRectLayer = context.pushClipRect(
needsCompositing, needsCompositing,
offset, offset,
Offset.zero & size, Offset.zero & size,
_paintVisibleChildren, _paintVisibleChildren,
clipBehavior: clipBehavior, clipBehavior: clipBehavior,
oldLayer: _clipRectLayer,
); );
} else { } else {
_clipRectLayer = null;
_paintVisibleChildren(context, offset); _paintVisibleChildren(context, offset);
} }
} }
} }
ClipRectLayer? _clipRectLayer;
/// Paints all children visible in the current viewport. /// Paints all children visible in the current viewport.
void _paintVisibleChildren(PaintingContext context, Offset offset) { void _paintVisibleChildren(PaintingContext context, Offset offset) {
RenderBox? childToPaint = firstChild; RenderBox? childToPaint = firstChild;
......
...@@ -206,13 +206,16 @@ class RenderAndroidView extends RenderBox with _PlatformViewGestureMixin { ...@@ -206,13 +206,16 @@ class RenderAndroidView extends RenderBox with _PlatformViewGestureMixin {
// Clip the texture if it's going to paint out of the bounds of the renter box // Clip the texture if it's going to paint out of the bounds of the renter box
// (see comment in _paintTexture for an explanation of when this happens). // (see comment in _paintTexture for an explanation of when this happens).
if ((size.width < _currentAndroidViewSize.width || size.height < _currentAndroidViewSize.height) && clipBehavior != Clip.none) { if ((size.width < _currentAndroidViewSize.width || size.height < _currentAndroidViewSize.height) && clipBehavior != Clip.none) {
context.pushClipRect(true, offset, offset & size, _paintTexture, clipBehavior: clipBehavior); _clipRectLayer = context.pushClipRect(true, offset, offset & size, _paintTexture, clipBehavior: clipBehavior,
oldLayer: _clipRectLayer);
return; return;
} }
_clipRectLayer = null;
_paintTexture(context, offset); _paintTexture(context, offset);
} }
ClipRectLayer? _clipRectLayer;
void _paintTexture(PaintingContext context, Offset offset) { void _paintTexture(PaintingContext context, Offset offset) {
// As resizing the Android view happens asynchronously we don't know exactly when is a // As resizing the Android view happens asynchronously we don't know exactly when is a
// texture frame with the new size is ready for consumption. // texture frame with the new size is ready for consumption.
......
...@@ -9,6 +9,7 @@ import 'package:flutter/painting.dart'; ...@@ -9,6 +9,7 @@ import 'package:flutter/painting.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
import 'box.dart'; import 'box.dart';
import 'layer.dart';
import 'object.dart'; import 'object.dart';
const double _kQuarterTurnsInRadians = math.pi / 2.0; const double _kQuarterTurnsInRadians = math.pi / 2.0;
...@@ -108,10 +109,16 @@ class RenderRotatedBox extends RenderBox with RenderObjectWithChildMixin<RenderB ...@@ -108,10 +109,16 @@ class RenderRotatedBox extends RenderBox with RenderObjectWithChildMixin<RenderB
@override @override
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
if (child != null) if (child != null) {
context.pushTransform(needsCompositing, offset, _paintTransform!, _paintChild); _transformLayer = context.pushTransform(needsCompositing, offset, _paintTransform!, _paintChild,
oldLayer: _transformLayer);
} else {
_transformLayer = null;
}
} }
TransformLayer? _transformLayer;
@override @override
void applyPaintTransform(RenderBox child, Matrix4 transform) { void applyPaintTransform(RenderBox child, Matrix4 transform) {
if (_paintTransform != null) if (_paintTransform != null)
......
...@@ -9,6 +9,7 @@ import 'package:flutter/foundation.dart'; ...@@ -9,6 +9,7 @@ import 'package:flutter/foundation.dart';
import 'box.dart'; import 'box.dart';
import 'debug.dart'; import 'debug.dart';
import 'debug_overflow_indicator.dart'; import 'debug_overflow_indicator.dart';
import 'layer.dart';
import 'object.dart'; import 'object.dart';
import 'stack.dart' show RelativeRect; import 'stack.dart' show RelativeRect;
...@@ -712,10 +713,12 @@ class RenderUnconstrainedBox extends RenderAligningShiftedBox with DebugOverflow ...@@ -712,10 +713,12 @@ class RenderUnconstrainedBox extends RenderAligningShiftedBox with DebugOverflow
} }
if (clipBehavior == Clip.none) { if (clipBehavior == Clip.none) {
_clipRectLayer = null;
super.paint(context, offset); super.paint(context, offset);
} else { } else {
// We have overflow and the clipBehavior isn't none. Clip it. // We have overflow and the clipBehavior isn't none. Clip it.
context.pushClipRect(needsCompositing, offset, Offset.zero & size, super.paint, clipBehavior: clipBehavior); _clipRectLayer = context.pushClipRect(needsCompositing, offset, Offset.zero & size, super.paint,
clipBehavior: clipBehavior, oldLayer:_clipRectLayer);
} }
// Display the overflow indicator. // Display the overflow indicator.
...@@ -725,6 +728,8 @@ class RenderUnconstrainedBox extends RenderAligningShiftedBox with DebugOverflow ...@@ -725,6 +728,8 @@ class RenderUnconstrainedBox extends RenderAligningShiftedBox with DebugOverflow
}()); }());
} }
ClipRectLayer? _clipRectLayer;
@override @override
Rect? describeApproximatePaintClip(RenderObject child) { Rect? describeApproximatePaintClip(RenderObject child) {
return _isOverflowing ? Offset.zero & size : null; return _isOverflowing ? Offset.zero & size : null;
......
...@@ -8,6 +8,7 @@ import 'dart:ui' show lerpDouble, hashValues; ...@@ -8,6 +8,7 @@ import 'dart:ui' show lerpDouble, hashValues;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'box.dart'; import 'box.dart';
import 'layer.dart';
import 'object.dart'; import 'object.dart';
/// An immutable 2D, axis-aligned, floating-point rectangle whose coordinates /// An immutable 2D, axis-aligned, floating-point rectangle whose coordinates
...@@ -613,12 +614,16 @@ class RenderStack extends RenderBox ...@@ -613,12 +614,16 @@ class RenderStack extends RenderBox
@override @override
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
if (clipBehavior != Clip.none && _hasVisualOverflow) { if (clipBehavior != Clip.none && _hasVisualOverflow) {
context.pushClipRect(needsCompositing, offset, Offset.zero & size, paintStack, clipBehavior: clipBehavior); _clipRectLayer = context.pushClipRect(needsCompositing, offset, Offset.zero & size, paintStack,
clipBehavior: clipBehavior, oldLayer: _clipRectLayer);
} else { } else {
_clipRectLayer = null;
paintStack(context, offset); paintStack(context, offset);
} }
} }
ClipRectLayer? _clipRectLayer;
@override @override
Rect? describeApproximatePaintClip(RenderObject child) => _hasVisualOverflow ? Offset.zero & size : null; Rect? describeApproximatePaintClip(RenderObject child) => _hasVisualOverflow ? Offset.zero & size : null;
......
...@@ -11,6 +11,7 @@ import 'package:flutter/semantics.dart'; ...@@ -11,6 +11,7 @@ import 'package:flutter/semantics.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
import 'box.dart'; import 'box.dart';
import 'layer.dart';
import 'object.dart'; import 'object.dart';
import 'sliver.dart'; import 'sliver.dart';
import 'viewport_offset.dart'; import 'viewport_offset.dart';
...@@ -629,12 +630,16 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix ...@@ -629,12 +630,16 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix
if (firstChild == null) if (firstChild == null)
return; return;
if (hasVisualOverflow && clipBehavior != Clip.none) { if (hasVisualOverflow && clipBehavior != Clip.none) {
context.pushClipRect(needsCompositing, offset, Offset.zero & size, _paintContents, clipBehavior: clipBehavior); _clipRectLayer = context.pushClipRect(needsCompositing, offset, Offset.zero & size, _paintContents,
clipBehavior: clipBehavior, oldLayer: _clipRectLayer);
} else { } else {
_clipRectLayer = null;
_paintContents(context, offset); _paintContents(context, offset);
} }
} }
ClipRectLayer? _clipRectLayer;
void _paintContents(PaintingContext context, Offset offset) { void _paintContents(PaintingContext context, Offset offset) {
for (final RenderSliver child in childrenInPaintOrder) { for (final RenderSliver child in childrenInPaintOrder) {
if (child.geometry!.visible) if (child.geometry!.visible)
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'box.dart'; import 'box.dart';
import 'layer.dart';
import 'object.dart'; import 'object.dart';
/// How [Wrap] should align objects. /// How [Wrap] should align objects.
...@@ -763,12 +764,17 @@ class RenderWrap extends RenderBox ...@@ -763,12 +764,17 @@ class RenderWrap extends RenderBox
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
// TODO(ianh): move the debug flex overflow paint logic somewhere common so // TODO(ianh): move the debug flex overflow paint logic somewhere common so
// it can be reused here // it can be reused here
if (_hasVisualOverflow && clipBehavior != Clip.none) if (_hasVisualOverflow && clipBehavior != Clip.none) {
context.pushClipRect(needsCompositing, offset, Offset.zero & size, defaultPaint, clipBehavior: clipBehavior); _clipRectLayer = context.pushClipRect(needsCompositing, offset, Offset.zero & size, defaultPaint,
else clipBehavior: clipBehavior, oldLayer: _clipRectLayer);
} else {
_clipRectLayer = null;
defaultPaint(context, offset); defaultPaint(context, offset);
}
} }
ClipRectLayer? _clipRectLayer;
@override @override
void debugFillProperties(DiagnosticPropertiesBuilder properties) { void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties); super.debugFillProperties(properties);
......
...@@ -756,12 +756,16 @@ class _RenderTheatre extends RenderBox with ContainerRenderObjectMixin<RenderBox ...@@ -756,12 +756,16 @@ class _RenderTheatre extends RenderBox with ContainerRenderObjectMixin<RenderBox
@override @override
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
if (_hasVisualOverflow && clipBehavior != Clip.none) { if (_hasVisualOverflow && clipBehavior != Clip.none) {
context.pushClipRect(needsCompositing, offset, Offset.zero & size, paintStack, clipBehavior: clipBehavior); _clipRectLayer = context.pushClipRect(needsCompositing, offset, Offset.zero & size, paintStack,
clipBehavior: clipBehavior, oldLayer: _clipRectLayer);
} else { } else {
_clipRectLayer = null;
paintStack(context, offset); paintStack(context, offset);
} }
} }
ClipRectLayer? _clipRectLayer;
@override @override
void visitChildrenForSemantics(RenderObjectVisitor visitor) { void visitChildrenForSemantics(RenderObjectVisitor visitor) {
RenderBox? child = _firstOnstageChild; RenderBox? child = _firstOnstageChild;
......
...@@ -583,13 +583,17 @@ class _RenderSingleChildViewport extends RenderBox with RenderObjectWithChildMix ...@@ -583,13 +583,17 @@ class _RenderSingleChildViewport extends RenderBox with RenderObjectWithChildMix
} }
if (_shouldClipAtPaintOffset(paintOffset) && clipBehavior != Clip.none) { if (_shouldClipAtPaintOffset(paintOffset) && clipBehavior != Clip.none) {
context.pushClipRect(needsCompositing, offset, Offset.zero & size, paintContents, clipBehavior: clipBehavior); _clipRectLayer = context.pushClipRect(needsCompositing, offset, Offset.zero & size, paintContents,
clipBehavior: clipBehavior, oldLayer: _clipRectLayer);
} else { } else {
_clipRectLayer = null;
paintContents(context, offset); paintContents(context, offset);
} }
} }
} }
ClipRectLayer? _clipRectLayer;
@override @override
void applyPaintTransform(RenderBox child, Matrix4 transform) { void applyPaintTransform(RenderBox child, Matrix4 transform) {
final Offset paintOffset = _paintOffset; final Offset paintOffset = _paintOffset;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment