| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/layers/layer_impl.h" | 5 #include "cc/layers/layer_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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 contents_opaque_(false), | 63 contents_opaque_(false), |
| 64 use_parent_backface_visibility_(false), | 64 use_parent_backface_visibility_(false), |
| 65 use_local_transform_for_backface_visibility_(false), | 65 use_local_transform_for_backface_visibility_(false), |
| 66 should_check_backface_visibility_(false), | 66 should_check_backface_visibility_(false), |
| 67 draws_content_(false), | 67 draws_content_(false), |
| 68 is_drawn_render_surface_layer_list_member_(false), | 68 is_drawn_render_surface_layer_list_member_(false), |
| 69 is_affected_by_page_scale_(true), | 69 is_affected_by_page_scale_(true), |
| 70 was_ever_ready_since_last_transform_animation_(true), | 70 was_ever_ready_since_last_transform_animation_(true), |
| 71 background_color_(0), | 71 background_color_(0), |
| 72 safe_opaque_background_color_(0), | 72 safe_opaque_background_color_(0), |
| 73 opacity_(1.0), | |
| 74 blend_mode_(SkXfermode::kSrcOver_Mode), | 73 blend_mode_(SkXfermode::kSrcOver_Mode), |
| 75 draw_blend_mode_(SkXfermode::kSrcOver_Mode), | 74 draw_blend_mode_(SkXfermode::kSrcOver_Mode), |
| 76 transform_tree_index_(-1), | 75 transform_tree_index_(-1), |
| 77 effect_tree_index_(-1), | 76 effect_tree_index_(-1), |
| 78 clip_tree_index_(-1), | 77 clip_tree_index_(-1), |
| 79 scroll_tree_index_(-1), | 78 scroll_tree_index_(-1), |
| 80 sorting_context_id_(0), | 79 sorting_context_id_(0), |
| 81 current_draw_mode_(DRAW_MODE_NONE), | 80 current_draw_mode_(DRAW_MODE_NONE), |
| 82 element_id_(0), | 81 element_id_(0), |
| 83 mutable_properties_(MutableProperty::kNone), | 82 mutable_properties_(MutableProperty::kNone), |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 // update render surfaces without rebuilding property trees. | 372 // update render surfaces without rebuilding property trees. |
| 374 if (layer->has_render_surface() != has_render_surface()) | 373 if (layer->has_render_surface() != has_render_surface()) |
| 375 layer->layer_tree_impl()->set_needs_update_draw_properties(); | 374 layer->layer_tree_impl()->set_needs_update_draw_properties(); |
| 376 layer->SetFilters(filters()); | 375 layer->SetFilters(filters()); |
| 377 layer->SetBackgroundFilters(background_filters()); | 376 layer->SetBackgroundFilters(background_filters()); |
| 378 layer->SetMasksToBounds(masks_to_bounds_); | 377 layer->SetMasksToBounds(masks_to_bounds_); |
| 379 layer->set_main_thread_scrolling_reasons(main_thread_scrolling_reasons_); | 378 layer->set_main_thread_scrolling_reasons(main_thread_scrolling_reasons_); |
| 380 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_); | 379 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_); |
| 381 layer->SetTouchEventHandlerRegion(touch_event_handler_region_); | 380 layer->SetTouchEventHandlerRegion(touch_event_handler_region_); |
| 382 layer->SetContentsOpaque(contents_opaque_); | 381 layer->SetContentsOpaque(contents_opaque_); |
| 383 layer->SetOpacity(opacity_); | |
| 384 layer->SetBlendMode(blend_mode_); | 382 layer->SetBlendMode(blend_mode_); |
| 385 layer->SetPosition(position_); | 383 layer->SetPosition(position_); |
| 386 layer->set_should_flatten_transform_from_property_tree( | 384 layer->set_should_flatten_transform_from_property_tree( |
| 387 should_flatten_transform_from_property_tree_); | 385 should_flatten_transform_from_property_tree_); |
| 388 layer->set_draw_blend_mode(draw_blend_mode_); | 386 layer->set_draw_blend_mode(draw_blend_mode_); |
| 389 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 387 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
| 390 layer->SetUseLocalTransformForBackfaceVisibility( | 388 layer->SetUseLocalTransformForBackfaceVisibility( |
| 391 use_local_transform_for_backface_visibility_); | 389 use_local_transform_for_backface_visibility_); |
| 392 layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility_); | 390 layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility_); |
| 393 layer->SetTransform(transform_); | 391 layer->SetTransform(transform_); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 const gfx::Transform& gfx_transform = transform(); | 458 const gfx::Transform& gfx_transform = transform(); |
| 461 double transform[16]; | 459 double transform[16]; |
| 462 gfx_transform.matrix().asColMajord(transform); | 460 gfx_transform.matrix().asColMajord(transform); |
| 463 list = new base::ListValue; | 461 list = new base::ListValue; |
| 464 for (int i = 0; i < 16; ++i) | 462 for (int i = 0; i < 16; ++i) |
| 465 list->AppendDouble(transform[i]); | 463 list->AppendDouble(transform[i]); |
| 466 result->Set("Transform", list); | 464 result->Set("Transform", list); |
| 467 | 465 |
| 468 result->SetBoolean("DrawsContent", draws_content_); | 466 result->SetBoolean("DrawsContent", draws_content_); |
| 469 result->SetBoolean("Is3dSorted", Is3dSorted()); | 467 result->SetBoolean("Is3dSorted", Is3dSorted()); |
| 470 result->SetDouble("OPACITY", opacity()); | 468 result->SetDouble("OPACITY", Opacity()); |
| 471 result->SetBoolean("ContentsOpaque", contents_opaque_); | 469 result->SetBoolean("ContentsOpaque", contents_opaque_); |
| 472 | 470 |
| 473 if (scrollable()) | 471 if (scrollable()) |
| 474 result->SetBoolean("Scrollable", true); | 472 result->SetBoolean("Scrollable", true); |
| 475 | 473 |
| 476 if (!touch_event_handler_region_.IsEmpty()) { | 474 if (!touch_event_handler_region_.IsEmpty()) { |
| 477 std::unique_ptr<base::Value> region = touch_event_handler_region_.AsValue(); | 475 std::unique_ptr<base::Value> region = touch_event_handler_region_.AsValue(); |
| 478 result->Set("TouchRegion", region.release()); | 476 result->Set("TouchRegion", region.release()); |
| 479 } | 477 } |
| 480 | 478 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 node->data.local_starting_animation_scale = 0.f; | 613 node->data.local_starting_animation_scale = 0.f; |
| 616 node->data.has_only_translation_animations = true; | 614 node->data.has_only_translation_animations = true; |
| 617 } | 615 } |
| 618 | 616 |
| 619 property_trees->transform_tree.set_needs_update(true); | 617 property_trees->transform_tree.set_needs_update(true); |
| 620 layer_tree_impl()->set_needs_update_draw_properties(); | 618 layer_tree_impl()->set_needs_update_draw_properties(); |
| 621 } | 619 } |
| 622 } | 620 } |
| 623 } | 621 } |
| 624 | 622 |
| 625 void LayerImpl::UpdatePropertyTreeOpacity() { | 623 void LayerImpl::UpdatePropertyTreeOpacity(float opacity) { |
| 626 PropertyTrees* property_trees = layer_tree_impl()->property_trees(); | 624 PropertyTrees* property_trees = layer_tree_impl()->property_trees(); |
| 627 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::EFFECT, id())) { | 625 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::EFFECT, id())) { |
| 628 // A LayerImpl's own current state is insufficient for determining whether | 626 // A LayerImpl's own current state is insufficient for determining whether |
| 629 // it owns an OpacityNode, since this depends on the state of the | 627 // it owns an OpacityNode, since this depends on the state of the |
| 630 // corresponding Layer at the time of the last commit. For example, an | 628 // corresponding Layer at the time of the last commit. For example, an |
| 631 // opacity animation might have been in progress at the time the last commit | 629 // opacity animation might have been in progress at the time the last commit |
| 632 // started, but might have finished since then on the compositor thread. | 630 // started, but might have finished since then on the compositor thread. |
| 633 EffectNode* node = property_trees->effect_tree.Node( | 631 EffectNode* node = property_trees->effect_tree.Node( |
| 634 property_trees->effect_id_to_index_map[id()]); | 632 property_trees->effect_id_to_index_map[id()]); |
| 635 node->data.opacity = opacity_; | 633 if (node->data.opacity == opacity) |
| 634 return; |
| 635 node->data.opacity = opacity; |
| 636 node->data.effect_changed = true; | 636 node->data.effect_changed = true; |
| 637 property_trees->changed = true; | 637 property_trees->changed = true; |
| 638 property_trees->effect_tree.set_needs_update(true); | 638 property_trees->effect_tree.set_needs_update(true); |
| 639 } | 639 } |
| 640 } | 640 } |
| 641 | 641 |
| 642 void LayerImpl::UpdatePropertyTreeForScrollingAndAnimationIfNeeded() { | 642 void LayerImpl::UpdatePropertyTreeForScrollingAndAnimationIfNeeded() { |
| 643 if (scrollable()) | 643 if (scrollable()) |
| 644 UpdatePropertyTreeScrollOffset(); | 644 UpdatePropertyTreeScrollOffset(); |
| 645 | 645 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 663 EffectNode* node = effect_tree.Node(effect_tree_index_); | 663 EffectNode* node = effect_tree.Node(effect_tree_index_); |
| 664 DCHECK(layer_tree_impl()->property_trees()->IsInIdToIndexMap( | 664 DCHECK(layer_tree_impl()->property_trees()->IsInIdToIndexMap( |
| 665 PropertyTrees::TreeType::EFFECT, id())); | 665 PropertyTrees::TreeType::EFFECT, id())); |
| 666 node->data.effect_changed = true; | 666 node->data.effect_changed = true; |
| 667 layer_tree_impl()->property_trees()->changed = true; | 667 layer_tree_impl()->property_trees()->changed = true; |
| 668 effect_tree.set_needs_update(true); | 668 effect_tree.set_needs_update(true); |
| 669 } | 669 } |
| 670 } | 670 } |
| 671 | 671 |
| 672 void LayerImpl::OnOpacityAnimated(float opacity) { | 672 void LayerImpl::OnOpacityAnimated(float opacity) { |
| 673 SetOpacity(opacity); | 673 UpdatePropertyTreeOpacity(opacity); |
| 674 UpdatePropertyTreeOpacity(); | |
| 675 SetNeedsPushProperties(); | 674 SetNeedsPushProperties(); |
| 676 layer_tree_impl()->set_needs_update_draw_properties(); | 675 layer_tree_impl()->set_needs_update_draw_properties(); |
| 677 layer_tree_impl()->AddToOpacityAnimationsMap(id(), opacity); | 676 layer_tree_impl()->AddToOpacityAnimationsMap(id(), opacity); |
| 678 } | 677 } |
| 679 | 678 |
| 680 void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { | 679 void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { |
| 681 gfx::Transform old_transform = transform_; | 680 gfx::Transform old_transform = transform_; |
| 682 SetTransform(transform); | 681 SetTransform(transform); |
| 683 UpdatePropertyTreeTransform(); | 682 UpdatePropertyTreeTransform(); |
| 684 was_ever_ready_since_last_transform_animation_ = false; | 683 was_ever_ready_since_last_transform_animation_ = false; |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 masks_to_bounds_ = masks_to_bounds; | 925 masks_to_bounds_ = masks_to_bounds; |
| 927 } | 926 } |
| 928 | 927 |
| 929 void LayerImpl::SetContentsOpaque(bool opaque) { | 928 void LayerImpl::SetContentsOpaque(bool opaque) { |
| 930 if (contents_opaque_ == opaque) | 929 if (contents_opaque_ == opaque) |
| 931 return; | 930 return; |
| 932 | 931 |
| 933 contents_opaque_ = opaque; | 932 contents_opaque_ = opaque; |
| 934 } | 933 } |
| 935 | 934 |
| 936 void LayerImpl::SetOpacity(float opacity) { | 935 float LayerImpl::Opacity() const { |
| 937 if (opacity_ == opacity) | 936 if (!layer_tree_impl()->property_trees()->IsInIdToIndexMap( |
| 938 return; | 937 PropertyTrees::TreeType::EFFECT, id())) |
| 939 | 938 return 1.f; |
| 940 opacity_ = opacity; | 939 EffectNode* node = |
| 940 layer_tree_impl()->property_trees()->effect_tree.Node(effect_tree_index_); |
| 941 return node->data.opacity; |
| 941 } | 942 } |
| 942 | 943 |
| 943 bool LayerImpl::OpacityIsAnimating() const { | 944 bool LayerImpl::OpacityIsAnimating() const { |
| 944 return layer_tree_impl_->IsAnimatingOpacityProperty(this); | 945 return layer_tree_impl_->IsAnimatingOpacityProperty(this); |
| 945 } | 946 } |
| 946 | 947 |
| 947 bool LayerImpl::HasPotentiallyRunningOpacityAnimation() const { | 948 bool LayerImpl::HasPotentiallyRunningOpacityAnimation() const { |
| 948 return layer_tree_impl_->HasPotentiallyRunningOpacityAnimation(this); | 949 return layer_tree_impl_->HasPotentiallyRunningOpacityAnimation(this); |
| 949 } | 950 } |
| 950 | 951 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1133 void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const { | 1134 void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const { |
| 1134 TracedValue::MakeDictIntoImplicitSnapshotWithCategory( | 1135 TracedValue::MakeDictIntoImplicitSnapshotWithCategory( |
| 1135 TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1136 TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 1136 state, | 1137 state, |
| 1137 "cc::LayerImpl", | 1138 "cc::LayerImpl", |
| 1138 LayerTypeAsString(), | 1139 LayerTypeAsString(), |
| 1139 this); | 1140 this); |
| 1140 state->SetInteger("layer_id", id()); | 1141 state->SetInteger("layer_id", id()); |
| 1141 MathUtil::AddToTracedValue("bounds", bounds_, state); | 1142 MathUtil::AddToTracedValue("bounds", bounds_, state); |
| 1142 | 1143 |
| 1143 state->SetDouble("opacity", opacity()); | 1144 state->SetDouble("opacity", Opacity()); |
| 1144 | 1145 |
| 1145 MathUtil::AddToTracedValue("position", position_, state); | 1146 MathUtil::AddToTracedValue("position", position_, state); |
| 1146 | 1147 |
| 1147 state->SetInteger("draws_content", DrawsContent()); | 1148 state->SetInteger("draws_content", DrawsContent()); |
| 1148 state->SetInteger("gpu_memory_usage", | 1149 state->SetInteger("gpu_memory_usage", |
| 1149 base::saturated_cast<int>(GPUMemoryUsageInBytes())); | 1150 base::saturated_cast<int>(GPUMemoryUsageInBytes())); |
| 1150 | 1151 |
| 1151 if (mutable_properties_ != MutableProperty::kNone) { | 1152 if (mutable_properties_ != MutableProperty::kNone) { |
| 1152 state->SetInteger("element_id", base::saturated_cast<int>(element_id_)); | 1153 state->SetInteger("element_id", base::saturated_cast<int>(element_id_)); |
| 1153 state->SetInteger("mutable_properties", mutable_properties_); | 1154 state->SetInteger("mutable_properties", mutable_properties_); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1340 .layer_transforms_should_scale_layer_contents) { | 1341 .layer_transforms_should_scale_layer_contents) { |
| 1341 return default_scale; | 1342 return default_scale; |
| 1342 } | 1343 } |
| 1343 | 1344 |
| 1344 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( | 1345 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( |
| 1345 ScreenSpaceTransform(), default_scale); | 1346 ScreenSpaceTransform(), default_scale); |
| 1346 return std::max(transform_scales.x(), transform_scales.y()); | 1347 return std::max(transform_scales.x(), transform_scales.y()); |
| 1347 } | 1348 } |
| 1348 | 1349 |
| 1349 } // namespace cc | 1350 } // namespace cc |
| OLD | NEW |