Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Side by Side Diff: cc/trees/layer_tree_host_common.cc

Issue 15579002: Implement transform/clip support for Android WebView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Turn on fuzzy comparator for new SoftwareRenderer tests Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 // the following steps need to be done: 399 // the following steps need to be done:
400 // Step 1a. transform from target surface space to the container's target 400 // Step 1a. transform from target surface space to the container's target
401 // surface space 401 // surface space
402 // Step 1b. transform from container's target surface space to the 402 // Step 1b. transform from container's target surface space to the
403 // container's layer space 403 // container's layer space
404 // Step 2. apply the compensation 404 // Step 2. apply the compensation
405 // Step 3. transform back to target surface space 405 // Step 3. transform back to target surface space
406 406
407 gfx::Transform target_surface_space_to_container_layer_space; 407 gfx::Transform target_surface_space_to_container_layer_space;
408 // Calculate step 1a 408 // Calculate step 1a
409 LayerImpl* container_target_surface = 409 LayerImpl* container_target_surface = container->render_target();
410 container ? container->render_target() : 0;
411 for (LayerImpl* current_target_surface = NextTargetSurface(layer); 410 for (LayerImpl* current_target_surface = NextTargetSurface(layer);
412 current_target_surface && 411 current_target_surface &&
413 current_target_surface != container_target_surface; 412 current_target_surface != container_target_surface;
414 current_target_surface = NextTargetSurface(current_target_surface)) { 413 current_target_surface = NextTargetSurface(current_target_surface)) {
415 // Note: Concat is used here to convert the result coordinate space from 414 // Note: Concat is used here to convert the result coordinate space from
416 // current render surface to the next render surface. 415 // current render surface to the next render surface.
417 target_surface_space_to_container_layer_space.ConcatTransform( 416 target_surface_space_to_container_layer_space.ConcatTransform(
418 current_target_surface->render_surface()->draw_transform()); 417 current_target_surface->render_surface()->draw_transform());
419 } 418 }
420 // Calculate step 1b 419 // Calculate step 1b
421 if (container) { 420 gfx::Transform container_layer_space_to_container_target_surface_space =
422 gfx::Transform container_layer_space_to_container_target_surface_space = 421 container->draw_transform();
423 container->draw_transform(); 422 container_layer_space_to_container_target_surface_space.Scale(
424 container_layer_space_to_container_target_surface_space.Scale( 423 container->contents_scale_x(), container->contents_scale_y());
425 container->contents_scale_x(), container->contents_scale_y());
426 424
427 gfx::Transform container_target_surface_space_to_container_layer_space; 425 gfx::Transform container_target_surface_space_to_container_layer_space;
428 if (container_layer_space_to_container_target_surface_space.GetInverse( 426 if (container_layer_space_to_container_target_surface_space.GetInverse(
429 &container_target_surface_space_to_container_layer_space)) { 427 &container_target_surface_space_to_container_layer_space)) {
430 // Note: Again, Concat is used to conver the result coordinate space from 428 // Note: Again, Concat is used to conver the result coordinate space from
431 // the container render surface to the container layer. 429 // the container render surface to the container layer.
432 target_surface_space_to_container_layer_space.ConcatTransform( 430 target_surface_space_to_container_layer_space.ConcatTransform(
433 container_target_surface_space_to_container_layer_space); 431 container_target_surface_space_to_container_layer_space);
434 }
435 } 432 }
436 433
437 // Apply step 3 434 // Apply step 3
438 gfx::Transform container_layer_space_to_target_surface_space; 435 gfx::Transform container_layer_space_to_target_surface_space;
439 if (target_surface_space_to_container_layer_space.GetInverse( 436 if (target_surface_space_to_container_layer_space.GetInverse(
440 &container_layer_space_to_target_surface_space)) { 437 &container_layer_space_to_target_surface_space)) {
441 result_transform.PreconcatTransform( 438 result_transform.PreconcatTransform(
442 container_layer_space_to_target_surface_space); 439 container_layer_space_to_target_surface_space);
443 } else { 440 } else {
444 // FIXME: A non-invertible matrix could still make meaningful projection. 441 // FIXME: A non-invertible matrix could still make meaningful projection.
(...skipping 30 matching lines...) Expand all
475 // Note carefully: this is Concat, not Preconcat 472 // Note carefully: this is Concat, not Preconcat
476 // (current_scroll_compensation * combined_transform). 473 // (current_scroll_compensation * combined_transform).
477 combined_transform->ConcatTransform(scroll_compensation); 474 combined_transform->ConcatTransform(scroll_compensation);
478 475
479 // For right-edge or bottom-edge anchored fixed position layers, 476 // For right-edge or bottom-edge anchored fixed position layers,
480 // the layer should relocate itself if the container changes its size. 477 // the layer should relocate itself if the container changes its size.
481 bool fixed_to_right_edge = 478 bool fixed_to_right_edge =
482 layer->position_constraint().is_fixed_to_right_edge(); 479 layer->position_constraint().is_fixed_to_right_edge();
483 bool fixed_to_bottom_edge = 480 bool fixed_to_bottom_edge =
484 layer->position_constraint().is_fixed_to_bottom_edge(); 481 layer->position_constraint().is_fixed_to_bottom_edge();
485 gfx::Vector2dF position_offset = 482 gfx::Vector2dF position_offset = container->fixed_container_size_delta();
486 container ? container->fixed_container_size_delta() : gfx::Vector2dF();
487 position_offset.set_x(fixed_to_right_edge ? position_offset.x() : 0); 483 position_offset.set_x(fixed_to_right_edge ? position_offset.x() : 0);
488 position_offset.set_y(fixed_to_bottom_edge ? position_offset.y() : 0); 484 position_offset.set_y(fixed_to_bottom_edge ? position_offset.y() : 0);
489 if (position_offset.IsZero()) 485 if (position_offset.IsZero())
490 return; 486 return;
491 487
492 // Note: Again, this is Concat. The compensation matrix will be applied on 488 // Note: Again, this is Concat. The compensation matrix will be applied on
493 // the vector in target surface space. 489 // the vector in target surface space.
494 combined_transform->ConcatTransform( 490 combined_transform->ConcatTransform(
495 ComputeSizeDeltaCompensation(layer, container, position_offset)); 491 ComputeSizeDeltaCompensation(layer, container, position_offset));
496 } 492 }
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 if (!layer->double_sided() && TransformToParentIsKnown(layer) && 1104 if (!layer->double_sided() && TransformToParentIsKnown(layer) &&
1109 IsSurfaceBackFaceVisible(layer, combined_transform)) 1105 IsSurfaceBackFaceVisible(layer, combined_transform))
1110 return; 1106 return;
1111 1107
1112 if (!layer->render_surface()) 1108 if (!layer->render_surface())
1113 layer->CreateRenderSurface(); 1109 layer->CreateRenderSurface();
1114 1110
1115 RenderSurfaceType* render_surface = layer->render_surface(); 1111 RenderSurfaceType* render_surface = layer->render_surface();
1116 render_surface->ClearLayerLists(); 1112 render_surface->ClearLayerLists();
1117 1113
1118 // The owning layer's draw transform has a scale from content to layer 1114 if (IsRootLayer(layer)) {
1119 // space which we do not want; so here we use the combined_transform 1115 // The root layer's render surface size is predetermined and so the root
1120 // instead of the draw_transform. However, we do need to add a different 1116 // layer can't directly support non-identity transforms. It should just
1121 // scale factor that accounts for the surface's pixel dimensions. 1117 // forward top-level transforms to the rest of the tree.
1122 combined_transform.Scale(1.0 / render_surface_sublayer_scale.x(), 1118 sublayer_matrix = combined_transform;
1123 1.0 / render_surface_sublayer_scale.y()); 1119 } else {
1124 render_surface->SetDrawTransform(combined_transform); 1120 // The owning layer's draw transform has a scale from content to layer
1121 // space which we do not want; so here we use the combined_transform
1122 // instead of the draw_transform. However, we do need to add a different
1123 // scale factor that accounts for the surface's pixel dimensions.
1124 combined_transform.Scale(1.0 / render_surface_sublayer_scale.x(),
1125 1.0 / render_surface_sublayer_scale.y());
1126 render_surface->SetDrawTransform(combined_transform);
1125 1127
1126 // If this is the root layer, there should be no scale in the surface's draw 1128 // The owning layer's transform was re-parented by the surface, so the
1127 // transform. 1129 // layer's new draw_transform only needs to scale the layer to surface
1128 if (IsRootLayer(layer)) { 1130 // space.
1129 DCHECK_EQ(render_surface_sublayer_scale.x(), 1131 layer_draw_properties.target_space_transform.MakeIdentity();
1130 combined_transform_scales.x()); 1132 layer_draw_properties.target_space_transform.
1131 DCHECK_EQ(render_surface_sublayer_scale.y(), 1133 Scale(render_surface_sublayer_scale.x() / layer->contents_scale_x(),
1132 combined_transform_scales.y()); 1134 render_surface_sublayer_scale.y() / layer->contents_scale_y());
1135
1136 // Inside the surface's subtree, we scale everything to the owning layer's
1137 // scale. The sublayer matrix transforms layer rects into target surface
1138 // content space. Conceptually, all layers in the subtree inherit the
1139 // scale at the point of the render surface in the transform hierarchy,
1140 // but we apply it explicitly to the owning layer and the remainder of the
1141 // subtree independently.
1142 DCHECK(sublayer_matrix.IsIdentity());
1143 sublayer_matrix.Scale(render_surface_sublayer_scale.x(),
1144 render_surface_sublayer_scale.y());
1133 } 1145 }
1134 1146
1135 // The owning layer's transform was re-parented by the surface, so the
1136 // layer's new draw_transform only needs to scale the layer to surface
1137 // space.
1138 layer_draw_properties.target_space_transform.MakeIdentity();
1139 layer_draw_properties.target_space_transform.
1140 Scale(render_surface_sublayer_scale.x() / layer->contents_scale_x(),
1141 render_surface_sublayer_scale.y() / layer->contents_scale_y());
1142
1143 // Inside the surface's subtree, we scale everything to the owning layer's
1144 // scale. The sublayer matrix transforms layer rects into target surface
1145 // content space. Conceptually, all layers in the subtree inherit the scale
1146 // at the point of the render surface in the transform hierarchy, but we
1147 // apply it explicitly to the owning layer and the remainder of the subtree
1148 // indenpendently.
1149 DCHECK(sublayer_matrix.IsIdentity());
1150 sublayer_matrix.Scale(render_surface_sublayer_scale.x(),
1151 render_surface_sublayer_scale.y());
1152
1153 // The opacity value is moved from the layer to its surface, so that the 1147 // The opacity value is moved from the layer to its surface, so that the
1154 // entire subtree properly inherits opacity. 1148 // entire subtree properly inherits opacity.
1155 render_surface->SetDrawOpacity(accumulated_draw_opacity); 1149 render_surface->SetDrawOpacity(accumulated_draw_opacity);
1156 render_surface->SetDrawOpacityIsAnimating(animating_opacity_to_target); 1150 render_surface->SetDrawOpacityIsAnimating(animating_opacity_to_target);
1157 animating_opacity_to_target = false; 1151 animating_opacity_to_target = false;
1158 layer_draw_properties.opacity = 1.f; 1152 layer_draw_properties.opacity = 1.f;
1159 layer_draw_properties.opacity_is_animating = animating_opacity_to_target; 1153 layer_draw_properties.opacity_is_animating = animating_opacity_to_target;
1160 layer_draw_properties.screen_space_opacity_is_animating = 1154 layer_draw_properties.screen_space_opacity_is_animating =
1161 animating_opacity_to_screen; 1155 animating_opacity_to_screen;
1162 1156
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 current_scroll_compensation_matrix); 1324 current_scroll_compensation_matrix);
1331 LayerType* next_fixed_container = 1325 LayerType* next_fixed_container =
1332 layer->IsContainerForFixedPositionLayers() ? 1326 layer->IsContainerForFixedPositionLayers() ?
1333 layer : current_fixed_container; 1327 layer : current_fixed_container;
1334 1328
1335 gfx::Rect accumulated_drawable_content_rect_of_children; 1329 gfx::Rect accumulated_drawable_content_rect_of_children;
1336 for (size_t i = 0; i < layer->children().size(); ++i) { 1330 for (size_t i = 0; i < layer->children().size(); ++i) {
1337 LayerType* child = 1331 LayerType* child =
1338 LayerTreeHostCommon::get_child_as_raw_ptr(layer->children(), i); 1332 LayerTreeHostCommon::get_child_as_raw_ptr(layer->children(), i);
1339 gfx::Rect drawable_content_rect_of_child_subtree; 1333 gfx::Rect drawable_content_rect_of_child_subtree;
1334 gfx::Transform identity_matrix;
1340 CalculateDrawPropertiesInternal<LayerType, LayerList, RenderSurfaceType>( 1335 CalculateDrawPropertiesInternal<LayerType, LayerList, RenderSurfaceType>(
1341 child, 1336 child,
1342 sublayer_matrix, 1337 sublayer_matrix,
1343 next_hierarchy_matrix, 1338 next_hierarchy_matrix,
1344 next_scroll_compensation_matrix, 1339 next_scroll_compensation_matrix,
1345 next_fixed_container, 1340 next_fixed_container,
1346 clip_rect_for_subtree, 1341 clip_rect_for_subtree,
1347 clip_rect_for_subtree_in_descendant_space, 1342 clip_rect_for_subtree_in_descendant_space,
1348 subtree_should_be_clipped, 1343 subtree_should_be_clipped,
1349 nearest_ancestor_that_moves_pixels, 1344 nearest_ancestor_that_moves_pixels,
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 layer->render_target()->render_surface()-> 1514 layer->render_target()->render_surface()->
1520 AddContributingDelegatedRenderPassLayer(layer); 1515 AddContributingDelegatedRenderPassLayer(layer);
1521 } 1516 }
1522 1517
1523 SavePaintPropertiesLayer(layer); 1518 SavePaintPropertiesLayer(layer);
1524 } 1519 }
1525 1520
1526 void LayerTreeHostCommon::CalculateDrawProperties( 1521 void LayerTreeHostCommon::CalculateDrawProperties(
1527 Layer* root_layer, 1522 Layer* root_layer,
1528 gfx::Size device_viewport_size, 1523 gfx::Size device_viewport_size,
1524 const gfx::Transform& device_transform,
1529 float device_scale_factor, 1525 float device_scale_factor,
1530 float page_scale_factor, 1526 float page_scale_factor,
1531 Layer* page_scale_application_layer, 1527 Layer* page_scale_application_layer,
1532 int max_texture_size, 1528 int max_texture_size,
1533 bool can_use_lcd_text, 1529 bool can_use_lcd_text,
1534 bool can_adjust_raster_scales, 1530 bool can_adjust_raster_scales,
1535 LayerList* render_surface_layer_list) { 1531 LayerList* render_surface_layer_list) {
1536 gfx::Rect total_drawable_content_rect; 1532 gfx::Rect total_drawable_content_rect;
1537 gfx::Transform identity_matrix; 1533 gfx::Transform identity_matrix;
1538 gfx::Transform device_scale_transform; 1534 gfx::Transform scaled_device_transform = device_transform;
1539 device_scale_transform.Scale(device_scale_factor, device_scale_factor); 1535 scaled_device_transform.Scale(device_scale_factor, device_scale_factor);
1540 LayerList dummy_layer_list; 1536 LayerList dummy_layer_list;
1541 1537
1542 // The root layer's render_surface should receive the device viewport as the 1538 // The root layer's render_surface should receive the device viewport as the
1543 // initial clip rect. 1539 // initial clip rect.
1544 bool subtree_should_be_clipped = true; 1540 bool subtree_should_be_clipped = true;
1545 gfx::Rect device_viewport_rect(device_viewport_size); 1541 gfx::Rect device_viewport_rect(device_viewport_size);
1546 bool in_subtree_of_page_scale_application_layer = false; 1542 bool in_subtree_of_page_scale_application_layer = false;
1547 1543
1548 // This function should have received a root layer. 1544 // This function should have received a root layer.
1549 DCHECK(IsRootLayer(root_layer)); 1545 DCHECK(IsRootLayer(root_layer));
1550 1546
1551 PreCalculateMetaInformation<Layer>(root_layer); 1547 PreCalculateMetaInformation<Layer>(root_layer);
1552 CalculateDrawPropertiesInternal<Layer, LayerList, RenderSurface>( 1548 CalculateDrawPropertiesInternal<Layer, LayerList, RenderSurface>(
1553 root_layer, 1549 root_layer,
1554 device_scale_transform, 1550 scaled_device_transform,
1555 identity_matrix, 1551 identity_matrix,
1556 identity_matrix, 1552 identity_matrix,
1557 NULL, 1553 root_layer,
1558 device_viewport_rect, 1554 device_viewport_rect,
1559 device_viewport_rect, 1555 device_viewport_rect,
1560 subtree_should_be_clipped, 1556 subtree_should_be_clipped,
1561 NULL, 1557 NULL,
1562 render_surface_layer_list, 1558 render_surface_layer_list,
1563 &dummy_layer_list, 1559 &dummy_layer_list,
1564 NULL, 1560 NULL,
1565 max_texture_size, 1561 max_texture_size,
1566 device_scale_factor, 1562 device_scale_factor,
1567 page_scale_factor, 1563 page_scale_factor,
1568 page_scale_application_layer, 1564 page_scale_application_layer,
1569 in_subtree_of_page_scale_application_layer, 1565 in_subtree_of_page_scale_application_layer,
1570 can_use_lcd_text, 1566 can_use_lcd_text,
1571 can_adjust_raster_scales, 1567 can_adjust_raster_scales,
1572 &total_drawable_content_rect); 1568 &total_drawable_content_rect);
1573 1569
1574 // The dummy layer list should not have been used. 1570 // The dummy layer list should not have been used.
1575 DCHECK_EQ(0u, dummy_layer_list.size()); 1571 DCHECK_EQ(0u, dummy_layer_list.size());
1576 // A root layer render_surface should always exist after 1572 // A root layer render_surface should always exist after
1577 // CalculateDrawProperties. 1573 // CalculateDrawProperties.
1578 DCHECK(root_layer->render_surface()); 1574 DCHECK(root_layer->render_surface());
1579 } 1575 }
1580 1576
1581 void LayerTreeHostCommon::CalculateDrawProperties( 1577 void LayerTreeHostCommon::CalculateDrawProperties(
1582 LayerImpl* root_layer, 1578 LayerImpl* root_layer,
1583 gfx::Size device_viewport_size, 1579 gfx::Size device_viewport_size,
1580 const gfx::Transform& device_transform,
1584 float device_scale_factor, 1581 float device_scale_factor,
1585 float page_scale_factor, 1582 float page_scale_factor,
1586 LayerImpl* page_scale_application_layer, 1583 LayerImpl* page_scale_application_layer,
1587 int max_texture_size, 1584 int max_texture_size,
1588 bool can_use_lcd_text, 1585 bool can_use_lcd_text,
1589 bool can_adjust_raster_scales, 1586 bool can_adjust_raster_scales,
1590 LayerImplList* render_surface_layer_list) { 1587 LayerImplList* render_surface_layer_list) {
1591 gfx::Rect total_drawable_content_rect; 1588 gfx::Rect total_drawable_content_rect;
1592 gfx::Transform identity_matrix; 1589 gfx::Transform identity_matrix;
1593 gfx::Transform device_scale_transform; 1590 gfx::Transform scaled_device_transform = device_transform;
1594 device_scale_transform.Scale(device_scale_factor, device_scale_factor); 1591 scaled_device_transform.Scale(device_scale_factor, device_scale_factor);
1595 LayerImplList dummy_layer_list; 1592 LayerImplList dummy_layer_list;
1596 LayerSorter layer_sorter; 1593 LayerSorter layer_sorter;
1597 1594
1598 // The root layer's render_surface should receive the device viewport as the 1595 // The root layer's render_surface should receive the device viewport as the
1599 // initial clip rect. 1596 // initial clip rect.
1600 bool subtree_should_be_clipped = true; 1597 bool subtree_should_be_clipped = true;
1601 gfx::Rect device_viewport_rect(device_viewport_size); 1598 gfx::Rect device_viewport_rect(device_viewport_size);
1602 bool in_subtree_of_page_scale_application_layer = false; 1599 bool in_subtree_of_page_scale_application_layer = false;
1603 1600
1604 // This function should have received a root layer. 1601 // This function should have received a root layer.
1605 DCHECK(IsRootLayer(root_layer)); 1602 DCHECK(IsRootLayer(root_layer));
1606 1603
1607 PreCalculateMetaInformation<LayerImpl>(root_layer); 1604 PreCalculateMetaInformation<LayerImpl>(root_layer);
1608 CalculateDrawPropertiesInternal<LayerImpl, 1605 CalculateDrawPropertiesInternal<LayerImpl,
1609 LayerImplList, 1606 LayerImplList,
1610 RenderSurfaceImpl>( 1607 RenderSurfaceImpl>(
1611 root_layer, 1608 root_layer,
1612 device_scale_transform, 1609 scaled_device_transform,
1613 identity_matrix, 1610 identity_matrix,
1614 identity_matrix, 1611 identity_matrix,
1615 NULL, 1612 root_layer,
1616 device_viewport_rect, 1613 device_viewport_rect,
1617 device_viewport_rect, 1614 device_viewport_rect,
1618 subtree_should_be_clipped, 1615 subtree_should_be_clipped,
1619 NULL, 1616 NULL,
1620 render_surface_layer_list, 1617 render_surface_layer_list,
1621 &dummy_layer_list, 1618 &dummy_layer_list,
1622 &layer_sorter, 1619 &layer_sorter,
1623 max_texture_size, 1620 max_texture_size,
1624 device_scale_factor, 1621 device_scale_factor,
1625 page_scale_factor, 1622 page_scale_factor,
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1821 // At this point, we think the point does hit the touch event handler region 1818 // At this point, we think the point does hit the touch event handler region
1822 // on the layer, but we need to walk up the parents to ensure that the layer 1819 // on the layer, but we need to walk up the parents to ensure that the layer
1823 // was not clipped in such a way that the hit point actually should not hit 1820 // was not clipped in such a way that the hit point actually should not hit
1824 // the layer. 1821 // the layer.
1825 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) 1822 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl))
1826 return false; 1823 return false;
1827 1824
1828 return true; 1825 return true;
1829 } 1826 }
1830 } // namespace cc 1827 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698