blob: b04d505b0f7cae5aff6efb5ee7ff540e60246897 [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;
egdanielb6cbc382014-11-13 11:00:34 -080077 if (fColorProcInfoValid) {
78 fColorProcInfo = that.fColorProcInfo;
79 }
80 if (fCoverageProcInfoValid) {
81 fCoverageProcInfo = that.fCoverageProcInfo;
82 }
bsalomon8f727332014-08-05 07:50:06 -070083 return *this;
84}
85
86void GrDrawState::onReset(const SkMatrix* initialViewMatrix) {
joshualitt56995b52014-12-11 15:44:02 -080087 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages());
bsalomonae59b772014-11-19 08:23:49 -080088 fRenderTarget.reset(NULL);
bsalomon2a9ca782014-09-05 14:27:43 -070089
egdanielc016fb82014-12-03 11:41:54 -080090 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
egdaniel8cbf3d52014-08-21 06:27:22 -070091 fColorStages.reset();
92 fCoverageStages.reset();
bsalomon8f727332014-08-05 07:50:06 -070093
bsalomon8f727332014-08-05 07:50:06 -070094 if (NULL == initialViewMatrix) {
95 fViewMatrix.reset();
96 } else {
97 fViewMatrix = *initialViewMatrix;
98 }
bsalomon8f727332014-08-05 07:50:06 -070099 fFlagBits = 0x0;
100 fStencilSettings.setDisabled();
bsalomon8f727332014-08-05 07:50:06 -0700101 fDrawFace = kBoth_DrawFace;
102
egdanielb6cbc382014-11-13 11:00:34 -0800103 fColorProcInfoValid = false;
104 fCoverageProcInfoValid = false;
joshualitt9b338222014-12-10 12:28:08 -0800105
106 fColorCache = GrColor_ILLEGAL;
107 fCoverageCache = GrColor_ILLEGAL;
joshualitt56995b52014-12-11 15:44:02 -0800108
109 fColorPrimProc = NULL;
110 fCoveragePrimProc = NULL;
111
bsalomon8f727332014-08-05 07:50:06 -0700112}
113
bsalomon@google.com137f1342013-05-29 21:27:53 +0000114bool GrDrawState::setIdentityViewMatrix() {
joshualitt4dd99882014-11-11 08:51:30 -0800115 if (this->numFragmentStages()) {
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000116 SkMatrix invVM;
bsalomon2ed5ef82014-07-07 08:44:05 -0700117 if (!fViewMatrix.invert(&invVM)) {
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000118 // sad trombone sound
119 return false;
120 }
egdaniel776bdbd2014-08-06 11:07:02 -0700121 for (int s = 0; s < this->numColorStages(); ++s) {
egdaniel8cbf3d52014-08-21 06:27:22 -0700122 fColorStages[s].localCoordChange(invVM);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000123 }
egdaniel776bdbd2014-08-06 11:07:02 -0700124 for (int s = 0; s < this->numCoverageStages(); ++s) {
egdaniel8cbf3d52014-08-21 06:27:22 -0700125 fCoverageStages[s].localCoordChange(invVM);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000126 }
127 }
bsalomon2ed5ef82014-07-07 08:44:05 -0700128 fViewMatrix.reset();
bsalomon@google.com137f1342013-05-29 21:27:53 +0000129 return true;
130}
131
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +0000132void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRenderTarget* rt) {
joshualitt56995b52014-12-11 15:44:02 -0800133 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000134
egdaniel8cbf3d52014-08-21 06:27:22 -0700135 fColorStages.reset();
136 fCoverageStages.reset();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000137
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +0000138 for (int i = 0; i < paint.numColorStages(); ++i) {
egdaniel8cbf3d52014-08-21 06:27:22 -0700139 fColorStages.push_back(paint.getColorStage(i));
bsalomon@google.comaf84e742012-10-05 13:23:24 +0000140 }
141
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +0000142 for (int i = 0; i < paint.numCoverageStages(); ++i) {
egdaniel8cbf3d52014-08-21 06:27:22 -0700143 fCoverageStages.push_back(paint.getCoverageStage(i));
bsalomon@google.comaf84e742012-10-05 13:23:24 +0000144 }
145
egdaniel378092f2014-12-03 10:40:13 -0800146 fXPFactory.reset(SkRef(paint.getXPFactory()));
147
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +0000148 this->setRenderTarget(rt);
bsalomon@google.comaf84e742012-10-05 13:23:24 +0000149
bsalomon2ed5ef82014-07-07 08:44:05 -0700150 fViewMatrix = vm;
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +0000151
152 // These have no equivalent in GrPaint, set them to defaults
bsalomon2ed5ef82014-07-07 08:44:05 -0700153 fDrawFace = kBoth_DrawFace;
154 fStencilSettings.setDisabled();
bsalomon04ddf892014-11-19 12:36:22 -0800155 fFlagBits = 0;
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +0000156
bsalomon@google.com21c10c52013-06-13 17:44:07 +0000157 // Enable the clip bit
158 this->enableState(GrDrawState::kClip_StateBit);
159
bsalomon@google.comc7448ce2012-10-05 19:04:13 +0000160 this->setState(GrDrawState::kDither_StateBit, paint.isDither());
161 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias());
bsalomon@google.comaf84e742012-10-05 13:23:24 +0000162
egdanielb6cbc382014-11-13 11:00:34 -0800163 fColorProcInfoValid = false;
164 fCoverageProcInfoValid = false;
joshualitt2e3b3e32014-12-09 13:31:14 -0800165
166 fColorCache = GrColor_ILLEGAL;
167 fCoverageCache = GrColor_ILLEGAL;
bsalomon@google.comaf84e742012-10-05 13:23:24 +0000168}
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000169
170////////////////////////////////////////////////////////////////////////////////
171
joshualitt2e3b3e32014-12-09 13:31:14 -0800172bool GrDrawState::canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCaps& caps) const {
bsalomon62c447d2014-08-08 08:08:50 -0700173 if (caps.dualSourceBlendingSupport()) {
174 return true;
175 }
egdaniel95131432014-12-09 11:15:43 -0800176
joshualitt2e3b3e32014-12-09 13:31:14 -0800177 this->calcColorInvariantOutput(color);
178
179 // The coverage isn't actually white, its unknown, but this will produce the same effect
180 // TODO we want to cache the result of this call, but we can probably clean up the interface
181 // so we don't have to pass in a seemingly known coverage
182 this->calcCoverageInvariantOutput(GrColor_WHITE);
egdaniel95131432014-12-09 11:15:43 -0800183 return fXPFactory->canApplyCoverage(fColorProcInfo, fCoverageProcInfo,
184 this->isCoverageDrawing(), this->isColorWriteDisabled());
bsalomon62c447d2014-08-08 08:08:50 -0700185}
186
joshualitt56995b52014-12-11 15:44:02 -0800187bool GrDrawState::hasSolidCoverage(const GrPrimitiveProcessor* pp) const {
egdaniel89af44a2014-09-26 06:15:04 -0700188 // If we're drawing coverage directly then coverage is effectively treated as color.
189 if (this->isCoverageDrawing()) {
190 return true;
191 }
192
joshualitt4dd99882014-11-11 08:51:30 -0800193 if (this->numCoverageStages() > 0) {
194 return false;
195 }
196
joshualitt56995b52014-12-11 15:44:02 -0800197 this->calcCoverageInvariantOutput(pp);
egdanielb6cbc382014-11-13 11:00:34 -0800198 return fCoverageProcInfo.isSolidWhite();
egdaniel89af44a2014-09-26 06:15:04 -0700199}
200
egdaniel21aed572014-08-26 12:24:06 -0700201//////////////////////////////////////////////////////////////////////////////s
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000202
joshualitt56995b52014-12-11 15:44:02 -0800203bool GrDrawState::willEffectReadDstColor(const GrPrimitiveProcessor* pp) const {
204 this->calcColorInvariantOutput(pp);
205 this->calcCoverageInvariantOutput(pp);
egdaniel95131432014-12-09 11:15:43 -0800206 // TODO: Remove need to create the XP here.
207 // Also once all custom blends are turned into XPs we can remove the need
208 // to check other stages since only xp's will be able to read dst
209 SkAutoTUnref<GrXferProcessor> xferProcessor(fXPFactory->createXferProcessor(fColorProcInfo,
210 fCoverageProcInfo));
211 if (xferProcessor && xferProcessor->willReadDstColor()) {
212 return true;
213 }
214
egdaniel89af44a2014-09-26 06:15:04 -0700215 if (!this->isColorWriteDisabled()) {
egdanielb6cbc382014-11-13 11:00:34 -0800216 if (fColorProcInfo.readsDst()) {
egdaniel89af44a2014-09-26 06:15:04 -0700217 return true;
218 }
219 }
egdanielb6cbc382014-11-13 11:00:34 -0800220 return fCoverageProcInfo.readsDst();
egdaniel89af44a2014-09-26 06:15:04 -0700221}
222
egdaniel21aed572014-08-26 12:24:06 -0700223void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
bsalomon49f085d2014-09-05 13:34:00 -0700224 if (fDrawState) {
egdaniel21aed572014-08-26 12:24:06 -0700225 int m = fDrawState->numColorStages() - fColorEffectCnt;
226 SkASSERT(m >= 0);
227 fDrawState->fColorStages.pop_back_n(m);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000228
egdaniel21aed572014-08-26 12:24:06 -0700229 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt;
230 SkASSERT(n >= 0);
231 fDrawState->fCoverageStages.pop_back_n(n);
egdanielb6cbc382014-11-13 11:00:34 -0800232 if (m + n > 0) {
233 fDrawState->fColorProcInfoValid = false;
234 fDrawState->fCoverageProcInfoValid = false;
235 }
egdaniel21aed572014-08-26 12:24:06 -0700236 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000237 }
egdaniel21aed572014-08-26 12:24:06 -0700238 fDrawState = ds;
239 if (NULL != ds) {
240 fColorEffectCnt = ds->numColorStages();
241 fCoverageEffectCnt = ds->numCoverageStages();
242 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;)
243 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000244}
245
jvanverth@google.comcc782382013-01-28 20:39:48 +0000246////////////////////////////////////////////////////////////////////////////////
247
egdaniel89af44a2014-09-26 06:15:04 -0700248// Some blend modes allow folding a fractional coverage value into the color's alpha channel, while
249// others will blend incorrectly.
250bool GrDrawState::canTweakAlphaForCoverage() const {
egdaniel95131432014-12-09 11:15:43 -0800251 return fXPFactory->canTweakAlphaForCoverage(this->isCoverageDrawing());
egdaniel89af44a2014-09-26 06:15:04 -0700252}
253
254////////////////////////////////////////////////////////////////////////////////
255
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000256void GrDrawState::AutoViewMatrixRestore::restore() {
bsalomon49f085d2014-09-05 13:34:00 -0700257 if (fDrawState) {
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000258 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
bsalomon2ed5ef82014-07-07 08:44:05 -0700259 fDrawState->fViewMatrix = fViewMatrix;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000260 SkASSERT(fDrawState->numColorStages() >= fNumColorStages);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000261 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000262 SkASSERT(fDrawState->numCoverageStages() >= numCoverageStages);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000263
264 int i = 0;
265 for (int s = 0; s < fNumColorStages; ++s, ++i) {
egdaniel8cbf3d52014-08-21 06:27:22 -0700266 fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i]);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000267 }
268 for (int s = 0; s < numCoverageStages; ++s, ++i) {
egdaniel8cbf3d52014-08-21 06:27:22 -0700269 fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges[i]);
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000270 }
bsalomon@google.com137f1342013-05-29 21:27:53 +0000271 fDrawState = NULL;
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000272 }
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000273}
274
275void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState,
bsalomon@google.comc7818882013-03-20 19:19:53 +0000276 const SkMatrix& preconcatMatrix) {
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000277 this->restore();
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000278
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000279 SkASSERT(NULL == fDrawState);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000280 if (NULL == drawState || preconcatMatrix.isIdentity()) {
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000281 return;
282 }
bsalomon@google.com137f1342013-05-29 21:27:53 +0000283 fDrawState = drawState;
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000284
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000285 fViewMatrix = drawState->getViewMatrix();
bsalomon2ed5ef82014-07-07 08:44:05 -0700286 drawState->fViewMatrix.preConcat(preconcatMatrix);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000287
288 this->doEffectCoordChanges(preconcatMatrix);
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000289 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000290}
291
bsalomon@google.com137f1342013-05-29 21:27:53 +0000292bool GrDrawState::AutoViewMatrixRestore::setIdentity(GrDrawState* drawState) {
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000293 this->restore();
294
bsalomon@google.com137f1342013-05-29 21:27:53 +0000295 if (NULL == drawState) {
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000296 return false;
skia.committer@gmail.comf467ce72012-10-09 02:01:37 +0000297 }
bsalomon@google.com2fdcdeb2012-10-08 17:15:55 +0000298
bsalomon@google.com137f1342013-05-29 21:27:53 +0000299 if (drawState->getViewMatrix().isIdentity()) {
300 return true;
301 }
302
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000303 fViewMatrix = drawState->getViewMatrix();
joshualitt4dd99882014-11-11 08:51:30 -0800304 if (0 == drawState->numFragmentStages()) {
bsalomon2ed5ef82014-07-07 08:44:05 -0700305 drawState->fViewMatrix.reset();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000306 fDrawState = drawState;
307 fNumColorStages = 0;
308 fSavedCoordChanges.reset(0);
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000309 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000310 return true;
311 } else {
312 SkMatrix inv;
313 if (!fViewMatrix.invert(&inv)) {
314 return false;
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000315 }
bsalomon2ed5ef82014-07-07 08:44:05 -0700316 drawState->fViewMatrix.reset();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000317 fDrawState = drawState;
318 this->doEffectCoordChanges(inv);
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000319 SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000320 return true;
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000321 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000322}
323
324void GrDrawState::AutoViewMatrixRestore::doEffectCoordChanges(const SkMatrix& coordChangeMatrix) {
joshualitt4dd99882014-11-11 08:51:30 -0800325 fSavedCoordChanges.reset(fDrawState->numFragmentStages());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000326 int i = 0;
327
328 fNumColorStages = fDrawState->numColorStages();
329 for (int s = 0; s < fNumColorStages; ++s, ++i) {
egdaniel776bdbd2014-08-06 11:07:02 -0700330 fDrawState->getColorStage(s).saveCoordChange(&fSavedCoordChanges[i]);
egdaniel8cbf3d52014-08-21 06:27:22 -0700331 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000332 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000333
334 int numCoverageStages = fDrawState->numCoverageStages();
335 for (int s = 0; s < numCoverageStages; ++s, ++i) {
egdaniel776bdbd2014-08-06 11:07:02 -0700336 fDrawState->getCoverageStage(s).saveCoordChange(&fSavedCoordChanges[i]);
egdaniel8cbf3d52014-08-21 06:27:22 -0700337 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000338 }
bsalomon@google.com5b3e8902012-10-05 20:13:28 +0000339}
egdaniel21aed572014-08-26 12:24:06 -0700340
egdaniel170f90b2014-09-16 12:54:40 -0700341////////////////////////////////////////////////////////////////////////////////
342
egdaniel170f90b2014-09-16 12:54:40 -0700343GrDrawState::~GrDrawState() {
egdaniel170f90b2014-09-16 12:54:40 -0700344 SkASSERT(0 == fBlockEffectRemovalCnt);
345}
346
egdaniel89af44a2014-09-26 06:15:04 -0700347////////////////////////////////////////////////////////////////////////////////
348
joshualitt56995b52014-12-11 15:44:02 -0800349bool GrDrawState::willBlendWithDst(const GrPrimitiveProcessor* pp) const {
350 this->calcColorInvariantOutput(pp);
351 this->calcCoverageInvariantOutput(pp);
egdaniel95131432014-12-09 11:15:43 -0800352 return fXPFactory->willBlendWithDst(fColorProcInfo, fCoverageProcInfo,
353 this->isCoverageDrawing(), this->isColorWriteDisabled());
egdanielcd8b6302014-11-11 14:46:05 -0800354}
355
joshualitt56995b52014-12-11 15:44:02 -0800356void GrDrawState::calcColorInvariantOutput(const GrPrimitiveProcessor* pp) const {
357 if (!fColorProcInfoValid || fColorPrimProc != pp) {
358 fColorProcInfo.calcColorWithPrimProc(pp, fColorStages.begin(), this->numColorStages());
359 fColorProcInfoValid = true;
360 fColorPrimProc = pp;
361 }
362}
363
364void GrDrawState::calcCoverageInvariantOutput(const GrPrimitiveProcessor* pp) const {
365 if (!fCoverageProcInfoValid || fCoveragePrimProc != pp) {
366 fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageStages.begin(),
367 this->numCoverageStages());
368 fCoverageProcInfoValid = true;
369 fCoveragePrimProc = pp;
370 }
371}
372
joshualitt2e3b3e32014-12-09 13:31:14 -0800373void GrDrawState::calcColorInvariantOutput(GrColor color) const {
374 if (!fColorProcInfoValid || color != fColorCache) {
joshualitt56995b52014-12-11 15:44:02 -0800375 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags;
376 fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColorStages(), color,
377 flags, false);
egdanielb6cbc382014-11-13 11:00:34 -0800378 fColorProcInfoValid = true;
joshualitt2e3b3e32014-12-09 13:31:14 -0800379 fColorCache = color;
egdanielb6cbc382014-11-13 11:00:34 -0800380 }
381}
382
joshualitt2e3b3e32014-12-09 13:31:14 -0800383void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const {
384 if (!fCoverageProcInfoValid || coverage != fCoverageCache) {
joshualitt56995b52014-12-11 15:44:02 -0800385 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags;
386 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(),
387 this->numCoverageStages(), coverage, flags,
388 true);
egdanielb6cbc382014-11-13 11:00:34 -0800389 fCoverageProcInfoValid = true;
joshualitt2e3b3e32014-12-09 13:31:14 -0800390 fCoverageCache = coverage;
egdanielb6cbc382014-11-13 11:00:34 -0800391 }
392}