blob: 883c74b8ee65ef6b15dddf06143f23afa5529cf5 [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);
egdaniel95131432014-12-09 11:15:43 -0800187 return fXPFactory->canApplyCoverage(fColorProcInfo, fCoverageProcInfo,
egdaniel87509242014-12-17 13:37:13 -0800188 this->isColorWriteDisabled());
egdaniel89af44a2014-09-26 06:15:04 -0700189}
190
egdaniel21aed572014-08-26 12:24:06 -0700191//////////////////////////////////////////////////////////////////////////////s
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000192
joshualitt56995b52014-12-11 15:44:02 -0800193bool GrDrawState::willEffectReadDstColor(const GrPrimitiveProcessor* pp) const {
194 this->calcColorInvariantOutput(pp);
195 this->calcCoverageInvariantOutput(pp);
egdaniel95131432014-12-09 11:15:43 -0800196 // TODO: Remove need to create the XP here.
197 // Also once all custom blends are turned into XPs we can remove the need
198 // to check other stages since only xp's will be able to read dst
199 SkAutoTUnref<GrXferProcessor> xferProcessor(fXPFactory->createXferProcessor(fColorProcInfo,
200 fCoverageProcInfo));
201 if (xferProcessor && xferProcessor->willReadDstColor()) {
202 return true;
203 }
204
egdaniel89af44a2014-09-26 06:15:04 -0700205 if (!this->isColorWriteDisabled()) {
egdanielb6cbc382014-11-13 11:00:34 -0800206 if (fColorProcInfo.readsDst()) {
egdaniel89af44a2014-09-26 06:15:04 -0700207 return true;
208 }
209 }
egdanielb6cbc382014-11-13 11:00:34 -0800210 return fCoverageProcInfo.readsDst();
egdaniel89af44a2014-09-26 06:15:04 -0700211}
212
egdaniel21aed572014-08-26 12:24:06 -0700213void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
bsalomon49f085d2014-09-05 13:34:00 -0700214 if (fDrawState) {
egdaniel21aed572014-08-26 12:24:06 -0700215 int m = fDrawState->numColorStages() - fColorEffectCnt;
216 SkASSERT(m >= 0);
217 fDrawState->fColorStages.pop_back_n(m);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000218
egdaniel21aed572014-08-26 12:24:06 -0700219 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt;
220 SkASSERT(n >= 0);
221 fDrawState->fCoverageStages.pop_back_n(n);
egdanielb6cbc382014-11-13 11:00:34 -0800222 if (m + n > 0) {
223 fDrawState->fColorProcInfoValid = false;
224 fDrawState->fCoverageProcInfoValid = false;
225 }
egdaniel21aed572014-08-26 12:24:06 -0700226 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000227 }
egdaniel21aed572014-08-26 12:24:06 -0700228 fDrawState = ds;
229 if (NULL != ds) {
230 fColorEffectCnt = ds->numColorStages();
231 fCoverageEffectCnt = ds->numCoverageStages();
232 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;)
233 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000234}
235
jvanverth@google.comcc782382013-01-28 20:39:48 +0000236////////////////////////////////////////////////////////////////////////////////
237
egdaniel89af44a2014-09-26 06:15:04 -0700238// Some blend modes allow folding a fractional coverage value into the color's alpha channel, while
239// others will blend incorrectly.
240bool GrDrawState::canTweakAlphaForCoverage() const {
egdaniel87509242014-12-17 13:37:13 -0800241 return fXPFactory->canTweakAlphaForCoverage();
egdaniel89af44a2014-09-26 06:15:04 -0700242}
243
244////////////////////////////////////////////////////////////////////////////////
245
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000246void GrDrawState::AutoViewMatrixRestore::restore() {
bsalomon49f085d2014-09-05 13:34:00 -0700247 if (fDrawState) {
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000248 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
bsalomon2ed5ef82014-07-07 08:44:05 -0700249 fDrawState->fViewMatrix = fViewMatrix;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000250 SkASSERT(fDrawState->numColorStages() >= fNumColorStages);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000251 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000252 SkASSERT(fDrawState->numCoverageStages() >= numCoverageStages);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000253
254 int i = 0;
255 for (int s = 0; s < fNumColorStages; ++s, ++i) {
egdaniel8cbf3d52014-08-21 06:27:22 -0700256 fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i]);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000257 }
258 for (int s = 0; s < numCoverageStages; ++s, ++i) {
egdaniel8cbf3d52014-08-21 06:27:22 -0700259 fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges[i]);
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000260 }
bsalomon@google.com137f1342013-05-29 21:27:53 +0000261 fDrawState = NULL;
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000262 }
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000263}
264
265void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState,
bsalomon@google.comc7818882013-03-20 19:19:53 +0000266 const SkMatrix& preconcatMatrix) {
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000267 this->restore();
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000268
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000269 SkASSERT(NULL == fDrawState);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000270 if (NULL == drawState || preconcatMatrix.isIdentity()) {
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000271 return;
272 }
bsalomon@google.com137f1342013-05-29 21:27:53 +0000273 fDrawState = drawState;
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000274
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000275 fViewMatrix = drawState->getViewMatrix();
bsalomon2ed5ef82014-07-07 08:44:05 -0700276 drawState->fViewMatrix.preConcat(preconcatMatrix);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000277
278 this->doEffectCoordChanges(preconcatMatrix);
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000279 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000280}
281
bsalomon@google.com137f1342013-05-29 21:27:53 +0000282bool GrDrawState::AutoViewMatrixRestore::setIdentity(GrDrawState* drawState) {
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000283 this->restore();
284
bsalomon@google.com137f1342013-05-29 21:27:53 +0000285 if (NULL == drawState) {
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000286 return false;
skia.committer@gmail.comf467ce72012-10-09 02:01:37 +0000287 }
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000288
bsalomon@google.com137f1342013-05-29 21:27:53 +0000289 if (drawState->getViewMatrix().isIdentity()) {
290 return true;
291 }
292
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000293 fViewMatrix = drawState->getViewMatrix();
joshualitt4dd99882014-11-11 08:51:30 -0800294 if (0 == drawState->numFragmentStages()) {
bsalomon2ed5ef82014-07-07 08:44:05 -0700295 drawState->fViewMatrix.reset();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000296 fDrawState = drawState;
297 fNumColorStages = 0;
298 fSavedCoordChanges.reset(0);
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000299 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000300 return true;
301 } else {
302 SkMatrix inv;
303 if (!fViewMatrix.invert(&inv)) {
304 return false;
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000305 }
bsalomon2ed5ef82014-07-07 08:44:05 -0700306 drawState->fViewMatrix.reset();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000307 fDrawState = drawState;
308 this->doEffectCoordChanges(inv);
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000309 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000310 return true;
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000311 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000312}
313
314void GrDrawState::AutoViewMatrixRestore::doEffectCoordChanges(const SkMatrix& coordChangeMatrix) {
joshualitt4dd99882014-11-11 08:51:30 -0800315 fSavedCoordChanges.reset(fDrawState->numFragmentStages());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000316 int i = 0;
317
318 fNumColorStages = fDrawState->numColorStages();
319 for (int s = 0; s < fNumColorStages; ++s, ++i) {
egdaniel776bdbd2014-08-06 11:07:02 -0700320 fDrawState->getColorStage(s).saveCoordChange(&fSavedCoordChanges[i]);
egdaniel8cbf3d52014-08-21 06:27:22 -0700321 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000322 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000323
324 int numCoverageStages = fDrawState->numCoverageStages();
325 for (int s = 0; s < numCoverageStages; ++s, ++i) {
egdaniel776bdbd2014-08-06 11:07:02 -0700326 fDrawState->getCoverageStage(s).saveCoordChange(&fSavedCoordChanges[i]);
egdaniel8cbf3d52014-08-21 06:27:22 -0700327 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000328 }
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000329}
egdaniel21aed572014-08-26 12:24:06 -0700330
egdaniel170f90b2014-09-16 12:54:40 -0700331////////////////////////////////////////////////////////////////////////////////
332
egdaniel170f90b2014-09-16 12:54:40 -0700333GrDrawState::~GrDrawState() {
egdaniel170f90b2014-09-16 12:54:40 -0700334 SkASSERT(0 == fBlockEffectRemovalCnt);
335}
336
egdaniel89af44a2014-09-26 06:15:04 -0700337////////////////////////////////////////////////////////////////////////////////
338
joshualitt56995b52014-12-11 15:44:02 -0800339bool GrDrawState::willBlendWithDst(const GrPrimitiveProcessor* pp) const {
340 this->calcColorInvariantOutput(pp);
341 this->calcCoverageInvariantOutput(pp);
egdaniel9e4ecdc2014-12-18 12:44:55 -0800342
343 GrXPFactory::InvariantOutput output;
344 fXPFactory->getInvariantOutput(fColorProcInfo, fCoverageProcInfo, this->isColorWriteDisabled(),
345 &output);
346 return output.fWillBlendWithDst;
egdanielcd8b6302014-11-11 14:46:05 -0800347}
348
joshualitt56995b52014-12-11 15:44:02 -0800349void GrDrawState::calcColorInvariantOutput(const GrPrimitiveProcessor* pp) const {
350 if (!fColorProcInfoValid || fColorPrimProc != pp) {
351 fColorProcInfo.calcColorWithPrimProc(pp, fColorStages.begin(), this->numColorStages());
352 fColorProcInfoValid = true;
353 fColorPrimProc = pp;
354 }
355}
356
357void GrDrawState::calcCoverageInvariantOutput(const GrPrimitiveProcessor* pp) const {
358 if (!fCoverageProcInfoValid || fCoveragePrimProc != pp) {
359 fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageStages.begin(),
360 this->numCoverageStages());
361 fCoverageProcInfoValid = true;
362 fCoveragePrimProc = pp;
363 }
364}
365
joshualitt2e3b3e32014-12-09 13:31:14 -0800366void GrDrawState::calcColorInvariantOutput(GrColor color) const {
367 if (!fColorProcInfoValid || color != fColorCache) {
joshualitt56995b52014-12-11 15:44:02 -0800368 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags;
369 fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColorStages(), color,
370 flags, false);
egdanielb6cbc382014-11-13 11:00:34 -0800371 fColorProcInfoValid = true;
joshualitt2e3b3e32014-12-09 13:31:14 -0800372 fColorCache = color;
egdanielb6cbc382014-11-13 11:00:34 -0800373 }
374}
375
joshualitt2e3b3e32014-12-09 13:31:14 -0800376void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const {
377 if (!fCoverageProcInfoValid || coverage != fCoverageCache) {
joshualitt56995b52014-12-11 15:44:02 -0800378 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags;
379 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(),
380 this->numCoverageStages(), coverage, flags,
381 true);
egdanielb6cbc382014-11-13 11:00:34 -0800382 fCoverageProcInfoValid = true;
joshualitt2e3b3e32014-12-09 13:31:14 -0800383 fCoverageCache = coverage;
egdanielb6cbc382014-11-13 11:00:34 -0800384 }
385}