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

Side by Side Diff: cc/layer_tree_host_common.cc

Issue 12045086: cc: Throttle tile priority updates to once a frame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
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/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
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()) {
247 layer->replicaLayer()->didUpdateTransforms(); 247 layer->replicaLayer()->updateTilePriorities();
248 if (layer->replicaLayer()->maskLayer()) 248 if (layer->replicaLayer()->maskLayer())
249 layer->replicaLayer()->maskLayer()->didUpdateTransforms(); 249 layer->replicaLayer()->maskLayer()->updateTilePriorities();
250 } 250 }
251 } 251 }
252 252
253 static inline void markLayerAsUpdated(Layer* layer) 253 static inline void updateTilePrioritiesForLayer(Layer* layer)
254 { 254 {
255 } 255 }
256 256
257 template<typename LayerType> 257 template<typename LayerType>
258 static bool subtreeShouldRenderToSeparateSurface(LayerType* layer, bool axisAlig nedWithRespectToParent) 258 static bool subtreeShouldRenderToSeparateSurface(LayerType* layer, bool axisAlig nedWithRespectToParent)
259 { 259 {
260 // 260 //
261 // A layer and its descendants should render onto a new RenderSurfaceImpl if any of these rules hold: 261 // A layer and its descendants should render onto a new RenderSurfaceImpl if any of these rules hold:
262 // 262 //
263 263
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 } 527 }
528 528
529 // Recursively walks the layer tree starting at the given node and computes all the 529 // Recursively walks the layer tree starting at the given node and computes all the
530 // necessary transformations, clipRects, render surfaces, etc. 530 // necessary transformations, clipRects, render surfaces, etc.
531 template<typename LayerType, typename LayerList, typename RenderSurfaceType> 531 template<typename LayerType, typename LayerList, typename RenderSurfaceType>
532 static void calculateDrawPropertiesInternal(LayerType* layer, const gfx::Transfo rm& parentMatrix, 532 static void calculateDrawPropertiesInternal(LayerType* layer, const gfx::Transfo rm& parentMatrix,
533 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro llCompensationMatrix, 533 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro llCompensationMatrix,
534 const gfx::Rect& clipRectFromAncestor, const gfx::Rect& clipRectFromAncestor InDescendantSpace, bool ancestorClipsSubtree, 534 const gfx::Rect& clipRectFromAncestor, const gfx::Rect& clipRectFromAncestor InDescendantSpace, bool ancestorClipsSubtree,
535 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList, 535 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList,
536 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, bool subtreeCanUseLCDText, 536 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, bool subtreeCanUseLCDText,
537 gfx::Rect& drawableContentRectOfSubtree) 537 gfx::Rect& drawableContentRectOfSubtree, bool updateTilePriorities)
538 { 538 {
539 // This function computes the new matrix transformations recursively for thi s 539 // 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. 540 // layer and all its descendants. It also computes the appropriate render su rfaces.
541 // Some important points to remember: 541 // Some important points to remember:
542 // 542 //
543 // 0. Here, transforms are notated in Matrix x Vector order, and in words we describe what 543 // 0. Here, transforms are notated in Matrix x Vector order, and in words we describe what
544 // the transform does from left to right. 544 // the transform does from left to right.
545 // 545 //
546 // 1. In our terminology, the "layer origin" refers to the top-left corner o f a layer, and the 546 // 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 547 // positive Y-axis points downwards. This interpretation is valid because the orthographic
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 873
874 gfx::Transform nextScrollCompensationMatrix = computeScrollCompensationMatri xForChildren(layer, parentMatrix, currentScrollCompensationMatrix);; 874 gfx::Transform nextScrollCompensationMatrix = computeScrollCompensationMatri xForChildren(layer, parentMatrix, currentScrollCompensationMatrix);;
875 875
876 gfx::Rect accumulatedDrawableContentRectOfChildren; 876 gfx::Rect accumulatedDrawableContentRectOfChildren;
877 for (size_t i = 0; i < layer->children().size(); ++i) { 877 for (size_t i = 0; i < layer->children().size(); ++i) {
878 LayerType* child = LayerTreeHostCommon::getChildAsRawPtr(layer->children (), i); 878 LayerType* child = LayerTreeHostCommon::getChildAsRawPtr(layer->children (), i);
879 gfx::Rect drawableContentRectOfChildSubtree; 879 gfx::Rect drawableContentRectOfChildSubtree;
880 calculateDrawPropertiesInternal<LayerType, LayerList, RenderSurfaceType> (child, sublayerMatrix, nextHierarchyMatrix, nextScrollCompensationMatrix, 880 calculateDrawPropertiesInternal<LayerType, LayerList, RenderSurfaceType> (child, sublayerMatrix, nextHierarchyMatrix, nextScrollCompensationMatrix,
881 clipRectForSubtree, clipRectForSubtreeInDescendantSpace, subtreeShouldBeClipped , nearestAncestorThatMovesPixels, 881 clipRectForSubtree, clipRectForSubtreeInDescendantSpace, subtreeShouldBeClipped , nearestAncestorThatMovesPixels,
882 renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFa ctor, pageScaleFactor, 882 renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFa ctor, pageScaleFactor,
883 subtreeCanUseLCDText, drawableContentRectOfChildSubtree); 883 subtreeCanUseLCDText, drawableContentRectOfChildSubtree, updateTilePriorities);
884 if (!drawableContentRectOfChildSubtree.IsEmpty()) { 884 if (!drawableContentRectOfChildSubtree.IsEmpty()) {
885 accumulatedDrawableContentRectOfChildren.Union(drawableContentRectOf ChildSubtree); 885 accumulatedDrawableContentRectOfChildren.Union(drawableContentRectOf ChildSubtree);
886 if (child->renderSurface()) 886 if (child->renderSurface())
887 descendants.push_back(child); 887 descendants.push_back(child);
888 } 888 }
889 } 889 }
890 890
891 if (layer->renderSurface() && !isRootLayer(layer) && !layer->renderSurface() ->layerList().size()) { 891 if (layer->renderSurface() && !isRootLayer(layer) && !layer->renderSurface() ->layerList().size()) {
892 removeSurfaceForEarlyExit(layer, renderSurfaceLayerList); 892 removeSurfaceForEarlyExit(layer, renderSurfaceLayerList);
893 return; 893 return;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 // Compute the replica's "originTransform" that maps from the replic a's origin space to the target surface origin space. 973 // 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; 974 gfx::Transform replicaOriginTransform = layer->renderSurface()->draw Transform() * surfaceOriginToReplicaOriginTransform;
975 renderSurface->setReplicaDrawTransform(replicaOriginTransform); 975 renderSurface->setReplicaDrawTransform(replicaOriginTransform);
976 976
977 // Compute the replica's "screenSpaceTransform" that maps from the r eplica's origin space to the screen's origin space. 977 // 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; 978 gfx::Transform replicaScreenSpaceTransform = layer->renderSurface()- >screenSpaceTransform() * surfaceOriginToReplicaOriginTransform;
979 renderSurface->setReplicaScreenSpaceTransform(replicaScreenSpaceTran sform); 979 renderSurface->setReplicaScreenSpaceTransform(replicaScreenSpaceTran sform);
980 } 980 }
981 } 981 }
982 982
983 markLayerAsUpdated(layer); 983 if (updateTilePriorities)
984 updateTilePrioritiesForLayer(layer);
984 985
985 // If neither this layer nor any of its children were added, early out. 986 // If neither this layer nor any of its children were added, early out.
986 if (sortingStartIndex == descendants.size()) 987 if (sortingStartIndex == descendants.size())
987 return; 988 return;
988 989
989 // If preserves-3d then sort all the descendants in 3D so that they can be 990 // 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 991 // 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. 992 // 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())) 993 if (layerSorter && descendants.size() && layer->preserves3D() && (!layer->pa rent() || !layer->parent()->preserves3D()))
993 sortLayers(descendants.begin() + sortingStartIndex, descendants.end(), l ayerSorter); 994 sortLayers(descendants.begin() + sortingStartIndex, descendants.end(), l ayerSorter);
(...skipping 11 matching lines...) Expand all
1005 { 1006 {
1006 gfx::Rect totalDrawableContentRect; 1007 gfx::Rect totalDrawableContentRect;
1007 gfx::Transform identityMatrix; 1008 gfx::Transform identityMatrix;
1008 gfx::Transform deviceScaleTransform; 1009 gfx::Transform deviceScaleTransform;
1009 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); 1010 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor);
1010 std::vector<scoped_refptr<Layer> > dummyLayerList; 1011 std::vector<scoped_refptr<Layer> > dummyLayerList;
1011 1012
1012 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect. 1013 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect.
1013 bool subtreeShouldBeClipped = true; 1014 bool subtreeShouldBeClipped = true;
1014 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); 1015 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize);
1016 bool updateTilePriorities = false;
1015 1017
1016 // This function should have received a root layer. 1018 // This function should have received a root layer.
1017 DCHECK(isRootLayer(rootLayer)); 1019 DCHECK(isRootLayer(rootLayer));
1018 1020
1019 preCalculateMetaInformation<Layer>(rootLayer); 1021 preCalculateMetaInformation<Layer>(rootLayer);
1020 calculateDrawPropertiesInternal<Layer, std::vector<scoped_refptr<Layer> >, R enderSurface>( 1022 calculateDrawPropertiesInternal<Layer, std::vector<scoped_refptr<Layer> >, R enderSurface>(
1021 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, 1023 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix,
1022 deviceViewportRect, deviceViewportRect, subtreeShouldBeClipped, 0, rende rSurfaceLayerList, 1024 deviceViewportRect, deviceViewportRect, subtreeShouldBeClipped, 0, rende rSurfaceLayerList,
1023 dummyLayerList, 0, maxTextureSize, 1025 dummyLayerList, 0, maxTextureSize,
1024 deviceScaleFactor, pageScaleFactor, canUseLCDText, totalDrawableContentR ect); 1026 deviceScaleFactor, pageScaleFactor, canUseLCDText, totalDrawableContentR ect,
1027 updateTilePriorities);
1025 1028
1026 // The dummy layer list should not have been used. 1029 // The dummy layer list should not have been used.
1027 DCHECK(dummyLayerList.size() == 0); 1030 DCHECK(dummyLayerList.size() == 0);
1028 // A root layer renderSurface should always exist after calculateDrawPropert ies. 1031 // A root layer renderSurface should always exist after calculateDrawPropert ies.
1029 DCHECK(rootLayer->renderSurface()); 1032 DCHECK(rootLayer->renderSurface());
1030 } 1033 }
1031 1034
1032 void LayerTreeHostCommon::calculateDrawProperties(LayerImpl* rootLayer, const gf x::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int maxTextureSize, bool canUseLCDText, std::vector<LayerImpl*>& renderSurfaceLayer List) 1035 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 { 1036 {
1034 gfx::Rect totalDrawableContentRect; 1037 gfx::Rect totalDrawableContentRect;
1035 gfx::Transform identityMatrix; 1038 gfx::Transform identityMatrix;
1036 gfx::Transform deviceScaleTransform; 1039 gfx::Transform deviceScaleTransform;
1037 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); 1040 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor);
1038 std::vector<LayerImpl*> dummyLayerList; 1041 std::vector<LayerImpl*> dummyLayerList;
1039 LayerSorter layerSorter; 1042 LayerSorter layerSorter;
1040 1043
1041 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect. 1044 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect.
1042 bool subtreeShouldBeClipped = true; 1045 bool subtreeShouldBeClipped = true;
1043 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); 1046 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize);
1044 1047
1045 // This function should have received a root layer. 1048 // This function should have received a root layer.
1046 DCHECK(isRootLayer(rootLayer)); 1049 DCHECK(isRootLayer(rootLayer));
1047 1050
1048 preCalculateMetaInformation<LayerImpl>(rootLayer); 1051 preCalculateMetaInformation<LayerImpl>(rootLayer);
1049 calculateDrawPropertiesInternal<LayerImpl, std::vector<LayerImpl*>, RenderSu rfaceImpl>( 1052 calculateDrawPropertiesInternal<LayerImpl, std::vector<LayerImpl*>, RenderSu rfaceImpl>(
1050 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, 1053 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix,
1051 deviceViewportRect, deviceViewportRect, subtreeShouldBeClipped, 0, rende rSurfaceLayerList, 1054 deviceViewportRect, deviceViewportRect, subtreeShouldBeClipped, 0, rende rSurfaceLayerList,
1052 dummyLayerList, &layerSorter, maxTextureSize, 1055 dummyLayerList, &layerSorter, maxTextureSize,
1053 deviceScaleFactor, pageScaleFactor, canUseLCDText, totalDrawableContentR ect); 1056 deviceScaleFactor, pageScaleFactor, canUseLCDText, totalDrawableContentR ect,
1057 updateTilePriorities);
1054 1058
1055 // The dummy layer list should not have been used. 1059 // The dummy layer list should not have been used.
1056 DCHECK(dummyLayerList.size() == 0); 1060 DCHECK(dummyLayerList.size() == 0);
1057 // A root layer renderSurface should always exist after calculateDrawPropert ies. 1061 // A root layer renderSurface should always exist after calculateDrawPropert ies.
1058 DCHECK(rootLayer->renderSurface()); 1062 DCHECK(rootLayer->renderSurface());
1059 } 1063 }
1060 1064
1061 static bool pointHitsRect(const gfx::PointF& screenSpacePoint, const gfx::Transf orm& localSpaceToScreenSpaceTransform, gfx::RectF localSpaceRect) 1065 static bool pointHitsRect(const gfx::PointF& screenSpacePoint, const gfx::Transf orm& localSpaceToScreenSpaceTransform, gfx::RectF localSpaceRect)
1062 { 1066 {
1063 // If the transform is not invertible, then assume that this point doesn't h it this rect. 1067 // 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
1183 1187
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 1188 // 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 1189 // 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. 1190 // hit point actually should not hit the layer.
1187 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, layerImpl)) 1191 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, layerImpl))
1188 return false; 1192 return false;
1189 1193
1190 return true; 1194 return true;
1191 } 1195 }
1192 } // namespace cc 1196 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698