Removing the assumption that child->SetParent will not change Drawability

R=danakj

Review URL: https://codereview.chromium.org/471233002

Cr-Commit-Position: refs/heads/master@{#289958}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289958 0039d316-1c4b-4281-b951-d872f2087c98
parent befe90df
...@@ -247,13 +247,13 @@ void Layer::AddChild(scoped_refptr<Layer> child) { ...@@ -247,13 +247,13 @@ void Layer::AddChild(scoped_refptr<Layer> child) {
void Layer::InsertChild(scoped_refptr<Layer> child, size_t index) { void Layer::InsertChild(scoped_refptr<Layer> child, size_t index) {
DCHECK(IsPropertyChangeAllowed()); DCHECK(IsPropertyChangeAllowed());
child->RemoveFromParent(); child->RemoveFromParent();
AddDrawableDescendants(child->NumDescendantsThatDrawContent() +
(child->DrawsContent() ? 1 : 0));
child->SetParent(this); child->SetParent(this);
child->stacking_order_changed_ = true; child->stacking_order_changed_ = true;
index = std::min(index, children_.size()); index = std::min(index, children_.size());
children_.insert(children_.begin() + index, child); children_.insert(children_.begin() + index, child);
AddDrawableDescendants(child->NumDescendantsThatDrawContent() +
(child->DrawsContent() ? 1 : 0));
SetNeedsFullTreeSync(); SetNeedsFullTreeSync();
} }
......
...@@ -56,7 +56,6 @@ class MockLayerPainter : public LayerPainter { ...@@ -56,7 +56,6 @@ class MockLayerPainter : public LayerPainter {
gfx::RectF* opaque) OVERRIDE {} gfx::RectF* opaque) OVERRIDE {}
}; };
class LayerTest : public testing::Test { class LayerTest : public testing::Test {
public: public:
LayerTest() LayerTest()
...@@ -1152,5 +1151,50 @@ TEST_F(LayerTest, SafeOpaqueBackgroundColor) { ...@@ -1152,5 +1151,50 @@ TEST_F(LayerTest, SafeOpaqueBackgroundColor) {
} }
} }
class DrawsContentChangeLayer : public Layer {
public:
static scoped_refptr<DrawsContentChangeLayer> Create() {
return make_scoped_refptr(new DrawsContentChangeLayer());
}
virtual void SetLayerTreeHost(LayerTreeHost* host) OVERRIDE {
Layer::SetLayerTreeHost(host);
SetFakeDrawsContent(!fake_draws_content_);
}
virtual bool HasDrawableContent() const OVERRIDE {
return fake_draws_content_ && Layer::HasDrawableContent();
}
void SetFakeDrawsContent(bool fake_draws_content) {
fake_draws_content_ = fake_draws_content;
UpdateDrawsContent(HasDrawableContent());
}
private:
DrawsContentChangeLayer() : Layer(), fake_draws_content_(false) {}
virtual ~DrawsContentChangeLayer() OVERRIDE {}
bool fake_draws_content_;
};
TEST_F(LayerTest, DrawsContentChangedInSetLayerTreeHost) {
scoped_refptr<Layer> root_layer = Layer::Create();
scoped_refptr<DrawsContentChangeLayer> becomes_not_draws_content =
DrawsContentChangeLayer::Create();
scoped_refptr<DrawsContentChangeLayer> becomes_draws_content =
DrawsContentChangeLayer::Create();
root_layer->SetIsDrawable(true);
becomes_not_draws_content->SetIsDrawable(true);
becomes_not_draws_content->SetFakeDrawsContent(true);
EXPECT_EQ(0, root_layer->NumDescendantsThatDrawContent());
root_layer->AddChild(becomes_not_draws_content);
EXPECT_EQ(0, root_layer->NumDescendantsThatDrawContent());
becomes_draws_content->SetIsDrawable(true);
root_layer->AddChild(becomes_draws_content);
EXPECT_EQ(1, root_layer->NumDescendantsThatDrawContent());
}
} // namespace } // namespace
} // namespace cc } // namespace cc
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