Skip to content

Commit

Permalink
Remove Layer::double_sided and Blink callsites.
Browse files Browse the repository at this point in the history
This field doesn't do anything in cc in layer list mode, and is
not called in other clients of cc than Blink.

Layer::should_check_backface_visibility() does all the actual
work in layer list mode.

Bug: 1008483

Change-Id: Ia535f6912d6c6a9b3305851639360ae9693fd375
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2131024
Reviewed-by: Philip Rogers <pdr@chromium.org>
Commit-Queue: Chris Harrelson <chrishtr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756279}
  • Loading branch information
chrishtr authored and Commit Bot committed Apr 3, 2020
1 parent 9c074de commit ec8a86e
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 245 deletions.
10 changes: 0 additions & 10 deletions cc/layers/layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1112,16 +1112,6 @@ void Layer::SetForceRenderSurfaceForTesting(bool force) {
SetNeedsCommit();
}

void Layer::SetDoubleSided(bool double_sided) {
DCHECK(IsPropertyChangeAllowed());
if (inputs_.double_sided == double_sided)
return;
inputs_.double_sided = double_sided;
SetNeedsCommit();
SetPropertyTreesNeedRebuild();
SetSubtreePropertyChanged();
}

void Layer::SetTransformTreeIndex(int index) {
DCHECK(IsPropertyChangeAllowed());
if (transform_tree_index_ == index)
Expand Down
16 changes: 0 additions & 16 deletions cc/layers/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,22 +475,6 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
return force_render_surface_for_testing_;
}

// Set or get if this layer should continue to be visible when rotated such
// that its back face is facing toward the camera. If false, the layer will
// disappear when its back face is visible, but if true, the mirror image of
// its front face will be shown. For instance, with a 180deg rotation around
// the middle of the layer on the Y axis, if this is false then nothing is
// visible. But if true, the layer is seen with its contents flipped along the
// Y axis. Being single-sided applies transitively to the subtree of this
// layer. If it is hidden because of its back face being visible, then its
// subtree will be too (even if a subtree layer's front face would have been
// visible).
//
// Note that should_check_backface_visibility() is the final computed value
// for back face visibility, which is only for internal use.
void SetDoubleSided(bool double_sided);
bool double_sided() const { return inputs_.double_sided; }

