| 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(); | |
| 416 double transform[16]; | |
| 417 gfx_transform.matrix().asColMajord(transform); | |
| 418 list = new base::ListValue; | |
| 419 for (int i = 0; i < 16; ++i) | |
| 420 list->AppendDouble(transform[i]); | |
| 421 result->Set("Transform", list); | |
| 422 | |
| 423 result->SetBoolean("DrawsContent", draws_content_); | 414 result->SetBoolean("DrawsContent", draws_content_); |
| 424 result->SetBoolean("Is3dSorted", Is3dSorted()); | 415 result->SetBoolean("Is3dSorted", Is3dSorted()); |
| 425 result->SetDouble("OPACITY", Opacity()); | 416 result->SetDouble("OPACITY", Opacity()); |
| 426 result->SetBoolean("ContentsOpaque", contents_opaque_); | 417 result->SetBoolean("ContentsOpaque", contents_opaque_); |
| 427 | 418 |
| 428 if (scrollable()) | 419 if (scrollable()) |
| 429 result->SetBoolean("Scrollable", true); | 420 result->SetBoolean("Scrollable", true); |
| 430 | 421 |
| 431 if (!touch_event_handler_region_.IsEmpty()) { | 422 if (!touch_event_handler_region_.IsEmpty()) { |
| 432 std::unique_ptr<base::Value> region = touch_event_handler_region_.AsValue(); | 423 std::unique_ptr<base::Value> region = touch_event_handler_region_.AsValue(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 render_surface_->ResetPropertyChangedFlag(); | 484 render_surface_->ResetPropertyChangedFlag(); |
| 494 } | 485 } |
| 495 | 486 |
| 496 int LayerImpl::num_copy_requests_in_target_subtree() { | 487 int LayerImpl::num_copy_requests_in_target_subtree() { |
| 497 return layer_tree_impl() | 488 return layer_tree_impl() |
| 498 ->property_trees() | 489 ->property_trees() |
| 499 ->effect_tree.Node(effect_tree_index()) | 490 ->effect_tree.Node(effect_tree_index()) |
| 500 ->num_copy_requests_in_subtree; | 491 ->num_copy_requests_in_subtree; |
| 501 } | 492 } |
| 502 | 493 |
| 503 void LayerImpl::UpdatePropertyTreeTransform() { | 494 void LayerImpl::UpdatePropertyTreeTransform(const gfx::Transform& transform) { |
| 504 PropertyTrees* property_trees = layer_tree_impl()->property_trees(); | 495 PropertyTrees* property_trees = layer_tree_impl()->property_trees(); |
| 505 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, | 496 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, |
| 506 id())) { | 497 id())) { |
| 507 // A LayerImpl's own current state is insufficient for determining whether | 498 // A LayerImpl's own current state is insufficient for determining whether |
| 508 // it owns a TransformNode, since this depends on the state of the | 499 // 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 | 500 // 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 | 501 // transform animation might have been in progress at the time the last |
| 511 // commit started, but might have finished since then on the compositor | 502 // commit started, but might have finished since then on the compositor |
| 512 // thread. | 503 // thread. |
| 513 TransformNode* node = property_trees->transform_tree.Node( | 504 TransformNode* node = property_trees->transform_tree.Node( |
| 514 property_trees->transform_id_to_index_map[id()]); | 505 property_trees->transform_id_to_index_map[id()]); |
| 515 if (node->local != transform_) { | 506 if (node->local != transform) { |
| 516 node->local = transform_; | 507 node->local = transform; |
| 517 node->needs_local_transform_update = true; | 508 node->needs_local_transform_update = true; |
| 518 node->transform_changed = true; | 509 node->transform_changed = true; |
| 519 property_trees->changed = true; | 510 property_trees->changed = true; |
| 520 property_trees->transform_tree.set_needs_update(true); | 511 property_trees->transform_tree.set_needs_update(true); |
| 512 layer_tree_impl()->set_needs_update_draw_properties(); |
| 521 // TODO(ajuma): The current criteria for creating clip nodes means that | 513 // 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 | 514 // property trees may need to be rebuilt when the new transform isn't |
| 523 // axis-aligned wrt the old transform (see Layer::SetTransform). Since | 515 // axis-aligned wrt the old transform (see Layer::SetTransform). Since |
| 524 // rebuilding property trees every frame of a transform animation is | 516 // rebuilding property trees every frame of a transform animation is |
| 525 // something we should try to avoid, change property tree-building so that | 517 // something we should try to avoid, change property tree-building so that |
| 526 // it doesn't depend on axis aliginment. | 518 // it doesn't depend on axis aliginment. |
| 527 } | 519 } |
| 528 } | 520 } |
| 529 } | 521 } |
| 530 | 522 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 } | 599 } |
| 608 | 600 |
| 609 void LayerImpl::OnOpacityAnimated(float opacity) { | 601 void LayerImpl::OnOpacityAnimated(float opacity) { |
| 610 UpdatePropertyTreeOpacity(opacity); | 602 UpdatePropertyTreeOpacity(opacity); |
| 611 SetNeedsPushProperties(); | 603 SetNeedsPushProperties(); |
| 612 layer_tree_impl()->set_needs_update_draw_properties(); | 604 layer_tree_impl()->set_needs_update_draw_properties(); |
| 613 layer_tree_impl()->AddToOpacityAnimationsMap(id(), opacity); | 605 layer_tree_impl()->AddToOpacityAnimationsMap(id(), opacity); |
| 614 } | 606 } |
| 615 | 607 |
| 616 void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { | 608 void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { |
| 617 gfx::Transform old_transform = transform_; | 609 UpdatePropertyTreeTransform(transform); |
| 618 SetTransform(transform); | |
| 619 UpdatePropertyTreeTransform(); | |
| 620 was_ever_ready_since_last_transform_animation_ = false; | 610 was_ever_ready_since_last_transform_animation_ = false; |
| 621 layer_tree_impl()->AddToTransformAnimationsMap(id(), transform); | 611 layer_tree_impl()->AddToTransformAnimationsMap(id(), transform); |
| 622 if (old_transform != transform) { | |
| 623 SetNeedsPushProperties(); | |
| 624 layer_tree_impl()->set_needs_update_draw_properties(); | |
| 625 } | |
| 626 } | 612 } |
| 627 | 613 |
| 628 void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { | 614 void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { |
| 629 // Only layers in the active tree should need to do anything here, since | 615 // 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 | 616 // layers in the pending tree will find out about these changes as a |
| 631 // result of the shared SyncedProperty. | 617 // result of the shared SyncedProperty. |
| 632 if (!IsActive()) | 618 if (!IsActive()) |
| 633 return; | 619 return; |
| 634 | 620 |
| 635 SetCurrentScrollOffset(ClampScrollOffsetToLimits(scroll_offset)); | 621 SetCurrentScrollOffset(ClampScrollOffsetToLimits(scroll_offset)); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 | 801 |
| 816 float LayerImpl::Opacity() const { | 802 float LayerImpl::Opacity() const { |
| 817 PropertyTrees* property_trees = layer_tree_impl()->property_trees(); | 803 PropertyTrees* property_trees = layer_tree_impl()->property_trees(); |
| 818 if (!property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::EFFECT, id())) | 804 if (!property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::EFFECT, id())) |
| 819 return 1.f; | 805 return 1.f; |
| 820 EffectNode* node = property_trees->effect_tree.Node( | 806 EffectNode* node = property_trees->effect_tree.Node( |
| 821 property_trees->effect_id_to_index_map[id()]); | 807 property_trees->effect_id_to_index_map[id()]); |
| 822 return node->opacity; | 808 return node->opacity; |
| 823 } | 809 } |
| 824 | 810 |
| 811 const gfx::Transform& LayerImpl::Transform() const { |
| 812 PropertyTrees* property_trees = layer_tree_impl()->property_trees(); |
| 813 DCHECK(property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, |
| 814 id())); |
| 815 TransformNode* node = property_trees->transform_tree.Node( |
| 816 property_trees->transform_id_to_index_map[id()]); |
| 817 return node->local; |
| 818 } |
| 819 |
| 825 void LayerImpl::SetElementId(ElementId element_id) { | 820 void LayerImpl::SetElementId(ElementId element_id) { |
| 826 if (element_id == element_id_) | 821 if (element_id == element_id_) |
| 827 return; | 822 return; |
| 828 | 823 |
| 829 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), | 824 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), |
| 830 "LayerImpl::SetElementId", "element", | 825 "LayerImpl::SetElementId", "element", |
| 831 element_id.AsValue().release()); | 826 element_id.AsValue().release()); |
| 832 | 827 |
| 833 layer_tree_impl_->RemoveFromElementMap(this); | 828 layer_tree_impl_->RemoveFromElementMap(this); |
| 834 element_id_ = element_id; | 829 element_id_ = element_id; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 850 } | 845 } |
| 851 | 846 |
| 852 void LayerImpl::SetPosition(const gfx::PointF& position) { | 847 void LayerImpl::SetPosition(const gfx::PointF& position) { |
| 853 position_ = position; | 848 position_ = position; |
| 854 } | 849 } |
| 855 | 850 |
| 856 void LayerImpl::Set3dSortingContextId(int id) { | 851 void LayerImpl::Set3dSortingContextId(int id) { |
| 857 sorting_context_id_ = id; | 852 sorting_context_id_ = id; |
| 858 } | 853 } |
| 859 | 854 |
| 860 void LayerImpl::SetTransform(const gfx::Transform& transform) { | |
| 861 transform_ = transform; | |
| 862 } | |
| 863 | |
| 864 bool LayerImpl::TransformIsAnimating() const { | 855 bool LayerImpl::TransformIsAnimating() const { |
| 865 return GetAnimationHost()->IsAnimatingTransformProperty( | 856 return GetAnimationHost()->IsAnimatingTransformProperty( |
| 866 element_id(), GetElementTypeForAnimation()); | 857 element_id(), GetElementTypeForAnimation()); |
| 867 } | 858 } |
| 868 | 859 |
| 869 bool LayerImpl::HasPotentiallyRunningTransformAnimation() const { | 860 bool LayerImpl::HasPotentiallyRunningTransformAnimation() const { |
| 870 return GetAnimationHost()->HasPotentiallyRunningTransformAnimation( | 861 return GetAnimationHost()->HasPotentiallyRunningTransformAnimation( |
| 871 element_id(), GetElementTypeForAnimation()); | 862 element_id(), GetElementTypeForAnimation()); |
| 872 } | 863 } |
| 873 | 864 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 base::saturated_cast<int>(GPUMemoryUsageInBytes())); | 997 base::saturated_cast<int>(GPUMemoryUsageInBytes())); |
| 1007 | 998 |
| 1008 if (element_id_) | 999 if (element_id_) |
| 1009 element_id_.AddToTracedValue(state); | 1000 element_id_.AddToTracedValue(state); |
| 1010 | 1001 |
| 1011 if (mutable_properties_ != MutableProperty::kNone) | 1002 if (mutable_properties_ != MutableProperty::kNone) |
| 1012 state->SetInteger("mutable_properties", mutable_properties_); | 1003 state->SetInteger("mutable_properties", mutable_properties_); |
| 1013 | 1004 |
| 1014 MathUtil::AddToTracedValue("scroll_offset", CurrentScrollOffset(), state); | 1005 MathUtil::AddToTracedValue("scroll_offset", CurrentScrollOffset(), state); |
| 1015 | 1006 |
| 1016 if (!transform().IsIdentity()) | 1007 if (!ScreenSpaceTransform().IsIdentity()) |
| 1017 MathUtil::AddToTracedValue("transform", transform(), state); | 1008 MathUtil::AddToTracedValue("screen_space_transform", ScreenSpaceTransform(), |
| 1009 state); |
| 1018 | 1010 |
| 1019 bool clipped; | 1011 bool clipped; |
| 1020 gfx::QuadF layer_quad = | 1012 gfx::QuadF layer_quad = |
| 1021 MathUtil::MapQuad(ScreenSpaceTransform(), | 1013 MathUtil::MapQuad(ScreenSpaceTransform(), |
| 1022 gfx::QuadF(gfx::RectF(gfx::Rect(bounds()))), &clipped); | 1014 gfx::QuadF(gfx::RectF(gfx::Rect(bounds()))), &clipped); |
| 1023 MathUtil::AddToTracedValue("layer_quad", layer_quad, state); | 1015 MathUtil::AddToTracedValue("layer_quad", layer_quad, state); |
| 1024 if (!touch_event_handler_region_.IsEmpty()) { | 1016 if (!touch_event_handler_region_.IsEmpty()) { |
| 1025 state->BeginArray("touch_event_handler_region"); | 1017 state->BeginArray("touch_event_handler_region"); |
| 1026 touch_event_handler_region_.AsValueInto(state); | 1018 touch_event_handler_region_.AsValueInto(state); |
| 1027 state->EndArray(); | 1019 state->EndArray(); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 .layer_transforms_should_scale_layer_contents) { | 1188 .layer_transforms_should_scale_layer_contents) { |
| 1197 return default_scale; | 1189 return default_scale; |
| 1198 } | 1190 } |
| 1199 | 1191 |
| 1200 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( | 1192 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( |
| 1201 ScreenSpaceTransform(), default_scale); | 1193 ScreenSpaceTransform(), default_scale); |
| 1202 return std::max(transform_scales.x(), transform_scales.y()); | 1194 return std::max(transform_scales.x(), transform_scales.y()); |
| 1203 } | 1195 } |
| 1204 | 1196 |
| 1205 } // namespace cc | 1197 } // namespace cc |
| OLD | NEW |