| 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 27 matching lines...) Expand all Loading... |
| 38 #include "ui/gfx/geometry/box_f.h" | 38 #include "ui/gfx/geometry/box_f.h" |
| 39 #include "ui/gfx/geometry/point_conversions.h" | 39 #include "ui/gfx/geometry/point_conversions.h" |
| 40 #include "ui/gfx/geometry/quad_f.h" | 40 #include "ui/gfx/geometry/quad_f.h" |
| 41 #include "ui/gfx/geometry/rect_conversions.h" | 41 #include "ui/gfx/geometry/rect_conversions.h" |
| 42 #include "ui/gfx/geometry/size_conversions.h" | 42 #include "ui/gfx/geometry/size_conversions.h" |
| 43 #include "ui/gfx/geometry/vector2d_conversions.h" | 43 #include "ui/gfx/geometry/vector2d_conversions.h" |
| 44 | 44 |
| 45 namespace cc { | 45 namespace cc { |
| 46 LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, int id) | 46 LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, int id) |
| 47 : parent_(nullptr), | 47 : parent_(nullptr), |
| 48 mask_layer_id_(-1), | |
| 49 mask_layer_(nullptr), | |
| 50 replica_layer_id_(-1), | |
| 51 replica_layer_(nullptr), | |
| 52 layer_id_(id), | 48 layer_id_(id), |
| 53 layer_tree_impl_(tree_impl), | 49 layer_tree_impl_(tree_impl), |
| 54 test_properties_(nullptr), | 50 test_properties_(nullptr), |
| 55 scroll_clip_layer_id_(Layer::INVALID_ID), | 51 scroll_clip_layer_id_(Layer::INVALID_ID), |
| 56 main_thread_scrolling_reasons_( | 52 main_thread_scrolling_reasons_( |
| 57 MainThreadScrollingReason::kNotScrollingOnMain), | 53 MainThreadScrollingReason::kNotScrollingOnMain), |
| 58 user_scrollable_horizontal_(true), | 54 user_scrollable_horizontal_(true), |
| 59 user_scrollable_vertical_(true), | 55 user_scrollable_vertical_(true), |
| 60 should_flatten_transform_from_property_tree_(false), | 56 should_flatten_transform_from_property_tree_(false), |
| 61 layer_property_changed_(false), | 57 layer_property_changed_(false), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_); | 92 DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_); |
| 97 | 93 |
| 98 layer_tree_impl_->UnregisterScrollLayer(this); | 94 layer_tree_impl_->UnregisterScrollLayer(this); |
| 99 layer_tree_impl_->UnregisterLayer(this); | 95 layer_tree_impl_->UnregisterLayer(this); |
| 100 layer_tree_impl_->RemoveLayerShouldPushProperties(this); | 96 layer_tree_impl_->RemoveLayerShouldPushProperties(this); |
| 101 | 97 |
| 102 layer_tree_impl_->RemoveFromElementMap(this); | 98 layer_tree_impl_->RemoveFromElementMap(this); |
| 103 | 99 |
| 104 TRACE_EVENT_OBJECT_DELETED_WITH_ID( | 100 TRACE_EVENT_OBJECT_DELETED_WITH_ID( |
| 105 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this); | 101 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this); |
| 106 | |
| 107 // The mask and replica layers should have been removed already. | |
| 108 if (mask_layer_) | |
| 109 DCHECK(!layer_tree_impl_->RemoveLayer(mask_layer_id_)); | |
| 110 if (replica_layer_) | |
| 111 DCHECK(!layer_tree_impl_->RemoveLayer(replica_layer_id_)); | |
| 112 } | 102 } |
| 113 | 103 |
| 114 void LayerImpl::AddChild(std::unique_ptr<LayerImpl> child) { | 104 void LayerImpl::AddChild(std::unique_ptr<LayerImpl> child) { |
| 115 child->SetParent(this); | 105 child->SetParent(this); |
| 116 DCHECK_EQ(layer_tree_impl(), child->layer_tree_impl()); | 106 DCHECK_EQ(layer_tree_impl(), child->layer_tree_impl()); |
| 117 test_properties()->children.push_back(child.get()); | 107 test_properties()->children.push_back(child.get()); |
| 118 layer_tree_impl_->AddLayer(std::move(child)); | 108 layer_tree_impl_->AddLayer(std::move(child)); |
| 119 } | 109 } |
| 120 | 110 |
| 121 std::unique_ptr<LayerImpl> LayerImpl::RemoveChildForTesting(LayerImpl* child) { | 111 std::unique_ptr<LayerImpl> LayerImpl::RemoveChildForTesting(LayerImpl* child) { |
| 122 auto it = std::find(test_properties()->children.begin(), | 112 auto it = std::find(test_properties()->children.begin(), |
| 123 test_properties()->children.end(), child); | 113 test_properties()->children.end(), child); |
| 124 if (it != test_properties()->children.end()) | 114 if (it != test_properties()->children.end()) |
| 125 test_properties()->children.erase(it); | 115 test_properties()->children.erase(it); |
| 126 layer_tree_impl()->property_trees()->RemoveIdFromIdToIndexMaps(child->id()); | 116 layer_tree_impl()->property_trees()->RemoveIdFromIdToIndexMaps(child->id()); |
| 127 return layer_tree_impl_->RemoveLayer(child->id()); | 117 return layer_tree_impl_->RemoveLayer(child->id()); |
| 128 } | 118 } |
| 129 | 119 |
| 130 void LayerImpl::SetParent(LayerImpl* parent) { | 120 void LayerImpl::SetParent(LayerImpl* parent) { |
| 131 parent_ = parent; | 121 parent_ = parent; |
| 132 } | 122 } |
| 133 | 123 |
| 134 void LayerImpl::ClearLinksToOtherLayers() { | |
| 135 mask_layer_ = nullptr; | |
| 136 replica_layer_ = nullptr; | |
| 137 } | |
| 138 | |
| 139 void LayerImpl::SetHasWillChangeTransformHint(bool has_will_change) { | 124 void LayerImpl::SetHasWillChangeTransformHint(bool has_will_change) { |
| 140 if (has_will_change_transform_hint_ == has_will_change) | 125 if (has_will_change_transform_hint_ == has_will_change) |
| 141 return; | 126 return; |
| 142 has_will_change_transform_hint_ = has_will_change; | 127 has_will_change_transform_hint_ = has_will_change; |
| 143 SetNeedsPushProperties(); | 128 SetNeedsPushProperties(); |
| 144 } | 129 } |
| 145 | 130 |
| 146 void LayerImpl::SetDebugInfo( | 131 void LayerImpl::SetDebugInfo( |
| 147 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info) { | 132 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info) { |
| 148 owned_debug_info_ = std::move(debug_info); | 133 owned_debug_info_ = std::move(debug_info); |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 } | 503 } |
| 519 | 504 |
| 520 void LayerImpl::ResetChangeTracking() { | 505 void LayerImpl::ResetChangeTracking() { |
| 521 layer_property_changed_ = false; | 506 layer_property_changed_ = false; |
| 522 | 507 |
| 523 update_rect_.SetRect(0, 0, 0, 0); | 508 update_rect_.SetRect(0, 0, 0, 0); |
| 524 damage_rect_.SetRect(0, 0, 0, 0); | 509 damage_rect_.SetRect(0, 0, 0, 0); |
| 525 | 510 |
| 526 if (render_surface_) | 511 if (render_surface_) |
| 527 render_surface_->ResetPropertyChangedFlag(); | 512 render_surface_->ResetPropertyChangedFlag(); |
| 528 | |
| 529 if (mask_layer_) | |
| 530 mask_layer_->ResetChangeTracking(); | |
| 531 | |
| 532 if (replica_layer_) { | |
| 533 // This also resets the replica mask, if it exists. | |
| 534 replica_layer_->ResetChangeTracking(); | |
| 535 } | |
| 536 } | 513 } |
| 537 | 514 |
| 538 int LayerImpl::num_copy_requests_in_target_subtree() { | 515 int LayerImpl::num_copy_requests_in_target_subtree() { |
| 539 return layer_tree_impl() | 516 return layer_tree_impl() |
| 540 ->property_trees() | 517 ->property_trees() |
| 541 ->effect_tree.Node(effect_tree_index()) | 518 ->effect_tree.Node(effect_tree_index()) |
| 542 ->data.num_copy_requests_in_subtree; | 519 ->data.num_copy_requests_in_subtree; |
| 543 } | 520 } |
| 544 | 521 |
| 545 void LayerImpl::UpdatePropertyTreeTransform() { | 522 void LayerImpl::UpdatePropertyTreeTransform() { |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 gfx::PointF() + offset_to_transform_parent(), gfx::SizeF(bounds())); | 763 gfx::PointF() + offset_to_transform_parent(), gfx::SizeF(bounds())); |
| 787 property_trees->clip_tree.set_needs_update(true); | 764 property_trees->clip_tree.set_needs_update(true); |
| 788 } | 765 } |
| 789 property_trees->full_tree_damaged = true; | 766 property_trees->full_tree_damaged = true; |
| 790 layer_tree_impl()->set_needs_update_draw_properties(); | 767 layer_tree_impl()->set_needs_update_draw_properties(); |
| 791 } else { | 768 } else { |
| 792 NoteLayerPropertyChanged(); | 769 NoteLayerPropertyChanged(); |
| 793 } | 770 } |
| 794 } | 771 } |
| 795 | 772 |
| 796 void LayerImpl::SetMaskLayer(std::unique_ptr<LayerImpl> mask_layer) { | |
| 797 int new_layer_id = mask_layer ? mask_layer->id() : -1; | |
| 798 | |
| 799 if (mask_layer) { | |
| 800 DCHECK_EQ(layer_tree_impl(), mask_layer->layer_tree_impl()); | |
| 801 DCHECK_NE(new_layer_id, mask_layer_id_); | |
| 802 } else if (new_layer_id == mask_layer_id_) { | |
| 803 return; | |
| 804 } | |
| 805 | |
| 806 if (mask_layer_) | |
| 807 layer_tree_impl_->RemoveLayer(mask_layer_->id()); | |
| 808 mask_layer_ = mask_layer.get(); | |
| 809 if (mask_layer_) | |
| 810 layer_tree_impl_->AddLayer(std::move(mask_layer)); | |
| 811 | |
| 812 mask_layer_id_ = new_layer_id; | |
| 813 } | |
| 814 | |
| 815 std::unique_ptr<LayerImpl> LayerImpl::TakeMaskLayer() { | |
| 816 mask_layer_id_ = -1; | |
| 817 std::unique_ptr<LayerImpl> ret; | |
| 818 if (mask_layer_) | |
| 819 ret = layer_tree_impl_->RemoveLayer(mask_layer_->id()); | |
| 820 mask_layer_ = nullptr; | |
| 821 return ret; | |
| 822 } | |
| 823 | |
| 824 void LayerImpl::SetReplicaLayer(std::unique_ptr<LayerImpl> replica_layer) { | |
| 825 int new_layer_id = replica_layer ? replica_layer->id() : -1; | |
| 826 | |
| 827 if (replica_layer) { | |
| 828 DCHECK_EQ(layer_tree_impl(), replica_layer->layer_tree_impl()); | |
| 829 DCHECK_NE(new_layer_id, replica_layer_id_); | |
| 830 } else if (new_layer_id == replica_layer_id_) { | |
| 831 return; | |
| 832 } | |
| 833 | |
| 834 if (replica_layer_) | |
| 835 layer_tree_impl_->RemoveLayer(replica_layer_->id()); | |
| 836 replica_layer_ = replica_layer.get(); | |
| 837 if (replica_layer_) | |
| 838 layer_tree_impl_->AddLayer(std::move(replica_layer)); | |
| 839 | |
| 840 replica_layer_id_ = new_layer_id; | |
| 841 } | |
| 842 | |
| 843 std::unique_ptr<LayerImpl> LayerImpl::TakeReplicaLayerForTesting() { | |
| 844 replica_layer_id_ = -1; | |
| 845 std::unique_ptr<LayerImpl> ret; | |
| 846 if (replica_layer_) { | |
| 847 if (replica_layer_->mask_layer()) | |
| 848 replica_layer_->SetMaskLayer(nullptr); | |
| 849 ret = layer_tree_impl_->RemoveLayer(replica_layer_->id()); | |
| 850 } | |
| 851 replica_layer_ = nullptr; | |
| 852 return ret; | |
| 853 } | |
| 854 | |
| 855 ScrollbarLayerImplBase* LayerImpl::ToScrollbarLayer() { | 773 ScrollbarLayerImplBase* LayerImpl::ToScrollbarLayer() { |
| 856 return nullptr; | 774 return nullptr; |
| 857 } | 775 } |
| 858 | 776 |
| 859 void LayerImpl::SetDrawsContent(bool draws_content) { | 777 void LayerImpl::SetDrawsContent(bool draws_content) { |
| 860 if (draws_content_ == draws_content) | 778 if (draws_content_ == draws_content) |
| 861 return; | 779 return; |
| 862 | 780 |
| 863 draws_content_ = draws_content; | 781 draws_content_ = draws_content; |
| 864 NoteLayerPropertyChanged(); | 782 NoteLayerPropertyChanged(); |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1162 if (!touch_event_handler_region_.IsEmpty()) { | 1080 if (!touch_event_handler_region_.IsEmpty()) { |
| 1163 state->BeginArray("touch_event_handler_region"); | 1081 state->BeginArray("touch_event_handler_region"); |
| 1164 touch_event_handler_region_.AsValueInto(state); | 1082 touch_event_handler_region_.AsValueInto(state); |
| 1165 state->EndArray(); | 1083 state->EndArray(); |
| 1166 } | 1084 } |
| 1167 if (!non_fast_scrollable_region_.IsEmpty()) { | 1085 if (!non_fast_scrollable_region_.IsEmpty()) { |
| 1168 state->BeginArray("non_fast_scrollable_region"); | 1086 state->BeginArray("non_fast_scrollable_region"); |
| 1169 non_fast_scrollable_region_.AsValueInto(state); | 1087 non_fast_scrollable_region_.AsValueInto(state); |
| 1170 state->EndArray(); | 1088 state->EndArray(); |
| 1171 } | 1089 } |
| 1172 if (mask_layer_) { | |
| 1173 state->BeginDictionary("mask_layer"); | |
| 1174 mask_layer_->AsValueInto(state); | |
| 1175 state->EndDictionary(); | |
| 1176 } | |
| 1177 if (replica_layer_) { | |
| 1178 state->BeginDictionary("replica_layer"); | |
| 1179 replica_layer_->AsValueInto(state); | |
| 1180 state->EndDictionary(); | |
| 1181 } | |
| 1182 | 1090 |
| 1183 state->SetBoolean("can_use_lcd_text", CanUseLCDText()); | 1091 state->SetBoolean("can_use_lcd_text", CanUseLCDText()); |
| 1184 state->SetBoolean("contents_opaque", contents_opaque()); | 1092 state->SetBoolean("contents_opaque", contents_opaque()); |
| 1185 | 1093 |
| 1186 state->SetBoolean("has_animation_bounds", | 1094 state->SetBoolean("has_animation_bounds", |
| 1187 layer_tree_impl_->HasAnimationThatInflatesBounds(this)); | 1095 layer_tree_impl_->HasAnimationThatInflatesBounds(this)); |
| 1188 | 1096 |
| 1189 state->SetBoolean("has_will_change_transform_hint", | 1097 state->SetBoolean("has_will_change_transform_hint", |
| 1190 has_will_change_transform_hint()); | 1098 has_will_change_transform_hint()); |
| 1191 | 1099 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1327 return node->data.screen_space_opacity == 0.f; | 1235 return node->data.screen_space_opacity == 0.f; |
| 1328 } | 1236 } |
| 1329 | 1237 |
| 1330 bool LayerImpl::InsideReplica() const { | 1238 bool LayerImpl::InsideReplica() const { |
| 1331 // There are very few render targets so this should be cheap to do for each | 1239 // There are very few render targets so this should be cheap to do for each |
| 1332 // layer instead of something more complicated. | 1240 // layer instead of something more complicated. |
| 1333 EffectTree& effect_tree = layer_tree_impl_->property_trees()->effect_tree; | 1241 EffectTree& effect_tree = layer_tree_impl_->property_trees()->effect_tree; |
| 1334 EffectNode* node = effect_tree.Node(effect_tree_index_); | 1242 EffectNode* node = effect_tree.Node(effect_tree_index_); |
| 1335 | 1243 |
| 1336 while (node->id > 0) { | 1244 while (node->id > 0) { |
| 1337 LayerImpl* target_layer = layer_tree_impl()->LayerById(node->owner_id); | 1245 if (node->data.replica_layer_id != -1) |
| 1338 DCHECK(target_layer); | |
| 1339 if (target_layer->has_replica()) | |
| 1340 return true; | 1246 return true; |
| 1341 node = effect_tree.Node(node->data.target_id); | 1247 node = effect_tree.Node(node->data.target_id); |
| 1342 } | 1248 } |
| 1343 | 1249 |
| 1344 return false; | 1250 return false; |
| 1345 } | 1251 } |
| 1346 | 1252 |
| 1347 float LayerImpl::GetIdealContentsScale() const { | 1253 float LayerImpl::GetIdealContentsScale() const { |
| 1348 float page_scale = IsAffectedByPageScale() | 1254 float page_scale = IsAffectedByPageScale() |
| 1349 ? layer_tree_impl()->current_page_scale_factor() | 1255 ? layer_tree_impl()->current_page_scale_factor() |
| 1350 : 1.f; | 1256 : 1.f; |
| 1351 float device_scale = layer_tree_impl()->device_scale_factor(); | 1257 float device_scale = layer_tree_impl()->device_scale_factor(); |
| 1352 | 1258 |
| 1353 float default_scale = page_scale * device_scale; | 1259 float default_scale = page_scale * device_scale; |
| 1354 if (!layer_tree_impl() | 1260 if (!layer_tree_impl() |
| 1355 ->settings() | 1261 ->settings() |
| 1356 .layer_transforms_should_scale_layer_contents) { | 1262 .layer_transforms_should_scale_layer_contents) { |
| 1357 return default_scale; | 1263 return default_scale; |
| 1358 } | 1264 } |
| 1359 | 1265 |
| 1360 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( | 1266 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( |
| 1361 ScreenSpaceTransform(), default_scale); | 1267 ScreenSpaceTransform(), default_scale); |
| 1362 return std::max(transform_scales.x(), transform_scales.y()); | 1268 return std::max(transform_scales.x(), transform_scales.y()); |
| 1363 } | 1269 } |
| 1364 | 1270 |
| 1365 } // namespace cc | 1271 } // namespace cc |
| OLD | NEW |