@@ -1827,9 +1827,6 @@ abstract class _RenderPhysicalModelBase<T> extends _RenderCustomClip<T> {
1827
1827
markNeedsPaint ();
1828
1828
}
1829
1829
1830
- @override
1831
- bool get alwaysNeedsCompositing => true ;
1832
-
1833
1830
@override
1834
1831
void describeSemanticsConfiguration (SemanticsConfiguration config) {
1835
1832
super .describeSemanticsConfiguration (config);
@@ -1845,6 +1842,8 @@ abstract class _RenderPhysicalModelBase<T> extends _RenderCustomClip<T> {
1845
1842
}
1846
1843
}
1847
1844
1845
+ final Paint _transparentPaint = Paint ()..color = const Color (0x00000000 );
1846
+
1848
1847
/// Creates a physical model layer that clips its child to a rounded
1849
1848
/// rectangle.
1850
1849
///
@@ -1873,9 +1872,6 @@ class RenderPhysicalModel extends _RenderPhysicalModelBase<RRect> {
1873
1872
_shape = shape,
1874
1873
_borderRadius = borderRadius;
1875
1874
1876
- @override
1877
- PhysicalModelLayer ? get layer => super .layer as PhysicalModelLayer ? ;
1878
-
1879
1875
/// The shape of the layer.
1880
1876
///
1881
1877
/// Defaults to [BoxShape.rectangle] . The [borderRadius] affects the corners
@@ -1933,42 +1929,79 @@ class RenderPhysicalModel extends _RenderPhysicalModelBase<RRect> {
1933
1929
1934
1930
@override
1935
1931
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 ) {
1970
1933
layer = null ;
1934
+ return ;
1971
1935
}
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
+ }());
1972
2005
}
1973
2006
1974
2007
@override
@@ -2006,9 +2039,6 @@ class RenderPhysicalShape extends _RenderPhysicalModelBase<Path> {
2006
2039
assert (color != null ),
2007
2040
assert (shadowColor != null );
2008
2041
2009
- @override
2010
- PhysicalModelLayer ? get layer => super .layer as PhysicalModelLayer ? ;
2011
-
2012
2042
@override
2013
2043
Path get _defaultClip => Path ()..addRect (Offset .zero & size);
2014
2044
@@ -2025,41 +2055,78 @@ class RenderPhysicalShape extends _RenderPhysicalModelBase<Path> {
2025
2055
2026
2056
@override
2027
2057
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 ) {
2061
2059
layer = null ;
2060
+ return ;
2062
2061
}
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
+ }());
2063
2130
}
2064
2131
2065
2132
@override
0 commit comments