Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit fba9214

Browse files
[framework] remove usage and deprecate physical model layer (#102274)
1 parent e493d5c commit fba9214

20 files changed

+279
-293
lines changed

packages/flutter/lib/src/rendering/flex.dart

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,20 +1083,14 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
10831083
if (size.isEmpty)
10841084
return;
10851085

1086-
if (clipBehavior == Clip.none) {
1087-
_clipRectLayer.layer = null;
1088-
defaultPaint(context, offset);
1089-
} else {
1090-
// We have overflow and the clipBehavior isn't none. Clip it.
1091-
_clipRectLayer.layer = context.pushClipRect(
1092-
needsCompositing,
1093-
offset,
1094-
Offset.zero & size,
1095-
defaultPaint,
1096-
clipBehavior: clipBehavior,
1097-
oldLayer: _clipRectLayer.layer,
1098-
);
1099-
}
1086+
_clipRectLayer.layer = context.pushClipRect(
1087+
needsCompositing,
1088+
offset,
1089+
Offset.zero & size,
1090+
defaultPaint,
1091+
clipBehavior: clipBehavior,
1092+
oldLayer: _clipRectLayer.layer,
1093+
);
11001094

11011095
assert(() {
11021096
// Only set this if it's null to save work. It gets reset to null if the

packages/flutter/lib/src/rendering/flow.dart

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -388,19 +388,14 @@ class RenderFlow extends RenderBox
388388

389389
@override
390390
void paint(PaintingContext context, Offset offset) {
391-
if (clipBehavior == Clip.none) {
392-
_clipRectLayer.layer = null;
393-
_paintWithDelegate(context, offset);
394-
} else {
395-
_clipRectLayer.layer = context.pushClipRect(
396-
needsCompositing,
397-
offset,
398-
Offset.zero & size,
399-
_paintWithDelegate,
400-
clipBehavior: clipBehavior,
401-
oldLayer: _clipRectLayer.layer,
402-
);
403-
}
391+
_clipRectLayer.layer = context.pushClipRect(
392+
needsCompositing,
393+
offset,
394+
Offset.zero & size,
395+
_paintWithDelegate,
396+
clipBehavior: clipBehavior,
397+
oldLayer: _clipRectLayer.layer,
398+
);
404399
}
405400

406401
final LayerHandle<ClipRectLayer> _clipRectLayer = LayerHandle<ClipRectLayer>();

packages/flutter/lib/src/rendering/layer.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,12 +1972,20 @@ class BackdropFilterLayer extends ContainerLayer {
19721972
/// When debugging, setting [debugDisablePhysicalShapeLayers] to true will cause this
19731973
/// layer to be skipped (directly replaced by its children). This can be helpful
19741974
/// to track down the cause of performance problems.
1975+
@Deprecated(
1976+
'Use a clip and canvas operations directly (See RenderPhysicalModel). '
1977+
'This feature was deprecated after v2.13.0-0.0.pre.',
1978+
)
19751979
class PhysicalModelLayer extends ContainerLayer {
19761980
/// Creates a composited layer that uses a physical model to producing
19771981
/// lighting effects.
19781982
///
19791983
/// The [clipPath], [clipBehavior], [elevation], [color], and [shadowColor]
19801984
/// arguments must be non-null before the compositing phase of the pipeline.
1985+
@Deprecated(
1986+
'Use a clip and canvas operations directly (See RenderPhysicalModel). '
1987+
'This feature was deprecated after v2.13.0-0.0.pre.',
1988+
)
19811989
PhysicalModelLayer({
19821990
Path? clipPath,
19831991
Clip clipBehavior = Clip.none,

packages/flutter/lib/src/rendering/object.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ class PaintingContext extends ClipContext {
491491
/// (e.g. from opacity layer to a clip rect layer).
492492
/// {@endtemplate}
493493
ClipRectLayer? pushClipRect(bool needsCompositing, Offset offset, Rect clipRect, PaintingContextCallback painter, { Clip clipBehavior = Clip.hardEdge, ClipRectLayer? oldLayer }) {
494+
if (clipBehavior == Clip.none) {
495+
painter(this, offset);
496+
return null;
497+
}
494498
final Rect offsetClipRect = clipRect.shift(offset);
495499
if (needsCompositing) {
496500
final ClipRectLayer layer = oldLayer ?? ClipRectLayer();
@@ -526,6 +530,10 @@ class PaintingContext extends ClipContext {
526530
/// {@macro flutter.rendering.PaintingContext.pushClipRect.oldLayer}
527531
ClipRRectLayer? pushClipRRect(bool needsCompositing, Offset offset, Rect bounds, RRect clipRRect, PaintingContextCallback painter, { Clip clipBehavior = Clip.antiAlias, ClipRRectLayer? oldLayer }) {
528532
assert(clipBehavior != null);
533+
if (clipBehavior == Clip.none) {
534+
painter(this, offset);
535+
return null;
536+
}
529537
final Rect offsetBounds = bounds.shift(offset);
530538
final RRect offsetClipRRect = clipRRect.shift(offset);
531539
if (needsCompositing) {
@@ -562,6 +570,10 @@ class PaintingContext extends ClipContext {
562570
/// {@macro flutter.rendering.PaintingContext.pushClipRect.oldLayer}
563571
ClipPathLayer? pushClipPath(bool needsCompositing, Offset offset, Rect bounds, Path clipPath, PaintingContextCallback painter, { Clip clipBehavior = Clip.antiAlias, ClipPathLayer? oldLayer }) {
564572
assert(clipBehavior != null);
573+
if (clipBehavior == Clip.none) {
574+
painter(this, offset);
575+
return null;
576+
}
565577
final Rect offsetBounds = bounds.shift(offset);
566578
final Path offsetClipPath = clipPath.shift(offset);
567579
if (needsCompositing) {

packages/flutter/lib/src/rendering/proxy_box.dart

Lines changed: 143 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,9 +1827,6 @@ abstract class _RenderPhysicalModelBase<T> extends _RenderCustomClip<T> {
18271827
markNeedsPaint();
18281828
}
18291829

1830-
@override
1831-
bool get alwaysNeedsCompositing => true;
1832-
18331830
@override
18341831
void describeSemanticsConfiguration(SemanticsConfiguration config) {
18351832
super.describeSemanticsConfiguration(config);
@@ -1845,6 +1842,8 @@ abstract class _RenderPhysicalModelBase<T> extends _RenderCustomClip<T> {
18451842
}
18461843
}
18471844

1845+
final Paint _transparentPaint = Paint()..color = const Color(0x00000000);
1846+
18481847
/// Creates a physical model layer that clips its child to a rounded
18491848
/// rectangle.
18501849
///
@@ -1873,9 +1872,6 @@ class RenderPhysicalModel extends _RenderPhysicalModelBase<RRect> {
18731872
_shape = shape,
18741873
_borderRadius = borderRadius;
18751874

1876-
@override
1877-
PhysicalModelLayer? get layer => super.layer as PhysicalModelLayer?;
1878-
18791875
/// The shape of the layer.
18801876
///
18811877
/// Defaults to [BoxShape.rectangle]. The [borderRadius] affects the corners
@@ -1933,42 +1929,79 @@ class RenderPhysicalModel extends _RenderPhysicalModelBase<RRect> {
19331929

19341930
@override
19351931
void paint(PaintingContext context, Offset offset) {
1936-
if (child != null) {
1937-
_updateClip();
1938-
final RRect offsetRRect = _clip!.shift(offset);
1939-
final Rect offsetBounds = offsetRRect.outerRect;
1940-
final Path offsetRRectAsPath = Path()..addRRect(offsetRRect);
1941-
bool paintShadows = true;
1942-
assert(() {
1943-
if (debugDisableShadows) {
1944-
if (elevation > 0.0) {
1945-
context.canvas.drawRRect(
1946-
offsetRRect,
1947-
Paint()
1948-
..color = shadowColor
1949-
..style = PaintingStyle.stroke
1950-
..strokeWidth = elevation * 2.0,
1951-
);
1952-
}
1953-
paintShadows = false;
1954-
}
1955-
return true;
1956-
}());
1957-
layer ??= PhysicalModelLayer();
1958-
layer!
1959-
..clipPath = offsetRRectAsPath
1960-
..clipBehavior = clipBehavior
1961-
..elevation = paintShadows ? elevation : 0.0
1962-
..color = color
1963-
..shadowColor = shadowColor;
1964-
context.pushLayer(layer!, super.paint, offset, childPaintBounds: offsetBounds);
1965-
assert(() {
1966-
layer!.debugCreator = debugCreator;
1967-
return true;
1968-
}());
1969-
} else {
1932+
if (child == null) {
19701933
layer = null;
1934+
return;
19711935
}
1936+
1937+
_updateClip();
1938+
final RRect offsetRRect = _clip!.shift(offset);
1939+
final Rect offsetBounds = offsetRRect.outerRect;
1940+
final Path offsetRRectAsPath = Path()..addRRect(offsetRRect);
1941+
bool paintShadows = true;
1942+
assert(() {
1943+
if (debugDisableShadows) {
1944+
if (elevation > 0.0) {
1945+
context.canvas.drawRRect(
1946+
offsetRRect,
1947+
Paint()
1948+
..color = shadowColor
1949+
..style = PaintingStyle.stroke
1950+
..strokeWidth = elevation * 2.0,
1951+
);
1952+
}
1953+
paintShadows = false;
1954+
}
1955+
return true;
1956+
}());
1957+
1958+
final Canvas canvas = context.canvas;
1959+
if (elevation != 0.0 && paintShadows) {
1960+
// The drawShadow call doesn't add the region of the shadow to the
1961+
// picture's bounds, so we draw a hardcoded amount of extra space to
1962+
// account for the maximum potential area of the shadow.
1963+
// TODO(jsimmons): remove this when Skia does it for us.
1964+
canvas.drawRect(
1965+
offsetBounds.inflate(20.0),
1966+
_transparentPaint,
1967+
);
1968+
canvas.drawShadow(
1969+
offsetRRectAsPath,
1970+
shadowColor,
1971+
elevation,
1972+
color.alpha != 0xFF,
1973+
);
1974+
}
1975+
final bool usesSaveLayer = clipBehavior == Clip.antiAliasWithSaveLayer;
1976+
if (!usesSaveLayer) {
1977+
canvas.drawRRect(
1978+
offsetRRect,
1979+
Paint()..color = color
1980+
);
1981+
}
1982+
layer = context.pushClipRRect(
1983+
needsCompositing,
1984+
offset,
1985+
Offset.zero & size,
1986+
_clip!,
1987+
(PaintingContext context, Offset offset) {
1988+
if (usesSaveLayer) {
1989+
// If we want to avoid the bleeding edge artifact
1990+
// (https://github.com/flutter/flutter/issues/18057#issue-328003931)
1991+
// using saveLayer, we have to call drawPaint instead of drawPath as
1992+
// anti-aliased drawPath will always have such artifacts.
1993+
context.canvas.drawPaint( Paint()..color = color);
1994+
}
1995+
super.paint(context, offset);
1996+
},
1997+
oldLayer: layer as ClipRRectLayer?,
1998+
clipBehavior: clipBehavior,
1999+
);
2000+
2001+
assert(() {
2002+
layer?.debugCreator = debugCreator;
2003+
return true;
2004+
}());
19722005
}
19732006

19742007
@override
@@ -2006,9 +2039,6 @@ class RenderPhysicalShape extends _RenderPhysicalModelBase<Path> {
20062039
assert(color != null),
20072040
assert(shadowColor != null);
20082041

2009-
@override
2010-
PhysicalModelLayer? get layer => super.layer as PhysicalModelLayer?;
2011-
20122042
@override
20132043
Path get _defaultClip => Path()..addRect(Offset.zero & size);
20142044

@@ -2025,41 +2055,78 @@ class RenderPhysicalShape extends _RenderPhysicalModelBase<Path> {
20252055

20262056
@override
20272057
void paint(PaintingContext context, Offset offset) {
2028-
if (child != null) {
2029-
_updateClip();
2030-
final Rect offsetBounds = offset & size;
2031-
final Path offsetPath = _clip!.shift(offset);
2032-
bool paintShadows = true;
2033-
assert(() {
2034-
if (debugDisableShadows) {
2035-
if (elevation > 0.0) {
2036-
context.canvas.drawPath(
2037-
offsetPath,
2038-
Paint()
2039-
..color = shadowColor
2040-
..style = PaintingStyle.stroke
2041-
..strokeWidth = elevation * 2.0,
2042-
);
2043-
}
2044-
paintShadows = false;
2045-
}
2046-
return true;
2047-
}());
2048-
layer ??= PhysicalModelLayer();
2049-
layer!
2050-
..clipPath = offsetPath
2051-
..clipBehavior = clipBehavior
2052-
..elevation = paintShadows ? elevation : 0.0
2053-
..color = color
2054-
..shadowColor = shadowColor;
2055-
context.pushLayer(layer!, super.paint, offset, childPaintBounds: offsetBounds);
2056-
assert(() {
2057-
layer!.debugCreator = debugCreator;
2058-
return true;
2059-
}());
2060-
} else {
2058+
if (child == null) {
20612059
layer = null;
2060+
return;
20622061
}
2062+
2063+
_updateClip();
2064+
final Rect offsetBounds = offset & size;
2065+
final Path offsetPath = _clip!.shift(offset);
2066+
bool paintShadows = true;
2067+
assert(() {
2068+
if (debugDisableShadows) {
2069+
if (elevation > 0.0) {
2070+
context.canvas.drawPath(
2071+
offsetPath,
2072+
Paint()
2073+
..color = shadowColor
2074+
..style = PaintingStyle.stroke
2075+
..strokeWidth = elevation * 2.0,
2076+
);
2077+
}
2078+
paintShadows = false;
2079+
}
2080+
return true;
2081+
}());
2082+
2083+
final Canvas canvas = context.canvas;
2084+
if (elevation != 0.0 && paintShadows) {
2085+
// The drawShadow call doesn't add the region of the shadow to the
2086+
// picture's bounds, so we draw a hardcoded amount of extra space to
2087+
// account for the maximum potential area of the shadow.
2088+
// TODO(jsimmons): remove this when Skia does it for us.
2089+
canvas.drawRect(
2090+
offsetBounds.inflate(20.0),
2091+
_transparentPaint,
2092+
);
2093+
canvas.drawShadow(
2094+
offsetPath,
2095+
shadowColor,
2096+
elevation,
2097+
color.alpha != 0xFF,
2098+
);
2099+
}
2100+
final bool usesSaveLayer = clipBehavior == Clip.antiAliasWithSaveLayer;
2101+
if (!usesSaveLayer) {
2102+
canvas.drawPath(
2103+
offsetPath,
2104+
Paint()..color = color
2105+
);
2106+
}
2107+
layer = context.pushClipPath(
2108+
needsCompositing,
2109+
offset,
2110+
Offset.zero & size,
2111+
_clip!,
2112+
(PaintingContext context, Offset offset) {
2113+
if (usesSaveLayer) {
2114+
// If we want to avoid the bleeding edge artifact
2115+
// (https://github.com/flutter/flutter/issues/18057#issue-328003931)
2116+
// using saveLayer, we have to call drawPaint instead of drawPath as
2117+
// anti-aliased drawPath will always have such artifacts.
2118+
context.canvas.drawPaint( Paint()..color = color);
2119+
}
2120+
super.paint(context, offset);
2121+
},
2122+
oldLayer: layer as ClipPathLayer?,
2123+
clipBehavior: clipBehavior,
2124+
);
2125+
2126+
assert(() {
2127+
layer?.debugCreator = debugCreator;
2128+
return true;
2129+
}());
20632130
}
20642131

20652132
@override

0 commit comments

Comments
 (0)