Use SkXfermode as public facing enum for GrPorterDuffXP

BUG=skia:

Review URL: https://codereview.chromium.org/926593005
This commit is contained in:
egdaniel 2015-02-17 07:34:43 -08:00 committed by Commit bot
parent d1371a6019
commit b197b8ff31
14 changed files with 60 additions and 102 deletions

View 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',
@ -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',

View 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.

View File

@ -155,32 +155,6 @@ static inline bool GrIsPrimTypeTris(GrPrimitiveType type) {
kTriangleFan_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.

View File

@ -19,6 +19,34 @@ class GrGLCaps;
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

View File

@ -14,16 +14,22 @@
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;
}

View 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,

View 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);
}

View File

@ -8,6 +8,7 @@
#include "GrTypes.h"
#include "GrColor.h"
#include "GrXferProcessor.h"
#ifndef GrBlend_DEFINED
#define GrBlend_DEFINED

View File

@ -26,21 +26,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

View 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();
}

View 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));
}

View 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;

View File

@ -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) {

View 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);
}