//////////////////////////////////////////////////////////////////////////////s
-GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix)
- : fCachedOptState(NULL) {
+GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix) {
SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
*this = state;
if (!preConcatMatrix.isIdentity()) {
for (int i = 0; i < this->numCoverageStages(); ++i) {
fCoverageStages[i].localCoordChange(preConcatMatrix);
}
- this->invalidateOptState();
}
}
fHints = that.fHints;
- SkRefCnt_SafeAssign(fCachedOptState, that.fCachedOptState);
-
memcpy(fFixedFunctionVertexAttribIndices,
that.fFixedFunctionVertexAttribIndices,
sizeof(fFixedFunctionVertexAttribIndices));
fDrawFace = kBoth_DrawFace;
fHints = 0;
-
- this->invalidateOptState();
}
bool GrDrawState::setIdentityViewMatrix() {
fCoverageStages[s].localCoordChange(invVM);
}
}
- this->invalidateOptState();
fViewMatrix.reset();
return true;
}
this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff());
this->setCoverage(paint.getCoverage());
- this->invalidateOptState();
}
////////////////////////////////////////////////////////////////////////////////
overlapCheck |= (mask << offsetShift);
#endif
}
- this->invalidateOptState();
// Positions must be specified.
SkASSERT(-1 != fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding]);
}
0xff,
sizeof(fFixedFunctionVertexAttribIndices));
fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] = 0;
- this->invalidateOptState();
}
////////////////////////////////////////////////////////////////////////////////
int n = fDrawState->numCoverageStages() - fCoverageEffectCnt;
SkASSERT(n >= 0);
fDrawState->fCoverageStages.pop_back_n(n);
- if (m + n > 0) {
- fDrawState->invalidateOptState();
- }
SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
}
fDrawState = ds;
for (int s = 0; s < numCoverageStages; ++s, ++i) {
fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges[i]);
}
- fDrawState->invalidateOptState();
fDrawState = NULL;
}
}
this->doEffectCoordChanges(preconcatMatrix);
SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
- drawState->invalidateOptState();
}
bool GrDrawState::AutoViewMatrixRestore::setIdentity(GrDrawState* drawState) {
return true;
}
- drawState->invalidateOptState();
fViewMatrix = drawState->getViewMatrix();
if (0 == drawState->numTotalStages()) {
drawState->fViewMatrix.reset();
////////////////////////////////////////////////////////////////////////////////
-void GrDrawState::invalidateOptState() const {
- SkSafeSetNull(fCachedOptState);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
GrDrawState::~GrDrawState() {
- SkSafeUnref(fCachedOptState);
SkASSERT(0 == fBlockEffectRemovalCnt);
}
public:
SK_DECLARE_INST_COUNT(GrDrawState)
- GrDrawState() : fCachedOptState(NULL) {
+ GrDrawState() {
SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
this->reset();
}
- GrDrawState(const SkMatrix& initialViewMatrix) : fCachedOptState(NULL) {
+ GrDrawState(const SkMatrix& initialViewMatrix) {
SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
this->reset(initialViewMatrix);
}
/**
* Copies another draw state.
**/
- GrDrawState(const GrDrawState& state) : INHERITED(), fCachedOptState(NULL) {
+ GrDrawState(const GrDrawState& state) : INHERITED() {
SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
*this = state;
}
void setColor(GrColor color) {
if (color != fColor) {
fColor = color;
- this->invalidateOptState();
}
}
void setCoverage(uint8_t coverage) {
if (coverage != fCoverage) {
fCoverage = coverage;
- this->invalidateOptState();
}
}
SkASSERT(geometryProcessor);
SkASSERT(!this->hasGeometryProcessor());
fGeometryProcessor.reset(SkRef(geometryProcessor));
- this->invalidateOptState();
return geometryProcessor;
}
const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effect) {
SkASSERT(effect);
SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect));
- this->invalidateOptState();
return effect;
}
const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* effect) {
SkASSERT(effect);
SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect));
- this->invalidateOptState();
return effect;
}
if (srcCoeff != fSrcBlend || dstCoeff != fDstBlend) {
fSrcBlend = srcCoeff;
fDstBlend = dstCoeff;
- this->invalidateOptState();
}
#ifdef SK_DEBUG
if (GrBlendCoeffRefsDst(dstCoeff)) {
void setBlendConstant(GrColor constant) {
if (constant != fBlendConstant) {
fBlendConstant = constant;
- this->invalidateOptState();
}
}
*/
void setRenderTarget(GrRenderTarget* target) {
fRenderTarget.set(SkSafeRef(target), kWrite_GrIOType);
- this->invalidateOptState();
}
/// @}
void setStencil(const GrStencilSettings& settings) {
if (settings != fStencilSettings) {
fStencilSettings = settings;
- this->invalidateOptState();
}
}
void disableStencil() {
if (!fStencilSettings.isDisabled()) {
fStencilSettings.setDisabled();
- this->invalidateOptState();
}
}
void resetStateFlags() {
if (0 != fFlagBits) {
fFlagBits = 0;
- this->invalidateOptState();
}
}
void enableState(uint32_t stateBits) {
if (stateBits & ~fFlagBits) {
fFlagBits |= stateBits;
- this->invalidateOptState();
}
}
void disableState(uint32_t stateBits) {
if (stateBits & fFlagBits) {
fFlagBits &= ~(stateBits);
- this->invalidateOptState();
}
}
*/
bool srcAlphaWillBeOne() const;
- void invalidateOptState() const;
-
void onReset(const SkMatrix* initialViewMatrix);
// Some of the auto restore objects assume that no effects are removed during their lifetime.
// not need to be compared in op==.
int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt];
- mutable GrOptDrawState* fCachedOptState;
- mutable uint32_t fCachedCapsID;
-
friend class GrOptDrawState;
typedef SkRefCnt INHERITED;
GrGpu* gpu,
const GrDeviceCoordTexture* dstCopy,
GrGpu::DrawType drawType) {
- const GrDrawTargetCaps& caps = *gpu->caps();
- if (NULL == drawState.fCachedOptState || caps.getUniqueID() != drawState.fCachedCapsID) {
- GrBlendCoeff srcCoeff;
- GrBlendCoeff dstCoeff;
- BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false,
- &srcCoeff,
- &dstCoeff);
-
- // If our blend coeffs are set to 0,1 we know we will not end up drawing unless we are
- // stenciling. When path rendering the stencil settings are not always set on the draw state
- // so we must check the draw type. In cases where we will skip drawing we simply return a
- // null GrOptDrawState.
- if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff &&
- !drawState.getStencil().doesWrite() && GrGpu::kStencilPath_DrawType != drawType) {
- return NULL;
- }
-
- drawState.fCachedOptState = SkNEW_ARGS(GrOptDrawState, (drawState, blendFlags, srcCoeff,
- dstCoeff, gpu, dstCopy, drawType));
- drawState.fCachedCapsID = caps.getUniqueID();
- } else {
-#ifdef SK_DEBUG
- GrBlendCoeff srcCoeff;
- GrBlendCoeff dstCoeff;
- BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false,
- &srcCoeff,
- &dstCoeff);
- SkASSERT(GrOptDrawState(drawState, blendFlags, srcCoeff, dstCoeff, gpu, dstCopy,
- drawType) == *drawState.fCachedOptState);
-#endif
+ GrBlendCoeff srcCoeff;
+ GrBlendCoeff dstCoeff;
+ BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false,
+ &srcCoeff,
+ &dstCoeff);
+
+ // If our blend coeffs are set to 0,1 we know we will not end up drawing unless we are
+ // stenciling. When path rendering the stencil settings are not always set on the draw state
+ // so we must check the draw type. In cases where we will skip drawing we simply return a
+ // null GrOptDrawState.
+ if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff &&
+ !drawState.getStencil().doesWrite() && GrGpu::kStencilPath_DrawType != drawType) {
+ return NULL;
}
- drawState.fCachedOptState->ref();
- return drawState.fCachedOptState;
+
+ return SkNEW_ARGS(GrOptDrawState, (drawState, blendFlags, srcCoeff,
+ dstCoeff, gpu, dstCopy, drawType));
}
void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds,
class GrOptDrawState : public SkRefCnt {
public:
/**
- * Returns a snapshot of the current optimized state. If the current drawState has a valid
- * cached optimiezed state it will simply return a pointer to it otherwise it will create a new
- * GrOptDrawState. In all cases the GrOptDrawState is reffed and ownership is given to the
- * caller.
+ * Returns a snapshot of the current optimized state. The GrOptDrawState is reffed and ownership
+ * is given to the caller.
*/
static GrOptDrawState* Create(const GrDrawState& drawState, GrGpu*,
const GrDeviceCoordTexture* dstCopy, GrGpu::DrawType drawType);