-
Notifications
You must be signed in to change notification settings - Fork 6k
Fix Opacity performance regression on Fuchsia #15573
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, tested and verified no visual regressions and a 40% reduced frame rasterizer time on benchmarks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind describing at a high level what your intended changes to the layer tree and passes are and why you're making them in the PR description? I was asked to give this a review pass but I'm having difficulty figuring out the big picture of all the changes this patch is trying to make and why. Some text going over the broad strokes would help. :) It would also be useful to any future historians who are trying to reason through why a particular change was made while they're debugging.
This patch also needs tests before we can merge it into the tree, see Tree Hygiene #4.
@@ -31,6 +31,7 @@ void ChildSceneLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { | |||
void ChildSceneLayer::Paint(PaintContext& context) const { | |||
TRACE_EVENT0("flutter", "ChildSceneLayer::Paint"); | |||
FML_DCHECK(needs_painting()); | |||
FML_DCHECK(needs_system_composite()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to make sure I understand this: So before FuchsiaSystemCompositedLayer would wrap this call. Now we're not constructing it any more, so we're calling it before every paint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing,
We landed this PR: #14024 in order to have OpacityLayer work on Fuchsia even with cross-process content. This way you could do say Opacity(opacity: 0.1, children: [chromium_child_view]) and the chromium that you embedded would be rendered at 0.1 group opacity.
In order to do so, OpacityLayer's need to be "popped out" as their own system composited layer. We also wanted to remove this same "popping out" from the PhysicalShapeLayer as it is wasteful in terms of resources. needs_system_composite
flag indicates that one of the layers children or the layer itself is going to be popped out.
Unfortunately, the PhysicalShapeLayer part of that change caused a large performance regression on Fuchsia. So, this patch reverts the original one and then re-applies it but without this commit: c4df6df
Definitely agreed on the tests, I'm thinking about that right now. Lack of tests is why the perf regression made it through in the first place. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, to your previous question: ChildSceneLayer is a layer to embed cross-process content, so by definition needs_system_composite
is true for it. I added that DCHECK as a sanity check while debugging
@@ -83,7 +83,7 @@ void LayerTree::UpdateScene(SceneUpdateContext& context, | |||
context, | |||
SkRRect::MakeRect( | |||
SkRect::MakeWH(frame_size_.width(), frame_size_.height())), | |||
SK_ColorTRANSPARENT); | |||
SK_ColorTRANSPARENT, SK_AlphaOPAQUE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this is covering Flutter's UI with an opaque rect. On other platforms Flutter UIs are expected to blend with other backgrounds transparently. Is it safe to assume that's never the case here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is safe to assume. I think we would like to have the same blending on Fuchsia, but unfortunately Scenic doesn't support that at the moment; you get a black square if you try
@@ -14,6 +14,7 @@ | |||
#include "flutter/fml/macros.h" | |||
#include "flutter/fml/time/time_delta.h" | |||
#include "third_party/skia/include/core/SkPicture.h" | |||
#include "third_party/skia/include/core/SkSize.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Extra import?
// able to have developers specify the behavior here to alternatives besides | ||
// clamping, like normalization on some arbitrary curve. | ||
float clamped_elevation = elevation; | ||
if (max_elevation > -1 && (parent_elevation + elevation) > max_elevation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(For any other reviewers: this was moved into the SceneUpdateContext. That should keep working.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect moving this here had something to do with the perfoprmance regression. Out next CL will rethink how flutter elevation -> scenic Z works entirely.
SkMatrix child_matrix = matrix; | ||
child_matrix.postTranslate(offset_.fX, offset_.fY); | ||
|
||
total_elevation_ = context->total_elevation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we're always adding kOpacityElevationWhenUsingSystemCompositor
to the total, but presumably there are some conditions where we're not using the system compositor and opacity layers don't add to the elevation. Are we going to be incorrectly adding to our elevation in those cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
We only use the system compositor if the OpacityLayer has an out-of-process child somewhere (a ChildSceneLayer)
|
||
if (elevation() == 0) { | ||
context->total_elevation += elevation_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think it's a potential foot gun to leave it on individual layers to remember to update total_elevation_ correctly if they happen to be elevated. Right now it's only two places so it's reasonable, but this is the type of bug that wouldn't be immediately obvious if a third was introduced for some reason and didn't feed back into the global state. I don't have any immediate suggestions on how to fix it though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with Michael on this. It might make sense for us unify the layer state management pieces. Maybe making the MutatorStack
struct more general would be one way of addressing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree.
Fortunately I think context->total_elevation is going to go away in my next PR and this problem will be moot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that:
- This is a partial revert of c4df6df
- Test infra for in-tree Fuchsia testing is not at a place where we can identify the regression. Me and @gw280 are working on improving it this quarter.
- This addresses a high priority issue and http://fxb/43364 has multiple people who have seem the regression fixed with this change.
@Hixie can we get exemption for testing for this PR.
@iskakaushik given the circumstances, go for it when green. |
flutter/engine@839b34c...0427416 git log 839b34c..0427416 --first-parent --oneline 2020-01-16 [email protected] Fix Opacity performance regression on Fuchsia (flutter/engine#15573) 2020-01-16 [email protected] [web] edge launcher for windows (flutter/engine#15690) 2020-01-16 [email protected] [web] Add BoxHeightStyle.strut (flutter/engine#15694) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected] on the revert to ensure that a human is aware of the problem. To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
* Add more profile markers * Revert FuchsiaSystemCompistedLayer changes * Re-add opacity w/o elevation changes * Fix formatting
* Add more profile markers * Revert FuchsiaSystemCompistedLayer changes * Re-add opacity w/o elevation changes * Fix formatting
* Add more profile markers * Revert FuchsiaSystemCompistedLayer changes * Re-add opacity w/o elevation changes * Fix formatting
This reverts commit 79d2b7d.
* Add more profile markers * Revert FuchsiaSystemCompistedLayer changes * Re-add opacity w/o elevation changes * Fix formatting
Details and traces at fxbug/43364