Revert of Remove gpu support for willUseHWAALines. (https://codereview.chromium.org/423943003/)

Reason for revert:
Breaking windows 7 compare gm's

Original issue's description:
> Remove gpu support for willUseHWAALines.
>
> By removing willUseHWAALines, we also no long reference the blend opt flag kDisableBlend so it has been removed
>
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/e6dfba868c19b00562f8c733b9bf37dd4ec9e68c

R=bsalomon@google.com
TBR=bsalomon@google.com
NOTREECHECKS=true
NOTRY=true
BUG=skia:

Author: egdaniel@google.com

Review URL: https://codereview.chromium.org/430493003
This commit is contained in:
egdaniel 2014-07-29 08:52:23 -07:00 committed by Commit bot
parent 137bac0673
commit b09bdd6bac
8 changed files with 127 additions and 50 deletions

View File

@ -667,7 +667,7 @@ enum GrGLBackendState {
// View state stands for scissor and viewport // View state stands for scissor and viewport
kView_GrGLBackendState = 1 << 2, kView_GrGLBackendState = 1 << 2,
kBlend_GrGLBackendState = 1 << 3, kBlend_GrGLBackendState = 1 << 3,
kMSAAEnable_GrGLBackendState = 1 << 4, kAA_GrGLBackendState = 1 << 4,
kVertex_GrGLBackendState = 1 << 5, kVertex_GrGLBackendState = 1 << 5,
kStencil_GrGLBackendState = 1 << 6, kStencil_GrGLBackendState = 1 << 6,
kPixelStore_GrGLBackendState = 1 << 7, kPixelStore_GrGLBackendState = 1 << 7,

View File

@ -751,6 +751,10 @@ static bool apply_aa_to_rect(GrDrawTarget* target,
return false; return false;
} }
if (0 == strokeWidth && target->willUseHWAALines()) {
return false;
}
#if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT) #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT)
if (strokeWidth >= 0) { if (strokeWidth >= 0) {
#endif #endif

View File

@ -339,7 +339,8 @@ GrDrawState::BlendOptFlags GrDrawState::calcBlendOpts(bool forceCoverage,
// (0,1). The same applies when coverage is known to be 0. // (0,1). The same applies when coverage is known to be 0.
if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne) || covIsZero) { if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne) || covIsZero) {
if (this->getStencil().doesWrite()) { if (this->getStencil().doesWrite()) {
return kEmitCoverage_BlendOptFlag; return kDisableBlend_BlendOptFlag |
kEmitCoverage_BlendOptFlag;
} else { } else {
return kSkipDraw_BlendOptFlag; return kSkipDraw_BlendOptFlag;
} }
@ -358,14 +359,13 @@ GrDrawState::BlendOptFlags GrDrawState::calcBlendOpts(bool forceCoverage,
if (kOne_GrBlendCoeff == *srcCoeff) { if (kOne_GrBlendCoeff == *srcCoeff) {
// if there is no coverage and coeffs are (1,0) then we // 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 // won't need to read the dst at all, it gets replaced by src
*dstCoeff = kZero_GrBlendCoeff; return kDisableBlend_BlendOptFlag;
return kNone_BlendOpt;
} else if (kZero_GrBlendCoeff == *srcCoeff) { } else if (kZero_GrBlendCoeff == *srcCoeff) {
// if the op is "clear" then we don't need to emit a color // if the op is "clear" then we don't need to emit a color
// or blend, just write transparent black into the dst. // or blend, just write transparent black into the dst.
*srcCoeff = kOne_GrBlendCoeff; *srcCoeff = kOne_GrBlendCoeff;
*dstCoeff = kZero_GrBlendCoeff; *dstCoeff = kZero_GrBlendCoeff;
return kEmitTransBlack_BlendOptFlag; return kDisableBlend_BlendOptFlag | kEmitTransBlack_BlendOptFlag;
} }
} }
} else if (this->isCoverageDrawing()) { } else if (this->isCoverageDrawing()) {
@ -399,7 +399,13 @@ GrDrawState::BlendOptFlags GrDrawState::calcBlendOpts(bool forceCoverage,
return kCoverageAsAlpha_BlendOptFlag; 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; return kNone_BlendOpt;
} }

View File

@ -520,25 +520,29 @@ public:
* Don't draw at all * Don't draw at all
*/ */
kSkipDraw_BlendOptFlag = 0x1, 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 * The coverage value does not have to be computed separately from alpha, the the output
* color can be the modulation of the two. * color can be the modulation of the two.
*/ */
kCoverageAsAlpha_BlendOptFlag = 0x2, kCoverageAsAlpha_BlendOptFlag = 0x4,
/** /**
* Instead of emitting a src color, emit coverage in the alpha channel and r,g,b are * Instead of emitting a src color, emit coverage in the alpha channel and r,g,b are
* "don't cares". * "don't cares".
*/ */
kEmitCoverage_BlendOptFlag = 0x4, kEmitCoverage_BlendOptFlag = 0x8,
/** /**
* Emit transparent black instead of the src color, no need to compute coverage. * Emit transparent black instead of the src color, no need to compute coverage.
*/ */
kEmitTransBlack_BlendOptFlag = 0x8, kEmitTransBlack_BlendOptFlag = 0x10,
/** /**
* Flag used to invalidate the cached BlendOptFlags, OptSrcCoeff, and OptDstCoeff cached by * Flag used to invalidate the cached BlendOptFlags, OptSrcCoeff, and OptDstCoeff cached by
* the get BlendOpts function. * the get BlendOpts function.
*/ */
kInvalid_BlendOptFlag = 0x10, kInvalid_BlendOptFlag = 0x20,
}; };
GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags);

