Unverified Commit c567f843 authored by Jason C.H's avatar Jason C.H Committed by GitHub

Ensure the engineLayer is disposed when an OpacityLayer is disabled (#94280)

parent 5a862ebe
......@@ -1764,11 +1764,16 @@ class OpacityLayer extends OffsetLayer {
@override
void addToScene(ui.SceneBuilder builder) {
assert(alpha != null);
bool enabled = firstChild != null; // don't add this layer if there's no child
// Don't add this layer if there's no child.
bool enabled = firstChild != null;
if (!enabled) {
// Ensure the engineLayer is disposed.
engineLayer = null;
// TODO(dnfield): Remove this if/when we can fix https://github.com/flutter/flutter/issues/90004
return;
}
assert(() {
enabled = enabled && !debugDisableOpacityLayers;
return true;
......
......@@ -637,6 +637,21 @@ void main() {
expect(builder.addedPicture, true);
expect(layer.engineLayer, isA<FakeOpacityEngineLayer>());
});
test('OpacityLayer dispose its engineLayer if there are no children', () {
final OpacityLayer layer = OpacityLayer(alpha: 128);
final FakeSceneBuilder builder = FakeSceneBuilder();
layer.addToScene(builder);
expect(layer.engineLayer, null);
layer.append(PictureLayer(Rect.largest)..picture = FakePicture());
layer.addToScene(builder);
expect(layer.engineLayer, isA<FakeOpacityEngineLayer>());
layer.removeAllChildren();
layer.addToScene(builder);
expect(layer.engineLayer, null);
});
}
class FakeEngineLayer extends Fake implements EngineLayer {
......
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