Index: cc/layer_tree_host_common.cc |
diff --git a/cc/layer_tree_host_common.cc b/cc/layer_tree_host_common.cc |
index ca7d45050f85c0857e5f88a4def5818ef1b5374e..771a6ae47ab590372751bcd11e64b414cd4cd6ff 100644 |
--- a/cc/layer_tree_host_common.cc |
+++ b/cc/layer_tree_host_common.cc |
@@ -141,6 +141,26 @@ static gfx::Rect calculateVisibleContentRect(LayerType* layer) |
return LayerTreeHostCommon::calculateVisibleRect(targetSurfaceClipRect, gfx::Rect(gfx::Point(), layer->contentBounds()), layer->drawTransform()); |
} |
+// Note that this function is short circuiting for speed. When the number of |
+// descendants that draw content is >1, the result if guaranteed to by >1 but |
danakj
2012/11/27 01:57:49
nit: "to be"
|
+// not the actual number of descendants that draw content. |
+template<typename LayerType> |
+static int getNumDescendantsDrawContent(LayerType* layer) |
+{ |
+ typedef LayerType* LayerTypePtr; |
+ const typename LayerType::LayerList& children = layer->children(); |
+ |
+ int result = 0; |
+ for (size_t i = 0; i < children.size(); ++i) { |
+ if (children[i]->drawsContent()) |
+ ++result; |
+ result += getNumDescendantsDrawContent(LayerTypePtr(children[i])); |
+ if (result > 1) |
+ return result; |
+ } |
+ return result; |
+} |
+ |
static bool isScaleOrTranslation(const WebTransformationMatrix& m) |
{ |
return !m.m12() && !m.m13() && !m.m14() |
@@ -247,7 +267,8 @@ static bool subtreeShouldRenderToSeparateSurface(LayerType* layer, bool axisAlig |
return true; |
// Cache this value, because otherwise it walks the entire subtree several times. |
- bool descendantDrawsContent = layer->descendantDrawsContent(); |
+ int numDescendantsDrawContent = getNumDescendantsDrawContent(layer); |
+ bool descendantDrawsContent = numDescendantsDrawContent > 0; |
// If the layer flattens its subtree (i.e. the layer doesn't preserve-3d), but it is |
// treated as a 3D object by its parent (i.e. parent does preserve-3d). |
@@ -259,7 +280,8 @@ static bool subtreeShouldRenderToSeparateSurface(LayerType* layer, bool axisAlig |
return true; |
// If the layer has opacity != 1 and does not have a preserves-3d transform style. |
- if (layer->opacity() != 1 && !layer->preserves3D() && descendantDrawsContent) |
+ if (layer->opacity() != 1 && !layer->preserves3D() && descendantDrawsContent |
+ && (layer->drawsContent() || numDescendantsDrawContent > 1)) |
shawnsingh
2012/11/27 07:16:10
Sorry, I'm not following why this is our desired s
|
return true; |
return false; |
@@ -484,10 +506,10 @@ static void calculateDrawTransformsInternal(LayerType* layer, const WebTransform |
gfx::Rect clipRectForSubtree; |
bool subtreeShouldBeClipped = false; |
- |
+ |
float drawOpacity = layer->opacity(); |
bool drawOpacityIsAnimating = layer->opacityIsAnimating(); |
- if (layer->parent() && layer->parent()->preserves3D()) { |
+ if (layer->parent()) { |
drawOpacity *= layer->parent()->drawOpacity(); |
drawOpacityIsAnimating |= layer->parent()->drawOpacityIsAnimating(); |
} |