| 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 layer->use_local_transform_for_backface_visibility_ = | 333 layer->use_local_transform_for_backface_visibility_ = |
| 334 use_local_transform_for_backface_visibility_; | 334 use_local_transform_for_backface_visibility_; |
| 335 layer->should_check_backface_visibility_ = should_check_backface_visibility_; | 335 layer->should_check_backface_visibility_ = should_check_backface_visibility_; |
| 336 layer->draws_content_ = draws_content_; | 336 layer->draws_content_ = draws_content_; |
| 337 layer->non_fast_scrollable_region_ = non_fast_scrollable_region_; | 337 layer->non_fast_scrollable_region_ = non_fast_scrollable_region_; |
| 338 layer->touch_event_handler_region_ = touch_event_handler_region_; | 338 layer->touch_event_handler_region_ = touch_event_handler_region_; |
| 339 layer->background_color_ = background_color_; | 339 layer->background_color_ = background_color_; |
| 340 layer->safe_opaque_background_color_ = safe_opaque_background_color_; | 340 layer->safe_opaque_background_color_ = safe_opaque_background_color_; |
| 341 layer->draw_blend_mode_ = draw_blend_mode_; | 341 layer->draw_blend_mode_ = draw_blend_mode_; |
| 342 layer->position_ = position_; | 342 layer->position_ = position_; |
| 343 layer->transform_ = transform_; | |
| 344 layer->transform_tree_index_ = transform_tree_index_; | 343 layer->transform_tree_index_ = transform_tree_index_; |
| 345 layer->effect_tree_index_ = effect_tree_index_; | 344 layer->effect_tree_index_ = effect_tree_index_; |
| 346 layer->clip_tree_index_ = clip_tree_index_; | 345 layer->clip_tree_index_ = clip_tree_index_; |
| 347 layer->scroll_tree_index_ = scroll_tree_index_; | 346 layer->scroll_tree_index_ = scroll_tree_index_; |
| 348 layer->sorting_context_id_ = sorting_context_id_; | 347 layer->sorting_context_id_ = sorting_context_id_; |
| 349 layer->has_will_change_transform_hint_ = has_will_change_transform_hint_; | 348 layer->has_will_change_transform_hint_ = has_will_change_transform_hint_; |
| 350 | 349 |
| 351 if (layer_property_changed_) { | 350 if (layer_property_changed_) { |
| 352 layer->layer_tree_impl()->set_needs_update_draw_properties(); | 351 layer->layer_tree_impl()->set_needs_update_draw_properties(); |
| 353 layer->layer_property_changed_ = true; | 352 layer->layer_property_changed_ = true; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 base::ListValue* list = new base::ListValue; | 404 base::ListValue* list = new base::ListValue; |
| 406 list->AppendInteger(bounds().width()); | 405 list->AppendInteger(bounds().width()); |
| 407 list->AppendInteger(bounds().height()); | 406 list->AppendInteger(bounds().height()); |
| 408 result->Set("Bounds", list); | 407 result->Set("Bounds", list); |
| 409 | 408 |
| 410 list = new base::ListValue; | 409 list = new base::ListValue; |
| 411 list->AppendDouble(position_.x()); | 410 list->AppendDouble(position_.x()); |
| 412 list->AppendDouble(position_.y()); | 411 list->AppendDouble(position_.y()); |
| 413 result->Set("Position", list); | 412 result->Set("Position", list); |
| 414 | 413 |
| 415 const gfx::Transform& gfx_transform = transform(); | 414 const gfx::Transform& gfx_transform = test_properties()->transform; |
| 416 double transform[16]; | 415 double transform[16]; |
| 417 gfx_transform.matrix().asColMajord(transform); | 416 gfx_transform.matrix().asColMajord(transform); |
| 418 list = new base::ListValue; | 417 list = new base::ListValue; |
| 419 for (int i = 0; i < 16; ++i) | 418 for (int i = 0; i < 16; ++i) |
| 420 list->AppendDouble(transform[i]); | 419 list->AppendDouble(transform[i]); |
| 421 result->Set("Transform", list); | 420 result->Set("Transform", list); |
| 422 | 421 |
| 423 result->SetBoolean("DrawsContent", draws_content_); | 422 result->SetBoolean("DrawsContent", draws_content_); |
| 424 result->SetBoolean("Is3dSorted", Is3dSorted()); | 423 result->SetBoolean("Is3dSorted", Is3dSorted()); |
| 425 result->SetDouble("OPACITY", Opacity()); | 424 result->SetDouble("OPACITY", Opacity()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 render_surface_->ResetPropertyChangedFlag(); | 492 render_surface_->ResetPropertyChangedFlag(); |
| 494 } | 493 } |
| 495 | 494 |
| 496 int LayerImpl::num_copy_requests_in_target_subtree() { | 495 int LayerImpl::num_copy_requests_in_target_subtree() { |
| 497 return layer_tree_impl() | 496 return layer_tree_impl() |
| 498 ->property_trees() | 497 ->property_trees() |
| 499 ->effect_tree.Node(effect_tree_index()) | 498 ->effect_tree.Node(effect_tree_index()) |
| 500 ->num_copy_requests_in_subtree; | 499 ->num_copy_requests_in_subtree; |
| 501 } | 500 } |
| 502 | 501 |
| 503 void LayerImpl::UpdatePropertyTreeTransform() { | 502 void LayerImpl::UpdatePropertyTreeTransform(const gfx::Transform& transform) { |
| 504 PropertyTrees* property_trees = layer_tree_impl()->property_trees(); | 503 PropertyTrees* property_trees = layer_tree_impl()->property_trees(); |
| 505 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, | 504 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, |
| 506 id())) { | 505 id())) { |
| 507 // A LayerImpl's own current state is insufficient for determining whether | 506 // A LayerImpl's own current state is insufficient for determining whether |
| 508 // it owns a TransformNode, since this depends on the state of the | 507 // it owns a TransformNode, since this depends on the state of the |
| 509 // corresponding Layer at the time of the last commit. For example, a | 508 // corresponding Layer at the time of the last commit. For example, a |
| 510 // transform animation might have been in progress at the time the last | 509 // transform animation might have been in progress at the time the last |
| 511 // commit started, but might have finished since then on the compositor | 510 // commit started, but might have finished since then on the compositor |
| 512 // thread. | 511 // thread. |
| 513 TransformNode* node = property_trees->transform_tree.Node( | 512 TransformNode* node = property_trees->transform_tree.Node( |
| 514 property_trees->transform_id_to_index_map[id()]); | 513 property_trees->transform_id_to_index_map[id()]); |
| 515 if (node->local != transform_) { | 514 if (node->local != transform) { |
| 516 node->local = transform_; | 515 node->local = transform; |
| 517 node->needs_local_transform_update = true; | 516 node->needs_local_transform_update = true; |
| 518 node->transform_changed = true; | 517 node->transform_changed = true; |
| 519 property_trees->changed = true; | 518 property_trees->changed = true; |
| 520 property_trees->transform_tree.set_needs_update(true); | 519 property_trees->transform_tree.set_needs_update(true); |
| 520 layer_tree_impl()->set_needs_update_draw_properties(); |
| 521 // TODO(ajuma): The current criteria for creating clip nodes means that | 521 // TODO(ajuma): The current criteria for creating clip nodes means that |
| 522 // property trees may need to be rebuilt when the new transform isn't | 522 // property trees may need to be rebuilt when the new transform isn't |
| 523 // axis-aligned wrt the old transform (see Layer::SetTransform). Since | 523 // axis-aligned wrt the old transform (see Layer::SetTransform). Since |
| 524 // rebuilding property trees every frame of a transform animation is | 524 // rebuilding property trees every frame of a transform animation is |
| 525 // something we should try to avoid, change property tree-building so that | 525 // something we should try to avoid, change property tree-building so that |
| 526 // it doesn't depend on axis aliginment. | 526 // it doesn't depend on axis aliginment. |
| 527 } | 527 } |
| 528 } | 528 } |
| 529 } | 529 } |
| 530 | 530 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 } | 607 } |
| 608 | 608 |
| 609 void LayerImpl::OnOpacityAnimated(float opacity) { | 609 void LayerImpl::OnOpacityAnimated(float opacity) { |
| 610 UpdatePropertyTreeOpacity(opacity); | 610 UpdatePropertyTreeOpacity(opacity); |
| 611 SetNeedsPushProperties(); | 611 SetNeedsPushProperties(); |
| 612 layer_tree_impl()->set_needs_update_draw_properties(); | 612 layer_tree_impl()->set_needs_update_draw_properties(); |
| 613 layer_tree_impl()->AddToOpacityAnimationsMap(id(), opacity); | 613 layer_tree_impl()->AddToOpacityAnimationsMap(id(), opacity); |
| 614 } | 614 } |
| 615 | 615 |
| 616 void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { | 616 void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { |
| 617 gfx::Transform old_transform = transform_; | 617 UpdatePropertyTreeTransform(transform); |
| 618 SetTransform(transform); | |
| 619 UpdatePropertyTreeTransform(); | |
| 620 was_ever_ready_since_last_transform_animation_ = false; | 618 was_ever_ready_since_last_transform_animation_ = false; |
| 621 layer_tree_impl()->AddToTransformAnimationsMap(id(), transform); | 619 layer_tree_impl()->AddToTransformAnimationsMap(id(), transform); |
| 622 if (old_transform != transform) { | |
| 623 SetNeedsPushProperties(); | |
| 624 layer_tree_impl()->set_needs_update_draw_properties(); | |
| 625 } | |
| 626 } | 620 } |
| 627 | 621 |
| 628 void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { | 622 void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { |
| 629 // Only layers in the active tree should need to do anything here, since | 623 // Only layers in the active tree should need to do anything here, since |
| 630 // layers in the pending tree will find out about these changes as a | 624 // layers in the pending tree will find out about these changes as a |
| 631 // result of the shared SyncedProperty. | 625 // result of the shared SyncedProperty. |
| 632 if (!IsActive()) | 626 if (!IsActive()) |
| 633 return; | 627 return; |
| 634 | 628 |
| 635 SetCurrentScrollOffset(ClampScrollOffsetToLimits(scroll_offset)); | 629 SetCurrentScrollOffset(ClampScrollOffsetToLimits(scroll_offset)); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 | 809 |
| 816 float LayerImpl::Opacity() const { | 810 float LayerImpl::Opacity() const { |
| 817 PropertyTrees* property_trees = layer_tree_impl()->property_trees(); | 811 PropertyTrees* property_trees = layer_tree_impl()->property_trees(); |
| 818 if (!property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::EFFECT, id())) | 812 if (!property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::EFFECT, id())) |
| 819 return 1.f; | 813 return 1.f; |
| 820 EffectNode* node = property_trees->effect_tree.Node( | 814 EffectNode* node = property_trees->effect_tree.Node( |
| 821 property_trees->effect_id_to_index_map[id()]); | 815 property_trees->effect_id_to_index_map[id()]); |
| 822 return node->opacity; | 816 return node->opacity; |
| 823 } | 817 } |
| 824 | 818 |
| 819 const gfx::Transform& LayerImpl::Transform() const { |
| 820 PropertyTrees* property_trees = layer_tree_impl()->property_trees(); |
| 821 DCHECK(property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, |
| 822 id())); |
| 823 TransformNode* node = property_trees->transform_tree.Node( |
| 824 property_trees->transform_id_to_index_map[id()]); |
| 825 return node->local; |
| 826 } |
| 827 |
| 825 void LayerImpl::SetElementId(ElementId element_id) { | 828 void LayerImpl::SetElementId(ElementId element_id) { |
| 826 if (element_id == element_id_) | 829 if (element_id == element_id_) |
| 827 return; | 830 return; |
| 828 | 831 |
| 829 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), | 832 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), |
| 830 "LayerImpl::SetElementId", "element", | 833 "LayerImpl::SetElementId", "element", |
| 831 element_id.AsValue().release()); | 834 element_id.AsValue().release()); |
| 832 | 835 |
| 833 layer_tree_impl_->RemoveFromElementMap(this); | 836 layer_tree_impl_->RemoveFromElementMap(this); |
| 834 element_id_ = element_id; | 837 element_id_ = element_id; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 850 } | 853 } |
| 851 | 854 |
| 852 void LayerImpl::SetPosition(const gfx::PointF& position) { | 855 void LayerImpl::SetPosition(const gfx::PointF& position) { |
| 853 position_ = position; | 856 position_ = position; |
| 854 } | 857 } |
| 855 | 858 |
| 856 void LayerImpl::Set3dSortingContextId(int id) { | 859 void LayerImpl::Set3dSortingContextId(int id) { |
| 857 sorting_context_id_ = id; | 860 sorting_context_id_ = id; |
| 858 } | 861 } |
| 859 | 862 |
| 860 void LayerImpl::SetTransform(const gfx::Transform& transform) { | |
| 861 transform_ = transform; | |
| 862 } | |
| 863 | |
| 864 bool LayerImpl::TransformIsAnimating() const { | 863 bool LayerImpl::TransformIsAnimating() const { |
| 865 return GetAnimationHost()->IsAnimatingTransformProperty( | 864 return GetAnimationHost()->IsAnimatingTransformProperty( |
| 866 element_id(), GetElementTypeForAnimation()); | 865 element_id(), GetElementTypeForAnimation()); |
| 867 } | 866 } |
| 868 | 867 |
| 869 bool LayerImpl::HasPotentiallyRunningTransformAnimation() const { | 868 bool LayerImpl::HasPotentiallyRunningTransformAnimation() const { |
| 870 return GetAnimationHost()->HasPotentiallyRunningTransformAnimation( | 869 return GetAnimationHost()->HasPotentiallyRunningTransformAnimation( |
| 871 element_id(), GetElementTypeForAnimation()); | 870 element_id(), GetElementTypeForAnimation()); |
| 872 } | 871 } |
| 873 | 872 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 base::saturated_cast<int>(GPUMemoryUsageInBytes())); | 1005 base::saturated_cast<int>(GPUMemoryUsageInBytes())); |
| 1007 | 1006 |
| 1008 if (element_id_) | 1007 if (element_id_) |
| 1009 element_id_.AddToTracedValue(state); | 1008 element_id_.AddToTracedValue(state); |
| 1010 | 1009 |
| 1011 if (mutable_properties_ != MutableProperty::kNone) | 1010 if (mutable_properties_ != MutableProperty::kNone) |
| 1012 state->SetInteger("mutable_properties", mutable_properties_); | 1011 state->SetInteger("mutable_properties", mutable_properties_); |
| 1013 | 1012 |
| 1014 MathUtil::AddToTracedValue("scroll_offset", CurrentScrollOffset(), state); | 1013 MathUtil::AddToTracedValue("scroll_offset", CurrentScrollOffset(), state); |
| 1015 | 1014 |
| 1016 if (!transform().IsIdentity()) | 1015 if (!ScreenSpaceTransform().IsIdentity()) |
| 1017 MathUtil::AddToTracedValue("transform", transform(), state); | 1016 MathUtil::AddToTracedValue("screen_space_transform", ScreenSpaceTransform(), |
| 1017 state); |
| 1018 | 1018 |
| 1019 bool clipped; | 1019 bool clipped; |
| 1020 gfx::QuadF layer_quad = | 1020 gfx::QuadF layer_quad = |
| 1021 MathUtil::MapQuad(ScreenSpaceTransform(), | 1021 MathUtil::MapQuad(ScreenSpaceTransform(), |
| 1022 gfx::QuadF(gfx::RectF(gfx::Rect(bounds()))), &clipped); | 1022 gfx::QuadF(gfx::RectF(gfx::Rect(bounds()))), &clipped); |
| 1023 MathUtil::AddToTracedValue("layer_quad", layer_quad, state); | 1023 MathUtil::AddToTracedValue("layer_quad", layer_quad, state); |
| 1024 if (!touch_event_handler_region_.IsEmpty()) { | 1024 if (!touch_event_handler_region_.IsEmpty()) { |
| 1025 state->BeginArray("touch_event_handler_region"); | 1025 state->BeginArray("touch_event_handler_region"); |
| 1026 touch_event_handler_region_.AsValueInto(state); | 1026 touch_event_handler_region_.AsValueInto(state); |
| 1027 state->EndArray(); | 1027 state->EndArray(); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 .layer_transforms_should_scale_layer_contents) { | 1196 .layer_transforms_should_scale_layer_contents) { |
| 1197 return default_scale; | 1197 return default_scale; |
| 1198 } | 1198 } |
| 1199 | 1199 |
| 1200 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( | 1200 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( |
| 1201 ScreenSpaceTransform(), default_scale); | 1201 ScreenSpaceTransform(), default_scale); |
| 1202 return std::max(transform_scales.x(), transform_scales.y()); | 1202 return std::max(transform_scales.x(), transform_scales.y()); |
| 1203 } | 1203 } |
| 1204 | 1204 |
| 1205 } // namespace cc | 1205 } // namespace cc |
| OLD | NEW |