// When true the layer may contribute to the compositor's output. When false,
// it does not. This property does not apply to children of the layer, they
// may contribute while this layer does not. The layer itself will determine
Expand Down
3 changes: 0 additions & 3 deletions cc/layers/layer_perftest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ TEST_F(LayerPerfTest, PushPropertiesTo) {
float transform_origin_z = 0;
bool scrollable = true;
bool contents_opaque = true;
bool double_sided = true;
bool hide_layer_and_subtree = true;
bool masks_to_bounds = true;

Expand All @@ -84,15 +83,13 @@ TEST_F(LayerPerfTest, PushPropertiesTo) {
test_layer->SetNeedsDisplayRect(gfx::Rect(5, 5));
test_layer->SetTransformOrigin(gfx::Point3F(0.f, 0.f, transform_origin_z));
test_layer->SetContentsOpaque(contents_opaque);
test_layer->SetDoubleSided(double_sided);
test_layer->SetHideLayerAndSubtree(hide_layer_and_subtree);
test_layer->SetMasksToBounds(masks_to_bounds);
test_layer->PushPropertiesTo(impl_layer.get());

transform_origin_z += 0.01f;
scrollable = !scrollable;
contents_opaque = !contents_opaque;
double_sided = !double_sided;
hide_layer_and_subtree = !hide_layer_and_subtree;
masks_to_bounds = !masks_to_bounds;

Expand Down
9 changes: 0 additions & 9 deletions cc/layers/layer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,6 @@ TEST_F(LayerTest, LayerPropertyChangedForSubtree) {
child2->PushPropertiesTo(child2_impl.get());
grand_child->PushPropertiesTo(grand_child_impl.get()));

EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1);
EXECUTE_AND_VERIFY_SUBTREE_CHANGED(top->SetDoubleSided(false));
EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET(
top->PushPropertiesTo(top_impl.get());
child->PushPropertiesTo(child_impl.get());
child2->PushPropertiesTo(child2_impl.get());
grand_child->PushPropertiesTo(grand_child_impl.get()));

EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1);
EXECUTE_AND_VERIFY_SUBTREE_CHANGED(top->SetHideLayerAndSubtree(true));
EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET(
Expand Down Expand Up @@ -937,7 +929,6 @@ TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) {
Region(gfx::Rect(1, 1, 2, 2))));
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTransform(
gfx::Transform(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)));
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetDoubleSided(false));
TouchActionRegion touch_action_region;
touch_action_region.Union(TouchAction::kNone, gfx::Rect(10, 10));
EXPECT_SET_NEEDS_COMMIT(
Expand Down
23 changes: 19 additions & 4 deletions cc/trees/draw_properties_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4481,10 +4481,13 @@ TEST_F(DrawPropertiesTest,

TEST_F(DrawPropertiesTest, TransformAnimationUpdatesBackfaceVisibility) {
LayerImpl* root = root_layer();
root->SetDrawsContent(true);
LayerImpl* back_facing = AddLayer<LayerImpl>();
back_facing->SetDrawsContent(true);
LayerImpl* render_surface1 = AddLayer<LayerImpl>();
render_surface1->SetDrawsContent(true);
LayerImpl* render_surface2 = AddLayer<LayerImpl>();

render_surface2->SetDrawsContent(true);
gfx::Transform rotate_about_y;
rotate_about_y.RotateAboutYAxis(180.0);

Expand Down Expand Up @@ -4519,21 +4522,36 @@ TEST_F(DrawPropertiesTest, TransformAnimationUpdatesBackfaceVisibility) {
UpdateActiveTreeDrawProperties();

EXPECT_TRUE(GetEffectNode(render_surface1)->hidden_by_backface_visibility);
EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect());
EXPECT_TRUE(GetEffectNode(render_surface2)->hidden_by_backface_visibility);
EXPECT_EQ(gfx::Rect(), render_surface2->visible_layer_rect());

EXPECT_EQ(1u, GetRenderSurfaceList().size());

root->layer_tree_impl()->SetTransformMutated(back_facing->element_id(),
gfx::Transform());
root->layer_tree_impl()->SetTransformMutated(render_surface2->element_id(),
rotate_about_y);
UpdateActiveTreeDrawProperties();
EXPECT_FALSE(GetEffectNode(render_surface1)->hidden_by_backface_visibility);
EXPECT_EQ(gfx::Rect(0, 0, 30, 30), render_surface1->visible_layer_rect());
EXPECT_TRUE(GetEffectNode(render_surface2)->hidden_by_backface_visibility);
EXPECT_EQ(gfx::Rect(), render_surface2->visible_layer_rect());

EXPECT_EQ(2u, GetRenderSurfaceList().size());

root->layer_tree_impl()->SetTransformMutated(render_surface1->element_id(),
rotate_about_y);
UpdateActiveTreeDrawProperties();
EXPECT_TRUE(GetEffectNode(render_surface1)->hidden_by_backface_visibility);
// Draw properties are only updated for visible layers, so this remains the
// cached value from last time. The expectation is commented out because
// this result is not required.
// EXPECT_EQ(gfx::Rect(0, 0, 30, 30), render_surface1->visible_layer_rect());
EXPECT_TRUE(GetEffectNode(render_surface2)->hidden_by_backface_visibility);
EXPECT_EQ(gfx::Rect(), render_surface2->visible_layer_rect());

EXPECT_EQ(1u, GetRenderSurfaceList().size());
}

TEST_F(DrawPropertiesTest, ScrollChildAndScrollParentDifferentTargets) {
Expand Down Expand Up @@ -6616,7 +6634,6 @@ TEST_F(DrawPropertiesTestWithLayerTree, SkippingLayerImpl) {
// A double sided render surface with backface visible should not be skipped
ImplOf(grandchild)->set_visible_layer_rect(gfx::Rect());
child->SetForceRenderSurfaceForTesting(true);
child->SetDoubleSided(true);
child->SetTransform(rotate_back_and_translate);
CommitAndActivate();
EXPECT_EQ(gfx::Rect(10, 10), ImplOf(grandchild)->visible_layer_rect());
Expand Down Expand Up @@ -6817,12 +6834,10 @@ TEST_F(DrawPropertiesTestWithLayerTree, SkippingLayer) {
child->SetBounds(gfx::Size(10, 10));

gfx::Transform rotate;
child->SetDoubleSided(false);
rotate.RotateAboutXAxis(180.f);
child->SetTransform(rotate);
CommitAndActivate();
EXPECT_EQ(gfx::Rect(0, 0), ImplOf(child)->visible_layer_rect());
child->SetDoubleSided(true);
child->SetTransform(gfx::Transform());

child->SetOpacity(0.f);
Expand Down
2 changes: 1 addition & 1 deletion cc/trees/layer_tree_host_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ class LayerTreeHostTestSurfaceDamage : public LayerTreeHostTest {
root_->SetBounds(gfx::Size(20, 20));
break;
case 3:
child_->SetDoubleSided(false);
child_->SetOpacity(0.8f);
break;
}
}
Expand Down
11 changes: 0 additions & 11 deletions cc/trees/property_tree_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ bool PropertyTreeBuilderContext::AddEffectNodeIfNeeded(
node->trilinear_filtering = layer->trilinear_filtering();
node->has_potential_opacity_animation = has_potential_opacity_animation;
node->has_potential_filter_animation = has_potential_filter_animation;
node->double_sided = layer->double_sided();
node->subtree_hidden = layer->hide_layer_and_subtree();
node->is_currently_animating_opacity =
OpacityIsAnimating(mutator_host_, layer);
Expand Down Expand Up @@ -633,15 +632,6 @@ void PropertyTreeBuilderContext::AddScrollNodeIfNeeded(
layer->SetScrollTreeIndex(node_id);
}

void SetBackfaceVisibilityTransform(Layer* layer, bool created_transform_node) {
// A double-sided layer's backface can been shown when its visible.
// In addition, we need to check if (1) there might be a local 3D transform
// on the layer that might turn it to the backface, or (2) it is not drawn
// into a flattened space.
layer->SetShouldCheckBackfaceVisibility(!layer->double_sided() &&
created_transform_node);
}

void SetSafeOpaqueBackgroundColor(const DataForRecursion& data_from_ancestor,
Layer* layer,
DataForRecursion* data_for_children) {
Expand Down Expand Up @@ -673,7 +663,6 @@ void PropertyTreeBuilderContext::BuildPropertyTreesInternal(

AddScrollNodeIfNeeded(data_from_parent, layer, &data_for_children);

SetBackfaceVisibilityTransform(layer, created_transform_node);
SetSafeOpaqueBackgroundColor(data_from_parent, layer, &data_for_children);

bool not_axis_aligned_since_last_clip =
Expand Down
179 changes: 0 additions & 179 deletions cc/trees/property_tree_builder_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -453,185 +453,6 @@ TEST_F(PropertyTreeBuilderTest, TextureLayerSnapping) {
EXPECT_EQ(layer_bounds_in_screen_space, gfx::RectF(11.f, 20.f, 100.f, 100.f));
}

// Verify the behavior of back-face culling when there are no preserve-3d
// layers. Note that 3d transforms still apply in this case, but they are
// "flattened" to each parent layer according to current W3C spec.
TEST_F(PropertyTreeBuilderTest, BackFaceCullingWithoutPreserves3d) {
auto root = Layer::Create();
host()->SetRootLayer(root);
auto front_facing_child = Layer::Create();
root->AddChild(front_facing_child);
auto back_facing_child = Layer::Create();
root->AddChild(back_facing_child);
auto front_facing_surface = Layer::Create();
root->AddChild(front_facing_surface);
auto back_facing_surface = Layer::Create();
root->AddChild(back_facing_surface);
auto front_facing_child_of_front_facing_surface = Layer::Create();
front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
auto back_facing_child_of_front_facing_surface = Layer::Create();
front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
auto front_facing_child_of_back_facing_surface = Layer::Create();
back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
auto back_facing_child_of_back_facing_surface = Layer::Create();
back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);

// Nothing is double-sided
front_facing_child->SetDoubleSided(false);
back_facing_child->SetDoubleSided(false);
front_facing_surface->SetDoubleSided(false);
back_facing_surface->SetDoubleSided(false);
front_facing_child_of_front_facing_surface->SetDoubleSided(false);
back_facing_child_of_front_facing_surface->SetDoubleSided(false);
front_facing_child_of_back_facing_surface->SetDoubleSided(false);
back_facing_child_of_back_facing_surface->SetDoubleSided(false);

// Everything draws content.
front_facing_child->SetIsDrawable(true);
back_facing_child->SetIsDrawable(true);
front_facing_surface->SetIsDrawable(true);
back_facing_surface->SetIsDrawable(true);
front_facing_child_of_front_facing_surface->SetIsDrawable(true);
back_facing_child_of_front_facing_surface->SetIsDrawable(true);
front_facing_child_of_back_facing_surface->SetIsDrawable(true);
back_facing_child_of_back_facing_surface->SetIsDrawable(true);

gfx::Transform backface_matrix;
backface_matrix.Translate(50.0, 50.0);
backface_matrix.RotateAboutYAxis(180.0);
backface_matrix.Translate(-50.0, -50.0);

root->SetBounds(gfx::Size(100, 100));
front_facing_child->SetBounds(gfx::Size(100, 100));
back_facing_child->SetBounds(gfx::Size(100, 100));
front_facing_surface->SetBounds(gfx::Size(100, 100));
back_facing_surface->SetBounds(gfx::Size(100, 100));
front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));

front_facing_surface->SetForceRenderSurfaceForTesting(true);
back_facing_surface->SetForceRenderSurfaceForTesting(true);

back_facing_child->SetTransform(backface_matrix);
back_facing_surface->SetTransform(backface_matrix);
back_facing_child_of_front_facing_surface->SetTransform(backface_matrix);
back_facing_child_of_back_facing_surface->SetTransform(backface_matrix);

// Note: No layers preserve 3d. According to current W3C CSS gfx::Transforms
// spec, these layers should blindly use their own local transforms to
// determine back-face culling.
CommitAndActivate();

// Verify which render surfaces were created.
EXPECT_EQ(GetRenderSurfaceImpl(front_facing_child),
GetRenderSurfaceImpl(root));
EXPECT_EQ(GetRenderSurfaceImpl(back_facing_child),
GetRenderSurfaceImpl(root));
EXPECT_NE(GetRenderSurfaceImpl(front_facing_surface),
GetRenderSurfaceImpl(root));
EXPECT_NE(GetRenderSurfaceImpl(back_facing_surface),
GetRenderSurfaceImpl(root));
EXPECT_NE(GetRenderSurfaceImpl(back_facing_surface),
GetRenderSurfaceImpl(front_facing_surface));
EXPECT_EQ(GetRenderSurfaceImpl(front_facing_child_of_front_facing_surface),
GetRenderSurfaceImpl(front_facing_surface));
EXPECT_EQ(GetRenderSurfaceImpl(back_facing_child_of_front_facing_surface),
GetRenderSurfaceImpl(front_facing_surface));
EXPECT_EQ(GetRenderSurfaceImpl(front_facing_child_of_back_facing_surface),
GetRenderSurfaceImpl(back_facing_surface));
EXPECT_EQ(GetRenderSurfaceImpl(back_facing_child_of_back_facing_surface),
GetRenderSurfaceImpl(back_facing_surface));

EXPECT_EQ(3u, update_layer_impl_list().size());
EXPECT_TRUE(UpdateLayerImplListContains(front_facing_child->id()));
EXPECT_TRUE(UpdateLayerImplListContains(front_facing_surface->id()));
EXPECT_TRUE(UpdateLayerImplListContains(
front_facing_child_of_front_facing_surface->id()));
}

// Verify that layers are appropriately culled when their back face is showing
// and they are not double sided, while animations are going on.
// Even layers that are animating get culled if their back face is showing and
// they are not double sided.
TEST_F(PropertyTreeBuilderTest, BackFaceCullingWithAnimatingTransforms) {
auto root = Layer::Create();
host()->SetRootLayer(root);
auto child = Layer::Create();
root->AddChild(child);
auto animating_surface = Layer::Create();
root->AddChild(animating_surface);
auto child_of_animating_surface = Layer::Create();
animating_surface->AddChild(child_of_animating_surface);
auto animating_child = Layer::Create();
root->AddChild(animating_child);
auto child2 = Layer::Create();
root->AddChild(child2);

// Nothing is double-sided
child->SetDoubleSided(false);
child2->SetDoubleSided(false);
animating_surface->SetDoubleSided(false);
child_of_animating_surface->SetDoubleSided(false);
animating_child->SetDoubleSided(false);

// Everything draws content.
child->SetIsDrawable(true);
child2->SetIsDrawable(true);
animating_surface->SetIsDrawable(true);
child_of_animating_surface->SetIsDrawable(true);
animating_child->SetIsDrawable(true);

gfx::Transform backface_matrix;
backface_matrix.Translate(50.0, 50.0);
backface_matrix.RotateAboutYAxis(180.0);
backface_matrix.Translate(-50.0, -50.0);

host()->SetElementIdsForTesting();

// Animate the transform on the render surface.
AddAnimatedTransformToElementWithAnimation(animating_surface->element_id(),
timeline(), 10.0, 30, 0);
// This is just an animating layer, not a surface.
AddAnimatedTransformToElementWithAnimation(animating_child->element_id(),
timeline(), 10.0, 30, 0);

root->SetBounds(gfx::Size(100, 100));
child->SetBounds(gfx::Size(100, 100));
child->SetTransform(backface_matrix);
animating_surface->SetBounds(gfx::Size(100, 100));
animating_surface->SetTransform(backface_matrix);
animating_surface->SetForceRenderSurfaceForTesting(true);
child_of_animating_surface->SetBounds(gfx::Size(100, 100));
child_of_animating_surface->SetTransform(backface_matrix);
animating_child->SetBounds(gfx::Size(100, 100));
animating_child->SetTransform(backface_matrix);
child2->SetBounds(gfx::Size(100, 100));

CommitAndActivate();

EXPECT_EQ(GetRenderSurfaceImpl(child), GetRenderSurfaceImpl(root));
EXPECT_TRUE(GetRenderSurfaceImpl(animating_surface));
EXPECT_EQ(GetRenderSurfaceImpl(child_of_animating_surface),
GetRenderSurfaceImpl(animating_surface));
EXPECT_EQ(GetRenderSurfaceImpl(animating_child), GetRenderSurfaceImpl(root));
EXPECT_EQ(GetRenderSurfaceImpl(child2), GetRenderSurfaceImpl(root));

EXPECT_EQ(1u, update_layer_impl_list().size());

// The back facing layers are culled from the layer list, and have an empty
// visible rect.
EXPECT_TRUE(UpdateLayerImplListContains(child2->id()));
EXPECT_TRUE(ImplOf(child)->visible_layer_rect().IsEmpty());
EXPECT_TRUE(ImplOf(animating_surface)->visible_layer_rect().IsEmpty());
EXPECT_TRUE(
ImplOf(child_of_animating_surface)->visible_layer_rect().IsEmpty());
EXPECT_TRUE(ImplOf(animating_child)->visible_layer_rect().IsEmpty());

EXPECT_EQ(gfx::Rect(100, 100), ImplOf(child2)->visible_layer_rect());
}

// Verify that having animated opacity but current opacity 1 still creates
// a render surface.
TEST_F(PropertyTreeBuilderTest, AnimatedOpacityCreatesRenderSurface) {
Expand Down
Loading

0 comments on commit ec8a86e

Please sign in to comment.