diff options
author | 2015-02-17 07:34:43 -0800 | |
---|---|---|
committer | 2015-02-17 07:34:43 -0800 | |
commit | b197b8ff31b73ccb20423023e03592df8ae78ea6 (patch) | |
tree | 562ffa91d1f1d6f6a8fdac50eb86569a39cae163 /src | |
parent | d1371a6019189820653aaf20f72ee8f5d0ee3fef (diff) |
Use SkXfermode as public facing enum for GrPorterDuffXP
BUG=skia:
Review URL: https://codereview.chromium.org/926593005
Diffstat (limited to 'src')
-rw-r--r-- | src/effects/SkBlurMaskFilter.cpp | 11 | ||||
-rw-r--r-- | src/gpu/GrBlend.h | 1 | ||||
-rw-r--r-- | src/gpu/GrGpu.h | 15 | ||||
-rw-r--r-- | src/gpu/GrPaint.cpp | 5 | ||||
-rw-r--r-- | src/gpu/GrPipelineBuilder.h | 8 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 13 | ||||
-rw-r--r-- | src/gpu/effects/GrCoverageSetOpXP.cpp | 5 | ||||
-rw-r--r-- | src/gpu/effects/GrCoverageSetOpXP.h | 60 | ||||
-rw-r--r-- | src/gpu/effects/GrPorterDuffXferProcessor.cpp | 19 |
9 files changed, 18 insertions, 119 deletions
diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp index b521546a80..bfc5a5c420 100644 --- a/src/effects/SkBlurMaskFilter.cpp +++ b/src/effects/SkBlurMaskFilter.cpp @@ -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); } diff --git a/src/gpu/GrBlend.h b/src/gpu/GrBlend.h index e70d945777..e5b8993377 100644 --- a/src/gpu/GrBlend.h +++ b/src/gpu/GrBlend.h @@ -8,6 +8,7 @@ #include "GrTypes.h" #include "GrColor.h" +#include "GrXferProcessor.h" #ifndef GrBlend_DEFINED #define GrBlend_DEFINED diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index 8a3c32b7ab..2d5eaba8e8 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -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. diff --git a/src/gpu/GrPaint.cpp b/src/gpu/GrPaint.cpp index d35b41feb3..c9cebad9d8 100644 --- a/src/gpu/GrPaint.cpp +++ b/src/gpu/GrPaint.cpp @@ -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(); } diff --git a/src/gpu/GrPipelineBuilder.h b/src/gpu/GrPipelineBuilder.h index 72f8e28c57..ad509e14f8 100644 --- a/src/gpu/GrPipelineBuilder.h +++ b/src/gpu/GrPipelineBuilder.h @@ -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)); } diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 8912851d8f..b6cc69d858 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -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; diff --git a/src/gpu/effects/GrCoverageSetOpXP.cpp b/src/gpu/effects/GrCoverageSetOpXP.cpp index f0ec1f9b00..2b262116f0 100644 --- a/src/gpu/effects/GrCoverageSetOpXP.cpp +++ b/src/gpu/effects/GrCoverageSetOpXP.cpp @@ -15,11 +15,6 @@ #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) { diff --git a/src/gpu/effects/GrCoverageSetOpXP.h b/src/gpu/effects/GrCoverageSetOpXP.h deleted file mode 100644 index 01dce95211..0000000000 --- a/src/gpu/effects/GrCoverageSetOpXP.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GrCoverageSetOpXP_DEFINED -#define GrCoverageSetOpXP_DEFINED - -#include "GrTypes.h" -#include "GrXferProcessor.h" -#include "SkRegion.h" - -class GrProcOptInfo; - -class GrCoverageSetOpXPFactory : public GrXPFactory { -public: - static GrXPFactory* Create(SkRegion::Op regionOp, bool invertCoverage = false); - - bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlags) const SK_OVERRIDE { - return true; - } - - bool canApplyCoverage(const GrProcOptInfo& colorPOI, - const GrProcOptInfo& coveragePOI) const SK_OVERRIDE { - return true; - } - - bool canTweakAlphaForCoverage() const SK_OVERRIDE { return false; } - - void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcOptInfo& coveragePOI, - GrXPFactory::InvariantOutput*) const SK_OVERRIDE; - -private: - GrCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage); - - GrXferProcessor* onCreateXferProcessor(const GrProcOptInfo& colorPOI, - const GrProcOptInfo& coveragePOI, - const GrDeviceCoordTexture* dstCopy) const SK_OVERRIDE; - - bool willReadDstColor(const GrProcOptInfo& colorPOI, - const GrProcOptInfo& coveragePOI) const SK_OVERRIDE { - return false; - } - - bool onIsEqual(const GrXPFactory& xpfBase) const SK_OVERRIDE { - const GrCoverageSetOpXPFactory& xpf = xpfBase.cast<GrCoverageSetOpXPFactory>(); - return fRegionOp == xpf.fRegionOp; - } - - GR_DECLARE_XP_FACTORY_TEST; - - SkRegion::Op fRegionOp; - bool fInvertCoverage; - - typedef GrXPFactory INHERITED; -}; -#endif - diff --git a/src/gpu/effects/GrPorterDuffXferProcessor.cpp b/src/gpu/effects/GrPorterDuffXferProcessor.cpp index 428b76a38a..a08776a20f 100644 --- a/src/gpu/effects/GrPorterDuffXferProcessor.cpp +++ b/src/gpu/effects/GrPorterDuffXferProcessor.cpp @@ -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); } |