blob: a9d8ec48881c1fc77c7d8f6b86bd2f1e72e75f65 [file] [log] [blame]
egdaniel3658f382014-09-15 07:01:59 -07001/*
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
joshualitt4973d9d2014-11-08 09:24:25 -080010#include "GrDefaultGeoProcFactory.h"
egdaniel3658f382014-09-15 07:01:59 -070011#include "GrDrawState.h"
egdanielc0648242014-09-22 13:17:02 -070012#include "GrDrawTargetCaps.h"
joshualitt4973d9d2014-11-08 09:24:25 -080013#include "GrGpu.h"
egdaniel3658f382014-09-15 07:01:59 -070014
egdaniel170f90b2014-09-16 12:54:40 -070015GrOptDrawState::GrOptDrawState(const GrDrawState& drawState,
16 BlendOptFlags blendOptFlags,
17 GrBlendCoeff optSrcCoeff,
egdanielc0648242014-09-22 13:17:02 -070018 GrBlendCoeff optDstCoeff,
joshualitt79f8fae2014-10-28 17:59:26 -070019 GrGpu* gpu,
20 const GrDeviceCoordTexture* dstCopy,
21 GrGpu::DrawType drawType) {
bsalomonbcf0a522014-10-08 08:40:09 -070022 fRenderTarget.set(SkSafeRef(drawState.getRenderTarget()), kWrite_GrIOType);
egdaniel3658f382014-09-15 07:01:59 -070023 fColor = drawState.getColor();
24 fCoverage = drawState.getCoverage();
25 fViewMatrix = drawState.getViewMatrix();
26 fBlendConstant = drawState.getBlendConstant();
27 fFlagBits = drawState.getFlagBits();
28 fVAPtr = drawState.getVertexAttribs();
29 fVACount = drawState.getVertexAttribCount();
30 fVAStride = drawState.getVertexStride();
31 fStencilSettings = drawState.getStencil();
egdaniel89af44a2014-09-26 06:15:04 -070032 fDrawFace = (DrawFace)drawState.getDrawFace();
egdaniel170f90b2014-09-16 12:54:40 -070033 fBlendOptFlags = blendOptFlags;
34 fSrcBlend = optSrcCoeff;
35 fDstBlend = optDstCoeff;
joshualitt79f8fae2014-10-28 17:59:26 -070036 GrProgramDesc::DescInfo descInfo;
egdaniel3658f382014-09-15 07:01:59 -070037
joshualitt79f8fae2014-10-28 17:59:26 -070038 memcpy(descInfo.fFixedFunctionVertexAttribIndices,
egdaniel89af44a2014-09-26 06:15:04 -070039 drawState.getFixedFunctionVertexAttribIndices(),
joshualitt79f8fae2014-10-28 17:59:26 -070040 sizeof(descInfo.fFixedFunctionVertexAttribIndices));
egdaniel3658f382014-09-15 07:01:59 -070041
joshualitt79f8fae2014-10-28 17:59:26 -070042 descInfo.fInputColorIsUsed = true;
43 descInfo.fInputCoverageIsUsed = true;
egdaniel3658f382014-09-15 07:01:59 -070044
egdaniel9cf45bf2014-10-08 06:49:10 -070045 int firstColorStageIdx = 0;
46 int firstCoverageStageIdx = 0;
47 bool separateCoverageFromColor;
48
49 uint8_t fixedFunctionVAToRemove = 0;
50
joshualitt79f8fae2014-10-28 17:59:26 -070051 this->computeEffectiveColorStages(drawState, &descInfo, &firstColorStageIdx,
52 &fixedFunctionVAToRemove);
53 this->computeEffectiveCoverageStages(drawState, &descInfo, &firstCoverageStageIdx);
54 this->adjustFromBlendOpts(drawState, &descInfo, &firstColorStageIdx, &firstCoverageStageIdx,
egdaniel9cf45bf2014-10-08 06:49:10 -070055 &fixedFunctionVAToRemove);
56 // Should not be setting any more FFVA to be removed at this point
egdanielc0651c12014-10-21 07:47:10 -070057 if (0 != fixedFunctionVAToRemove) {
joshualitt79f8fae2014-10-28 17:59:26 -070058 this->removeFixedFunctionVertexAttribs(fixedFunctionVAToRemove, &descInfo);
egdanielc0651c12014-10-21 07:47:10 -070059 }
joshualitt79f8fae2014-10-28 17:59:26 -070060 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, &descInfo);
61 this->setOutputStateInfo(drawState, *gpu->caps(), firstCoverageStageIdx, &descInfo,
62 &separateCoverageFromColor);
egdaniel9cf45bf2014-10-08 06:49:10 -070063
64 // Copy GeometryProcesssor from DS or ODS
egdaniel3658f382014-09-15 07:01:59 -070065 if (drawState.hasGeometryProcessor()) {
joshualitta5305a12014-10-10 17:47:00 -070066 fGeometryProcessor.initAndRef(drawState.fGeometryProcessor);
joshualitt4973d9d2014-11-08 09:24:25 -080067 } else if (!GrGpu::IsPathRenderingDrawType(drawType)) {
68 // Install default GP, this will be ignored if we are rendering with fragment shader only
69 // TODO(joshualitt) rendering code should do this
70 fGeometryProcessor.reset(GrDefaultGeoProcFactory::Create());
egdaniel3658f382014-09-15 07:01:59 -070071 } else {
72 fGeometryProcessor.reset(NULL);
73 }
74
egdaniel9cf45bf2014-10-08 06:49:10 -070075 // Copy Color Stages from DS to ODS
76 if (firstColorStageIdx < drawState.numColorStages()) {
egdanield9aa2182014-10-09 13:47:05 -070077 fFragmentStages.reset(&drawState.getColorStage(firstColorStageIdx),
78 drawState.numColorStages() - firstColorStageIdx);
egdaniel9cf45bf2014-10-08 06:49:10 -070079 } else {
egdanield9aa2182014-10-09 13:47:05 -070080 fFragmentStages.reset();
egdaniel9cf45bf2014-10-08 06:49:10 -070081 }
82
egdanield9aa2182014-10-09 13:47:05 -070083 fNumColorStages = fFragmentStages.count();
84
egdaniel9cf45bf2014-10-08 06:49:10 -070085 // Copy Coverage Stages from DS to ODS
egdanield9aa2182014-10-09 13:47:05 -070086 if (firstCoverageStageIdx < drawState.numCoverageStages()) {
87 fFragmentStages.push_back_n(drawState.numCoverageStages() - firstCoverageStageIdx,
88 &drawState.getCoverageStage(firstCoverageStageIdx));
89 if (!separateCoverageFromColor) {
90 fNumColorStages = fFragmentStages.count();
egdaniel9cf45bf2014-10-08 06:49:10 -070091 }
92 }
joshualitt79f8fae2014-10-28 17:59:26 -070093
94 // now create a key
95 gpu->buildProgramDesc(*this, descInfo, drawType, dstCopy, &fDesc);
egdaniel3658f382014-09-15 07:01:59 -070096};
97
joshualitt79f8fae2014-10-28 17:59:26 -070098GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState,
99 GrGpu* gpu,
100 const GrDeviceCoordTexture* dstCopy,
egdanielb109ac22014-10-07 06:45:44 -0700101 GrGpu::DrawType drawType) {
joshualitt79f8fae2014-10-28 17:59:26 -0700102 const GrDrawTargetCaps& caps = *gpu->caps();
egdanielb109ac22014-10-07 06:45:44 -0700103 if (NULL == drawState.fCachedOptState || caps.getUniqueID() != drawState.fCachedCapsID) {
104 GrBlendCoeff srcCoeff;
105 GrBlendCoeff dstCoeff;
106 BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false,
107 &srcCoeff,
108 &dstCoeff);
109
110 // If our blend coeffs are set to 0,1 we know we will not end up drawing unless we are
111 // stenciling. When path rendering the stencil settings are not always set on the draw state
112 // so we must check the draw type. In cases where we will skip drawing we simply return a
113 // null GrOptDrawState.
114 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff &&
115 !drawState.getStencil().doesWrite() && GrGpu::kStencilPath_DrawType != drawType) {
116 return NULL;
117 }
118
119 drawState.fCachedOptState = SkNEW_ARGS(GrOptDrawState, (drawState, blendFlags, srcCoeff,
joshualitt79f8fae2014-10-28 17:59:26 -0700120 dstCoeff, gpu, dstCopy, drawType));
egdanielb109ac22014-10-07 06:45:44 -0700121 drawState.fCachedCapsID = caps.getUniqueID();
122 } else {
123#ifdef SK_DEBUG
124 GrBlendCoeff srcCoeff;
125 GrBlendCoeff dstCoeff;
126 BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false,
127 &srcCoeff,
128 &dstCoeff);
joshualitt79f8fae2014-10-28 17:59:26 -0700129 SkASSERT(GrOptDrawState(drawState, blendFlags, srcCoeff, dstCoeff, gpu, dstCopy,
130 drawType) == *drawState.fCachedOptState);
egdanielb109ac22014-10-07 06:45:44 -0700131#endif
132 }
133 drawState.fCachedOptState->ref();
134 return drawState.fCachedOptState;
135}
136
egdaniel9cf45bf2014-10-08 06:49:10 -0700137void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds,
138 const GrDrawTargetCaps& caps,
139 int firstCoverageStageIdx,
joshualitt79f8fae2014-10-28 17:59:26 -0700140 GrProgramDesc::DescInfo* descInfo,
egdaniel9cf45bf2014-10-08 06:49:10 -0700141 bool* separateCoverageFromColor) {
egdanielc0648242014-09-22 13:17:02 -0700142 // Set this default and then possibly change our mind if there is coverage.
joshualitt79f8fae2014-10-28 17:59:26 -0700143 descInfo->fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType;
144 descInfo->fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType;
egdanielc0648242014-09-22 13:17:02 -0700145
146 // If we do have coverage determine whether it matters.
egdaniel9cf45bf2014-10-08 06:49:10 -0700147 *separateCoverageFromColor = this->hasGeometryProcessor();
egdanielc0648242014-09-22 13:17:02 -0700148 if (!this->isCoverageDrawing() &&
egdaniel9cf45bf2014-10-08 06:49:10 -0700149 (ds.numCoverageStages() - firstCoverageStageIdx > 0 ||
150 ds.hasGeometryProcessor() ||
joshualitt79f8fae2014-10-28 17:59:26 -0700151 descInfo->hasCoverageVertexAttribute())) {
egdanielc0648242014-09-22 13:17:02 -0700152
153 if (caps.dualSourceBlendingSupport()) {
154 if (kZero_GrBlendCoeff == fDstBlend) {
155 // write the coverage value to second color
joshualitt79f8fae2014-10-28 17:59:26 -0700156 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverage_SecondaryOutputType;
egdaniel9cf45bf2014-10-08 06:49:10 -0700157 *separateCoverageFromColor = true;
egdanielc0648242014-09-22 13:17:02 -0700158 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
159 } else if (kSA_GrBlendCoeff == fDstBlend) {
160 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered.
joshualitt79f8fae2014-10-28 17:59:26 -0700161 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISA_SecondaryOutputType;
egdaniel9cf45bf2014-10-08 06:49:10 -0700162 *separateCoverageFromColor = true;
egdanielc0648242014-09-22 13:17:02 -0700163 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
164 } else if (kSC_GrBlendCoeff == fDstBlend) {
165 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered.
joshualitt79f8fae2014-10-28 17:59:26 -0700166 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISC_SecondaryOutputType;
egdaniel9cf45bf2014-10-08 06:49:10 -0700167 *separateCoverageFromColor = true;
egdanielc0648242014-09-22 13:17:02 -0700168 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
169 }
joshualitt79f8fae2014-10-28 17:59:26 -0700170 } else if (descInfo->fReadsDst &&
egdanielc0648242014-09-22 13:17:02 -0700171 kOne_GrBlendCoeff == fSrcBlend &&
172 kZero_GrBlendCoeff == fDstBlend) {
joshualitt79f8fae2014-10-28 17:59:26 -0700173 descInfo->fPrimaryOutputType = GrProgramDesc::kCombineWithDst_PrimaryOutputType;
egdaniel9cf45bf2014-10-08 06:49:10 -0700174 *separateCoverageFromColor = true;
egdanielc0648242014-09-22 13:17:02 -0700175 }
176 }
egdanielc0648242014-09-22 13:17:02 -0700177}
178
egdaniel9cf45bf2014-10-08 06:49:10 -0700179void GrOptDrawState::adjustFromBlendOpts(const GrDrawState& ds,
joshualitt79f8fae2014-10-28 17:59:26 -0700180 GrProgramDesc::DescInfo* descInfo,
egdaniel9cf45bf2014-10-08 06:49:10 -0700181 int* firstColorStageIdx,
182 int* firstCoverageStageIdx,
183 uint8_t* fixedFunctionVAToRemove) {
egdaniel170f90b2014-09-16 12:54:40 -0700184 switch (fBlendOptFlags) {
185 case kNone_BlendOpt:
186 case kSkipDraw_BlendOptFlag:
187 break;
188 case kCoverageAsAlpha_BlendOptFlag:
189 fFlagBits |= kCoverageDrawing_StateBit;
190 break;
191 case kEmitCoverage_BlendOptFlag:
192 fColor = 0xffffffff;
joshualitt79f8fae2014-10-28 17:59:26 -0700193 descInfo->fInputColorIsUsed = true;
egdaniel9cf45bf2014-10-08 06:49:10 -0700194 *firstColorStageIdx = ds.numColorStages();
195 *fixedFunctionVAToRemove |= 0x1 << kColor_GrVertexAttribBinding;
egdaniel170f90b2014-09-16 12:54:40 -0700196 break;
197 case kEmitTransBlack_BlendOptFlag:
198 fColor = 0;
199 fCoverage = 0xff;
joshualitt79f8fae2014-10-28 17:59:26 -0700200 descInfo->fInputColorIsUsed = true;
201 descInfo->fInputCoverageIsUsed = true;
egdaniel9cf45bf2014-10-08 06:49:10 -0700202 *firstColorStageIdx = ds.numColorStages();
203 *firstCoverageStageIdx = ds.numCoverageStages();
204 *fixedFunctionVAToRemove |= (0x1 << kColor_GrVertexAttribBinding |
205 0x1 << kCoverage_GrVertexAttribBinding);
egdaniel170f90b2014-09-16 12:54:40 -0700206 break;
207 default:
208 SkFAIL("Unknown BlendOptFlag");
egdaniel170f90b2014-09-16 12:54:40 -0700209 }
210}
211
joshualitt79f8fae2014-10-28 17:59:26 -0700212void GrOptDrawState::removeFixedFunctionVertexAttribs(uint8_t removeVAFlag,
213 GrProgramDesc::DescInfo* descInfo) {
egdaniel3658f382014-09-15 07:01:59 -0700214 int numToRemove = 0;
215 uint8_t maskCheck = 0x1;
216 // Count the number of vertex attributes that we will actually remove
217 for (int i = 0; i < kGrFixedFunctionVertexAttribBindingCnt; ++i) {
joshualitt79f8fae2014-10-28 17:59:26 -0700218 if ((maskCheck & removeVAFlag) && -1 != descInfo->fFixedFunctionVertexAttribIndices[i]) {
egdaniel3658f382014-09-15 07:01:59 -0700219 ++numToRemove;
220 }
221 maskCheck <<= 1;
222 }
egdaniel170f90b2014-09-16 12:54:40 -0700223
egdaniel3658f382014-09-15 07:01:59 -0700224 fOptVA.reset(fVACount - numToRemove);
225
226 GrVertexAttrib* dst = fOptVA.get();
227 const GrVertexAttrib* src = fVAPtr;
228
229 for (int i = 0, newIdx = 0; i < fVACount; ++i, ++src) {
230 const GrVertexAttrib& currAttrib = *src;
231 if (currAttrib.fBinding < kGrFixedFunctionVertexAttribBindingCnt) {
232 uint8_t maskCheck = 0x1 << currAttrib.fBinding;
233 if (maskCheck & removeVAFlag) {
joshualitt79f8fae2014-10-28 17:59:26 -0700234 SkASSERT(-1 != descInfo->fFixedFunctionVertexAttribIndices[currAttrib.fBinding]);
235 descInfo->fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = -1;
egdaniel3658f382014-09-15 07:01:59 -0700236 continue;
237 }
joshualitt79f8fae2014-10-28 17:59:26 -0700238 descInfo->fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = newIdx;
egdaniel3658f382014-09-15 07:01:59 -0700239 }
240 memcpy(dst, src, sizeof(GrVertexAttrib));
egdaniel3658f382014-09-15 07:01:59 -0700241 ++newIdx;
242 ++dst;
243 }
244 fVACount -= numToRemove;
245 fVAPtr = fOptVA.get();
246}
247
joshualitt79f8fae2014-10-28 17:59:26 -0700248void GrOptDrawState::computeEffectiveColorStages(const GrDrawState& ds,
249 GrProgramDesc::DescInfo* descInfo,
250 int* firstColorStageIdx,
egdaniel9cf45bf2014-10-08 06:49:10 -0700251 uint8_t* fixedFunctionVAToRemove) {
egdaniel3658f382014-09-15 07:01:59 -0700252 // Set up color and flags for ConstantColorComponent checks
egdaniel1a8ecdf2014-10-03 06:24:12 -0700253 GrProcessor::InvariantOutput inout;
254 inout.fIsSingleComponent = false;
joshualitt79f8fae2014-10-28 17:59:26 -0700255 if (!descInfo->hasColorVertexAttribute()) {
egdaniel1a8ecdf2014-10-03 06:24:12 -0700256 inout.fColor = ds.getColor();
257 inout.fValidFlags = kRGBA_GrColorComponentFlags;
egdaniel3658f382014-09-15 07:01:59 -0700258 } else {
259 if (ds.vertexColorsAreOpaque()) {
egdaniel1a8ecdf2014-10-03 06:24:12 -0700260 inout.fColor = 0xFF << GrColor_SHIFT_A;
261 inout.fValidFlags = kA_GrColorComponentFlag;
egdaniel3658f382014-09-15 07:01:59 -0700262 } else {
egdaniel1a8ecdf2014-10-03 06:24:12 -0700263 inout.fValidFlags = 0;
264 // not strictly necessary but we get false alarms from tools about uninit.
265 inout.fColor = 0;
egdaniel3658f382014-09-15 07:01:59 -0700266 }
267 }
268
269 for (int i = 0; i < ds.numColorStages(); ++i) {
joshualitt47bb3822014-10-07 16:43:25 -0700270 const GrFragmentProcessor* fp = ds.getColorStage(i).getProcessor();
egdaniel9e4d6d12014-10-15 13:49:02 -0700271 fp->computeInvariantOutput(&inout);
272 if (!inout.fWillUseInputColor) {
egdaniel9cf45bf2014-10-08 06:49:10 -0700273 *firstColorStageIdx = i;
joshualitt79f8fae2014-10-28 17:59:26 -0700274 descInfo->fInputColorIsUsed = false;
egdaniel3658f382014-09-15 07:01:59 -0700275 }
egdaniel1a8ecdf2014-10-03 06:24:12 -0700276 if (kRGBA_GrColorComponentFlags == inout.fValidFlags) {
egdaniel9cf45bf2014-10-08 06:49:10 -0700277 *firstColorStageIdx = i + 1;
egdaniel1a8ecdf2014-10-03 06:24:12 -0700278 fColor = inout.fColor;
joshualitt79f8fae2014-10-28 17:59:26 -0700279 descInfo->fInputColorIsUsed = true;
egdaniel9cf45bf2014-10-08 06:49:10 -0700280 *fixedFunctionVAToRemove |= 0x1 << kColor_GrVertexAttribBinding;
egdaniel9e4d6d12014-10-15 13:49:02 -0700281 // Since we are clearing all previous color stages we are in a state where we have found
282 // zero stages that don't multiply the inputColor.
283 inout.fNonMulStageFound = false;
egdaniel3658f382014-09-15 07:01:59 -0700284 }
285 }
egdaniel3658f382014-09-15 07:01:59 -0700286}
287
egdaniel9cf45bf2014-10-08 06:49:10 -0700288void GrOptDrawState::computeEffectiveCoverageStages(const GrDrawState& ds,
joshualitt79f8fae2014-10-28 17:59:26 -0700289 GrProgramDesc::DescInfo* descInfo,
egdaniel9cf45bf2014-10-08 06:49:10 -0700290 int* firstCoverageStageIdx) {
egdaniel3658f382014-09-15 07:01:59 -0700291 // We do not try to optimize out constantColor coverage effects here. It is extremely rare
292 // to have a coverage effect that returns a constant value for all four channels. Thus we
293 // save having to make extra virtual calls by not checking for it.
294
295 // Don't do any optimizations on coverage stages. It should not be the case where we do not use
296 // input coverage in an effect
297#ifdef OptCoverageStages
egdaniel9e4d6d12014-10-15 13:49:02 -0700298 GrProcessor::InvariantOutput inout;
egdaniel3658f382014-09-15 07:01:59 -0700299 for (int i = 0; i < ds.numCoverageStages(); ++i) {
egdaniel9e4d6d12014-10-15 13:49:02 -0700300 const GrFragmentProcessor* fp = ds.getCoverageStage(i).getProcessor();
301 fp->computeInvariantOutput(&inout);
302 if (!inout.fWillUseInputColor) {
egdaniel9cf45bf2014-10-08 06:49:10 -0700303 *firstCoverageStageIdx = i;
joshualitt79f8fae2014-10-28 17:59:26 -0700304 descInfo->fInputCoverageIsUsed = false;
egdaniel3658f382014-09-15 07:01:59 -0700305 }
306 }
307#endif
egdaniel3658f382014-09-15 07:01:59 -0700308}
309
joshualittb0a8a372014-09-23 09:50:21 -0700310static void get_stage_stats(const GrFragmentStage& stage, bool* readsDst, bool* readsFragPosition) {
joshualitt47bb3822014-10-07 16:43:25 -0700311 if (stage.getProcessor()->willReadDstColor()) {
egdaniela7dc0a82014-09-17 08:25:05 -0700312 *readsDst = true;
313 }
joshualitt47bb3822014-10-07 16:43:25 -0700314 if (stage.getProcessor()->willReadFragmentPosition()) {
egdaniela7dc0a82014-09-17 08:25:05 -0700315 *readsFragPosition = true;
316 }
317}
joshualittb0a8a372014-09-23 09:50:21 -0700318
egdaniel9cf45bf2014-10-08 06:49:10 -0700319void GrOptDrawState::getStageStats(const GrDrawState& ds, int firstColorStageIdx,
joshualitt79f8fae2014-10-28 17:59:26 -0700320 int firstCoverageStageIdx, GrProgramDesc::DescInfo* descInfo) {
egdaniela7dc0a82014-09-17 08:25:05 -0700321 // We will need a local coord attrib if there is one currently set on the optState and we are
322 // actually generating some effect code
joshualitt79f8fae2014-10-28 17:59:26 -0700323 descInfo->fRequiresLocalCoordAttrib = descInfo->hasLocalCoordAttribute() &&
egdaniel9cf45bf2014-10-08 06:49:10 -0700324 ds.numTotalStages() - firstColorStageIdx - firstCoverageStageIdx > 0;
egdaniela7dc0a82014-09-17 08:25:05 -0700325
joshualitt79f8fae2014-10-28 17:59:26 -0700326 descInfo->fReadsDst = false;
327 descInfo->fReadsFragPosition = false;
egdaniela7dc0a82014-09-17 08:25:05 -0700328
egdaniel9cf45bf2014-10-08 06:49:10 -0700329 for (int s = firstColorStageIdx; s < ds.numColorStages(); ++s) {
330 const GrFragmentStage& stage = ds.getColorStage(s);
joshualitt79f8fae2014-10-28 17:59:26 -0700331 get_stage_stats(stage, &descInfo->fReadsDst, &descInfo->fReadsFragPosition);
egdaniela7dc0a82014-09-17 08:25:05 -0700332 }
egdaniel9cf45bf2014-10-08 06:49:10 -0700333 for (int s = firstCoverageStageIdx; s < ds.numCoverageStages(); ++s) {
334 const GrFragmentStage& stage = ds.getCoverageStage(s);
joshualitt79f8fae2014-10-28 17:59:26 -0700335 get_stage_stats(stage, &descInfo->fReadsDst, &descInfo->fReadsFragPosition);
egdaniela7dc0a82014-09-17 08:25:05 -0700336 }
egdaniel9cf45bf2014-10-08 06:49:10 -0700337 if (ds.hasGeometryProcessor()) {
joshualitta5305a12014-10-10 17:47:00 -0700338 const GrGeometryProcessor& gp = *ds.getGeometryProcessor();
joshualitt79f8fae2014-10-28 17:59:26 -0700339 descInfo->fReadsFragPosition = descInfo->fReadsFragPosition || gp.willReadFragmentPosition();
egdaniela7dc0a82014-09-17 08:25:05 -0700340 }
341}
342
egdaniel89af44a2014-09-26 06:15:04 -0700343////////////////////////////////////////////////////////////////////////////////
344
egdaniel3658f382014-09-15 07:01:59 -0700345bool GrOptDrawState::operator== (const GrOptDrawState& that) const {
346 return this->isEqual(that);
347}
348
egdaniel89af44a2014-09-26 06:15:04 -0700349bool GrOptDrawState::isEqual(const GrOptDrawState& that) const {
joshualitt79f8fae2014-10-28 17:59:26 -0700350 if (this->fDesc != that.fDesc) {
351 return false;
352 }
353 bool usingVertexColors = that.fDesc.header().fColorAttributeIndex != -1;
egdaniel89af44a2014-09-26 06:15:04 -0700354 if (!usingVertexColors && this->fColor != that.fColor) {
355 return false;
356 }
357
358 if (this->getRenderTarget() != that.getRenderTarget() ||
egdaniel89af44a2014-09-26 06:15:04 -0700359 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) ||
360 this->fSrcBlend != that.fSrcBlend ||
361 this->fDstBlend != that.fDstBlend ||
362 this->fBlendConstant != that.fBlendConstant ||
363 this->fFlagBits != that.fFlagBits ||
364 this->fVACount != that.fVACount ||
365 this->fVAStride != that.fVAStride ||
366 memcmp(this->fVAPtr, that.fVAPtr, this->fVACount * sizeof(GrVertexAttrib)) ||
367 this->fStencilSettings != that.fStencilSettings ||
joshualitt79f8fae2014-10-28 17:59:26 -0700368 this->fDrawFace != that.fDrawFace) {
egdaniel89af44a2014-09-26 06:15:04 -0700369 return false;
370 }
371
joshualitt79f8fae2014-10-28 17:59:26 -0700372 bool usingVertexCoverage = this->fDesc.header().fCoverageAttributeIndex != -1;
egdaniel89af44a2014-09-26 06:15:04 -0700373 if (!usingVertexCoverage && this->fCoverage != that.fCoverage) {
374 return false;
375 }
376
egdaniel89af44a2014-09-26 06:15:04 -0700377 if (this->hasGeometryProcessor()) {
378 if (!that.hasGeometryProcessor()) {
379 return false;
joshualitta5305a12014-10-10 17:47:00 -0700380 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProcessor())) {
egdaniel89af44a2014-09-26 06:15:04 -0700381 return false;
382 }
383 } else if (that.hasGeometryProcessor()) {
384 return false;
385 }
386
joshualitt79f8fae2014-10-28 17:59:26 -0700387 bool explicitLocalCoords = this->fDesc.header().fLocalCoordAttributeIndex != -1;
egdanield9aa2182014-10-09 13:47:05 -0700388 for (int i = 0; i < this->numFragmentStages(); i++) {
joshualitta5305a12014-10-10 17:47:00 -0700389 if (!GrFragmentStage::AreCompatible(this->getFragmentStage(i), that.getFragmentStage(i),
390 explicitLocalCoords)) {
egdaniel89af44a2014-09-26 06:15:04 -0700391 return false;
392 }
393 }
egdaniel89af44a2014-09-26 06:15:04 -0700394 return true;
395}
396