Skip to content

Commit

Permalink
cc: Move LayerImpl::AddChild and RemoveChild to LayerImplTestProperties
Browse files Browse the repository at this point in the history
BUG=602438
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

Review-Url: https://codereview.chromium.org/2084233002
Cr-Commit-Position: refs/heads/master@{#401163}
  • Loading branch information
jaydasika authored and Commit bot committed Jun 22, 2016
1 parent a84983c commit 89f7b5a
Show file tree
Hide file tree
Showing 25 changed files with 368 additions and 334 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class ScrollbarAnimationControllerLinearFadeTest
clip_layer_ = clip.get();
scroll_layer->SetScrollClipLayer(clip_layer_->id());
LayerImpl* scroll_layer_ptr = scroll_layer.get();
scroll_layer->AddChild(std::move(scrollbar));
clip->AddChild(std::move(scroll_layer));
scroll_layer->test_properties()->AddChild(std::move(scrollbar));
clip->test_properties()->AddChild(std::move(scroll_layer));
host_impl_.active_tree()->SetRootLayer(std::move(clip));

scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id());
Expand Down
4 changes: 2 additions & 2 deletions cc/input/scrollbar_animation_controller_thinning_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class ScrollbarAnimationControllerThinningTest
kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar);
scrollbar_layer_ = scrollbar.get();

scroll_layer->AddChild(std::move(scrollbar));
clip_layer_->AddChild(std::move(scroll_layer));
scroll_layer->test_properties()->AddChild(std::move(scrollbar));
clip_layer_->test_properties()->AddChild(std::move(scroll_layer));
host_impl_.active_tree()->SetRootLayer(std::move(clip));

scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id());
Expand Down
16 changes: 0 additions & 16 deletions cc/layers/layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,6 @@ LayerImpl::~LayerImpl() {
TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this);
}

void LayerImpl::AddChild(std::unique_ptr<LayerImpl> child) {
child->test_properties()->parent = this;
DCHECK_EQ(layer_tree_impl(), child->layer_tree_impl());
test_properties()->children.push_back(child.get());
layer_tree_impl_->AddLayer(std::move(child));
}

std::unique_ptr<LayerImpl> LayerImpl::RemoveChildForTesting(LayerImpl* child) {
auto it = std::find(test_properties()->children.begin(),
test_properties()->children.end(), child);
if (it != test_properties()->children.end())
test_properties()->children.erase(it);
layer_tree_impl()->property_trees()->RemoveIdFromIdToIndexMaps(child->id());
return layer_tree_impl_->RemoveLayer(child->id());
}

