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