blob: 68cd01c3d5ac38fb6248593255a52c5d434b76d8 [file] [log] [blame]
bsalomon@google.comaf84e742012-10-05 13:23:24 +00001/*
2 * Copyright 2012 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 "GrDrawState.h"
egdaniel3658f382014-09-15 07:01:59 -07009
egdanielb1cff032014-11-13 06:19:25 -080010#include "GrBlend.h"
egdaniel3658f382014-09-15 07:01:59 -070011#include "GrOptDrawState.h"
12#include "GrPaint.h"
egdanielb6cbc382014-11-13 11:00:34 -080013#include "GrProcOptInfo.h"
egdaniel378092f2014-12-03 10:40:13 -080014#include "GrXferProcessor.h"
15#include "effects/GrPorterDuffXferProcessor.h"
egdaniel3658f382014-09-15 07:01:59 -070016
joshualitt56995b52014-12-11 15:44:02 -080017bool GrDrawState::isEqual(const GrDrawState& that, bool explicitLocalCoords) const {
egdaniel89af44a2014-09-26 06:15:04 -070018 if (this->getRenderTarget() != that.getRenderTarget() ||
19 this->fColorStages.count() != that.fColorStages.count() ||
20 this->fCoverageStages.count() != that.fCoverageStages.count() ||
21 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) ||
egdaniel89af44a2014-09-26 06:15:04 -070022 this->fFlagBits != that.fFlagBits ||
egdaniel89af44a2014-09-26 06:15:04 -070023 this->fStencilSettings != that.fStencilSettings ||
24 this->fDrawFace != that.fDrawFace) {
25 return false;
26 }
27
egdaniel915187b2014-12-05 12:58:28 -080028 if (!this->getXPFactory()->isEqual(*that.getXPFactory())) {
29 return false;
30 }
31
egdaniel89af44a2014-09-26 06:15:04 -070032 for (int i = 0; i < this->numColorStages(); i++) {
joshualitta5305a12014-10-10 17:47:00 -070033 if (!GrFragmentStage::AreCompatible(this->getColorStage(i), that.getColorStage(i),
egdaniel89af44a2014-09-26 06:15:04 -070034 explicitLocalCoords)) {
35 return false;
36 }
37 }
38 for (int i = 0; i < this->numCoverageStages(); i++) {
joshualitta5305a12014-10-10 17:47:00 -070039 if (!GrFragmentStage::AreCompatible(this->getCoverageStage(i), that.getCoverageStage(i),
egdaniel89af44a2014-09-26 06:15:04 -070040 explicitLocalCoords)) {
41 return false;
42 }
43 }
44
egdaniel89af44a2014-09-26 06:15:04 -070045 return true;
46}
47
bsalomon8f727332014-08-05 07:50:06 -070048//////////////////////////////////////////////////////////////////////////////s
49
egdaniel69bb90c2014-11-11 07:32:45 -080050GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix) {
bsalomon8f727332014-08-05 07:50:06 -070051 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
52 *this = state;
53 if (!preConcatMatrix.isIdentity()) {
egdaniel776bdbd2014-08-06 11:07:02 -070054 for (int i = 0; i < this->numColorStages(); ++i) {
egdaniel8cbf3d52014-08-21 06:27:22 -070055 fColorStages[i].localCoordChange(preConcatMatrix);
bsalomon8f727332014-08-05 07:50:06 -070056 }
egdaniel776bdbd2014-08-06 11:07:02 -070057 for (int i = 0; i < this->numCoverageStages(); ++i) {
egdaniel8cbf3d52014-08-21 06:27:22 -070058 fCoverageStages[i].localCoordChange(preConcatMatrix);
bsalomon8f727332014-08-05 07:50:06 -070059 }
bsalomon8f727332014-08-05 07:50:06 -070060 }
61}
62
63GrDrawState& GrDrawState::operator=(const GrDrawState& that) {
bsalomonae59b772014-11-19 08:23:49 -080064 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get()));
bsalomon8f727332014-08-05 07:50:06 -070065 fViewMatrix = that.fViewMatrix;
bsalomon8f727332014-08-05 07:50:06 -070066 fFlagBits = that.fFlagBits;
bsalomon8f727332014-08-05 07:50:06 -070067 fStencilSettings = that.fStencilSettings;
bsalomon8f727332014-08-05 07:50:06 -070068 fDrawFace = that.fDrawFace;
egdaniel378092f2014-12-03 10:40:13 -080069 fXPFactory.reset(SkRef(that.getXPFactory()));
egdaniel8cbf3d52014-08-21 06:27:22 -070070 fColorStages = that.fColorStages;
71 fCoverageStages = that.fCoverageStages;
bsalomon8f727332014-08-05 07:50:06 -070072
egdanielb6cbc382014-11-13 11:00:34 -080073 fColorProcInfoValid = that.fColorProcInfoValid;
74 fCoverageProcInfoValid = that.fCoverageProcInfoValid;
joshualittf364b612014-12-11 06:52:01 -080075 fColorCache = that.fColorCache;
76 fCoverageCache = that.fCoverageCache;
joshualitte832b952014-12-12 08:41:15 -080077 fColorPrimProc = that.fColorPrimProc;
78 fCoveragePrimProc = that.fCoveragePrimProc;
egdanielb6cbc382014-11-13 11:00:34 -080079 if (fColorProcInfoValid) {
80 fColorProcInfo = that.fColorProcInfo;
81 }
82 if (fCoverageProcInfoValid) {
83 fCoverageProcInfo = that.fCoverageProcInfo;
84 }
bsalomon8f727332014-08-05 07:50:06 -070085 return *this;
86}
87
88void GrDrawState::onReset(const SkMatrix* initialViewMatrix) {
joshualitt56995b52014-12-11 15:44:02 -080089 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages());
bsalomonae59b772014-11-19 08:23:49 -080090 fRenderTarget.reset(NULL);
bsalomon2a9ca782014-09-05 14:27:43 -070091
egdanielc016fb82014-12-03 11:41:54 -080092 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
egdaniel8cbf3d52014-08-21 06:27:22 -070093 fColorStages.reset();
94 fCoverageStages.reset();
bsalomon8f727332014-08-05 07:50:06 -070095
bsalomon8f727332014-08-05 07:50:06 -070096 if (NULL == initialViewMatrix) {
97 fViewMatrix.reset();
98 } else {
99 fViewMatrix = *initialViewMatrix;
100 }
bsalomon8f727332014-08-05 07:50:06 -0700101 fFlagBits = 0x0;
102 fStencilSettings.setDisabled();
bsalomon8f727332014-08-05 07:50:06 -0700103 fDrawFace = kBoth_DrawFace;
104
egdanielb6cbc382014-11-13 11:00:34 -0800105 fColorProcInfoValid = false;
106 fCoverageProcInfoValid = false;
joshualitt9b338222014-12-10 12:28:08 -0800107
108 fColorCache = GrColor_ILLEGAL;
109 fCoverageCache = GrColor_ILLEGAL;
joshualitt56995b52014-12-11 15:44:02 -0800110
111 fColorPrimProc = NULL;
112 fCoveragePrimProc = NULL;
bsalomon8f727332014-08-05 07:50:06 -0700113}
114
bsalomon@google.com137f1342013-05-29 21:27:53 +0000115bool GrDrawState::setIdentityViewMatrix() {
joshualitt4dd99882014-11-11 08:51:30 -0800116 if (this->numFragmentStages()) {
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000117 SkMatrix invVM;
bsalomon2ed5ef82014-07-07 08:44:05 -0700118 if (!fViewMatrix.invert(&invVM)) {
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000119 // sad trombone sound
120 return false;
121 }
egdaniel776bdbd2014-08-06 11:07:02 -0700122 for (int s = 0; s < this->numColorStages(); ++s) {
egdaniel8cbf3d52014-08-21 06:27:22 -0700123 fColorStages[s].localCoordChange(invVM);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000124 }
egdaniel776bdbd2014-08-06 11:07:02 -0700125 for (int s = 0; s < this->numCoverageStages(); ++s) {
egdaniel8cbf3d52014-08-21 06:27:22 -0700126 fCoverageStages[s].localCoordChange(invVM);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000127 }
128 }
bsalomon2ed5ef82014-07-07 08:44:05 -0700129 fViewMatrix.reset();
bsalomon@google.com137f1342013-05-29 21:27:53 +0000130 return true;
131}
132
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +0000133void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRenderTarget* rt) {
joshualitt56995b52014-12-11 15:44:02 -0800134 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000135
egdaniel8cbf3d52014-08-21 06:27:22 -0700136 fColorStages.reset();
137 fCoverageStages.reset();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000138
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +0000139 for (int i = 0; i < paint.numColorStages(); ++i) {
egdaniel8cbf3d52014-08-21 06:27:22 -0700140 fColorStages.push_back(paint.getColorStage(i));
bsalomon@google.comaf84e742012-10-05 13:23:24 +0000141 }
142
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +0000143 for (int i = 0; i < paint.numCoverageStages(); ++i) {
egdaniel8cbf3d52014-08-21 06:27:22 -0700144 fCoverageStages.push_back(paint.getCoverageStage(i));
bsalomon@google.comaf84e742012-10-05 13:23:24 +0000145 }
146
egdaniel378092f2014-12-03 10:40:13 -0800147 fXPFactory.reset(SkRef(paint.getXPFactory()));
148
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +0000149 this->setRenderTarget(rt);
bsalomon@google.comaf84e742012-10-05 13:23:24 +0000150
bsalomon2ed5ef82014-07-07 08:44:05 -0700151 fViewMatrix = vm;
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +0000152
153 // These have no equivalent in GrPaint, set them to defaults
bsalomon2ed5ef82014-07-07 08:44:05 -0700154 fDrawFace = kBoth_DrawFace;
155 fStencilSettings.setDisabled();
bsalomon04ddf892014-11-19 12:36:22 -0800156 fFlagBits = 0;
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +0000157
bsalomon@google.com21c10c52013-06-13 17:44:07 +0000158 // Enable the clip bit
159 this->enableState(GrDrawState::kClip_StateBit);
160
bsalomon@google.comc7448ce2012-10-05 19:04:13 +0000161 this->setState(GrDrawState::kDither_StateBit, paint.isDither());
162 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias());
bsalomon@google.comaf84e742012-10-05 13:23:24 +0000163
egdanielb6cbc382014-11-13 11:00:34 -0800164 fColorProcInfoValid = false;
165 fCoverageProcInfoValid = false;
joshualitt2e3b3e32014-12-09 13:31:14 -0800166
167 fColorCache = GrColor_ILLEGAL;
168 fCoverageCache = GrColor_ILLEGAL;
joshualitte832b952014-12-12 08:41:15 -0800169
170 fColorPrimProc = NULL;
171 fCoveragePrimProc = NULL;
bsalomon@google.comaf84e742012-10-05 13:23:24 +0000172}
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000173
174////////////////////////////////////////////////////////////////////////////////
175
joshualitt2e3b3e32014-12-09 13:31:14 -0800176bool GrDrawState::canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCaps& caps) const {
bsalomon62c447d2014-08-08 08:08:50 -0700177 if (caps.dualSourceBlendingSupport()) {
178 return true;
179 }
egdaniel95131432014-12-09 11:15:43 -0800180
joshualitt2e3b3e32014-12-09 13:31:14 -0800181 this->calcColorInvariantOutput(color);
182
183 // The coverage isn't actually white, its unknown, but this will produce the same effect
184 // TODO we want to cache the result of this call, but we can probably clean up the interface
185 // so we don't have to pass in a seemingly known coverage
186 this->calcCoverageInvariantOutput(GrColor_WHITE);
egdaniel080e6732014-12-22 07:35:52 -0800187 return fXPFactory->canApplyCoverage(fColorProcInfo, fCoverageProcInfo);
egdaniel89af44a2014-09-26 06:15:04 -0700188}
189
egdaniel21aed572014-08-26 12:24:06 -0700190//////////////////////////////////////////////////////////////////////////////s
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000191
joshualitt56995b52014-12-11 15:44:02 -0800192bool GrDrawState::willEffectReadDstColor(const GrPrimitiveProcessor* pp) const {
193 this->calcColorInvariantOutput(pp);
194 this->calcCoverageInvariantOutput(pp);
egdaniel95131432014-12-09 11:15:43 -0800195
egdaniel080e6732014-12-22 07:35:52 -0800196 return fXPFactory->willReadDst(fColorProcInfo, fCoverageProcInfo);
egdaniel89af44a2014-09-26 06:15:04 -0700197}
198
egdaniel21aed572014-08-26 12:24:06 -0700199void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
bsalomon49f085d2014-09-05 13:34:00 -0700200 if (fDrawState) {
egdaniel21aed572014-08-26 12:24:06 -0700201 int m = fDrawState->numColorStages() - fColorEffectCnt;
202 SkASSERT(m >= 0);
203 fDrawState->fColorStages.pop_back_n(m);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000204
egdaniel21aed572014-08-26 12:24:06 -0700205 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt;
206 SkASSERT(n >= 0);
207 fDrawState->fCoverageStages.pop_back_n(n);
egdanielb6cbc382014-11-13 11:00:34 -0800208 if (m + n > 0) {
209 fDrawState->fColorProcInfoValid = false;
210 fDrawState->fCoverageProcInfoValid = false;
211 }
egdaniel21aed572014-08-26 12:24:06 -0700212 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000213 }
egdaniel21aed572014-08-26 12:24:06 -0700214 fDrawState = ds;
215 if (NULL != ds) {
216 fColorEffectCnt = ds->numColorStages();
217 fCoverageEffectCnt = ds->numCoverageStages();
218 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;)
219 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000220}
221
jvanverth@google.comcc782382013-01-28 20:39:48 +0000222////////////////////////////////////////////////////////////////////////////////
223
egdaniel89af44a2014-09-26 06:15:04 -0700224// Some blend modes allow folding a fractional coverage value into the color's alpha channel, while
225// others will blend incorrectly.
226bool GrDrawState::canTweakAlphaForCoverage() const {
egdaniel87509242014-12-17 13:37:13 -0800227 return fXPFactory->canTweakAlphaForCoverage();
egdaniel89af44a2014-09-26 06:15:04 -0700228}
229
230////////////////////////////////////////////////////////////////////////////////
231
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000232void GrDrawState::AutoViewMatrixRestore::restore() {
bsalomon49f085d2014-09-05 13:34:00 -0700233 if (fDrawState) {
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000234 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
bsalomon2ed5ef82014-07-07 08:44:05 -0700235 fDrawState->fViewMatrix = fViewMatrix;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000236 SkASSERT(fDrawState->numColorStages() >= fNumColorStages);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000237 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000238 SkASSERT(fDrawState->numCoverageStages() >= numCoverageStages);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000239
240 int i = 0;
241 for (int s = 0; s < fNumColorStages; ++s, ++i) {
egdaniel8cbf3d52014-08-21 06:27:22 -0700242 fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i]);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000243 }
244 for (int s = 0; s < numCoverageStages; ++s, ++i) {
egdaniel8cbf3d52014-08-21 06:27:22 -0700245 fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges[i]);
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000246 }
bsalomon@google.com137f1342013-05-29 21:27:53 +0000247 fDrawState = NULL;
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000248 }
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000249}
250
251void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState,
bsalomon@google.comc7818882013-03-20 19:19:53 +0000252 const SkMatrix& preconcatMatrix) {
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000253 this->restore();
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000254
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000255 SkASSERT(NULL == fDrawState);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000256 if (NULL == drawState || preconcatMatrix.isIdentity()) {
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000257 return;
258 }
bsalomon@google.com137f1342013-05-29 21:27:53 +0000259 fDrawState = drawState;
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000260
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000261 fViewMatrix = drawState->getViewMatrix();
bsalomon2ed5ef82014-07-07 08:44:05 -0700262 drawState->fViewMatrix.preConcat(preconcatMatrix);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000263
264 this->doEffectCoordChanges(preconcatMatrix);
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000265 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000266}
267
bsalomon@google.com137f1342013-05-29 21:27:53 +0000268bool GrDrawState::AutoViewMatrixRestore::setIdentity(GrDrawState* drawState) {
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000269 this->restore();
270
bsalomon@google.com137f1342013-05-29 21:27:53 +0000271 if (NULL == drawState) {
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000272 return false;
skia.committer@gmail.comf467ce72012-10-09 02:01:37 +0000273 }
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000274
bsalomon@google.com137f1342013-05-29 21:27:53 +0000275 if (drawState->getViewMatrix().isIdentity()) {
276 return true;
277 }
278
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000279 fViewMatrix = drawState->getViewMatrix();
joshualitt4dd99882014-11-11 08:51:30 -0800280 if (0 == drawState->numFragmentStages()) {
bsalomon2ed5ef82014-07-07 08:44:05 -0700281 drawState->fViewMatrix.reset();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000282 fDrawState = drawState;
283 fNumColorStages = 0;
284 fSavedCoordChanges.reset(0);
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000285 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000286 return true;
287 } else {
288 SkMatrix inv;
289 if (!fViewMatrix.invert(&inv)) {
290 return false;
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000291 }
bsalomon2ed5ef82014-07-07 08:44:05 -0700292 drawState->fViewMatrix.reset();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000293 fDrawState = drawState;
294 this->doEffectCoordChanges(inv);
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000295 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000296 return true;
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000297 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000298}
299
300void GrDrawState::AutoViewMatrixRestore::doEffectCoordChanges(const SkMatrix& coordChangeMatrix) {
joshualitt4dd99882014-11-11 08:51:30 -0800301 fSavedCoordChanges.reset(fDrawState->numFragmentStages());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000302 int i = 0;
303
304 fNumColorStages = fDrawState->numColorStages();
305 for (int s = 0; s < fNumColorStages; ++s, ++i) {
egdaniel776bdbd2014-08-06 11:07:02 -0700306 fDrawState->getColorStage(s).saveCoordChange(&fSavedCoordChanges[i]);
egdaniel8cbf3d52014-08-21 06:27:22 -0700307 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000308 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000309
310 int numCoverageStages = fDrawState->numCoverageStages();
311 for (int s = 0; s < numCoverageStages; ++s, ++i) {
egdaniel776bdbd2014-08-06 11:07:02 -0700312 fDrawState->getCoverageStage(s).saveCoordChange(&fSavedCoordChanges[i]);
egdaniel8cbf3d52014-08-21 06:27:22 -0700313 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000314 }
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000315}
egdaniel21aed572014-08-26 12:24:06 -0700316
egdaniel170f90b2014-09-16 12:54:40 -0700317////////////////////////////////////////////////////////////////////////////////
318
egdaniel170f90b2014-09-16 12:54:40 -0700319GrDrawState::~GrDrawState() {
egdaniel170f90b2014-09-16 12:54:40 -0700320 SkASSERT(0 == fBlockEffectRemovalCnt);
321}
322
egdaniel89af44a2014-09-26 06:15:04 -0700323////////////////////////////////////////////////////////////////////////////////
324
joshualitt56995b52014-12-11 15:44:02 -0800325bool GrDrawState::willBlendWithDst(const GrPrimitiveProcessor* pp) const {
326 this->calcColorInvariantOutput(pp);
327 this->calcCoverageInvariantOutput(pp);
egdaniel9e4ecdc2014-12-18 12:44:55 -0800328
329 GrXPFactory::InvariantOutput output;
egdaniel080e6732014-12-22 07:35:52 -0800330 fXPFactory->getInvariantOutput(fColorProcInfo, fCoverageProcInfo, &output);
egdaniel9e4ecdc2014-12-18 12:44:55 -0800331 return output.fWillBlendWithDst;
egdanielcd8b6302014-11-11 14:46:05 -0800332}
333
joshualitt56995b52014-12-11 15:44:02 -0800334void GrDrawState::calcColorInvariantOutput(const GrPrimitiveProcessor* pp) const {
335 if (!fColorProcInfoValid || fColorPrimProc != pp) {
336 fColorProcInfo.calcColorWithPrimProc(pp, fColorStages.begin(), this->numColorStages());
337 fColorProcInfoValid = true;
338 fColorPrimProc = pp;
339 }
340}
341
342void GrDrawState::calcCoverageInvariantOutput(const GrPrimitiveProcessor* pp) const {
343 if (!fCoverageProcInfoValid || fCoveragePrimProc != pp) {
344 fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageStages.begin(),
345 this->numCoverageStages());
346 fCoverageProcInfoValid = true;
347 fCoveragePrimProc = pp;
348 }
349}
350
joshualitt2e3b3e32014-12-09 13:31:14 -0800351void GrDrawState::calcColorInvariantOutput(GrColor color) const {
352 if (!fColorProcInfoValid || color != fColorCache) {
joshualitt56995b52014-12-11 15:44:02 -0800353 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags;
354 fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColorStages(), color,
355 flags, false);
egdanielb6cbc382014-11-13 11:00:34 -0800356 fColorProcInfoValid = true;
joshualitt2e3b3e32014-12-09 13:31:14 -0800357 fColorCache = color;
egdanielb6cbc382014-11-13 11:00:34 -0800358 }
359}
360
joshualitt2e3b3e32014-12-09 13:31:14 -0800361void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const {
362 if (!fCoverageProcInfoValid || coverage != fCoverageCache) {
joshualitt56995b52014-12-11 15:44:02 -0800363 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags;
364 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(),
365 this->numCoverageStages(), coverage, flags,
366 true);
egdanielb6cbc382014-11-13 11:00:34 -0800367 fCoverageProcInfoValid = true;
joshualitt2e3b3e32014-12-09 13:31:14 -0800368 fCoverageCache = coverage;
egdanielb6cbc382014-11-13 11:00:34 -0800369 }
370}