Bug 1275826 - Part 1. Determine composition mode base on layer index and image type. draft
authorcku <cku@mozilla.com>
Mon, 05 Sep 2016 18:17:25 +0800
changeset 409895 3ab72db16fe0c5a36a8a4399387b64f4e9b3f495
parent 409737 dbe4b47941c7b3d6298a0ead5e40dd828096c808
child 409896 52d799a2dc21666dfd7a72be88d7c6ba767298e6
push id28605
push userbmo:cku@mozilla.com
push dateMon, 05 Sep 2016 16:00:16 +0000
bugs1275826
milestone51.0a1
Bug 1275826 - Part 1. Determine composition mode base on layer index and image type. MozReview-Commit-ID: 3rVotKORxWV
layout/base/nsCSSRendering.cpp
--- 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,