Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(457)

Side by Side Diff: cc/trees/layer_tree_impl.cc

Issue 1973083002: Use element id's for animations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: get element id's from scroll node data directly. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/layer_tree_impl.h" 5 #include "cc/trees/layer_tree_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 } 453 }
454 454
455 LayerListReverseIterator<LayerImpl> LayerTreeImpl::rbegin() { 455 LayerListReverseIterator<LayerImpl> LayerTreeImpl::rbegin() {
456 return LayerListReverseIterator<LayerImpl>(root_layer_); 456 return LayerListReverseIterator<LayerImpl>(root_layer_);
457 } 457 }
458 458
459 LayerListReverseIterator<LayerImpl> LayerTreeImpl::rend() { 459 LayerListReverseIterator<LayerImpl> LayerTreeImpl::rend() {
460 return LayerListReverseIterator<LayerImpl>(nullptr); 460 return LayerListReverseIterator<LayerImpl>(nullptr);
461 } 461 }
462 462
463 LayerImpl* LayerTreeImpl::LayerByElementId(ElementId element_id) const {
464 auto iter = element_layers_map_.find(element_id);
465 if (iter == element_layers_map_.end())
466 return nullptr;
467
468 return iter->second;
469 }
470
463 void LayerTreeImpl::AddToElementMap(LayerImpl* layer) { 471 void LayerTreeImpl::AddToElementMap(LayerImpl* layer) {
464 if (!layer->element_id() || !layer->mutable_properties()) 472 if (!layer->element_id())
465 return; 473 return;
466 474
467 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), 475 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("compositor-worker"),
468 "LayerTreeImpl::AddToElementMap", "element_id", 476 "LayerTreeImpl::AddToElementMap", "element",
469 layer->element_id(), "layer_id", layer->id()); 477 layer->element_id().AsValue().release(), "layer_id",
478 layer->id());
470 479
471 ElementLayers& layers = element_layers_map_[layer->element_id()]; 480 element_layers_map_[layer->element_id()] = layer;
472 if ((!layers.main || layer->IsActive()) && !layer->scrollable()) { 481
473 layers.main = layer; 482 layer_tree_host_impl_->animation_host()->RegisterElement(
474 } else if ((!layers.scroll || layer->IsActive()) && layer->scrollable()) { 483 layer->element_id(),
475 TRACE_EVENT2("compositor-worker", "LayerTreeImpl::AddToElementMap scroll", 484 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING);
476 "element_id", layer->element_id(), "layer_id", layer->id());
477 layers.scroll = layer;
478 }
479 } 485 }
480 486
481 void LayerTreeImpl::RemoveFromElementMap(LayerImpl* layer) { 487 void LayerTreeImpl::RemoveFromElementMap(LayerImpl* layer) {
482 if (!layer->element_id()) 488 if (!layer->element_id())
483 return; 489 return;
484 490
485 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), 491 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("compositor-worker"),
486 "LayerTreeImpl::RemoveFromElementMap", "element_id", 492 "LayerTreeImpl::RemoveFromElementMap", "element",
487 layer->element_id(), "layer_id", layer->id()); 493 layer->element_id().AsValue().release(), "layer_id",
494 layer->id());
488 495
489 ElementLayers& layers = element_layers_map_[layer->element_id()]; 496 layer_tree_host_impl_->animation_host()->UnregisterElement(
490 if (!layer->scrollable()) 497 layer->element_id(),
491 layers.main = nullptr; 498 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING);
492 if (layer->scrollable())
493 layers.scroll = nullptr;
494 499
495 if (!layers.main && !layers.scroll) 500 element_layers_map_.erase(layer->element_id());
496 element_layers_map_.erase(layer->element_id());
497 } 501 }
498 502
499 void LayerTreeImpl::AddToOpacityAnimationsMap(int id, float opacity) { 503 void LayerTreeImpl::AddToOpacityAnimationsMap(int id, float opacity) {
500 opacity_animations_map_[id] = opacity; 504 opacity_animations_map_[id] = opacity;
501 } 505 }
502 506
503 LayerTreeImpl::ElementLayers LayerTreeImpl::GetMutableLayers(
504 uint64_t element_id) {
505 auto iter = element_layers_map_.find(element_id);
506 if (iter == element_layers_map_.end())
507 return ElementLayers();
508
509 return iter->second;
510 }
511
512 LayerImpl* LayerTreeImpl::InnerViewportContainerLayer() const { 507 LayerImpl* LayerTreeImpl::InnerViewportContainerLayer() const {
513 return InnerViewportScrollLayer() 508 return InnerViewportScrollLayer()
514 ? InnerViewportScrollLayer()->scroll_clip_layer() 509 ? InnerViewportScrollLayer()->scroll_clip_layer()
515 : NULL; 510 : NULL;
516 } 511 }
517 512
518 LayerImpl* LayerTreeImpl::OuterViewportContainerLayer() const { 513 LayerImpl* LayerTreeImpl::OuterViewportContainerLayer() const {
519 return OuterViewportScrollLayer() 514 return OuterViewportScrollLayer()
520 ? OuterViewportScrollLayer()->scroll_clip_layer() 515 ? OuterViewportScrollLayer()->scroll_clip_layer()
521 : NULL; 516 : NULL;
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 outer_viewport_scroll_layer_id_ = outer_viewport_scroll_layer_id; 777 outer_viewport_scroll_layer_id_ = outer_viewport_scroll_layer_id;
783 } 778 }
784 779
785 void LayerTreeImpl::ClearViewportLayers() { 780 void LayerTreeImpl::ClearViewportLayers() {
786 overscroll_elasticity_layer_id_ = Layer::INVALID_ID; 781 overscroll_elasticity_layer_id_ = Layer::INVALID_ID;
787 page_scale_layer_id_ = Layer::INVALID_ID; 782 page_scale_layer_id_ = Layer::INVALID_ID;
788 inner_viewport_scroll_layer_id_ = Layer::INVALID_ID; 783 inner_viewport_scroll_layer_id_ = Layer::INVALID_ID;
789 outer_viewport_scroll_layer_id_ = Layer::INVALID_ID; 784 outer_viewport_scroll_layer_id_ = Layer::INVALID_ID;
790 } 785 }
791 786
787 // For unit tests, we use the layer's id as its element id.
788 static void SetElementIdForTesting(LayerImpl* layer) {
789 layer->SetElementId(LayerIdToElementIdForTesting(layer->id()));
790 }
791
792 void LayerTreeImpl::SetElementIdsForTesting() {
793 LayerTreeHostCommon::CallFunctionForEveryLayer(this, SetElementIdForTesting);
794 }
795
792 bool LayerTreeImpl::UpdateDrawProperties(bool update_lcd_text) { 796 bool LayerTreeImpl::UpdateDrawProperties(bool update_lcd_text) {
793 if (!needs_update_draw_properties_) 797 if (!needs_update_draw_properties_)
794 return true; 798 return true;
795 799
796 // Calling UpdateDrawProperties must clear this flag, so there can be no 800 // Calling UpdateDrawProperties must clear this flag, so there can be no
797 // early outs before this. 801 // early outs before this.
798 needs_update_draw_properties_ = false; 802 needs_update_draw_properties_ = false;
799 803
800 // For max_texture_size. When the renderer is re-created in 804 // For max_texture_size. When the renderer is re-created in
801 // CreateAndSetRenderer, the needs update draw properties flag is set 805 // CreateAndSetRenderer, the needs update draw properties flag is set
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 } 1019 }
1016 1020
1017 bool LayerTreeImpl::LayerNeedsPushPropertiesForTesting(LayerImpl* layer) { 1021 bool LayerTreeImpl::LayerNeedsPushPropertiesForTesting(LayerImpl* layer) {
1018 return layers_that_should_push_properties_.find(layer) != 1022 return layers_that_should_push_properties_.find(layer) !=
1019 layers_that_should_push_properties_.end(); 1023 layers_that_should_push_properties_.end();
1020 } 1024 }
1021 1025
1022 void LayerTreeImpl::RegisterLayer(LayerImpl* layer) { 1026 void LayerTreeImpl::RegisterLayer(LayerImpl* layer) {
1023 DCHECK(!LayerById(layer->id())); 1027 DCHECK(!LayerById(layer->id()));
1024 layer_id_map_[layer->id()] = layer; 1028 layer_id_map_[layer->id()] = layer;
1025 layer_tree_host_impl_->animation_host()->RegisterElement(
1026 layer->id(),
1027 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING);
1028 } 1029 }
1029 1030
1030 void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) { 1031 void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) {
1031 DCHECK(LayerById(layer->id())); 1032 DCHECK(LayerById(layer->id()));
1032 layer_tree_host_impl_->animation_host()->UnregisterElement(
1033 layer->id(),
1034 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING);
1035 layer_id_map_.erase(layer->id()); 1033 layer_id_map_.erase(layer->id());
1036 DCHECK_NE(root_layer_, layer); 1034 DCHECK_NE(root_layer_, layer);
1037 } 1035 }
1038 1036
1039 // These manage ownership of the LayerImpl. 1037 // These manage ownership of the LayerImpl.
1040 void LayerTreeImpl::AddLayer(std::unique_ptr<LayerImpl> layer) { 1038 void LayerTreeImpl::AddLayer(std::unique_ptr<LayerImpl> layer) {
1041 DCHECK(std::find(layers_->begin(), layers_->end(), layer) == layers_->end()); 1039 DCHECK(std::find(layers_->begin(), layers_->end(), layer) == layers_->end());
1042 layers_->push_back(std::move(layer)); 1040 layers_->push_back(std::move(layer));
1043 set_needs_update_draw_properties(); 1041 set_needs_update_draw_properties();
1044 } 1042 }
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 1904
1907 std::unique_ptr<PendingPageScaleAnimation> 1905 std::unique_ptr<PendingPageScaleAnimation>
1908 LayerTreeImpl::TakePendingPageScaleAnimation() { 1906 LayerTreeImpl::TakePendingPageScaleAnimation() {
1909 return std::move(pending_page_scale_animation_); 1907 return std::move(pending_page_scale_animation_);
1910 } 1908 }
1911 1909
1912 bool LayerTreeImpl::IsAnimatingFilterProperty(const LayerImpl* layer) const { 1910 bool LayerTreeImpl::IsAnimatingFilterProperty(const LayerImpl* layer) const {
1913 ElementListType list_type = 1911 ElementListType list_type =
1914 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING; 1912 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING;
1915 return layer_tree_host_impl_->animation_host()->IsAnimatingFilterProperty( 1913 return layer_tree_host_impl_->animation_host()->IsAnimatingFilterProperty(
1916 layer->id(), list_type); 1914 layer->element_id(), list_type);
1917 } 1915 }
1918 1916
1919 bool LayerTreeImpl::IsAnimatingOpacityProperty(const LayerImpl* layer) const { 1917 bool LayerTreeImpl::IsAnimatingOpacityProperty(const LayerImpl* layer) const {
1920 ElementListType list_type = 1918 ElementListType list_type =
1921 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING; 1919 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING;
1922 return layer_tree_host_impl_->animation_host()->IsAnimatingOpacityProperty( 1920 return layer_tree_host_impl_->animation_host()->IsAnimatingOpacityProperty(
1923 layer->id(), list_type); 1921 layer->element_id(), list_type);
1924 } 1922 }
1925 1923
1926 bool LayerTreeImpl::IsAnimatingTransformProperty(const LayerImpl* layer) const { 1924 bool LayerTreeImpl::IsAnimatingTransformProperty(const LayerImpl* layer) const {
1927 ElementListType list_type = 1925 ElementListType list_type =
1928 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING; 1926 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING;
1929 return layer_tree_host_impl_->animation_host()->IsAnimatingTransformProperty( 1927 return layer_tree_host_impl_->animation_host()->IsAnimatingTransformProperty(
1930 layer->id(), list_type); 1928 layer->element_id(), list_type);
1931 } 1929 }
1932 1930
1933 bool LayerTreeImpl::HasPotentiallyRunningFilterAnimation( 1931 bool LayerTreeImpl::HasPotentiallyRunningFilterAnimation(
1934 const LayerImpl* layer) const { 1932 const LayerImpl* layer) const {
1935 ElementListType list_type = 1933 ElementListType list_type =
1936 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING; 1934 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING;
1937 return layer_tree_host_impl_->animation_host() 1935 return layer_tree_host_impl_->animation_host()
1938 ->HasPotentiallyRunningFilterAnimation(layer->id(), list_type); 1936 ->HasPotentiallyRunningFilterAnimation(layer->element_id(), list_type);
1939 } 1937 }
1940 1938
1941 bool LayerTreeImpl::HasPotentiallyRunningOpacityAnimation( 1939 bool LayerTreeImpl::HasPotentiallyRunningOpacityAnimation(
1942 const LayerImpl* layer) const { 1940 const LayerImpl* layer) const {
1943 ElementListType list_type = 1941 ElementListType list_type =
1944 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING; 1942 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING;
1945 return layer_tree_host_impl_->animation_host() 1943 return layer_tree_host_impl_->animation_host()
1946 ->HasPotentiallyRunningOpacityAnimation(layer->id(), list_type); 1944 ->HasPotentiallyRunningOpacityAnimation(layer->element_id(), list_type);
1947 } 1945 }
1948 1946
1949 bool LayerTreeImpl::HasPotentiallyRunningTransformAnimation( 1947 bool LayerTreeImpl::HasPotentiallyRunningTransformAnimation(
1950 const LayerImpl* layer) const { 1948 const LayerImpl* layer) const {
1951 ElementListType list_type = 1949 ElementListType list_type =
1952 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING; 1950 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING;
1953 return layer_tree_host_impl_->animation_host() 1951 return layer_tree_host_impl_->animation_host()
1954 ->HasPotentiallyRunningTransformAnimation(layer->id(), list_type); 1952 ->HasPotentiallyRunningTransformAnimation(layer->element_id(), list_type);
1955 } 1953 }
1956 1954
1957 bool LayerTreeImpl::HasAnyAnimationTargetingProperty( 1955 bool LayerTreeImpl::HasAnyAnimationTargetingProperty(
1958 const LayerImpl* layer, 1956 const LayerImpl* layer,
1959 TargetProperty::Type property) const { 1957 TargetProperty::Type property) const {
1960 return layer_tree_host_impl_->animation_host() 1958 return layer_tree_host_impl_->animation_host()
1961 ->HasAnyAnimationTargetingProperty(layer->id(), property); 1959 ->HasAnyAnimationTargetingProperty(layer->element_id(), property);
1962 } 1960 }
1963 1961
1964 bool LayerTreeImpl::AnimationsPreserveAxisAlignment( 1962 bool LayerTreeImpl::AnimationsPreserveAxisAlignment(
1965 const LayerImpl* layer) const { 1963 const LayerImpl* layer) const {
1966 return layer_tree_host_impl_->animation_host() 1964 return layer_tree_host_impl_->animation_host()
1967 ->AnimationsPreserveAxisAlignment(layer->id()); 1965 ->AnimationsPreserveAxisAlignment(layer->element_id());
1968 } 1966 }
1969 1967
1970 bool LayerTreeImpl::HasOnlyTranslationTransforms(const LayerImpl* layer) const { 1968 bool LayerTreeImpl::HasOnlyTranslationTransforms(const LayerImpl* layer) const {
1971 ElementListType list_type = 1969 ElementListType list_type =
1972 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING; 1970 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING;
1973 return layer_tree_host_impl_->animation_host()->HasOnlyTranslationTransforms( 1971 return layer_tree_host_impl_->animation_host()->HasOnlyTranslationTransforms(
1974 layer->id(), list_type); 1972 layer->element_id(), list_type);
1975 } 1973 }
1976 1974
1977 bool LayerTreeImpl::MaximumTargetScale(const LayerImpl* layer, 1975 bool LayerTreeImpl::MaximumTargetScale(const LayerImpl* layer,
1978 float* max_scale) const { 1976 float* max_scale) const {
1979 *max_scale = 0.f; 1977 *max_scale = 0.f;
1980 ElementListType list_type = 1978 ElementListType list_type =
1981 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING; 1979 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING;
1982 return layer_tree_host_impl_->animation_host()->MaximumTargetScale( 1980 return layer_tree_host_impl_->animation_host()->MaximumTargetScale(
1983 layer->id(), list_type, max_scale); 1981 layer->element_id(), list_type, max_scale);
1984 } 1982 }
1985 1983
1986 bool LayerTreeImpl::AnimationStartScale(const LayerImpl* layer, 1984 bool LayerTreeImpl::AnimationStartScale(const LayerImpl* layer,
1987 float* start_scale) const { 1985 float* start_scale) const {
1988 *start_scale = 0.f; 1986 *start_scale = 0.f;
1989 ElementListType list_type = 1987 ElementListType list_type =
1990 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING; 1988 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING;
1991 return layer_tree_host_impl_->animation_host()->AnimationStartScale( 1989 return layer_tree_host_impl_->animation_host()->AnimationStartScale(
1992 layer->id(), list_type, start_scale); 1990 layer->element_id(), list_type, start_scale);
1993 } 1991 }
1994 1992
1995 bool LayerTreeImpl::HasFilterAnimationThatInflatesBounds( 1993 bool LayerTreeImpl::HasFilterAnimationThatInflatesBounds(
1996 const LayerImpl* layer) const { 1994 const LayerImpl* layer) const {
1997 return layer_tree_host_impl_->animation_host() 1995 return layer_tree_host_impl_->animation_host()
1998 ->HasFilterAnimationThatInflatesBounds(layer->id()); 1996 ->HasFilterAnimationThatInflatesBounds(layer->element_id());
1999 } 1997 }
2000 1998
2001 bool LayerTreeImpl::HasTransformAnimationThatInflatesBounds( 1999 bool LayerTreeImpl::HasTransformAnimationThatInflatesBounds(
2002 const LayerImpl* layer) const { 2000 const LayerImpl* layer) const {
2003 return layer_tree_host_impl_->animation_host() 2001 return layer_tree_host_impl_->animation_host()
2004 ->HasTransformAnimationThatInflatesBounds(layer->id()); 2002 ->HasTransformAnimationThatInflatesBounds(layer->element_id());
2005 } 2003 }
2006 2004
2007 bool LayerTreeImpl::HasAnimationThatInflatesBounds( 2005 bool LayerTreeImpl::HasAnimationThatInflatesBounds(
2008 const LayerImpl* layer) const { 2006 const LayerImpl* layer) const {
2009 return layer_tree_host_impl_->animation_host() 2007 return layer_tree_host_impl_->animation_host()
2010 ->HasAnimationThatInflatesBounds(layer->id()); 2008 ->HasAnimationThatInflatesBounds(layer->element_id());
2011 } 2009 }
2012 2010
2013 bool LayerTreeImpl::FilterAnimationBoundsForBox(const LayerImpl* layer, 2011 bool LayerTreeImpl::FilterAnimationBoundsForBox(const LayerImpl* layer,
2014 const gfx::BoxF& box, 2012 const gfx::BoxF& box,
2015 gfx::BoxF* bounds) const { 2013 gfx::BoxF* bounds) const {
2016 return layer_tree_host_impl_->animation_host()->FilterAnimationBoundsForBox( 2014 return layer_tree_host_impl_->animation_host()->FilterAnimationBoundsForBox(
2017 layer->id(), box, bounds); 2015 layer->element_id(), box, bounds);
2018 } 2016 }
2019 2017
2020 bool LayerTreeImpl::TransformAnimationBoundsForBox(const LayerImpl* layer, 2018 bool LayerTreeImpl::TransformAnimationBoundsForBox(const LayerImpl* layer,
2021 const gfx::BoxF& box, 2019 const gfx::BoxF& box,
2022 gfx::BoxF* bounds) const { 2020 gfx::BoxF* bounds) const {
2023 *bounds = gfx::BoxF(); 2021 *bounds = gfx::BoxF();
2024 return layer_tree_host_impl_->animation_host() 2022 return layer_tree_host_impl_->animation_host()
2025 ->TransformAnimationBoundsForBox(layer->id(), box, bounds); 2023 ->TransformAnimationBoundsForBox(layer->element_id(), box, bounds);
2026 } 2024 }
2027 2025
2028 void LayerTreeImpl::ScrollAnimationAbort(bool needs_completion) { 2026 void LayerTreeImpl::ScrollAnimationAbort(bool needs_completion) {
2029 layer_tree_host_impl_->animation_host()->ScrollAnimationAbort( 2027 layer_tree_host_impl_->animation_host()->ScrollAnimationAbort(
2030 needs_completion); 2028 needs_completion);
2031 } 2029 }
2032 2030
2033 void LayerTreeImpl::ResetAllChangeTracking() { 2031 void LayerTreeImpl::ResetAllChangeTracking() {
2034 layers_that_should_push_properties_.clear(); 2032 layers_that_should_push_properties_.clear();
2035 for (auto* layer : *this) 2033 for (auto* layer : *this)
2036 layer->ResetChangeTracking(); 2034 layer->ResetChangeTracking();
2037 property_trees_.ResetAllChangeTracking(); 2035 property_trees_.ResetAllChangeTracking();
2038 } 2036 }
2039 2037
2040 } // namespace cc 2038 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698