Use SkXfermode as public facing enum for GrPorterDuffXP
authoregdaniel <egdaniel@google.com>
Tue, 17 Feb 2015 15:34:43 +0000 (07:34 -0800)
committerCommit bot <commit-bot@chromium.org>
Tue, 17 Feb 2015 15:34:43 +0000 (07:34 -0800)
BUG=skia:

Review URL: https://codereview.chromium.org/926593005

14 files changed:
gyp/gpu.gypi
include/gpu/GrPaint.h
include/gpu/GrTypes.h
include/gpu/GrXferProcessor.h
include/gpu/effects/GrCoverageSetOpXP.h [moved from src/gpu/effects/GrCoverageSetOpXP.h with 68% similarity]
include/gpu/effects/GrPorterDuffXferProcessor.h
src/effects/SkBlurMaskFilter.cpp
src/gpu/GrBlend.h
src/gpu/GrGpu.h
src/gpu/GrPaint.cpp
src/gpu/GrPipelineBuilder.h
src/gpu/SkGpuDevice.cpp
src/gpu/effects/GrCoverageSetOpXP.cpp
src/gpu/effects/GrPorterDuffXferProcessor.cpp

index ad3d357..68264f0 100644 (file)
@@ -34,6 +34,7 @@
       '<(skia_include_path)/gpu/GrUserConfig.h',
       '<(skia_include_path)/gpu/GrXferProcessor.h',
 
+      '<(skia_include_path)/gpu/effects/GrCoverageSetOpXP.h',
       '<(skia_include_path)/gpu/effects/GrCustomXfermode.h',
       '<(skia_include_path)/gpu/effects/GrPorterDuffXferProcessor.h',
 
       '<(skia_src_path)/gpu/effects/GrConfigConversionEffect.cpp',
       '<(skia_src_path)/gpu/effects/GrConfigConversionEffect.h',
       '<(skia_src_path)/gpu/effects/GrCoverageSetOpXP.cpp',
-      '<(skia_src_path)/gpu/effects/GrCoverageSetOpXP.h',
       '<(skia_src_path)/gpu/effects/GrCustomXfermode.cpp',
       '<(skia_src_path)/gpu/effects/GrCustomXfermodePriv.h',
       '<(skia_src_path)/gpu/effects/GrBezierEffect.cpp',
index 64b51d2..bf29693 100644 (file)
@@ -15,6 +15,7 @@
 #include "GrXferProcessor.h"
 #include "effects/GrPorterDuffXferProcessor.h"
 
+#include "SkRegion.h"
 #include "SkXfermode.h"
 
 /**
@@ -70,9 +71,7 @@ public:
         fXPFactory.reset(GrPorterDuffXPFactory::Create(mode));
     }
 
-    void setPorterDuffXPFactory(GrBlendCoeff src, GrBlendCoeff dst) {
-        fXPFactory.reset(GrPorterDuffXPFactory::Create(src, dst));
-    }
+    void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = false); 
 
     /**
      * Appends an additional color processor to the color computation.
index 7532984..7fbe432 100644 (file)
@@ -156,32 +156,6 @@ static inline bool GrIsPrimTypeTris(GrPrimitiveType type) {
 }
 
 /**
- * Coeffecients for alpha-blending.
- */
-enum GrBlendCoeff {
-    kInvalid_GrBlendCoeff = -1,
-
-    kZero_GrBlendCoeff,    //<! 0
-    kOne_GrBlendCoeff,     //<! 1
-    kSC_GrBlendCoeff,      //<! src color
-    kISC_GrBlendCoeff,     //<! one minus src color
-    kDC_GrBlendCoeff,      //<! dst color
-    kIDC_GrBlendCoeff,     //<! one minus dst color
-    kSA_GrBlendCoeff,      //<! src alpha
-    kISA_GrBlendCoeff,     //<! one minus src alpha
-    kDA_GrBlendCoeff,      //<! dst alpha
-    kIDA_GrBlendCoeff,     //<! one minus dst alpha
-    kConstC_GrBlendCoeff,  //<! constant color
-    kIConstC_GrBlendCoeff, //<! one minus constant color
-    kConstA_GrBlendCoeff,  //<! constant color alpha
-    kIConstA_GrBlendCoeff, //<! one minus constant color alpha
-
-    kFirstPublicGrBlendCoeff = kZero_GrBlendCoeff,
-    kLastPublicGrBlendCoeff = kIConstA_GrBlendCoeff,
-};
-static const int kPublicGrBlendCoeffCount = kLastPublicGrBlendCoeff + 1;
-
-/**
  *  Formats for masks, used by the font cache.
  *  Important that these are 0-based.
  */
