Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: src/gpu/GrDrawState.cpp

Issue 791743003: Remove GP from drawstate, revision of invariant output for GP (Closed) Base URL: https://skia.googlesource.com/skia.git@color-to-gp
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrDrawState.h" 8 #include "GrDrawState.h"
9 9
10 #include "GrBlend.h" 10 #include "GrBlend.h"
11 #include "GrOptDrawState.h" 11 #include "GrOptDrawState.h"
12 #include "GrPaint.h" 12 #include "GrPaint.h"
13 #include "GrProcOptInfo.h" 13 #include "GrProcOptInfo.h"
14 #include "GrXferProcessor.h" 14 #include "GrXferProcessor.h"
15 #include "effects/GrPorterDuffXferProcessor.h" 15 #include "effects/GrPorterDuffXferProcessor.h"
16 16
17 bool GrDrawState::isEqual(const GrDrawState& that) const { 17 bool GrDrawState::isEqual(const GrDrawState& that, bool explicitLocalCoords) con st {
18 if (this->getRenderTarget() != that.getRenderTarget() || 18 if (this->getRenderTarget() != that.getRenderTarget() ||
19 this->fColorStages.count() != that.fColorStages.count() || 19 this->fColorStages.count() != that.fColorStages.count() ||
20 this->fCoverageStages.count() != that.fCoverageStages.count() || 20 this->fCoverageStages.count() != that.fCoverageStages.count() ||
21 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || 21 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) ||
22 this->fFlagBits != that.fFlagBits || 22 this->fFlagBits != that.fFlagBits ||
23 this->fStencilSettings != that.fStencilSettings || 23 this->fStencilSettings != that.fStencilSettings ||
24 this->fDrawFace != that.fDrawFace) { 24 this->fDrawFace != that.fDrawFace) {
25 return false; 25 return false;
26 } 26 }
27 27
28 bool explicitLocalCoords = this->hasLocalCoordAttribute();
29 if (this->hasGeometryProcessor()) {
30 if (!that.hasGeometryProcessor()) {
31 return false;
32 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProce ssor())) {
33 return false;
34 }
35 } else if (that.hasGeometryProcessor()) {
36 return false;
37 }
38
39 if (!this->getXPFactory()->isEqual(*that.getXPFactory())) { 28 if (!this->getXPFactory()->isEqual(*that.getXPFactory())) {
40 return false; 29 return false;
41 } 30 }
42 31
43 for (int i = 0; i < this->numColorStages(); i++) { 32 for (int i = 0; i < this->numColorStages(); i++) {
44 if (!GrFragmentStage::AreCompatible(this->getColorStage(i), that.getColo rStage(i), 33 if (!GrFragmentStage::AreCompatible(this->getColorStage(i), that.getColo rStage(i),
45 explicitLocalCoords)) { 34 explicitLocalCoords)) {
46 return false; 35 return false;
47 } 36 }
48 } 37 }
(...skipping 21 matching lines...) Expand all
70 } 59 }
71 } 60 }
72 } 61 }
73 62
74 GrDrawState& GrDrawState::operator=(const GrDrawState& that) { 63 GrDrawState& GrDrawState::operator=(const GrDrawState& that) {
75 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get())); 64 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get()));
76 fViewMatrix = that.fViewMatrix; 65 fViewMatrix = that.fViewMatrix;
77 fFlagBits = that.fFlagBits; 66 fFlagBits = that.fFlagBits;
78 fStencilSettings = that.fStencilSettings; 67 fStencilSettings = that.fStencilSettings;
79 fDrawFace = that.fDrawFace; 68 fDrawFace = that.fDrawFace;
80 fGeometryProcessor.reset(SkSafeRef(that.fGeometryProcessor.get()));
81 fXPFactory.reset(SkRef(that.getXPFactory())); 69 fXPFactory.reset(SkRef(that.getXPFactory()));
82 fColorStages = that.fColorStages; 70 fColorStages = that.fColorStages;
83 fCoverageStages = that.fCoverageStages; 71 fCoverageStages = that.fCoverageStages;
84 72
85 fHints = that.fHints; 73 fHints = that.fHints;
86 74
87 fColorProcInfoValid = that.fColorProcInfoValid; 75 fColorProcInfoValid = that.fColorProcInfoValid;
88 fCoverageProcInfoValid = that.fCoverageProcInfoValid; 76 fCoverageProcInfoValid = that.fCoverageProcInfoValid;
89 if (fColorProcInfoValid) { 77 if (fColorProcInfoValid) {
90 fColorProcInfo = that.fColorProcInfo; 78 fColorProcInfo = that.fColorProcInfo;
91 } 79 }
92 if (fCoverageProcInfoValid) { 80 if (fCoverageProcInfoValid) {
93 fCoverageProcInfo = that.fCoverageProcInfo; 81 fCoverageProcInfo = that.fCoverageProcInfo;
94 } 82 }
95 return *this; 83 return *this;
96 } 84 }
97 85
98 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { 86 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) {
99 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); 87 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages());
100 fRenderTarget.reset(NULL); 88 fRenderTarget.reset(NULL);
101 89
102 fGeometryProcessor.reset(NULL);
103 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); 90 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
104 fColorStages.reset(); 91 fColorStages.reset();
105 fCoverageStages.reset(); 92 fCoverageStages.reset();
106 93
107 if (NULL == initialViewMatrix) { 94 if (NULL == initialViewMatrix) {
108 fViewMatrix.reset(); 95 fViewMatrix.reset();
109 } else { 96 } else {
110 fViewMatrix = *initialViewMatrix; 97 fViewMatrix = *initialViewMatrix;
111 } 98 }
112 fFlagBits = 0x0; 99 fFlagBits = 0x0;
(...skipping 18 matching lines...) Expand all
131 } 118 }
132 for (int s = 0; s < this->numCoverageStages(); ++s) { 119 for (int s = 0; s < this->numCoverageStages(); ++s) {
133 fCoverageStages[s].localCoordChange(invVM); 120 fCoverageStages[s].localCoordChange(invVM);
134 } 121 }
135 } 122 }
136 fViewMatrix.reset(); 123 fViewMatrix.reset();
137 return true; 124 return true;
138 } 125 }
139 126
140 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende rTarget* rt) { 127 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende rTarget* rt) {
141 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); 128 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages());
142 129
143 fGeometryProcessor.reset(NULL);
144 fColorStages.reset(); 130 fColorStages.reset();
145 fCoverageStages.reset(); 131 fCoverageStages.reset();
146 132
147 for (int i = 0; i < paint.numColorStages(); ++i) { 133 for (int i = 0; i < paint.numColorStages(); ++i) {
148 fColorStages.push_back(paint.getColorStage(i)); 134 fColorStages.push_back(paint.getColorStage(i));
149 } 135 }
150 136
151 for (int i = 0; i < paint.numCoverageStages(); ++i) { 137 for (int i = 0; i < paint.numCoverageStages(); ++i) {
152 fCoverageStages.push_back(paint.getCoverageStage(i)); 138 fCoverageStages.push_back(paint.getCoverageStage(i));
153 } 139 }
(...skipping 20 matching lines...) Expand all
174 fCoverageProcInfoValid = false; 160 fCoverageProcInfoValid = false;
175 } 161 }
176 162
177 //////////////////////////////////////////////////////////////////////////////// 163 ////////////////////////////////////////////////////////////////////////////////
178 164
179 bool GrDrawState::canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCa ps& caps) const { 165 bool GrDrawState::canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCa ps& caps) const {
180 if (caps.dualSourceBlendingSupport()) { 166 if (caps.dualSourceBlendingSupport()) {
181 return true; 167 return true;
182 } 168 }
183 169
184 this->calcColorInvariantOutput(color); 170 this->calcColorInvariantOutput(NULL, color);
185 171
186 // The coverage isn't actually white, its unknown, but this will produce the same effect 172 // The coverage isn't actually white, its unknown, but this will produce the same effect
187 // TODO we want to cache the result of this call, but we can probably clean up the interface 173 // TODO we want to cache the result of this call, but we can probably clean up the interface
188 // so we don't have to pass in a seemingly known coverage 174 // so we don't have to pass in a seemingly known coverage
189 this->calcCoverageInvariantOutput(GrColor_WHITE); 175 this->calcCoverageInvariantOutput(NULL, GrColor_WHITE);
190 return fXPFactory->canApplyCoverage(fColorProcInfo, fCoverageProcInfo, 176 return fXPFactory->canApplyCoverage(fColorProcInfo, fCoverageProcInfo,
191 this->isCoverageDrawing(), this->isColor WriteDisabled()); 177 this->isCoverageDrawing(), this->isColor WriteDisabled());
192 } 178 }
193 179
194 bool GrDrawState::hasSolidCoverage(GrColor coverage) const { 180 bool GrDrawState::hasSolidCoverage(const GrPrimitiveProcessor* pp, GrColor cover age) const {
195 // If we're drawing coverage directly then coverage is effectively treated a s color. 181 // If we're drawing coverage directly then coverage is effectively treated a s color.
196 if (this->isCoverageDrawing()) { 182 if (this->isCoverageDrawing()) {
197 return true; 183 return true;
198 } 184 }
199 185
200 if (this->numCoverageStages() > 0) { 186 if (this->numCoverageStages() > 0) {
201 return false; 187 return false;
202 } 188 }
203 189
204 this->calcCoverageInvariantOutput(coverage); 190 this->calcCoverageInvariantOutput(pp, coverage);
205 return fCoverageProcInfo.isSolidWhite(); 191 return fCoverageProcInfo.isSolidWhite();
206 } 192 }
207 193
208 //////////////////////////////////////////////////////////////////////////////s 194 //////////////////////////////////////////////////////////////////////////////s
209 195
210 bool GrDrawState::willEffectReadDstColor(GrColor color, GrColor coverage) const { 196 bool GrDrawState::willEffectReadDstColor(const GrPrimitiveProcessor* pp,
211 this->calcColorInvariantOutput(color); 197 GrColor color,
212 this->calcCoverageInvariantOutput(coverage); 198 GrColor coverage) const {
199 this->calcColorInvariantOutput(pp, color);
200 this->calcCoverageInvariantOutput(pp, coverage);
213 // TODO: Remove need to create the XP here. 201 // TODO: Remove need to create the XP here.
214 // Also once all custom blends are turned into XPs we can remove the n eed 202 // Also once all custom blends are turned into XPs we can remove the n eed
215 // to check other stages since only xp's will be able to read dst 203 // to check other stages since only xp's will be able to read dst
216 SkAutoTUnref<GrXferProcessor> xferProcessor(fXPFactory->createXferProcessor( fColorProcInfo, 204 SkAutoTUnref<GrXferProcessor> xferProcessor(fXPFactory->createXferProcessor( fColorProcInfo,
217 fCoverageProcInfo)); 205 fCoverageProcInfo));
218 if (xferProcessor && xferProcessor->willReadDstColor()) { 206 if (xferProcessor && xferProcessor->willReadDstColor()) {
219 return true; 207 return true;
220 } 208 }
221 209
222 if (!this->isColorWriteDisabled()) { 210 if (!this->isColorWriteDisabled()) {
223 if (fColorProcInfo.readsDst()) { 211 if (fColorProcInfo.readsDst()) {
224 return true; 212 return true;
225 } 213 }
226 } 214 }
227 return fCoverageProcInfo.readsDst(); 215 return fCoverageProcInfo.readsDst();
228 } 216 }
229 217
230 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { 218 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
231 if (fDrawState) { 219 if (fDrawState) {
232 // See the big comment on the class definition about GPs.
233 if (SK_InvalidUniqueID == fOriginalGPID) {
234 fDrawState->fGeometryProcessor.reset(NULL);
235 } else {
236 SkASSERT(fDrawState->getGeometryProcessor()->getUniqueID() ==
237 fOriginalGPID);
238 fOriginalGPID = SK_InvalidUniqueID;
239 }
240
241 int m = fDrawState->numColorStages() - fColorEffectCnt; 220 int m = fDrawState->numColorStages() - fColorEffectCnt;
242 SkASSERT(m >= 0); 221 SkASSERT(m >= 0);
243 fDrawState->fColorStages.pop_back_n(m); 222 fDrawState->fColorStages.pop_back_n(m);
244 223
245 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt; 224 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt;
246 SkASSERT(n >= 0); 225 SkASSERT(n >= 0);
247 fDrawState->fCoverageStages.pop_back_n(n); 226 fDrawState->fCoverageStages.pop_back_n(n);
248 if (m + n > 0) { 227 if (m + n > 0) {
249 fDrawState->fColorProcInfoValid = false; 228 fDrawState->fColorProcInfoValid = false;
250 fDrawState->fCoverageProcInfoValid = false; 229 fDrawState->fCoverageProcInfoValid = false;
251 } 230 }
252 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) 231 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
253 } 232 }
254 fDrawState = ds; 233 fDrawState = ds;
255 if (NULL != ds) { 234 if (NULL != ds) {
256 SkASSERT(SK_InvalidUniqueID == fOriginalGPID);
257 if (NULL != ds->getGeometryProcessor()) {
258 fOriginalGPID = ds->getGeometryProcessor()->getUniqueID();
259 }
260 fColorEffectCnt = ds->numColorStages(); 235 fColorEffectCnt = ds->numColorStages();
261 fCoverageEffectCnt = ds->numCoverageStages(); 236 fCoverageEffectCnt = ds->numCoverageStages();
262 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;) 237 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;)
263 } 238 }
264 } 239 }
265 240
266 //////////////////////////////////////////////////////////////////////////////// 241 ////////////////////////////////////////////////////////////////////////////////
267 242
268 // Some blend modes allow folding a fractional coverage value into the color's a lpha channel, while 243 // Some blend modes allow folding a fractional coverage value into the color's a lpha channel, while
269 // others will blend incorrectly. 244 // others will blend incorrectly.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 } 334 }
360 335
361 //////////////////////////////////////////////////////////////////////////////// 336 ////////////////////////////////////////////////////////////////////////////////
362 337
363 GrDrawState::~GrDrawState() { 338 GrDrawState::~GrDrawState() {
364 SkASSERT(0 == fBlockEffectRemovalCnt); 339 SkASSERT(0 == fBlockEffectRemovalCnt);
365 } 340 }
366 341
367 //////////////////////////////////////////////////////////////////////////////// 342 ////////////////////////////////////////////////////////////////////////////////
368 343
369 bool GrDrawState::srcAlphaWillBeOne(GrColor color, GrColor coverage) const { 344 bool GrDrawState::willBlendWithDst(const GrPrimitiveProcessor* pp,
370 this->calcColorInvariantOutput(color); 345 GrColor color,
371 if (this->isCoverageDrawing()) { 346 GrColor coverage) const {
372 this->calcCoverageInvariantOutput(coverage); 347 this->calcColorInvariantOutput(pp, color);
373 return (fColorProcInfo.isOpaque() && fCoverageProcInfo.isOpaque()); 348 this->calcCoverageInvariantOutput(pp, coverage);
374 }
375 return fColorProcInfo.isOpaque();
376 }
377
378 bool GrDrawState::willBlendWithDst(GrColor color, GrColor coverage) const {
379 this->calcColorInvariantOutput(color);
380 this->calcCoverageInvariantOutput(coverage);
381 return fXPFactory->willBlendWithDst(fColorProcInfo, fCoverageProcInfo, 349 return fXPFactory->willBlendWithDst(fColorProcInfo, fCoverageProcInfo,
382 this->isCoverageDrawing(), this->isColor WriteDisabled()); 350 this->isCoverageDrawing(), this->isColor WriteDisabled());
383 } 351 }
384 352
385 void GrDrawState::calcColorInvariantOutput(GrColor color) const { 353 void GrDrawState::calcColorInvariantOutput(const GrPrimitiveProcessor* pp, GrCol or color) const {
386 if (!fColorProcInfoValid || color != fColorCache) { 354 if (!fColorProcInfoValid || color != fColorCache || fColorPrimProc != pp) {
387 GrColorComponentFlags flags; 355 if (pp) {
388 if (this->hasColorVertexAttribute()) { 356 fColorProcInfo.calcColorWithPrimProc(pp, fColorStages.begin(), this- >numColorStages());
389 if (fHints & kVertexColorsAreOpaque_Hint) {
390 flags = kA_GrColorComponentFlag;
391 color = 0xFF << GrColor_SHIFT_A;
392 } else {
393 flags = static_cast<GrColorComponentFlags>(0);
394 color = 0;
395 }
396 } else { 357 } else {
397 flags = kRGBA_GrColorComponentFlags; 358 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags;
359 fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->num ColorStages(),
360 color, flags, false);
398 } 361 }
399 fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColo rStages(),
400 color, flags, false);
401 fColorProcInfoValid = true; 362 fColorProcInfoValid = true;
402 fColorCache = color; 363 fColorCache = color;
364 fColorPrimProc = pp;
403 } 365 }
404 } 366 }
405 367
406 void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const { 368 void GrDrawState::calcCoverageInvariantOutput(const GrPrimitiveProcessor* pp,
407 if (!fCoverageProcInfoValid || coverage != fCoverageCache) { 369 GrColor coverage) const {
408 GrColorComponentFlags flags; 370 if (!fCoverageProcInfoValid || coverage != fCoverageCache || fCoveragePrimPr oc != pp) {
409 // Check if per-vertex or constant color may have partial alpha 371 if (pp) {
410 if (this->hasCoverageVertexAttribute()) { 372 fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageStages.begin (),
411 flags = static_cast<GrColorComponentFlags>(0); 373 this->numCoverageStages() );
412 coverage = 0;
413 } else { 374 } else {
414 flags = kRGBA_GrColorComponentFlags; 375 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags;
376 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(),
377 this->numCoverageStages(), c overage, flags,
378 true);
415 } 379 }
416 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->n umCoverageStages(),
417 coverage, flags, true, fGeometry Processor.get());
418 fCoverageProcInfoValid = true; 380 fCoverageProcInfoValid = true;
419 fCoverageCache = coverage; 381 fCoverageCache = coverage;
382 fCoveragePrimProc = pp;
420 } 383 }
421 } 384 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698