blob: ebabb43ad2113caf44a41ab57125d34eaad3de0a [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,
188 this->isCoverageDrawing(), this->isColorWriteDisabled());
bsalomon62c447d2014-08-08 08:08:50 -0700189}
190
joshualitt56995b52014-12-11 15:44:02 -0800191bool GrDrawState::hasSolidCoverage(const GrPrimitiveProcessor* pp) const {
egdaniel89af44a2014-09-26 06:15:04 -0700192 // If we're drawing coverage directly then coverage is effectively treated as color.
193 if (this->isCoverageDrawing()) {
194 return true;
195 }
196
joshualitt4dd99882014-11-11 08:51:30 -0800197 if (this->numCoverageStages() > 0) {
198 return false;
199 }
200
joshualitt56995b52014-12-11 15:44:02 -0800201 this->calcCoverageInvariantOutput(pp);
egdanielb6cbc382014-11-13 11:00:34 -0800202 return fCoverageProcInfo.isSolidWhite();
egdaniel89af44a2014-09-26 06:15:04 -0700203}
204
egdaniel21aed572014-08-26 12:24:06 -0700205//////////////////////////////////////////////////////////////////////////////s
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000206
joshualitt56995b52014-12-11 15:44:02 -0800207bool GrDrawState::willEffectReadDstColor(const GrPrimitiveProcessor* pp) const {
208 this->calcColorInvariantOutput(pp);
209 this->calcCoverageInvariantOutput(pp);
egdaniel95131432014-12-09 11:15:43 -0800210 // TODO: Remove need to create the XP here.
211 // Also once all custom blends are turned into XPs we can remove the need
212 // to check other stages since only xp's will be able to read dst
213 SkAutoTUnref<GrXferProcessor> xferProcessor(fXPFactory->createXferProcessor(fColorProcInfo,
214 fCoverageProcInfo));
215 if (xferProcessor && xferProcessor->willReadDstColor()) {
216 return true;
217 }
218
egdaniel89af44a2014-09-26 06:15:04 -0700219 if (!this->isColorWriteDisabled()) {
egdanielb6cbc382014-11-13 11:00:34 -0800220 if (fColorProcInfo.readsDst()) {
egdaniel89af44a2014-09-26 06:15:04 -0700221 return true;
222 }
223 }
egdanielb6cbc382014-11-13 11:00:34 -0800224 return fCoverageProcInfo.readsDst();
egdaniel89af44a2014-09-26 06:15:04 -0700225}
226
egdaniel21aed572014-08-26 12:24:06 -0700227void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
bsalomon49f085d2014-09-05 13:34:00 -0700228 if (fDrawState) {
egdaniel21aed572014-08-26 12:24:06 -0700229 int m = fDrawState->numColorStages() - fColorEffectCnt;
230 SkASSERT(m >= 0);
231 fDrawState->fColorStages.pop_back_n(m);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000232
egdaniel21aed572014-08-26 12:24:06 -0700233 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt;
234 SkASSERT(n >= 0);
235 fDrawState->fCoverageStages.pop_back_n(n);
egdanielb6cbc382014-11-13 11:00:34 -0800236 if (m + n > 0) {
237 fDrawState->fColorProcInfoValid = false;
238 fDrawState->fCoverageProcInfoValid = false;
239 }
egdaniel21aed572014-08-26 12:24:06 -0700240 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000241 }
egdaniel21aed572014-08-26 12:24:06 -0700242 fDrawState = ds;
243 if (NULL != ds) {
244 fColorEffectCnt = ds->numColorStages();
245 fCoverageEffectCnt = ds->numCoverageStages();
246 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;)
247 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000248}
249
jvanverth@google.comcc782382013-01-28 20:39:48 +0000250////////////////////////////////////////////////////////////////////////////////
251
egdaniel89af44a2014-09-26 06:15:04 -0700252// Some blend modes allow folding a fractional coverage value into the color's alpha channel, while
253// others will blend incorrectly.
254bool GrDrawState::canTweakAlphaForCoverage() const {
egdaniel95131432014-12-09 11:15:43 -0800255 return fXPFactory->canTweakAlphaForCoverage(this->isCoverageDrawing());
egdaniel89af44a2014-09-26 06:15:04 -0700256}
257
258////////////////////////////////////////////////////////////////////////////////
259
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000260void GrDrawState::AutoViewMatrixRestore::restore() {
bsalomon49f085d2014-09-05 13:34:00 -0700261 if (fDrawState) {
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000262 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
bsalomon2ed5ef82014-07-07 08:44:05 -0700263 fDrawState->fViewMatrix = fViewMatrix;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000264 SkASSERT(fDrawState->numColorStages() >= fNumColorStages);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000265 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000266 SkASSERT(fDrawState->numCoverageStages() >= numCoverageStages);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000267
268 int i = 0;
269 for (int s = 0; s < fNumColorStages; ++s, ++i) {
egdaniel8cbf3d52014-08-21 06:27:22 -0700270 fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i]);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000271 }
272 for (int s = 0; s < numCoverageStages; ++s, ++i) {
egdaniel8cbf3d52014-08-21 06:27:22 -0700273 fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges[i]);
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000274 }
bsalomon@google.com137f1342013-05-29 21:27:53 +0000275 fDrawState = NULL;
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000276 }
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000277}
278
279void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState,
bsalomon@google.comc7818882013-03-20 19:19:53 +0000280 const SkMatrix& preconcatMatrix) {
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000281 this->restore();
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000282
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000283 SkASSERT(NULL == fDrawState);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000284 if (NULL == drawState || preconcatMatrix.isIdentity()) {
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000285 return;
286 }
bsalomon@google.com137f1342013-05-29 21:27:53 +0000287 fDrawState = drawState;
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000288
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000289 fViewMatrix = drawState->getViewMatrix();
bsalomon2ed5ef82014-07-07 08:44:05 -0700290 drawState->fViewMatrix.preConcat(preconcatMatrix);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000291
292 this->doEffectCoordChanges(preconcatMatrix);
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000293 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000294}
295
bsalomon@google.com137f1342013-05-29 21:27:53 +0000296bool GrDrawState::AutoViewMatrixRestore::setIdentity(GrDrawState* drawState) {
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000297 this->restore();
298
bsalomon@google.com137f1342013-05-29 21:27:53 +0000299 if (NULL == drawState) {
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000300 return false;
skia.committer@gmail.comf467ce72012-10-09 02:01:37 +0000301 }
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000302
bsalomon@google.com137f1342013-05-29 21:27:53 +0000303 if (drawState->getViewMatrix().isIdentity()) {
304 return true;
305 }
306
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000307 fViewMatrix = drawState->getViewMatrix();
joshualitt4dd99882014-11-11 08:51:30 -0800308 if (0 == drawState->numFragmentStages()) {
bsalomon2ed5ef82014-07-07 08:44:05 -0700309 drawState->fViewMatrix.reset();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000310 fDrawState = drawState;
311 fNumColorStages = 0;
312 fSavedCoordChanges.reset(0);
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000313 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000314 return true;
315 } else {
316 SkMatrix inv;
317 if (!fViewMatrix.invert(&inv)) {
318 return false;
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000319 }
bsalomon2ed5ef82014-07-07 08:44:05 -0700320 drawState->fViewMatrix.reset();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000321 fDrawState = drawState;
322 this->doEffectCoordChanges(inv);
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000323 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000324 return true;
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000325 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000326}
327
328void GrDrawState::AutoViewMatrixRestore::doEffectCoordChanges(const SkMatrix& coordChangeMatrix) {
joshualitt4dd99882014-11-11 08:51:30 -0800329 fSavedCoordChanges.reset(fDrawState->numFragmentStages());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000330 int i = 0;
331
332 fNumColorStages = fDrawState->numColorStages();
333 for (int s = 0; s < fNumColorStages; ++s, ++i) {
egdaniel776bdbd2014-08-06 11:07:02 -0700334 fDrawState->getColorStage(s).saveCoordChange(&fSavedCoordChanges[i]);
egdaniel8cbf3d52014-08-21 06:27:22 -0700335 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000336 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000337
338 int numCoverageStages = fDrawState->numCoverageStages();
339 for (int s = 0; s < numCoverageStages; ++s, ++i) {
egdaniel776bdbd2014-08-06 11:07:02 -0700340 fDrawState->getCoverageStage(s).saveCoordChange(&fSavedCoordChanges[i]);
egdaniel8cbf3d52014-08-21 06:27:22 -0700341 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000342 }
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000343}
egdaniel21aed572014-08-26 12:24:06 -0700344
egdaniel170f90b2014-09-16 12:54:40 -0700345////////////////////////////////////////////////////////////////////////////////
346
egdaniel170f90b2014-09-16 12:54:40 -0700347GrDrawState::~GrDrawState() {
egdaniel170f90b2014-09-16 12:54:40 -0700348 SkASSERT(0 == fBlockEffectRemovalCnt);
349}
350
egdaniel89af44a2014-09-26 06:15:04 -0700351////////////////////////////////////////////////////////////////////////////////
352
joshualitt56995b52014-12-11 15:44:02 -0800353bool GrDrawState::willBlendWithDst(const GrPrimitiveProcessor* pp) const {
354 this->calcColorInvariantOutput(pp);
355 this->calcCoverageInvariantOutput(pp);
egdaniel95131432014-12-09 11:15:43 -0800356 return fXPFactory->willBlendWithDst(fColorProcInfo, fCoverageProcInfo,
357 this->isCoverageDrawing(), this->isColorWriteDisabled());
egdanielcd8b6302014-11-11 14:46:05 -0800358}
359
joshualitt56995b52014-12-11 15:44:02 -0800360void GrDrawState::calcColorInvariantOutput(const GrPrimitiveProcessor* pp) const {
361 if (!fColorProcInfoValid || fColorPrimProc != pp) {
362 fColorProcInfo.calcColorWithPrimProc(pp, fColorStages.begin(), this->numColorStages());
363 fColorProcInfoValid = true;
364 fColorPrimProc = pp;
365 }
366}
367
368void GrDrawState::calcCoverageInvariantOutput(const GrPrimitiveProcessor* pp) const {
369 if (!fCoverageProcInfoValid || fCoveragePrimProc != pp) {
370 fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageStages.begin(),
371 this->numCoverageStages());
372 fCoverageProcInfoValid = true;
373 fCoveragePrimProc = pp;
374 }
375}
376
joshualitt2e3b3e32014-12-09 13:31:14 -0800377void GrDrawState::calcColorInvariantOutput(GrColor color) const {
378 if (!fColorProcInfoValid || color != fColorCache) {
joshualitt56995b52014-12-11 15:44:02 -0800379 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags;
380 fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColorStages(), color,
381 flags, false);
egdanielb6cbc382014-11-13 11:00:34 -0800382 fColorProcInfoValid = true;
joshualitt2e3b3e32014-12-09 13:31:14 -0800383 fColorCache = color;
egdanielb6cbc382014-11-13 11:00:34 -0800384 }
385}
386
joshualitt2e3b3e32014-12-09 13:31:14 -0800387void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const {
388 if (!fCoverageProcInfoValid || coverage != fCoverageCache) {
joshualitt56995b52014-12-11 15:44:02 -0800389 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags;
390 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(),
391 this->numCoverageStages(), coverage, flags,
392 true);
egdanielb6cbc382014-11-13 11:00:34 -0800393 fCoverageProcInfoValid = true;
joshualitt2e3b3e32014-12-09 13:31:14 -0800394 fCoverageCache = coverage;
egdanielb6cbc382014-11-13 11:00:34 -0800395 }
396}