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

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: more windows fix 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
« no previous file with comments | « src/gpu/GrDrawState.h ('k') | src/gpu/GrDrawTarget.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
86
87 fColorProcInfoValid = that.fColorProcInfoValid; 73 fColorProcInfoValid = that.fColorProcInfoValid;
88 fCoverageProcInfoValid = that.fCoverageProcInfoValid; 74 fCoverageProcInfoValid = that.fCoverageProcInfoValid;
89 fColorCache = that.fColorCache; 75 fColorCache = that.fColorCache;
90 fCoverageCache = that.fCoverageCache; 76 fCoverageCache = that.fCoverageCache;
91 if (fColorProcInfoValid) { 77 if (fColorProcInfoValid) {
92 fColorProcInfo = that.fColorProcInfo; 78 fColorProcInfo = that.fColorProcInfo;
93 } 79 }
94 if (fCoverageProcInfoValid) { 80 if (fCoverageProcInfoValid) {
95 fCoverageProcInfo = that.fCoverageProcInfo; 81 fCoverageProcInfo = that.fCoverageProcInfo;
96 } 82 }
97 return *this; 83 return *this;
98 } 84 }
99 85
100 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { 86 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) {
101 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); 87 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages());
102 fRenderTarget.reset(NULL); 88 fRenderTarget.reset(NULL);
103 89
104 fGeometryProcessor.reset(NULL);
105 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); 90 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
106 fColorStages.reset(); 91 fColorStages.reset();
107 fCoverageStages.reset(); 92 fCoverageStages.reset();
108 93
109 if (NULL == initialViewMatrix) { 94 if (NULL == initialViewMatrix) {
110 fViewMatrix.reset(); 95 fViewMatrix.reset();
111 } else { 96 } else {
112 fViewMatrix = *initialViewMatrix; 97 fViewMatrix = *initialViewMatrix;
113 } 98 }
114 fFlagBits = 0x0; 99 fFlagBits = 0x0;
115 fStencilSettings.setDisabled(); 100 fStencilSettings.setDisabled();
116 fDrawFace = kBoth_DrawFace; 101 fDrawFace = kBoth_DrawFace;
117 102
118 fHints = 0;
119
120 fColorProcInfoValid = false; 103 fColorProcInfoValid = false;
121 fCoverageProcInfoValid = false; 104 fCoverageProcInfoValid = false;
122 105
123 fColorCache = GrColor_ILLEGAL; 106 fColorCache = GrColor_ILLEGAL;
124 fCoverageCache = GrColor_ILLEGAL; 107 fCoverageCache = GrColor_ILLEGAL;
108
109 fColorPrimProc = NULL;
110 fCoveragePrimProc = NULL;
111
125 } 112 }
126 113
127 bool GrDrawState::setIdentityViewMatrix() { 114 bool GrDrawState::setIdentityViewMatrix() {
128 if (this->numFragmentStages()) { 115 if (this->numFragmentStages()) {
129 SkMatrix invVM; 116 SkMatrix invVM;
130 if (!fViewMatrix.invert(&invVM)) { 117 if (!fViewMatrix.invert(&invVM)) {
131 // sad trombone sound 118 // sad trombone sound
132 return false; 119 return false;
133 } 120 }
134 for (int s = 0; s < this->numColorStages(); ++s) { 121 for (int s = 0; s < this->numColorStages(); ++s) {
135 fColorStages[s].localCoordChange(invVM); 122 fColorStages[s].localCoordChange(invVM);
136 } 123 }
137 for (int s = 0; s < this->numCoverageStages(); ++s) { 124 for (int s = 0; s < this->numCoverageStages(); ++s) {
138 fCoverageStages[s].localCoordChange(invVM); 125 fCoverageStages[s].localCoordChange(invVM);
139 } 126 }
140 } 127 }
141 fViewMatrix.reset(); 128 fViewMatrix.reset();
142 return true; 129 return true;
143 } 130 }
144 131
145 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende rTarget* rt) { 132 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende rTarget* rt) {
146 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); 133 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages());
147 134
148 fGeometryProcessor.reset(NULL);
149 fColorStages.reset(); 135 fColorStages.reset();
150 fCoverageStages.reset(); 136 fCoverageStages.reset();
151 137
152 for (int i = 0; i < paint.numColorStages(); ++i) { 138 for (int i = 0; i < paint.numColorStages(); ++i) {
153 fColorStages.push_back(paint.getColorStage(i)); 139 fColorStages.push_back(paint.getColorStage(i));
154 } 140 }
155 141
156 for (int i = 0; i < paint.numCoverageStages(); ++i) { 142 for (int i = 0; i < paint.numCoverageStages(); ++i) {
157 fCoverageStages.push_back(paint.getCoverageStage(i)); 143 fCoverageStages.push_back(paint.getCoverageStage(i));
158 } 144 }
159 145
160 fXPFactory.reset(SkRef(paint.getXPFactory())); 146 fXPFactory.reset(SkRef(paint.getXPFactory()));
161 147
162 this->setRenderTarget(rt); 148 this->setRenderTarget(rt);
163 149
164 fViewMatrix = vm; 150 fViewMatrix = vm;
165 151
166 // These have no equivalent in GrPaint, set them to defaults 152 // These have no equivalent in GrPaint, set them to defaults
167 fDrawFace = kBoth_DrawFace; 153 fDrawFace = kBoth_DrawFace;
168 fStencilSettings.setDisabled(); 154 fStencilSettings.setDisabled();
169 fFlagBits = 0; 155 fFlagBits = 0;
170 fHints = 0;
171 156
172 // Enable the clip bit 157 // Enable the clip bit
173 this->enableState(GrDrawState::kClip_StateBit); 158 this->enableState(GrDrawState::kClip_StateBit);
174 159
175 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); 160 this->setState(GrDrawState::kDither_StateBit, paint.isDither());
176 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); 161 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias());
177 162
178 fColorProcInfoValid = false; 163 fColorProcInfoValid = false;
179 fCoverageProcInfoValid = false; 164 fCoverageProcInfoValid = false;
180 165
(...skipping 11 matching lines...) Expand all
192 this->calcColorInvariantOutput(color); 177 this->calcColorInvariantOutput(color);
193 178
194 // The coverage isn't actually white, its unknown, but this will produce the same effect 179 // The coverage isn't actually white, its unknown, but this will produce the same effect
195 // TODO we want to cache the result of this call, but we can probably clean up the interface 180 // TODO we want to cache the result of this call, but we can probably clean up the interface
196 // so we don't have to pass in a seemingly known coverage 181 // so we don't have to pass in a seemingly known coverage
197 this->calcCoverageInvariantOutput(GrColor_WHITE); 182 this->calcCoverageInvariantOutput(GrColor_WHITE);
198 return fXPFactory->canApplyCoverage(fColorProcInfo, fCoverageProcInfo, 183 return fXPFactory->canApplyCoverage(fColorProcInfo, fCoverageProcInfo,
199 this->isCoverageDrawing(), this->isColor WriteDisabled()); 184 this->isCoverageDrawing(), this->isColor WriteDisabled());
200 } 185 }
201 186
202 bool GrDrawState::hasSolidCoverage(GrColor coverage) const { 187 bool GrDrawState::hasSolidCoverage(const GrPrimitiveProcessor* pp) const {
203 // If we're drawing coverage directly then coverage is effectively treated a s color. 188 // If we're drawing coverage directly then coverage is effectively treated a s color.
204 if (this->isCoverageDrawing()) { 189 if (this->isCoverageDrawing()) {
205 return true; 190 return true;
206 } 191 }
207 192
208 if (this->numCoverageStages() > 0) { 193 if (this->numCoverageStages() > 0) {
209 return false; 194 return false;
210 } 195 }
211 196
212 this->calcCoverageInvariantOutput(coverage); 197 this->calcCoverageInvariantOutput(pp);
213 return fCoverageProcInfo.isSolidWhite(); 198 return fCoverageProcInfo.isSolidWhite();
214 } 199 }
215 200
216 //////////////////////////////////////////////////////////////////////////////s 201 //////////////////////////////////////////////////////////////////////////////s
217 202
218 bool GrDrawState::willEffectReadDstColor(GrColor color, GrColor coverage) const { 203 bool GrDrawState::willEffectReadDstColor(const GrPrimitiveProcessor* pp) const {
219 this->calcColorInvariantOutput(color); 204 this->calcColorInvariantOutput(pp);
220 this->calcCoverageInvariantOutput(coverage); 205 this->calcCoverageInvariantOutput(pp);
221 // TODO: Remove need to create the XP here. 206 // TODO: Remove need to create the XP here.
222 // Also once all custom blends are turned into XPs we can remove the n eed 207 // Also once all custom blends are turned into XPs we can remove the n eed
223 // to check other stages since only xp's will be able to read dst 208 // to check other stages since only xp's will be able to read dst
224 SkAutoTUnref<GrXferProcessor> xferProcessor(fXPFactory->createXferProcessor( fColorProcInfo, 209 SkAutoTUnref<GrXferProcessor> xferProcessor(fXPFactory->createXferProcessor( fColorProcInfo,
225 fCoverageProcInfo)); 210 fCoverageProcInfo));
226 if (xferProcessor && xferProcessor->willReadDstColor()) { 211 if (xferProcessor && xferProcessor->willReadDstColor()) {
227 return true; 212 return true;
228 } 213 }
229 214
230 if (!this->isColorWriteDisabled()) { 215 if (!this->isColorWriteDisabled()) {
231 if (fColorProcInfo.readsDst()) { 216 if (fColorProcInfo.readsDst()) {
232 return true; 217 return true;
233 } 218 }
234 } 219 }
235 return fCoverageProcInfo.readsDst(); 220 return fCoverageProcInfo.readsDst();
236 } 221 }
237 222
238 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { 223 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
239 if (fDrawState) { 224 if (fDrawState) {
240 // See the big comment on the class definition about GPs.
241 if (SK_InvalidUniqueID == fOriginalGPID) {
242 fDrawState->fGeometryProcessor.reset(NULL);
243 } else {
244 SkASSERT(fDrawState->getGeometryProcessor()->getUniqueID() ==
245 fOriginalGPID);
246 fOriginalGPID = SK_InvalidUniqueID;
247 }
248
249 int m = fDrawState->numColorStages() - fColorEffectCnt; 225 int m = fDrawState->numColorStages() - fColorEffectCnt;
250 SkASSERT(m >= 0); 226 SkASSERT(m >= 0);
251 fDrawState->fColorStages.pop_back_n(m); 227 fDrawState->fColorStages.pop_back_n(m);
252 228
253 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt; 229 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt;
254 SkASSERT(n >= 0); 230 SkASSERT(n >= 0);
255 fDrawState->fCoverageStages.pop_back_n(n); 231 fDrawState->fCoverageStages.pop_back_n(n);
256 if (m + n > 0) { 232 if (m + n > 0) {
257 fDrawState->fColorProcInfoValid = false; 233 fDrawState->fColorProcInfoValid = false;
258 fDrawState->fCoverageProcInfoValid = false; 234 fDrawState->fCoverageProcInfoValid = false;
259 } 235 }
260 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) 236 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
261 } 237 }
262 fDrawState = ds; 238 fDrawState = ds;
263 if (NULL != ds) { 239 if (NULL != ds) {
264 SkASSERT(SK_InvalidUniqueID == fOriginalGPID);
265 if (NULL != ds->getGeometryProcessor()) {
266 fOriginalGPID = ds->getGeometryProcessor()->getUniqueID();
267 }
268 fColorEffectCnt = ds->numColorStages(); 240 fColorEffectCnt = ds->numColorStages();
269 fCoverageEffectCnt = ds->numCoverageStages(); 241 fCoverageEffectCnt = ds->numCoverageStages();
270 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;) 242 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;)
271 } 243 }
272 } 244 }
273 245
274 //////////////////////////////////////////////////////////////////////////////// 246 ////////////////////////////////////////////////////////////////////////////////
275 247
276 // Some blend modes allow folding a fractional coverage value into the color's a lpha channel, while 248 // Some blend modes allow folding a fractional coverage value into the color's a lpha channel, while
277 // others will blend incorrectly. 249 // others will blend incorrectly.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 339 }
368 340
369 //////////////////////////////////////////////////////////////////////////////// 341 ////////////////////////////////////////////////////////////////////////////////
370 342
371 GrDrawState::~GrDrawState() { 343 GrDrawState::~GrDrawState() {
372 SkASSERT(0 == fBlockEffectRemovalCnt); 344 SkASSERT(0 == fBlockEffectRemovalCnt);
373 } 345 }
374 346
375 //////////////////////////////////////////////////////////////////////////////// 347 ////////////////////////////////////////////////////////////////////////////////
376 348
377 bool GrDrawState::srcAlphaWillBeOne(GrColor color, GrColor coverage) const { 349 bool GrDrawState::willBlendWithDst(const GrPrimitiveProcessor* pp) const {
378 this->calcColorInvariantOutput(color); 350 this->calcColorInvariantOutput(pp);
379 if (this->isCoverageDrawing()) { 351 this->calcCoverageInvariantOutput(pp);
380 this->calcCoverageInvariantOutput(coverage);
381 return (fColorProcInfo.isOpaque() && fCoverageProcInfo.isOpaque());
382 }
383 return fColorProcInfo.isOpaque();
384 }
385
386 bool GrDrawState::willBlendWithDst(GrColor color, GrColor coverage) const {
387 this->calcColorInvariantOutput(color);
388 this->calcCoverageInvariantOutput(coverage);
389 return fXPFactory->willBlendWithDst(fColorProcInfo, fCoverageProcInfo, 352 return fXPFactory->willBlendWithDst(fColorProcInfo, fCoverageProcInfo,
390 this->isCoverageDrawing(), this->isColor WriteDisabled()); 353 this->isCoverageDrawing(), this->isColor WriteDisabled());
391 } 354 }
392 355
356 void GrDrawState::calcColorInvariantOutput(const GrPrimitiveProcessor* pp) const {
357 if (!fColorProcInfoValid || fColorPrimProc != pp) {
358 fColorProcInfo.calcColorWithPrimProc(pp, fColorStages.begin(), this->num ColorStages());
359 fColorProcInfoValid = true;
360 fColorPrimProc = pp;
361 }
362 }
363
364 void GrDrawState::calcCoverageInvariantOutput(const GrPrimitiveProcessor* pp) co nst {
365 if (!fCoverageProcInfoValid || fCoveragePrimProc != pp) {
366 fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageStages.begin(),
367 this->numCoverageStages());
368 fCoverageProcInfoValid = true;
369 fCoveragePrimProc = pp;
370 }
371 }
372
393 void GrDrawState::calcColorInvariantOutput(GrColor color) const { 373 void GrDrawState::calcColorInvariantOutput(GrColor color) const {
394 if (!fColorProcInfoValid || color != fColorCache) { 374 if (!fColorProcInfoValid || color != fColorCache) {
395 GrColorComponentFlags flags; 375 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags;
396 if (this->hasColorVertexAttribute()) { 376 fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColo rStages(), color,
397 if (fHints & kVertexColorsAreOpaque_Hint) { 377 flags, false);
398 flags = kA_GrColorComponentFlag;
399 color = 0xFF << GrColor_SHIFT_A;
400 } else {
401 flags = static_cast<GrColorComponentFlags>(0);
402 color = 0;
403 }
404 } else {
405 flags = kRGBA_GrColorComponentFlags;
406 }
407 fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColo rStages(),
408 color, flags, false);
409 fColorProcInfoValid = true; 378 fColorProcInfoValid = true;
410 fColorCache = color; 379 fColorCache = color;
411 } 380 }
412 } 381 }
413 382
414 void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const { 383 void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const {
415 if (!fCoverageProcInfoValid || coverage != fCoverageCache) { 384 if (!fCoverageProcInfoValid || coverage != fCoverageCache) {
416 GrColorComponentFlags flags; 385 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags;
417 // Check if per-vertex or constant color may have partial alpha 386 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(),
418 if (this->hasCoverageVertexAttribute()) { 387 this->numCoverageStages(), cover age, flags,
419 flags = static_cast<GrColorComponentFlags>(0); 388 true);
420 coverage = 0;
421 } else {
422 flags = kRGBA_GrColorComponentFlags;
423 }
424 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->n umCoverageStages(),
425 coverage, flags, true, fGeometry Processor.get());
426 fCoverageProcInfoValid = true; 389 fCoverageProcInfoValid = true;
427 fCoverageCache = coverage; 390 fCoverageCache = coverage;
428 } 391 }
429 } 392 }
OLDNEW
« no previous file with comments | « src/gpu/GrDrawState.h ('k') | src/gpu/GrDrawTarget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698