| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 replica_layer_id_(-1), | 52 replica_layer_id_(-1), |
| 53 replica_layer_(nullptr), | 53 replica_layer_(nullptr), |
| 54 layer_id_(id), | 54 layer_id_(id), |
| 55 layer_tree_impl_(tree_impl), | 55 layer_tree_impl_(tree_impl), |
| 56 test_properties_(nullptr), | 56 test_properties_(nullptr), |
| 57 scroll_clip_layer_id_(Layer::INVALID_ID), | 57 scroll_clip_layer_id_(Layer::INVALID_ID), |
| 58 main_thread_scrolling_reasons_( | 58 main_thread_scrolling_reasons_( |
| 59 MainThreadScrollingReason::kNotScrollingOnMain), | 59 MainThreadScrollingReason::kNotScrollingOnMain), |
| 60 user_scrollable_horizontal_(true), | 60 user_scrollable_horizontal_(true), |
| 61 user_scrollable_vertical_(true), | 61 user_scrollable_vertical_(true), |
| 62 should_flatten_transform_(true), | |
| 63 should_flatten_transform_from_property_tree_(false), | 62 should_flatten_transform_from_property_tree_(false), |
| 64 layer_property_changed_(false), | 63 layer_property_changed_(false), |
| 65 masks_to_bounds_(false), | 64 masks_to_bounds_(false), |
| 66 contents_opaque_(false), | 65 contents_opaque_(false), |
| 67 is_root_for_isolated_group_(false), | |
| 68 use_parent_backface_visibility_(false), | 66 use_parent_backface_visibility_(false), |
| 69 use_local_transform_for_backface_visibility_(false), | 67 use_local_transform_for_backface_visibility_(false), |
| 70 should_check_backface_visibility_(false), | 68 should_check_backface_visibility_(false), |
| 71 draws_content_(false), | 69 draws_content_(false), |
| 72 hide_layer_and_subtree_(false), | 70 hide_layer_and_subtree_(false), |
| 73 transform_is_invertible_(true), | |
| 74 is_container_for_fixed_position_layers_(false), | |
| 75 is_affected_by_page_scale_(true), | 71 is_affected_by_page_scale_(true), |
| 76 was_ever_ready_since_last_transform_animation_(true), | 72 was_ever_ready_since_last_transform_animation_(true), |
| 77 background_color_(0), | 73 background_color_(0), |
| 78 safe_opaque_background_color_(0), | 74 safe_opaque_background_color_(0), |
| 79 opacity_(1.0), | 75 opacity_(1.0), |
| 80 blend_mode_(SkXfermode::kSrcOver_Mode), | 76 blend_mode_(SkXfermode::kSrcOver_Mode), |
| 81 draw_blend_mode_(SkXfermode::kSrcOver_Mode), | 77 draw_blend_mode_(SkXfermode::kSrcOver_Mode), |
| 82 num_descendants_that_draw_content_(0), | |
| 83 transform_tree_index_(-1), | 78 transform_tree_index_(-1), |
| 84 effect_tree_index_(-1), | 79 effect_tree_index_(-1), |
| 85 clip_tree_index_(-1), | 80 clip_tree_index_(-1), |
| 86 scroll_tree_index_(-1), | 81 scroll_tree_index_(-1), |
| 87 sorting_context_id_(0), | 82 sorting_context_id_(0), |
| 88 current_draw_mode_(DRAW_MODE_NONE), | 83 current_draw_mode_(DRAW_MODE_NONE), |
| 89 element_id_(0), | 84 element_id_(0), |
| 90 mutable_properties_(MutableProperty::kNone), | 85 mutable_properties_(MutableProperty::kNone), |
| 91 debug_info_(nullptr), | 86 debug_info_(nullptr), |
| 92 scrolls_drawn_descendant_(false), | 87 scrolls_drawn_descendant_(false), |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 ApplyScroll(scroll_state); | 192 ApplyScroll(scroll_state); |
| 198 } | 193 } |
| 199 | 194 |
| 200 void LayerImpl::ApplyScroll(ScrollState* scroll_state) { | 195 void LayerImpl::ApplyScroll(ScrollState* scroll_state) { |
| 201 DCHECK(scroll_state); | 196 DCHECK(scroll_state); |
| 202 ScrollNode* node = layer_tree_impl()->property_trees()->scroll_tree.Node( | 197 ScrollNode* node = layer_tree_impl()->property_trees()->scroll_tree.Node( |
| 203 scroll_tree_index()); | 198 scroll_tree_index()); |
| 204 layer_tree_impl()->ApplyScroll(node, scroll_state); | 199 layer_tree_impl()->ApplyScroll(node, scroll_state); |
| 205 } | 200 } |
| 206 | 201 |
| 207 void LayerImpl::SetNumDescendantsThatDrawContent(int num_descendants) { | |
| 208 if (num_descendants_that_draw_content_ == num_descendants) | |
| 209 return; | |
| 210 num_descendants_that_draw_content_ = num_descendants; | |
| 211 SetNeedsPushProperties(); | |
| 212 } | |
| 213 | |
| 214 void LayerImpl::SetClipParent(LayerImpl* ancestor) { | 202 void LayerImpl::SetClipParent(LayerImpl* ancestor) { |
| 215 if (clip_parent_ == ancestor) | 203 if (clip_parent_ == ancestor) |
| 216 return; | 204 return; |
| 217 | 205 |
| 218 clip_parent_ = ancestor; | 206 clip_parent_ = ancestor; |
| 219 SetNeedsPushProperties(); | 207 SetNeedsPushProperties(); |
| 220 } | 208 } |
| 221 | 209 |
| 222 void LayerImpl::SetClipChildren(std::set<LayerImpl*>* children) { | 210 void LayerImpl::SetClipChildren(std::set<LayerImpl*>* children) { |
| 223 if (clip_children_.get() == children) | 211 if (clip_children_.get() == children) |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 layer->SetHasRenderSurface(!!render_surface()); | 485 layer->SetHasRenderSurface(!!render_surface()); |
| 498 layer->SetFilters(filters()); | 486 layer->SetFilters(filters()); |
| 499 layer->SetBackgroundFilters(background_filters()); | 487 layer->SetBackgroundFilters(background_filters()); |
| 500 layer->SetMasksToBounds(masks_to_bounds_); | 488 layer->SetMasksToBounds(masks_to_bounds_); |
| 501 layer->set_main_thread_scrolling_reasons(main_thread_scrolling_reasons_); | 489 layer->set_main_thread_scrolling_reasons(main_thread_scrolling_reasons_); |
| 502 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_); | 490 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_); |
| 503 layer->SetTouchEventHandlerRegion(touch_event_handler_region_); | 491 layer->SetTouchEventHandlerRegion(touch_event_handler_region_); |
| 504 layer->SetContentsOpaque(contents_opaque_); | 492 layer->SetContentsOpaque(contents_opaque_); |
| 505 layer->SetOpacity(opacity_); | 493 layer->SetOpacity(opacity_); |
| 506 layer->SetBlendMode(blend_mode_); | 494 layer->SetBlendMode(blend_mode_); |
| 507 layer->SetIsRootForIsolatedGroup(is_root_for_isolated_group_); | |
| 508 layer->SetPosition(position_); | 495 layer->SetPosition(position_); |
| 509 layer->SetIsContainerForFixedPositionLayers( | |
| 510 is_container_for_fixed_position_layers_); | |
| 511 layer->SetPositionConstraint(position_constraint_); | |
| 512 layer->SetShouldFlattenTransform(should_flatten_transform_); | |
| 513 layer->set_should_flatten_transform_from_property_tree( | 496 layer->set_should_flatten_transform_from_property_tree( |
| 514 should_flatten_transform_from_property_tree_); | 497 should_flatten_transform_from_property_tree_); |
| 515 layer->set_draw_blend_mode(draw_blend_mode_); | 498 layer->set_draw_blend_mode(draw_blend_mode_); |
| 516 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 499 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
| 517 layer->SetUseLocalTransformForBackfaceVisibility( | 500 layer->SetUseLocalTransformForBackfaceVisibility( |
| 518 use_local_transform_for_backface_visibility_); | 501 use_local_transform_for_backface_visibility_); |
| 519 layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility_); | 502 layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility_); |
| 520 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); | 503 layer->SetTransform(transform_); |
| 521 if (layer_property_changed_) | 504 if (layer_property_changed_) |
| 522 layer->NoteLayerPropertyChanged(); | 505 layer->NoteLayerPropertyChanged(); |
| 523 | 506 |
| 524 layer->SetScrollClipLayer(scroll_clip_layer_id_); | 507 layer->SetScrollClipLayer(scroll_clip_layer_id_); |
| 525 layer->SetElementId(element_id_); | 508 layer->SetElementId(element_id_); |
| 526 layer->SetMutableProperties(mutable_properties_); | 509 layer->SetMutableProperties(mutable_properties_); |
| 527 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 510 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
| 528 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 511 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
| 529 | 512 |
| 530 layer->Set3dSortingContextId(sorting_context_id_); | 513 layer->Set3dSortingContextId(sorting_context_id_); |
| 531 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); | |
| 532 | 514 |
| 533 layer->SetTransformTreeIndex(transform_tree_index_); | 515 layer->SetTransformTreeIndex(transform_tree_index_); |
| 534 layer->SetClipTreeIndex(clip_tree_index_); | 516 layer->SetClipTreeIndex(clip_tree_index_); |
| 535 layer->SetEffectTreeIndex(effect_tree_index_); | 517 layer->SetEffectTreeIndex(effect_tree_index_); |
| 536 layer->SetScrollTreeIndex(scroll_tree_index_); | 518 layer->SetScrollTreeIndex(scroll_tree_index_); |
| 537 layer->set_offset_to_transform_parent(offset_to_transform_parent_); | 519 layer->set_offset_to_transform_parent(offset_to_transform_parent_); |
| 538 | 520 |
| 539 LayerImpl* scroll_parent = nullptr; | 521 LayerImpl* scroll_parent = nullptr; |
| 540 if (scroll_parent_) { | 522 if (scroll_parent_) { |
| 541 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 523 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1162 SetNeedsPushProperties(); | 1144 SetNeedsPushProperties(); |
| 1163 } | 1145 } |
| 1164 | 1146 |
| 1165 void LayerImpl::SetBlendMode(SkXfermode::Mode blend_mode) { | 1147 void LayerImpl::SetBlendMode(SkXfermode::Mode blend_mode) { |
| 1166 if (blend_mode_ == blend_mode) | 1148 if (blend_mode_ == blend_mode) |
| 1167 return; | 1149 return; |
| 1168 | 1150 |
| 1169 blend_mode_ = blend_mode; | 1151 blend_mode_ = blend_mode; |
| 1170 } | 1152 } |
| 1171 | 1153 |
| 1172 void LayerImpl::SetIsRootForIsolatedGroup(bool root) { | |
| 1173 if (is_root_for_isolated_group_ == root) | |
| 1174 return; | |
| 1175 | |
| 1176 is_root_for_isolated_group_ = root; | |
| 1177 SetNeedsPushProperties(); | |
| 1178 } | |
| 1179 | |
| 1180 void LayerImpl::SetPosition(const gfx::PointF& position) { | 1154 void LayerImpl::SetPosition(const gfx::PointF& position) { |
| 1181 if (position_ == position) | 1155 if (position_ == position) |
| 1182 return; | 1156 return; |
| 1183 | 1157 |
| 1184 position_ = position; | 1158 position_ = position; |
| 1185 } | 1159 } |
| 1186 | 1160 |
| 1187 void LayerImpl::SetShouldFlattenTransform(bool flatten) { | |
| 1188 if (should_flatten_transform_ == flatten) | |
| 1189 return; | |
| 1190 | |
| 1191 should_flatten_transform_ = flatten; | |
| 1192 } | |
| 1193 | |
| 1194 void LayerImpl::Set3dSortingContextId(int id) { | 1161 void LayerImpl::Set3dSortingContextId(int id) { |
| 1195 if (id == sorting_context_id_) | 1162 if (id == sorting_context_id_) |
| 1196 return; | 1163 return; |
| 1197 sorting_context_id_ = id; | 1164 sorting_context_id_ = id; |
| 1198 } | 1165 } |
| 1199 | 1166 |
| 1200 void LayerImpl::SetTransform(const gfx::Transform& transform) { | 1167 void LayerImpl::SetTransform(const gfx::Transform& transform) { |
| 1201 if (transform_ == transform) | 1168 if (transform_ == transform) |
| 1202 return; | 1169 return; |
| 1203 | 1170 |
| 1204 transform_ = transform; | 1171 transform_ = transform; |
| 1205 transform_is_invertible_ = transform_.IsInvertible(); | |
| 1206 } | |
| 1207 | |
| 1208 void LayerImpl::SetTransformAndInvertibility(const gfx::Transform& transform, | |
| 1209 bool transform_is_invertible) { | |
| 1210 if (transform_ == transform) { | |
| 1211 DCHECK(transform_is_invertible_ == transform_is_invertible) | |
| 1212 << "Can't change invertibility if transform is unchanged"; | |
| 1213 return; | |
| 1214 } | |
| 1215 transform_ = transform; | |
| 1216 transform_is_invertible_ = transform_is_invertible; | |
| 1217 } | 1172 } |
| 1218 | 1173 |
| 1219 bool LayerImpl::TransformIsAnimating() const { | 1174 bool LayerImpl::TransformIsAnimating() const { |
| 1220 return layer_tree_impl_->IsAnimatingTransformProperty(this); | 1175 return layer_tree_impl_->IsAnimatingTransformProperty(this); |
| 1221 } | 1176 } |
| 1222 | 1177 |
| 1223 bool LayerImpl::HasPotentiallyRunningTransformAnimation() const { | 1178 bool LayerImpl::HasPotentiallyRunningTransformAnimation() const { |
| 1224 return layer_tree_impl_->HasPotentiallyRunningTransformAnimation(this); | 1179 return layer_tree_impl_->HasPotentiallyRunningTransformAnimation(this); |
| 1225 } | 1180 } |
| 1226 | 1181 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1372 if (mutable_properties_ != MutableProperty::kNone) { | 1327 if (mutable_properties_ != MutableProperty::kNone) { |
| 1373 state->SetInteger("element_id", base::saturated_cast<int>(element_id_)); | 1328 state->SetInteger("element_id", base::saturated_cast<int>(element_id_)); |
| 1374 state->SetInteger("mutable_properties", mutable_properties_); | 1329 state->SetInteger("mutable_properties", mutable_properties_); |
| 1375 } | 1330 } |
| 1376 | 1331 |
| 1377 MathUtil::AddToTracedValue("scroll_offset", CurrentScrollOffset(), state); | 1332 MathUtil::AddToTracedValue("scroll_offset", CurrentScrollOffset(), state); |
| 1378 | 1333 |
| 1379 if (!transform().IsIdentity()) | 1334 if (!transform().IsIdentity()) |
| 1380 MathUtil::AddToTracedValue("transform", transform(), state); | 1335 MathUtil::AddToTracedValue("transform", transform(), state); |
| 1381 | 1336 |
| 1382 state->SetBoolean("should_flatten", should_flatten_transform_); | |
| 1383 | |
| 1384 bool clipped; | 1337 bool clipped; |
| 1385 gfx::QuadF layer_quad = | 1338 gfx::QuadF layer_quad = |
| 1386 MathUtil::MapQuad(ScreenSpaceTransform(), | 1339 MathUtil::MapQuad(ScreenSpaceTransform(), |
| 1387 gfx::QuadF(gfx::RectF(gfx::Rect(bounds()))), &clipped); | 1340 gfx::QuadF(gfx::RectF(gfx::Rect(bounds()))), &clipped); |
| 1388 MathUtil::AddToTracedValue("layer_quad", layer_quad, state); | 1341 MathUtil::AddToTracedValue("layer_quad", layer_quad, state); |
| 1389 if (!touch_event_handler_region_.IsEmpty()) { | 1342 if (!touch_event_handler_region_.IsEmpty()) { |
| 1390 state->BeginArray("touch_event_handler_region"); | 1343 state->BeginArray("touch_event_handler_region"); |
| 1391 touch_event_handler_region_.AsValueInto(state); | 1344 touch_event_handler_region_.AsValueInto(state); |
| 1392 state->EndArray(); | 1345 state->EndArray(); |
| 1393 } | 1346 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1455 return draw_properties_.last_drawn_render_surface_layer_list_id == | 1408 return draw_properties_.last_drawn_render_surface_layer_list_id == |
| 1456 layer_tree_impl_->current_render_surface_list_id(); | 1409 layer_tree_impl_->current_render_surface_list_id(); |
| 1457 } | 1410 } |
| 1458 | 1411 |
| 1459 size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; } | 1412 size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; } |
| 1460 | 1413 |
| 1461 void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { | 1414 void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { |
| 1462 benchmark->RunOnLayer(this); | 1415 benchmark->RunOnLayer(this); |
| 1463 } | 1416 } |
| 1464 | 1417 |
| 1465 int LayerImpl::NumDescendantsThatDrawContent() const { | |
| 1466 return num_descendants_that_draw_content_; | |
| 1467 } | |
| 1468 | |
| 1469 void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) { | 1418 void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) { |
| 1470 if (!!render_surface() == should_have_render_surface) | 1419 if (!!render_surface() == should_have_render_surface) |
| 1471 return; | 1420 return; |
| 1472 | 1421 |
| 1473 SetNeedsPushProperties(); | 1422 SetNeedsPushProperties(); |
| 1474 if (should_have_render_surface) { | 1423 if (should_have_render_surface) { |
| 1475 render_surface_ = base::WrapUnique(new RenderSurfaceImpl(this)); | 1424 render_surface_ = base::WrapUnique(new RenderSurfaceImpl(this)); |
| 1476 return; | 1425 return; |
| 1477 } | 1426 } |
| 1478 render_surface_.reset(); | 1427 render_surface_.reset(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1576 .layer_transforms_should_scale_layer_contents) { | 1525 .layer_transforms_should_scale_layer_contents) { |
| 1577 return default_scale; | 1526 return default_scale; |
| 1578 } | 1527 } |
| 1579 | 1528 |
| 1580 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( | 1529 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( |
| 1581 DrawTransform(), default_scale); | 1530 DrawTransform(), default_scale); |
| 1582 return std::max(transform_scales.x(), transform_scales.y()); | 1531 return std::max(transform_scales.x(), transform_scales.y()); |
| 1583 } | 1532 } |
| 1584 | 1533 |
| 1585 } // namespace cc | 1534 } // namespace cc |
| OLD | NEW |