// (0,1). The same applies when coverage is known to be 0.
if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne) || covIsZero) {
if (this->getStencil().doesWrite()) {
- return kDisableBlend_BlendOptFlag |
- kEmitCoverage_BlendOptFlag;
+ return kEmitCoverage_BlendOptFlag;
} else {
return kSkipDraw_BlendOptFlag;
}
if (kOne_GrBlendCoeff == *srcCoeff) {
// if there is no coverage and coeffs are (1,0) then we
// won't need to read the dst at all, it gets replaced by src
- return kDisableBlend_BlendOptFlag;
+ *dstCoeff = kZero_GrBlendCoeff;
+ return kNone_BlendOpt;
} else if (kZero_GrBlendCoeff == *srcCoeff) {
// if the op is "clear" then we don't need to emit a color
// or blend, just write transparent black into the dst.
*srcCoeff = kOne_GrBlendCoeff;
*dstCoeff = kZero_GrBlendCoeff;
- return kDisableBlend_BlendOptFlag | kEmitTransBlack_BlendOptFlag;
+ return kEmitTransBlack_BlendOptFlag;
}
}
} else if (this->isCoverageDrawing()) {
return kCoverageAsAlpha_BlendOptFlag;
}
}
- if (kOne_GrBlendCoeff == *srcCoeff &&
- kZero_GrBlendCoeff == *dstCoeff &&
- this->willEffectReadDstColor()) {
- // In this case the shader will fully resolve the color, coverage, and dst and we don't
- // need blending.
- return kDisableBlend_BlendOptFlag;
- }
+
return kNone_BlendOpt;
}
*/
kSkipDraw_BlendOptFlag = 0x1,
/**
- * Emit the src color, disable HW blending (replace dst with src)
- */
- kDisableBlend_BlendOptFlag = 0x2,
- /**
* The coverage value does not have to be computed separately from alpha, the the output
* color can be the modulation of the two.
*/
- kCoverageAsAlpha_BlendOptFlag = 0x4,
+ kCoverageAsAlpha_BlendOptFlag = 0x2,
/**
* Instead of emitting a src color, emit coverage in the alpha channel and r,g,b are
* "don't cares".
*/
- kEmitCoverage_BlendOptFlag = 0x8,
+ kEmitCoverage_BlendOptFlag = 0x4,
/**
* Emit transparent black instead of the src color, no need to compute coverage.
*/
- kEmitTransBlack_BlendOptFlag = 0x10,
+ kEmitTransBlack_BlendOptFlag = 0x8,
/**
* Flag used to invalidate the cached BlendOptFlags, OptSrcCoeff, and OptDstCoeff cached by
* the get BlendOpts function.
*/
- kInvalid_BlendOptFlag = 0x20,
+ kInvalid_BlendOptFlag = 0x10,
};
GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags);
////////////////////////////////////////////////////////////////////////////////
-bool GrDrawTarget::willUseHWAALines() const {
- // There is a conflict between using smooth lines and our use of premultiplied alpha. Smooth
- // lines tweak the incoming alpha value but not in a premul-alpha way. So we only use them when
- // our alpha is 0xff and tweaking the color for partial coverage is OK
- if (!this->caps()->hwAALineSupport() ||
- !this->getDrawState().isHWAntialiasState()) {
- return false;
- }
- GrDrawState::BlendOptFlags opts = this->getDrawState().getBlendOpts();
- return (GrDrawState::kDisableBlend_BlendOptFlag & opts) &&
- (GrDrawState::kCoverageAsAlpha_BlendOptFlag & opts);
-}
-
bool GrDrawTarget::canApplyCoverage() const {
// we can correctly apply coverage if a) we have dual source blending
- // or b) one of our blend optimizations applies.
+ // or b) one of our blend optimizations applies
+ // or c) the src/dst coefficients are 1, 0 respectively.
+ GrBlendCoeff srcCoeff;
+ GrBlendCoeff dstCoeff;
return this->caps()->dualSourceBlendingSupport() ||
- GrDrawState::kNone_BlendOpt != this->getDrawState().getBlendOpts(true);
+ GrDrawState::kNone_BlendOpt != this->getDrawState().getBlendOpts(true, &srcCoeff,
+ &dstCoeff) ||
+ (kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff);
}
////////////////////////////////////////////////////////////////////////////////
GL_CALL(LineWidth(1));
}
- if (resetBits & kAA_GrGLBackendState) {
- fHWAAState.invalidate();
+ if (resetBits & kMSAAEnable_GrGLBackendState) {
+ fMSAAEnabled = kUnknown_TriState;
}
fHWActiveTextureUnitIdx = -1; // invalid
const GrRenderTarget* rt = this->getDrawState().getRenderTarget();
if (kGL_GrGLStandard == this->glStandard()) {
- // ES doesn't support toggling GL_MULTISAMPLE and doesn't have
- // smooth lines.
- // we prefer smooth lines over multisampled lines
- bool smoothLines = false;
-
- if (kDrawLines_DrawType == type) {
- smoothLines = this->willUseHWAALines();
- if (smoothLines) {
- if (kYes_TriState != fHWAAState.fSmoothLineEnabled) {
- GL_CALL(Enable(GR_GL_LINE_SMOOTH));
- fHWAAState.fSmoothLineEnabled = kYes_TriState;
- // must disable msaa to use line smoothing
- if (RT_HAS_MSAA &&
- kNo_TriState != fHWAAState.fMSAAEnabled) {
- GL_CALL(Disable(GR_GL_MULTISAMPLE));
- fHWAAState.fMSAAEnabled = kNo_TriState;
- }
- }
- } else {
- if (kNo_TriState != fHWAAState.fSmoothLineEnabled) {
- GL_CALL(Disable(GR_GL_LINE_SMOOTH));
- fHWAAState.fSmoothLineEnabled = kNo_TriState;
- }
- }
- }
- if (!smoothLines && RT_HAS_MSAA) {
+ if (RT_HAS_MSAA) {
// FIXME: GL_NV_pr doesn't seem to like MSAA disabled. The paths
// convex hulls of each segment appear to get filled.
bool enableMSAA = kStencilPath_DrawType == type ||
this->getDrawState().isHWAntialiasState();
if (enableMSAA) {
- if (kYes_TriState != fHWAAState.fMSAAEnabled) {
+ if (kYes_TriState != fMSAAEnabled) {
GL_CALL(Enable(GR_GL_MULTISAMPLE));
- fHWAAState.fMSAAEnabled = kYes_TriState;
+ fMSAAEnabled = kYes_TriState;
}
} else {
- if (kNo_TriState != fHWAAState.fMSAAEnabled) {
+ if (kNo_TriState != fMSAAEnabled) {
GL_CALL(Disable(GR_GL_MULTISAMPLE));
- fHWAAState.fMSAAEnabled = kNo_TriState;
+ fMSAAEnabled = kNo_TriState;
}
}
}
void GrGpuGL::flushBlend(bool isLines,
GrBlendCoeff srcCoeff,
GrBlendCoeff dstCoeff) {
- if (isLines && this->willUseHWAALines()) {
+ // any optimization to disable blending should have already been applied and
+ // tweaked the coeffs to (1, 0).
+ bool blendOff = kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff;
+ if (blendOff) {
+ if (kNo_TriState != fHWBlendState.fEnabled) {
+ GL_CALL(Disable(GR_GL_BLEND));
+ fHWBlendState.fEnabled = kNo_TriState;
+ }
+ } else {
if (kYes_TriState != fHWBlendState.fEnabled) {
GL_CALL(Enable(GR_GL_BLEND));
fHWBlendState.fEnabled = kYes_TriState;
}
- if (kSA_GrBlendCoeff != fHWBlendState.fSrcCoeff ||
- kISA_GrBlendCoeff != fHWBlendState.fDstCoeff) {
- GL_CALL(BlendFunc(gXfermodeCoeff2Blend[kSA_GrBlendCoeff],
- gXfermodeCoeff2Blend[kISA_GrBlendCoeff]));
- fHWBlendState.fSrcCoeff = kSA_GrBlendCoeff;
- fHWBlendState.fDstCoeff = kISA_GrBlendCoeff;
- }
- } else {
- // any optimization to disable blending should
- // have already been applied and tweaked the coeffs
- // to (1, 0).
- bool blendOff = kOne_GrBlendCoeff == srcCoeff &&
- kZero_GrBlendCoeff == dstCoeff;
- if (blendOff) {
- if (kNo_TriState != fHWBlendState.fEnabled) {
- GL_CALL(Disable(GR_GL_BLEND));
- fHWBlendState.fEnabled = kNo_TriState;
- }
- } else {
- if (kYes_TriState != fHWBlendState.fEnabled) {
- GL_CALL(Enable(GR_GL_BLEND));
- fHWBlendState.fEnabled = kYes_TriState;
- }
- if (fHWBlendState.fSrcCoeff != srcCoeff ||
- fHWBlendState.fDstCoeff != dstCoeff) {
- GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff],
- gXfermodeCoeff2Blend[dstCoeff]));
- fHWBlendState.fSrcCoeff = srcCoeff;
- fHWBlendState.fDstCoeff = dstCoeff;
- }
- GrColor blendConst = this->getDrawState().getBlendConstant();
- if ((BlendCoeffReferencesConstant(srcCoeff) ||
- BlendCoeffReferencesConstant(dstCoeff)) &&
- (!fHWBlendState.fConstColorValid ||
- fHWBlendState.fConstColor != blendConst)) {
- GrGLfloat c[4];
- GrColorToRGBAFloat(blendConst, c);
- GL_CALL(BlendColor(c[0], c[1], c[2], c[3]));
- fHWBlendState.fConstColor = blendConst;
- fHWBlendState.fConstColorValid = true;
- }
+ if (fHWBlendState.fSrcCoeff != srcCoeff ||
+ fHWBlendState.fDstCoeff != dstCoeff) {
+ GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff],
+ gXfermodeCoeff2Blend[dstCoeff]));
+ fHWBlendState.fSrcCoeff = srcCoeff;
+ fHWBlendState.fDstCoeff = dstCoeff;
+ }
+ GrColor blendConst = this->getDrawState().getBlendConstant();
+ if ((BlendCoeffReferencesConstant(srcCoeff) ||
+ BlendCoeffReferencesConstant(dstCoeff)) &&
+ (!fHWBlendState.fConstColorValid ||
+ fHWBlendState.fConstColor != blendConst)) {
+ GrGLfloat c[4];
+ GrColorToRGBAFloat(blendConst, c);
+ GL_CALL(BlendColor(c[0], c[1], c[2], c[3]));
+ fHWBlendState.fConstColor = blendConst;
+ fHWBlendState.fConstColorValid = true;
}
}
}