void LayerImpl::SetHasWillChangeTransformHint(bool has_will_change) {
if (has_will_change_transform_hint_ == has_will_change)
return;
Expand Down
4 changes: 0 additions & 4 deletions cc/layers/layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ class CC_EXPORT LayerImpl {
void OnOpacityIsPotentiallyAnimatingChanged(bool has_potential_animation);
bool IsActive() const;

// Tree structure.
void AddChild(std::unique_ptr<LayerImpl> child);
std::unique_ptr<LayerImpl> RemoveChildForTesting(LayerImpl* child);

void DistributeScroll(ScrollState* scroll_state);
void ApplyScroll(ScrollState* scroll_state);

Expand Down
16 changes: 16 additions & 0 deletions cc/layers/layer_impl_test_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ LayerImplTestProperties::LayerImplTestProperties(LayerImpl* owning_layer)

LayerImplTestProperties::~LayerImplTestProperties() {}

void LayerImplTestProperties::AddChild(std::unique_ptr<LayerImpl> child) {
child->test_properties()->parent = owning_layer;
children.push_back(child.get());
owning_layer->layer_tree_impl()->AddLayer(std::move(child));
}

std::unique_ptr<LayerImpl> LayerImplTestProperties::RemoveChild(
LayerImpl* child) {
auto it = std::find(children.begin(), children.end(), child);
if (it != children.end())
children.erase(it);
owning_layer->layer_tree_impl()->property_trees()->RemoveIdFromIdToIndexMaps(
child->id());
return owning_layer->layer_tree_impl()->RemoveLayer(child->id());
}

void LayerImplTestProperties::SetMaskLayer(std::unique_ptr<LayerImpl> mask) {
if (mask_layer)
owning_layer->layer_tree_impl()->RemoveLayer(mask_layer->id());
Expand Down
2 changes: 2 additions & 0 deletions cc/layers/layer_impl_test_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ struct CC_EXPORT LayerImplTestProperties {
explicit LayerImplTestProperties(LayerImpl* owning_layer);
~LayerImplTestProperties();

void AddChild(std::unique_ptr<LayerImpl> child);
std::unique_ptr<LayerImpl> RemoveChild(LayerImpl* child);
void SetMaskLayer(std::unique_ptr<LayerImpl> mask);
void SetReplicaLayer(std::unique_ptr<LayerImpl> replica);

Expand Down
14 changes: 8 additions & 6 deletions cc/layers/layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,17 @@ TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) {
std::unique_ptr<LayerImpl> root_ptr =
LayerImpl::Create(host_impl.active_tree(), 2);
LayerImpl* root = root_ptr.get();
root_clip_ptr->AddChild(std::move(root_ptr));
root_clip_ptr->test_properties()->AddChild(std::move(root_ptr));
host_impl.active_tree()->SetRootLayer(std::move(root_clip_ptr));

root->test_properties()->force_render_surface = true;
root->layer_tree_impl()->ResetAllChangeTracking();

root->AddChild(LayerImpl::Create(host_impl.active_tree(), 7));
root->test_properties()->AddChild(
LayerImpl::Create(host_impl.active_tree(), 7));
LayerImpl* child = root->test_properties()->children[0];
child->AddChild(LayerImpl::Create(host_impl.active_tree(), 8));
child->test_properties()->AddChild(
LayerImpl::Create(host_impl.active_tree(), 8));
LayerImpl* grand_child = child->test_properties()->children[0];
root->SetScrollClipLayer(root_clip->id());
host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
Expand Down Expand Up @@ -239,12 +241,12 @@ TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) {
std::unique_ptr<LayerImpl> layer_ptr =
LayerImpl::Create(host_impl.active_tree(), 2);
LayerImpl* layer = layer_ptr.get();
root->AddChild(std::move(layer_ptr));
root->test_properties()->AddChild(std::move(layer_ptr));
layer->SetScrollClipLayer(root->id());
std::unique_ptr<LayerImpl> layer2_ptr =
LayerImpl::Create(host_impl.active_tree(), 3);
LayerImpl* layer2 = layer2_ptr.get();
root->AddChild(std::move(layer2_ptr));
root->test_properties()->AddChild(std::move(layer2_ptr));
host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
DCHECK(host_impl.CanDraw());

Expand Down Expand Up @@ -393,7 +395,7 @@ class LayerImplScrollTest : public testing::Test {
root_id_(7) {
host_impl_.active_tree()->SetRootLayer(
LayerImpl::Create(host_impl_.active_tree(), root_id_));
host_impl_.active_tree()->root_layer()->AddChild(
host_impl_.active_tree()->root_layer()->test_properties()->AddChild(
LayerImpl::Create(host_impl_.active_tree(), root_id_ + 1));
layer()->SetScrollClipLayer(root_id_);
// Set the max scroll offset by noting that the root layer has bounds (1,1),
Expand Down
40 changes: 20 additions & 20 deletions cc/layers/layer_iterator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ TEST_F(LayerIteratorTest, SimpleTree) {
TestLayerImpl* third_ptr = third.get();
TestLayerImpl* fourth_ptr = fourth.get();

root_layer->AddChild(std::move(first));
root_layer->AddChild(std::move(second));
root_layer->AddChild(std::move(third));
root_layer->AddChild(std::move(fourth));
root_layer->test_properties()->AddChild(std::move(first));
root_layer->test_properties()->AddChild(std::move(second));
root_layer->test_properties()->AddChild(std::move(third));
root_layer->test_properties()->AddChild(std::move(fourth));

host_impl_.active_tree()->SetRootLayer(std::move(root_layer));

Expand Down Expand Up @@ -172,14 +172,14 @@ TEST_F(LayerIteratorTest, ComplexTree) {
TestLayerImpl* root221_ptr = root221.get();
TestLayerImpl* root231_ptr = root231.get();

root22->AddChild(std::move(root221));
root23->AddChild(std::move(root231));
root2->AddChild(std::move(root21));
root2->AddChild(std::move(root22));
root2->AddChild(std::move(root23));
root_layer->AddChild(std::move(root1));
root_layer->AddChild(std::move(root2));
root_layer->AddChild(std::move(root3));
root22->test_properties()->AddChild(std::move(root221));
root23->test_properties()->AddChild(std::move(root231));
root2->test_properties()->AddChild(std::move(root21));
root2->test_properties()->AddChild(std::move(root22));
root2->test_properties()->AddChild(std::move(root23));
root_layer->test_properties()->AddChild(std::move(root1));
root_layer->test_properties()->AddChild(std::move(root2));
root_layer->test_properties()->AddChild(std::move(root3));

host_impl_.active_tree()->SetRootLayer(std::move(root_layer));

Expand Down Expand Up @@ -224,15 +224,15 @@ TEST_F(LayerIteratorTest, ComplexTreeMultiSurface) {
root22->test_properties()->force_render_surface = true;
root23->test_properties()->force_render_surface = true;
root2->test_properties()->force_render_surface = true;
root22->AddChild(std::move(root221));
root23->AddChild(std::move(root231));
root22->test_properties()->AddChild(std::move(root221));
root23->test_properties()->AddChild(std::move(root231));
root2->SetDrawsContent(false);
root2->AddChild(std::move(root21));
root2->AddChild(std::move(root22));
root2->AddChild(std::move(root23));
root_layer->AddChild(std::move(root1));
root_layer->AddChild(std::move(root2));
root_layer->AddChild(std::move(root3));
root2->test_properties()->AddChild(std::move(root21));
root2->test_properties()->AddChild(std::move(root22));
root2->test_properties()->AddChild(std::move(root23));
root_layer->test_properties()->AddChild(std::move(root1));
root_layer->test_properties()->AddChild(std::move(root2));
root_layer->test_properties()->AddChild(std::move(root3));

host_impl_.active_tree()->SetRootLayer(std::move(root_layer));

Expand Down
24 changes: 12 additions & 12 deletions cc/layers/layer_list_iterator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@ TEST(LayerListIteratorTest, VerifyTraversalOrderImpl) {
std::unique_ptr<LayerImpl> layer7 =
LayerImpl::Create(host_impl.active_tree(), 7);

layer2->AddChild(std::move(layer3));
layer2->AddChild(std::move(layer4));
layer2->test_properties()->AddChild(std::move(layer3));
layer2->test_properties()->AddChild(std::move(layer4));

layer5->AddChild(std::move(layer6));
layer5->AddChild(std::move(layer7));
layer5->test_properties()->AddChild(std::move(layer6));
layer5->test_properties()->AddChild(std::move(layer7));

layer1->AddChild(std::move(layer2));
layer1->AddChild(std::move(layer5));
layer1->test_properties()->AddChild(std::move(layer2));
layer1->test_properties()->AddChild(std::move(layer5));

host_impl.active_tree()->SetRootLayer(std::move(layer1));
host_impl.active_tree()->BuildLayerListForTesting();
Expand Down Expand Up @@ -320,14 +320,14 @@ TEST(LayerListReverseIteratorTest, VerifyTraversalOrderImpl) {
std::unique_ptr<LayerImpl> layer7 =
LayerImpl::Create(host_impl.active_tree(), 7);

layer2->AddChild(std::move(layer3));
layer2->AddChild(std::move(layer4));
layer2->test_properties()->AddChild(std::move(layer3));
layer2->test_properties()->AddChild(std::move(layer4));

layer5->AddChild(std::move(layer6));
layer5->AddChild(std::move(layer7));
layer5->test_properties()->AddChild(std::move(layer6));
layer5->test_properties()->AddChild(std::move(layer7));

layer1->AddChild(std::move(layer2));
layer1->AddChild(std::move(layer5));
layer1->test_properties()->AddChild(std::move(layer2));
layer1->test_properties()->AddChild(std::move(layer5));

host_impl.active_tree()->SetRootLayer(std::move(layer1));
host_impl.active_tree()->BuildLayerListForTesting();
Expand Down
12 changes: 8 additions & 4 deletions cc/layers/layer_utils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,27 @@ class LayerUtilsGetAnimationBoundsTest : public testing::Test {
std::unique_ptr<LayerImpl> root =
LayerImpl::Create(host_impl->active_tree(), 1);
LayerImpl* root_ptr = root.get();
root->AddChild(LayerImpl::Create(host_impl->active_tree(), 2));
root->test_properties()->children[0]->AddChild(
root->test_properties()->AddChild(
LayerImpl::Create(host_impl->active_tree(), 2));
root->test_properties()->children[0]->test_properties()->AddChild(
LayerImpl::Create(host_impl->active_tree(), 3));
root->AddChild(LayerImpl::Create(host_impl->active_tree(), 4));
root->test_properties()->children[1]->AddChild(
root->test_properties()->AddChild(
LayerImpl::Create(host_impl->active_tree(), 4));
root->test_properties()->children[1]->test_properties()->AddChild(
LayerImpl::Create(host_impl->active_tree(), 5));
root->test_properties()
->children[1]
->test_properties()
->children[0]
->test_properties()
->AddChild(LayerImpl::Create(host_impl->active_tree(), 6));
root->test_properties()
->children[1]
->test_properties()
->children[0]
->test_properties()
->children[0]
->test_properties()
->AddChild(LayerImpl::Create(host_impl->active_tree(), 7));
host_impl->active_tree()->SetRootLayer(std::move(root));
return root_ptr;
Expand Down
18 changes: 12 additions & 6 deletions cc/layers/picture_layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3694,7 +3694,8 @@ TEST_F(OcclusionTrackingPictureLayerImplTest,
EXPECT_EQ(unoccluded_tile_count, 25);

// Partial occlusion.
pending_layer()->AddChild(LayerImpl::Create(host_impl()->pending_tree(), 1));
pending_layer()->test_properties()->AddChild(
LayerImpl::Create(host_impl()->pending_tree(), 1));
LayerImpl* layer1 = pending_layer()->test_properties()->children[0];
layer1->SetBounds(layer_bounds);
layer1->SetDrawsContent(true);
Expand Down Expand Up @@ -3789,7 +3790,8 @@ TEST_F(OcclusionTrackingPictureLayerImplTest,
}

// Partial occlusion.
pending_layer()->AddChild(LayerImpl::Create(host_impl()->pending_tree(), 1));
pending_layer()->test_properties()->AddChild(
LayerImpl::Create(host_impl()->pending_tree(), 1));
LayerImpl* layer1 = pending_layer()->test_properties()->children[0];
layer1->SetBounds(layer_bounds);
layer1->SetDrawsContent(true);
Expand Down Expand Up @@ -3886,7 +3888,8 @@ TEST_F(OcclusionTrackingPictureLayerImplTest, OcclusionForDifferentScales) {
SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
ASSERT_TRUE(pending_layer()->CanHaveTilings());

pending_layer()->AddChild(LayerImpl::Create(host_impl()->pending_tree(), 1));
pending_layer()->test_properties()->AddChild(
LayerImpl::Create(host_impl()->pending_tree(), 1));
LayerImpl* layer1 = pending_layer()->test_properties()->children[0];
layer1->SetBounds(layer_bounds);
layer1->SetDrawsContent(true);
Expand Down Expand Up @@ -3961,7 +3964,8 @@ TEST_F(OcclusionTrackingPictureLayerImplTest, DifferentOcclusionOnTrees) {
SetupPendingTree(active_raster_source);

// Partially occlude the active layer.
pending_layer()->AddChild(LayerImpl::Create(host_impl()->pending_tree(), 2));
pending_layer()->test_properties()->AddChild(
LayerImpl::Create(host_impl()->pending_tree(), 2));
LayerImpl* layer1 = pending_layer()->test_properties()->children[0];
layer1->SetBounds(layer_bounds);
layer1->SetDrawsContent(true);
Expand Down Expand Up @@ -4055,7 +4059,8 @@ TEST_F(OcclusionTrackingPictureLayerImplTest,
SetupPendingTreeWithFixedTileSize(active_raster_source, tile_size, Region());

// Partially occlude the active layer.
pending_layer()->AddChild(LayerImpl::Create(host_impl()->pending_tree(), 2));
pending_layer()->test_properties()->AddChild(
LayerImpl::Create(host_impl()->pending_tree(), 2));
LayerImpl* active_occluding_layer =
pending_layer()->test_properties()->children[0];
active_occluding_layer->SetBounds(layer_bounds);
Expand All @@ -4071,7 +4076,8 @@ TEST_F(OcclusionTrackingPictureLayerImplTest,
invalidation_rect);

// Partially occlude the pending layer in a different way.
pending_layer()->AddChild(LayerImpl::Create(host_impl()->pending_tree(), 3));
pending_layer()->test_properties()->AddChild(
LayerImpl::Create(host_impl()->pending_tree(), 3));
LayerImpl* pending_occluding_layer =
pending_layer()->test_properties()->children[0];
pending_occluding_layer->SetBounds(layer_bounds);
Expand Down
4 changes: 2 additions & 2 deletions cc/layers/render_surface_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ TEST(RenderSurfaceLayerImplTest, AppendQuadsWithScaledMask) {
child->SetDrawsContent(true);
child->SetBounds(layer_size);

surface->AddChild(std::move(child));
root->AddChild(std::move(surface));
surface->test_properties()->AddChild(std::move(child));
root->test_properties()->AddChild(std::move(surface));
impl.host_impl()->active_tree()->SetRootLayer(std::move(root));

impl.host_impl()->SetViewportSize(viewport_size);
Expand Down
4 changes: 2 additions & 2 deletions cc/layers/render_surface_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ TEST(RenderSurfaceTest, SanityCheckSurfaceCreatesCorrectSharedQuadState) {
owning_layer->SetBlendMode(blend_mode);
RenderSurfaceImpl* render_surface = owning_layer->render_surface();

root_layer->AddChild(std::move(owning_layer));
root_layer->test_properties()->AddChild(std::move(owning_layer));
host_impl.active_tree()->SetRootLayer(std::move(root_layer));
host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();

Expand Down Expand Up @@ -167,7 +167,7 @@ TEST(RenderSurfaceTest, SanityCheckSurfaceCreatesCorrectRenderPass) {
ASSERT_TRUE(owning_layer->render_surface());
RenderSurfaceImpl* render_surface = owning_layer->render_surface();

root_layer->AddChild(std::move(owning_layer));
root_layer->test_properties()->AddChild(std::move(owning_layer));

gfx::Rect content_rect(0, 0, 50, 50);
gfx::Transform origin;
Expand Down
2 changes: 1 addition & 1 deletion cc/layers/video_layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ TEST(VideoLayerImplTest, OccludesOtherLayers) {
video_layer_impl->SetDrawsContent(true);
video_layer_impl->SetContentsOpaque(true);

layer_impl->AddChild(std::move(video_layer_impl));
layer_impl->test_properties()->AddChild(std::move(video_layer_impl));
active_tree->SetRootLayer(std::move(layer_impl));

active_tree->BuildLayerListAndPropertyTreesForTesting();
Expand Down
Loading

0 comments on commit 89f7b5a

Please sign in to comment.