Bug 1275826 - Part 1. Determine composition mode base on layer index and image type.
MozReview-Commit-ID: 3rVotKORxWV
--- a/layout/base/nsCSSRendering.cpp
+++ b/layout/base/nsCSSRendering.cpp
@@ -3031,16 +3031,40 @@ nsCSSRendering::PaintGradient(nsPresCont
ctx->SetPattern(gradientPattern);
}
ctx->Fill();
ctx->SetMatrix(ctm);
}
}
}
+static CompositionOp
+DetermineCompositionOp(const nsCSSRendering::PaintBGParams& aParams,
+ const nsStyleImageLayers& aLayers,
+ uint32_t aLayerIndex)
+{
+ if (aParams.layer >= 0) {
+ // When drawing a single layer, use the specified composition op.
+ return aParams.compositionOp;
+ }
+
+ const nsStyleImageLayers::Layer& layer = aLayers.mLayers[aLayerIndex];
+ // When drawing all layers, get the compositon op from each image layer.
+ if (aParams.paintFlags & nsCSSRendering::PAINTBG_MASK_IMAGE) {
+ // Always using OP_OVER mode while drawing the bottom mask layer.
+ if (aLayerIndex == (aLayers.mImageCount - 1)) {
+ return CompositionOp::OP_OVER;
+ }
+
+ return nsCSSRendering::GetGFXCompositeMode(layer.mComposite);
+ }
+
+ return nsCSSRendering::GetGFXBlendMode(layer.mBlendMode);
+}
+
DrawResult
nsCSSRendering::PaintBackgroundWithSC(const PaintBGParams& aParams,
nsStyleContext *aBackgroundSC,
const nsStyleBorder& aBorder)
{
NS_PRECONDITION(aParams.frame,
"Frame is expected to be provided to PaintBackground");
@@ -3221,31 +3245,24 @@ nsCSSRendering::PaintBackgroundWithSC(co
ctx->NewPath();
ctx->SnappedRectangle(clip);
ctx->Clip();
}
}
}
if ((aParams.layer < 0 || i == (uint32_t)startLayer) &&
!clipState.mDirtyRectGfx.IsEmpty()) {
- // When we're drawing a single layer, use the specified composition op,
- // otherwise get the compositon op from the image layer.
- CompositionOp co = (aParams.layer >= 0) ? aParams.compositionOp :
- (paintMask ? GetGFXCompositeMode(layer.mComposite) :
- GetGFXBlendMode(layer.mBlendMode));
+ CompositionOp co = DetermineCompositionOp(aParams, layers, i);
nsBackgroundLayerState state =
PrepareImageLayer(&aParams.presCtx, aParams.frame,
aParams.paintFlags, paintBorderArea, clipState.mBGClipArea,
layer, nullptr, co);
result &= state.mImageRenderer.PrepareResult();
if (!state.mFillArea.IsEmpty()) {
- // Always using OP_OVER mode while drawing the bottom mask layer.
- bool isBottomMaskLayer = paintMask ?
- (i == (layers.mImageCount - 1)) : false;
- if (co != CompositionOp::OP_OVER && !isBottomMaskLayer) {
+ if (co != CompositionOp::OP_OVER) {
NS_ASSERTION(ctx->CurrentOp() == CompositionOp::OP_OVER,
"It is assumed the initial op is OP_OVER, when it is restored later");
ctx->SetOp(co);
}
result &=
state.mImageRenderer.DrawBackground(&aParams.presCtx,
aParams.renderingCtx,