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/layer.h" | 10 #include "cc/layer.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 { | 228 { |
229 // If the opacity is being animated then the opacity on the main thread is u
nreliable | 229 // If the opacity is being animated then the opacity on the main thread is u
nreliable |
230 // (since the impl thread may be using a different opacity), so it should no
t be trusted. | 230 // (since the impl thread may be using a different opacity), so it should no
t be trusted. |
231 // In particular, it should not cause the subtree to be skipped. | 231 // In particular, it should not cause the subtree to be skipped. |
232 return !layer->opacity() && !layer->opacityIsAnimating(); | 232 return !layer->opacity() && !layer->opacityIsAnimating(); |
233 } | 233 } |
234 | 234 |
235 // Called on each layer that could be drawn after all information from | 235 // Called on each layer that could be drawn after all information from |
236 // calcDrawProperties has been updated on that layer. May have some false | 236 // calcDrawProperties has been updated on that layer. May have some false |
237 // positives (e.g. layers get this called on them but don't actually get drawn). | 237 // positives (e.g. layers get this called on them but don't actually get drawn). |
238 static inline void markLayerAsUpdated(LayerImpl* layer) | 238 static inline void updateTilePrioritiesForLayer(LayerImpl* layer) |
239 { | 239 { |
240 layer->didUpdateTransforms(); | 240 layer->updateTilePriorities(); |
241 | 241 |
242 // Mask layers don't get this call, so explicitly update them so they can | 242 // Mask layers don't get this call, so explicitly update them so they can |
243 // kick off tile rasterization. | 243 // kick off tile rasterization. |
244 if (layer->maskLayer()) | 244 if (layer->maskLayer()) |
245 layer->maskLayer()->didUpdateTransforms(); | 245 layer->maskLayer()->updateTilePriorities(); |
246 if (layer->replicaLayer()) { | 246 if (layer->replicaLayer() && layer->replicaLayer()->maskLayer()) |
247 layer->replicaLayer()->didUpdateTransforms(); | 247 layer->replicaLayer()->maskLayer()->updateTilePriorities(); |
248 if (layer->replicaLayer()->maskLayer()) | |
249 layer->replicaLayer()->maskLayer()->didUpdateTransforms(); | |
250 } | |
251 } | 248 } |
252 | 249 |
253 static inline void markLayerAsUpdated(Layer* layer) | 250 static inline void updateTilePrioritiesForLayer(Layer* layer) |
254 { | 251 { |
255 } | 252 } |
256 | 253 |
257 template<typename LayerType> | 254 template<typename LayerType> |
258 static bool subtreeShouldRenderToSeparateSurface(LayerType* layer, bool axisAlig
nedWithRespectToParent) | 255 static bool subtreeShouldRenderToSeparateSurface(LayerType* layer, bool axisAlig
nedWithRespectToParent) |
259 { | 256 { |
260 // | 257 // |
261 // A layer and its descendants should render onto a new RenderSurfaceImpl if
any of these rules hold: | 258 // A layer and its descendants should render onto a new RenderSurfaceImpl if
any of these rules hold: |
262 // | 259 // |
263 | 260 |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 } | 524 } |
528 | 525 |
529 // Recursively walks the layer tree starting at the given node and computes all
the | 526 // Recursively walks the layer tree starting at the given node and computes all
the |
530 // necessary transformations, clipRects, render surfaces, etc. | 527 // necessary transformations, clipRects, render surfaces, etc. |
531 template<typename LayerType, typename LayerList, typename RenderSurfaceType> | 528 template<typename LayerType, typename LayerList, typename RenderSurfaceType> |
532 static void calculateDrawPropertiesInternal(LayerType* layer, const gfx::Transfo
rm& parentMatrix, | 529 static void calculateDrawPropertiesInternal(LayerType* layer, const gfx::Transfo
rm& parentMatrix, |
533 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro
llCompensationMatrix, | 530 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro
llCompensationMatrix, |
534 const gfx::Rect& clipRectFromAncestor, const gfx::Rect& clipRectFromAncestor
InDescendantSpace, bool ancestorClipsSubtree, | 531 const gfx::Rect& clipRectFromAncestor, const gfx::Rect& clipRectFromAncestor
InDescendantSpace, bool ancestorClipsSubtree, |
535 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL
ayerList, LayerList& layerList, | 532 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL
ayerList, LayerList& layerList, |
536 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float
pageScaleFactor, bool subtreeCanUseLCDText, | 533 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float
pageScaleFactor, bool subtreeCanUseLCDText, |
537 gfx::Rect& drawableContentRectOfSubtree) | 534 gfx::Rect& drawableContentRectOfSubtree, bool updateTilePriorities) |
538 { | 535 { |
539 // This function computes the new matrix transformations recursively for thi
s | 536 // This function computes the new matrix transformations recursively for thi
s |
540 // layer and all its descendants. It also computes the appropriate render su
rfaces. | 537 // layer and all its descendants. It also computes the appropriate render su
rfaces. |
541 // Some important points to remember: | 538 // Some important points to remember: |
542 // | 539 // |
543 // 0. Here, transforms are notated in Matrix x Vector order, and in words we
describe what | 540 // 0. Here, transforms are notated in Matrix x Vector order, and in words we
describe what |
544 // the transform does from left to right. | 541 // the transform does from left to right. |
545 // | 542 // |
546 // 1. In our terminology, the "layer origin" refers to the top-left corner o
f a layer, and the | 543 // 1. In our terminology, the "layer origin" refers to the top-left corner o
f a layer, and the |
547 // positive Y-axis points downwards. This interpretation is valid because
the orthographic | 544 // positive Y-axis points downwards. This interpretation is valid because
the orthographic |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 | 870 |
874 gfx::Transform nextScrollCompensationMatrix = computeScrollCompensationMatri
xForChildren(layer, parentMatrix, currentScrollCompensationMatrix);; | 871 gfx::Transform nextScrollCompensationMatrix = computeScrollCompensationMatri
xForChildren(layer, parentMatrix, currentScrollCompensationMatrix);; |
875 | 872 |
876 gfx::Rect accumulatedDrawableContentRectOfChildren; | 873 gfx::Rect accumulatedDrawableContentRectOfChildren; |
877 for (size_t i = 0; i < layer->children().size(); ++i) { | 874 for (size_t i = 0; i < layer->children().size(); ++i) { |
878 LayerType* child = LayerTreeHostCommon::getChildAsRawPtr(layer->children
(), i); | 875 LayerType* child = LayerTreeHostCommon::getChildAsRawPtr(layer->children
(), i); |
879 gfx::Rect drawableContentRectOfChildSubtree; | 876 gfx::Rect drawableContentRectOfChildSubtree; |
880 calculateDrawPropertiesInternal<LayerType, LayerList, RenderSurfaceType>
(child, sublayerMatrix, nextHierarchyMatrix, nextScrollCompensationMatrix, | 877 calculateDrawPropertiesInternal<LayerType, LayerList, RenderSurfaceType>
(child, sublayerMatrix, nextHierarchyMatrix, nextScrollCompensationMatrix, |
881
clipRectForSubtree, clipRectForSubtreeInDescendantSpace, subtreeShouldBeClipped
, nearestAncestorThatMovesPixels, | 878
clipRectForSubtree, clipRectForSubtreeInDescendantSpace, subtreeShouldBeClipped
, nearestAncestorThatMovesPixels, |
882
renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFa
ctor, pageScaleFactor, | 879
renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFa
ctor, pageScaleFactor, |
883
subtreeCanUseLCDText, drawableContentRectOfChildSubtree); | 880
subtreeCanUseLCDText, drawableContentRectOfChildSubtree, updateTilePriorities); |
884 if (!drawableContentRectOfChildSubtree.IsEmpty()) { | 881 if (!drawableContentRectOfChildSubtree.IsEmpty()) { |
885 accumulatedDrawableContentRectOfChildren.Union(drawableContentRectOf
ChildSubtree); | 882 accumulatedDrawableContentRectOfChildren.Union(drawableContentRectOf
ChildSubtree); |
886 if (child->renderSurface()) | 883 if (child->renderSurface()) |
887 descendants.push_back(child); | 884 descendants.push_back(child); |
888 } | 885 } |
889 } | 886 } |
890 | 887 |
891 if (layer->renderSurface() && !isRootLayer(layer) && !layer->renderSurface()
->layerList().size()) { | 888 if (layer->renderSurface() && !isRootLayer(layer) && !layer->renderSurface()
->layerList().size()) { |
892 removeSurfaceForEarlyExit(layer, renderSurfaceLayerList); | 889 removeSurfaceForEarlyExit(layer, renderSurfaceLayerList); |
893 return; | 890 return; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 // Compute the replica's "originTransform" that maps from the replic
a's origin space to the target surface origin space. | 970 // Compute the replica's "originTransform" that maps from the replic
a's origin space to the target surface origin space. |
974 gfx::Transform replicaOriginTransform = layer->renderSurface()->draw
Transform() * surfaceOriginToReplicaOriginTransform; | 971 gfx::Transform replicaOriginTransform = layer->renderSurface()->draw
Transform() * surfaceOriginToReplicaOriginTransform; |
975 renderSurface->setReplicaDrawTransform(replicaOriginTransform); | 972 renderSurface->setReplicaDrawTransform(replicaOriginTransform); |
976 | 973 |
977 // Compute the replica's "screenSpaceTransform" that maps from the r
eplica's origin space to the screen's origin space. | 974 // Compute the replica's "screenSpaceTransform" that maps from the r
eplica's origin space to the screen's origin space. |
978 gfx::Transform replicaScreenSpaceTransform = layer->renderSurface()-
>screenSpaceTransform() * surfaceOriginToReplicaOriginTransform; | 975 gfx::Transform replicaScreenSpaceTransform = layer->renderSurface()-
>screenSpaceTransform() * surfaceOriginToReplicaOriginTransform; |
979 renderSurface->setReplicaScreenSpaceTransform(replicaScreenSpaceTran
sform); | 976 renderSurface->setReplicaScreenSpaceTransform(replicaScreenSpaceTran
sform); |
980 } | 977 } |
981 } | 978 } |
982 | 979 |
983 markLayerAsUpdated(layer); | 980 if (updateTilePriorities) |
| 981 updateTilePrioritiesForLayer(layer); |
984 | 982 |
985 // If neither this layer nor any of its children were added, early out. | 983 // If neither this layer nor any of its children were added, early out. |
986 if (sortingStartIndex == descendants.size()) | 984 if (sortingStartIndex == descendants.size()) |
987 return; | 985 return; |
988 | 986 |
989 // If preserves-3d then sort all the descendants in 3D so that they can be | 987 // If preserves-3d then sort all the descendants in 3D so that they can be |
990 // drawn from back to front. If the preserves-3d property is also set on the
parent then | 988 // drawn from back to front. If the preserves-3d property is also set on the
parent then |
991 // skip the sorting as the parent will sort all the descendants anyway. | 989 // skip the sorting as the parent will sort all the descendants anyway. |
992 if (layerSorter && descendants.size() && layer->preserves3D() && (!layer->pa
rent() || !layer->parent()->preserves3D())) | 990 if (layerSorter && descendants.size() && layer->preserves3D() && (!layer->pa
rent() || !layer->parent()->preserves3D())) |
993 sortLayers(descendants.begin() + sortingStartIndex, descendants.end(), l
ayerSorter); | 991 sortLayers(descendants.begin() + sortingStartIndex, descendants.end(), l
ayerSorter); |
(...skipping 11 matching lines...) Expand all Loading... |
1005 { | 1003 { |
1006 gfx::Rect totalDrawableContentRect; | 1004 gfx::Rect totalDrawableContentRect; |
1007 gfx::Transform identityMatrix; | 1005 gfx::Transform identityMatrix; |
1008 gfx::Transform deviceScaleTransform; | 1006 gfx::Transform deviceScaleTransform; |
1009 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); | 1007 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); |
1010 std::vector<scoped_refptr<Layer> > dummyLayerList; | 1008 std::vector<scoped_refptr<Layer> > dummyLayerList; |
1011 | 1009 |
1012 // The root layer's renderSurface should receive the deviceViewport as the i
nitial clipRect. | 1010 // The root layer's renderSurface should receive the deviceViewport as the i
nitial clipRect. |
1013 bool subtreeShouldBeClipped = true; | 1011 bool subtreeShouldBeClipped = true; |
1014 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); | 1012 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); |
| 1013 bool updateTilePriorities = false; |
1015 | 1014 |
1016 // This function should have received a root layer. | 1015 // This function should have received a root layer. |
1017 DCHECK(isRootLayer(rootLayer)); | 1016 DCHECK(isRootLayer(rootLayer)); |
1018 | 1017 |
1019 preCalculateMetaInformation<Layer>(rootLayer); | 1018 preCalculateMetaInformation<Layer>(rootLayer); |
1020 calculateDrawPropertiesInternal<Layer, std::vector<scoped_refptr<Layer> >, R
enderSurface>( | 1019 calculateDrawPropertiesInternal<Layer, std::vector<scoped_refptr<Layer> >, R
enderSurface>( |
1021 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, | 1020 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, |
1022 deviceViewportRect, deviceViewportRect, subtreeShouldBeClipped, 0, rende
rSurfaceLayerList, | 1021 deviceViewportRect, deviceViewportRect, subtreeShouldBeClipped, 0, rende
rSurfaceLayerList, |
1023 dummyLayerList, 0, maxTextureSize, | 1022 dummyLayerList, 0, maxTextureSize, |
1024 deviceScaleFactor, pageScaleFactor, canUseLCDText, totalDrawableContentR
ect); | 1023 deviceScaleFactor, pageScaleFactor, canUseLCDText, totalDrawableContentR
ect, |
| 1024 updateTilePriorities); |
1025 | 1025 |
1026 // The dummy layer list should not have been used. | 1026 // The dummy layer list should not have been used. |
1027 DCHECK(dummyLayerList.size() == 0); | 1027 DCHECK(dummyLayerList.size() == 0); |
1028 // A root layer renderSurface should always exist after calculateDrawPropert
ies. | 1028 // A root layer renderSurface should always exist after calculateDrawPropert
ies. |
1029 DCHECK(rootLayer->renderSurface()); | 1029 DCHECK(rootLayer->renderSurface()); |
1030 } | 1030 } |
1031 | 1031 |
1032 void LayerTreeHostCommon::calculateDrawProperties(LayerImpl* rootLayer, const gf
x::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int
maxTextureSize, bool canUseLCDText, std::vector<LayerImpl*>& renderSurfaceLayer
List) | 1032 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) |
1033 { | 1033 { |
1034 gfx::Rect totalDrawableContentRect; | 1034 gfx::Rect totalDrawableContentRect; |
1035 gfx::Transform identityMatrix; | 1035 gfx::Transform identityMatrix; |
1036 gfx::Transform deviceScaleTransform; | 1036 gfx::Transform deviceScaleTransform; |
1037 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); | 1037 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); |
1038 std::vector<LayerImpl*> dummyLayerList; | 1038 std::vector<LayerImpl*> dummyLayerList; |
1039 LayerSorter layerSorter; | 1039 LayerSorter layerSorter; |
1040 | 1040 |
1041 // The root layer's renderSurface should receive the deviceViewport as the i
nitial clipRect. | 1041 // The root layer's renderSurface should receive the deviceViewport as the i
nitial clipRect. |
1042 bool subtreeShouldBeClipped = true; | 1042 bool subtreeShouldBeClipped = true; |
1043 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); | 1043 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); |
1044 | 1044 |
1045 // This function should have received a root layer. | 1045 // This function should have received a root layer. |
1046 DCHECK(isRootLayer(rootLayer)); | 1046 DCHECK(isRootLayer(rootLayer)); |
1047 | 1047 |
1048 preCalculateMetaInformation<LayerImpl>(rootLayer); | 1048 preCalculateMetaInformation<LayerImpl>(rootLayer); |
1049 calculateDrawPropertiesInternal<LayerImpl, std::vector<LayerImpl*>, RenderSu
rfaceImpl>( | 1049 calculateDrawPropertiesInternal<LayerImpl, std::vector<LayerImpl*>, RenderSu
rfaceImpl>( |
1050 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, | 1050 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, |
1051 deviceViewportRect, deviceViewportRect, subtreeShouldBeClipped, 0, rende
rSurfaceLayerList, | 1051 deviceViewportRect, deviceViewportRect, subtreeShouldBeClipped, 0, rende
rSurfaceLayerList, |
1052 dummyLayerList, &layerSorter, maxTextureSize, | 1052 dummyLayerList, &layerSorter, maxTextureSize, |
1053 deviceScaleFactor, pageScaleFactor, canUseLCDText, totalDrawableContentR
ect); | 1053 deviceScaleFactor, pageScaleFactor, canUseLCDText, totalDrawableContentR
ect, |
| 1054 updateTilePriorities); |
1054 | 1055 |
1055 // The dummy layer list should not have been used. | 1056 // The dummy layer list should not have been used. |
1056 DCHECK(dummyLayerList.size() == 0); | 1057 DCHECK(dummyLayerList.size() == 0); |
1057 // A root layer renderSurface should always exist after calculateDrawPropert
ies. | 1058 // A root layer renderSurface should always exist after calculateDrawPropert
ies. |
1058 DCHECK(rootLayer->renderSurface()); | 1059 DCHECK(rootLayer->renderSurface()); |
1059 } | 1060 } |
1060 | 1061 |
1061 static bool pointHitsRect(const gfx::PointF& screenSpacePoint, const gfx::Transf
orm& localSpaceToScreenSpaceTransform, gfx::RectF localSpaceRect) | 1062 static bool pointHitsRect(const gfx::PointF& screenSpacePoint, const gfx::Transf
orm& localSpaceToScreenSpaceTransform, gfx::RectF localSpaceRect) |
1062 { | 1063 { |
1063 // If the transform is not invertible, then assume that this point doesn't h
it this rect. | 1064 // If the transform is not invertible, then assume that this point doesn't h
it this rect. |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 | 1184 |
1184 // At this point, we think the point does hit the touch event handler region o
n the layer, but we need to walk up | 1185 // At this point, we think the point does hit the touch event handler region o
n the layer, but we need to walk up |
1185 // the parents to ensure that the layer was not clipped in such a way that the | 1186 // the parents to ensure that the layer was not clipped in such a way that the |
1186 // hit point actually should not hit the layer. | 1187 // hit point actually should not hit the layer. |
1187 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, layerImpl)) | 1188 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, layerImpl)) |
1188 return false; | 1189 return false; |
1189 | 1190 |
1190 return true; | 1191 return true; |
1191 } | 1192 } |
1192 } // namespace cc | 1193 } // namespace cc |
OLD | NEW |