| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_tree_host_common.h" | 5 #include "cc/trees/layer_tree_host_common.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 DCHECK_EQ(scrolls.size(), 0u); | 181 DCHECK_EQ(scrolls.size(), 0u); |
| 182 for (int i = 0; i < proto.scrolls_size(); ++i) { | 182 for (int i = 0; i < proto.scrolls_size(); ++i) { |
| 183 scrolls.push_back(LayerTreeHostCommon::ScrollUpdateInfo()); | 183 scrolls.push_back(LayerTreeHostCommon::ScrollUpdateInfo()); |
| 184 scrolls[i].FromProtobuf(proto.scrolls(i)); | 184 scrolls[i].FromProtobuf(proto.scrolls(i)); |
| 185 } | 185 } |
| 186 page_scale_delta = proto.page_scale_delta(); | 186 page_scale_delta = proto.page_scale_delta(); |
| 187 elastic_overscroll_delta = ProtoToVector2dF(proto.elastic_overscroll_delta()); | 187 elastic_overscroll_delta = ProtoToVector2dF(proto.elastic_overscroll_delta()); |
| 188 top_controls_delta = proto.top_controls_delta(); | 188 top_controls_delta = proto.top_controls_delta(); |
| 189 } | 189 } |
| 190 | 190 |
| 191 static inline bool IsRootLayer(const Layer* layer) { | |
| 192 return !layer->parent(); | |
| 193 } | |
| 194 | |
| 195 static bool HasInvertibleOrAnimatedTransform(Layer* layer) { | |
| 196 return layer->transform_is_invertible() || | |
| 197 layer->HasPotentiallyRunningTransformAnimation(); | |
| 198 } | |
| 199 | |
| 200 static bool HasInvertibleOrAnimatedTransformForTesting(LayerImpl* layer) { | |
| 201 return layer->transform().IsInvertible() || | |
| 202 layer->HasPotentiallyRunningTransformAnimation(); | |
| 203 } | |
| 204 | 191 |
| 205 static inline void SetMaskLayersAreDrawnRenderSurfaceLayerListMembers( | 192 static inline void SetMaskLayersAreDrawnRenderSurfaceLayerListMembers( |
| 206 LayerImpl* layer) { | 193 LayerImpl* layer) { |
| 207 if (layer->mask_layer()) | 194 if (layer->mask_layer()) |
| 208 layer->mask_layer()->set_is_drawn_render_surface_layer_list_member(true); | 195 layer->mask_layer()->set_is_drawn_render_surface_layer_list_member(true); |
| 209 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) { | 196 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) { |
| 210 layer->replica_layer() | 197 layer->replica_layer() |
| 211 ->mask_layer() | 198 ->mask_layer() |
| 212 ->set_is_drawn_render_surface_layer_list_member(true); | 199 ->set_is_drawn_render_surface_layer_list_member(true); |
| 213 } | 200 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 233 DCHECK_GT(scroll_tree->Node(layer->scroll_tree_index()) | 220 DCHECK_GT(scroll_tree->Node(layer->scroll_tree_index()) |
| 234 ->data.num_drawn_descendants, | 221 ->data.num_drawn_descendants, |
| 235 0); | 222 0); |
| 236 scroll_tree->Node(layer->scroll_tree_index()) | 223 scroll_tree->Node(layer->scroll_tree_index()) |
| 237 ->data.num_drawn_descendants--; | 224 ->data.num_drawn_descendants--; |
| 238 } | 225 } |
| 239 ClearLayerIsDrawnRenderSurfaceLayerListMember(layer); | 226 ClearLayerIsDrawnRenderSurfaceLayerListMember(layer); |
| 240 } | 227 } |
| 241 } | 228 } |
| 242 | 229 |
| 243 struct PreCalculateMetaInformationRecursiveData { | |
| 244 size_t num_unclipped_descendants; | |
| 245 int num_layer_or_descendants_with_copy_request; | |
| 246 int num_layer_or_descendants_with_touch_handler; | |
| 247 int num_descendants_that_draw_content; | |
| 248 | |
| 249 PreCalculateMetaInformationRecursiveData() | |
| 250 : num_unclipped_descendants(0), | |
| 251 num_layer_or_descendants_with_copy_request(0), | |
| 252 num_layer_or_descendants_with_touch_handler(0), | |
| 253 num_descendants_that_draw_content(0) {} | |
| 254 | |
| 255 void Merge(const PreCalculateMetaInformationRecursiveData& data) { | |
| 256 num_layer_or_descendants_with_copy_request += | |
| 257 data.num_layer_or_descendants_with_copy_request; | |
| 258 num_layer_or_descendants_with_touch_handler += | |
| 259 data.num_layer_or_descendants_with_touch_handler; | |
| 260 num_unclipped_descendants += data.num_unclipped_descendants; | |
| 261 num_descendants_that_draw_content += data.num_descendants_that_draw_content; | |
| 262 } | |
| 263 }; | |
| 264 | |
| 265 static bool IsMetaInformationRecomputationNeeded(Layer* layer) { | |
| 266 return layer->layer_tree_host()->needs_meta_info_recomputation(); | |
| 267 } | |
| 268 | |
| 269 static void UpdateMetaInformationSequenceNumber(Layer* root_layer) { | |
| 270 root_layer->layer_tree_host()->IncrementMetaInformationSequenceNumber(); | |
| 271 } | |
| 272 | |
| 273 // Recursively walks the layer tree(if needed) to compute any information | |
| 274 // that is needed before doing the main recursion. | |
| 275 static void PreCalculateMetaInformationInternal( | |
| 276 Layer* layer, | |
| 277 PreCalculateMetaInformationRecursiveData* recursive_data) { | |
| 278 if (!IsMetaInformationRecomputationNeeded(layer)) { | |
| 279 DCHECK(IsRootLayer(layer)); | |
| 280 return; | |
| 281 } | |
| 282 | |
| 283 if (layer->clip_parent()) | |
| 284 recursive_data->num_unclipped_descendants++; | |
| 285 | |
| 286 if (!HasInvertibleOrAnimatedTransform(layer)) { | |
| 287 // Layers with singular transforms should not be drawn, the whole subtree | |
| 288 // can be skipped. | |
| 289 return; | |
| 290 } | |
| 291 | |
| 292 for (size_t i = 0; i < layer->children().size(); ++i) { | |
| 293 Layer* child_layer = layer->child_at(i); | |
| 294 | |
| 295 PreCalculateMetaInformationRecursiveData data_for_child; | |
| 296 PreCalculateMetaInformationInternal(child_layer, &data_for_child); | |
| 297 recursive_data->Merge(data_for_child); | |
| 298 } | |
| 299 | |
| 300 if (layer->clip_children()) { | |
| 301 size_t num_clip_children = layer->clip_children()->size(); | |
| 302 DCHECK_GE(recursive_data->num_unclipped_descendants, num_clip_children); | |
| 303 recursive_data->num_unclipped_descendants -= num_clip_children; | |
| 304 } | |
| 305 | |
| 306 if (layer->HasCopyRequest()) | |
| 307 recursive_data->num_layer_or_descendants_with_copy_request++; | |
| 308 | |
| 309 if (!layer->touch_event_handler_region().IsEmpty()) | |
| 310 recursive_data->num_layer_or_descendants_with_touch_handler++; | |
| 311 | |
| 312 layer->set_num_unclipped_descendants( | |
| 313 recursive_data->num_unclipped_descendants); | |
| 314 | |
| 315 if (IsRootLayer(layer)) | |
| 316 layer->layer_tree_host()->SetNeedsMetaInfoRecomputation(false); | |
| 317 } | |
| 318 | |
| 319 static void PreCalculateMetaInformationInternalForTesting( | |
| 320 LayerImpl* layer, | |
| 321 PreCalculateMetaInformationRecursiveData* recursive_data) { | |
| 322 if (layer->test_properties()->clip_parent) | |
| 323 recursive_data->num_unclipped_descendants++; | |
| 324 | |
| 325 if (!HasInvertibleOrAnimatedTransformForTesting(layer)) { | |
| 326 // Layers with singular transforms should not be drawn, the whole subtree | |
| 327 // can be skipped. | |
| 328 return; | |
| 329 } | |
| 330 | |
| 331 for (size_t i = 0; i < layer->children().size(); ++i) { | |
| 332 LayerImpl* child_layer = layer->child_at(i); | |
| 333 | |
| 334 PreCalculateMetaInformationRecursiveData data_for_child; | |
| 335 PreCalculateMetaInformationInternalForTesting(child_layer, &data_for_child); | |
| 336 recursive_data->Merge(data_for_child); | |
| 337 } | |
| 338 | |
| 339 if (layer->test_properties()->clip_children) { | |
| 340 size_t num_clip_children = layer->test_properties()->clip_children->size(); | |
| 341 DCHECK_GE(recursive_data->num_unclipped_descendants, num_clip_children); | |
| 342 recursive_data->num_unclipped_descendants -= num_clip_children; | |
| 343 } | |
| 344 | |
| 345 if (layer->HasCopyRequest()) | |
| 346 recursive_data->num_layer_or_descendants_with_copy_request++; | |
| 347 | |
| 348 if (!layer->touch_event_handler_region().IsEmpty()) | |
| 349 recursive_data->num_layer_or_descendants_with_touch_handler++; | |
| 350 | |
| 351 layer->draw_properties().num_unclipped_descendants = | |
| 352 recursive_data->num_unclipped_descendants; | |
| 353 layer->set_layer_or_descendant_has_touch_handler( | |
| 354 (recursive_data->num_layer_or_descendants_with_touch_handler != 0)); | |
| 355 // TODO(enne): this should be synced from the main thread, so is only | |
| 356 // for tests constructing layers on the compositor thread. | |
| 357 layer->test_properties()->num_descendants_that_draw_content = | |
| 358 recursive_data->num_descendants_that_draw_content; | |
| 359 | |
| 360 if (layer->DrawsContent()) | |
| 361 recursive_data->num_descendants_that_draw_content++; | |
| 362 } | |
| 363 | |
| 364 void LayerTreeHostCommon::PreCalculateMetaInformation(Layer* root_layer) { | |
| 365 PreCalculateMetaInformationRecursiveData recursive_data; | |
| 366 PreCalculateMetaInformationInternal(root_layer, &recursive_data); | |
| 367 } | |
| 368 | |
| 369 void LayerTreeHostCommon::PreCalculateMetaInformationForTesting( | |
| 370 LayerImpl* root_layer) { | |
| 371 PreCalculateMetaInformationRecursiveData recursive_data; | |
| 372 PreCalculateMetaInformationInternalForTesting(root_layer, &recursive_data); | |
| 373 } | |
| 374 | |
| 375 void LayerTreeHostCommon::PreCalculateMetaInformationForTesting( | |
| 376 Layer* root_layer) { | |
| 377 UpdateMetaInformationSequenceNumber(root_layer); | |
| 378 PreCalculateMetaInformationRecursiveData recursive_data; | |
| 379 PreCalculateMetaInformationInternal(root_layer, &recursive_data); | |
| 380 } | |
| 381 | |
| 382 static bool CdpPerfTracingEnabled() { | 230 static bool CdpPerfTracingEnabled() { |
| 383 bool tracing_enabled; | 231 bool tracing_enabled; |
| 384 TRACE_EVENT_CATEGORY_GROUP_ENABLED("cdp.perf", &tracing_enabled); | 232 TRACE_EVENT_CATEGORY_GROUP_ENABLED("cdp.perf", &tracing_enabled); |
| 385 return tracing_enabled; | 233 return tracing_enabled; |
| 386 } | 234 } |
| 387 | 235 |
| 388 static float TranslationFromActiveTreeLayerScreenSpaceTransform( | 236 static float TranslationFromActiveTreeLayerScreenSpaceTransform( |
| 389 LayerImpl* pending_tree_layer) { | 237 LayerImpl* pending_tree_layer) { |
| 390 LayerTreeImpl* layer_tree_impl = pending_tree_layer->layer_tree_impl(); | 238 LayerTreeImpl* layer_tree_impl = pending_tree_layer->layer_tree_impl(); |
| 391 if (layer_tree_impl) { | 239 if (layer_tree_impl) { |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 inputs->root_layer->layer_tree_impl()->set_is_first_frame_after_commit( | 683 inputs->root_layer->layer_tree_impl()->set_is_first_frame_after_commit( |
| 836 false); | 684 false); |
| 837 TRACE_EVENT_ASYNC_END1( | 685 TRACE_EVENT_ASYNC_END1( |
| 838 "cdp.perf", "jitter", | 686 "cdp.perf", "jitter", |
| 839 inputs->root_layer->layer_tree_impl()->source_frame_number(), "value", | 687 inputs->root_layer->layer_tree_impl()->source_frame_number(), "value", |
| 840 jitter); | 688 jitter); |
| 841 } | 689 } |
| 842 } | 690 } |
| 843 } | 691 } |
| 844 | 692 |
| 845 void LayerTreeHostCommon::CalculateDrawProperties( | 693 void LayerTreeHostCommon::CalculateDrawPropertiesForTesting( |
| 846 CalcDrawPropsImplInputsForTesting* inputs) { | 694 CalcDrawPropsImplInputsForTesting* inputs) { |
| 847 PreCalculateMetaInformationRecursiveData recursive_data; | 695 PropertyTreeBuilder::PreCalculateMetaInformationForTesting( |
| 848 PreCalculateMetaInformationInternalForTesting(inputs->root_layer, | 696 inputs->root_layer); |
| 849 &recursive_data); | |
| 850 CalculateDrawPropertiesInternal(inputs, BUILD_PROPERTY_TREES_IF_NEEDED); | 697 CalculateDrawPropertiesInternal(inputs, BUILD_PROPERTY_TREES_IF_NEEDED); |
| 851 } | 698 } |
| 852 | 699 |
| 853 PropertyTrees* GetPropertyTrees(Layer* layer) { | 700 PropertyTrees* GetPropertyTrees(Layer* layer) { |
| 854 return layer->layer_tree_host()->property_trees(); | 701 return layer->layer_tree_host()->property_trees(); |
| 855 } | 702 } |
| 856 | 703 |
| 857 PropertyTrees* GetPropertyTrees(LayerImpl* layer) { | 704 PropertyTrees* GetPropertyTrees(LayerImpl* layer) { |
| 858 return layer->layer_tree_impl()->property_trees(); | 705 return layer->layer_tree_impl()->property_trees(); |
| 859 } | 706 } |
| 860 | 707 |
| 861 } // namespace cc | 708 } // namespace cc |
| OLD | NEW |