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

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: Add 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 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 if (!layer->double_sided() && TransformToParentIsKnown(layer) && 1108 if (!layer->double_sided() && TransformToParentIsKnown(layer) &&
1109 IsSurfaceBackFaceVisible(layer, combined_transform)) 1109 IsSurfaceBackFaceVisible(layer, combined_transform))
1110 return; 1110 return;
1111 1111
1112 if (!layer->render_surface()) 1112 if (!layer->render_surface())
1113 layer->CreateRenderSurface(); 1113 layer->CreateRenderSurface();
1114 1114
1115 RenderSurfaceType* render_surface = layer->render_surface(); 1115 RenderSurfaceType* render_surface = layer->render_surface();
1116 render_surface->ClearLayerLists(); 1116 render_surface->ClearLayerLists();
1117 1117
1118 // The owning layer's draw transform has a scale from content to layer 1118 if (IsRootLayer(layer)) {
1119 // space which we do not want; so here we use the combined_transform 1119 // The root layer isn't capable of transforming its render surface since
enne (OOO) 2013/06/04 17:26:03 Hmm. I'm not sure about the "external to the CC i
aelias_OOO_until_Jul13 2013/06/04 17:54:20 Done.
1120 // instead of the draw_transform. However, we do need to add a different 1120 // it's not created from within this CC instance. So it should just
1121 // scale factor that accounts for the surface's pixel dimensions. 1121 // forward top-level transforms to the rest of the tree.
1122 combined_transform.Scale(1.0 / render_surface_sublayer_scale.x(), 1122 sublayer_matrix = combined_transform;
enne (OOO) 2013/06/04 17:26:03 What if the root layer also has a sublayer_matrix
aelias_OOO_until_Jul13 2013/06/04 17:54:20 It should be fine because that will be applied lat
1123 1.0 / render_surface_sublayer_scale.y()); 1123 } else {
1124 render_surface->SetDrawTransform(combined_transform); 1124 // The owning layer's draw transform has a scale from content to layer
1125 // space which we do not want; so here we use the combined_transform
1126 // instead of the draw_transform. However, we do need to add a different
1127 // scale factor that accounts for the surface's pixel dimensions.
1128 combined_transform.Scale(1.0 / render_surface_sublayer_scale.x(),
1129 1.0 / render_surface_sublayer_scale.y());
1130 render_surface->SetDrawTransform(combined_transform);
1125 1131
1126 // If this is the root layer, there should be no scale in the surface's draw 1132 // The owning layer's transform was re-parented by the surface, so the
1127 // transform. 1133 // layer's new draw_transform only needs to scale the layer to surface
1128 if (IsRootLayer(layer)) { 1134 // space.
1129 DCHECK_EQ(render_surface_sublayer_scale.x(), 1135 layer_draw_properties.target_space_transform.MakeIdentity();
danakj 2013/06/04 17:26:40 Can these checks stay in the IsRootLayer() block?
danakj 2013/06/04 17:31:30 enne pointed out that webview may want to actually
aelias_OOO_until_Jul13 2013/06/04 17:54:20 Patch Set 1 above applied it directly to root-laye
danakj 2013/06/04 18:02:50 Lost information: I mean that if you set a scale 2
aelias_OOO_until_Jul13 2013/06/04 22:18:27 I changed my mind on this, I believe this use case
1130 combined_transform_scales.x()); 1136 layer_draw_properties.target_space_transform.
1131 DCHECK_EQ(render_surface_sublayer_scale.y(), 1137 Scale(render_surface_sublayer_scale.x() / layer->contents_scale_x(),
1132 combined_transform_scales.y()); 1138 render_surface_sublayer_scale.y() / layer->contents_scale_y());
1139
1140 // Inside the surface's subtree, we scale everything to the owning layer's
1141 // scale. The sublayer matrix transforms layer rects into target surface
1142 // content space. Conceptually, all layers in the subtree inherit the
1143 // scale at the point of the render surface in the transform hierarchy,
1144 // but we apply it explicitly to the owning layer and the remainder of the
1145 // subtree independently.
1146 DCHECK(sublayer_matrix.IsIdentity());
1147 sublayer_matrix.Scale(render_surface_sublayer_scale.x(),
1148 render_surface_sublayer_scale.y());
1133 } 1149 }
1134 1150
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 1151 // The opacity value is moved from the layer to its surface, so that the
1154 // entire subtree properly inherits opacity. 1152 // entire subtree properly inherits opacity.
1155 render_surface->SetDrawOpacity(accumulated_draw_opacity); 1153 render_surface->SetDrawOpacity(accumulated_draw_opacity);
1156 render_surface->SetDrawOpacityIsAnimating(animating_opacity_to_target); 1154 render_surface->SetDrawOpacityIsAnimating(animating_opacity_to_target);
1157 animating_opacity_to_target = false; 1155 animating_opacity_to_target = false;
1158 layer_draw_properties.opacity = 1.f; 1156 layer_draw_properties.opacity = 1.f;
1159 layer_draw_properties.opacity_is_animating = animating_opacity_to_target; 1157 layer_draw_properties.opacity_is_animating = animating_opacity_to_target;
1160 layer_draw_properties.screen_space_opacity_is_animating = 1158 layer_draw_properties.screen_space_opacity_is_animating =
1161 animating_opacity_to_screen; 1159 animating_opacity_to_screen;
1162 1160
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 current_scroll_compensation_matrix); 1328 current_scroll_compensation_matrix);
1331 LayerType* next_fixed_container = 1329 LayerType* next_fixed_container =
1332 layer->IsContainerForFixedPositionLayers() ? 1330 layer->IsContainerForFixedPositionLayers() ?
1333 layer : current_fixed_container; 1331 layer : current_fixed_container;
1334 1332
1335 gfx::Rect accumulated_drawable_content_rect_of_children; 1333 gfx::Rect accumulated_drawable_content_rect_of_children;
1336 for (size_t i = 0; i < layer->children().size(); ++i) { 1334 for (size_t i = 0; i < layer->children().size(); ++i) {
1337 LayerType* child = 1335 LayerType* child =
1338 LayerTreeHostCommon::get_child_as_raw_ptr(layer->children(), i); 1336 LayerTreeHostCommon::get_child_as_raw_ptr(layer->children(), i);
1339 gfx::Rect drawable_content_rect_of_child_subtree; 1337 gfx::Rect drawable_content_rect_of_child_subtree;
1338 gfx::Transform identity_matrix;
1340 CalculateDrawPropertiesInternal<LayerType, LayerList, RenderSurfaceType>( 1339 CalculateDrawPropertiesInternal<LayerType, LayerList, RenderSurfaceType>(
1341 child, 1340 child,
1342 sublayer_matrix, 1341 sublayer_matrix,
1343 next_hierarchy_matrix, 1342 next_hierarchy_matrix,
1344 next_scroll_compensation_matrix, 1343 next_scroll_compensation_matrix,
1345 next_fixed_container, 1344 next_fixed_container,
1346 clip_rect_for_subtree, 1345 clip_rect_for_subtree,
1347 clip_rect_for_subtree_in_descendant_space, 1346 clip_rect_for_subtree_in_descendant_space,
1348 subtree_should_be_clipped, 1347 subtree_should_be_clipped,
1349 nearest_ancestor_that_moves_pixels, 1348 nearest_ancestor_that_moves_pixels,
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 layer->render_target()->render_surface()-> 1518 layer->render_target()->render_surface()->
1520 AddContributingDelegatedRenderPassLayer(layer); 1519 AddContributingDelegatedRenderPassLayer(layer);
1521 } 1520 }
1522 1521
1523 SavePaintPropertiesLayer(layer); 1522 SavePaintPropertiesLayer(layer);
1524 } 1523 }
1525 1524
1526 void LayerTreeHostCommon::CalculateDrawProperties( 1525 void LayerTreeHostCommon::CalculateDrawProperties(
1527 Layer* root_layer, 1526 Layer* root_layer,
1528 gfx::Size device_viewport_size, 1527 gfx::Size device_viewport_size,
1528 const gfx::Transform& device_transform,
1529 float device_scale_factor, 1529 float device_scale_factor,
1530 float page_scale_factor, 1530 float page_scale_factor,
1531 Layer* page_scale_application_layer, 1531 Layer* page_scale_application_layer,
1532 int max_texture_size, 1532 int max_texture_size,
1533 bool can_use_lcd_text, 1533 bool can_use_lcd_text,
1534 bool can_adjust_raster_scales, 1534 bool can_adjust_raster_scales,
1535 LayerList* render_surface_layer_list) { 1535 LayerList* render_surface_layer_list) {
1536 gfx::Rect total_drawable_content_rect; 1536 gfx::Rect total_drawable_content_rect;
1537 gfx::Transform identity_matrix; 1537 gfx::Transform identity_matrix;
1538 gfx::Transform device_scale_transform; 1538 gfx::Transform scaled_device_transform = device_transform;
1539 device_scale_transform.Scale(device_scale_factor, device_scale_factor); 1539 scaled_device_transform.Scale(device_scale_factor, device_scale_factor);
1540 LayerList dummy_layer_list; 1540 LayerList dummy_layer_list;
1541 1541
1542 // The root layer's render_surface should receive the device viewport as the 1542 // The root layer's render_surface should receive the device viewport as the
1543 // initial clip rect. 1543 // initial clip rect.
1544 bool subtree_should_be_clipped = true; 1544 bool subtree_should_be_clipped = true;
1545 gfx::Rect device_viewport_rect(device_viewport_size); 1545 gfx::Rect device_viewport_rect(device_viewport_size);
1546 bool in_subtree_of_page_scale_application_layer = false; 1546 bool in_subtree_of_page_scale_application_layer = false;
1547 1547
1548 // This function should have received a root layer. 1548 // This function should have received a root layer.
1549 DCHECK(IsRootLayer(root_layer)); 1549 DCHECK(IsRootLayer(root_layer));
1550 1550
1551 PreCalculateMetaInformation<Layer>(root_layer); 1551 PreCalculateMetaInformation<Layer>(root_layer);
1552 CalculateDrawPropertiesInternal<Layer, LayerList, RenderSurface>( 1552 CalculateDrawPropertiesInternal<Layer, LayerList, RenderSurface>(
1553 root_layer, 1553 root_layer,
1554 device_scale_transform, 1554 scaled_device_transform,
1555 identity_matrix, 1555 identity_matrix,
1556 identity_matrix, 1556 identity_matrix,
1557 NULL, 1557 NULL,
1558 device_viewport_rect, 1558 device_viewport_rect,
1559 device_viewport_rect, 1559 device_viewport_rect,
1560 subtree_should_be_clipped, 1560 subtree_should_be_clipped,
1561 NULL, 1561 NULL,
1562 render_surface_layer_list, 1562 render_surface_layer_list,
1563 &dummy_layer_list, 1563 &dummy_layer_list,
1564 NULL, 1564 NULL,
1565 max_texture_size, 1565 max_texture_size,
1566 device_scale_factor, 1566 device_scale_factor,
1567 page_scale_factor, 1567 page_scale_factor,
1568 page_scale_application_layer, 1568 page_scale_application_layer,
1569 in_subtree_of_page_scale_application_layer, 1569 in_subtree_of_page_scale_application_layer,
1570 can_use_lcd_text, 1570 can_use_lcd_text,
1571 can_adjust_raster_scales, 1571 can_adjust_raster_scales,
1572 &total_drawable_content_rect); 1572 &total_drawable_content_rect);
1573 1573
1574 // The dummy layer list should not have been used. 1574 // The dummy layer list should not have been used.
1575 DCHECK_EQ(0u, dummy_layer_list.size()); 1575 DCHECK_EQ(0u, dummy_layer_list.size());
1576 // A root layer render_surface should always exist after 1576 // A root layer render_surface should always exist after
1577 // CalculateDrawProperties. 1577 // CalculateDrawProperties.
1578 DCHECK(root_layer->render_surface()); 1578 DCHECK(root_layer->render_surface());
1579 } 1579 }
1580 1580
1581 void LayerTreeHostCommon::CalculateDrawProperties( 1581 void LayerTreeHostCommon::CalculateDrawProperties(
1582 LayerImpl* root_layer, 1582 LayerImpl* root_layer,
1583 gfx::Size device_viewport_size, 1583 gfx::Size device_viewport_size,
1584 const gfx::Transform& device_transform,
1584 float device_scale_factor, 1585 float device_scale_factor,
1585 float page_scale_factor, 1586 float page_scale_factor,
1586 LayerImpl* page_scale_application_layer, 1587 LayerImpl* page_scale_application_layer,
1587 int max_texture_size, 1588 int max_texture_size,
1588 bool can_use_lcd_text, 1589 bool can_use_lcd_text,
1589 bool can_adjust_raster_scales, 1590 bool can_adjust_raster_scales,
1590 LayerImplList* render_surface_layer_list) { 1591 LayerImplList* render_surface_layer_list) {
1591 gfx::Rect total_drawable_content_rect; 1592 gfx::Rect total_drawable_content_rect;
1592 gfx::Transform identity_matrix; 1593 gfx::Transform identity_matrix;
1593 gfx::Transform device_scale_transform; 1594 gfx::Transform scaled_device_transform = device_transform;
1594 device_scale_transform.Scale(device_scale_factor, device_scale_factor); 1595 scaled_device_transform.Scale(device_scale_factor, device_scale_factor);
1595 LayerImplList dummy_layer_list; 1596 LayerImplList dummy_layer_list;
1596 LayerSorter layer_sorter; 1597 LayerSorter layer_sorter;
1597 1598
1598 // The root layer's render_surface should receive the device viewport as the 1599 // The root layer's render_surface should receive the device viewport as the
1599 // initial clip rect. 1600 // initial clip rect.
1600 bool subtree_should_be_clipped = true; 1601 bool subtree_should_be_clipped = true;
1601 gfx::Rect device_viewport_rect(device_viewport_size); 1602 gfx::Rect device_viewport_rect(device_viewport_size);
1602 bool in_subtree_of_page_scale_application_layer = false; 1603 bool in_subtree_of_page_scale_application_layer = false;
1603 1604
1604 // This function should have received a root layer. 1605 // This function should have received a root layer.
1605 DCHECK(IsRootLayer(root_layer)); 1606 DCHECK(IsRootLayer(root_layer));
1606 1607
1607 PreCalculateMetaInformation<LayerImpl>(root_layer); 1608 PreCalculateMetaInformation<LayerImpl>(root_layer);
1608 CalculateDrawPropertiesInternal<LayerImpl, 1609 CalculateDrawPropertiesInternal<LayerImpl,
1609 LayerImplList, 1610 LayerImplList,
1610 RenderSurfaceImpl>( 1611 RenderSurfaceImpl>(
1611 root_layer, 1612 root_layer,
1612 device_scale_transform, 1613 scaled_device_transform,
1613 identity_matrix, 1614 identity_matrix,
1614 identity_matrix, 1615 identity_matrix,
1615 NULL, 1616 NULL,
1616 device_viewport_rect, 1617 device_viewport_rect,
1617 device_viewport_rect, 1618 device_viewport_rect,
1618 subtree_should_be_clipped, 1619 subtree_should_be_clipped,
1619 NULL, 1620 NULL,
1620 render_surface_layer_list, 1621 render_surface_layer_list,
1621 &dummy_layer_list, 1622 &dummy_layer_list,
1622 &layer_sorter, 1623 &layer_sorter,
(...skipping 198 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 1822 // 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 1823 // 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 1824 // was not clipped in such a way that the hit point actually should not hit
1824 // the layer. 1825 // the layer.
1825 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) 1826 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl))
1826 return false; 1827 return false;
1827 1828
1828 return true; 1829 return true;
1829 } 1830 }
1830 } // namespace cc 1831 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698