diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/compositor/layer.cc | 28 | ||||
-rw-r--r-- | ui/compositor/layer.h | 3 | ||||
-rw-r--r-- | ui/compositor/layer_unittest.cc | 24 |
3 files changed, 36 insertions, 19 deletions
diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc index f729c9e..09009ea 100644 --- a/ui/compositor/layer.cc +++ b/ui/compositor/layer.cc @@ -47,6 +47,7 @@ Layer::Layer() compositor_(NULL), parent_(NULL), visible_(true), + is_drawn_(true), force_render_surface_(false), fills_bounds_opaquely_(true), layer_updated_externally_(false), @@ -71,6 +72,7 @@ Layer::Layer(LayerType type) compositor_(NULL), parent_(NULL), visible_(true), + is_drawn_(true), force_render_surface_(false), fills_bounds_opaquely_(true), layer_updated_externally_(false), @@ -140,6 +142,7 @@ void Layer::Add(Layer* child) { children_.push_back(child); cc_layer_->AddChild(child->cc_layer_); child->OnDeviceScaleFactorChanged(device_scale_factor_); + child->UpdateIsDrawn(); if (GetCompositor()) child->SendPendingThreadedAnimations(); } @@ -367,10 +370,21 @@ bool Layer::GetTargetVisibility() const { } bool Layer::IsDrawn() const { - const Layer* layer = this; - while (layer && layer->visible_) - layer = layer->parent_; - return layer == NULL; + return is_drawn_; +} + +void Layer::UpdateIsDrawn() { + bool updated_is_drawn = visible_ && (!parent_ || parent_->IsDrawn()); + + if (updated_is_drawn == is_drawn_) + return; + + is_drawn_ = updated_is_drawn; + cc_layer_->SetIsDrawable(is_drawn_ && type_ != LAYER_NOT_DRAWN); + + for (size_t i = 0; i < children_.size(); ++i) { + children_[i]->UpdateIsDrawn(); + } } bool Layer::ShouldDraw() const { @@ -464,7 +478,7 @@ void Layer::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { cc_layer_->SetAnchorPoint(gfx::PointF()); cc_layer_->SetContentsOpaque(fills_bounds_opaquely_); cc_layer_->SetForceRenderSurface(force_render_surface_); - cc_layer_->SetHideLayerAndSubtree(!visible_); + cc_layer_->SetIsDrawable(IsDrawn()); } void Layer::SwitchCCLayerForTest() { @@ -737,7 +751,7 @@ void Layer::SetBoundsImmediately(const gfx::Rect& bounds) { if (was_move) { // Don't schedule a draw if we're invisible. We'll schedule one // automatically when we get visible. - if (visible_) + if (IsDrawn()) ScheduleDraw(); } else { // Always schedule a paint, even if we're invisible. @@ -759,7 +773,7 @@ void Layer::SetVisibilityImmediately(bool visible) { return; visible_ = visible; - cc_layer_->SetHideLayerAndSubtree(!visible_); + UpdateIsDrawn(); } void Layer::SetBrightnessImmediately(float brightness) { diff --git a/ui/compositor/layer.h b/ui/compositor/layer.h index d536bf8..1159d0b 100644 --- a/ui/compositor/layer.h +++ b/ui/compositor/layer.h @@ -409,6 +409,9 @@ class COMPOSITOR_EXPORT Layer // Visibility of this layer. See SetVisible/IsDrawn for more details. bool visible_; + // Computed based on the visibility of this layer and its ancestors. + bool is_drawn_; + bool force_render_surface_; bool fills_bounds_opaquely_; diff --git a/ui/compositor/layer_unittest.cc b/ui/compositor/layer_unittest.cc index 0be8a0a..c326d4a 100644 --- a/ui/compositor/layer_unittest.cc +++ b/ui/compositor/layer_unittest.cc @@ -646,9 +646,9 @@ TEST_F(LayerWithNullDelegateTest, Visibility) { EXPECT_TRUE(l1->IsDrawn()); EXPECT_TRUE(l2->IsDrawn()); EXPECT_TRUE(l3->IsDrawn()); - EXPECT_FALSE(l1->cc_layer()->hide_layer_and_subtree()); - EXPECT_FALSE(l2->cc_layer()->hide_layer_and_subtree()); - EXPECT_FALSE(l3->cc_layer()->hide_layer_and_subtree()); + EXPECT_TRUE(l1->cc_layer()->DrawsContent()); + EXPECT_TRUE(l2->cc_layer()->DrawsContent()); + EXPECT_TRUE(l3->cc_layer()->DrawsContent()); compositor()->SetRootLayer(l1.get()); @@ -658,25 +658,25 @@ TEST_F(LayerWithNullDelegateTest, Visibility) { EXPECT_FALSE(l1->IsDrawn()); EXPECT_FALSE(l2->IsDrawn()); EXPECT_FALSE(l3->IsDrawn()); - EXPECT_TRUE(l1->cc_layer()->hide_layer_and_subtree()); - EXPECT_FALSE(l2->cc_layer()->hide_layer_and_subtree()); - EXPECT_FALSE(l3->cc_layer()->hide_layer_and_subtree()); + EXPECT_FALSE(l1->cc_layer()->DrawsContent()); + EXPECT_FALSE(l2->cc_layer()->DrawsContent()); + EXPECT_FALSE(l3->cc_layer()->DrawsContent()); l3->SetVisible(false); EXPECT_FALSE(l1->IsDrawn()); EXPECT_FALSE(l2->IsDrawn()); EXPECT_FALSE(l3->IsDrawn()); - EXPECT_TRUE(l1->cc_layer()->hide_layer_and_subtree()); - EXPECT_FALSE(l2->cc_layer()->hide_layer_and_subtree()); - EXPECT_TRUE(l3->cc_layer()->hide_layer_and_subtree()); + EXPECT_FALSE(l1->cc_layer()->DrawsContent()); + EXPECT_FALSE(l2->cc_layer()->DrawsContent()); + EXPECT_FALSE(l3->cc_layer()->DrawsContent()); l1->SetVisible(true); EXPECT_TRUE(l1->IsDrawn()); EXPECT_TRUE(l2->IsDrawn()); EXPECT_FALSE(l3->IsDrawn()); - EXPECT_FALSE(l1->cc_layer()->hide_layer_and_subtree()); - EXPECT_FALSE(l2->cc_layer()->hide_layer_and_subtree()); - EXPECT_TRUE(l3->cc_layer()->hide_layer_and_subtree()); + EXPECT_TRUE(l1->cc_layer()->DrawsContent()); + EXPECT_TRUE(l2->cc_layer()->DrawsContent()); + EXPECT_FALSE(l3->cc_layer()->DrawsContent()); } // Checks that stacking-related methods behave as advertised. |