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/layer_tree_host_common.h" | 5 #include "cc/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/heads_up_display_layer_impl.h" | 10 #include "cc/heads_up_display_layer_impl.h" |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 if (!layer->renderSurface()->drawTransform().GetInverse(&inverseSurfaceD rawTransform)) { | 400 if (!layer->renderSurface()->drawTransform().GetInverse(&inverseSurfaceD rawTransform)) { |
401 // TODO(shawnsingh): Either we need to handle uninvertible transform s | 401 // TODO(shawnsingh): Either we need to handle uninvertible transform s |
402 // here, or DCHECK that the transform is invertible. | 402 // here, or DCHECK that the transform is invertible. |
403 } | 403 } |
404 nextScrollCompensationMatrix = inverseSurfaceDrawTransform * nextScrollC ompensationMatrix * layer->renderSurface()->drawTransform(); | 404 nextScrollCompensationMatrix = inverseSurfaceDrawTransform * nextScrollC ompensationMatrix * layer->renderSurface()->drawTransform(); |
405 } | 405 } |
406 | 406 |
407 return nextScrollCompensationMatrix; | 407 return nextScrollCompensationMatrix; |
408 } | 408 } |
409 | 409 |
410 static gfx::Vector2dF computeFixedContainerSizeDeltaForChildren(Layer*, const gf x::Vector2dF&) | |
411 { | |
412 return gfx::Vector2dF(); | |
413 } | |
414 | |
415 static gfx::Vector2dF computeFixedContainerSizeDeltaForChildren(LayerImpl* layer , const gfx::Vector2dF& currentFixedContainerSizeDelta) | |
416 { | |
417 if (layer->isContainerForFixedPositionLayers()) | |
418 return layer->fixedContainerSizeDelta(); | |
419 return currentFixedContainerSizeDelta; | |
420 } | |
421 | |
410 template<typename LayerType> | 422 template<typename LayerType> |
411 static inline void calculateContentsScale(LayerType* layer, float contentsScale, bool animatingTransformToScreen) | 423 static inline void calculateContentsScale(LayerType* layer, float contentsScale, bool animatingTransformToScreen) |
412 { | 424 { |
413 layer->calculateContentsScale( | 425 layer->calculateContentsScale( |
414 contentsScale, | 426 contentsScale, |
415 animatingTransformToScreen, | 427 animatingTransformToScreen, |
416 &layer->drawProperties().contents_scale_x, | 428 &layer->drawProperties().contents_scale_x, |
417 &layer->drawProperties().contents_scale_y, | 429 &layer->drawProperties().contents_scale_y, |
418 &layer->drawProperties().content_bounds); | 430 &layer->drawProperties().content_bounds); |
419 | 431 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
537 } | 549 } |
538 | 550 |
539 layer->drawProperties().num_descendants_that_draw_content = numDescendantsTh atDrawContent; | 551 layer->drawProperties().num_descendants_that_draw_content = numDescendantsTh atDrawContent; |
540 layer->drawProperties().descendants_can_clip_selves = descendantsCanClipSelv es; | 552 layer->drawProperties().descendants_can_clip_selves = descendantsCanClipSelv es; |
541 } | 553 } |
542 | 554 |
543 // Recursively walks the layer tree starting at the given node and computes all the | 555 // Recursively walks the layer tree starting at the given node and computes all the |
544 // necessary transformations, clipRects, render surfaces, etc. | 556 // necessary transformations, clipRects, render surfaces, etc. |
545 template<typename LayerType, typename LayerList, typename RenderSurfaceType> | 557 template<typename LayerType, typename LayerList, typename RenderSurfaceType> |
546 static void calculateDrawPropertiesInternal(LayerType* layer, const gfx::Transfo rm& parentMatrix, | 558 static void calculateDrawPropertiesInternal(LayerType* layer, const gfx::Transfo rm& parentMatrix, |
547 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro llCompensationMatrix, | 559 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro llCompensationMatrix, const gfx::Vector2dF& currentFixedContainerSizeDelta, |
548 const gfx::Rect& clipRectFromAncestor, const gfx::Rect& clipRectFromAncestor InDescendantSpace, bool ancestorClipsSubtree, | 560 const gfx::Rect& clipRectFromAncestor, const gfx::Rect& clipRectFromAncestor InDescendantSpace, bool ancestorClipsSubtree, |
549 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList, | 561 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList, |
550 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, bool subtreeCanUseLCDText, | 562 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, bool subtreeCanUseLCDText, |
551 gfx::Rect& drawableContentRectOfSubtree, bool updateTilePriorities) | 563 gfx::Rect& drawableContentRectOfSubtree, bool updateTilePriorities) |
552 { | 564 { |
553 // This function computes the new matrix transformations recursively for thi s | 565 // This function computes the new matrix transformations recursively for thi s |
554 // layer and all its descendants. It also computes the appropriate render su rfaces. | 566 // layer and all its descendants. It also computes the appropriate render su rfaces. |
555 // Some important points to remember: | 567 // Some important points to remember: |
556 // | 568 // |
557 // 0. Here, transforms are notated in Matrix x Vector order, and in words we describe what | 569 // 0. Here, transforms are notated in Matrix x Vector order, and in words we describe what |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
693 // computation of contentsScale above. | 705 // computation of contentsScale above. |
694 // Note carefully: this is Concat, not Preconcat (implTransform * combinedTr ansform). | 706 // Note carefully: this is Concat, not Preconcat (implTransform * combinedTr ansform). |
695 combinedTransform.ConcatTransform(layer->implTransform()); | 707 combinedTransform.ConcatTransform(layer->implTransform()); |
696 | 708 |
697 if (layer->fixedToContainerLayer()) { | 709 if (layer->fixedToContainerLayer()) { |
698 // Special case: this layer is a composited fixed-position layer; we nee d to | 710 // Special case: this layer is a composited fixed-position layer; we nee d to |
699 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep this layer | 711 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep this layer |
700 // fixed correctly. | 712 // fixed correctly. |
701 // Note carefully: this is Concat, not Preconcat (currentScrollCompensat ion * combinedTransform). | 713 // Note carefully: this is Concat, not Preconcat (currentScrollCompensat ion * combinedTransform). |
702 combinedTransform.ConcatTransform(currentScrollCompensationMatrix); | 714 combinedTransform.ConcatTransform(currentScrollCompensationMatrix); |
715 | |
716 gfx::Transform bottomRightAnchorCompensation; | |
717 bottomRightAnchorCompensation.Translate( | |
718 layer->fixedToRightEdge() ? currentFixedContainerSizeDelta.x() : 0, | |
719 layer->fixedToBottomEdge() ? currentFixedContainerSizeDelta.y() : 0) ; | |
720 combinedTransform.PreconcatTransform(bottomRightAnchorCompensation); | |
shawnsingh
2013/03/07 09:57:06
Chances are, once we do this correctly, that this
| |
703 } | 721 } |
704 | 722 |
705 // The drawTransform that gets computed below is effectively the layer's dra wTransform, unless | 723 // The drawTransform that gets computed below is effectively the layer's dra wTransform, unless |
706 // the layer itself creates a renderSurface. In that case, the renderSurface re-parents the transforms. | 724 // the layer itself creates a renderSurface. In that case, the renderSurface re-parents the transforms. |
707 layerDrawProperties.target_space_transform = combinedTransform; | 725 layerDrawProperties.target_space_transform = combinedTransform; |
708 // M[draw] = M[parent] * LT * S[layer2content] | 726 // M[draw] = M[parent] * LT * S[layer2content] |
709 layerDrawProperties.target_space_transform.Scale(1.0 / layer->contentsScaleX (), 1.0 / layer->contentsScaleY()); | 727 layerDrawProperties.target_space_transform.Scale(1.0 / layer->contentsScaleX (), 1.0 / layer->contentsScaleY()); |
710 | 728 |
711 // layerScreenSpaceTransform represents the transform between root layer's " screen space" and local content space. | 729 // layerScreenSpaceTransform represents the transform between root layer's " screen space" and local content space. |
712 layerDrawProperties.screen_space_transform = fullHierarchyMatrix; | 730 layerDrawProperties.screen_space_transform = fullHierarchyMatrix; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
876 | 894 |
877 LayerList& descendants = (layer->renderSurface() ? layer->renderSurface()->l ayerList() : layerList); | 895 LayerList& descendants = (layer->renderSurface() ? layer->renderSurface()->l ayerList() : layerList); |
878 | 896 |
879 // Any layers that are appended after this point are in the layer's subtree and should be included in the sorting process. | 897 // Any layers that are appended after this point are in the layer's subtree and should be included in the sorting process. |
880 unsigned sortingStartIndex = descendants.size(); | 898 unsigned sortingStartIndex = descendants.size(); |
881 | 899 |
882 if (!layerShouldBeSkipped(layer)) | 900 if (!layerShouldBeSkipped(layer)) |
883 descendants.push_back(layer); | 901 descendants.push_back(layer); |
884 | 902 |
885 gfx::Transform nextScrollCompensationMatrix = computeScrollCompensationMatri xForChildren(layer, parentMatrix, currentScrollCompensationMatrix);; | 903 gfx::Transform nextScrollCompensationMatrix = computeScrollCompensationMatri xForChildren(layer, parentMatrix, currentScrollCompensationMatrix);; |
904 gfx::Vector2dF nextFixedContainerSizeDelta = computeFixedContainerSizeDeltaF orChildren(layer, currentFixedContainerSizeDelta); | |
886 | 905 |
887 gfx::Rect accumulatedDrawableContentRectOfChildren; | 906 gfx::Rect accumulatedDrawableContentRectOfChildren; |
888 for (size_t i = 0; i < layer->children().size(); ++i) { | 907 for (size_t i = 0; i < layer->children().size(); ++i) { |
889 LayerType* child = LayerTreeHostCommon::getChildAsRawPtr(layer->children (), i); | 908 LayerType* child = LayerTreeHostCommon::getChildAsRawPtr(layer->children (), i); |
890 gfx::Rect drawableContentRectOfChildSubtree; | 909 gfx::Rect drawableContentRectOfChildSubtree; |
891 calculateDrawPropertiesInternal<LayerType, LayerList, RenderSurfaceType> (child, sublayerMatrix, nextHierarchyMatrix, nextScrollCompensationMatrix, | 910 calculateDrawPropertiesInternal<LayerType, LayerList, RenderSurfaceType> (child, sublayerMatrix, nextHierarchyMatrix, nextScrollCompensationMatrix, nextF ixedContainerSizeDelta, |
892 clipRectForSubtree, clipRectForSubtreeInDescendantSpace, subtreeShouldBeClipped , nearestAncestorThatMovesPixels, | 911 clipRectForSubtree, clipRectForSubtreeInDescendantSpace, subtreeShouldBeClipped , nearestAncestorThatMovesPixels, |
893 renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFa ctor, pageScaleFactor, | 912 renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFa ctor, pageScaleFactor, |
894 subtreeCanUseLCDText, drawableContentRectOfChildSubtree, updateTilePriorities); | 913 subtreeCanUseLCDText, drawableContentRectOfChildSubtree, updateTilePriorities); |
895 if (!drawableContentRectOfChildSubtree.IsEmpty()) { | 914 if (!drawableContentRectOfChildSubtree.IsEmpty()) { |
896 accumulatedDrawableContentRectOfChildren.Union(drawableContentRectOf ChildSubtree); | 915 accumulatedDrawableContentRectOfChildren.Union(drawableContentRectOf ChildSubtree); |
897 if (child->renderSurface()) | 916 if (child->renderSurface()) |
898 descendants.push_back(child); | 917 descendants.push_back(child); |
899 } | 918 } |
900 } | 919 } |
901 | 920 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1024 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect. | 1043 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect. |
1025 bool subtreeShouldBeClipped = true; | 1044 bool subtreeShouldBeClipped = true; |
1026 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); | 1045 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); |
1027 bool updateTilePriorities = false; | 1046 bool updateTilePriorities = false; |
1028 | 1047 |
1029 // This function should have received a root layer. | 1048 // This function should have received a root layer. |
1030 DCHECK(isRootLayer(rootLayer)); | 1049 DCHECK(isRootLayer(rootLayer)); |
1031 | 1050 |
1032 preCalculateMetaInformation<Layer>(rootLayer); | 1051 preCalculateMetaInformation<Layer>(rootLayer); |
1033 calculateDrawPropertiesInternal<Layer, std::vector<scoped_refptr<Layer> >, R enderSurface>( | 1052 calculateDrawPropertiesInternal<Layer, std::vector<scoped_refptr<Layer> >, R enderSurface>( |
1034 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, | 1053 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, gfx::Ve ctor2dF(), |
1035 deviceViewportRect, deviceViewportRect, subtreeShouldBeClipped, 0, rende rSurfaceLayerList, | 1054 deviceViewportRect, deviceViewportRect, subtreeShouldBeClipped, 0, rende rSurfaceLayerList, |
1036 dummyLayerList, 0, maxTextureSize, | 1055 dummyLayerList, 0, maxTextureSize, |
1037 deviceScaleFactor, pageScaleFactor, canUseLCDText, totalDrawableContentR ect, | 1056 deviceScaleFactor, pageScaleFactor, canUseLCDText, totalDrawableContentR ect, |
1038 updateTilePriorities); | 1057 updateTilePriorities); |
1039 | 1058 |
1040 // The dummy layer list should not have been used. | 1059 // The dummy layer list should not have been used. |
1041 DCHECK(dummyLayerList.size() == 0); | 1060 DCHECK(dummyLayerList.size() == 0); |
1042 // A root layer renderSurface should always exist after calculateDrawPropert ies. | 1061 // A root layer renderSurface should always exist after calculateDrawPropert ies. |
1043 DCHECK(rootLayer->renderSurface()); | 1062 DCHECK(rootLayer->renderSurface()); |
1044 } | 1063 } |
1045 | 1064 |
1046 void LayerTreeHostCommon::calculateDrawProperties(LayerImpl* rootLayer, const gf x::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int maxTextureSize, bool canUseLCDText, std::vector<LayerImpl*>& renderSurfaceLayer List, bool updateTilePriorities) | 1065 void LayerTreeHostCommon::calculateDrawProperties(LayerImpl* rootLayer, const gf x::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int maxTextureSize, bool canUseLCDText, std::vector<LayerImpl*>& renderSurfaceLayer List, bool updateTilePriorities) |
1047 { | 1066 { |
1048 gfx::Rect totalDrawableContentRect; | 1067 gfx::Rect totalDrawableContentRect; |
1049 gfx::Transform identityMatrix; | 1068 gfx::Transform identityMatrix; |
1050 gfx::Transform deviceScaleTransform; | 1069 gfx::Transform deviceScaleTransform; |
1051 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); | 1070 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); |
1052 std::vector<LayerImpl*> dummyLayerList; | 1071 std::vector<LayerImpl*> dummyLayerList; |
1053 LayerSorter layerSorter; | 1072 LayerSorter layerSorter; |
1054 | 1073 |
1055 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect. | 1074 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect. |
1056 bool subtreeShouldBeClipped = true; | 1075 bool subtreeShouldBeClipped = true; |
1057 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); | 1076 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); |
1058 | 1077 |
1059 // This function should have received a root layer. | 1078 // This function should have received a root layer. |
1060 DCHECK(isRootLayer(rootLayer)); | 1079 DCHECK(isRootLayer(rootLayer)); |
1061 | 1080 |
1062 preCalculateMetaInformation<LayerImpl>(rootLayer); | 1081 preCalculateMetaInformation<LayerImpl>(rootLayer); |
1063 calculateDrawPropertiesInternal<LayerImpl, std::vector<LayerImpl*>, RenderSu rfaceImpl>( | 1082 calculateDrawPropertiesInternal<LayerImpl, std::vector<LayerImpl*>, RenderSu rfaceImpl>( |
1064 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, | 1083 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, gfx::Ve ctor2dF(), |
1065 deviceViewportRect, deviceViewportRect, subtreeShouldBeClipped, 0, rende rSurfaceLayerList, | 1084 deviceViewportRect, deviceViewportRect, subtreeShouldBeClipped, 0, rende rSurfaceLayerList, |
1066 dummyLayerList, &layerSorter, maxTextureSize, | 1085 dummyLayerList, &layerSorter, maxTextureSize, |
1067 deviceScaleFactor, pageScaleFactor, canUseLCDText, totalDrawableContentR ect, | 1086 deviceScaleFactor, pageScaleFactor, canUseLCDText, totalDrawableContentR ect, |
1068 updateTilePriorities); | 1087 updateTilePriorities); |
1069 | 1088 |
1070 // The dummy layer list should not have been used. | 1089 // The dummy layer list should not have been used. |
1071 DCHECK(dummyLayerList.size() == 0); | 1090 DCHECK(dummyLayerList.size() == 0); |
1072 // A root layer renderSurface should always exist after calculateDrawPropert ies. | 1091 // A root layer renderSurface should always exist after calculateDrawPropert ies. |
1073 DCHECK(rootLayer->renderSurface()); | 1092 DCHECK(rootLayer->renderSurface()); |
1074 } | 1093 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1202 | 1221 |
1203 // At this point, we think the point does hit the touch event handler region o n the layer, but we need to walk up | 1222 // At this point, we think the point does hit the touch event handler region o n the layer, but we need to walk up |
1204 // the parents to ensure that the layer was not clipped in such a way that the | 1223 // the parents to ensure that the layer was not clipped in such a way that the |
1205 // hit point actually should not hit the layer. | 1224 // hit point actually should not hit the layer. |
1206 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, layerImpl)) | 1225 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, layerImpl)) |
1207 return false; | 1226 return false; |
1208 | 1227 |
1209 return true; | 1228 return true; |
1210 } | 1229 } |
1211 } // namespace cc | 1230 } // namespace cc |
OLD | NEW |