diff options
Diffstat (limited to 'chromium/cc/layers/layer.cc')
-rw-r--r-- | chromium/cc/layers/layer.cc | 204 |
1 files changed, 147 insertions, 57 deletions
diff --git a/chromium/cc/layers/layer.cc b/chromium/cc/layers/layer.cc index 269226aca78..dfc03bb5898 100644 --- a/chromium/cc/layers/layer.cc +++ b/chromium/cc/layers/layer.cc @@ -53,7 +53,9 @@ Layer::Inputs::Inputs(int layer_id) sorting_context_id(0), use_parent_backface_visibility(false), background_color(0), + backdrop_filter_quality(1.0f), scrollable(false), + is_scrollbar(false), user_scrollable_horizontal(true), user_scrollable_vertical(true), main_thread_scrolling_reasons( @@ -94,6 +96,7 @@ Layer::Layer() may_contain_video_(false), needs_show_scrollbars_(false), has_transform_node_(false), + is_rounded_corner_mask_(false), subtree_has_copy_request_(false), safe_opaque_background_color_(0) {} @@ -119,24 +122,30 @@ void Layer::SetLayerTreeHost(LayerTreeHost* host) { if (layer_tree_host_ == host) return; + bool property_tree_indices_invalid = false; if (layer_tree_host_) { layer_tree_host_->property_trees()->needs_rebuild = true; layer_tree_host_->UnregisterLayer(this); - if (!layer_tree_host_->IsUsingLayerLists() && inputs_.element_id) { + if (inputs_.element_id) { layer_tree_host_->UnregisterElement(inputs_.element_id, ElementListType::ACTIVE); } + if (!layer_tree_host_->IsUsingLayerLists()) + property_tree_indices_invalid = true; } if (host) { host->property_trees()->needs_rebuild = true; host->RegisterLayer(this); - if (!host->IsUsingLayerLists() && inputs_.element_id) { + if (inputs_.element_id) host->RegisterElement(inputs_.element_id, ElementListType::ACTIVE, this); - } + if (!host->IsUsingLayerLists()) + property_tree_indices_invalid = true; } layer_tree_host_ = host; - InvalidatePropertyTreesIndices(); + + if (property_tree_indices_invalid) + InvalidatePropertyTreesIndices(); // When changing hosts, the layer needs to commit its properties to the impl // side for the new host. @@ -236,8 +245,8 @@ void Layer::RemoveChildOrDependent(Layer* child) { return; } - for (LayerList::iterator iter = inputs_.children.begin(); - iter != inputs_.children.end(); ++iter) { + for (auto iter = inputs_.children.begin(); iter != inputs_.children.end(); + ++iter) { if (iter->get() != child) continue; @@ -290,7 +299,7 @@ void Layer::SetBounds(const gfx::Size& size) { SetPropertyTreesNeedRebuild(); } - if (scrollable()) { + if (scrollable() && !layer_tree_host_->IsUsingLayerLists()) { auto& scroll_tree = layer_tree_host_->property_trees()->scroll_tree; if (auto* scroll_node = scroll_tree.Node(scroll_tree_index_)) scroll_node->bounds = inputs_.bounds; @@ -309,7 +318,7 @@ void Layer::SetOverscrollBehavior(const OverscrollBehavior& behavior) { if (!layer_tree_host_) return; - if (scrollable()) { + if (scrollable() && !layer_tree_host_->IsUsingLayerLists()) { auto& scroll_tree = layer_tree_host_->property_trees()->scroll_tree; if (auto* scroll_node = scroll_tree.Node(scroll_tree_index_)) scroll_node->overscroll_behavior = behavior; @@ -328,7 +337,7 @@ void Layer::SetSnapContainerData(base::Optional<SnapContainerData> data) { if (!layer_tree_host_) return; - if (scrollable()) { + if (scrollable() && !layer_tree_host_->IsUsingLayerLists()) { auto& scroll_tree = layer_tree_host_->property_trees()->scroll_tree; if (auto* scroll_node = scroll_tree.Node(scroll_tree_index_)) scroll_node->snap_container_data = inputs_.snap_container_data; @@ -355,6 +364,57 @@ void Layer::RemoveAllChildren() { } } +void Layer::SetChildLayerList(LayerList new_children) { + DCHECK(layer_tree_host_->IsUsingLayerLists()); + + // Early out without calling |LayerTreeHost::SetNeedsFullTreeSync| if no + // layer has changed. + if (children() == new_children) + return; + + // Remove existing children that will not be in the new child list. + { + std::unordered_set<Layer*> children_to_remove; + for (auto& existing_child : children()) + children_to_remove.insert(existing_child.get()); + for (auto& new_child : new_children) + children_to_remove.erase(new_child.get()); + for (auto* child : children_to_remove) { + child->SetParent(nullptr); + AddDrawableDescendants(-child->NumDescendantsThatDrawContent() - + (child->DrawsContent() ? 1 : 0)); + } + } + + // Mark existing children as changed if their order changes. + auto existing_child_it = children().begin(); + for (auto& child : new_children) { + if (child->parent() == this) { + // Search forward in the existing child list to find the new child. + existing_child_it = std::find(existing_child_it, children().end(), child); + if (existing_child_it == children().end()) + child->SetSubtreePropertyChanged(); + } + } + + // Process new children and mark them as changed. + // Because this changes the child's parent, it must be after code that uses + // |child->parent()| such as the above loop. + for (auto& child : new_children) { + if (child->parent() != this) { + child->RemoveFromParent(); + AddDrawableDescendants(child->NumDescendantsThatDrawContent() + + (child->DrawsContent() ? 1 : 0)); + child->SetParent(this); + child->SetSubtreePropertyChanged(); + } + } + + inputs_.children = std::move(new_children); + + layer_tree_host_->SetNeedsFullTreeSync(); +} + bool Layer::HasAncestor(const Layer* ancestor) const { for (const Layer* layer = parent(); layer; layer = layer->parent()) { if (layer == ancestor) @@ -495,6 +555,10 @@ void Layer::SetBackgroundFilters(const FilterOperations& filters) { SetNeedsCommit(); } +void Layer::SetBackdropFilterQuality(const float quality) { + inputs_.backdrop_filter_quality = quality; +} + void Layer::SetFiltersOrigin(const gfx::PointF& filters_origin) { DCHECK(IsPropertyChangeAllowed()); if (inputs_.filters_origin == filters_origin) @@ -517,17 +581,21 @@ void Layer::SetOpacity(float opacity) { bool force_rebuild = opacity == 1.f || inputs_.opacity == 1.f; inputs_.opacity = opacity; SetSubtreePropertyChanged(); - if (layer_tree_host_ && !force_rebuild) { - PropertyTrees* property_trees = layer_tree_host_->property_trees(); - if (EffectNode* node = - property_trees->effect_tree.Node(effect_tree_index())) { - node->opacity = opacity; - node->effect_changed = true; - property_trees->effect_tree.set_needs_update(true); + + if (layer_tree_host_ && !layer_tree_host_->IsUsingLayerLists()) { + if (!force_rebuild) { + PropertyTrees* property_trees = layer_tree_host_->property_trees(); + if (EffectNode* node = + property_trees->effect_tree.Node(effect_tree_index())) { + node->opacity = opacity; + node->effect_changed = true; + property_trees->effect_tree.set_needs_update(true); + } + } else { + SetPropertyTreesNeedRebuild(); } } - if (force_rebuild) - SetPropertyTreesNeedRebuild(); + SetNeedsCommit(); } @@ -629,16 +697,19 @@ void Layer::SetPosition(const gfx::PointF& position) { return; SetSubtreePropertyChanged(); - if (has_transform_node_) { - TransformNode* transform_node = - layer_tree_host_->property_trees()->transform_tree.Node( - transform_tree_index_); - transform_node->update_post_local_transform(position, transform_origin()); - transform_node->needs_local_transform_update = true; - transform_node->transform_changed = true; - layer_tree_host_->property_trees()->transform_tree.set_needs_update(true); - } else { - SetPropertyTreesNeedRebuild(); + + if (!layer_tree_host_->IsUsingLayerLists()) { + if (has_transform_node_) { + TransformNode* transform_node = + layer_tree_host_->property_trees()->transform_tree.Node( + transform_tree_index_); + transform_node->update_post_local_transform(position, transform_origin()); + transform_node->needs_local_transform_update = true; + transform_node->transform_changed = true; + layer_tree_host_->property_trees()->transform_tree.set_needs_update(true); + } else { + SetPropertyTreesNeedRebuild(); + } } SetNeedsCommit(); @@ -669,7 +740,7 @@ void Layer::SetTransform(const gfx::Transform& transform) { return; SetSubtreePropertyChanged(); - if (layer_tree_host_) { + if (layer_tree_host_ && !layer_tree_host_->IsUsingLayerLists()) { if (has_transform_node_) { TransformNode* transform_node = layer_tree_host_->property_trees()->transform_tree.Node( @@ -705,18 +776,21 @@ void Layer::SetTransformOrigin(const gfx::Point3F& transform_origin) { return; SetSubtreePropertyChanged(); - if (has_transform_node_) { - TransformNode* transform_node = - layer_tree_host_->property_trees()->transform_tree.Node( - transform_tree_index_); - DCHECK_EQ(transform_tree_index(), transform_node->id); - transform_node->update_pre_local_transform(transform_origin); - transform_node->update_post_local_transform(position(), transform_origin); - transform_node->needs_local_transform_update = true; - transform_node->transform_changed = true; - layer_tree_host_->property_trees()->transform_tree.set_needs_update(true); - } else { - SetPropertyTreesNeedRebuild(); + + if (!layer_tree_host_->IsUsingLayerLists()) { + if (has_transform_node_) { + TransformNode* transform_node = + layer_tree_host_->property_trees()->transform_tree.Node( + transform_tree_index_); + DCHECK_EQ(transform_tree_index(), transform_node->id); + transform_node->update_pre_local_transform(transform_origin); + transform_node->update_post_local_transform(position(), transform_origin); + transform_node->needs_local_transform_update = true; + transform_node->transform_changed = true; + layer_tree_host_->property_trees()->transform_tree.set_needs_update(true); + } else { + SetPropertyTreesNeedRebuild(); + } } SetNeedsCommit(); @@ -801,6 +875,12 @@ void Layer::SetScrollOffsetFromImplSide( void Layer::UpdateScrollOffset(const gfx::ScrollOffset& scroll_offset) { DCHECK(scrollable()); + + // This function updates the property tree scroll offsets but in layer list + // mode this should occur during the main -> cc property tree push. + if (layer_tree_host_->IsUsingLayerLists()) + return; + if (scroll_tree_index() == ScrollTree::kInvalidNodeId) { // Ensure the property trees just have not been built yet but are marked for // being built which will set the correct scroll offset values. @@ -832,13 +912,23 @@ void Layer::SetScrollable(const gfx::Size& bounds) { if (!layer_tree_host_) return; - auto& scroll_tree = layer_tree_host_->property_trees()->scroll_tree; - auto* scroll_node = scroll_tree.Node(scroll_tree_index_); - if (was_scrollable && scroll_node) - scroll_node->container_bounds = inputs_.scroll_container_bounds; - else - SetPropertyTreesNeedRebuild(); + if (!layer_tree_host_->IsUsingLayerLists()) { + auto& scroll_tree = layer_tree_host_->property_trees()->scroll_tree; + auto* scroll_node = scroll_tree.Node(scroll_tree_index_); + if (was_scrollable && scroll_node) + scroll_node->container_bounds = inputs_.scroll_container_bounds; + else + SetPropertyTreesNeedRebuild(); + } + + SetNeedsCommit(); +} + +void Layer::SetIsScrollbar(bool is_scrollbar) { + if (inputs_.is_scrollbar == is_scrollbar) + return; + inputs_.is_scrollbar = is_scrollbar; SetNeedsCommit(); } @@ -852,7 +942,7 @@ void Layer::SetUserScrollable(bool horizontal, bool vertical) { if (!layer_tree_host_) return; - if (scrollable()) { + if (scrollable() && !layer_tree_host_->IsUsingLayerLists()) { auto& scroll_tree = layer_tree_host_->property_trees()->scroll_tree; if (auto* scroll_node = scroll_tree.Node(scroll_tree_index_)) { scroll_node->user_scrollable_horizontal = horizontal; @@ -1172,6 +1262,7 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { // deprecated. http://crbug.com/709137 layer->SetElementId(inputs_.element_id); layer->SetHasTransformNode(has_transform_node_); + layer->set_is_rounded_corner_mask(is_rounded_corner_mask_); layer->SetBackgroundColor(inputs_.background_color); layer->SetSafeOpaqueBackgroundColor(safe_opaque_background_color_); layer->SetBounds(inputs_.bounds); @@ -1196,12 +1287,11 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { layer->SetTouchActionRegion(inputs_.touch_action_region); // TODO(sunxd): Pass the correct region for wheel event handlers, see // https://crbug.com/841364. - if (layer_tree_host()->event_listener_properties( - EventListenerClass::kMouseWheel) == - EventListenerProperties::kBlocking || + EventListenerProperties mouse_wheel_props = layer_tree_host()->event_listener_properties( - EventListenerClass::kMouseWheel) == - EventListenerProperties::kBlockingAndPassive) { + EventListenerClass::kMouseWheel); + if (mouse_wheel_props == EventListenerProperties::kBlocking || + mouse_wheel_props == EventListenerProperties::kBlockingAndPassive) { layer->SetWheelEventHandlerRegion(Region(gfx::Rect(bounds()))); } else { layer->SetWheelEventHandlerRegion(Region()); @@ -1216,6 +1306,8 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { if (scrollable()) layer->SetScrollable(inputs_.scroll_container_bounds); + layer->set_is_scrollbar(inputs_.is_scrollbar); + // The property trees must be safe to access because they will be used below // to call |SetScrollOffsetClobberActiveValue|. DCHECK(layer->layer_tree_impl()->lifecycle().AllowsPropertyTreeAccess()); @@ -1250,7 +1342,6 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { if (mask_layer()) DCHECK_EQ(bounds().ToString(), mask_layer()->bounds().ToString()); - layer_tree_host_->RemoveLayerShouldPushProperties(this); } void Layer::TakeCopyRequests( @@ -1391,7 +1482,7 @@ ElementListType Layer::GetElementTypeForAnimation() const { void Layer::RemoveFromClipTree() { if (clip_children_.get()) { std::set<Layer*> copy = *clip_children_; - for (std::set<Layer*>::iterator it = copy.begin(); it != copy.end(); ++it) + for (auto it = copy.begin(); it != copy.end(); ++it) (*it)->SetClipParent(nullptr); } @@ -1414,8 +1505,7 @@ void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) {} void Layer::SetElementId(ElementId id) { DCHECK(IsPropertyChangeAllowed()); - if ((layer_tree_host_ && layer_tree_host_->IsUsingLayerLists()) || - inputs_.element_id == id) + if (inputs_.element_id == id) return; TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug"), "Layer::SetElementId", "element", id.AsValue().release()); |