Unverified Commit fa8e3e68 authored by Dan Field's avatar Dan Field Committed by GitHub

Reland "Ensure the engineLayer is disposed when an OpacityLayer is disabled"" (#96295)

parent bb65333c
......@@ -1763,11 +1763,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