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 "cc/layer.h" | 7 #include "cc/layer.h" |
8 #include "cc/layer_impl.h" | 8 #include "cc/layer_impl.h" |
9 #include "cc/layer_iterator.h" | 9 #include "cc/layer_iterator.h" |
10 #include "cc/layer_sorter.h" | 10 #include "cc/layer_sorter.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 targetSurfaceClipRect = gfx::ToEnclosingRect(MathUtil::projectClippedRec
t(layer->renderTarget()->renderSurface()->drawTransform().inverse(), layer->rend
erTarget()->renderSurface()->clipRect())); | 134 targetSurfaceClipRect = gfx::ToEnclosingRect(MathUtil::projectClippedRec
t(layer->renderTarget()->renderSurface()->drawTransform().inverse(), layer->rend
erTarget()->renderSurface()->clipRect())); |
135 targetSurfaceClipRect.Intersect(layer->drawableContentRect()); | 135 targetSurfaceClipRect.Intersect(layer->drawableContentRect()); |
136 } | 136 } |
137 | 137 |
138 if (targetSurfaceClipRect.IsEmpty()) | 138 if (targetSurfaceClipRect.IsEmpty()) |
139 return gfx::Rect(); | 139 return gfx::Rect(); |
140 | 140 |
141 return LayerTreeHostCommon::calculateVisibleRect(targetSurfaceClipRect, gfx:
:Rect(gfx::Point(), layer->contentBounds()), layer->drawTransform()); | 141 return LayerTreeHostCommon::calculateVisibleRect(targetSurfaceClipRect, gfx:
:Rect(gfx::Point(), layer->contentBounds()), layer->drawTransform()); |
142 } | 142 } |
143 | 143 |
| 144 // Note that this function is short circuiting for speed. When the number of |
| 145 // descendants that draw content is >1, the result if guaranteed to by >1 but |
| 146 // not the actual number of descendants that draw content. |
| 147 template<typename LayerType> |
| 148 static int getNumDescendantsDrawContent(LayerType* layer) |
| 149 { |
| 150 typedef LayerType* LayerTypePtr; |
| 151 const typename LayerType::LayerList& children = layer->children(); |
| 152 |
| 153 int result = 0; |
| 154 for (size_t i = 0; i < children.size(); ++i) { |
| 155 if (children[i]->drawsContent()) |
| 156 ++result; |
| 157 result += getNumDescendantsDrawContent(LayerTypePtr(children[i])); |
| 158 if (result > 1) |
| 159 return result; |
| 160 } |
| 161 return result; |
| 162 } |
| 163 |
144 static bool isScaleOrTranslation(const WebTransformationMatrix& m) | 164 static bool isScaleOrTranslation(const WebTransformationMatrix& m) |
145 { | 165 { |
146 return !m.m12() && !m.m13() && !m.m14() | 166 return !m.m12() && !m.m13() && !m.m14() |
147 && !m.m21() && !m.m23() && !m.m24() | 167 && !m.m21() && !m.m23() && !m.m24() |
148 && !m.m31() && !m.m32() && !m.m43() | 168 && !m.m31() && !m.m32() && !m.m43() |
149 && m.m44(); | 169 && m.m44(); |
150 } | 170 } |
151 | 171 |
152 static inline bool transformToParentIsKnown(LayerImpl*) | 172 static inline bool transformToParentIsKnown(LayerImpl*) |
153 { | 173 { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 260 |
241 // If the layer has a reflection. | 261 // If the layer has a reflection. |
242 if (layer->replicaLayer()) | 262 if (layer->replicaLayer()) |
243 return true; | 263 return true; |
244 | 264 |
245 // If the layer uses a CSS filter. | 265 // If the layer uses a CSS filter. |
246 if (!layer->filters().isEmpty() || !layer->backgroundFilters().isEmpty() ||
layer->filter()) | 266 if (!layer->filters().isEmpty() || !layer->backgroundFilters().isEmpty() ||
layer->filter()) |
247 return true; | 267 return true; |
248 | 268 |
249 // Cache this value, because otherwise it walks the entire subtree several t
imes. | 269 // Cache this value, because otherwise it walks the entire subtree several t
imes. |
250 bool descendantDrawsContent = layer->descendantDrawsContent(); | 270 int numDescendantsDrawContent = getNumDescendantsDrawContent(layer); |
| 271 bool descendantDrawsContent = numDescendantsDrawContent > 0; |
251 | 272 |
252 // If the layer flattens its subtree (i.e. the layer doesn't preserve-3d), b
ut it is | 273 // If the layer flattens its subtree (i.e. the layer doesn't preserve-3d), b
ut it is |
253 // treated as a 3D object by its parent (i.e. parent does preserve-3d). | 274 // treated as a 3D object by its parent (i.e. parent does preserve-3d). |
254 if (layerIsInExisting3DRenderingContext(layer) && !layer->preserves3D() && d
escendantDrawsContent) | 275 if (layerIsInExisting3DRenderingContext(layer) && !layer->preserves3D() && d
escendantDrawsContent) |
255 return true; | 276 return true; |
256 | 277 |
257 // If the layer clips its descendants but it is not axis-aligned with respec
t to its parent. | 278 // If the layer clips its descendants but it is not axis-aligned with respec
t to its parent. |
258 if (layerClipsSubtree(layer) && !axisAlignedWithRespectToParent && descendan
tDrawsContent) | 279 if (layerClipsSubtree(layer) && !axisAlignedWithRespectToParent && descendan
tDrawsContent) |
259 return true; | 280 return true; |
260 | 281 |
261 // If the layer has opacity != 1 and does not have a preserves-3d transform
style. | 282 // If the layer has opacity != 1 and does not have a preserves-3d transform
style. |
262 if (layer->opacity() != 1 && !layer->preserves3D() && descendantDrawsContent
) | 283 if (layer->opacity() != 1 && !layer->preserves3D() && descendantDrawsContent |
| 284 && (layer->drawsContent() || numDescendantsDrawContent > 1)) |
263 return true; | 285 return true; |
264 | 286 |
265 return false; | 287 return false; |
266 } | 288 } |
267 | 289 |
268 WebTransformationMatrix computeScrollCompensationForThisLayer(LayerImpl* scrolli
ngLayer, const WebTransformationMatrix& parentMatrix) | 290 WebTransformationMatrix computeScrollCompensationForThisLayer(LayerImpl* scrolli
ngLayer, const WebTransformationMatrix& parentMatrix) |
269 { | 291 { |
270 // For every layer that has non-zero scrollDelta, we have to compute a trans
form that can undo the | 292 // For every layer that has non-zero scrollDelta, we have to compute a trans
form that can undo the |
271 // scrollDelta translation. In particular, we want this matrix to premultipl
y a fixed-position layer's | 293 // scrollDelta translation. In particular, we want this matrix to premultipl
y a fixed-position layer's |
272 // parentMatrix, so we design this transform in three steps as follows. The
steps described here apply | 294 // parentMatrix, so we design this transform in three steps as follows. The
steps described here apply |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 | 499 |
478 // If we early-exit anywhere in this function, the drawableContentRect of th
is subtree should be considered empty. | 500 // If we early-exit anywhere in this function, the drawableContentRect of th
is subtree should be considered empty. |
479 drawableContentRectOfSubtree = gfx::Rect(); | 501 drawableContentRectOfSubtree = gfx::Rect(); |
480 | 502 |
481 // The root layer cannot skip calcDrawTransforms. | 503 // The root layer cannot skip calcDrawTransforms. |
482 if (!isRootLayer(layer) && subtreeShouldBeSkipped(layer)) | 504 if (!isRootLayer(layer) && subtreeShouldBeSkipped(layer)) |
483 return; | 505 return; |
484 | 506 |
485 gfx::Rect clipRectForSubtree; | 507 gfx::Rect clipRectForSubtree; |
486 bool subtreeShouldBeClipped = false; | 508 bool subtreeShouldBeClipped = false; |
487 | 509 |
488 float drawOpacity = layer->opacity(); | 510 float drawOpacity = layer->opacity(); |
489 bool drawOpacityIsAnimating = layer->opacityIsAnimating(); | 511 bool drawOpacityIsAnimating = layer->opacityIsAnimating(); |
490 if (layer->parent() && layer->parent()->preserves3D()) { | 512 if (layer->parent()) { |
491 drawOpacity *= layer->parent()->drawOpacity(); | 513 drawOpacity *= layer->parent()->drawOpacity(); |
492 drawOpacityIsAnimating |= layer->parent()->drawOpacityIsAnimating(); | 514 drawOpacityIsAnimating |= layer->parent()->drawOpacityIsAnimating(); |
493 } | 515 } |
494 | 516 |
495 bool animatingTransformToTarget = layer->transformIsAnimating(); | 517 bool animatingTransformToTarget = layer->transformIsAnimating(); |
496 bool animatingTransformToScreen = animatingTransformToTarget; | 518 bool animatingTransformToScreen = animatingTransformToTarget; |
497 if (layer->parent()) { | 519 if (layer->parent()) { |
498 animatingTransformToTarget |= layer->parent()->drawTransformIsAnimating(
); | 520 animatingTransformToTarget |= layer->parent()->drawTransformIsAnimating(
); |
499 animatingTransformToScreen |= layer->parent()->screenSpaceTransformIsAni
mating(); | 521 animatingTransformToScreen |= layer->parent()->screenSpaceTransformIsAni
mating(); |
500 } | 522 } |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 | 1009 |
988 foundLayer = currentLayer; | 1010 foundLayer = currentLayer; |
989 break; | 1011 break; |
990 } | 1012 } |
991 | 1013 |
992 // This can potentially return 0, which means the screenSpacePoint did not s
uccessfully hit test any layers, not even the root layer. | 1014 // This can potentially return 0, which means the screenSpacePoint did not s
uccessfully hit test any layers, not even the root layer. |
993 return foundLayer; | 1015 return foundLayer; |
994 } | 1016 } |
995 | 1017 |
996 } // namespace cc | 1018 } // namespace cc |
OLD | NEW |