Unverified Commit d36ecec5 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[framework] partial removal of forced compositing from opacity (#106989)

parent efd006e1
......@@ -883,15 +883,7 @@ class RenderOpacity extends RenderProxyBox {
super(child);
@override
bool get alwaysNeedsCompositing => child != null && (_alpha > 0);
@override
OffsetLayer updateCompositedLayer({required covariant OpacityLayer? oldLayer}) {
assert(_alpha != 255);
final OpacityLayer updatedLayer = oldLayer ?? OpacityLayer();
updatedLayer.alpha = _alpha;
return updatedLayer;
}
bool get alwaysNeedsCompositing => child != null && (_alpha > 0 && _alpha < 255);
int _alpha;
......@@ -949,19 +941,26 @@ class RenderOpacity extends RenderProxyBox {
@override
void paint(PaintingContext context, Offset offset) {
if (child != null) {
if (_alpha == 0) {
// No need to keep the layer. We'll create a new one if necessary.
layer = null;
return;
}
assert(needsCompositing);
layer = context.pushOpacity(offset, _alpha, super.paint, oldLayer: layer as OpacityLayer?);
assert(() {
layer!.debugCreator = debugCreator;
return true;
}());
if (child == null) {
return;
}
if (_alpha == 0) {
// No need to keep the layer. We'll create a new one if necessary.
layer = null;
return;
}
if (_alpha == 255) {
// No need to keep the layer. We'll create a new one if necessary.
layer = null;
return super.paint(context, offset);
}
assert(needsCompositing);
layer = context.pushOpacity(offset, _alpha, super.paint, oldLayer: layer as OpacityLayer?);
assert(() {
layer!.debugCreator = debugCreator;
return true;
}());
}
@override
......
......@@ -240,11 +240,21 @@ void main() {
expect(renderOpacity.needsCompositing, false);
});
test('RenderOpacity does composite if it is opaque', () {
test('RenderOpacity does not composite if it is opaque', () {
final RenderOpacity renderOpacity = RenderOpacity(
child: RenderSizedBox(const Size(1.0, 1.0)), // size doesn't matter
);
layout(renderOpacity, phase: EnginePhase.composite);
expect(renderOpacity.needsCompositing, false);
});
test('RenderOpacity does composite if it is partially opaque', () {
final RenderOpacity renderOpacity = RenderOpacity(
opacity: 0.1,
child: RenderSizedBox(const Size(1.0, 1.0)), // size doesn't matter
);
layout(renderOpacity, phase: EnginePhase.composite);
expect(renderOpacity.needsCompositing, true);
});
......
......@@ -285,7 +285,7 @@ void main() {
child: Placeholder(),
),
const Opacity(
opacity: 1.0,
opacity: 0.9,
child: Placeholder(),
),
ImageFiltered(
......
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