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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 return true; | 267 return true; |
268 | 268 |
269 int numDescendantsThatDrawContent = layer->drawProperties().num_descendants_ that_draw_content; | 269 int numDescendantsThatDrawContent = layer->drawProperties().num_descendants_ that_draw_content; |
270 | 270 |
271 // 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 |
272 // 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). |
273 if (layerIsInExisting3DRenderingContext(layer) && !layer->preserves3D() && n umDescendantsThatDrawContent > 0) | 273 if (layerIsInExisting3DRenderingContext(layer) && !layer->preserves3D() && n umDescendantsThatDrawContent > 0) |
274 return true; | 274 return true; |
275 | 275 |
276 // 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. |
277 if (layerClipsSubtree(layer) && !axisAlignedWithRespectToParent && numDescen dantsThatDrawContent > 0) | 277 if (layerClipsSubtree(layer) && !axisAlignedWithRespectToParent && !layer->d rawProperties().can_clip_self) |
278 return true; | 278 return true; |
279 | 279 |
280 // If the layer has some translucency and does not have a preserves-3d trans form style. | 280 // If the layer has some translucency and does not have a preserves-3d trans form style. |
281 // This condition only needs a render surface if two or more layers in the | 281 // This condition only needs a render surface if two or more layers in the |
282 // subtree overlap. But checking layer overlaps is unnecessarily costly so | 282 // subtree overlap. But checking layer overlaps is unnecessarily costly so |
283 // instead we conservatively create a surface whenever at least two layers | 283 // instead we conservatively create a surface whenever at least two layers |
284 // draw content for this subtree. | 284 // draw content for this subtree. |
285 bool atLeastTwoLayersInSubtreeDrawContent = layer->hasDelegatedContent() || | 285 bool atLeastTwoLayersInSubtreeDrawContent = layer->hasDelegatedContent() || |
286 (numDescendantsThatDrawContent > 0 && (layer->drawsContent() || numDesce ndantsThatDrawContent > 1)); | 286 (numDescendantsThatDrawContent > 0 && (layer->drawsContent() || numDesce ndantsThatDrawContent > 1)); |
287 | 287 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
422 // layers from the end of the list. | 422 // layers from the end of the list. |
423 while (renderSurfaceLayerList.back() != layerToRemove) { | 423 while (renderSurfaceLayerList.back() != layerToRemove) { |
424 renderSurfaceLayerList.back()->clearRenderSurface(); | 424 renderSurfaceLayerList.back()->clearRenderSurface(); |
425 renderSurfaceLayerList.pop_back(); | 425 renderSurfaceLayerList.pop_back(); |
426 } | 426 } |
427 DCHECK(renderSurfaceLayerList.back() == layerToRemove); | 427 DCHECK(renderSurfaceLayerList.back() == layerToRemove); |
428 renderSurfaceLayerList.pop_back(); | 428 renderSurfaceLayerList.pop_back(); |
429 layerToRemove->clearRenderSurface(); | 429 layerToRemove->clearRenderSurface(); |
430 } | 430 } |
431 | 431 |
432 inline bool isPositiveScaleOrTranslation(const gfx::Transform& xform) | |
shawnsingh
2012/12/14 23:59:11
Re: James' comment; I think a good place for this,
danakj
2012/12/15 00:02:17
nit: call the variable "transform"? we don't do th
| |
433 { | |
434 if (!xform.IsScaleOrTranslation()) | |
435 return false; | |
436 | |
437 // Grab our scale and make sure it's positive. | |
438 double x_scale = xform.matrix().getDouble(0, 0); | |
439 double y_scale = xform.matrix().getDouble(1, 1); | |
danakj
2012/12/15 00:02:17
What about z_scale?
| |
440 if (x_scale <= 0.0 || y_scale <= 0.0) | |
441 return false; | |
442 | |
443 return true; | |
444 } | |
445 | |
432 // Recursively walks the layer tree to compute any information that is needed | 446 // Recursively walks the layer tree to compute any information that is needed |
433 // before doing the main recursion. | 447 // before doing the main recursion. |
434 template<typename LayerType> | 448 template<typename LayerType> |
435 static void preCalculateMetaInformation(LayerType* layer) | 449 static void preCalculateMetaInformation(LayerType* layer) |
436 { | 450 { |
437 int numDescendantsThatDrawContent = 0; | 451 int numDescendantsThatDrawContent = 0; |
452 bool canClipSelf = true; | |
453 bool sublayerXformPreventsClip = !isPositiveScaleOrTranslation(layer->sublay erTransform()); | |
danakj
2012/12/15 00:02:17
nit: "sublayerTransform..."
| |
438 | 454 |
439 for (size_t i = 0; i < layer->children().size(); ++i) { | 455 for (size_t i = 0; i < layer->children().size(); ++i) { |
440 LayerType* childLayer = layer->children()[i]; | 456 LayerType* childLayer = layer->children()[i]; |
441 preCalculateMetaInformation<LayerType>(childLayer); | 457 preCalculateMetaInformation<LayerType>(childLayer); |
458 | |
442 numDescendantsThatDrawContent += childLayer->drawsContent() ? 1 : 0; | 459 numDescendantsThatDrawContent += childLayer->drawsContent() ? 1 : 0; |
443 numDescendantsThatDrawContent += childLayer->drawProperties().num_descen dants_that_draw_content; | 460 numDescendantsThatDrawContent += childLayer->drawProperties().num_descen dants_that_draw_content; |
461 | |
462 if (childLayer->drawsContent() && !childLayer->CanClipSelf() || | |
jamesr
2012/12/14 22:51:16
multiple invocations of && and || merit some group
| |
463 !childLayer->drawProperties().can_clip_self || | |
464 sublayerXformPreventsClip || | |
465 !isPositiveScaleOrTranslation(childLayer->transform())) | |
466 canClipSelf = false; | |
jamesr
2012/12/14 22:51:16
i would probably use braces around this block sinc
shawnsingh
2012/12/14 23:59:11
looking at this if-statement, there is a triple-me
| |
444 } | 467 } |
445 | 468 |
446 layer->drawProperties().num_descendants_that_draw_content = numDescendantsTh atDrawContent; | 469 layer->drawProperties().num_descendants_that_draw_content = numDescendantsTh atDrawContent; |
470 layer->drawProperties().can_clip_self = canClipSelf; | |
447 } | 471 } |
448 | 472 |
449 // Recursively walks the layer tree starting at the given node and computes all the | 473 // Recursively walks the layer tree starting at the given node and computes all the |
450 // necessary transformations, clipRects, render surfaces, etc. | 474 // necessary transformations, clipRects, render surfaces, etc. |
451 template<typename LayerType, typename LayerList, typename RenderSurfaceType> | 475 template<typename LayerType, typename LayerList, typename RenderSurfaceType> |
452 static void calculateDrawPropertiesInternal(LayerType* layer, const gfx::Transfo rm& parentMatrix, | 476 static void calculateDrawPropertiesInternal(LayerType* layer, const gfx::Transfo rm& parentMatrix, |
453 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro llCompensationMatrix, | 477 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro llCompensationMatrix, |
454 const gfx::Rect& clipRectFromAncestor, const gfx::Rect& clipRectFromAncestor InDescendantSpace, bool ancestorClipsSubtree, | 478 const gfx::Rect& clipRectFromAncestor, const gfx::Rect& clipRectFromAncestor InDescendantSpace, bool ancestorClipsSubtree, |
455 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList, | 479 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList, |
456 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, bool subtreeCanUseLCDText, | 480 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, bool subtreeCanUseLCDText, |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1095 | 1119 |
1096 // At this point, we think the point does hit the touch event handler region o n the layer, but we need to walk up | 1120 // At this point, we think the point does hit the touch event handler region o n the layer, but we need to walk up |
1097 // the parents to ensure that the layer was not clipped in such a way that the | 1121 // the parents to ensure that the layer was not clipped in such a way that the |
1098 // hit point actually should not hit the layer. | 1122 // hit point actually should not hit the layer. |
1099 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, layerImpl)) | 1123 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, layerImpl)) |
1100 return false; | 1124 return false; |
1101 | 1125 |
1102 return true; | 1126 return true; |
1103 } | 1127 } |
1104 } // namespace cc | 1128 } // namespace cc |
OLD | NEW |