Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fuchsia] Move physical shape layer compositing to Flutter #17005

Conversation

mikejurka
Copy link
Contributor

I split the change up into smaller CLs. I haven't independently tested the sub-CLs, but just the full stack. No known issues at this time (the one issue I ran into today turned out to be a Scenic/Escher issue).

flow/scene_update_context.cc Outdated Show resolved Hide resolved
// if there is a OpacityNode higher in the tree with opacity != 1. For now,
// clamp to a infinitesimally smaller value than 1, which does not cause visual
// problems in practice.
opacity_node_.SetOpacity(std::min(1 - FLT_EPSILON, opacity_ / 255.0f));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add Scenic bug for API for marking surfaces as transparent

Copy link
Contributor

@liyuqian liyuqian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if there are some layer unit tests for these new changes. I believe @gw280 and @arbreng have done similar tests before.

flow/layers/child_scene_layer.cc Outdated Show resolved Hide resolved
flow/layers/layer.h Show resolved Hide resolved
flow/layers/physical_shape_layer.cc Outdated Show resolved Hide resolved
@@ -37,11 +37,18 @@ class PhysicalShapeLayer : public ContainerLayer {

#if defined(OS_FUCHSIA)
void UpdateScene(SceneUpdateContext& context) override;

void UpdateSceneChildren(SceneUpdateContext& context);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that UpdateSceneChildren is protected in other layers but public in here. Shall we make them consistent as I don't see why this needs to be public. Also, it might be nice to add some documentation to these function declarations. Although we lack the documentation traditionally (just like tests), we're pushing for better documentations and tests for all new code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid overriding it entirely if you follow one of my suggestions above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the separate method and moved inline, which removed a member variable at the cost of a little extra duplication.

flow/scene_update_context.cc Outdated Show resolved Hide resolved
@@ -222,6 +222,9 @@ SceneUpdateContext::ExecutePaintTasks(CompositorContext::ScopedFrame& frame) {
surfaces_to_submit.emplace_back(std::move(task.surface));
}
paint_tasks_.clear();
alpha_ = 1.f;
topmost_global_scenic_elevation_ = 10.f;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I curious where this 10.f comes from, and whether it's configurable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will pull out to constant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: did you forget to use kScenicZElevationBetweenLayers here? I saw that you've changed other places.

flow/scene_update_context.cc Outdated Show resolved Hide resolved

float GetGlobalElevationForNextScenicLayer() {
float elevation = topmost_global_scenic_elevation_;
topmost_global_scenic_elevation_ += 10.f;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for the 10.f here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -134,9 +134,9 @@ class VulkanSurface final
// |EntityNode| associated with the retained surface instead of using the
// retained surface directly. Hence Flutter can't modify the surface during
// retained rendering.
const scenic::EntityNode& GetRetainedNode() {
scenic::EntityNode* GetRetainedNode() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment of this method says that we want to prevent Flutter from modifying the surface. Is changing const scenic::EntityNode& to scenic::EntityNode* breaking that promise?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Updating comment.

Copy link
Contributor

@arbreng arbreng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be good once we do the simplifications and write a screenshot test

flow/layers/layer.h Show resolved Hide resolved
flow/layers/child_scene_layer.cc Show resolved Hide resolved
// PhysicalShapeLayers that appear above the embedded content will be turned
// into their own Scenic layers.
if (child_layer_exists_below_) {
// Reset paint bounds, because shadows are not rendered in this case
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about this part? There is no comment (or changes at all for that matter) in Paint()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, after reading forward I'm even more sure. If you follow my other comment below in this function, you can remove this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look for "// TODO: Re-enable shadow drawing here." in Pain().

I think our offline discussion clarified why we need to do a check for child_layer_exists_below_; keeping it. Let me know if that wasn't the case.

flow/layers/physical_shape_layer.cc Show resolved Hide resolved
#endif // defined(OS_FUCHSIA)

float total_elevation() const { return total_elevation_; }

private:
#if defined(OS_FUCHSIA)
float local_scenic_elevation_ = 0.0f;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2 and #3 in this list should be unnecesary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments above for child_layer_exists_below_

As far as children_need_system_compositing_ -- I think you are right, we can just get away with always calling UpdateSceneChildren in PhysicalShapeLayer::UpdateScene. I initially thought I needed it for correctness, but I think at this point it's just a tiny optimization. Getting rid of it will simplify things.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got rid of #1 and #3 as per our discussion.


// Node: UpdateSceneChildren needs to be called here so that |frame| is still
// in scope (and therefore alive) while UpdateSceneChildren is being called.
if (children_need_system_compositing_) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need this if, UpdateSceneChildren will check internally whether each child needs system compositing or not and skip over it if it doesnt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 I concur (see comment above)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.


void PhysicalShapeLayer::UpdateSceneChildren(SceneUpdateContext& context) {
float scenic_elevation = context.scenic_elevation();
context.set_scenic_elevation(scenic_elevation + local_scenic_elevation_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do this line in PhysicalShapeLayer::UpdateScene instead, you won't need to store local_scenic_elevation_ as a member variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i moved this because UpdateSceneChildren is called in two different places and this removed some duplicated code. But I think I can put the elevation logic at the very top and very bottom of UpdateScene which would eliminate the duplication and need for a variable, at the cost of a slight reduction in understandability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed local_scenic_elevation_.

@@ -37,11 +37,18 @@ class PhysicalShapeLayer : public ContainerLayer {

#if defined(OS_FUCHSIA)
void UpdateScene(SceneUpdateContext& context) override;

void UpdateSceneChildren(SceneUpdateContext& context);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid overriding it entirely if you follow one of my suggestions above

#endif // defined(OS_FUCHSIA)

float total_elevation() const { return total_elevation_; }

private:
#if defined(OS_FUCHSIA)
float local_scenic_elevation_ = 0.0f;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, #1 is also unnecesary if following one of my suggestions above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

flow/layers/transform_layer.cc Show resolved Hide resolved
@mikejurka
Copy link
Contributor Author

mikejurka commented Mar 15, 2020

Ok, added tests (see latest CL), and I also addressed comments in the last CL as well. Hope that's ok, I haven't found a productive workflow for going back and modifying the previous CLs.

See 9c629e4#diff-377431c448d255a96bd1943992182b3d and click "Load Diff" for the tests (not rendered by default since it's too big; file is fuchsia_layer_unittests.cc)

@mikejurka mikejurka force-pushed the feb19_fuchsia_physical_shape_layer_compositing branch from 9c629e4 to 11f9263 Compare March 16, 2020 00:12
@mikejurka mikejurka force-pushed the feb19_fuchsia_physical_shape_layer_compositing branch from 11f9263 to 0e03239 Compare March 16, 2020 00:42
@liyuqian
Copy link
Contributor

Thank you @mikejurka for adding the test! I wonder why all the presubmit tests are failing. Maybe you need to rebase against newest engine?

I also couldn't find my comment regarding flutter/flutter#18320 although that issue showed that I referenced it from this PR...

Anyway, it mostly looks good to me, and the only thing obvious to me is that you forget one more 10.f :)

Copy link
Contributor

@liyuqian liyuqian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed with Mike offline about flutter/flutter#18320. This PR fixes that issue for PhysicalShapeLayer, but we'll still have to fix that issue for other layers such as PerformanceOverlayerLayer.

@@ -222,6 +222,9 @@ SceneUpdateContext::ExecutePaintTasks(CompositorContext::ScopedFrame& frame) {
surfaces_to_submit.emplace_back(std::move(task.surface));
}
paint_tasks_.clear();
alpha_ = 1.f;
topmost_global_scenic_elevation_ = 10.f;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: did you forget to use kScenicZElevationBetweenLayers here? I saw that you've changed other places.

@mikejurka mikejurka force-pushed the feb19_fuchsia_physical_shape_layer_compositing branch 2 times, most recently from b1383a9 to 0792c63 Compare March 18, 2020 00:43
@mikejurka
Copy link
Contributor Author

Replaced the stray 10.f with kScenicZElevationBetweenLayers

@mikejurka mikejurka force-pushed the feb19_fuchsia_physical_shape_layer_compositing branch 2 times, most recently from 6f14029 to 80f08eb Compare March 18, 2020 01:00
…need to float above child views.

In that case, they will still need to be pulled
into separate Scenic nodes to be composited on top
of the child view[s].
@mikejurka mikejurka force-pushed the feb19_fuchsia_physical_shape_layer_compositing branch from 80f08eb to 8b4aedc Compare March 18, 2020 18:24
Inspect commands going to Scenic and make sure
they match what is expected.

Also, restructure code to need less member variables,
and other cleanups based on review feedback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants