Chromium Code Reviews| 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 #include "GrDrawTargetCaps.h" | 11 #include "GrDrawTargetCaps.h" |
| 12 #include "gl/GrGpuGL.h" | |
| 12 | 13 |
| 13 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, | 14 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, |
| 14 BlendOptFlags blendOptFlags, | 15 BlendOptFlags blendOptFlags, |
| 15 GrBlendCoeff optSrcCoeff, | 16 GrBlendCoeff optSrcCoeff, |
| 16 GrBlendCoeff optDstCoeff, | 17 GrBlendCoeff optDstCoeff, |
| 17 const GrDrawTargetCaps& caps) { | 18 GrGpu* gpu, |
| 19 const GrDeviceCoordTexture* dstCopy, | |
| 20 GrGpu::DrawType drawType) { | |
| 18 fRenderTarget.set(SkSafeRef(drawState.getRenderTarget()), kWrite_GrIOType); | 21 fRenderTarget.set(SkSafeRef(drawState.getRenderTarget()), kWrite_GrIOType); |
| 19 fColor = drawState.getColor(); | 22 fColor = drawState.getColor(); |
| 20 fCoverage = drawState.getCoverage(); | 23 fCoverage = drawState.getCoverage(); |
| 21 fViewMatrix = drawState.getViewMatrix(); | 24 fViewMatrix = drawState.getViewMatrix(); |
| 22 fBlendConstant = drawState.getBlendConstant(); | 25 fBlendConstant = drawState.getBlendConstant(); |
| 23 fFlagBits = drawState.getFlagBits(); | 26 fFlagBits = drawState.getFlagBits(); |
| 24 fVAPtr = drawState.getVertexAttribs(); | 27 fVAPtr = drawState.getVertexAttribs(); |
| 25 fVACount = drawState.getVertexAttribCount(); | 28 fVACount = drawState.getVertexAttribCount(); |
| 26 fVAStride = drawState.getVertexStride(); | 29 fVAStride = drawState.getVertexStride(); |
| 27 fStencilSettings = drawState.getStencil(); | 30 fStencilSettings = drawState.getStencil(); |
| 28 fDrawFace = (DrawFace)drawState.getDrawFace(); | 31 fDrawFace = (DrawFace)drawState.getDrawFace(); |
| 29 fBlendOptFlags = blendOptFlags; | 32 fBlendOptFlags = blendOptFlags; |
| 30 fSrcBlend = optSrcCoeff; | 33 fSrcBlend = optSrcCoeff; |
| 31 fDstBlend = optDstCoeff; | 34 fDstBlend = optDstCoeff; |
| 35 GrProgramDesc::DescInfo descInfo; | |
| 32 | 36 |
| 33 memcpy(fFixedFunctionVertexAttribIndices, | 37 memcpy(descInfo.fFixedFunctionVertexAttribIndices, |
| 34 drawState.getFixedFunctionVertexAttribIndices(), | 38 drawState.getFixedFunctionVertexAttribIndices(), |
| 35 sizeof(fFixedFunctionVertexAttribIndices)); | 39 sizeof(descInfo.fFixedFunctionVertexAttribIndices)); |
| 36 | 40 |
| 37 fInputColorIsUsed = true; | 41 descInfo.fInputColorIsUsed = true; |
| 38 fInputCoverageIsUsed = true; | 42 descInfo.fInputCoverageIsUsed = true; |
| 39 | 43 |
| 40 int firstColorStageIdx = 0; | 44 int firstColorStageIdx = 0; |
| 41 int firstCoverageStageIdx = 0; | 45 int firstCoverageStageIdx = 0; |
| 42 bool separateCoverageFromColor; | 46 bool separateCoverageFromColor; |
| 43 | 47 |
| 44 uint8_t fixedFunctionVAToRemove = 0; | 48 uint8_t fixedFunctionVAToRemove = 0; |
| 45 | 49 |
| 46 this->computeEffectiveColorStages(drawState, &firstColorStageIdx, &fixedFunc tionVAToRemove); | 50 this->computeEffectiveColorStages(drawState, &descInfo, &firstColorStageIdx, |
| 47 this->computeEffectiveCoverageStages(drawState, &firstCoverageStageIdx); | 51 &fixedFunctionVAToRemove); |
| 48 this->adjustFromBlendOpts(drawState, &firstColorStageIdx, &firstCoverageStag eIdx, | 52 this->computeEffectiveCoverageStages(drawState, &descInfo, &firstCoverageSta geIdx); |
| 53 this->adjustFromBlendOpts(drawState, &descInfo, &firstColorStageIdx, &firstC overageStageIdx, | |
| 49 &fixedFunctionVAToRemove); | 54 &fixedFunctionVAToRemove); |
| 50 // Should not be setting any more FFVA to be removed at this point | 55 // Should not be setting any more FFVA to be removed at this point |
| 51 if (0 != fixedFunctionVAToRemove) { | 56 if (0 != fixedFunctionVAToRemove) { |
| 52 this->removeFixedFunctionVertexAttribs(fixedFunctionVAToRemove); | 57 this->removeFixedFunctionVertexAttribs(fixedFunctionVAToRemove, &descInf o); |
| 53 } | 58 } |
| 54 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx); | 59 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, &d escInfo); |
| 55 this->setOutputStateInfo(drawState, caps, firstCoverageStageIdx, &separateCo verageFromColor); | 60 this->setOutputStateInfo(drawState, *gpu->caps(), firstCoverageStageIdx, &de scInfo, |
| 61 &separateCoverageFromColor); | |
| 56 | 62 |
| 57 // Copy GeometryProcesssor from DS or ODS | 63 // Copy GeometryProcesssor from DS or ODS |
| 58 if (drawState.hasGeometryProcessor()) { | 64 if (drawState.hasGeometryProcessor()) { |
| 59 fGeometryProcessor.initAndRef(drawState.fGeometryProcessor); | 65 fGeometryProcessor.initAndRef(drawState.fGeometryProcessor); |
| 60 } else { | 66 } else { |
| 61 fGeometryProcessor.reset(NULL); | 67 fGeometryProcessor.reset(NULL); |
| 62 } | 68 } |
| 63 | 69 |
| 64 // Copy Color Stages from DS to ODS | 70 // Copy Color Stages from DS to ODS |
| 65 if (firstColorStageIdx < drawState.numColorStages()) { | 71 if (firstColorStageIdx < drawState.numColorStages()) { |
| 66 fFragmentStages.reset(&drawState.getColorStage(firstColorStageIdx), | 72 fFragmentStages.reset(&drawState.getColorStage(firstColorStageIdx), |
| 67 drawState.numColorStages() - firstColorStageIdx); | 73 drawState.numColorStages() - firstColorStageIdx); |
| 68 } else { | 74 } else { |
| 69 fFragmentStages.reset(); | 75 fFragmentStages.reset(); |
| 70 } | 76 } |
| 71 | 77 |
| 72 fNumColorStages = fFragmentStages.count(); | 78 fNumColorStages = fFragmentStages.count(); |
| 73 | 79 |
| 74 // Copy Coverage Stages from DS to ODS | 80 // Copy Coverage Stages from DS to ODS |
| 75 if (firstCoverageStageIdx < drawState.numCoverageStages()) { | 81 if (firstCoverageStageIdx < drawState.numCoverageStages()) { |
| 76 fFragmentStages.push_back_n(drawState.numCoverageStages() - firstCoverag eStageIdx, | 82 fFragmentStages.push_back_n(drawState.numCoverageStages() - firstCoverag eStageIdx, |
| 77 &drawState.getCoverageStage(firstCoverageSta geIdx)); | 83 &drawState.getCoverageStage(firstCoverageSta geIdx)); |
| 78 if (!separateCoverageFromColor) { | 84 if (!separateCoverageFromColor) { |
| 79 fNumColorStages = fFragmentStages.count(); | 85 fNumColorStages = fFragmentStages.count(); |
| 80 } | 86 } |
| 81 } | 87 } |
| 88 | |
| 89 // now create a key | |
| 90 gpu->buildProgramDesc(this, descInfo, drawType, dstCopy, &fDesc); | |
| 82 }; | 91 }; |
| 83 | 92 |
| 84 GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState, const GrDra wTargetCaps& caps, | 93 GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState, |
| 94 GrGpu* gpu, | |
| 95 const GrDeviceCoordTexture* dstCopy, | |
| 85 GrGpu::DrawType drawType) { | 96 GrGpu::DrawType drawType) { |
| 97 const GrDrawTargetCaps& caps = *gpu->caps(); | |
| 86 if (NULL == drawState.fCachedOptState || caps.getUniqueID() != drawState.fCa chedCapsID) { | 98 if (NULL == drawState.fCachedOptState || caps.getUniqueID() != drawState.fCa chedCapsID) { |
| 87 GrBlendCoeff srcCoeff; | 99 GrBlendCoeff srcCoeff; |
| 88 GrBlendCoeff dstCoeff; | 100 GrBlendCoeff dstCoeff; |
| 89 BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false, | 101 BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false, |
| 90 &srcCo eff, | 102 &srcCo eff, |
| 91 &dstCo eff); | 103 &dstCo eff); |
| 92 | 104 |
| 93 // If our blend coeffs are set to 0,1 we know we will not end up drawing unless we are | 105 // If our blend coeffs are set to 0,1 we know we will not end up drawing unless we are |
| 94 // stenciling. When path rendering the stencil settings are not always s et on the draw state | 106 // stenciling. When path rendering the stencil settings are not always s et on the draw state |
| 95 // so we must check the draw type. In cases where we will skip drawing w e simply return a | 107 // so we must check the draw type. In cases where we will skip drawing w e simply return a |
| 96 // null GrOptDrawState. | 108 // null GrOptDrawState. |
| 97 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff && | 109 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff && |
| 98 !drawState.getStencil().doesWrite() && GrGpu::kStencilPath_DrawType != drawType) { | 110 !drawState.getStencil().doesWrite() && GrGpu::kStencilPath_DrawType != drawType) { |
| 99 return NULL; | 111 return NULL; |
| 100 } | 112 } |
| 101 | 113 |
| 102 drawState.fCachedOptState = SkNEW_ARGS(GrOptDrawState, (drawState, blend Flags, srcCoeff, | 114 drawState.fCachedOptState = SkNEW_ARGS(GrOptDrawState, (drawState, blend Flags, srcCoeff, |
| 103 dstCoeff, caps)) ; | 115 dstCoeff, gpu, d stCopy, drawType)); |
| 104 drawState.fCachedCapsID = caps.getUniqueID(); | 116 drawState.fCachedCapsID = caps.getUniqueID(); |
| 105 } else { | 117 } else { |
| 106 #ifdef SK_DEBUG | 118 #ifdef SK_DEBUG |
| 107 GrBlendCoeff srcCoeff; | 119 GrBlendCoeff srcCoeff; |
| 108 GrBlendCoeff dstCoeff; | 120 GrBlendCoeff dstCoeff; |
| 109 BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false, | 121 BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false, |
| 110 &srcCo eff, | 122 &srcCo eff, |
| 111 &dstCo eff); | 123 &dstCo eff); |
| 112 SkASSERT(GrOptDrawState(drawState, blendFlags, srcCoeff, dstCoeff, caps) == | 124 SkASSERT(GrOptDrawState(drawState, blendFlags, srcCoeff, dstCoeff, gpu, dstCopy, |
| 113 *drawState.fCachedOptState); | 125 drawType) == *drawState.fCachedOptState); |
| 114 #endif | 126 #endif |
| 115 } | 127 } |
| 116 drawState.fCachedOptState->ref(); | 128 drawState.fCachedOptState->ref(); |
| 117 return drawState.fCachedOptState; | 129 return drawState.fCachedOptState; |
| 118 } | 130 } |
| 119 | 131 |
| 120 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, | 132 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, |
| 121 const GrDrawTargetCaps& caps, | 133 const GrDrawTargetCaps& caps, |
| 122 int firstCoverageStageIdx, | 134 int firstCoverageStageIdx, |
| 135 GrProgramDesc::DescInfo* descInfo, | |
| 123 bool* separateCoverageFromColor) { | 136 bool* separateCoverageFromColor) { |
| 124 // Set this default and then possibly change our mind if there is coverage. | 137 // Set this default and then possibly change our mind if there is coverage. |
| 125 fPrimaryOutputType = kModulate_PrimaryOutputType; | 138 descInfo->fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; |
| 126 fSecondaryOutputType = kNone_SecondaryOutputType; | 139 descInfo->fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; |
| 127 | 140 |
| 128 // If we do have coverage determine whether it matters. | 141 // If we do have coverage determine whether it matters. |
| 129 *separateCoverageFromColor = this->hasGeometryProcessor(); | 142 *separateCoverageFromColor = this->hasGeometryProcessor(); |
| 130 if (!this->isCoverageDrawing() && | 143 if (!this->isCoverageDrawing() && |
| 131 (ds.numCoverageStages() - firstCoverageStageIdx > 0 || | 144 (ds.numCoverageStages() - firstCoverageStageIdx > 0 || |
| 132 ds.hasGeometryProcessor() || | 145 ds.hasGeometryProcessor() || |
| 133 this->hasCoverageVertexAttribute())) { | 146 descInfo->hasCoverageVertexAttribute())) { |
| 134 | 147 |
| 135 if (caps.dualSourceBlendingSupport()) { | 148 if (caps.dualSourceBlendingSupport()) { |
| 136 if (kZero_GrBlendCoeff == fDstBlend) { | 149 if (kZero_GrBlendCoeff == fDstBlend) { |
| 137 // write the coverage value to second color | 150 // write the coverage value to second color |
| 138 fSecondaryOutputType = kCoverage_SecondaryOutputType; | 151 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverage_Second aryOutputType; |
| 139 *separateCoverageFromColor = true; | 152 *separateCoverageFromColor = true; |
| 140 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 153 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
| 141 } else if (kSA_GrBlendCoeff == fDstBlend) { | 154 } else if (kSA_GrBlendCoeff == fDstBlend) { |
| 142 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. | 155 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. |
| 143 fSecondaryOutputType = kCoverageISA_SecondaryOutputType; | 156 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISA_Sec ondaryOutputType; |
| 144 *separateCoverageFromColor = true; | 157 *separateCoverageFromColor = true; |
| 145 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 158 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
| 146 } else if (kSC_GrBlendCoeff == fDstBlend) { | 159 } else if (kSC_GrBlendCoeff == fDstBlend) { |
| 147 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. | 160 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. |
| 148 fSecondaryOutputType = kCoverageISC_SecondaryOutputType; | 161 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISC_Sec ondaryOutputType; |
| 149 *separateCoverageFromColor = true; | 162 *separateCoverageFromColor = true; |
| 150 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 163 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
| 151 } | 164 } |
| 152 } else if (fReadsDst && | 165 } else if (descInfo->fReadsDst && |
| 153 kOne_GrBlendCoeff == fSrcBlend && | 166 kOne_GrBlendCoeff == fSrcBlend && |
| 154 kZero_GrBlendCoeff == fDstBlend) { | 167 kZero_GrBlendCoeff == fDstBlend) { |
| 155 fPrimaryOutputType = kCombineWithDst_PrimaryOutputType; | 168 descInfo->fPrimaryOutputType = GrProgramDesc::kCombineWithDst_Primar yOutputType; |
| 156 *separateCoverageFromColor = true; | 169 *separateCoverageFromColor = true; |
| 157 } | 170 } |
| 158 } | 171 } |
| 159 } | 172 } |
| 160 | 173 |
| 161 void GrOptDrawState::adjustFromBlendOpts(const GrDrawState& ds, | 174 void GrOptDrawState::adjustFromBlendOpts(const GrDrawState& ds, |
| 175 GrProgramDesc::DescInfo* descInfo, | |
| 162 int* firstColorStageIdx, | 176 int* firstColorStageIdx, |
| 163 int* firstCoverageStageIdx, | 177 int* firstCoverageStageIdx, |
| 164 uint8_t* fixedFunctionVAToRemove) { | 178 uint8_t* fixedFunctionVAToRemove) { |
| 165 switch (fBlendOptFlags) { | 179 switch (fBlendOptFlags) { |
| 166 case kNone_BlendOpt: | 180 case kNone_BlendOpt: |
| 167 case kSkipDraw_BlendOptFlag: | 181 case kSkipDraw_BlendOptFlag: |
| 168 break; | 182 break; |
| 169 case kCoverageAsAlpha_BlendOptFlag: | 183 case kCoverageAsAlpha_BlendOptFlag: |
| 170 fFlagBits |= kCoverageDrawing_StateBit; | 184 fFlagBits |= kCoverageDrawing_StateBit; |
| 171 break; | 185 break; |
| 172 case kEmitCoverage_BlendOptFlag: | 186 case kEmitCoverage_BlendOptFlag: |
| 173 fColor = 0xffffffff; | 187 fColor = 0xffffffff; |
| 174 fInputColorIsUsed = true; | 188 descInfo->fInputColorIsUsed = true; |
| 175 *firstColorStageIdx = ds.numColorStages(); | 189 *firstColorStageIdx = ds.numColorStages(); |
| 176 *fixedFunctionVAToRemove |= 0x1 << kColor_GrVertexAttribBinding; | 190 *fixedFunctionVAToRemove |= 0x1 << kColor_GrVertexAttribBinding; |
| 177 break; | 191 break; |
| 178 case kEmitTransBlack_BlendOptFlag: | 192 case kEmitTransBlack_BlendOptFlag: |
| 179 fColor = 0; | 193 fColor = 0; |
| 180 fCoverage = 0xff; | 194 fCoverage = 0xff; |
| 181 fInputColorIsUsed = true; | 195 descInfo->fInputColorIsUsed = true; |
| 182 fInputCoverageIsUsed = true; | 196 descInfo->fInputCoverageIsUsed = true; |
| 183 *firstColorStageIdx = ds.numColorStages(); | 197 *firstColorStageIdx = ds.numColorStages(); |
| 184 *firstCoverageStageIdx = ds.numCoverageStages(); | 198 *firstCoverageStageIdx = ds.numCoverageStages(); |
| 185 *fixedFunctionVAToRemove |= (0x1 << kColor_GrVertexAttribBinding | | 199 *fixedFunctionVAToRemove |= (0x1 << kColor_GrVertexAttribBinding | |
| 186 0x1 << kCoverage_GrVertexAttribBinding) ; | 200 0x1 << kCoverage_GrVertexAttribBinding) ; |
| 187 break; | 201 break; |
| 188 default: | 202 default: |
| 189 SkFAIL("Unknown BlendOptFlag"); | 203 SkFAIL("Unknown BlendOptFlag"); |
| 190 } | 204 } |
| 191 } | 205 } |
| 192 | 206 |
| 193 void GrOptDrawState::removeFixedFunctionVertexAttribs(uint8_t removeVAFlag) { | 207 void GrOptDrawState::removeFixedFunctionVertexAttribs(uint8_t removeVAFlag, |
| 208 GrProgramDesc::DescInfo* d escInfo) { | |
| 194 int numToRemove = 0; | 209 int numToRemove = 0; |
| 195 uint8_t maskCheck = 0x1; | 210 uint8_t maskCheck = 0x1; |
| 196 // Count the number of vertex attributes that we will actually remove | 211 // Count the number of vertex attributes that we will actually remove |
| 197 for (int i = 0; i < kGrFixedFunctionVertexAttribBindingCnt; ++i) { | 212 for (int i = 0; i < kGrFixedFunctionVertexAttribBindingCnt; ++i) { |
| 198 if ((maskCheck & removeVAFlag) && -1 != fFixedFunctionVertexAttribIndice s[i]) { | 213 if ((maskCheck & removeVAFlag) && -1 != descInfo->fFixedFunctionVertexAt tribIndices[i]) { |
| 199 ++numToRemove; | 214 ++numToRemove; |
| 200 } | 215 } |
| 201 maskCheck <<= 1; | 216 maskCheck <<= 1; |
| 202 } | 217 } |
| 203 | 218 |
| 204 fOptVA.reset(fVACount - numToRemove); | 219 fOptVA.reset(fVACount - numToRemove); |
| 205 | 220 |
| 206 GrVertexAttrib* dst = fOptVA.get(); | 221 GrVertexAttrib* dst = fOptVA.get(); |
| 207 const GrVertexAttrib* src = fVAPtr; | 222 const GrVertexAttrib* src = fVAPtr; |
| 208 | 223 |
| 209 for (int i = 0, newIdx = 0; i < fVACount; ++i, ++src) { | 224 for (int i = 0, newIdx = 0; i < fVACount; ++i, ++src) { |
| 210 const GrVertexAttrib& currAttrib = *src; | 225 const GrVertexAttrib& currAttrib = *src; |
| 211 if (currAttrib.fBinding < kGrFixedFunctionVertexAttribBindingCnt) { | 226 if (currAttrib.fBinding < kGrFixedFunctionVertexAttribBindingCnt) { |
| 212 uint8_t maskCheck = 0x1 << currAttrib.fBinding; | 227 uint8_t maskCheck = 0x1 << currAttrib.fBinding; |
| 213 if (maskCheck & removeVAFlag) { | 228 if (maskCheck & removeVAFlag) { |
| 214 SkASSERT(-1 != fFixedFunctionVertexAttribIndices[currAttrib.fBin ding]); | 229 SkASSERT(-1 != descInfo->fFixedFunctionVertexAttribIndices[currA ttrib.fBinding]); |
| 215 fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = -1; | 230 descInfo->fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = -1; |
| 216 continue; | 231 continue; |
| 217 } | 232 } |
| 218 fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = newIdx; | 233 descInfo->fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = n ewIdx; |
| 219 } | 234 } |
| 220 memcpy(dst, src, sizeof(GrVertexAttrib)); | 235 memcpy(dst, src, sizeof(GrVertexAttrib)); |
| 221 ++newIdx; | 236 ++newIdx; |
| 222 ++dst; | 237 ++dst; |
| 223 } | 238 } |
| 224 fVACount -= numToRemove; | 239 fVACount -= numToRemove; |
| 225 fVAPtr = fOptVA.get(); | 240 fVAPtr = fOptVA.get(); |
| 226 } | 241 } |
| 227 | 242 |
| 228 void GrOptDrawState::computeEffectiveColorStages(const GrDrawState& ds, int* fir stColorStageIdx, | 243 void GrOptDrawState::computeEffectiveColorStages(const GrDrawState& ds, |
| 244 GrProgramDesc::DescInfo* descIn fo, | |
| 245 int* firstColorStageIdx, | |
| 229 uint8_t* fixedFunctionVAToRemov e) { | 246 uint8_t* fixedFunctionVAToRemov e) { |
| 230 // Set up color and flags for ConstantColorComponent checks | 247 // Set up color and flags for ConstantColorComponent checks |
| 231 GrProcessor::InvariantOutput inout; | 248 GrProcessor::InvariantOutput inout; |
| 232 inout.fIsSingleComponent = false; | 249 inout.fIsSingleComponent = false; |
| 233 if (!this->hasColorVertexAttribute()) { | 250 if (!descInfo->hasColorVertexAttribute()) { |
| 234 inout.fColor = ds.getColor(); | 251 inout.fColor = ds.getColor(); |
| 235 inout.fValidFlags = kRGBA_GrColorComponentFlags; | 252 inout.fValidFlags = kRGBA_GrColorComponentFlags; |
| 236 } else { | 253 } else { |
| 237 if (ds.vertexColorsAreOpaque()) { | 254 if (ds.vertexColorsAreOpaque()) { |
| 238 inout.fColor = 0xFF << GrColor_SHIFT_A; | 255 inout.fColor = 0xFF << GrColor_SHIFT_A; |
| 239 inout.fValidFlags = kA_GrColorComponentFlag; | 256 inout.fValidFlags = kA_GrColorComponentFlag; |
| 240 } else { | 257 } else { |
| 241 inout.fValidFlags = 0; | 258 inout.fValidFlags = 0; |
| 242 // not strictly necessary but we get false alarms from tools about u ninit. | 259 // not strictly necessary but we get false alarms from tools about u ninit. |
| 243 inout.fColor = 0; | 260 inout.fColor = 0; |
| 244 } | 261 } |
| 245 } | 262 } |
| 246 | 263 |
| 247 for (int i = 0; i < ds.numColorStages(); ++i) { | 264 for (int i = 0; i < ds.numColorStages(); ++i) { |
| 248 const GrFragmentProcessor* fp = ds.getColorStage(i).getProcessor(); | 265 const GrFragmentProcessor* fp = ds.getColorStage(i).getProcessor(); |
| 249 fp->computeInvariantOutput(&inout); | 266 fp->computeInvariantOutput(&inout); |
| 250 if (!inout.fWillUseInputColor) { | 267 if (!inout.fWillUseInputColor) { |
| 251 *firstColorStageIdx = i; | 268 *firstColorStageIdx = i; |
| 252 fInputColorIsUsed = false; | 269 descInfo->fInputColorIsUsed = false; |
| 253 } | 270 } |
| 254 if (kRGBA_GrColorComponentFlags == inout.fValidFlags) { | 271 if (kRGBA_GrColorComponentFlags == inout.fValidFlags) { |
| 255 *firstColorStageIdx = i + 1; | 272 *firstColorStageIdx = i + 1; |
| 256 fColor = inout.fColor; | 273 fColor = inout.fColor; |
| 257 fInputColorIsUsed = true; | 274 descInfo->fInputColorIsUsed = true; |
| 258 *fixedFunctionVAToRemove |= 0x1 << kColor_GrVertexAttribBinding; | 275 *fixedFunctionVAToRemove |= 0x1 << kColor_GrVertexAttribBinding; |
| 259 // Since we are clearing all previous color stages we are in a state where we have found | 276 // Since we are clearing all previous color stages we are in a state where we have found |
| 260 // zero stages that don't multiply the inputColor. | 277 // zero stages that don't multiply the inputColor. |
| 261 inout.fNonMulStageFound = false; | 278 inout.fNonMulStageFound = false; |
| 262 } | 279 } |
| 263 } | 280 } |
| 264 } | 281 } |
| 265 | 282 |
| 266 void GrOptDrawState::computeEffectiveCoverageStages(const GrDrawState& ds, | 283 void GrOptDrawState::computeEffectiveCoverageStages(const GrDrawState& ds, |
| 284 GrProgramDesc::DescInfo* des cInfo, | |
| 267 int* firstCoverageStageIdx) { | 285 int* firstCoverageStageIdx) { |
| 268 // We do not try to optimize out constantColor coverage effects here. It is extremely rare | 286 // We do not try to optimize out constantColor coverage effects here. It is extremely rare |
| 269 // to have a coverage effect that returns a constant value for all four chan nels. Thus we | 287 // to have a coverage effect that returns a constant value for all four chan nels. Thus we |
| 270 // save having to make extra virtual calls by not checking for it. | 288 // save having to make extra virtual calls by not checking for it. |
| 271 | 289 |
| 272 // Don't do any optimizations on coverage stages. It should not be the case where we do not use | 290 // Don't do any optimizations on coverage stages. It should not be the case where we do not use |
| 273 // input coverage in an effect | 291 // input coverage in an effect |
| 274 #ifdef OptCoverageStages | 292 #ifdef OptCoverageStages |
| 275 GrProcessor::InvariantOutput inout; | 293 GrProcessor::InvariantOutput inout; |
| 276 for (int i = 0; i < ds.numCoverageStages(); ++i) { | 294 for (int i = 0; i < ds.numCoverageStages(); ++i) { |
| 277 const GrFragmentProcessor* fp = ds.getCoverageStage(i).getProcessor(); | 295 const GrFragmentProcessor* fp = ds.getCoverageStage(i).getProcessor(); |
| 278 fp->computeInvariantOutput(&inout); | 296 fp->computeInvariantOutput(&inout); |
| 279 if (!inout.fWillUseInputColor) { | 297 if (!inout.fWillUseInputColor) { |
| 280 *firstCoverageStageIdx = i; | 298 *firstCoverageStageIdx = i; |
| 281 fInputCoverageIsUsed = false; | 299 descInfo->fInputCoverageIsUsed = false; |
| 282 } | 300 } |
| 283 } | 301 } |
| 284 #endif | 302 #endif |
| 285 } | 303 } |
| 286 | 304 |
| 287 static void get_stage_stats(const GrFragmentStage& stage, bool* readsDst, bool* readsFragPosition) { | 305 static void get_stage_stats(const GrFragmentStage& stage, bool* readsDst, bool* readsFragPosition) { |
| 288 if (stage.getProcessor()->willReadDstColor()) { | 306 if (stage.getProcessor()->willReadDstColor()) { |
| 289 *readsDst = true; | 307 *readsDst = true; |
| 290 } | 308 } |
| 291 if (stage.getProcessor()->willReadFragmentPosition()) { | 309 if (stage.getProcessor()->willReadFragmentPosition()) { |
| 292 *readsFragPosition = true; | 310 *readsFragPosition = true; |
| 293 } | 311 } |
| 294 } | 312 } |
| 295 | 313 |
| 296 void GrOptDrawState::getStageStats(const GrDrawState& ds, int firstColorStageIdx , | 314 void GrOptDrawState::getStageStats(const GrDrawState& ds, int firstColorStageIdx , |
| 297 int firstCoverageStageIdx) { | 315 int firstCoverageStageIdx, GrProgramDesc::Des cInfo* descInfo) { |
| 298 // We will need a local coord attrib if there is one currently set on the op tState and we are | 316 // We will need a local coord attrib if there is one currently set on the op tState and we are |
| 299 // actually generating some effect code | 317 // actually generating some effect code |
| 300 fRequiresLocalCoordAttrib = this->hasLocalCoordAttribute() && | 318 descInfo->fRequiresLocalCoordAttrib = descInfo->hasLocalCoordAttribute() && |
| 301 ds.numTotalStages() - firstColorStageIdx - firstCoverageStageIdx > 0; | 319 ds.numTotalStages() - firstColorStageIdx - firstCoverageStageIdx > 0; |
| 302 | 320 |
| 303 fReadsDst = false; | 321 descInfo->fReadsDst = false; |
| 304 fReadsFragPosition = false; | 322 descInfo->fReadsFragPosition = false; |
| 305 | 323 |
| 306 for (int s = firstColorStageIdx; s < ds.numColorStages(); ++s) { | 324 for (int s = firstColorStageIdx; s < ds.numColorStages(); ++s) { |
| 307 const GrFragmentStage& stage = ds.getColorStage(s); | 325 const GrFragmentStage& stage = ds.getColorStage(s); |
| 308 get_stage_stats(stage, &fReadsDst, &fReadsFragPosition); | 326 get_stage_stats(stage, &descInfo->fReadsDst, &descInfo->fReadsFragPositi on); |
| 309 } | 327 } |
| 310 for (int s = firstCoverageStageIdx; s < ds.numCoverageStages(); ++s) { | 328 for (int s = firstCoverageStageIdx; s < ds.numCoverageStages(); ++s) { |
| 311 const GrFragmentStage& stage = ds.getCoverageStage(s); | 329 const GrFragmentStage& stage = ds.getCoverageStage(s); |
| 312 get_stage_stats(stage, &fReadsDst, &fReadsFragPosition); | 330 get_stage_stats(stage, &descInfo->fReadsDst, &descInfo->fReadsFragPositi on); |
| 313 } | 331 } |
| 314 if (ds.hasGeometryProcessor()) { | 332 if (ds.hasGeometryProcessor()) { |
| 315 const GrGeometryProcessor& gp = *ds.getGeometryProcessor(); | 333 const GrGeometryProcessor& gp = *ds.getGeometryProcessor(); |
| 316 fReadsFragPosition = fReadsFragPosition || gp.willReadFragmentPosition() ; | 334 descInfo->fReadsFragPosition = descInfo->fReadsFragPosition || gp.willRe adFragmentPosition(); |
| 317 } | 335 } |
| 318 } | 336 } |
| 319 | 337 |
| 320 //////////////////////////////////////////////////////////////////////////////// | 338 //////////////////////////////////////////////////////////////////////////////// |
| 321 | 339 |
| 322 bool GrOptDrawState::operator== (const GrOptDrawState& that) const { | 340 bool GrOptDrawState::operator== (const GrOptDrawState& that) const { |
| 323 return this->isEqual(that); | 341 return this->isEqual(that); |
| 324 } | 342 } |
| 325 | 343 |
| 326 bool GrOptDrawState::isEqual(const GrOptDrawState& that) const { | 344 bool GrOptDrawState::isEqual(const GrOptDrawState& that) const { |
| 327 bool usingVertexColors = this->hasColorVertexAttribute(); | 345 if (this->fDesc != that.fDesc) { |
| 346 return false; | |
| 347 } | |
| 348 bool usingVertexColors = that.fDesc.header().fColorAttributeIndex != -1; | |
| 328 if (!usingVertexColors && this->fColor != that.fColor) { | 349 if (!usingVertexColors && this->fColor != that.fColor) { |
| 329 return false; | 350 return false; |
| 330 } | 351 } |
| 331 | 352 |
| 332 if (this->getRenderTarget() != that.getRenderTarget() || | 353 if (this->getRenderTarget() != that.getRenderTarget() || |
| 333 this->fFragmentStages.count() != that.fFragmentStages.count() || | |
| 334 this->fNumColorStages != that.fNumColorStages || | |
| 335 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || | 354 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || |
| 336 this->fSrcBlend != that.fSrcBlend || | 355 this->fSrcBlend != that.fSrcBlend || |
| 337 this->fDstBlend != that.fDstBlend || | 356 this->fDstBlend != that.fDstBlend || |
| 338 this->fBlendConstant != that.fBlendConstant || | 357 this->fBlendConstant != that.fBlendConstant || |
| 339 this->fFlagBits != that.fFlagBits || | 358 this->fFlagBits != that.fFlagBits || |
| 340 this->fVACount != that.fVACount || | 359 this->fVACount != that.fVACount || |
| 341 this->fVAStride != that.fVAStride || | 360 this->fVAStride != that.fVAStride || |
| 342 memcmp(this->fVAPtr, that.fVAPtr, this->fVACount * sizeof(GrVertexAttrib )) || | 361 memcmp(this->fVAPtr, that.fVAPtr, this->fVACount * sizeof(GrVertexAttrib )) || |
| 343 this->fStencilSettings != that.fStencilSettings || | 362 this->fStencilSettings != that.fStencilSettings || |
| 344 this->fDrawFace != that.fDrawFace || | 363 this->fDrawFace != that.fDrawFace) { |
| 345 this->fInputColorIsUsed != that.fInputColorIsUsed || | |
| 346 this->fInputCoverageIsUsed != that.fInputCoverageIsUsed || | |
| 347 this->fReadsDst != that.fReadsDst || | |
| 348 this->fReadsFragPosition != that.fReadsFragPosition || | |
| 349 this->fRequiresLocalCoordAttrib != that.fRequiresLocalCoordAttrib || | |
| 350 this->fPrimaryOutputType != that.fPrimaryOutputType || | |
| 351 this->fSecondaryOutputType != that.fSecondaryOutputType) { | |
| 352 return false; | 364 return false; |
| 353 } | 365 } |
| 354 | 366 |
| 355 bool usingVertexCoverage = this->hasCoverageVertexAttribute(); | 367 bool usingVertexCoverage = this->fDesc.header().fCoverageAttributeIndex != - 1; |
| 356 if (!usingVertexCoverage && this->fCoverage != that.fCoverage) { | 368 if (!usingVertexCoverage && this->fCoverage != that.fCoverage) { |
| 357 return false; | 369 return false; |
| 358 } | 370 } |
| 359 | 371 |
| 360 bool explicitLocalCoords = this->hasLocalCoordAttribute(); | |
| 361 if (this->hasGeometryProcessor()) { | 372 if (this->hasGeometryProcessor()) { |
| 362 if (!that.hasGeometryProcessor()) { | 373 if (!that.hasGeometryProcessor()) { |
| 363 return false; | 374 return false; |
| 364 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProce ssor())) { | 375 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProce ssor())) { |
| 365 return false; | 376 return false; |
| 366 } | 377 } |
| 367 } else if (that.hasGeometryProcessor()) { | 378 } else if (that.hasGeometryProcessor()) { |
| 368 return false; | 379 return false; |
| 369 } | 380 } |
| 370 | 381 |
| 382 bool explicitLocalCoords = this->fDesc.header().fLocalCoordAttributeIndex; | |
|
egdaniel
2014/10/24 14:59:30
should this be != -1?
joshualitt
2014/10/24 15:15:38
Acknowledged.
| |
| 371 for (int i = 0; i < this->numFragmentStages(); i++) { | 383 for (int i = 0; i < this->numFragmentStages(); i++) { |
| 372 if (!GrFragmentStage::AreCompatible(this->getFragmentStage(i), that.getF ragmentStage(i), | 384 if (!GrFragmentStage::AreCompatible(this->getFragmentStage(i), that.getF ragmentStage(i), |
| 373 explicitLocalCoords)) { | 385 explicitLocalCoords)) { |
| 374 return false; | 386 return false; |
| 375 } | 387 } |
| 376 } | 388 } |
| 377 | |
| 378 SkASSERT(0 == memcmp(this->fFixedFunctionVertexAttribIndices, | |
| 379 that.fFixedFunctionVertexAttribIndices, | |
| 380 sizeof(this->fFixedFunctionVertexAttribIndices))); | |
| 381 | |
| 382 return true; | 389 return true; |
| 383 } | 390 } |
| 384 | 391 |
| OLD | NEW |