diff options
author | jaydasika <jaydasika@chromium.org> | 2016-03-23 18:26:05 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-24 01:27:58 +0000 |
commit | 0c2fd47d62aba824e36bc78560f8c9d4288a30dd (patch) | |
tree | 6f9e5025bd9dd55da00b2067de568a897b311770 | |
parent | eb0d622c183ae08eb51e1ca68b84cbb16c564363 (diff) | |
download | chromium_src-0c2fd47d62aba824e36bc78560f8c9d4288a30dd.zip chromium_src-0c2fd47d62aba824e36bc78560f8c9d4288a30dd.tar.gz chromium_src-0c2fd47d62aba824e36bc78560f8c9d4288a30dd.tar.bz2 |
cc : Determine if a layer is root by using the value in LayerTreeImpl
This CL also makes ValidateRenderSurfaces in DrawPropertyUtils use
Layer Iterator.
BUG=594024,568794
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
Review URL: https://codereview.chromium.org/1832663002
Cr-Commit-Position: refs/heads/master@{#383005}
-rw-r--r-- | cc/trees/draw_property_utils.cc | 39 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_common.cc | 11 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_common_unittest.cc | 53 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_impl.cc | 2 | ||||
-rw-r--r-- | cc/trees/layer_tree_impl.cc | 4 | ||||
-rw-r--r-- | cc/trees/layer_tree_impl.h | 1 | ||||
-rw-r--r-- | cc/trees/occlusion_tracker.cc | 11 |
7 files changed, 74 insertions, 47 deletions
diff --git a/cc/trees/draw_property_utils.cc b/cc/trees/draw_property_utils.cc index ab28243..15bdddc 100644 --- a/cc/trees/draw_property_utils.cc +++ b/cc/trees/draw_property_utils.cc @@ -23,12 +23,16 @@ namespace draw_property_utils { namespace { -template <typename LayerType> -static void ValidateRenderSurfaces(LayerType* layer) { - for (size_t i = 0; i < layer->children().size(); ++i) { - ValidateRenderSurfaces(layer->child_at(i)); - } +static bool IsRootLayer(const Layer* layer) { + return !layer->parent(); +} + +static bool IsRootLayer(const LayerImpl* layer) { + return layer->layer_tree_impl()->IsRootLayer(layer); +} +template <typename LayerType> +static void ValidateRenderSurfaceForLayer(LayerType* layer) { // This test verifies that there are no cases where a LayerImpl needs // a render surface, but doesn't have one. if (layer->has_render_surface()) @@ -36,7 +40,7 @@ static void ValidateRenderSurfaces(LayerType* layer) { DCHECK(layer->filters().IsEmpty()) << "layer: " << layer->id(); DCHECK(layer->background_filters().IsEmpty()) << "layer: " << layer->id(); - DCHECK(layer->parent()) << "layer: " << layer->id(); + DCHECK(!IsRootLayer(layer)) << "layer: " << layer->id(); if (layer->parent()->replica_layer() == layer) return; DCHECK(!layer->mask_layer()) << "layer: " << layer->id(); @@ -45,6 +49,12 @@ static void ValidateRenderSurfaces(LayerType* layer) { DCHECK(!layer->HasCopyRequest()) << "layer: " << layer->id(); } +static void ValidateRenderSurfacesRecursive(Layer* layer) { + ValidateRenderSurfaceForLayer(layer); + for (size_t i = 0; i < layer->children().size(); ++i) + ValidateRenderSurfacesRecursive(layer->child_at(i)); +} + template <typename LayerType> void CalculateVisibleRects(const std::vector<LayerType*>& visible_layer_list, const ClipTree& clip_tree, @@ -427,7 +437,7 @@ void FindLayersThatNeedUpdates( bool layer_is_drawn = effect_tree.Node(layer->effect_tree_index())->data.is_drawn; - if (layer->parent() && + if (!IsRootLayer(layer) && SubtreeShouldBeSkipped(layer, layer_is_drawn, transform_tree)) return; @@ -457,7 +467,7 @@ void UpdateRenderSurfaceForLayer(EffectTree* effect_tree, bool non_root_surfaces_enabled, LayerType* layer) { if (!non_root_surfaces_enabled) { - layer->SetHasRenderSurface(!layer->parent()); + layer->SetHasRenderSurface(IsRootLayer(layer)); return; } EffectNode* node = effect_tree->Node(layer->effect_tree_index()); @@ -687,7 +697,7 @@ void BuildPropertyTreesAndComputeVisibleRects( device_transform, property_trees); UpdateRenderSurfacesForLayersRecursive(&property_trees->effect_tree, root_layer); - ValidateRenderSurfaces(root_layer); + ValidateRenderSurfacesRecursive(root_layer); ComputeVisibleRects(root_layer, property_trees, can_render_to_separate_surface, update_layer_list); } @@ -729,11 +739,12 @@ void ComputeVisibleRects(LayerImpl* root_layer, PropertyTrees* property_trees, bool can_render_to_separate_surface, LayerImplList* visible_layer_list) { - for (auto* layer : *root_layer->layer_tree_impl()) + for (auto* layer : *root_layer->layer_tree_impl()) { UpdateRenderSurfaceForLayer(&property_trees->effect_tree, can_render_to_separate_surface, layer); - if (can_render_to_separate_surface) - ValidateRenderSurfaces(root_layer); + if (can_render_to_separate_surface) + ValidateRenderSurfaceForLayer(layer); + } LayerImplList update_layer_list; ComputeVisibleRectsInternal(root_layer, property_trees, can_render_to_separate_surface, @@ -745,7 +756,7 @@ static gfx::Transform DrawTransformInternal(const LayerType* layer, const TransformNode* node) { gfx::Transform xform; const bool owns_non_root_surface = - layer->parent() && layer->has_render_surface(); + !IsRootLayer(layer) && layer->has_render_surface(); if (!owns_non_root_surface) { // If you're not the root, or you don't own a surface, you need to apply // your local offset. @@ -1054,7 +1065,7 @@ static void UpdatePageScaleFactorInternal(PropertyTrees* property_trees, DCHECK_EQ(page_scale_layer->transform_origin().ToString(), gfx::Point3F().ToString()); - if (!page_scale_layer->parent()) { + if (IsRootLayer(page_scale_layer)) { // When the page scale layer is also the root layer, the node should also // store the combined scale factor and not just the page scale factor. float post_local_scale_factor = page_scale_factor * device_scale_factor; diff --git a/cc/trees/layer_tree_host_common.cc b/cc/trees/layer_tree_host_common.cc index 77b327b..143969b 100644 --- a/cc/trees/layer_tree_host_common.cc +++ b/cc/trees/layer_tree_host_common.cc @@ -243,11 +243,14 @@ gfx::Rect LayerTreeHostCommon::CalculateVisibleRect( target_surface_rect, layer_bound_rect, layer_in_surface_space, transform); } -template <typename LayerType> -static inline bool IsRootLayer(LayerType* layer) { +static inline bool IsRootLayer(const Layer* layer) { return !layer->parent(); } +static inline bool IsRootLayer(const LayerImpl* layer) { + return layer->layer_tree_impl()->IsRootLayer(layer); +} + template <typename LayerType> static inline bool LayerIsInExisting3DRenderingContext(LayerType* layer) { return layer->Is3dSorted() && layer->parent() && @@ -321,7 +324,7 @@ static bool LayerShouldBeSkipped(LayerImpl* layer, LayerImpl* backface_test_layer = layer; if (layer->use_parent_backface_visibility()) { - DCHECK(layer->parent()); + DCHECK(!IsRootLayer(layer)); DCHECK(!layer->parent()->use_parent_backface_visibility()); backface_test_layer = layer->parent(); } @@ -710,7 +713,7 @@ void CalculateRenderTarget(LayerImpl* layer, layer; } else { - DCHECK(layer->parent()); + DCHECK(!IsRootLayer(layer)); layer->draw_properties().render_target = layer->parent()->render_target(); } diff --git a/cc/trees/layer_tree_host_common_unittest.cc b/cc/trees/layer_tree_host_common_unittest.cc index 08e6113..25bafb0 100644 --- a/cc/trees/layer_tree_host_common_unittest.cc +++ b/cc/trees/layer_tree_host_common_unittest.cc @@ -5259,52 +5259,55 @@ TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { root->AddChild(std::move(child)); root->SetHasRenderSurface(true); + LayerImpl* root_layer = root.get(); + host_impl.pending_tree()->SetRootLayer(std::move(root)); LayerImplList render_surface_layer_list; - root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); + root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( - root.get(), root->bounds(), &render_surface_layer_list, - root->layer_tree_impl()->current_render_surface_list_id()); + root_layer, root_layer->bounds(), &render_surface_layer_list, + root_layer->layer_tree_impl()->current_render_surface_list_id()); inputs.can_adjust_raster_scales = true; LayerTreeHostCommon::CalculateDrawProperties(&inputs); // We should have one render surface and two layers. The child // layer should be included even though it is transparent. ASSERT_EQ(1u, render_surface_layer_list.size()); - ASSERT_EQ(2u, root->render_surface()->layer_list().size()); + ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); // If the root itself is hidden, the child should not be drawn even if it has // an animating opacity. - root->SetOpacity(0.0f); - root->layer_tree_impl()->property_trees()->needs_rebuild = true; + root_layer->SetOpacity(0.0f); + root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; LayerImplList render_surface_layer_list2; - root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); + root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2( - root.get(), root->bounds(), &render_surface_layer_list2, - root->layer_tree_impl()->current_render_surface_list_id()); + root_layer, root_layer->bounds(), &render_surface_layer_list2, + root_layer->layer_tree_impl()->current_render_surface_list_id()); inputs2.can_adjust_raster_scales = true; LayerTreeHostCommon::CalculateDrawProperties(&inputs2); - LayerImpl* child_ptr = root->layer_tree_impl()->LayerById(2); - EffectTree tree = root->layer_tree_impl()->property_trees()->effect_tree; + LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2); + EffectTree tree = + root_layer->layer_tree_impl()->property_trees()->effect_tree; EffectNode* node = tree.Node(child_ptr->effect_tree_index()); EXPECT_FALSE(node->data.is_drawn); // A layer should be drawn and it should contribute to drawn surface when // it has animating opacity even if it has opacity 0. - root->SetOpacity(1.0f); + root_layer->SetOpacity(1.0f); child_ptr->SetOpacity(0.0f); - root->layer_tree_impl()->property_trees()->needs_rebuild = true; + root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; LayerImplList render_surface_layer_list3; - root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); + root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3( - root.get(), root->bounds(), &render_surface_layer_list3, - root->layer_tree_impl()->current_render_surface_list_id()); + root_layer, root_layer->bounds(), &render_surface_layer_list3, + root_layer->layer_tree_impl()->current_render_surface_list_id()); inputs3.can_adjust_raster_scales = true; LayerTreeHostCommon::CalculateDrawProperties(&inputs3); - child_ptr = root->layer_tree_impl()->LayerById(2); - tree = root->layer_tree_impl()->property_trees()->effect_tree; + child_ptr = root_layer->layer_tree_impl()->LayerById(2); + tree = root_layer->layer_tree_impl()->property_trees()->effect_tree; node = tree.Node(child_ptr->effect_tree_index()); EXPECT_TRUE(node->data.is_drawn); EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index())); @@ -5551,6 +5554,7 @@ TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { const gfx::Transform identity_matrix; scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); + LayerImpl* root_layer = root.get(); SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), true, false, false); @@ -5573,21 +5577,22 @@ TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { child->AddChild(std::move(grand_child)); root->AddChild(std::move(child)); root->SetHasRenderSurface(true); + host_impl.pending_tree()->SetRootLayer(std::move(root)); LayerImplList render_surface_layer_list; - root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); + root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( - root.get(), root->bounds(), &render_surface_layer_list, - root->layer_tree_impl()->current_render_surface_list_id()); + root_layer, root_layer->bounds(), &render_surface_layer_list, + root_layer->layer_tree_impl()->current_render_surface_list_id()); inputs.can_adjust_raster_scales = true; LayerTreeHostCommon::CalculateDrawProperties(&inputs); // We should have one render surface and two layers. The grand child has // hidden itself. ASSERT_EQ(1u, render_surface_layer_list.size()); - ASSERT_EQ(2u, root->render_surface()->layer_list().size()); - EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); - EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id()); + ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); + EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id()); + EXPECT_EQ(2, root_layer->render_surface()->layer_list().at(1)->id()); } TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc index efc8eb0..32843bc 100644 --- a/cc/trees/layer_tree_host_impl.cc +++ b/cc/trees/layer_tree_host_impl.cc @@ -809,7 +809,7 @@ DrawResult LayerTreeHostImpl::CalculateRenderPasses( RenderSurfaceImpl* render_surface = render_surface_layer->render_surface(); bool should_draw_into_render_pass = - render_surface_layer->parent() == NULL || + active_tree_->IsRootLayer(render_surface_layer) || render_surface->contributes_to_drawn_surface() || render_surface_layer->HasCopyRequest(); if (should_draw_into_render_pass) diff --git a/cc/trees/layer_tree_impl.cc b/cc/trees/layer_tree_impl.cc index e89c84d..0420344 100644 --- a/cc/trees/layer_tree_impl.cc +++ b/cc/trees/layer_tree_impl.cc @@ -280,6 +280,10 @@ void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) { layer_tree_host_impl_->OnCanDrawStateChangedForTree(); } +bool LayerTreeImpl::IsRootLayer(const LayerImpl* layer) const { + return root_layer_ == layer; +} + LayerImpl* LayerTreeImpl::InnerViewportScrollLayer() const { return LayerById(inner_viewport_scroll_layer_id_); } diff --git a/cc/trees/layer_tree_impl.h b/cc/trees/layer_tree_impl.h index a137011..8bda30b 100644 --- a/cc/trees/layer_tree_impl.h +++ b/cc/trees/layer_tree_impl.h @@ -132,6 +132,7 @@ class CC_EXPORT LayerTreeImpl { // --------------------------------------------------------------------------- LayerImpl* root_layer() const { return root_layer_; } void SetRootLayer(scoped_ptr<LayerImpl>); + bool IsRootLayer(const LayerImpl* layer) const; scoped_ptr<OwnedLayerImplList> DetachLayers(); void ClearLayers(); diff --git a/cc/trees/occlusion_tracker.cc b/cc/trees/occlusion_tracker.cc index 4bcb762..a1a3ca0 100644 --- a/cc/trees/occlusion_tracker.cc +++ b/cc/trees/occlusion_tracker.cc @@ -13,6 +13,7 @@ #include "cc/layers/layer.h" #include "cc/layers/layer_impl.h" #include "cc/layers/render_surface_impl.h" +#include "cc/trees/layer_tree_impl.h" #include "ui/gfx/geometry/quad_f.h" #include "ui/gfx/geometry/rect_conversions.h" @@ -141,7 +142,8 @@ void OcclusionTracker::EnterRenderTarget(const LayerImpl* new_target) { new_target->render_surface()->screen_space_transform().GetInverse( &inverse_new_target_screen_space_transform); - bool entering_root_target = new_target->parent() == NULL; + bool entering_root_target = + new_target->layer_tree_impl()->IsRootLayer(new_target); bool copy_outside_occlusion_forward = stack_.size() > 1 && @@ -293,7 +295,7 @@ void OcclusionTracker::LeaveToRenderTarget(const LayerImpl* new_target) { old_occlusion_from_inside_target_in_new_target); // TODO(danakj): Strictly this should subtract the inside target occlusion // before union. - if (new_target->parent()) { + if (!new_target->layer_tree_impl()->IsRootLayer(new_target)) { stack_[last_index - 1].occlusion_from_outside_target.Union( old_occlusion_from_outside_target_in_new_target); } @@ -303,7 +305,7 @@ void OcclusionTracker::LeaveToRenderTarget(const LayerImpl* new_target) { stack_.back().target = new_target; stack_.back().occlusion_from_inside_target = old_occlusion_from_inside_target_in_new_target; - if (new_target->parent()) { + if (!new_target->layer_tree_impl()->IsRootLayer(new_target)) { stack_.back().occlusion_from_outside_target = old_occlusion_from_outside_target_in_new_target; } else { @@ -385,7 +387,8 @@ void OcclusionTracker::MarkOccludedBehindLayer(const LayerImpl* layer) { } Region OcclusionTracker::ComputeVisibleRegionInScreen() const { - DCHECK(!stack_.back().target->parent()); + DCHECK(stack_.back().target->layer_tree_impl()->IsRootLayer( + stack_.back().target)); const SimpleEnclosedRegion& occluded = stack_.back().occlusion_from_inside_target; Region visible_region(screen_space_clip_rect_); |