Commit 1e22f1dd authored by danakj's avatar danakj Committed by Commit Bot

Add documentation to cc::Layer API methods

Adds lots of comments explaining how to hold cc::Layer and what various
methods do or values mean.

Some cleanup while there, removing redundant child_at() and unused
SetChildren().

Also noticed SafeOpaqueBackgroundColor() is not safe if the root color
is non-opaque since that is what it inherits from. That occurs on the
ChromeOS lock screen, but there are no opaque layers there since
everything is trying to appear like widgets over the transparent space
so we're lucky right now. It would be a bug to try use non-opaque
colors to clear an "opaque" PictureLayer though, so I fixed it to
ensure the color is opaque even coming from the root layer.

R=enne@chromium.org

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: I325e3b03c4b4090068bbd1f453bf99a8cbfcd91c
Reviewed-on: https://chromium-review.googlesource.com/1087419Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarenne <enne@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564975}
parent fae3606b
...@@ -361,16 +361,6 @@ void Layer::RemoveAllChildren() { ...@@ -361,16 +361,6 @@ void Layer::RemoveAllChildren() {
} }
} }
void Layer::SetChildren(const LayerList& children) {
DCHECK(IsPropertyChangeAllowed());
if (children == inputs_.children)
return;
RemoveAllChildren();
for (size_t i = 0; i < children.size(); ++i)
AddChild(children[i]);
}
bool Layer::HasAncestor(const Layer* ancestor) const { bool Layer::HasAncestor(const Layer* ancestor) const {
for (const Layer* layer = parent(); layer; layer = layer->parent()) { for (const Layer* layer = parent(); layer; layer = layer->parent()) {
if (layer == ancestor) if (layer == ancestor)
...@@ -423,9 +413,10 @@ void Layer::SetBackgroundColor(SkColor background_color) { ...@@ -423,9 +413,10 @@ void Layer::SetBackgroundColor(SkColor background_color) {
void Layer::SetSafeOpaqueBackgroundColor(SkColor background_color) { void Layer::SetSafeOpaqueBackgroundColor(SkColor background_color) {
DCHECK(IsPropertyChangeAllowed()); DCHECK(IsPropertyChangeAllowed());
if (safe_opaque_background_color_ == background_color) SkColor opaque_color = SkColorSetA(background_color, 255);
if (safe_opaque_background_color_ == opaque_color)
return; return;
safe_opaque_background_color_ = background_color; safe_opaque_background_color_ = opaque_color;
SetNeedsPushProperties(); SetNeedsPushProperties();
} }
......
This diff is collapsed.
...@@ -36,7 +36,7 @@ static LayerImpl* ChildAt(LayerImpl* layer, int index) { ...@@ -36,7 +36,7 @@ static LayerImpl* ChildAt(LayerImpl* layer, int index) {
} }
static Layer* ChildAt(Layer* layer, int index) { static Layer* ChildAt(Layer* layer, int index) {
return layer->child_at(index); return layer->children()[index].get();
} }
template <typename LayerType> template <typename LayerType>
......
...@@ -688,37 +688,6 @@ TEST_F(LayerTest, RemoveAllChildren) { ...@@ -688,37 +688,6 @@ TEST_F(LayerTest, RemoveAllChildren) {
EXPECT_FALSE(child3_->parent()); EXPECT_FALSE(child3_->parent());
} }
TEST_F(LayerTest, SetChildren) {
scoped_refptr<Layer> old_parent = Layer::Create();
scoped_refptr<Layer> new_parent = Layer::Create();
scoped_refptr<Layer> child1 = Layer::Create();
scoped_refptr<Layer> child2 = Layer::Create();
LayerList new_children;
new_children.push_back(child1);
new_children.push_back(child2);
// Set up and verify initial test conditions: child1 has a parent, child2 has
// no parent.
old_parent->AddChild(child1);
ASSERT_EQ(0U, new_parent->children().size());
EXPECT_EQ(old_parent.get(), child1->parent());
EXPECT_FALSE(child2->parent());
EXPECT_SET_NEEDS_FULL_TREE_SYNC(1,
layer_tree_host_->SetRootLayer(new_parent));
EXPECT_SET_NEEDS_FULL_TREE_SYNC(
AtLeast(1), new_parent->SetChildren(new_children));
ASSERT_EQ(2U, new_parent->children().size());
EXPECT_EQ(new_parent.get(), child1->parent());
EXPECT_EQ(new_parent.get(), child2->parent());
EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr));
}
TEST_F(LayerTest, HasAncestor) { TEST_F(LayerTest, HasAncestor) {
scoped_refptr<Layer> parent = Layer::Create(); scoped_refptr<Layer> parent = Layer::Create();
EXPECT_FALSE(parent->HasAncestor(parent.get())); EXPECT_FALSE(parent->HasAncestor(parent.get()));
......
...@@ -155,7 +155,7 @@ static LayerImpl* LayerChildAt(LayerImpl* layer, int index) { ...@@ -155,7 +155,7 @@ static LayerImpl* LayerChildAt(LayerImpl* layer, int index) {
} }
static Layer* LayerChildAt(Layer* layer, int index) { static Layer* LayerChildAt(Layer* layer, int index) {
return layer->child_at(index); return layer->children()[index].get();
} }
static Layer* ScrollParent(Layer* layer) { static Layer* ScrollParent(Layer* layer) {
......
...@@ -48,8 +48,8 @@ void ThumbnailLayer::AddSelfToParentOrReplaceAt(scoped_refptr<cc::Layer> parent, ...@@ -48,8 +48,8 @@ void ThumbnailLayer::AddSelfToParentOrReplaceAt(scoped_refptr<cc::Layer> parent,
size_t index) { size_t index) {
if (index >= parent->children().size()) if (index >= parent->children().size())
parent->AddChild(layer_); parent->AddChild(layer_);
else if (parent->child_at(index)->id() != layer_->id()) else if (parent->children()[index]->id() != layer_->id())
parent->ReplaceChild(parent->child_at(index), layer_); parent->ReplaceChild(parent->children()[index].get(), layer_);
} }
scoped_refptr<cc::Layer> ThumbnailLayer::layer() { scoped_refptr<cc::Layer> ThumbnailLayer::layer() {
......
...@@ -116,7 +116,7 @@ void ToolbarLayer::PushResource( ...@@ -116,7 +116,7 @@ void ToolbarLayer::PushResource(
anonymize && layer_->children().back() != url_bar_background_layer_; anonymize && layer_->children().back() != url_bar_background_layer_;
bool needs_move_to_back = bool needs_move_to_back =
!anonymize && !anonymize &&
layer_->child_at(background_layer_index) != url_bar_background_layer_; layer_->children()[background_layer_index] != url_bar_background_layer_;
// If the layer needs to move, remove and re-add it. // If the layer needs to move, remove and re-add it.
if (needs_move_to_front) { if (needs_move_to_front) {
...@@ -138,7 +138,7 @@ void ToolbarLayer::PushResource( ...@@ -138,7 +138,7 @@ void ToolbarLayer::PushResource(
int ToolbarLayer::GetIndexOfLayer(scoped_refptr<cc::Layer> layer) { int ToolbarLayer::GetIndexOfLayer(scoped_refptr<cc::Layer> layer) {
for (unsigned int i = 0; i < layer_->children().size(); ++i) { for (unsigned int i = 0; i < layer_->children().size(); ++i) {
if (layer_->child_at(i) == layer) if (layer_->children()[i] == layer)
return i; return i;
} }
return -1; return -1;
......
...@@ -25,7 +25,8 @@ class PaintAndRasterInvalidationTest : public PaintControllerPaintTest { ...@@ -25,7 +25,8 @@ class PaintAndRasterInvalidationTest : public PaintControllerPaintTest {
.View() .View()
->GetPaintArtifactCompositorForTesting() ->GetPaintArtifactCompositorForTesting()
->RootLayer() ->RootLayer()
->child_at(index); ->children()[index]
.get();
} }
return GetLayoutView().Layer()->GraphicsLayerBacking()->ContentLayer(); return GetLayoutView().Layer()->GraphicsLayerBacking()->ContentLayer();
} }
......
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