index 312e769..b9adb66 100644 (file)
@@ -20,6 +20,34 @@ class GrGLXferProcessor;
 class GrProcOptInfo;
 
 /**
+ * Coeffecients for alpha-blending.
+ */
+enum GrBlendCoeff {
+    kInvalid_GrBlendCoeff = -1,
+
+    kZero_GrBlendCoeff,    //<! 0
+    kOne_GrBlendCoeff,     //<! 1
+    kSC_GrBlendCoeff,      //<! src color
+    kISC_GrBlendCoeff,     //<! one minus src color
+    kDC_GrBlendCoeff,      //<! dst color
+    kIDC_GrBlendCoeff,     //<! one minus dst color
+    kSA_GrBlendCoeff,      //<! src alpha
+    kISA_GrBlendCoeff,     //<! one minus src alpha
+    kDA_GrBlendCoeff,      //<! dst alpha
+    kIDA_GrBlendCoeff,     //<! one minus dst alpha
+    kConstC_GrBlendCoeff,  //<! constant color
+    kIConstC_GrBlendCoeff, //<! one minus constant color
+    kConstA_GrBlendCoeff,  //<! constant color alpha
+    kIConstA_GrBlendCoeff, //<! one minus constant color alpha
+    kS2C_GrBlendCoeff,
+    kIS2C_GrBlendCoeff,
+    kS2A_GrBlendCoeff,
+    kIS2A_GrBlendCoeff,
+
+    kTotalGrBlendCoeffCount
+};
+
+/**
  * GrXferProcessor is responsible for implementing the xfer mode that blends the src color and dst
  * color. It does this by emitting fragment shader code and controlling the fixed-function blend
  * state. The inputs to its shader code are the final computed src color and fractional pixel
similarity index 68%
rename from src/gpu/effects/GrCoverageSetOpXP.h
rename to include/gpu/effects/GrCoverageSetOpXP.h
index 01dce95..e781999 100644 (file)
 
 class GrProcOptInfo;
 
+/**
+ * This xfer processor directly blends the the src coverage with the dst using a set operator. It is
+ * useful for rendering coverage masks using CSG. It can optionally invert the src coverage before
+ * applying the set operator.
+ */
 class GrCoverageSetOpXPFactory : public GrXPFactory {
 public:
     static GrXPFactory* Create(SkRegion::Op regionOp, bool invertCoverage = false);
 
-    bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlags) const SK_OVERRIDE {
+    bool supportsRGBCoverage(GrColor /*knownColor*/,
+                             uint32_t /*knownColorFlags*/) const SK_OVERRIDE {
         return true;
     }
 
-    bool canApplyCoverage(const GrProcOptInfo& colorPOI,
-                          const GrProcOptInfo& coveragePOI) const SK_OVERRIDE {
+    bool canApplyCoverage(const GrProcOptInfo& /*colorPOI*/,
+                          const GrProcOptInfo& /*coveragePOI*/) const SK_OVERRIDE {
         return true;
     }
 
@@ -39,8 +45,8 @@ private:
                                            const GrProcOptInfo& coveragePOI,
                                            const GrDeviceCoordTexture* dstCopy) const SK_OVERRIDE;
 
-    bool willReadDstColor(const GrProcOptInfo& colorPOI,
-                          const GrProcOptInfo& coveragePOI) const SK_OVERRIDE {
+    bool willReadDstColor(const GrProcOptInfo& /*colorPOI*/,
+                          const GrProcOptInfo& /*coveragePOI*/) const SK_OVERRIDE {
         return false;
     }
 
index 1bd1993..0d3b01f 100644 (file)
@@ -18,14 +18,6 @@ class GrPorterDuffXPFactory : public GrXPFactory {
 public:
     static GrXPFactory* Create(SkXfermode::Mode mode); 
 
-    static GrXPFactory* Create(SkXfermode::Coeff src, SkXfermode::Coeff dst) {
-        return SkNEW_ARGS(GrPorterDuffXPFactory, ((GrBlendCoeff)(src), (GrBlendCoeff)(dst)));
-    }
-
-    static GrXPFactory* Create(GrBlendCoeff src, GrBlendCoeff dst) {
-        return SkNEW_ARGS(GrPorterDuffXPFactory, (src, dst));
-    }
-
     bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlags) const SK_OVERRIDE;
 
     bool canApplyCoverage(const GrProcOptInfo& colorPOI,
index b521546..bfc5a5c 100644 (file)
@@ -24,7 +24,6 @@
 #include "GrInvariantOutput.h"
 #include "SkGrPixelRef.h"
 #include "SkDraw.h"
-#include "effects/GrPorterDuffXferProcessor.h"
 #include "effects/GrSimpleTextureEffect.h"
 #include "gl/GrGLProcessor.h"
 #include "gl/builders/GrGLProgramBuilder.h"
@@ -1217,18 +1216,18 @@ bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src,
         matrix.setIDiv(src->width(), src->height());
         // Blend pathTexture over blurTexture.
         GrContext::AutoRenderTarget art(context, (*result)->asRenderTarget());
-        paint.addColorProcessor(GrSimpleTextureEffect::Create(src, matrix))->unref();
+        paint.addCoverageProcessor(GrSimpleTextureEffect::Create(src, matrix))->unref();
         if (kInner_SkBlurStyle == fBlurStyle) {
             // inner:  dst = dst * src
-            paint.setPorterDuffXPFactory(kDC_GrBlendCoeff, kZero_GrBlendCoeff);
+            paint.setCoverageSetOpXPFactory(SkRegion::kIntersect_Op);
         } else if (kSolid_SkBlurStyle == fBlurStyle) {
             // solid:  dst = src + dst - src * dst
-            //             = (1 - dst) * src + 1 * dst
-            paint.setPorterDuffXPFactory(kIDC_GrBlendCoeff, kOne_GrBlendCoeff);
+            //             = src + (1 - src) * dst
+            paint.setCoverageSetOpXPFactory(SkRegion::kUnion_Op);
         } else if (kOuter_SkBlurStyle == fBlurStyle) {
             // outer:  dst = dst * (1 - src)
             //             = 0 * src + (1 - src) * dst
-            paint.setPorterDuffXPFactory(kZero_GrBlendCoeff, kISC_GrBlendCoeff);
+            paint.setCoverageSetOpXPFactory(SkRegion::kDifference_Op);
         }
         context->drawRect(paint, SkMatrix::I(), clipRect);
     }
index e70d945..e5b8993 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "GrTypes.h"
 #include "GrColor.h"
+#include "GrXferProcessor.h"
 
 #ifndef GrBlend_DEFINED
 #define GrBlend_DEFINED
index 8a3c32b..2d5eaba 100644 (file)
@@ -27,21 +27,6 @@ class GrVertexBufferAllocPool;
 class GrGpu : public SkRefCnt {
 public:
     /**
-     * Additional blend coefficients for dual source blending, not exposed
-     * through GrPaint/GrContext.
-     */
-    enum ExtendedBlendCoeffs {
-        // source 2 refers to second output color when
-        // using dual source blending.
-        kS2C_GrBlendCoeff = kPublicGrBlendCoeffCount,
-        kIS2C_GrBlendCoeff,
-        kS2A_GrBlendCoeff,
-        kIS2A_GrBlendCoeff,
-
-        kTotalGrBlendCoeffCount
-    };
-
-    /**
      * Create an instance of GrGpu that matches the specified backend. If the requested backend is
      * not supported (at compile-time or run-time) this returns NULL. The context will not be
      * fully constructed and should not be used by GrGpu until after this function returns.
index d35b41f..c9cebad 100644 (file)
@@ -9,6 +9,7 @@
 #include "GrPaint.h"
 
 #include "GrProcOptInfo.h"
+#include "effects/GrCoverageSetOpXP.h"
 #include "effects/GrPorterDuffXferProcessor.h"
 #include "effects/GrSimpleTextureEffect.h"
 
@@ -18,6 +19,10 @@ GrPaint::GrPaint()
     , fColor(GrColor_WHITE) {
 }
 
+void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) {
+    fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage));
+}
+
 void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
     this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
 }
index 72f8e28..ad509e1 100644 (file)
@@ -114,14 +114,6 @@ public:
         return xpFactory;
     }
 
-    void setPorterDuffXPFactory(SkXfermode::Mode mode) {
-        fXPFactory.reset(GrPorterDuffXPFactory::Create(mode));
-    }
-
-    void setPorterDuffXPFactory(GrBlendCoeff src, GrBlendCoeff dst) {
-        fXPFactory.reset(GrPorterDuffXPFactory::Create(src, dst));
-    }
-
     void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = false) {
         fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage));
     }
index 8912851..b6cc69d 100644 (file)
@@ -9,7 +9,6 @@
 
 #include "effects/GrBicubicEffect.h"
 #include "effects/GrDashingEffect.h"
-#include "effects/GrPorterDuffXferProcessor.h"
 #include "effects/GrTextureDomain.h"
 #include "effects/GrSimpleTextureEffect.h"
 
@@ -677,16 +676,8 @@ GrTexture* create_mask_GPU(GrContext* context,
     context->clear(NULL, 0x0, true, mask->asRenderTarget());
 
     GrPaint tempPaint;
-    if (doAA) {
-        tempPaint.setAntiAlias(true);
-        // AA uses the "coverage" stages on GrDrawTarget. Coverage with a dst
-        // blend coeff of zero requires dual source blending support in order
-        // to properly blend partially covered pixels. This means the AA
-        // code path may not be taken. So we use a dst blend coeff of ISA. We
-        // could special case AA draws to a dst surface with known alpha=0 to
-        // use a zero dst coeff when dual source blending isn't available.
-        tempPaint.setPorterDuffXPFactory(kOne_GrBlendCoeff, kISC_GrBlendCoeff);
-    }
+    tempPaint.setAntiAlias(doAA);
+    tempPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op);
 
     // Draw the mask into maskTexture with the path's top-left at the origin using tempPaint.
     SkMatrix translate;
index f0ec1f9..2b26211 100644 (file)
 #include "gl/builders/GrGLFragmentShaderBuilder.h"
 #include "gl/builders/GrGLProgramBuilder.h"
 
-/**
- * This xfer processor directly blends the the src coverage with the dst using a set operator. It is
- * useful for rendering coverage masks using CSG. It can optionally invert the src coverage before
- * applying the set operator.
- * */
 class CoverageSetOpXP : public GrXferProcessor {
 public:
     static GrXferProcessor* Create(SkRegion::Op regionOp, bool invertCoverage) {
index 428b76a..a08776a 100644 (file)
@@ -266,15 +266,15 @@ void PorterDuffXferProcessor::calcOutputTypes(GrXferProcessor::OptFlags optFlags
             if (kZero_GrBlendCoeff == fDstBlend) {
                 // write the coverage value to second color
                 fSecondaryOutputType = kCoverage_SecondaryOutputType;
-                fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
+                fDstBlend = kIS2C_GrBlendCoeff;
             } else if (kSA_GrBlendCoeff == fDstBlend) {
                 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered.
                 fSecondaryOutputType = kCoverageISA_SecondaryOutputType;
-                fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
+                fDstBlend = kIS2C_GrBlendCoeff;
             } else if (kSC_GrBlendCoeff == fDstBlend) {
                 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered.
                 fSecondaryOutputType = kCoverageISC_SecondaryOutputType;
-                fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
+                fDstBlend = kIS2C_GrBlendCoeff;
             }
         }
     }
@@ -617,16 +617,7 @@ GrXPFactory* GrPorterDuffXPFactory::TestCreate(SkRandom* random,
                                                GrContext*,
                                                const GrDrawTargetCaps&,
                                                GrTexture*[]) {
-    GrBlendCoeff src;
-    do {
-        src = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPublicGrBlendCoeff));
-    } while (GrBlendCoeffRefsSrc(src));
-
-    GrBlendCoeff dst;
-    do {
-        dst = GrBlendCoeff(random->nextRangeU(kFirstPublicGrBlendCoeff, kLastPublicGrBlendCoeff));
-    } while (GrBlendCoeffRefsDst(dst));
-
-    return GrPorterDuffXPFactory::Create(src, dst);
+    SkXfermode::Mode mode = SkXfermode::Mode(random->nextULessThan(SkXfermode::kLastCoeffMode));
+    return GrPorterDuffXPFactory::Create(mode);
 }