| 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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 // update render surfaces without rebuilding property trees. | 425 // update render surfaces without rebuilding property trees. |
| 427 if (layer->has_render_surface() != has_render_surface()) | 426 if (layer->has_render_surface() != has_render_surface()) |
| 428 layer->layer_tree_impl()->set_needs_update_draw_properties(); | 427 layer->layer_tree_impl()->set_needs_update_draw_properties(); |
| 429 layer->SetFilters(filters()); | 428 layer->SetFilters(filters()); |
| 430 layer->SetBackgroundFilters(background_filters()); | 429 layer->SetBackgroundFilters(background_filters()); |
| 431 layer->SetMasksToBounds(masks_to_bounds_); | 430 layer->SetMasksToBounds(masks_to_bounds_); |
| 432 layer->set_main_thread_scrolling_reasons(main_thread_scrolling_reasons_); | 431 layer->set_main_thread_scrolling_reasons(main_thread_scrolling_reasons_); |
| 433 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_); | 432 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_); |
| 434 layer->SetTouchEventHandlerRegion(touch_event_handler_region_); | 433 layer->SetTouchEventHandlerRegion(touch_event_handler_region_); |
| 435 layer->SetContentsOpaque(contents_opaque_); | 434 layer->SetContentsOpaque(contents_opaque_); |
| 436 layer->SetOpacity(opacity_); | |
| 437 layer->SetBlendMode(blend_mode_); | 435 layer->SetBlendMode(blend_mode_); |
| 438 layer->SetPosition(position_); | 436 layer->SetPosition(position_); |
| 439 layer->set_should_flatten_transform_from_property_tree( | 437 layer->set_should_flatten_transform_from_property_tree( |
| 440 should_flatten_transform_from_property_tree_); | 438 should_flatten_transform_from_property_tree_); |
| 441 layer->set_draw_blend_mode(draw_blend_mode_); | 439 layer->set_draw_blend_mode(draw_blend_mode_); |
| 442 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 440 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
| 443 layer->SetUseLocalTransformForBackfaceVisibility( | 441 layer->SetUseLocalTransformForBackfaceVisibility( |
| 444 use_local_transform_for_backface_visibility_); | 442 use_local_transform_for_backface_visibility_); |
| 445 layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility_); | 443 layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility_); |
| 446 layer->SetTransform(transform_); | 444 layer->SetTransform(transform_); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 const gfx::Transform& gfx_transform = transform(); | 513 const gfx::Transform& gfx_transform = transform(); |
| 516 double transform[16]; | 514 double transform[16]; |
| 517 gfx_transform.matrix().asColMajord(transform); | 515 gfx_transform.matrix().asColMajord(transform); |
| 518 list = new base::ListValue; | 516 list = new base::ListValue; |
| 519 for (int i = 0; i < 16; ++i) | 517 for (int i = 0; i < 16; ++i) |
| 520 list->AppendDouble(transform[i]); | 518 list->AppendDouble(transform[i]); |
| 521 result->Set("Transform", list); | 519 result->Set("Transform", list); |
| 522 | 520 |
| 523 result->SetBoolean("DrawsContent", draws_content_); | 521 result->SetBoolean("DrawsContent", draws_content_); |
| 524 result->SetBoolean("Is3dSorted", Is3dSorted()); | 522 result->SetBoolean("Is3dSorted", Is3dSorted()); |
| 525 result->SetDouble("OPACITY", opacity()); | 523 result->SetDouble("OPACITY", Opacity()); |
| 526 result->SetBoolean("ContentsOpaque", contents_opaque_); | 524 result->SetBoolean("ContentsOpaque", contents_opaque_); |
| 527 | 525 |
| 528 if (scrollable()) | 526 if (scrollable()) |
| 529 result->SetBoolean("Scrollable", true); | 527 result->SetBoolean("Scrollable", true); |
| 530 | 528 |
| 531 if (!touch_event_handler_region_.IsEmpty()) { | 529 if (!touch_event_handler_region_.IsEmpty()) { |
| 532 std::unique_ptr<base::Value> region = touch_event_handler_region_.AsValue(); | 530 std::unique_ptr<base::Value> region = touch_event_handler_region_.AsValue(); |
| 533 result->Set("TouchRegion", region.release()); | 531 result->Set("TouchRegion", region.release()); |
| 534 } | 532 } |
| 535 | 533 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 node->data.local_starting_animation_scale = 0.f; | 668 node->data.local_starting_animation_scale = 0.f; |
| 671 node->data.has_only_translation_animations = true; | 669 node->data.has_only_translation_animations = true; |
| 672 } | 670 } |
| 673 | 671 |
| 674 property_trees->transform_tree.set_needs_update(true); | 672 property_trees->transform_tree.set_needs_update(true); |
| 675 layer_tree_impl()->set_needs_update_draw_properties(); | 673 layer_tree_impl()->set_needs_update_draw_properties(); |
| 676 } | 674 } |
| 677 } | 675 } |
| 678 } | 676 } |
| 679 | 677 |
| 680 void LayerImpl::UpdatePropertyTreeOpacity() { | 678 void LayerImpl::UpdatePropertyTreeOpacity(float opacity) { |
| 681 PropertyTrees* property_trees = layer_tree_impl()->property_trees(); | 679 PropertyTrees* property_trees = layer_tree_impl()->property_trees(); |
| 682 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::EFFECT, id())) { | 680 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::EFFECT, id())) { |
| 683 // A LayerImpl's own current state is insufficient for determining whether | 681 // A LayerImpl's own current state is insufficient for determining whether |
| 684 // it owns an OpacityNode, since this depends on the state of the | 682 // it owns an OpacityNode, since this depends on the state of the |
| 685 // corresponding Layer at the time of the last commit. For example, an | 683 // corresponding Layer at the time of the last commit. For example, an |
| 686 // opacity animation might have been in progress at the time the last commit | 684 // opacity animation might have been in progress at the time the last commit |
| 687 // started, but might have finished since then on the compositor thread. | 685 // started, but might have finished since then on the compositor thread. |
| 688 EffectNode* node = property_trees->effect_tree.Node( | 686 EffectNode* node = property_trees->effect_tree.Node( |
| 689 property_trees->effect_id_to_index_map[id()]); | 687 property_trees->effect_id_to_index_map[id()]); |
| 690 node->data.opacity = opacity_; | 688 if (node->data.opacity == opacity) |
| 689 return; |
| 690 node->data.opacity = opacity; |
| 691 node->data.effect_changed = true; | 691 node->data.effect_changed = true; |
| 692 property_trees->changed = true; | 692 property_trees->changed = true; |
| 693 property_trees->effect_tree.set_needs_update(true); | 693 property_trees->effect_tree.set_needs_update(true); |
| 694 } | 694 } |
| 695 } | 695 } |
| 696 | 696 |
| 697 void LayerImpl::UpdatePropertyTreeForScrollingAndAnimationIfNeeded() { | 697 void LayerImpl::UpdatePropertyTreeForScrollingAndAnimationIfNeeded() { |
| 698 if (scrollable()) | 698 if (scrollable()) |
| 699 UpdatePropertyTreeScrollOffset(); | 699 UpdatePropertyTreeScrollOffset(); |
| 700 | 700 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 718 EffectNode* node = effect_tree.Node(effect_tree_index_); | 718 EffectNode* node = effect_tree.Node(effect_tree_index_); |
| 719 DCHECK(layer_tree_impl()->property_trees()->IsInIdToIndexMap( | 719 DCHECK(layer_tree_impl()->property_trees()->IsInIdToIndexMap( |
| 720 PropertyTrees::TreeType::EFFECT, id())); | 720 PropertyTrees::TreeType::EFFECT, id())); |
| 721 node->data.effect_changed = true; | 721 node->data.effect_changed = true; |
| 722 layer_tree_impl()->property_trees()->changed = true; | 722 layer_tree_impl()->property_trees()->changed = true; |
| 723 effect_tree.set_needs_update(true); | 723 effect_tree.set_needs_update(true); |
| 724 } | 724 } |
| 725 } | 725 } |
| 726 | 726 |
| 727 void LayerImpl::OnOpacityAnimated(float opacity) { | 727 void LayerImpl::OnOpacityAnimated(float opacity) { |
| 728 SetOpacity(opacity); | 728 UpdatePropertyTreeOpacity(opacity); |
| 729 UpdatePropertyTreeOpacity(); | |
| 730 SetNeedsPushProperties(); | 729 SetNeedsPushProperties(); |
| 731 layer_tree_impl()->set_needs_update_draw_properties(); | 730 layer_tree_impl()->set_needs_update_draw_properties(); |
| 732 layer_tree_impl()->AddToOpacityAnimationsMap(id(), opacity); | 731 layer_tree_impl()->AddToOpacityAnimationsMap(id(), opacity); |
| 733 } | 732 } |
| 734 | 733 |
| 735 void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { | 734 void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { |
| 736 gfx::Transform old_transform = transform_; | 735 gfx::Transform old_transform = transform_; |
| 737 SetTransform(transform); | 736 SetTransform(transform); |
| 738 UpdatePropertyTreeTransform(); | 737 UpdatePropertyTreeTransform(); |
| 739 was_ever_ready_since_last_transform_animation_ = false; | 738 was_ever_ready_since_last_transform_animation_ = false; |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 masks_to_bounds_ = masks_to_bounds; | 980 masks_to_bounds_ = masks_to_bounds; |
| 982 } | 981 } |
| 983 | 982 |
| 984 void LayerImpl::SetContentsOpaque(bool opaque) { | 983 void LayerImpl::SetContentsOpaque(bool opaque) { |
| 985 if (contents_opaque_ == opaque) | 984 if (contents_opaque_ == opaque) |
| 986 return; | 985 return; |
| 987 | 986 |
| 988 contents_opaque_ = opaque; | 987 contents_opaque_ = opaque; |
| 989 } | 988 } |
| 990 | 989 |
| 991 void LayerImpl::SetOpacity(float opacity) { | 990 float LayerImpl::Opacity() const { |
| 992 if (opacity_ == opacity) | 991 if (!layer_tree_impl()->property_trees()->IsInIdToIndexMap( |
| 993 return; | 992 PropertyTrees::TreeType::EFFECT, id())) |
| 994 | 993 return 1.f; |
| 995 opacity_ = opacity; | 994 EffectNode* node = |
| 995 layer_tree_impl()->property_trees()->effect_tree.Node(effect_tree_index_); |
| 996 return node->data.opacity; |
| 996 } | 997 } |
| 997 | 998 |
| 998 bool LayerImpl::OpacityIsAnimating() const { | 999 bool LayerImpl::OpacityIsAnimating() const { |
| 999 return layer_tree_impl_->IsAnimatingOpacityProperty(this); | 1000 return layer_tree_impl_->IsAnimatingOpacityProperty(this); |
| 1000 } | 1001 } |
| 1001 | 1002 |
| 1002 bool LayerImpl::HasPotentiallyRunningOpacityAnimation() const { | 1003 bool LayerImpl::HasPotentiallyRunningOpacityAnimation() const { |
| 1003 return layer_tree_impl_->HasPotentiallyRunningOpacityAnimation(this); | 1004 return layer_tree_impl_->HasPotentiallyRunningOpacityAnimation(this); |
| 1004 } | 1005 } |
| 1005 | 1006 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const { | 1189 void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const { |
| 1189 TracedValue::MakeDictIntoImplicitSnapshotWithCategory( | 1190 TracedValue::MakeDictIntoImplicitSnapshotWithCategory( |
| 1190 TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1191 TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 1191 state, | 1192 state, |
| 1192 "cc::LayerImpl", | 1193 "cc::LayerImpl", |
| 1193 LayerTypeAsString(), | 1194 LayerTypeAsString(), |
| 1194 this); | 1195 this); |
| 1195 state->SetInteger("layer_id", id()); | 1196 state->SetInteger("layer_id", id()); |
| 1196 MathUtil::AddToTracedValue("bounds", bounds_, state); | 1197 MathUtil::AddToTracedValue("bounds", bounds_, state); |
| 1197 | 1198 |
| 1198 state->SetDouble("opacity", opacity()); | 1199 state->SetDouble("opacity", Opacity()); |
| 1199 | 1200 |
| 1200 MathUtil::AddToTracedValue("position", position_, state); | 1201 MathUtil::AddToTracedValue("position", position_, state); |
| 1201 | 1202 |
| 1202 state->SetInteger("draws_content", DrawsContent()); | 1203 state->SetInteger("draws_content", DrawsContent()); |
| 1203 state->SetInteger("gpu_memory_usage", | 1204 state->SetInteger("gpu_memory_usage", |
| 1204 base::saturated_cast<int>(GPUMemoryUsageInBytes())); | 1205 base::saturated_cast<int>(GPUMemoryUsageInBytes())); |
| 1205 | 1206 |
| 1206 if (mutable_properties_ != MutableProperty::kNone) { | 1207 if (mutable_properties_ != MutableProperty::kNone) { |
| 1207 state->SetInteger("element_id", base::saturated_cast<int>(element_id_)); | 1208 state->SetInteger("element_id", base::saturated_cast<int>(element_id_)); |
| 1208 state->SetInteger("mutable_properties", mutable_properties_); | 1209 state->SetInteger("mutable_properties", mutable_properties_); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1395 .layer_transforms_should_scale_layer_contents) { | 1396 .layer_transforms_should_scale_layer_contents) { |
| 1396 return default_scale; | 1397 return default_scale; |
| 1397 } | 1398 } |
| 1398 | 1399 |
| 1399 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( | 1400 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( |
| 1400 DrawTransform(), default_scale); | 1401 DrawTransform(), default_scale); |
| 1401 return std::max(transform_scales.x(), transform_scales.y()); | 1402 return std::max(transform_scales.x(), transform_scales.y()); |
| 1402 } | 1403 } |
| 1403 | 1404 |
| 1404 } // namespace cc | 1405 } // namespace cc |
| OLD | NEW |