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 | |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 10 | #include "GrDefaultGeoProcFactory.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 11 | #include "GrDrawState.h" |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 12 | #include "GrDrawTargetCaps.h" |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 13 | #include "GrGpu.h" |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 14 | #include "GrProcOptInfo.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 15 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 16 | GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 17 | GrGpu* gpu, |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 18 | const ScissorState& scissorState, |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 19 | const GrDeviceCoordTexture* dstCopy, |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 20 | GrGpu::DrawType drawType) { |
| 21 | |
| 22 | GrBlendCoeff optSrcCoeff; |
| 23 | GrBlendCoeff optDstCoeff; |
| 24 | GrDrawState::BlendOpt blendOpt = drawState.getBlendOpt(false, &optSrcCoeff, &optDstCoeff); |
| 25 | |
| 26 | // When path rendering the stencil settings are not always set on the draw state |
| 27 | // so we must check the draw type. In cases where we will skip drawing we simply return a |
| 28 | // null GrOptDrawState. |
| 29 | if (GrDrawState::kSkipDraw_BlendOpt == blendOpt && GrGpu::kStencilPath_DrawType != drawType) { |
| 30 | // Set the fields that don't default init and return. The lack of a render target will |
| 31 | // indicate that this can be skipped. |
| 32 | fFlags = 0; |
| 33 | fVAPtr = NULL; |
| 34 | fVACount = 0; |
| 35 | fVAStride = 0; |
| 36 | fDrawFace = GrDrawState::kInvalid_DrawFace; |
| 37 | fSrcBlend = kZero_GrBlendCoeff; |
| 38 | fDstBlend = kZero_GrBlendCoeff; |
| 39 | fBlendConstant = 0x0; |
| 40 | fViewMatrix.reset(); |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | fRenderTarget.reset(drawState.fRenderTarget.get()); |
| 45 | SkASSERT(fRenderTarget); |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 46 | fScissorState = scissorState; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 47 | fViewMatrix = drawState.getViewMatrix(); |
| 48 | fBlendConstant = drawState.getBlendConstant(); |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 49 | fVAPtr = drawState.getVertexAttribs(); |
| 50 | fVACount = drawState.getVertexAttribCount(); |
| 51 | fVAStride = drawState.getVertexStride(); |
| 52 | fStencilSettings = drawState.getStencil(); |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 53 | fDrawFace = drawState.getDrawFace(); |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 54 | fSrcBlend = optSrcCoeff; |
| 55 | fDstBlend = optDstCoeff; |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 56 | |
| 57 | // TODO move this out of optDrawState |
| 58 | if (dstCopy) { |
| 59 | fDstCopy = *dstCopy; |
| 60 | } |
| 61 | |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 62 | GrProgramDesc::DescInfo descInfo; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 63 | |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 64 | fFlags = 0; |
| 65 | if (drawState.isHWAntialias()) { |
| 66 | fFlags |= kHWAA_Flag; |
| 67 | } |
| 68 | if (drawState.isColorWriteDisabled()) { |
| 69 | fFlags |= kDisableColorWrite_Flag; |
| 70 | } |
| 71 | if (drawState.isDither()) { |
| 72 | fFlags |= kDither_Flag; |
| 73 | } |
| 74 | |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 75 | memcpy(descInfo.fFixedFunctionVertexAttribIndices, |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 76 | drawState.getFixedFunctionVertexAttribIndices(), |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 77 | sizeof(descInfo.fFixedFunctionVertexAttribIndices)); |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 78 | |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 79 | uint8_t fixedFunctionVAToRemove = 0; |
| 80 | |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 81 | const GrProcOptInfo& colorPOI = drawState.colorProcInfo(); |
| 82 | int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); |
| 83 | descInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed(); |
| 84 | fColor = colorPOI.inputColorToEffectiveStage(); |
| 85 | if (colorPOI.removeVertexAttrib()) { |
| 86 | fixedFunctionVAToRemove |= 0x1 << kColor_GrVertexAttribBinding; |
| 87 | } |
| 88 | |
| 89 | // TODO: Once we can handle single or four channel input into coverage stages then we can use |
| 90 | // drawState's coverageProcInfo (like color above) to set this initial information. |
| 91 | int firstCoverageStageIdx = 0; |
| 92 | descInfo.fInputCoverageIsUsed = true; |
| 93 | fCoverage = drawState.getCoverage(); |
| 94 | |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 95 | this->adjustProgramForBlendOpt(drawState, blendOpt, &descInfo, &firstColorStageIdx, |
| 96 | &firstCoverageStageIdx, &fixedFunctionVAToRemove); |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 97 | // Should not be setting any more FFVA to be removed at this point |
egdaniel | c0651c1 | 2014-10-21 07:47:10 -0700 | [diff] [blame] | 98 | if (0 != fixedFunctionVAToRemove) { |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 99 | this->removeFixedFunctionVertexAttribs(fixedFunctionVAToRemove, &descInfo); |
egdaniel | c0651c1 | 2014-10-21 07:47:10 -0700 | [diff] [blame] | 100 | } |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 101 | this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, &descInfo); |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 102 | |
| 103 | // Copy GeometryProcesssor from DS or ODS |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 104 | SkASSERT(GrGpu::IsPathRenderingDrawType(drawType) || |
| 105 | GrGpu::kStencilPath_DrawType || |
| 106 | drawState.hasGeometryProcessor()); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 107 | fGeometryProcessor.reset(drawState.getGeometryProcessor()); |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 108 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 109 | // Copy Stages from DS to ODS |
| 110 | bool explicitLocalCoords = descInfo.hasLocalCoordAttribute(); |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 111 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 112 | for (int i = firstColorStageIdx; i < drawState.numColorStages(); ++i) { |
| 113 | SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
| 114 | GrPendingFragmentStage, |
| 115 | (drawState.fColorStages[i], explicitLocalCoords)); |
| 116 | } |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 117 | fNumColorStages = fFragmentStages.count(); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 118 | for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i) { |
| 119 | SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
| 120 | GrPendingFragmentStage, |
| 121 | (drawState.fCoverageStages[i], explicitLocalCoords)); |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 122 | } |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 123 | |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 124 | this->setOutputStateInfo(drawState, blendOpt, *gpu->caps(), &descInfo); |
joshualitt | 4dd9988 | 2014-11-11 08:51:30 -0800 | [diff] [blame] | 125 | |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 126 | // now create a key |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 127 | gpu->buildProgramDesc(*this, descInfo, drawType, &fDesc); |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 128 | }; |
| 129 | |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 130 | void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 131 | GrDrawState::BlendOpt blendOpt, |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 132 | const GrDrawTargetCaps& caps, |
joshualitt | 4dd9988 | 2014-11-11 08:51:30 -0800 | [diff] [blame] | 133 | GrProgramDesc::DescInfo* descInfo) { |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 134 | // Set this default and then possibly change our mind if there is coverage. |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 135 | descInfo->fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; |
| 136 | descInfo->fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 137 | |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 138 | // Determine whether we should use dual source blending or shader code to keep coverage |
| 139 | // separate from color. |
| 140 | bool keepCoverageSeparate = !(GrDrawState::kCoverageAsAlpha_BlendOpt == blendOpt || |
| 141 | GrDrawState::kEmitCoverage_BlendOpt == blendOpt); |
| 142 | if (keepCoverageSeparate && !ds.hasSolidCoverage()) { |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 143 | if (caps.dualSourceBlendingSupport()) { |
| 144 | if (kZero_GrBlendCoeff == fDstBlend) { |
| 145 | // write the coverage value to second color |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 146 | descInfo->fSecondaryOutputType = GrProgramDesc::kCoverage_SecondaryOutputType; |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 147 | fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
| 148 | } else if (kSA_GrBlendCoeff == fDstBlend) { |
| 149 | // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 150 | descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISA_SecondaryOutputType; |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 151 | fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
| 152 | } else if (kSC_GrBlendCoeff == fDstBlend) { |
| 153 | // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 154 | descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISC_SecondaryOutputType; |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 155 | fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
| 156 | } |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 157 | } else if (descInfo->fReadsDst && |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 158 | kOne_GrBlendCoeff == fSrcBlend && |
| 159 | kZero_GrBlendCoeff == fDstBlend) { |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 160 | descInfo->fPrimaryOutputType = GrProgramDesc::kCombineWithDst_PrimaryOutputType; |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 161 | } |
| 162 | } |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 163 | } |
| 164 | |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 165 | void GrOptDrawState::adjustProgramForBlendOpt(const GrDrawState& ds, |
| 166 | GrDrawState::BlendOpt blendOpt, |
| 167 | GrProgramDesc::DescInfo* descInfo, |
| 168 | int* firstColorStageIdx, |
| 169 | int* firstCoverageStageIdx, |
| 170 | uint8_t* fixedFunctionVAToRemove) { |
| 171 | switch (blendOpt) { |
| 172 | case GrDrawState::kNone_BlendOpt: |
| 173 | case GrDrawState::kSkipDraw_BlendOpt: |
| 174 | case GrDrawState::kCoverageAsAlpha_BlendOpt: |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 175 | break; |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 176 | case GrDrawState::kEmitCoverage_BlendOpt: |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 177 | fColor = 0xffffffff; |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 178 | descInfo->fInputColorIsUsed = true; |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 179 | *firstColorStageIdx = ds.numColorStages(); |
| 180 | *fixedFunctionVAToRemove |= 0x1 << kColor_GrVertexAttribBinding; |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 181 | break; |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 182 | case GrDrawState::kEmitTransBlack_BlendOpt: |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 183 | fColor = 0; |
| 184 | fCoverage = 0xff; |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 185 | descInfo->fInputColorIsUsed = true; |
| 186 | descInfo->fInputCoverageIsUsed = true; |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 187 | *firstColorStageIdx = ds.numColorStages(); |
| 188 | *firstCoverageStageIdx = ds.numCoverageStages(); |
| 189 | *fixedFunctionVAToRemove |= (0x1 << kColor_GrVertexAttribBinding | |
| 190 | 0x1 << kCoverage_GrVertexAttribBinding); |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 191 | break; |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 195 | void GrOptDrawState::removeFixedFunctionVertexAttribs(uint8_t removeVAFlag, |
| 196 | GrProgramDesc::DescInfo* descInfo) { |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 197 | int numToRemove = 0; |
| 198 | uint8_t maskCheck = 0x1; |
| 199 | // Count the number of vertex attributes that we will actually remove |
| 200 | for (int i = 0; i < kGrFixedFunctionVertexAttribBindingCnt; ++i) { |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 201 | if ((maskCheck & removeVAFlag) && -1 != descInfo->fFixedFunctionVertexAttribIndices[i]) { |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 202 | ++numToRemove; |
| 203 | } |
| 204 | maskCheck <<= 1; |
| 205 | } |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 206 | |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 207 | fOptVA.reset(fVACount - numToRemove); |
| 208 | |
| 209 | GrVertexAttrib* dst = fOptVA.get(); |
| 210 | const GrVertexAttrib* src = fVAPtr; |
| 211 | |
| 212 | for (int i = 0, newIdx = 0; i < fVACount; ++i, ++src) { |
| 213 | const GrVertexAttrib& currAttrib = *src; |
| 214 | if (currAttrib.fBinding < kGrFixedFunctionVertexAttribBindingCnt) { |
| 215 | uint8_t maskCheck = 0x1 << currAttrib.fBinding; |
| 216 | if (maskCheck & removeVAFlag) { |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 217 | SkASSERT(-1 != descInfo->fFixedFunctionVertexAttribIndices[currAttrib.fBinding]); |
| 218 | descInfo->fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = -1; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 219 | continue; |
| 220 | } |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 221 | descInfo->fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = newIdx; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 222 | } |
| 223 | memcpy(dst, src, sizeof(GrVertexAttrib)); |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 224 | ++newIdx; |
| 225 | ++dst; |
| 226 | } |
| 227 | fVACount -= numToRemove; |
| 228 | fVAPtr = fOptVA.get(); |
| 229 | } |
| 230 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 231 | static void get_stage_stats(const GrFragmentStage& stage, bool* readsDst, bool* readsFragPosition) { |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 232 | if (stage.getProcessor()->willReadDstColor()) { |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 233 | *readsDst = true; |
| 234 | } |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 235 | if (stage.getProcessor()->willReadFragmentPosition()) { |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 236 | *readsFragPosition = true; |
| 237 | } |
| 238 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 239 | |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 240 | void GrOptDrawState::getStageStats(const GrDrawState& ds, int firstColorStageIdx, |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 241 | int firstCoverageStageIdx, GrProgramDesc::DescInfo* descInfo) { |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 242 | // We will need a local coord attrib if there is one currently set on the optState and we are |
| 243 | // actually generating some effect code |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 244 | descInfo->fRequiresLocalCoordAttrib = descInfo->hasLocalCoordAttribute() && |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 245 | ds.numTotalStages() - firstColorStageIdx - firstCoverageStageIdx > 0; |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 246 | |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 247 | descInfo->fReadsDst = false; |
| 248 | descInfo->fReadsFragPosition = false; |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 249 | |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 250 | for (int s = firstColorStageIdx; s < ds.numColorStages(); ++s) { |
| 251 | const GrFragmentStage& stage = ds.getColorStage(s); |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 252 | get_stage_stats(stage, &descInfo->fReadsDst, &descInfo->fReadsFragPosition); |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 253 | } |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 254 | for (int s = firstCoverageStageIdx; s < ds.numCoverageStages(); ++s) { |
| 255 | const GrFragmentStage& stage = ds.getCoverageStage(s); |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 256 | get_stage_stats(stage, &descInfo->fReadsDst, &descInfo->fReadsFragPosition); |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 257 | } |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 258 | if (ds.hasGeometryProcessor()) { |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 259 | const GrGeometryProcessor& gp = *ds.getGeometryProcessor(); |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 260 | descInfo->fReadsFragPosition = descInfo->fReadsFragPosition || gp.willReadFragmentPosition(); |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 264 | //////////////////////////////////////////////////////////////////////////////// |
| 265 | |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 266 | bool GrOptDrawState::operator== (const GrOptDrawState& that) const { |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 267 | if (this->fDesc != that.fDesc) { |
| 268 | return false; |
| 269 | } |
| 270 | bool usingVertexColors = that.fDesc.header().fColorAttributeIndex != -1; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 271 | if (!usingVertexColors && this->fColor != that.fColor) { |
| 272 | return false; |
| 273 | } |
| 274 | |
| 275 | if (this->getRenderTarget() != that.getRenderTarget() || |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 276 | this->fScissorState != that.fScissorState || |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 277 | !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || |
| 278 | this->fSrcBlend != that.fSrcBlend || |
| 279 | this->fDstBlend != that.fDstBlend || |
| 280 | this->fBlendConstant != that.fBlendConstant || |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 281 | this->fFlags != that.fFlags || |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 282 | this->fVACount != that.fVACount || |
| 283 | this->fVAStride != that.fVAStride || |
| 284 | memcmp(this->fVAPtr, that.fVAPtr, this->fVACount * sizeof(GrVertexAttrib)) || |
| 285 | this->fStencilSettings != that.fStencilSettings || |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 286 | this->fDrawFace != that.fDrawFace || |
| 287 | this->fDstCopy.texture() != that.fDstCopy.texture()) { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 288 | return false; |
| 289 | } |
| 290 | |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 291 | bool usingVertexCoverage = this->fDesc.header().fCoverageAttributeIndex != -1; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 292 | if (!usingVertexCoverage && this->fCoverage != that.fCoverage) { |
| 293 | return false; |
| 294 | } |
| 295 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 296 | if (this->hasGeometryProcessor()) { |
| 297 | if (!that.hasGeometryProcessor()) { |
| 298 | return false; |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 299 | } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProcessor())) { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 300 | return false; |
| 301 | } |
| 302 | } else if (that.hasGeometryProcessor()) { |
| 303 | return false; |
| 304 | } |
| 305 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 306 | // The program desc comparison should have already assured that the stage counts match. |
| 307 | SkASSERT(this->numFragmentStages() == that.numFragmentStages()); |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 308 | for (int i = 0; i < this->numFragmentStages(); i++) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 309 | |
| 310 | if (this->getFragmentStage(i) != that.getFragmentStage(i)) { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 311 | return false; |
| 312 | } |
| 313 | } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 314 | return true; |
| 315 | } |
| 316 | |