Bug 1042296 - Part 1. Implement ShouldCopyBackground.
MozReview-Commit-ID: CdUncJw9pBL
--- a/gfx/layers/basic/BasicLayerManager.cpp
+++ b/gfx/layers/basic/BasicLayerManager.cpp
@@ -71,16 +71,38 @@ ClipToContain(gfxContext* aContext, cons
aContext->NewPath();
aContext->Rectangle(deviceRect);
aContext->Clip();
aContext->SetMatrix(currentMatrix);
return aContext->DeviceToUser(deviceRect).IsEqualInterior(userRect);
}
+static
+bool ShouldCopyBackground(Layer* aLayer)
+{
+ if (aLayer->GetContentFlags() & Layer::CONTENT_COMPONENT_ALPHA) {
+ return true;
+ }
+
+ ContainerLayer* container = aLayer->AsContainerLayer();
+ if (container) {
+ for (Layer* child = container->GetFirstChild(); child;
+ child = child->GetNextSibling()) {
+ if (ShouldCopyBackground(child)) {
+ return true;
+ }
+ }
+ }
+
+ // We should copy backgronud into pushed draw target if any child layer
+ // has blend mode not OP_OVER.
+ return (GetEffectiveOperator(aLayer) != CompositionOp::OP_OVER);
+}
+
bool
BasicLayerManager::PushGroupForLayer(gfxContext* aContext, Layer* aLayer, const nsIntRegion& aRegion, PushedGroup& aGroupResult)
{
aGroupResult.mVisibleRegion = aRegion;
aGroupResult.mFinalTarget = aContext;
aGroupResult.mOperator = GetEffectiveOperator(aLayer);
aGroupResult.mOpacity = aLayer->GetEffectiveOpacity();
@@ -147,17 +169,17 @@ BasicLayerManager::PushGroupForLayer(gfx
aGroupResult.mNeedsClipToVisibleRegion = !didCompleteClip || aRegion.GetNumRects() > 1;
if (aGroupResult.mNeedsClipToVisibleRegion) {
aGroupResult.mFinalTarget->Save();
gfxUtils::ClipToRegion(aGroupResult.mFinalTarget, aGroupResult.mVisibleRegion);
}
aContext->PushGroupForBlendBack(gfxContentType::COLOR, aGroupResult.mOpacity, maskSurf, maskTransform);
} else {
- if (aLayer->GetContentFlags() & Layer::CONTENT_COMPONENT_ALPHA) {
+ if (ShouldCopyBackground(aLayer)) {
aContext->PushGroupAndCopyBackground(gfxContentType::COLOR_ALPHA, aGroupResult.mOpacity, maskSurf, maskTransform);
} else {
aContext->PushGroupForBlendBack(gfxContentType::COLOR_ALPHA, aGroupResult.mOpacity, maskSurf, maskTransform);
}
}
aGroupResult.mGroupTarget = aGroupResult.mFinalTarget;