Index: cc/trees/layer_tree_impl.cc |
diff --git a/cc/trees/layer_tree_impl.cc b/cc/trees/layer_tree_impl.cc |
index 27540d1263f03e008dba25fcdcd53d489582a2c1..51c58a9372e58e916c9ebba8c2f1b411c85d7492 100644 |
--- a/cc/trees/layer_tree_impl.cc |
+++ b/cc/trees/layer_tree_impl.cc |
@@ -460,22 +460,28 @@ LayerListReverseIterator<LayerImpl> LayerTreeImpl::rend() { |
return LayerListReverseIterator<LayerImpl>(nullptr); |
} |
+LayerImpl* LayerTreeImpl::LayerByElementId(ElementId element_id) const { |
+ auto iter = element_layers_map_.find(element_id); |
+ if (iter == element_layers_map_.end()) |
+ return nullptr; |
+ |
+ return iter->second; |
+} |
+ |
void LayerTreeImpl::AddToElementMap(LayerImpl* layer) { |
- if (!layer->element_id() || !layer->mutable_properties()) |
+ if (!layer->element_id()) |
return; |
TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), |
- "LayerTreeImpl::AddToElementMap", "element_id", |
- layer->element_id(), "layer_id", layer->id()); |
- |
- ElementLayers& layers = element_layers_map_[layer->element_id()]; |
- if ((!layers.main || layer->IsActive()) && !layer->scrollable()) { |
- layers.main = layer; |
- } else if ((!layers.scroll || layer->IsActive()) && layer->scrollable()) { |
- TRACE_EVENT2("compositor-worker", "LayerTreeImpl::AddToElementMap scroll", |
- "element_id", layer->element_id(), "layer_id", layer->id()); |
- layers.scroll = layer; |
- } |
+ "LayerTreeImpl::AddToElementMap", "element", |
+ layer->element_id().AsValue().release(), "layer_id", |
+ layer->id()); |
+ |
+ element_layers_map_[layer->element_id()] = layer; |
+ |
+ layer_tree_host_impl_->animation_host()->RegisterElement( |
+ layer->element_id(), |
+ IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING); |
} |
void LayerTreeImpl::RemoveFromElementMap(LayerImpl* layer) { |
@@ -483,32 +489,21 @@ void LayerTreeImpl::RemoveFromElementMap(LayerImpl* layer) { |
return; |
TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), |
- "LayerTreeImpl::RemoveFromElementMap", "element_id", |
- layer->element_id(), "layer_id", layer->id()); |
+ "LayerTreeImpl::RemoveFromElementMap", "element", |
+ layer->element_id().AsValue().release(), "layer_id", |
+ layer->id()); |
- ElementLayers& layers = element_layers_map_[layer->element_id()]; |
- if (!layer->scrollable()) |
- layers.main = nullptr; |
- if (layer->scrollable()) |
- layers.scroll = nullptr; |
+ layer_tree_host_impl_->animation_host()->UnregisterElement( |
+ layer->element_id(), |
+ IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING); |
- if (!layers.main && !layers.scroll) |
- element_layers_map_.erase(layer->element_id()); |
+ element_layers_map_.erase(layer->element_id()); |
} |
void LayerTreeImpl::AddToOpacityAnimationsMap(int id, float opacity) { |
opacity_animations_map_[id] = opacity; |
} |
-LayerTreeImpl::ElementLayers LayerTreeImpl::GetMutableLayers( |
- uint64_t element_id) { |
- auto iter = element_layers_map_.find(element_id); |
- if (iter == element_layers_map_.end()) |
- return ElementLayers(); |
- |
- return iter->second; |
-} |
- |
LayerImpl* LayerTreeImpl::InnerViewportContainerLayer() const { |
return InnerViewportScrollLayer() |
? InnerViewportScrollLayer()->scroll_clip_layer() |
@@ -789,6 +784,15 @@ void LayerTreeImpl::ClearViewportLayers() { |
outer_viewport_scroll_layer_id_ = Layer::INVALID_ID; |
} |
+// For unit tests, we use the layer's id as its element id. |
+static void SetElementIdForTesting(LayerImpl* layer) { |
+ layer->SetElementId(LayerIdToElementIdForTesting(layer->id())); |
+} |
+ |
+void LayerTreeImpl::SetElementIdsForTesting() { |
+ LayerTreeHostCommon::CallFunctionForEveryLayer(this, SetElementIdForTesting); |
+} |
+ |
bool LayerTreeImpl::UpdateDrawProperties(bool update_lcd_text) { |
if (!needs_update_draw_properties_) |
return true; |
@@ -1022,16 +1026,10 @@ bool LayerTreeImpl::LayerNeedsPushPropertiesForTesting(LayerImpl* layer) { |
void LayerTreeImpl::RegisterLayer(LayerImpl* layer) { |
DCHECK(!LayerById(layer->id())); |
layer_id_map_[layer->id()] = layer; |
- layer_tree_host_impl_->animation_host()->RegisterElement( |
- layer->id(), |
- IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING); |
} |
void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) { |
DCHECK(LayerById(layer->id())); |
- layer_tree_host_impl_->animation_host()->UnregisterElement( |
- layer->id(), |
- IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING); |
layer_id_map_.erase(layer->id()); |
DCHECK_NE(root_layer_, layer); |
} |
@@ -1913,21 +1911,21 @@ bool LayerTreeImpl::IsAnimatingFilterProperty(const LayerImpl* layer) const { |
ElementListType list_type = |
IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING; |
return layer_tree_host_impl_->animation_host()->IsAnimatingFilterProperty( |
- layer->id(), list_type); |
+ layer->element_id(), list_type); |
} |
bool LayerTreeImpl::IsAnimatingOpacityProperty(const LayerImpl* layer) const { |
ElementListType list_type = |
IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING; |
return layer_tree_host_impl_->animation_host()->IsAnimatingOpacityProperty( |
- layer->id(), list_type); |
+ layer->element_id(), list_type); |
} |
bool LayerTreeImpl::IsAnimatingTransformProperty(const LayerImpl* layer) const { |
ElementListType list_type = |
IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING; |
return layer_tree_host_impl_->animation_host()->IsAnimatingTransformProperty( |
- layer->id(), list_type); |
+ layer->element_id(), list_type); |
} |
bool LayerTreeImpl::HasPotentiallyRunningFilterAnimation( |
@@ -1935,7 +1933,7 @@ bool LayerTreeImpl::HasPotentiallyRunningFilterAnimation( |
ElementListType list_type = |
IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING; |
return layer_tree_host_impl_->animation_host() |
- ->HasPotentiallyRunningFilterAnimation(layer->id(), list_type); |
+ ->HasPotentiallyRunningFilterAnimation(layer->element_id(), list_type); |
} |
bool LayerTreeImpl::HasPotentiallyRunningOpacityAnimation( |
@@ -1943,7 +1941,7 @@ bool LayerTreeImpl::HasPotentiallyRunningOpacityAnimation( |
ElementListType list_type = |
IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING; |
return layer_tree_host_impl_->animation_host() |
- ->HasPotentiallyRunningOpacityAnimation(layer->id(), list_type); |
+ ->HasPotentiallyRunningOpacityAnimation(layer->element_id(), list_type); |
} |
bool LayerTreeImpl::HasPotentiallyRunningTransformAnimation( |
@@ -1951,27 +1949,27 @@ bool LayerTreeImpl::HasPotentiallyRunningTransformAnimation( |
ElementListType list_type = |
IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING; |
return layer_tree_host_impl_->animation_host() |
- ->HasPotentiallyRunningTransformAnimation(layer->id(), list_type); |
+ ->HasPotentiallyRunningTransformAnimation(layer->element_id(), list_type); |
} |
bool LayerTreeImpl::HasAnyAnimationTargetingProperty( |
const LayerImpl* layer, |
TargetProperty::Type property) const { |
return layer_tree_host_impl_->animation_host() |
- ->HasAnyAnimationTargetingProperty(layer->id(), property); |
+ ->HasAnyAnimationTargetingProperty(layer->element_id(), property); |
} |
bool LayerTreeImpl::AnimationsPreserveAxisAlignment( |
const LayerImpl* layer) const { |
return layer_tree_host_impl_->animation_host() |
- ->AnimationsPreserveAxisAlignment(layer->id()); |
+ ->AnimationsPreserveAxisAlignment(layer->element_id()); |
} |
bool LayerTreeImpl::HasOnlyTranslationTransforms(const LayerImpl* layer) const { |
ElementListType list_type = |
IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING; |
return layer_tree_host_impl_->animation_host()->HasOnlyTranslationTransforms( |
- layer->id(), list_type); |
+ layer->element_id(), list_type); |
} |
bool LayerTreeImpl::MaximumTargetScale(const LayerImpl* layer, |
@@ -1980,7 +1978,7 @@ bool LayerTreeImpl::MaximumTargetScale(const LayerImpl* layer, |
ElementListType list_type = |
IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING; |
return layer_tree_host_impl_->animation_host()->MaximumTargetScale( |
- layer->id(), list_type, max_scale); |
+ layer->element_id(), list_type, max_scale); |
} |
bool LayerTreeImpl::AnimationStartScale(const LayerImpl* layer, |
@@ -1989,32 +1987,32 @@ bool LayerTreeImpl::AnimationStartScale(const LayerImpl* layer, |
ElementListType list_type = |
IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING; |
return layer_tree_host_impl_->animation_host()->AnimationStartScale( |
- layer->id(), list_type, start_scale); |
+ layer->element_id(), list_type, start_scale); |
} |
bool LayerTreeImpl::HasFilterAnimationThatInflatesBounds( |
const LayerImpl* layer) const { |
return layer_tree_host_impl_->animation_host() |
- ->HasFilterAnimationThatInflatesBounds(layer->id()); |
+ ->HasFilterAnimationThatInflatesBounds(layer->element_id()); |
} |
bool LayerTreeImpl::HasTransformAnimationThatInflatesBounds( |
const LayerImpl* layer) const { |
return layer_tree_host_impl_->animation_host() |
- ->HasTransformAnimationThatInflatesBounds(layer->id()); |
+ ->HasTransformAnimationThatInflatesBounds(layer->element_id()); |
} |
bool LayerTreeImpl::HasAnimationThatInflatesBounds( |
const LayerImpl* layer) const { |
return layer_tree_host_impl_->animation_host() |
- ->HasAnimationThatInflatesBounds(layer->id()); |
+ ->HasAnimationThatInflatesBounds(layer->element_id()); |
} |
bool LayerTreeImpl::FilterAnimationBoundsForBox(const LayerImpl* layer, |
const gfx::BoxF& box, |
gfx::BoxF* bounds) const { |
return layer_tree_host_impl_->animation_host()->FilterAnimationBoundsForBox( |
- layer->id(), box, bounds); |
+ layer->element_id(), box, bounds); |
} |
bool LayerTreeImpl::TransformAnimationBoundsForBox(const LayerImpl* layer, |
@@ -2022,7 +2020,7 @@ bool LayerTreeImpl::TransformAnimationBoundsForBox(const LayerImpl* layer, |
gfx::BoxF* bounds) const { |
*bounds = gfx::BoxF(); |
return layer_tree_host_impl_->animation_host() |
- ->TransformAnimationBoundsForBox(layer->id(), box, bounds); |
+ ->TransformAnimationBoundsForBox(layer->element_id(), box, bounds); |
} |
void LayerTreeImpl::ScrollAnimationAbort(bool needs_completion) { |