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