Skip to content

Commit

Permalink
[framework] delete physical model layer. (#125719)
Browse files Browse the repository at this point in the history
Engine PR: flutter/engine#41593

This must land first

We should remove these, as they've been deprecated for a while. On the engine side of things, the physical model layer is the only one which requires the device pixel ratio, so deleting it will allow us to simplify the layer tree code in flutter/engine#41559
  • Loading branch information
jonahwilliams committed May 2, 2023
1 parent e51b616 commit 12b3023
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 221 deletions.
146 changes: 0 additions & 146 deletions packages/flutter/lib/src/rendering/layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2178,152 +2178,6 @@ class BackdropFilterLayer extends ContainerLayer {
}
}

/// A composited layer that uses a physical model to producing lighting effects.
///
/// For example, the layer casts a shadow according to its geometry and the
/// relative position of lights and other physically modeled objects in the
/// scene.
///
/// When debugging, setting [debugDisablePhysicalShapeLayers] to true will cause this
/// layer to be skipped (directly replaced by its children). This can be helpful
/// to track down the cause of performance problems.
@Deprecated(
'Use a clip and canvas operations directly (See RenderPhysicalModel). '
'This feature was deprecated after v2.13.0-0.0.pre.',
)
class PhysicalModelLayer extends ContainerLayer {
/// Creates a composited layer that uses a physical model to producing
/// lighting effects.
///
/// The [clipPath], [clipBehavior], [elevation], [color], and [shadowColor]
/// arguments must be non-null before the compositing phase of the pipeline.
@Deprecated(
'Use a clip and canvas operations directly (See RenderPhysicalModel). '
'This feature was deprecated after v2.13.0-0.0.pre.',
)
PhysicalModelLayer({
Path? clipPath,
Clip clipBehavior = Clip.none,
double? elevation,
Color? color,
Color? shadowColor,
}) : _clipPath = clipPath,
_clipBehavior = clipBehavior,
_elevation = elevation,
_color = color,
_shadowColor = shadowColor;

/// The path to clip in the parent's coordinate system.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
Path? get clipPath => _clipPath;
Path? _clipPath;
set clipPath(Path? value) {
if (value != _clipPath) {
_clipPath = value;
markNeedsAddToScene();
}
}

/// {@macro flutter.material.Material.clipBehavior}
Clip get clipBehavior => _clipBehavior;
Clip _clipBehavior;
set clipBehavior(Clip value) {
if (value != _clipBehavior) {
_clipBehavior = value;
markNeedsAddToScene();
}
}

/// The z-coordinate at which to place this physical object.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
///
/// In tests, the [debugDisableShadows] flag is set to true by default.
/// Several widgets and render objects force all elevations to zero when this
/// flag is set. For this reason, this property will often be set to zero in
/// tests even if the layer should be raised. To verify the actual value,
/// consider setting [debugDisableShadows] to false in your test.
double? get elevation => _elevation;
double? _elevation;
set elevation(double? value) {
if (value != _elevation) {
_elevation = value;
markNeedsAddToScene();
}
}

/// The background color.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
Color? get color => _color;
Color? _color;
set color(Color? value) {
if (value != _color) {
_color = value;
markNeedsAddToScene();
}
}

/// The shadow color.
Color? get shadowColor => _shadowColor;
Color? _shadowColor;
set shadowColor(Color? value) {
if (value != _shadowColor) {
_shadowColor = value;
markNeedsAddToScene();
}
}

@override
bool findAnnotations<S extends Object>(AnnotationResult<S> result, Offset localPosition, { required bool onlyFirst }) {
if (!clipPath!.contains(localPosition)) {
return false;
}
return super.findAnnotations<S>(result, localPosition, onlyFirst: onlyFirst);
}

@override
void addToScene(ui.SceneBuilder builder) {
assert(clipPath != null);
assert(elevation != null);
assert(color != null);
assert(shadowColor != null);

bool enabled = true;
assert(() {
enabled = !debugDisablePhysicalShapeLayers;
return true;
}());
if (enabled) {
engineLayer = builder.pushPhysicalShape(
path: clipPath!,
elevation: elevation!,
color: color!,
shadowColor: shadowColor,
clipBehavior: clipBehavior,
oldLayer: _engineLayer as ui.PhysicalShapeEngineLayer?,
);
} else {
engineLayer = null;
}
addChildrenToScene(builder);
if (enabled) {
builder.pop();
}
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DoubleProperty('elevation', elevation));
properties.add(ColorProperty('color', color));
}
}

