Chromium Code Reviews| 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 return true; | 259 return true; |
| 260 | 260 |
| 261 // If the layer has a reflection. | 261 // If the layer has a reflection. |
| 262 if (layer->replicaLayer()) | 262 if (layer->replicaLayer()) |
| 263 return true; | 263 return true; |
| 264 | 264 |
| 265 // If the layer uses a CSS filter. | 265 // If the layer uses a CSS filter. |
| 266 if (!layer->filters().isEmpty() || !layer->backgroundFilters().isEmpty() || layer->filter()) | 266 if (!layer->filters().isEmpty() || !layer->backgroundFilters().isEmpty() || layer->filter()) |
| 267 return true; | 267 return true; |
| 268 | 268 |
| 269 // Cache this value, because otherwise it walks the entire subtree several t imes. | 269 int numDescendantsThatDrawContent = layer->drawProperties().num_descendants_ that_draw_content; |
| 270 int descendantsDrawContent = layer->descendantsDrawContent(); | |
| 271 | 270 |
| 272 // If the layer flattens its subtree (i.e. the layer doesn't preserve-3d), b ut it is | 271 // If the layer flattens its subtree (i.e. the layer doesn't preserve-3d), b ut it is |
| 273 // treated as a 3D object by its parent (i.e. parent does preserve-3d). | 272 // treated as a 3D object by its parent (i.e. parent does preserve-3d). |
| 274 if (layerIsInExisting3DRenderingContext(layer) && !layer->preserves3D() && d escendantsDrawContent > 0) | 273 if (layerIsInExisting3DRenderingContext(layer) && !layer->preserves3D() && n umDescendantsThatDrawContent > 0) |
| 275 return true; | 274 return true; |
| 276 | 275 |
| 277 // If the layer clips its descendants but it is not axis-aligned with respec t to its parent. | 276 // If the layer clips its descendants but it is not axis-aligned with respec t to its parent. |
| 278 if (layerClipsSubtree(layer) && !axisAlignedWithRespectToParent && descendan tsDrawContent > 0) | 277 if (layerClipsSubtree(layer) && !axisAlignedWithRespectToParent && numDescen dantsThatDrawContent > 0) |
| 279 return true; | 278 return true; |
| 280 | 279 |
| 281 // If the layer has opacity != 1 and does not have a preserves-3d transform style. | 280 // If the layer has some translucency and does not have a preserves-3d trans form style. |
| 282 if (layer->opacity() != 1 && !layer->preserves3D() && descendantsDrawContent > 0 | 281 // This condition only needs a render surface if two or more layers in the |
| 283 && (layer->drawsContent() || descendantsDrawContent > 1)) | 282 // subtree overlap. But checking layer overlaps is unnecessarily costly so |
| 283 // instead we conservatively create a surface whenever at least two layers | |
| 284 // draw content for this subtree. | |
| 285 bool atLeastTwoLayersInSubtreeDrawContent = layer->hasDelegatedContent() || | |
| 286 (numDescendantsThatDrawContent > 0 && (layer->drawsContent() || numD escendantsThatDrawContent > 1)); | |
|
jamesr
2012/12/12 16:54:25
nit: odd indentation. 4 spaces for a continuation
| |
| 287 | |
| 288 if (layer->opacity() != 1 && !layer->preserves3D() && atLeastTwoLayersInSubt reeDrawContent) | |
| 284 return true; | 289 return true; |
| 285 | 290 |
| 286 return false; | 291 return false; |
| 287 } | 292 } |
| 288 | 293 |
| 289 gfx::Transform computeScrollCompensationForThisLayer(LayerImpl* scrollingLayer, const gfx::Transform& parentMatrix) | 294 gfx::Transform computeScrollCompensationForThisLayer(LayerImpl* scrollingLayer, const gfx::Transform& parentMatrix) |
| 290 { | 295 { |
| 291 // For every layer that has non-zero scrollDelta, we have to compute a trans form that can undo the | 296 // For every layer that has non-zero scrollDelta, we have to compute a trans form that can undo the |
| 292 // scrollDelta translation. In particular, we want this matrix to premultipl y a fixed-position layer's | 297 // scrollDelta translation. In particular, we want this matrix to premultipl y a fixed-position layer's |
| 293 // parentMatrix, so we design this transform in three steps as follows. The steps described here apply | 298 // parentMatrix, so we design this transform in three steps as follows. The steps described here apply |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 // layers from the end of the list. | 422 // layers from the end of the list. |
| 418 while (renderSurfaceLayerList.back() != layerToRemove) { | 423 while (renderSurfaceLayerList.back() != layerToRemove) { |
| 419 renderSurfaceLayerList.back()->clearRenderSurface(); | 424 renderSurfaceLayerList.back()->clearRenderSurface(); |
| 420 renderSurfaceLayerList.pop_back(); | 425 renderSurfaceLayerList.pop_back(); |
| 421 } | 426 } |
| 422 DCHECK(renderSurfaceLayerList.back() == layerToRemove); | 427 DCHECK(renderSurfaceLayerList.back() == layerToRemove); |
| 423 renderSurfaceLayerList.pop_back(); | 428 renderSurfaceLayerList.pop_back(); |
| 424 layerToRemove->clearRenderSurface(); | 429 layerToRemove->clearRenderSurface(); |
| 425 } | 430 } |
| 426 | 431 |
| 432 // Recursively walks the layer tree to compute any information that is needed | |
| 433 // before doing the main recursion. | |
| 434 template<typename LayerType> | |
| 435 static void preCalculateMetaInformation(LayerType* layer) | |
| 436 { | |
| 437 int numDescendantsThatDrawContent = 0; | |
| 438 | |
| 439 for (size_t i = 0; i < layer->children().size(); ++i) { | |
| 440 LayerType* childLayer = layer->children()[i]; | |
| 441 preCalculateMetaInformation<LayerType>(childLayer); | |
| 442 numDescendantsThatDrawContent += childLayer->drawsContent() ? 1 : 0; | |
| 443 numDescendantsThatDrawContent += childLayer->drawProperties().num_descen dants_that_draw_content; | |
| 444 } | |
| 445 | |
| 446 layer->drawProperties().num_descendants_that_draw_content = numDescendantsTh atDrawContent; | |
| 447 } | |
| 448 | |
| 427 // Recursively walks the layer tree starting at the given node and computes all the | 449 // Recursively walks the layer tree starting at the given node and computes all the |
| 428 // necessary transformations, clipRects, render surfaces, etc. | 450 // necessary transformations, clipRects, render surfaces, etc. |
| 429 template<typename LayerType, typename LayerList, typename RenderSurfaceType> | 451 template<typename LayerType, typename LayerList, typename RenderSurfaceType> |
| 430 static void calculateDrawPropertiesInternal(LayerType* layer, const gfx::Transfo rm& parentMatrix, | 452 static void calculateDrawPropertiesInternal(LayerType* layer, const gfx::Transfo rm& parentMatrix, |
| 431 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro llCompensationMatrix, | 453 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro llCompensationMatrix, |
| 432 const gfx::Rect& clipRectFromAncestor, const gfx::Rect& clipRectFromAncestor InDescendantSpace, bool ancestorClipsSubtree, | 454 const gfx::Rect& clipRectFromAncestor, const gfx::Rect& clipRectFromAncestor InDescendantSpace, bool ancestorClipsSubtree, |
| 433 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList, | 455 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList, |
| 434 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, gfx::Rect& drawableContentRectOfSubtree) | 456 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, gfx::Rect& drawableContentRectOfSubtree) |
| 435 { | 457 { |
| 436 // This function computes the new matrix transformations recursively for thi s | 458 // This function computes the new matrix transformations recursively for thi s |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 880 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); | 902 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); |
| 881 std::vector<scoped_refptr<Layer> > dummyLayerList; | 903 std::vector<scoped_refptr<Layer> > dummyLayerList; |
| 882 | 904 |
| 883 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect. | 905 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect. |
| 884 bool subtreeShouldBeClipped = true; | 906 bool subtreeShouldBeClipped = true; |
| 885 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); | 907 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); |
| 886 | 908 |
| 887 // This function should have received a root layer. | 909 // This function should have received a root layer. |
| 888 DCHECK(isRootLayer(rootLayer)); | 910 DCHECK(isRootLayer(rootLayer)); |
| 889 | 911 |
| 912 cc::preCalculateMetaInformation<Layer>(rootLayer); | |
|
jamesr
2012/12/12 16:54:25
we're in namespace cc:: here, aren't we? we should
| |
| 890 cc::calculateDrawPropertiesInternal<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface>( | 913 cc::calculateDrawPropertiesInternal<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface>( |
| 891 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, | 914 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, |
| 892 deviceViewportRect, deviceViewportRect, subtreeShouldBeClipped, 0, rende rSurfaceLayerList, | 915 deviceViewportRect, deviceViewportRect, subtreeShouldBeClipped, 0, rende rSurfaceLayerList, |
| 893 dummyLayerList, 0, maxTextureSize, | 916 dummyLayerList, 0, maxTextureSize, |
| 894 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); | 917 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); |
| 895 | 918 |
| 896 // The dummy layer list should not have been used. | 919 // The dummy layer list should not have been used. |
| 897 DCHECK(dummyLayerList.size() == 0); | 920 DCHECK(dummyLayerList.size() == 0); |
| 898 // A root layer renderSurface should always exist after calculateDrawPropert ies. | 921 // A root layer renderSurface should always exist after calculateDrawPropert ies. |
| 899 DCHECK(rootLayer->renderSurface()); | 922 DCHECK(rootLayer->renderSurface()); |
| 900 } | 923 } |
| 901 | 924 |
| 902 void LayerTreeHostCommon::calculateDrawProperties(LayerImpl* rootLayer, const gf x::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int maxTextureSize, std::vector<LayerImpl*>& renderSurfaceLayerList) | 925 void LayerTreeHostCommon::calculateDrawProperties(LayerImpl* rootLayer, const gf x::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int maxTextureSize, std::vector<LayerImpl*>& renderSurfaceLayerList) |
| 903 { | 926 { |
| 904 gfx::Rect totalDrawableContentRect; | 927 gfx::Rect totalDrawableContentRect; |
| 905 gfx::Transform identityMatrix; | 928 gfx::Transform identityMatrix; |
| 906 gfx::Transform deviceScaleTransform; | 929 gfx::Transform deviceScaleTransform; |
| 907 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); | 930 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); |
| 908 std::vector<LayerImpl*> dummyLayerList; | 931 std::vector<LayerImpl*> dummyLayerList; |
| 909 LayerSorter layerSorter; | 932 LayerSorter layerSorter; |
| 910 | 933 |
| 911 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect. | 934 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect. |
| 912 bool subtreeShouldBeClipped = true; | 935 bool subtreeShouldBeClipped = true; |
| 913 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); | 936 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); |
| 914 | 937 |
| 915 // This function should have received a root layer. | 938 // This function should have received a root layer. |
| 916 DCHECK(isRootLayer(rootLayer)); | 939 DCHECK(isRootLayer(rootLayer)); |
| 917 | 940 |
| 941 cc::preCalculateMetaInformation<LayerImpl>(rootLayer); | |
|
jamesr
2012/12/12 16:54:25
ditto
| |
| 918 cc::calculateDrawPropertiesInternal<LayerImpl, std::vector<LayerImpl*>, Rend erSurfaceImpl>( | 942 cc::calculateDrawPropertiesInternal<LayerImpl, std::vector<LayerImpl*>, Rend erSurfaceImpl>( |
| 919 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, | 943 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, |
| 920 deviceViewportRect, deviceViewportRect, subtreeShouldBeClipped, 0, rende rSurfaceLayerList, | 944 deviceViewportRect, deviceViewportRect, subtreeShouldBeClipped, 0, rende rSurfaceLayerList, |
| 921 dummyLayerList, &layerSorter, maxTextureSize, | 945 dummyLayerList, &layerSorter, maxTextureSize, |
| 922 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); | 946 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); |
| 923 | 947 |
| 924 // The dummy layer list should not have been used. | 948 // The dummy layer list should not have been used. |
| 925 DCHECK(dummyLayerList.size() == 0); | 949 DCHECK(dummyLayerList.size() == 0); |
| 926 // A root layer renderSurface should always exist after calculateDrawPropert ies. | 950 // A root layer renderSurface should always exist after calculateDrawPropert ies. |
| 927 DCHECK(rootLayer->renderSurface()); | 951 DCHECK(rootLayer->renderSurface()); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1044 | 1068 |
| 1045 foundLayer = currentLayer; | 1069 foundLayer = currentLayer; |
| 1046 break; | 1070 break; |
| 1047 } | 1071 } |
| 1048 | 1072 |
| 1049 // This can potentially return 0, which means the screenSpacePoint did not s uccessfully hit test any layers, not even the root layer. | 1073 // This can potentially return 0, which means the screenSpacePoint did not s uccessfully hit test any layers, not even the root layer. |
| 1050 return foundLayer; | 1074 return foundLayer; |
| 1051 } | 1075 } |
| 1052 | 1076 |
| 1053 } // namespace cc | 1077 } // namespace cc |
| OLD | NEW |