| 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 "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/numerics/safe_conversions.h" | 8 #include "base/numerics/safe_conversions.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 num_dependents_need_push_properties_(0), | 83 num_dependents_need_push_properties_(0), |
| 84 sorting_context_id_(0), | 84 sorting_context_id_(0), |
| 85 current_draw_mode_(DRAW_MODE_NONE), | 85 current_draw_mode_(DRAW_MODE_NONE), |
| 86 frame_timing_requests_dirty_(false), | 86 frame_timing_requests_dirty_(false), |
| 87 visited_(false), | 87 visited_(false), |
| 88 layer_or_descendant_is_drawn_(false), | 88 layer_or_descendant_is_drawn_(false), |
| 89 sorted_for_recursion_(false) { | 89 sorted_for_recursion_(false) { |
| 90 DCHECK_GT(layer_id_, 0); | 90 DCHECK_GT(layer_id_, 0); |
| 91 DCHECK(layer_tree_impl_); | 91 DCHECK(layer_tree_impl_); |
| 92 layer_tree_impl_->RegisterLayer(this); | 92 layer_tree_impl_->RegisterLayer(this); |
| 93 AnimationRegistrar* registrar = layer_tree_impl_->GetAnimationRegistrar(); | 93 |
| 94 layer_animation_controller_ = | 94 if (!layer_tree_impl_->settings().use_compositor_animation_timelines) { |
| 95 registrar->GetAnimationControllerForId(layer_id_); | 95 AnimationRegistrar* registrar = layer_tree_impl_->GetAnimationRegistrar(); |
| 96 layer_animation_controller_->AddValueObserver(this); | 96 layer_animation_controller_ = |
| 97 if (IsActive()) { | 97 registrar->GetAnimationControllerForId(layer_id_); |
| 98 layer_animation_controller_->set_value_provider(this); | 98 layer_animation_controller_->AddValueObserver(this); |
| 99 layer_animation_controller_->set_layer_animation_delegate(this); | 99 if (IsActive()) { |
| 100 layer_animation_controller_->set_value_provider(this); |
| 101 layer_animation_controller_->set_layer_animation_delegate(this); |
| 102 } |
| 100 } | 103 } |
| 101 SetNeedsPushProperties(); | 104 SetNeedsPushProperties(); |
| 102 } | 105 } |
| 103 | 106 |
| 104 LayerImpl::~LayerImpl() { | 107 LayerImpl::~LayerImpl() { |
| 105 DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_); | 108 DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_); |
| 106 | 109 |
| 107 layer_animation_controller_->RemoveValueObserver(this); | 110 if (layer_animation_controller_) { |
| 108 layer_animation_controller_->remove_value_provider(this); | 111 layer_animation_controller_->RemoveValueObserver(this); |
| 109 layer_animation_controller_->remove_layer_animation_delegate(this); | 112 layer_animation_controller_->remove_value_provider(this); |
| 113 layer_animation_controller_->remove_layer_animation_delegate(this); |
| 114 } |
| 110 | 115 |
| 111 if (!copy_requests_.empty() && layer_tree_impl_->IsActiveTree()) | 116 if (!copy_requests_.empty() && layer_tree_impl_->IsActiveTree()) |
| 112 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this); | 117 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this); |
| 113 layer_tree_impl_->UnregisterLayer(this); | 118 layer_tree_impl_->UnregisterLayer(this); |
| 114 | 119 |
| 115 TRACE_EVENT_OBJECT_DELETED_WITH_ID( | 120 TRACE_EVENT_OBJECT_DELETED_WITH_ID( |
| 116 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this); | 121 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this); |
| 117 } | 122 } |
| 118 | 123 |
| 119 void LayerImpl::AddChild(scoped_ptr<LayerImpl> child) { | 124 void LayerImpl::AddChild(scoped_ptr<LayerImpl> child) { |
| (...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 | 1006 |
| 1002 void LayerImpl::SetFilters(const FilterOperations& filters) { | 1007 void LayerImpl::SetFilters(const FilterOperations& filters) { |
| 1003 if (filters_ == filters) | 1008 if (filters_ == filters) |
| 1004 return; | 1009 return; |
| 1005 | 1010 |
| 1006 filters_ = filters; | 1011 filters_ = filters; |
| 1007 NoteLayerPropertyChangedForSubtree(); | 1012 NoteLayerPropertyChangedForSubtree(); |
| 1008 } | 1013 } |
| 1009 | 1014 |
| 1010 bool LayerImpl::FilterIsAnimating() const { | 1015 bool LayerImpl::FilterIsAnimating() const { |
| 1011 return layer_animation_controller_->IsAnimatingProperty(Animation::FILTER); | 1016 return layer_animation_controller_ |
| 1017 ? layer_animation_controller_->IsAnimatingProperty( |
| 1018 Animation::FILTER) |
| 1019 : layer_tree_impl_->IsAnimatingFilterProperty(this); |
| 1012 } | 1020 } |
| 1013 | 1021 |
| 1014 bool LayerImpl::FilterIsAnimatingOnImplOnly() const { | 1022 bool LayerImpl::FilterIsAnimatingOnImplOnly() const { |
| 1023 if (!layer_animation_controller_) |
| 1024 return layer_tree_impl_->FilterIsAnimatingOnImplOnly(this); |
| 1025 |
| 1015 Animation* filter_animation = | 1026 Animation* filter_animation = |
| 1016 layer_animation_controller_->GetAnimation(Animation::FILTER); | 1027 layer_animation_controller_->GetAnimation(Animation::FILTER); |
| 1017 return filter_animation && filter_animation->is_impl_only(); | 1028 return filter_animation && filter_animation->is_impl_only(); |
| 1018 } | 1029 } |
| 1019 | 1030 |
| 1020 void LayerImpl::SetBackgroundFilters( | 1031 void LayerImpl::SetBackgroundFilters( |
| 1021 const FilterOperations& filters) { | 1032 const FilterOperations& filters) { |
| 1022 if (background_filters_ == filters) | 1033 if (background_filters_ == filters) |
| 1023 return; | 1034 return; |
| 1024 | 1035 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1044 | 1055 |
| 1045 void LayerImpl::SetOpacity(float opacity) { | 1056 void LayerImpl::SetOpacity(float opacity) { |
| 1046 if (opacity_ == opacity) | 1057 if (opacity_ == opacity) |
| 1047 return; | 1058 return; |
| 1048 | 1059 |
| 1049 opacity_ = opacity; | 1060 opacity_ = opacity; |
| 1050 NoteLayerPropertyChangedForSubtree(); | 1061 NoteLayerPropertyChangedForSubtree(); |
| 1051 } | 1062 } |
| 1052 | 1063 |
| 1053 bool LayerImpl::OpacityIsAnimating() const { | 1064 bool LayerImpl::OpacityIsAnimating() const { |
| 1054 return layer_animation_controller_->IsAnimatingProperty(Animation::OPACITY); | 1065 return layer_animation_controller_ |
| 1066 ? layer_animation_controller_->IsAnimatingProperty( |
| 1067 Animation::OPACITY) |
| 1068 : layer_tree_impl_->IsAnimatingOpacityProperty(this); |
| 1069 } |
| 1070 |
| 1071 bool LayerImpl::HasPotentiallyRunningOpacityAnimation() const { |
| 1072 if (layer_animation_controller_) { |
| 1073 if (Animation* animation = |
| 1074 layer_animation_controller()->GetAnimation(Animation::OPACITY)) { |
| 1075 return !animation->is_finished(); |
| 1076 } |
| 1077 return false; |
| 1078 } else { |
| 1079 return layer_tree_impl_->HasPotentiallyRunningOpacityAnimation(this); |
| 1080 } |
| 1055 } | 1081 } |
| 1056 | 1082 |
| 1057 bool LayerImpl::OpacityIsAnimatingOnImplOnly() const { | 1083 bool LayerImpl::OpacityIsAnimatingOnImplOnly() const { |
| 1084 if (!layer_animation_controller_) |
| 1085 return layer_tree_impl_->OpacityIsAnimatingOnImplOnly(this); |
| 1086 |
| 1058 Animation* opacity_animation = | 1087 Animation* opacity_animation = |
| 1059 layer_animation_controller_->GetAnimation(Animation::OPACITY); | 1088 layer_animation_controller_->GetAnimation(Animation::OPACITY); |
| 1060 return opacity_animation && opacity_animation->is_impl_only(); | 1089 return opacity_animation && opacity_animation->is_impl_only(); |
| 1061 } | 1090 } |
| 1062 | 1091 |
| 1063 void LayerImpl::SetBlendMode(SkXfermode::Mode blend_mode) { | 1092 void LayerImpl::SetBlendMode(SkXfermode::Mode blend_mode) { |
| 1064 if (blend_mode_ == blend_mode) | 1093 if (blend_mode_ == blend_mode) |
| 1065 return; | 1094 return; |
| 1066 | 1095 |
| 1067 blend_mode_ = blend_mode; | 1096 blend_mode_ = blend_mode; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 DCHECK(transform_is_invertible_ == transform_is_invertible) | 1155 DCHECK(transform_is_invertible_ == transform_is_invertible) |
| 1127 << "Can't change invertibility if transform is unchanged"; | 1156 << "Can't change invertibility if transform is unchanged"; |
| 1128 return; | 1157 return; |
| 1129 } | 1158 } |
| 1130 transform_ = transform; | 1159 transform_ = transform; |
| 1131 transform_is_invertible_ = transform_is_invertible; | 1160 transform_is_invertible_ = transform_is_invertible; |
| 1132 NoteLayerPropertyChangedForSubtree(); | 1161 NoteLayerPropertyChangedForSubtree(); |
| 1133 } | 1162 } |
| 1134 | 1163 |
| 1135 bool LayerImpl::TransformIsAnimating() const { | 1164 bool LayerImpl::TransformIsAnimating() const { |
| 1136 return layer_animation_controller_->IsAnimatingProperty(Animation::TRANSFORM); | 1165 return layer_animation_controller_ |
| 1166 ? layer_animation_controller_->IsAnimatingProperty( |
| 1167 Animation::TRANSFORM) |
| 1168 : layer_tree_impl_->IsAnimatingTransformProperty(this); |
| 1169 } |
| 1170 |
| 1171 bool LayerImpl::HasPotentiallyRunningTransformAnimation() const { |
| 1172 if (layer_animation_controller_) { |
| 1173 if (Animation* animation = |
| 1174 layer_animation_controller()->GetAnimation(Animation::TRANSFORM)) { |
| 1175 return !animation->is_finished(); |
| 1176 } |
| 1177 return false; |
| 1178 } else { |
| 1179 return layer_tree_impl_->HasPotentiallyRunningTransformAnimation(this); |
| 1180 } |
| 1137 } | 1181 } |
| 1138 | 1182 |
| 1139 bool LayerImpl::TransformIsAnimatingOnImplOnly() const { | 1183 bool LayerImpl::TransformIsAnimatingOnImplOnly() const { |
| 1184 if (!layer_animation_controller_) |
| 1185 return layer_tree_impl_->TransformIsAnimatingOnImplOnly(this); |
| 1186 |
| 1140 Animation* transform_animation = | 1187 Animation* transform_animation = |
| 1141 layer_animation_controller_->GetAnimation(Animation::TRANSFORM); | 1188 layer_animation_controller_->GetAnimation(Animation::TRANSFORM); |
| 1142 return transform_animation && transform_animation->is_impl_only(); | 1189 return transform_animation && transform_animation->is_impl_only(); |
| 1143 } | 1190 } |
| 1144 | 1191 |
| 1192 bool LayerImpl::HasOnlyTranslationTransforms() const { |
| 1193 if (!layer_animation_controller_) |
| 1194 return layer_tree_impl_->HasOnlyTranslationTransforms(this); |
| 1195 |
| 1196 return layer_animation_controller_->HasOnlyTranslationTransforms(); |
| 1197 } |
| 1198 |
| 1199 bool LayerImpl::MaximumTargetScale(float* max_scale) const { |
| 1200 if (!layer_animation_controller_) |
| 1201 return layer_tree_impl_->MaximumTargetScale(this, max_scale); |
| 1202 |
| 1203 return layer_animation_controller_->MaximumTargetScale(max_scale); |
| 1204 } |
| 1205 |
| 1206 bool LayerImpl::AnimationStartScale(float* start_scale) const { |
| 1207 if (!layer_animation_controller_) |
| 1208 return layer_tree_impl_->AnimationStartScale(this, start_scale); |
| 1209 |
| 1210 return layer_animation_controller_->AnimationStartScale(start_scale); |
| 1211 } |
| 1212 |
| 1213 bool LayerImpl::HasFilterAnimationThatInflatesBounds() const { |
| 1214 if (!layer_animation_controller_) |
| 1215 return layer_tree_impl_->HasFilterAnimationThatInflatesBounds(this); |
| 1216 |
| 1217 return layer_animation_controller_->HasFilterAnimationThatInflatesBounds(); |
| 1218 } |
| 1219 |
| 1220 bool LayerImpl::HasTransformAnimationThatInflatesBounds() const { |
| 1221 if (!layer_animation_controller_) |
| 1222 return layer_tree_impl_->HasTransformAnimationThatInflatesBounds(this); |
| 1223 |
| 1224 return layer_animation_controller_->HasTransformAnimationThatInflatesBounds(); |
| 1225 } |
| 1226 |
| 1227 bool LayerImpl::HasAnimationThatInflatesBounds() const { |
| 1228 if (!layer_animation_controller_) |
| 1229 return layer_tree_impl_->HasAnimationThatInflatesBounds(this); |
| 1230 |
| 1231 return layer_animation_controller_->HasAnimationThatInflatesBounds(); |
| 1232 } |
| 1233 |
| 1234 bool LayerImpl::FilterAnimationBoundsForBox(const gfx::BoxF& box, |
| 1235 gfx::BoxF* bounds) const { |
| 1236 if (!layer_animation_controller_) |
| 1237 return layer_tree_impl_->FilterAnimationBoundsForBox(this, box, bounds); |
| 1238 |
| 1239 return layer_animation_controller_->FilterAnimationBoundsForBox(box, bounds); |
| 1240 } |
| 1241 |
| 1242 bool LayerImpl::TransformAnimationBoundsForBox(const gfx::BoxF& box, |
| 1243 gfx::BoxF* bounds) const { |
| 1244 if (!layer_animation_controller_) |
| 1245 return layer_tree_impl_->TransformAnimationBoundsForBox(this, box, bounds); |
| 1246 |
| 1247 return layer_animation_controller_->TransformAnimationBoundsForBox(box, |
| 1248 bounds); |
| 1249 } |
| 1250 |
| 1145 void LayerImpl::SetUpdateRect(const gfx::Rect& update_rect) { | 1251 void LayerImpl::SetUpdateRect(const gfx::Rect& update_rect) { |
| 1146 update_rect_ = update_rect; | 1252 update_rect_ = update_rect; |
| 1147 SetNeedsPushProperties(); | 1253 SetNeedsPushProperties(); |
| 1148 } | 1254 } |
| 1149 | 1255 |
| 1150 void LayerImpl::AddDamageRect(const gfx::RectF& damage_rect) { | 1256 void LayerImpl::AddDamageRect(const gfx::RectF& damage_rect) { |
| 1151 damage_rect_ = gfx::UnionRects(damage_rect_, damage_rect); | 1257 damage_rect_ = gfx::UnionRects(damage_rect_, damage_rect); |
| 1152 } | 1258 } |
| 1153 | 1259 |
| 1154 bool LayerImpl::IsExternalScrollActive() const { | 1260 bool LayerImpl::IsExternalScrollActive() const { |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1587 state->SetInteger("scroll_parent", scroll_parent_->id()); | 1693 state->SetInteger("scroll_parent", scroll_parent_->id()); |
| 1588 | 1694 |
| 1589 if (clip_parent_) | 1695 if (clip_parent_) |
| 1590 state->SetInteger("clip_parent", clip_parent_->id()); | 1696 state->SetInteger("clip_parent", clip_parent_->id()); |
| 1591 | 1697 |
| 1592 state->SetBoolean("can_use_lcd_text", can_use_lcd_text()); | 1698 state->SetBoolean("can_use_lcd_text", can_use_lcd_text()); |
| 1593 state->SetBoolean("contents_opaque", contents_opaque()); | 1699 state->SetBoolean("contents_opaque", contents_opaque()); |
| 1594 | 1700 |
| 1595 state->SetBoolean( | 1701 state->SetBoolean( |
| 1596 "has_animation_bounds", | 1702 "has_animation_bounds", |
| 1597 layer_animation_controller()->HasAnimationThatInflatesBounds()); | 1703 layer_animation_controller_ |
| 1704 ? layer_animation_controller_->HasAnimationThatInflatesBounds() |
| 1705 : layer_tree_impl_->HasAnimationThatInflatesBounds(this)); |
| 1598 | 1706 |
| 1599 gfx::BoxF box; | 1707 gfx::BoxF box; |
| 1600 if (LayerUtils::GetAnimationBounds(*this, &box)) | 1708 if (LayerUtils::GetAnimationBounds(*this, &box)) |
| 1601 MathUtil::AddToTracedValue("animation_bounds", box, state); | 1709 MathUtil::AddToTracedValue("animation_bounds", box, state); |
| 1602 | 1710 |
| 1603 if (debug_info_.get()) { | 1711 if (debug_info_.get()) { |
| 1604 std::string str; | 1712 std::string str; |
| 1605 debug_info_->AppendAsTraceFormat(&str); | 1713 debug_info_->AppendAsTraceFormat(&str); |
| 1606 base::JSONReader json_reader; | 1714 base::JSONReader json_reader; |
| 1607 scoped_ptr<base::Value> debug_info_value(json_reader.ReadToValue(str)); | 1715 scoped_ptr<base::Value> debug_info_value(json_reader.ReadToValue(str)); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1680 gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const { | 1788 gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const { |
| 1681 gfx::Transform scaled_draw_transform = | 1789 gfx::Transform scaled_draw_transform = |
| 1682 draw_properties_.target_space_transform; | 1790 draw_properties_.target_space_transform; |
| 1683 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale); | 1791 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale); |
| 1684 gfx::Size scaled_bounds = gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale)); | 1792 gfx::Size scaled_bounds = gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale)); |
| 1685 return MathUtil::MapEnclosingClippedRect(scaled_draw_transform, | 1793 return MathUtil::MapEnclosingClippedRect(scaled_draw_transform, |
| 1686 gfx::Rect(scaled_bounds)); | 1794 gfx::Rect(scaled_bounds)); |
| 1687 } | 1795 } |
| 1688 | 1796 |
| 1689 } // namespace cc | 1797 } // namespace cc |
| OLD | NEW |