Index: src/gpu/GrOptDrawState.cpp |
diff --git a/src/gpu/GrOptDrawState.cpp b/src/gpu/GrOptDrawState.cpp |
index 83546ba3b789aa556caefafd166baee52b38bef7..7fb673fe0f4e25bffc957d67ff245a245f76c7d7 100644 |
--- a/src/gpu/GrOptDrawState.cpp |
+++ b/src/gpu/GrOptDrawState.cpp |
@@ -9,7 +9,10 @@ |
#include "GrDrawState.h" |
-GrOptDrawState::GrOptDrawState(const GrDrawState& drawState) : INHERITED(drawState) { |
+GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, |
+ BlendOptFlags blendOptFlags, |
+ GrBlendCoeff optSrcCoeff, |
+ GrBlendCoeff optDstCoeff) : INHERITED(drawState) { |
fColor = drawState.getColor(); |
fCoverage = drawState.getCoverage(); |
fViewMatrix = drawState.getViewMatrix(); |
@@ -20,13 +23,17 @@ GrOptDrawState::GrOptDrawState(const GrDrawState& drawState) : INHERITED(drawSta |
fVAStride = drawState.getVertexStride(); |
fStencilSettings = drawState.getStencil(); |
fDrawFace = drawState.getDrawFace(); |
+ fBlendOptFlags = blendOptFlags; |
+ fSrcBlend = optSrcCoeff; |
+ fDstBlend = optDstCoeff; |
- fBlendOptFlags = drawState.getBlendOpts(false, &fSrcBlend, &fDstBlend); |
+ this->initializeVAIndexMap(); |
memcpy(fFixedFunctionVertexAttribIndices, |
drawState.getFixedFunctionVertexAttribIndices(), |
sizeof(fFixedFunctionVertexAttribIndices)); |
+ |
fInputColorIsUsed = true; |
fInputCoverageIsUsed = true; |
@@ -38,8 +45,64 @@ GrOptDrawState::GrOptDrawState(const GrDrawState& drawState) : INHERITED(drawSta |
this->copyEffectiveColorStages(drawState); |
this->copyEffectiveCoverageStages(drawState); |
+ this->adjustFromBlendOpts(); |
+ this->remapEffectStagesVAIndices(); |
}; |
+void GrOptDrawState::initializeVAIndexMap() { |
+ fVAIndexMap.reset(fVACount); |
+ int* map = fVAIndexMap.get(); |
+ for (int i = 0; i < fVACount; ++i) { |
+ map[i] = i; |
+ } |
+} |
+ |
+void GrOptDrawState::remapEffectStagesVAIndices() { |
+ for (int i = 0; i < this->numColorStages(); ++i) { |
+ fColorStages[i].remapAttribIndices(fVAIndexMap.get()); |
+ } |
+ for (int i = 0; i < this->numCoverageStages(); ++i) { |
+ fCoverageStages[i].remapAttribIndices(fVAIndexMap.get()); |
+ } |
+ |
+ if (this->hasGeometryProcessor()) { |
+ fGeometryProcessor->remapAttribIndices(fVAIndexMap.get()); |
+ } |
+} |
+ |
+void GrOptDrawState::adjustFromBlendOpts() { |
+ |
+ switch (fBlendOptFlags) { |
+ case kNone_BlendOpt: |
+ case kSkipDraw_BlendOptFlag: |
+ break; |
+ case kCoverageAsAlpha_BlendOptFlag: |
+ fFlagBits |= kCoverageDrawing_StateBit; |
+ break; |
+ case kEmitCoverage_BlendOptFlag: |
+ fColor = 0xffffffff; |
+ fInputColorIsUsed = true; |
+ fColorStages.reset(); |
+ this->removeFixedFunctionVertexAttribs(0x1 << kColor_GrVertexAttribBinding); |
+ break; |
+ case kEmitTransBlack_BlendOptFlag: |
+ fColor = 0; |
+ fCoverage = 0xff; |
+ fInputColorIsUsed = true; |
+ fInputCoverageIsUsed = true; |
+ fColorStages.reset(); |
+ fCoverageStages.reset(); |
+ this->removeFixedFunctionVertexAttribs(0x1 << kColor_GrVertexAttribBinding | |
+ 0x1 << kCoverage_GrVertexAttribBinding); |
+ break; |
+ case kInvalid_BlendOptFlag: |
+ break; |
+ default: |
+ SkFAIL("Unknown BlendOptFlag"); |
+ |
+ } |
+} |
+ |
void GrOptDrawState::removeFixedFunctionVertexAttribs(uint8_t removeVAFlag) { |
int numToRemove = 0; |
uint8_t maskCheck = 0x1; |
@@ -50,11 +113,14 @@ void GrOptDrawState::removeFixedFunctionVertexAttribs(uint8_t removeVAFlag) { |
} |
maskCheck <<= 1; |
} |
+ |
fOptVA.reset(fVACount - numToRemove); |
GrVertexAttrib* dst = fOptVA.get(); |
const GrVertexAttrib* src = fVAPtr; |
+ int* indexMap = fVAIndexMap.get(); |
+ |
for (int i = 0, newIdx = 0; i < fVACount; ++i, ++src) { |
const GrVertexAttrib& currAttrib = *src; |
if (currAttrib.fBinding < kGrFixedFunctionVertexAttribBindingCnt) { |
@@ -62,11 +128,13 @@ void GrOptDrawState::removeFixedFunctionVertexAttribs(uint8_t removeVAFlag) { |
if (maskCheck & removeVAFlag) { |
SkASSERT(-1 != fFixedFunctionVertexAttribIndices[currAttrib.fBinding]); |
fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = -1; |
+ indexMap[i] = -1; |
continue; |
} |
+ fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = newIdx; |
} |
+ indexMap[i] = newIdx; |
memcpy(dst, src, sizeof(GrVertexAttrib)); |
- fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = newIdx; |
++newIdx; |
++dst; |
} |