aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrOptDrawState.cpp
diff options
context:
space:
mode:
authorGravatar egdaniel <egdaniel@google.com>2014-09-16 12:54:40 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-09-16 12:54:40 -0700
commit170f90b4576f291879371ecd6ae4bc2b1d85c64a (patch)
tree5004347d4e5d285751f7a6e8713a2dc435c46b87 /src/gpu/GrOptDrawState.cpp
parent3375c8047e7f10e6bf9a2ce1c2e8b0df08c56024 (diff)
Attach GrOptDrawState into shader building pipeline
The OptDrawState is now used for creating the actual gl shader. Current optimizations dones in GrOptDrawState include: All blend optimizations Constant color/coverage stage optimizations BUG=skia: Committed: https://skia.googlesource.com/skia/+/ee6206572b42fec11f83ad0c1e6d435903640518 R=bsalomon@google.com, joshualitt@google.com Author: egdaniel@google.com Review URL: https://codereview.chromium.org/504203004
Diffstat (limited to 'src/gpu/GrOptDrawState.cpp')
-rw-r--r--src/gpu/GrOptDrawState.cpp46
1 files changed, 42 insertions, 4 deletions
diff --git a/src/gpu/GrOptDrawState.cpp b/src/gpu/GrOptDrawState.cpp
index 83546ba3b7..5f352966b8 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,15 @@ GrOptDrawState::GrOptDrawState(const GrDrawState& drawState) : INHERITED(drawSta
fVAStride = drawState.getVertexStride();
fStencilSettings = drawState.getStencil();
fDrawFace = drawState.getDrawFace();
-
- fBlendOptFlags = drawState.getBlendOpts(false, &fSrcBlend, &fDstBlend);
+ fBlendOptFlags = blendOptFlags;
+ fSrcBlend = optSrcCoeff;
+ fDstBlend = optDstCoeff;
memcpy(fFixedFunctionVertexAttribIndices,
drawState.getFixedFunctionVertexAttribIndices(),
sizeof(fFixedFunctionVertexAttribIndices));
+
fInputColorIsUsed = true;
fInputCoverageIsUsed = true;
@@ -38,8 +43,40 @@ GrOptDrawState::GrOptDrawState(const GrDrawState& drawState) : INHERITED(drawSta
this->copyEffectiveColorStages(drawState);
this->copyEffectiveCoverageStages(drawState);
+ this->adjustFromBlendOpts();
};
+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;
+ default:
+ SkFAIL("Unknown BlendOptFlag");
+
+ }
+}
+
void GrOptDrawState::removeFixedFunctionVertexAttribs(uint8_t removeVAFlag) {
int numToRemove = 0;
uint8_t maskCheck = 0x1;
@@ -50,6 +87,7 @@ void GrOptDrawState::removeFixedFunctionVertexAttribs(uint8_t removeVAFlag) {
}
maskCheck <<= 1;
}
+
fOptVA.reset(fVACount - numToRemove);
GrVertexAttrib* dst = fOptVA.get();
@@ -64,9 +102,9 @@ void GrOptDrawState::removeFixedFunctionVertexAttribs(uint8_t removeVAFlag) {
fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = -1;
continue;
}
+ fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = newIdx;
}
memcpy(dst, src, sizeof(GrVertexAttrib));
- fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = newIdx;
++newIdx;
++dst;
}