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 "cc/layer.h" | 9 #include "cc/layer.h" |
10 #include "cc/layer_impl.h" | 10 #include "cc/layer_impl.h" |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 return true; | 242 return true; |
243 | 243 |
244 // If the layer has a reflection. | 244 // If the layer has a reflection. |
245 if (layer->replicaLayer()) | 245 if (layer->replicaLayer()) |
246 return true; | 246 return true; |
247 | 247 |
248 // If the layer uses a CSS filter. | 248 // If the layer uses a CSS filter. |
249 if (!layer->filters().isEmpty() || !layer->backgroundFilters().isEmpty() || layer->filter()) | 249 if (!layer->filters().isEmpty() || !layer->backgroundFilters().isEmpty() || layer->filter()) |
250 return true; | 250 return true; |
251 | 251 |
252 // Cache this value, because otherwise it walks the entire subtree several t imes. | 252 // Caching this value avoids unnecessary virtual function overheads. |
253 int descendantsDrawContent = layer->descendantsDrawContent(); | 253 int numDescendantsThatDrawContent = layer->numDescendantsThatDrawContent(); |
254 | 254 |
255 // If the layer flattens its subtree (i.e. the layer doesn't preserve-3d), b ut it is | 255 // If the layer flattens its subtree (i.e. the layer doesn't preserve-3d), b ut it is |
256 // treated as a 3D object by its parent (i.e. parent does preserve-3d). | 256 // treated as a 3D object by its parent (i.e. parent does preserve-3d). |
257 if (layerIsInExisting3DRenderingContext(layer) && !layer->preserves3D() && d escendantsDrawContent > 0) | 257 if (layerIsInExisting3DRenderingContext(layer) && !layer->preserves3D() && n umDescendantsThatDrawContent > 0) |
258 return true; | 258 return true; |
259 | 259 |
260 // If the layer clips its descendants but it is not axis-aligned with respec t to its parent. | 260 // If the layer clips its descendants but it is not axis-aligned with respec t to its parent. |
261 if (layerClipsSubtree(layer) && !axisAlignedWithRespectToParent && descendan tsDrawContent > 0) | 261 if (layerClipsSubtree(layer) && !axisAlignedWithRespectToParent && numDescen dantsThatDrawContent > 0) |
262 return true; | 262 return true; |
263 | 263 |
264 // If the layer has opacity != 1 and does not have a preserves-3d transform style. | 264 // If the layer has some translucency and does not have a preserves-3d trans form style. |
265 if (layer->opacity() != 1 && !layer->preserves3D() && descendantsDrawContent > 0 | 265 // This condition only needs a render surface if two or more layers in the |
266 && (layer->drawsContent() || descendantsDrawContent > 1)) | 266 // subtree overlap. But checking layer overlaps is unnecesarily costly so |
267 // instead we conservatively create a surface whenever at least two layers | |
268 // draw content for this subtree. | |
269 bool atLeastTwoLayersInSubtreeDrawContent = numDescendantsThatDrawContent > 0 | |
danakj
2012/12/03 18:33:41
i like this var name
| |
270 && (layer->drawsContent() || numDescendantsThatDrawContent > 1); | |
danakj
2012/12/03 18:33:41
the "if" seems to have disappeared entirely.
| |
271 if (layer->opacity() != 1 && !layer->preserves3D() && atLeastTwoLayersInSubt reeDrawContent) | |
267 return true; | 272 return true; |
268 | 273 |
269 return false; | 274 return false; |
270 } | 275 } |
271 | 276 |
272 gfx::Transform computeScrollCompensationForThisLayer(LayerImpl* scrollingLayer, const gfx::Transform& parentMatrix) | 277 gfx::Transform computeScrollCompensationForThisLayer(LayerImpl* scrollingLayer, const gfx::Transform& parentMatrix) |
273 { | 278 { |
274 // For every layer that has non-zero scrollDelta, we have to compute a trans form that can undo the | 279 // For every layer that has non-zero scrollDelta, we have to compute a trans form that can undo the |
275 // scrollDelta translation. In particular, we want this matrix to premultipl y a fixed-position layer's | 280 // scrollDelta translation. In particular, we want this matrix to premultipl y a fixed-position layer's |
276 // parentMatrix, so we design this transform in three steps as follows. The steps described here apply | 281 // parentMatrix, so we design this transform in three steps as follows. The steps described here apply |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 | 386 |
382 Layer* maskLayer = layer->maskLayer(); | 387 Layer* maskLayer = layer->maskLayer(); |
383 if (maskLayer) | 388 if (maskLayer) |
384 maskLayer->setContentsScale(contentsScale); | 389 maskLayer->setContentsScale(contentsScale); |
385 | 390 |
386 Layer* replicaMaskLayer = layer->replicaLayer() ? layer->replicaLayer()->mas kLayer() : 0; | 391 Layer* replicaMaskLayer = layer->replicaLayer() ? layer->replicaLayer()->mas kLayer() : 0; |
387 if (replicaMaskLayer) | 392 if (replicaMaskLayer) |
388 replicaMaskLayer->setContentsScale(contentsScale); | 393 replicaMaskLayer->setContentsScale(contentsScale); |
389 } | 394 } |
390 | 395 |
396 // Recursively walks the layer tree to compute any information that is needed | |
397 // before doing the main recursion. | |
398 template<typename LayerType> | |
399 static void preCalculateMetaInformation(LayerType* layer) | |
400 { | |
401 int numDescendantsThatDrawContent = 0; | |
402 | |
403 for (size_t i = 0; i < layer->children().size(); ++i) { | |
404 LayerType* childLayer = layer->children()[i]; | |
405 preCalculateMetaInformation<LayerType>(childLayer); | |
406 | |
407 numDescendantsThatDrawContent += childLayer->drawsContent() ? 1 : 0; | |
408 numDescendantsThatDrawContent += childLayer->numDescendantsThatDrawConte nt(); | |
409 } | |
410 | |
411 layer->setNumDescendantsThatDrawContent(numDescendantsThatDrawContent); | |
412 } | |
413 | |
391 // Recursively walks the layer tree starting at the given node and computes all the | 414 // Recursively walks the layer tree starting at the given node and computes all the |
392 // necessary transformations, clipRects, render surfaces, etc. | 415 // necessary transformations, clipRects, render surfaces, etc. |
393 template<typename LayerType, typename LayerList, typename RenderSurfaceType, typ ename LayerSorter> | 416 template<typename LayerType, typename LayerList, typename RenderSurfaceType, typ ename LayerSorter> |
394 static void calculateDrawTransformsInternal(LayerType* layer, const gfx::Transfo rm& parentMatrix, | 417 static void calculateDrawTransformsInternal(LayerType* layer, const gfx::Transfo rm& parentMatrix, |
395 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro llCompensationMatrix, | 418 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro llCompensationMatrix, |
396 const gfx::Rect& clipRectFromAncestor, bool ancestorClipsSubtree, | 419 const gfx::Rect& clipRectFromAncestor, bool ancestorClipsSubtree, |
397 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList, | 420 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList, |
398 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, gfx::Rect& drawableContentRectOfSubtree) | 421 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, gfx::Rect& drawableContentRectOfSubtree) |
399 { | 422 { |
400 // This function computes the new matrix transformations recursively for thi s | 423 // This function computes the new matrix transformations recursively for thi s |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
830 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); | 853 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); |
831 std::vector<scoped_refptr<Layer> > dummyLayerList; | 854 std::vector<scoped_refptr<Layer> > dummyLayerList; |
832 | 855 |
833 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect. | 856 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect. |
834 bool subtreeShouldBeClipped = true; | 857 bool subtreeShouldBeClipped = true; |
835 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); | 858 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); |
836 | 859 |
837 // This function should have received a root layer. | 860 // This function should have received a root layer. |
838 DCHECK(isRootLayer(rootLayer)); | 861 DCHECK(isRootLayer(rootLayer)); |
839 | 862 |
863 cc::preCalculateMetaInformation<Layer>(rootLayer); | |
840 cc::calculateDrawTransformsInternal<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, void>( | 864 cc::calculateDrawTransformsInternal<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, void>( |
841 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, | 865 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, |
842 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList, | 866 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList, |
843 dummyLayerList, 0, maxTextureSize, | 867 dummyLayerList, 0, maxTextureSize, |
844 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); | 868 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); |
845 | 869 |
846 // The dummy layer list should not have been used. | 870 // The dummy layer list should not have been used. |
847 DCHECK(dummyLayerList.size() == 0); | 871 DCHECK(dummyLayerList.size() == 0); |
848 // A root layer renderSurface should always exist after calculateDrawTransfo rms. | 872 // A root layer renderSurface should always exist after calculateDrawTransfo rms. |
849 DCHECK(rootLayer->renderSurface()); | 873 DCHECK(rootLayer->renderSurface()); |
850 } | 874 } |
851 | 875 |
852 void LayerTreeHostCommon::calculateDrawTransforms(LayerImpl* rootLayer, const gf x::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, Lay erSorter* layerSorter, int maxTextureSize, std::vector<LayerImpl*>& renderSurfac eLayerList) | 876 void LayerTreeHostCommon::calculateDrawTransforms(LayerImpl* rootLayer, const gf x::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, Lay erSorter* layerSorter, int maxTextureSize, std::vector<LayerImpl*>& renderSurfac eLayerList) |
853 { | 877 { |
854 gfx::Rect totalDrawableContentRect; | 878 gfx::Rect totalDrawableContentRect; |
855 gfx::Transform identityMatrix; | 879 gfx::Transform identityMatrix; |
856 gfx::Transform deviceScaleTransform; | 880 gfx::Transform deviceScaleTransform; |
857 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); | 881 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); |
858 std::vector<LayerImpl*> dummyLayerList; | 882 std::vector<LayerImpl*> dummyLayerList; |
859 | 883 |
860 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect. | 884 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect. |
861 bool subtreeShouldBeClipped = true; | 885 bool subtreeShouldBeClipped = true; |
862 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); | 886 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); |
863 | 887 |
864 // This function should have received a root layer. | 888 // This function should have received a root layer. |
865 DCHECK(isRootLayer(rootLayer)); | 889 DCHECK(isRootLayer(rootLayer)); |
866 | 890 |
891 cc::preCalculateMetaInformation<LayerImpl>(rootLayer); | |
867 cc::calculateDrawTransformsInternal<LayerImpl, std::vector<LayerImpl*>, Rend erSurfaceImpl, LayerSorter>( | 892 cc::calculateDrawTransformsInternal<LayerImpl, std::vector<LayerImpl*>, Rend erSurfaceImpl, LayerSorter>( |
868 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, | 893 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, |
869 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList, | 894 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList, |
870 dummyLayerList, layerSorter, maxTextureSize, | 895 dummyLayerList, layerSorter, maxTextureSize, |
871 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); | 896 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); |
872 | 897 |
873 // The dummy layer list should not have been used. | 898 // The dummy layer list should not have been used. |
874 DCHECK(dummyLayerList.size() == 0); | 899 DCHECK(dummyLayerList.size() == 0); |
875 // A root layer renderSurface should always exist after calculateDrawTransfo rms. | 900 // A root layer renderSurface should always exist after calculateDrawTransfo rms. |
876 DCHECK(rootLayer->renderSurface()); | 901 DCHECK(rootLayer->renderSurface()); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
993 | 1018 |
994 foundLayer = currentLayer; | 1019 foundLayer = currentLayer; |
995 break; | 1020 break; |
996 } | 1021 } |
997 | 1022 |
998 // This can potentially return 0, which means the screenSpacePoint did not s uccessfully hit test any layers, not even the root layer. | 1023 // This can potentially return 0, which means the screenSpacePoint did not s uccessfully hit test any layers, not even the root layer. |
999 return foundLayer; | 1024 return foundLayer; |
1000 } | 1025 } |
1001 | 1026 |
1002 } // namespace cc | 1027 } // namespace cc |
OLD | NEW |