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

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

Issue 783763002: Initial CL to move color / coverage off of drawstate (Closed) Base URL: https://skia.googlesource.com/skia.git@no-static-gp
Patch Set: bug 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) const {
18 bool usingVertexColors = this->hasColorVertexAttribute();
19 if (!usingVertexColors && this->fColor != that.fColor) {
20 return false;
21 }
22
23 if (this->getRenderTarget() != that.getRenderTarget() || 18 if (this->getRenderTarget() != that.getRenderTarget() ||
24 this->fColorStages.count() != that.fColorStages.count() || 19 this->fColorStages.count() != that.fColorStages.count() ||
25 this->fCoverageStages.count() != that.fCoverageStages.count() || 20 this->fCoverageStages.count() != that.fCoverageStages.count() ||
26 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || 21 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) ||
27 this->fFlagBits != that.fFlagBits || 22 this->fFlagBits != that.fFlagBits ||
28 this->fStencilSettings != that.fStencilSettings || 23 this->fStencilSettings != that.fStencilSettings ||
29 this->fDrawFace != that.fDrawFace) { 24 this->fDrawFace != that.fDrawFace) {
30 return false; 25 return false;
31 } 26 }
32 27
33 bool usingVertexCoverage = this->hasCoverageVertexAttribute();
34 if (!usingVertexCoverage && this->fCoverage != that.fCoverage) {
35 return false;
36 }
37
38 bool explicitLocalCoords = this->hasLocalCoordAttribute(); 28 bool explicitLocalCoords = this->hasLocalCoordAttribute();
39 if (this->hasGeometryProcessor()) { 29 if (this->hasGeometryProcessor()) {
40 if (!that.hasGeometryProcessor()) { 30 if (!that.hasGeometryProcessor()) {
41 return false; 31 return false;
42 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProce ssor())) { 32 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProce ssor())) {
43 return false; 33 return false;
44 } 34 }
45 } else if (that.hasGeometryProcessor()) { 35 } else if (that.hasGeometryProcessor()) {
46 return false; 36 return false;
47 } 37 }
(...skipping 28 matching lines...) Expand all
76 fColorStages[i].localCoordChange(preConcatMatrix); 66 fColorStages[i].localCoordChange(preConcatMatrix);
77 } 67 }
78 for (int i = 0; i < this->numCoverageStages(); ++i) { 68 for (int i = 0; i < this->numCoverageStages(); ++i) {
79 fCoverageStages[i].localCoordChange(preConcatMatrix); 69 fCoverageStages[i].localCoordChange(preConcatMatrix);
80 } 70 }
81 } 71 }
82 } 72 }
83 73
84 GrDrawState& GrDrawState::operator=(const GrDrawState& that) { 74 GrDrawState& GrDrawState::operator=(const GrDrawState& that) {
85 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get())); 75 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get()));
86 fColor = that.fColor;
87 fViewMatrix = that.fViewMatrix; 76 fViewMatrix = that.fViewMatrix;
88 fFlagBits = that.fFlagBits; 77 fFlagBits = that.fFlagBits;
89 fStencilSettings = that.fStencilSettings; 78 fStencilSettings = that.fStencilSettings;
90 fCoverage = that.fCoverage;
91 fDrawFace = that.fDrawFace; 79 fDrawFace = that.fDrawFace;
92 fGeometryProcessor.reset(SkSafeRef(that.fGeometryProcessor.get())); 80 fGeometryProcessor.reset(SkSafeRef(that.fGeometryProcessor.get()));
93 fXPFactory.reset(SkRef(that.getXPFactory())); 81 fXPFactory.reset(SkRef(that.getXPFactory()));
94 fColorStages = that.fColorStages; 82 fColorStages = that.fColorStages;
95 fCoverageStages = that.fCoverageStages; 83 fCoverageStages = that.fCoverageStages;
96 84
97 fHints = that.fHints; 85 fHints = that.fHints;
98 86
99 fColorProcInfoValid = that.fColorProcInfoValid; 87 fColorProcInfoValid = that.fColorProcInfoValid;
100 fCoverageProcInfoValid = that.fCoverageProcInfoValid; 88 fCoverageProcInfoValid = that.fCoverageProcInfoValid;
101 if (fColorProcInfoValid) { 89 if (fColorProcInfoValid) {
102 fColorProcInfo = that.fColorProcInfo; 90 fColorProcInfo = that.fColorProcInfo;
103 } 91 }
104 if (fCoverageProcInfoValid) { 92 if (fCoverageProcInfoValid) {
105 fCoverageProcInfo = that.fCoverageProcInfo; 93 fCoverageProcInfo = that.fCoverageProcInfo;
106 } 94 }
107 return *this; 95 return *this;
108 } 96 }
109 97
110 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { 98 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) {
111 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); 99 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages());
112 fRenderTarget.reset(NULL); 100 fRenderTarget.reset(NULL);
113 101
114 fGeometryProcessor.reset(NULL); 102 fGeometryProcessor.reset(NULL);
115 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); 103 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
116 fColorStages.reset(); 104 fColorStages.reset();
117 fCoverageStages.reset(); 105 fCoverageStages.reset();
118 106
119 fColor = 0xffffffff;
120 if (NULL == initialViewMatrix) { 107 if (NULL == initialViewMatrix) {
121 fViewMatrix.reset(); 108 fViewMatrix.reset();
122 } else { 109 } else {
123 fViewMatrix = *initialViewMatrix; 110 fViewMatrix = *initialViewMatrix;
124 } 111 }
125 fFlagBits = 0x0; 112 fFlagBits = 0x0;
126 fStencilSettings.setDisabled(); 113 fStencilSettings.setDisabled();
127 fCoverage = 0xff;
128 fDrawFace = kBoth_DrawFace; 114 fDrawFace = kBoth_DrawFace;
129 115
130 fHints = 0; 116 fHints = 0;
131 117
132 fColorProcInfoValid = false; 118 fColorProcInfoValid = false;
133 fCoverageProcInfoValid = false; 119 fCoverageProcInfoValid = false;
134 } 120 }
135 121
136 bool GrDrawState::setIdentityViewMatrix() { 122 bool GrDrawState::setIdentityViewMatrix() {
137 if (this->numFragmentStages()) { 123 if (this->numFragmentStages()) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 160
175 // These have no equivalent in GrPaint, set them to defaults 161 // These have no equivalent in GrPaint, set them to defaults
176 fDrawFace = kBoth_DrawFace; 162 fDrawFace = kBoth_DrawFace;
177 fStencilSettings.setDisabled(); 163 fStencilSettings.setDisabled();
178 fFlagBits = 0; 164 fFlagBits = 0;
179 fHints = 0; 165 fHints = 0;
180 166
181 // Enable the clip bit 167 // Enable the clip bit
182 this->enableState(GrDrawState::kClip_StateBit); 168 this->enableState(GrDrawState::kClip_StateBit);
183 169
184 this->setColor(paint.getColor());
185 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); 170 this->setState(GrDrawState::kDither_StateBit, paint.isDither());
186 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); 171 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias());
187 172
188 this->setCoverage(0xFF);
189 fColorProcInfoValid = false; 173 fColorProcInfoValid = false;
190 fCoverageProcInfoValid = false; 174 fCoverageProcInfoValid = false;
175
176 fColorCache = GrColor_ILLEGAL;
177 fCoverageCache = GrColor_ILLEGAL;
191 } 178 }
192 179
193 //////////////////////////////////////////////////////////////////////////////// 180 ////////////////////////////////////////////////////////////////////////////////
194 181
195 bool GrDrawState::couldApplyCoverage(const GrDrawTargetCaps& caps) const { 182 bool GrDrawState::canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCa ps& caps) const {
196 if (caps.dualSourceBlendingSupport()) { 183 if (caps.dualSourceBlendingSupport()) {
197 return true; 184 return true;
198 } 185 }
199 186
200 this->calcColorInvariantOutput(); 187 this->calcColorInvariantOutput(color);
201 this->calcCoverageInvariantOutput(); 188
189 // The coverage isn't actually white, its unknown, but this will produce the same effect
190 // TODO we want to cache the result of this call, but we can probably clean up the interface
191 // so we don't have to pass in a seemingly known coverage
192 this->calcCoverageInvariantOutput(GrColor_WHITE);
202 return fXPFactory->canApplyCoverage(fColorProcInfo, fCoverageProcInfo, 193 return fXPFactory->canApplyCoverage(fColorProcInfo, fCoverageProcInfo,
203 this->isCoverageDrawing(), this->isColor WriteDisabled()); 194 this->isCoverageDrawing(), this->isColor WriteDisabled());
204 } 195 }
205 196
206 bool GrDrawState::hasSolidCoverage() const { 197 bool GrDrawState::hasSolidCoverage(GrColor coverage) const {
207 // If we're drawing coverage directly then coverage is effectively treated a s color. 198 // If we're drawing coverage directly then coverage is effectively treated a s color.
208 if (this->isCoverageDrawing()) { 199 if (this->isCoverageDrawing()) {
209 return true; 200 return true;
210 } 201 }
211 202
212 if (this->numCoverageStages() > 0) { 203 if (this->numCoverageStages() > 0) {
213 return false; 204 return false;
214 } 205 }
215 206
216 this->calcCoverageInvariantOutput(); 207 this->calcCoverageInvariantOutput(coverage);
217 return fCoverageProcInfo.isSolidWhite(); 208 return fCoverageProcInfo.isSolidWhite();
218 } 209 }
219 210
220 //////////////////////////////////////////////////////////////////////////////s 211 //////////////////////////////////////////////////////////////////////////////s
221 212
222 bool GrDrawState::willEffectReadDstColor() const { 213 bool GrDrawState::willEffectReadDstColor(GrColor color, GrColor coverage) const {
223 this->calcColorInvariantOutput(); 214 this->calcColorInvariantOutput(color);
224 this->calcCoverageInvariantOutput(); 215 this->calcCoverageInvariantOutput(coverage);
225 // TODO: Remove need to create the XP here. 216 // TODO: Remove need to create the XP here.
226 // Also once all custom blends are turned into XPs we can remove the n eed 217 // Also once all custom blends are turned into XPs we can remove the n eed
227 // to check other stages since only xp's will be able to read dst 218 // to check other stages since only xp's will be able to read dst
228 SkAutoTUnref<GrXferProcessor> xferProcessor(fXPFactory->createXferProcessor( fColorProcInfo, 219 SkAutoTUnref<GrXferProcessor> xferProcessor(fXPFactory->createXferProcessor( fColorProcInfo,
229 fCoverageProcInfo)); 220 fCoverageProcInfo));
230 if (xferProcessor && xferProcessor->willReadDstColor()) { 221 if (xferProcessor && xferProcessor->willReadDstColor()) {
231 return true; 222 return true;
232 } 223 }
233 224
234 if (!this->isColorWriteDisabled()) { 225 if (!this->isColorWriteDisabled()) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 } 362 }
372 363
373 //////////////////////////////////////////////////////////////////////////////// 364 ////////////////////////////////////////////////////////////////////////////////
374 365
375 GrDrawState::~GrDrawState() { 366 GrDrawState::~GrDrawState() {
376 SkASSERT(0 == fBlockEffectRemovalCnt); 367 SkASSERT(0 == fBlockEffectRemovalCnt);
377 } 368 }
378 369
379 //////////////////////////////////////////////////////////////////////////////// 370 ////////////////////////////////////////////////////////////////////////////////
380 371
381 bool GrDrawState::srcAlphaWillBeOne() const { 372 bool GrDrawState::srcAlphaWillBeOne(GrColor color, GrColor coverage) const {
382 this->calcColorInvariantOutput(); 373 this->calcColorInvariantOutput(color);
383 if (this->isCoverageDrawing()) { 374 if (this->isCoverageDrawing()) {
384 this->calcCoverageInvariantOutput(); 375 this->calcCoverageInvariantOutput(coverage);
385 return (fColorProcInfo.isOpaque() && fCoverageProcInfo.isOpaque()); 376 return (fColorProcInfo.isOpaque() && fCoverageProcInfo.isOpaque());
386 } 377 }
387 return fColorProcInfo.isOpaque(); 378 return fColorProcInfo.isOpaque();
388 } 379 }
389 380
390 bool GrDrawState::willBlendWithDst() const { 381 bool GrDrawState::willBlendWithDst(GrColor color, GrColor coverage) const {
391 this->calcColorInvariantOutput(); 382 this->calcColorInvariantOutput(color);
392 this->calcCoverageInvariantOutput(); 383 this->calcCoverageInvariantOutput(coverage);
393 return fXPFactory->willBlendWithDst(fColorProcInfo, fCoverageProcInfo, 384 return fXPFactory->willBlendWithDst(fColorProcInfo, fCoverageProcInfo,
394 this->isCoverageDrawing(), this->isColor WriteDisabled()); 385 this->isCoverageDrawing(), this->isColor WriteDisabled());
395 } 386 }
396 387
397 void GrDrawState::calcColorInvariantOutput() const { 388 void GrDrawState::calcColorInvariantOutput(GrColor color) const {
398 if (!fColorProcInfoValid) { 389 if (!fColorProcInfoValid || color != fColorCache) {
399 GrColor color;
400 GrColorComponentFlags flags; 390 GrColorComponentFlags flags;
401 if (this->hasColorVertexAttribute()) { 391 if (this->hasColorVertexAttribute()) {
402 if (fHints & kVertexColorsAreOpaque_Hint) { 392 if (fHints & kVertexColorsAreOpaque_Hint) {
403 flags = kA_GrColorComponentFlag; 393 flags = kA_GrColorComponentFlag;
404 color = 0xFF << GrColor_SHIFT_A; 394 color = 0xFF << GrColor_SHIFT_A;
405 } else { 395 } else {
406 flags = static_cast<GrColorComponentFlags>(0); 396 flags = static_cast<GrColorComponentFlags>(0);
407 color = 0; 397 color = 0;
408 } 398 }
409 } else { 399 } else {
410 flags = kRGBA_GrColorComponentFlags; 400 flags = kRGBA_GrColorComponentFlags;
411 color = this->getColor();
412 } 401 }
413 fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColo rStages(), 402 fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColo rStages(),
414 color, flags, false); 403 color, flags, false);
415 fColorProcInfoValid = true; 404 fColorProcInfoValid = true;
405 fColorCache = color;
416 } 406 }
417 } 407 }
418 408
419 void GrDrawState::calcCoverageInvariantOutput() const { 409 void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const {
420 if (!fCoverageProcInfoValid) { 410 if (!fCoverageProcInfoValid || coverage != fCoverageCache) {
421 GrColor color;
422 GrColorComponentFlags flags; 411 GrColorComponentFlags flags;
423 // Check if per-vertex or constant color may have partial alpha 412 // Check if per-vertex or constant color may have partial alpha
424 if (this->hasCoverageVertexAttribute()) { 413 if (this->hasCoverageVertexAttribute()) {
425 flags = static_cast<GrColorComponentFlags>(0); 414 flags = static_cast<GrColorComponentFlags>(0);
426 color = 0; 415 coverage = 0;
427 } else { 416 } else {
428 flags = kRGBA_GrColorComponentFlags; 417 flags = kRGBA_GrColorComponentFlags;
429 color = this->getCoverageColor();
430 } 418 }
431 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->n umCoverageStages(), 419 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->n umCoverageStages(),
432 color, flags, true, fGeometryPro cessor.get()); 420 coverage, flags, true, fGeometry Processor.get());
433 fCoverageProcInfoValid = true; 421 fCoverageProcInfoValid = true;
422 fCoverageCache = coverage;
434 } 423 }
435 } 424 }
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