/// An object that a [LeaderLayer] can register with.
///
/// An instance of this class should be provided as the [LeaderLayer.link] and
Expand Down
50 changes: 0 additions & 50 deletions packages/flutter/test/rendering/layer_annotations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -434,56 +434,6 @@ void main() {
);
});

test('PhysicalModelLayer.findAllAnnotations respects clipPath', () {
// For this triangle, location (1, 1) is inside, while (2, 2) is outside.
// 2
// —————
// | /
// | /
// 2 |/
final Path originalPath = Path();
originalPath.lineTo(2, 0);
originalPath.lineTo(0, 2);
originalPath.close();
// Shift this clip path by (10, 10).
final Path path = originalPath.shift(const Offset(10, 10));
const Offset insidePosition = Offset(11, 11);
const Offset outsidePosition = Offset(12, 12);

final Layer root = _withBackgroundAnnotation(
1000,
_Layers(
PhysicalModelLayer(
clipPath: path,
elevation: 10,
color: const Color.fromARGB(0, 0, 0, 0),
shadowColor: const Color.fromARGB(0, 0, 0, 0),
),
children: <Object>[
_TestAnnotatedLayer(
1,
opaque: true,
size: const Size(10, 10),
offset: const Offset(10, 10),
),
],
).build(),
);

expect(
root.findAllAnnotations<int>(insidePosition).entries.toList(),
_equalToAnnotationResult<int>(<AnnotationEntry<int>>[
const AnnotationEntry<int>(annotation: 1, localPosition: insidePosition),
]),
);
expect(
root.findAllAnnotations<int>(outsidePosition).entries.toList(),
_equalToAnnotationResult<int>(<AnnotationEntry<int>>[
const AnnotationEntry<int>(annotation: 1000, localPosition: outsidePosition),
]),
);
});

test('LeaderLayer.findAllAnnotations respects offset', () {
const Offset insidePosition = Offset(-5, 5);
const Offset outsidePosition = Offset(5, 5);
Expand Down
25 changes: 0 additions & 25 deletions packages/flutter/test/rendering/layers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -512,29 +512,6 @@ void main() {
});
});

test('mutating PhysicalModelLayer fields triggers needsAddToScene', () {
final PhysicalModelLayer layer = PhysicalModelLayer(
clipPath: Path(),
elevation: 0,
color: const Color(0x00000000),
shadowColor: const Color(0x00000000),
);
checkNeedsAddToScene(layer, () {
final Path newPath = Path();
newPath.addRect(unitRect);
layer.clipPath = newPath;
});
checkNeedsAddToScene(layer, () {
layer.elevation = 1;
});
checkNeedsAddToScene(layer, () {
layer.color = const Color(0x00000001);
});
checkNeedsAddToScene(layer, () {
layer.shadowColor = const Color(0x00000001);
});
});

test('ContainerLayer.toImage can render interior layer', () {
final OffsetLayer parent = OffsetLayer();
final OffsetLayer child = OffsetLayer();
Expand Down Expand Up @@ -1007,7 +984,6 @@ void main() {
final ClipRRectLayer clipRRectLayer = ClipRRectLayer();
final ImageFilterLayer imageFilterLayer = ImageFilterLayer();
final BackdropFilterLayer backdropFilterLayer = BackdropFilterLayer();
final PhysicalModelLayer physicalModelLayer = PhysicalModelLayer();
final ColorFilterLayer colorFilterLayer = ColorFilterLayer();
final ShaderMaskLayer shaderMaskLayer = ShaderMaskLayer();
final TextureLayer textureLayer = TextureLayer(rect: Rect.zero, textureId: 1);
Expand All @@ -1017,7 +993,6 @@ void main() {
expect(clipRRectLayer.supportsRasterization(), true);
expect(imageFilterLayer.supportsRasterization(), true);
expect(backdropFilterLayer.supportsRasterization(), true);
expect(physicalModelLayer.supportsRasterization(), true);
expect(colorFilterLayer.supportsRasterization(), true);
expect(shaderMaskLayer.supportsRasterization(), true);
expect(textureLayer.supportsRasterization(), true);
Expand Down

0 comments on commit 12b3023

Please sign in to comment.