OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrOptDrawState.h" | 8 #include "GrOptDrawState.h" |
9 | 9 |
10 #include "GrDrawState.h" | 10 #include "GrDrawState.h" |
11 | 11 |
12 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState) : INHERITED(drawSta
te) { | 12 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, |
| 13 BlendOptFlags blendOptFlags, |
| 14 GrBlendCoeff optSrcCoeff, |
| 15 GrBlendCoeff optDstCoeff) : INHERITED(drawState)
{ |
13 fColor = drawState.getColor(); | 16 fColor = drawState.getColor(); |
14 fCoverage = drawState.getCoverage(); | 17 fCoverage = drawState.getCoverage(); |
15 fViewMatrix = drawState.getViewMatrix(); | 18 fViewMatrix = drawState.getViewMatrix(); |
16 fBlendConstant = drawState.getBlendConstant(); | 19 fBlendConstant = drawState.getBlendConstant(); |
17 fFlagBits = drawState.getFlagBits(); | 20 fFlagBits = drawState.getFlagBits(); |
18 fVAPtr = drawState.getVertexAttribs(); | 21 fVAPtr = drawState.getVertexAttribs(); |
19 fVACount = drawState.getVertexAttribCount(); | 22 fVACount = drawState.getVertexAttribCount(); |
20 fVAStride = drawState.getVertexStride(); | 23 fVAStride = drawState.getVertexStride(); |
21 fStencilSettings = drawState.getStencil(); | 24 fStencilSettings = drawState.getStencil(); |
22 fDrawFace = drawState.getDrawFace(); | 25 fDrawFace = drawState.getDrawFace(); |
| 26 fBlendOptFlags = blendOptFlags; |
| 27 fSrcBlend = optSrcCoeff; |
| 28 fDstBlend = optDstCoeff; |
23 | 29 |
24 fBlendOptFlags = drawState.getBlendOpts(false, &fSrcBlend, &fDstBlend); | 30 this->initializeVAIndexMap(); |
25 | 31 |
26 memcpy(fFixedFunctionVertexAttribIndices, | 32 memcpy(fFixedFunctionVertexAttribIndices, |
27 drawState.getFixedFunctionVertexAttribIndices(), | 33 drawState.getFixedFunctionVertexAttribIndices(), |
28 sizeof(fFixedFunctionVertexAttribIndices)); | 34 sizeof(fFixedFunctionVertexAttribIndices)); |
29 | 35 |
| 36 |
30 fInputColorIsUsed = true; | 37 fInputColorIsUsed = true; |
31 fInputCoverageIsUsed = true; | 38 fInputCoverageIsUsed = true; |
32 | 39 |
33 if (drawState.hasGeometryProcessor()) { | 40 if (drawState.hasGeometryProcessor()) { |
34 fGeometryProcessor.reset(SkNEW_ARGS(GrEffectStage, (*drawState.getGeomet
ryProcessor()))); | 41 fGeometryProcessor.reset(SkNEW_ARGS(GrEffectStage, (*drawState.getGeomet
ryProcessor()))); |
35 } else { | 42 } else { |
36 fGeometryProcessor.reset(NULL); | 43 fGeometryProcessor.reset(NULL); |
37 } | 44 } |
38 | 45 |
39 this->copyEffectiveColorStages(drawState); | 46 this->copyEffectiveColorStages(drawState); |
40 this->copyEffectiveCoverageStages(drawState); | 47 this->copyEffectiveCoverageStages(drawState); |
| 48 this->adjustFromBlendOpts(); |
| 49 this->remapEffectStagesVAIndices(); |
41 }; | 50 }; |
42 | 51 |
| 52 void GrOptDrawState::initializeVAIndexMap() { |
| 53 fVAIndexMap.reset(fVACount); |
| 54 int* map = fVAIndexMap.get(); |
| 55 for (int i = 0; i < fVACount; ++i) { |
| 56 map[i] = i; |
| 57 } |
| 58 } |
| 59 |
| 60 void GrOptDrawState::remapEffectStagesVAIndices() { |
| 61 for (int i = 0; i < this->numColorStages(); ++i) { |
| 62 fColorStages[i].remapAttribIndices(fVAIndexMap.get()); |
| 63 } |
| 64 for (int i = 0; i < this->numCoverageStages(); ++i) { |
| 65 fCoverageStages[i].remapAttribIndices(fVAIndexMap.get()); |
| 66 } |
| 67 |
| 68 if (this->hasGeometryProcessor()) { |
| 69 fGeometryProcessor->remapAttribIndices(fVAIndexMap.get()); |
| 70 } |
| 71 } |
| 72 |
| 73 void GrOptDrawState::adjustFromBlendOpts() { |
| 74 |
| 75 switch (fBlendOptFlags) { |
| 76 case kNone_BlendOpt: |
| 77 case kSkipDraw_BlendOptFlag: |
| 78 break; |
| 79 case kCoverageAsAlpha_BlendOptFlag: |
| 80 fFlagBits |= kCoverageDrawing_StateBit; |
| 81 break; |
| 82 case kEmitCoverage_BlendOptFlag: |
| 83 fColor = 0xffffffff; |
| 84 fInputColorIsUsed = true; |
| 85 fColorStages.reset(); |
| 86 this->removeFixedFunctionVertexAttribs(0x1 << kColor_GrVertexAttribB
inding); |
| 87 break; |
| 88 case kEmitTransBlack_BlendOptFlag: |
| 89 fColor = 0; |
| 90 fCoverage = 0xff; |
| 91 fInputColorIsUsed = true; |
| 92 fInputCoverageIsUsed = true; |
| 93 fColorStages.reset(); |
| 94 fCoverageStages.reset(); |
| 95 this->removeFixedFunctionVertexAttribs(0x1 << kColor_GrVertexAttribB
inding | |
| 96 0x1 << kCoverage_GrVertexAttr
ibBinding); |
| 97 break; |
| 98 case kInvalid_BlendOptFlag: |
| 99 break; |
| 100 default: |
| 101 SkFAIL("Unknown BlendOptFlag"); |
| 102 |
| 103 } |
| 104 } |
| 105 |
43 void GrOptDrawState::removeFixedFunctionVertexAttribs(uint8_t removeVAFlag) { | 106 void GrOptDrawState::removeFixedFunctionVertexAttribs(uint8_t removeVAFlag) { |
44 int numToRemove = 0; | 107 int numToRemove = 0; |
45 uint8_t maskCheck = 0x1; | 108 uint8_t maskCheck = 0x1; |
46 // Count the number of vertex attributes that we will actually remove | 109 // Count the number of vertex attributes that we will actually remove |
47 for (int i = 0; i < kGrFixedFunctionVertexAttribBindingCnt; ++i) { | 110 for (int i = 0; i < kGrFixedFunctionVertexAttribBindingCnt; ++i) { |
48 if ((maskCheck & removeVAFlag) && -1 != fFixedFunctionVertexAttribIndice
s[i]) { | 111 if ((maskCheck & removeVAFlag) && -1 != fFixedFunctionVertexAttribIndice
s[i]) { |
49 ++numToRemove; | 112 ++numToRemove; |
50 } | 113 } |
51 maskCheck <<= 1; | 114 maskCheck <<= 1; |
52 } | 115 } |
| 116 |
53 fOptVA.reset(fVACount - numToRemove); | 117 fOptVA.reset(fVACount - numToRemove); |
54 | 118 |
55 GrVertexAttrib* dst = fOptVA.get(); | 119 GrVertexAttrib* dst = fOptVA.get(); |
56 const GrVertexAttrib* src = fVAPtr; | 120 const GrVertexAttrib* src = fVAPtr; |
57 | 121 |
| 122 int* indexMap = fVAIndexMap.get(); |
| 123 |
58 for (int i = 0, newIdx = 0; i < fVACount; ++i, ++src) { | 124 for (int i = 0, newIdx = 0; i < fVACount; ++i, ++src) { |
59 const GrVertexAttrib& currAttrib = *src; | 125 const GrVertexAttrib& currAttrib = *src; |
60 if (currAttrib.fBinding < kGrFixedFunctionVertexAttribBindingCnt) { | 126 if (currAttrib.fBinding < kGrFixedFunctionVertexAttribBindingCnt) { |
61 uint8_t maskCheck = 0x1 << currAttrib.fBinding; | 127 uint8_t maskCheck = 0x1 << currAttrib.fBinding; |
62 if (maskCheck & removeVAFlag) { | 128 if (maskCheck & removeVAFlag) { |
63 SkASSERT(-1 != fFixedFunctionVertexAttribIndices[currAttrib.fBin
ding]); | 129 SkASSERT(-1 != fFixedFunctionVertexAttribIndices[currAttrib.fBin
ding]); |
64 fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = -1; | 130 fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = -1; |
| 131 indexMap[i] = -1; |
65 continue; | 132 continue; |
66 } | 133 } |
| 134 fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = newIdx; |
67 } | 135 } |
| 136 indexMap[i] = newIdx; |
68 memcpy(dst, src, sizeof(GrVertexAttrib)); | 137 memcpy(dst, src, sizeof(GrVertexAttrib)); |
69 fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = newIdx; | |
70 ++newIdx; | 138 ++newIdx; |
71 ++dst; | 139 ++dst; |
72 } | 140 } |
73 fVACount -= numToRemove; | 141 fVACount -= numToRemove; |
74 fVAPtr = fOptVA.get(); | 142 fVAPtr = fOptVA.get(); |
75 } | 143 } |
76 | 144 |
77 void GrOptDrawState::copyEffectiveColorStages(const GrDrawState& ds) { | 145 void GrOptDrawState::copyEffectiveColorStages(const GrDrawState& ds) { |
78 int firstColorStage = 0; | 146 int firstColorStage = 0; |
79 | 147 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 ds.numCoverageStages() - firstCoverageStage); | 206 ds.numCoverageStages() - firstCoverageStage); |
139 } else { | 207 } else { |
140 fCoverageStages.reset(); | 208 fCoverageStages.reset(); |
141 } | 209 } |
142 } | 210 } |
143 | 211 |
144 bool GrOptDrawState::operator== (const GrOptDrawState& that) const { | 212 bool GrOptDrawState::operator== (const GrOptDrawState& that) const { |
145 return this->isEqual(that); | 213 return this->isEqual(that); |
146 } | 214 } |
147 | 215 |
OLD | NEW |