1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/trees/property_tree_layer_tree_delegate.h"
#include "base/trace_event/trace_event.h"
#include "cc/layers/heads_up_display_layer.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/mutator_host_client.h"
#include "cc/trees/property_tree_builder.h"
namespace cc {
void PropertyTreeLayerTreeDelegate::SetLayerTreeHost(LayerTreeHost* host) {
host_ = host;
}
LayerTreeHost* PropertyTreeLayerTreeDelegate::host() {
return host_;
}
const LayerTreeHost* PropertyTreeLayerTreeDelegate::host() const {
return host_;
}
void PropertyTreeLayerTreeDelegate::UpdatePropertyTreesIfNeeded() {
TRACE_EVENT0("cc",
"PropertyTreeLayerTreeDelegate::UpdatePropertyTreesIfNeeded");
PropertyTreeBuilder::BuildPropertyTrees(host());
TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
"PropertyTreeLayerTreeDelegate::"
"UpdatePropertyTreesIfNeeded_BuiltPropertyTrees",
TRACE_EVENT_SCOPE_THREAD, "property_trees",
host()->property_trees()->AsTracedValue());
}
void PropertyTreeLayerTreeDelegate::UpdateScrollOffsetFromImpl(
const ElementId& id,
const gfx::Vector2dF& delta,
const std::optional<TargetSnapAreaElementIds>& snap_target_ids) {
if (Layer* layer = host()->LayerByElementId(id)) {
layer->SetScrollOffsetFromImplSide(layer->scroll_offset() + delta);
host()->SetNeedsUpdateLayers();
}
}
void PropertyTreeLayerTreeDelegate::OnAnimateLayers() {
// Animation state changes will require rebuilding property trees to
// track them.
host()->property_trees()->set_needs_rebuild(true);
}
void PropertyTreeLayerTreeDelegate::RegisterViewportPropertyIds(
const ViewportPropertyIds& ids) {
// This is a no-op in layer tree mode.
}
void PropertyTreeLayerTreeDelegate::OnUnregisterElement(ElementId element_id) {
host()->mutator_host()->RemoveElementId(element_id);
}
bool PropertyTreeLayerTreeDelegate::IsElementInPropertyTrees(
ElementId element_id,
ElementListType list_type) const {
return list_type == ElementListType::ACTIVE &&
host_->LayerByElementId(element_id);
}
void PropertyTreeLayerTreeDelegate::OnElementFilterMutated(
ElementId element_id,
ElementListType list_type,
const FilterOperations& filters) {
Layer* layer = host()->LayerByElementId(element_id);
DCHECK(layer);
layer->OnFilterAnimated(filters);
}
void PropertyTreeLayerTreeDelegate::OnElementBackdropFilterMutated(
ElementId element_id,
ElementListType list_type,
const FilterOperations& backdrop_filters) {
Layer* layer = host()->LayerByElementId(element_id);
DCHECK(layer);
layer->OnBackdropFilterAnimated(backdrop_filters);
}
void PropertyTreeLayerTreeDelegate::OnElementOpacityMutated(
ElementId element_id,
ElementListType list_type,
float opacity) {
Layer* layer = host()->LayerByElementId(element_id);
DCHECK(layer);
layer->OnOpacityAnimated(opacity);
if (EffectNode* node = host()->property_trees()->effect_tree_mutable().Node(
layer->effect_tree_index())) {
DCHECK_EQ(layer->effect_tree_index(), node->id);
if (node->opacity == opacity) {
return;
}
node->opacity = opacity;
host()->property_trees()->effect_tree_mutable().set_needs_update(true);
}
host()->SetNeedsUpdateLayers();
}
void PropertyTreeLayerTreeDelegate::OnElementTransformMutated(
ElementId element_id,
ElementListType list_type,
const gfx::Transform& transform) {
Layer* layer = host()->LayerByElementId(element_id);
DCHECK(layer);
layer->OnTransformAnimated(transform);
if (layer->has_transform_node()) {
TransformNode* node =
host()->property_trees()->transform_tree_mutable().Node(
layer->transform_tree_index());
if (node->local == transform) {
return;
}
node->local = transform;
node->needs_local_transform_update = true;
node->has_potential_animation = true;
host()->property_trees()->transform_tree_mutable().set_needs_update(true);
}
host()->SetNeedsUpdateLayers();
}
} // namespace cc
|