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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 TRACE_EVENT_INSTANT0( | 335 TRACE_EVENT_INSTANT0( |
336 "cc", | 336 "cc", |
337 "LayerTreeHostCommon::SubtreeShouldRenderToSeparateSurface opacity", | 337 "LayerTreeHostCommon::SubtreeShouldRenderToSeparateSurface opacity", |
338 TRACE_EVENT_SCOPE_THREAD); | 338 TRACE_EVENT_SCOPE_THREAD); |
339 return true; | 339 return true; |
340 } | 340 } |
341 | 341 |
342 return false; | 342 return false; |
343 } | 343 } |
344 | 344 |
| 345 static LayerImpl* NextTargetSurface(LayerImpl* layer) { |
| 346 return layer->parent() ? layer->parent()->render_target() : 0; |
| 347 } |
| 348 |
| 349 // This function returns a translation matrix that can be applied on a vector |
| 350 // that's in the layer's target surface coordinate, while the position offset is |
| 351 // specified in some ancestor layer's coordinate. |
| 352 gfx::Transform ComputeSizeDeltaCompensation( |
| 353 LayerImpl* layer, |
| 354 LayerImpl* container, |
| 355 const gfx::Vector2dF& position_offset) { |
| 356 gfx::Transform result_transform; |
| 357 |
| 358 // To apply a translate in the container's layer space, |
| 359 // the following steps need to be done: |
| 360 // Step 1a. transform from target surface space to the container's target |
| 361 // surface space |
| 362 // Step 1b. transform from container's target surface space to the |
| 363 // container's layer space |
| 364 // Step 2. apply the compensation |
| 365 // Step 3. transform back to target surface space |
| 366 |
| 367 gfx::Transform target_surface_space_to_container_layer_space; |
| 368 // Calculate step 1a |
| 369 LayerImpl* container_target_surface = |
| 370 container ? container->render_target() : 0; |
| 371 for (LayerImpl* current_target_surface = NextTargetSurface(layer); |
| 372 current_target_surface && |
| 373 current_target_surface != container_target_surface; |
| 374 current_target_surface = NextTargetSurface(current_target_surface)) { |
| 375 // Note: Concat is used here to convert the result coordinate space from |
| 376 // current render surface to the next render surface. |
| 377 target_surface_space_to_container_layer_space.ConcatTransform( |
| 378 current_target_surface->render_surface()->draw_transform()); |
| 379 } |
| 380 // Calculate step 1b |
| 381 if (container) { |
| 382 gfx::Transform container_layer_space_to_container_target_surface_space = |
| 383 container->draw_transform(); |
| 384 container_layer_space_to_container_target_surface_space.Scale( |
| 385 container->contents_scale_x(), container->contents_scale_y()); |
| 386 |
| 387 gfx::Transform container_target_surface_space_to_container_layer_space; |
| 388 if (container_layer_space_to_container_target_surface_space.GetInverse( |
| 389 &container_target_surface_space_to_container_layer_space)) { |
| 390 // Note: Again, Concat is used to conver the result coordinate space from |
| 391 // the container render surface to the container layer. |
| 392 target_surface_space_to_container_layer_space.ConcatTransform( |
| 393 container_target_surface_space_to_container_layer_space); |
| 394 } |
| 395 } |
| 396 |
| 397 // Apply step 3 |
| 398 gfx::Transform container_layer_space_to_target_surface_space; |
| 399 if (target_surface_space_to_container_layer_space.GetInverse( |
| 400 &container_layer_space_to_target_surface_space)) |
| 401 result_transform.PreconcatTransform( |
| 402 container_layer_space_to_target_surface_space); |
| 403 else { |
| 404 // FIXME: A non-invertible matrix could still make meaningful projection. |
| 405 // For example ScaleZ(0) is non-invertible but the layer is still visible. |
| 406 return gfx::Transform(); |
| 407 } |
| 408 |
| 409 // Apply step 2 |
| 410 result_transform.Translate(position_offset.x(), position_offset.y()); |
| 411 |
| 412 // Apply step 1 |
| 413 result_transform.PreconcatTransform( |
| 414 target_surface_space_to_container_layer_space); |
| 415 |
| 416 return result_transform; |
| 417 } |
| 418 |
| 419 void ApplyPositionAdjustment( |
| 420 Layer* layer, |
| 421 Layer* container, |
| 422 const gfx::Transform& scroll_compensation, |
| 423 gfx::Transform* combined_transform) { } |
| 424 void ApplyPositionAdjustment( |
| 425 LayerImpl* layer, |
| 426 LayerImpl* container, |
| 427 const gfx::Transform& scroll_compensation, |
| 428 gfx::Transform* combined_transform) |
| 429 { |
| 430 if (!layer->position_constraint().is_fixed_position()) |
| 431 return; |
| 432 |
| 433 // Special case: this layer is a composited fixed-position layer; we need to |
| 434 // explicitly compensate for all ancestors' nonzero scroll_deltas to keep |
| 435 // this layer fixed correctly. |
| 436 // Note carefully: this is Concat, not Preconcat |
| 437 // (current_scroll_compensation * combined_transform). |
| 438 combined_transform->ConcatTransform(scroll_compensation); |
| 439 |
| 440 // For right-edge or bottom-edge anchored fixed position layers, |
| 441 // the layer should relocate itself if the container changes its size. |
| 442 bool fixed_to_right_edge = |
| 443 layer->position_constraint().is_fixed_to_right_edge(); |
| 444 bool fixed_to_bottom_edge = |
| 445 layer->position_constraint().is_fixed_to_bottom_edge(); |
| 446 gfx::Vector2dF position_offset = |
| 447 container ? container->fixed_container_size_delta() : gfx::Vector2dF(); |
| 448 position_offset.set_x(fixed_to_right_edge ? position_offset.x() : 0); |
| 449 position_offset.set_y(fixed_to_bottom_edge ? position_offset.y() : 0); |
| 450 if (position_offset.IsZero()) |
| 451 return; |
| 452 |
| 453 // Note: Again, this is Concat. The compensation matrix will be applied on |
| 454 // the vector in target surface space. |
| 455 combined_transform->ConcatTransform( |
| 456 ComputeSizeDeltaCompensation(layer, container, position_offset)); |
| 457 } |
| 458 |
345 gfx::Transform ComputeScrollCompensationForThisLayer( | 459 gfx::Transform ComputeScrollCompensationForThisLayer( |
346 LayerImpl* scrolling_layer, | 460 LayerImpl* scrolling_layer, |
347 const gfx::Transform& parent_matrix) { | 461 const gfx::Transform& parent_matrix) { |
348 // For every layer that has non-zero scroll_delta, we have to compute a | 462 // For every layer that has non-zero scroll_delta, we have to compute a |
349 // transform that can undo the scroll_delta translation. In particular, we | 463 // transform that can undo the scroll_delta translation. In particular, we |
350 // want this matrix to premultiply a fixed-position layer's parent_matrix, so | 464 // want this matrix to premultiply a fixed-position layer's parent_matrix, so |
351 // we design this transform in three steps as follows. The steps described | 465 // we design this transform in three steps as follows. The steps described |
352 // here apply from right-to-left, so Step 1 would be the right-most matrix: | 466 // here apply from right-to-left, so Step 1 would be the right-most matrix: |
353 // | 467 // |
354 // Step 1. transform from target surface space to the exact space where | 468 // Step 1. transform from target surface space to the exact space where |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 // - If the fixed-position layer has its own render_surface, then the | 532 // - If the fixed-position layer has its own render_surface, then the |
419 // render_surface is the one who gets fixed. | 533 // render_surface is the one who gets fixed. |
420 // | 534 // |
421 // This function needs to be called AFTER layers create their own | 535 // This function needs to be called AFTER layers create their own |
422 // render_surfaces. | 536 // render_surfaces. |
423 // | 537 // |
424 | 538 |
425 // Avoid the overheads (including stack allocation and matrix | 539 // Avoid the overheads (including stack allocation and matrix |
426 // initialization/copy) if we know that the scroll compensation doesn't need | 540 // initialization/copy) if we know that the scroll compensation doesn't need |
427 // to be reset or adjusted. | 541 // to be reset or adjusted. |
428 if (!layer->is_container_for_fixed_position_layers() && | 542 if (!layer->IsContainerForFixedPositionLayers() && |
429 layer->scroll_delta().IsZero() && !layer->render_surface()) | 543 layer->scroll_delta().IsZero() && !layer->render_surface()) |
430 return current_scroll_compensation_matrix; | 544 return current_scroll_compensation_matrix; |
431 | 545 |
432 // Start as identity matrix. | 546 // Start as identity matrix. |
433 gfx::Transform next_scroll_compensation_matrix; | 547 gfx::Transform next_scroll_compensation_matrix; |
434 | 548 |
435 // If this layer is not a container, then it inherits the existing scroll | 549 // If this layer is not a container, then it inherits the existing scroll |
436 // compensations. | 550 // compensations. |
437 if (!layer->is_container_for_fixed_position_layers()) | 551 if (!layer->IsContainerForFixedPositionLayers()) |
438 next_scroll_compensation_matrix = current_scroll_compensation_matrix; | 552 next_scroll_compensation_matrix = current_scroll_compensation_matrix; |
439 | 553 |
440 // If the current layer has a non-zero scroll_delta, then we should compute | 554 // If the current layer has a non-zero scroll_delta, then we should compute |
441 // its local scroll compensation and accumulate it to the | 555 // its local scroll compensation and accumulate it to the |
442 // next_scroll_compensation_matrix. | 556 // next_scroll_compensation_matrix. |
443 if (!layer->scroll_delta().IsZero()) { | 557 if (!layer->scroll_delta().IsZero()) { |
444 gfx::Transform scroll_compensation_for_this_layer = | 558 gfx::Transform scroll_compensation_for_this_layer = |
445 ComputeScrollCompensationForThisLayer(layer, parent_matrix); | 559 ComputeScrollCompensationForThisLayer(layer, parent_matrix); |
446 next_scroll_compensation_matrix.PreconcatTransform( | 560 next_scroll_compensation_matrix.PreconcatTransform( |
447 scroll_compensation_for_this_layer); | 561 scroll_compensation_for_this_layer); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 } | 743 } |
630 | 744 |
631 // Recursively walks the layer tree starting at the given node and computes all | 745 // Recursively walks the layer tree starting at the given node and computes all |
632 // the necessary transformations, clip rects, render surfaces, etc. | 746 // the necessary transformations, clip rects, render surfaces, etc. |
633 template <typename LayerType, typename LayerList, typename RenderSurfaceType> | 747 template <typename LayerType, typename LayerList, typename RenderSurfaceType> |
634 static void CalculateDrawPropertiesInternal( | 748 static void CalculateDrawPropertiesInternal( |
635 LayerType* layer, | 749 LayerType* layer, |
636 const gfx::Transform& parent_matrix, | 750 const gfx::Transform& parent_matrix, |
637 const gfx::Transform& full_hierarchy_matrix, | 751 const gfx::Transform& full_hierarchy_matrix, |
638 const gfx::Transform& current_scroll_compensation_matrix, | 752 const gfx::Transform& current_scroll_compensation_matrix, |
| 753 LayerType* current_fixed_container, |
639 gfx::Rect clip_rect_from_ancestor, | 754 gfx::Rect clip_rect_from_ancestor, |
640 gfx::Rect clip_rect_from_ancestor_in_descendant_space, | 755 gfx::Rect clip_rect_from_ancestor_in_descendant_space, |
641 bool ancestor_clips_subtree, | 756 bool ancestor_clips_subtree, |
642 RenderSurfaceType* nearest_ancestor_that_moves_pixels, | 757 RenderSurfaceType* nearest_ancestor_that_moves_pixels, |
643 LayerList* render_surface_layer_list, | 758 LayerList* render_surface_layer_list, |
644 LayerList* layer_list, | 759 LayerList* layer_list, |
645 LayerSorter* layer_sorter, | 760 LayerSorter* layer_sorter, |
646 int max_texture_size, | 761 int max_texture_size, |
647 float device_scale_factor, | 762 float device_scale_factor, |
648 float page_scale_factor, | 763 float page_scale_factor, |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 combined_transform.ConcatTransform(layer->impl_transform()); | 967 combined_transform.ConcatTransform(layer->impl_transform()); |
853 | 968 |
854 if (!animating_transform_to_target && layer->scrollable() && | 969 if (!animating_transform_to_target && layer->scrollable() && |
855 combined_transform.IsScaleOrTranslation()) { | 970 combined_transform.IsScaleOrTranslation()) { |
856 // Align the scrollable layer's position to screen space pixels to avoid | 971 // Align the scrollable layer's position to screen space pixels to avoid |
857 // blurriness. To avoid side-effects, do this only if the transform is | 972 // blurriness. To avoid side-effects, do this only if the transform is |
858 // simple. | 973 // simple. |
859 RoundTranslationComponents(&combined_transform); | 974 RoundTranslationComponents(&combined_transform); |
860 } | 975 } |
861 | 976 |
862 if (layer->fixed_to_container_layer()) { | 977 // Apply adjustment from position constraints. |
863 // Special case: this layer is a composited fixed-position layer; we need to | 978 ApplyPositionAdjustment(layer, current_fixed_container, |
864 // explicitly compensate for all ancestors' nonzero scroll_deltas to keep | 979 current_scroll_compensation_matrix, &combined_transform); |
865 // this layer fixed correctly. | |
866 // Note carefully: this is Concat, not Preconcat | |
867 // (current_scroll_compensation * combined_transform). | |
868 combined_transform.ConcatTransform(current_scroll_compensation_matrix); | |
869 } | |
870 | 980 |
871 // The draw_transform that gets computed below is effectively the layer's | 981 // The draw_transform that gets computed below is effectively the layer's |
872 // draw_transform, unless the layer itself creates a render_surface. In that | 982 // draw_transform, unless the layer itself creates a render_surface. In that |
873 // case, the render_surface re-parents the transforms. | 983 // case, the render_surface re-parents the transforms. |
874 layer_draw_properties.target_space_transform = combined_transform; | 984 layer_draw_properties.target_space_transform = combined_transform; |
875 // M[draw] = M[parent] * LT * S[layer2content] | 985 // M[draw] = M[parent] * LT * S[layer2content] |
876 layer_draw_properties.target_space_transform.Scale | 986 layer_draw_properties.target_space_transform.Scale |
877 (1.f / layer->contents_scale_x(), 1.f / layer->contents_scale_y()); | 987 (1.f / layer->contents_scale_x(), 1.f / layer->contents_scale_y()); |
878 | 988 |
879 // The layer's screen_space_transform represents the transform between root | 989 // The layer's screen_space_transform represents the transform between root |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 // Any layers that are appended after this point are in the layer's subtree | 1208 // Any layers that are appended after this point are in the layer's subtree |
1099 // and should be included in the sorting process. | 1209 // and should be included in the sorting process. |
1100 size_t sorting_start_index = descendants.size(); | 1210 size_t sorting_start_index = descendants.size(); |
1101 | 1211 |
1102 if (!LayerShouldBeSkipped(layer)) | 1212 if (!LayerShouldBeSkipped(layer)) |
1103 descendants.push_back(layer); | 1213 descendants.push_back(layer); |
1104 | 1214 |
1105 gfx::Transform next_scroll_compensation_matrix = | 1215 gfx::Transform next_scroll_compensation_matrix = |
1106 ComputeScrollCompensationMatrixForChildren( | 1216 ComputeScrollCompensationMatrixForChildren( |
1107 layer, parent_matrix, current_scroll_compensation_matrix); | 1217 layer, parent_matrix, current_scroll_compensation_matrix); |
| 1218 LayerType* next_fixed_container = |
| 1219 layer->IsContainerForFixedPositionLayers() ? |
| 1220 layer : current_fixed_container; |
1108 | 1221 |
1109 gfx::Rect accumulated_drawable_content_rect_of_children; | 1222 gfx::Rect accumulated_drawable_content_rect_of_children; |
1110 for (size_t i = 0; i < layer->children().size(); ++i) { | 1223 for (size_t i = 0; i < layer->children().size(); ++i) { |
1111 LayerType* child = | 1224 LayerType* child = |
1112 LayerTreeHostCommon::get_child_as_raw_ptr(layer->children(), i); | 1225 LayerTreeHostCommon::get_child_as_raw_ptr(layer->children(), i); |
1113 gfx::Rect drawable_content_rect_of_child_subtree; | 1226 gfx::Rect drawable_content_rect_of_child_subtree; |
1114 CalculateDrawPropertiesInternal<LayerType, LayerList, RenderSurfaceType>( | 1227 CalculateDrawPropertiesInternal<LayerType, LayerList, RenderSurfaceType>( |
1115 child, | 1228 child, |
1116 sublayer_matrix, | 1229 sublayer_matrix, |
1117 next_hierarchy_matrix, | 1230 next_hierarchy_matrix, |
1118 next_scroll_compensation_matrix, | 1231 next_scroll_compensation_matrix, |
| 1232 next_fixed_container, |
1119 clip_rect_for_subtree, | 1233 clip_rect_for_subtree, |
1120 clip_rect_for_subtree_in_descendant_space, | 1234 clip_rect_for_subtree_in_descendant_space, |
1121 subtree_should_be_clipped, | 1235 subtree_should_be_clipped, |
1122 nearest_ancestor_that_moves_pixels, | 1236 nearest_ancestor_that_moves_pixels, |
1123 render_surface_layer_list, | 1237 render_surface_layer_list, |
1124 &descendants, | 1238 &descendants, |
1125 layer_sorter, | 1239 layer_sorter, |
1126 max_texture_size, | 1240 max_texture_size, |
1127 device_scale_factor, | 1241 device_scale_factor, |
1128 page_scale_factor, | 1242 page_scale_factor, |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 // This function should have received a root layer. | 1430 // This function should have received a root layer. |
1317 DCHECK(IsRootLayer(root_layer)); | 1431 DCHECK(IsRootLayer(root_layer)); |
1318 | 1432 |
1319 PreCalculateMetaInformation<Layer>(root_layer); | 1433 PreCalculateMetaInformation<Layer>(root_layer); |
1320 CalculateDrawPropertiesInternal<Layer, | 1434 CalculateDrawPropertiesInternal<Layer, |
1321 LayerList, | 1435 LayerList, |
1322 RenderSurface>(root_layer, | 1436 RenderSurface>(root_layer, |
1323 device_scale_transform, | 1437 device_scale_transform, |
1324 identity_matrix, | 1438 identity_matrix, |
1325 identity_matrix, | 1439 identity_matrix, |
| 1440 NULL, |
1326 device_viewport_rect, | 1441 device_viewport_rect, |
1327 device_viewport_rect, | 1442 device_viewport_rect, |
1328 subtree_should_be_clipped, | 1443 subtree_should_be_clipped, |
1329 NULL, | 1444 NULL, |
1330 render_surface_layer_list, | 1445 render_surface_layer_list, |
1331 &dummy_layer_list, | 1446 &dummy_layer_list, |
1332 NULL, | 1447 NULL, |
1333 max_texture_size, | 1448 max_texture_size, |
1334 device_scale_factor, | 1449 device_scale_factor, |
1335 page_scale_factor, | 1450 page_scale_factor, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 DCHECK(IsRootLayer(root_layer)); | 1484 DCHECK(IsRootLayer(root_layer)); |
1370 | 1485 |
1371 PreCalculateMetaInformation<LayerImpl>(root_layer); | 1486 PreCalculateMetaInformation<LayerImpl>(root_layer); |
1372 CalculateDrawPropertiesInternal<LayerImpl, | 1487 CalculateDrawPropertiesInternal<LayerImpl, |
1373 LayerImplList, | 1488 LayerImplList, |
1374 RenderSurfaceImpl>( | 1489 RenderSurfaceImpl>( |
1375 root_layer, | 1490 root_layer, |
1376 device_scale_transform, | 1491 device_scale_transform, |
1377 identity_matrix, | 1492 identity_matrix, |
1378 identity_matrix, | 1493 identity_matrix, |
| 1494 NULL, |
1379 device_viewport_rect, | 1495 device_viewport_rect, |
1380 device_viewport_rect, | 1496 device_viewport_rect, |
1381 subtree_should_be_clipped, | 1497 subtree_should_be_clipped, |
1382 NULL, | 1498 NULL, |
1383 render_surface_layer_list, | 1499 render_surface_layer_list, |
1384 &dummy_layer_list, | 1500 &dummy_layer_list, |
1385 &layer_sorter, | 1501 &layer_sorter, |
1386 max_texture_size, | 1502 max_texture_size, |
1387 device_scale_factor, | 1503 device_scale_factor, |
1388 page_scale_factor, | 1504 page_scale_factor, |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1582 // At this point, we think the point does hit the touch event handler region | 1698 // At this point, we think the point does hit the touch event handler region |
1583 // on the layer, but we need to walk up the parents to ensure that the layer | 1699 // on the layer, but we need to walk up the parents to ensure that the layer |
1584 // was not clipped in such a way that the hit point actually should not hit | 1700 // was not clipped in such a way that the hit point actually should not hit |
1585 // the layer. | 1701 // the layer. |
1586 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) | 1702 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) |
1587 return false; | 1703 return false; |
1588 | 1704 |
1589 return true; | 1705 return true; |
1590 } | 1706 } |
1591 } // namespace cc | 1707 } // namespace cc |
OLD | NEW |