From b197b8ff31b73ccb20423023e03592df8ae78ea6 Mon Sep 17 00:00:00 2001 From: egdaniel Date: Tue, 17 Feb 2015 07:34:43 -0800 Subject: [PATCH] Use SkXfermode as public facing enum for GrPorterDuffXP BUG=skia: Review URL: https://codereview.chromium.org/926593005 --- gyp/gpu.gypi | 2 +- include/gpu/GrPaint.h | 5 ++--- include/gpu/GrTypes.h | 26 ---------------------- include/gpu/GrXferProcessor.h | 28 ++++++++++++++++++++++++ {src => include}/gpu/effects/GrCoverageSetOpXP.h | 16 +++++++++----- include/gpu/effects/GrPorterDuffXferProcessor.h | 8 ------- src/effects/SkBlurMaskFilter.cpp | 11 +++++----- src/gpu/GrBlend.h | 1 + src/gpu/GrGpu.h | 15 ------------- src/gpu/GrPaint.cpp | 5 +++++ src/gpu/GrPipelineBuilder.h | 8 ------- src/gpu/SkGpuDevice.cpp | 13 ++--------- src/gpu/effects/GrCoverageSetOpXP.cpp | 5 ----- src/gpu/effects/GrPorterDuffXferProcessor.cpp | 19 +++++----------- 14 files changed, 60 insertions(+), 102 deletions(-) rename {src => include}/gpu/effects/GrCoverageSetOpXP.h (68%) diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi index ad3d357..68264f0 100644 --- a/gyp/gpu.gypi +++ b/gyp/gpu.gypi @@ -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', @@ -186,7 +187,6 @@ '<(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', diff --git a/include/gpu/GrPaint.h b/include/gpu/GrPaint.h index 64b51d2..bf29693 100644 --- a/include/gpu/GrPaint.h +++ b/include/gpu/GrPaint.h @@ -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. diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h index 7532984..7fbe432 100644 --- a/include/gpu/GrTypes.h +++ b/include/gpu/GrTypes.h @@ -156,32 +156,6 @@ static inline bool GrIsPrimTypeTris(GrPrimitiveType type) { } /** - * Coeffecients for alpha-blending. - */ -enum GrBlendCoeff { - kInvalid_GrBlendCoeff = -1, - - kZero_GrBlendCoeff, //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 e70d945..e5b8993 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 8a3c32b..2d5eaba 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 d35b41f..c9cebad 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 72f8e28..ad509e1 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 8912851..b6cc69d 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 f0ec1f9..2b26211 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/GrPorterDuffXferProcessor.cpp b/src/gpu/effects/GrPorterDuffXferProcessor.cpp index 428b76a..a08776a 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); } -- 2.7.4