View File

@ -613,16 +613,24 @@ void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
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 { bool GrDrawTarget::canApplyCoverage() const {
// we can correctly apply coverage if a) we have dual source blending // 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() || return this->caps()->dualSourceBlendingSupport() ||
GrDrawState::kNone_BlendOpt != this->getDrawState().getBlendOpts(true, &srcCoeff, GrDrawState::kNone_BlendOpt != this->getDrawState().getBlendOpts(true);
&dstCoeff) ||
(kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -112,6 +112,12 @@ public:
return !this->canApplyCoverage(); return !this->canApplyCoverage();
} }
/**
* Given the current draw state and hw support, will HW AA lines be used (if
* a line primitive type is drawn)?
*/
bool willUseHWAALines() const;
/** /**
* There are three types of "sources" of geometry (vertices and indices) for * There are three types of "sources" of geometry (vertices and indices) for
* draw calls made on the target. When performing an indexed draw, the * draw calls made on the target. When performing an indexed draw, the

View File

@ -280,8 +280,8 @@ void GrGpuGL::onResetContext(uint32_t resetBits) {
GL_CALL(LineWidth(1)); GL_CALL(LineWidth(1));
} }
if (resetBits & kMSAAEnable_GrGLBackendState) { if (resetBits & kAA_GrGLBackendState) {
fMSAAEnabled = kUnknown_TriState; fHWAAState.invalidate();
} }
fHWActiveTextureUnitIdx = -1; // invalid fHWActiveTextureUnitIdx = -1; // invalid
@ -2164,20 +2164,45 @@ void GrGpuGL::flushAAState(DrawType type) {
const GrRenderTarget* rt = this->getDrawState().getRenderTarget(); const GrRenderTarget* rt = this->getDrawState().getRenderTarget();
if (kGL_GrGLStandard == this->glStandard()) { if (kGL_GrGLStandard == this->glStandard()) {
if (RT_HAS_MSAA) { // 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) {
// FIXME: GL_NV_pr doesn't seem to like MSAA disabled. The paths // FIXME: GL_NV_pr doesn't seem to like MSAA disabled. The paths
// convex hulls of each segment appear to get filled. // convex hulls of each segment appear to get filled.
bool enableMSAA = kStencilPath_DrawType == type || bool enableMSAA = kStencilPath_DrawType == type ||
this->getDrawState().isHWAntialiasState(); this->getDrawState().isHWAntialiasState();
if (enableMSAA) { if (enableMSAA) {
if (kYes_TriState != fMSAAEnabled) { if (kYes_TriState != fHWAAState.fMSAAEnabled) {
GL_CALL(Enable(GR_GL_MULTISAMPLE)); GL_CALL(Enable(GR_GL_MULTISAMPLE));
fMSAAEnabled = kYes_TriState; fHWAAState.fMSAAEnabled = kYes_TriState;
} }
} else { } else {
if (kNo_TriState != fMSAAEnabled) { if (kNo_TriState != fHWAAState.fMSAAEnabled) {
GL_CALL(Disable(GR_GL_MULTISAMPLE)); GL_CALL(Disable(GR_GL_MULTISAMPLE));
fMSAAEnabled = kNo_TriState; fHWAAState.fMSAAEnabled = kNo_TriState;
} }
} }
} }
@ -2203,9 +2228,24 @@ void GrGpuGL::flushPathStencilSettings(SkPath::FillType fill) {
void GrGpuGL::flushBlend(bool isLines, void GrGpuGL::flushBlend(bool isLines,
GrBlendCoeff srcCoeff, GrBlendCoeff srcCoeff,
GrBlendCoeff dstCoeff) { GrBlendCoeff dstCoeff) {
// any optimization to disable blending should have already been applied and if (isLines && this->willUseHWAALines()) {
// tweaked the coeffs to (1, 0). if (kYes_TriState != fHWBlendState.fEnabled) {
bool blendOff = kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff; 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 (blendOff) {
if (kNo_TriState != fHWBlendState.fEnabled) { if (kNo_TriState != fHWBlendState.fEnabled) {
GL_CALL(Disable(GR_GL_BLEND)); GL_CALL(Disable(GR_GL_BLEND));
@ -2235,6 +2275,7 @@ void GrGpuGL::flushBlend(bool isLines,
fHWBlendState.fConstColorValid = true; fHWBlendState.fConstColorValid = true;
} }
} }
}
} }
static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) { static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) {

View File

@ -443,7 +443,15 @@ private:
} }
} fHWBlendState; } fHWBlendState;
struct {
TriState fMSAAEnabled; TriState fMSAAEnabled;
TriState fSmoothLineEnabled;
void invalidate() {
fMSAAEnabled = kUnknown_TriState;
fSmoothLineEnabled = kUnknown_TriState;
}
} fHWAAState;
GrGLProgram::MatrixState fHWProjectionMatrixState; GrGLProgram::MatrixState fHWProjectionMatrixState;