OLD | NEW |
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, bool explicitLocalCoords) con
st { | 17 GrDrawState::GrDrawState() |
18 if (this->getRenderTarget() != that.getRenderTarget() || | 18 : fFlagBits(0x0) |
19 this->fColorStages.count() != that.fColorStages.count() || | 19 , fDrawFace(kBoth_DrawFace) |
20 this->fCoverageStages.count() != that.fCoverageStages.count() || | 20 , fColorProcInfoValid(false) |
21 this->fFlagBits != that.fFlagBits || | 21 , fCoverageProcInfoValid(false) |
22 this->fStencilSettings != that.fStencilSettings || | 22 , fColorCache(GrColor_ILLEGAL) |
23 this->fDrawFace != that.fDrawFace) { | 23 , fCoverageCache(GrColor_ILLEGAL) |
24 return false; | 24 , fColorPrimProc(NULL) |
25 } | 25 , fCoveragePrimProc(NULL) { |
26 | 26 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
27 if (!this->getXPFactory()->isEqual(*that.getXPFactory())) { | |
28 return false; | |
29 } | |
30 | |
31 for (int i = 0; i < this->numColorStages(); i++) { | |
32 if (this->getColorStage(i) != that.getColorStage(i)) { | |
33 return false; | |
34 } | |
35 } | |
36 for (int i = 0; i < this->numCoverageStages(); i++) { | |
37 if (this->getCoverageStage(i) != that.getCoverageStage(i)) { | |
38 return false; | |
39 } | |
40 } | |
41 | |
42 return true; | |
43 } | 27 } |
44 | 28 |
45 ////////////////////////////////////////////////////////////////////////////// | |
46 | |
47 GrDrawState& GrDrawState::operator=(const GrDrawState& that) { | 29 GrDrawState& GrDrawState::operator=(const GrDrawState& that) { |
48 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get())); | 30 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get())); |
49 fFlagBits = that.fFlagBits; | 31 fFlagBits = that.fFlagBits; |
50 fStencilSettings = that.fStencilSettings; | 32 fStencilSettings = that.fStencilSettings; |
51 fDrawFace = that.fDrawFace; | 33 fDrawFace = that.fDrawFace; |
52 fXPFactory.reset(SkRef(that.getXPFactory())); | 34 fXPFactory.reset(SkRef(that.getXPFactory())); |
53 fColorStages = that.fColorStages; | 35 fColorStages = that.fColorStages; |
54 fCoverageStages = that.fCoverageStages; | 36 fCoverageStages = that.fCoverageStages; |
55 | 37 |
56 fColorProcInfoValid = that.fColorProcInfoValid; | 38 fColorProcInfoValid = that.fColorProcInfoValid; |
57 fCoverageProcInfoValid = that.fCoverageProcInfoValid; | 39 fCoverageProcInfoValid = that.fCoverageProcInfoValid; |
58 fColorCache = that.fColorCache; | 40 fColorCache = that.fColorCache; |
59 fCoverageCache = that.fCoverageCache; | 41 fCoverageCache = that.fCoverageCache; |
60 fColorPrimProc = that.fColorPrimProc; | 42 fColorPrimProc = that.fColorPrimProc; |
61 fCoveragePrimProc = that.fCoveragePrimProc; | 43 fCoveragePrimProc = that.fCoveragePrimProc; |
62 if (fColorProcInfoValid) { | 44 if (fColorProcInfoValid) { |
63 fColorProcInfo = that.fColorProcInfo; | 45 fColorProcInfo = that.fColorProcInfo; |
64 } | 46 } |
65 if (fCoverageProcInfoValid) { | 47 if (fCoverageProcInfoValid) { |
66 fCoverageProcInfo = that.fCoverageProcInfo; | 48 fCoverageProcInfo = that.fCoverageProcInfo; |
67 } | 49 } |
68 return *this; | 50 return *this; |
69 } | 51 } |
70 | 52 |
71 void GrDrawState::onReset() { | |
72 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages()); | |
73 fRenderTarget.reset(NULL); | |
74 | |
75 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); | |
76 fColorStages.reset(); | |
77 fCoverageStages.reset(); | |
78 | |
79 fFlagBits = 0x0; | |
80 fStencilSettings.setDisabled(); | |
81 fDrawFace = kBoth_DrawFace; | |
82 | |
83 fColorProcInfoValid = false; | |
84 fCoverageProcInfoValid = false; | |
85 | |
86 fColorCache = GrColor_ILLEGAL; | |
87 fCoverageCache = GrColor_ILLEGAL; | |
88 | |
89 fColorPrimProc = NULL; | |
90 fCoveragePrimProc = NULL; | |
91 } | |
92 | |
93 void GrDrawState::setFromPaint(const GrPaint& paint, GrRenderTarget* rt) { | 53 void GrDrawState::setFromPaint(const GrPaint& paint, GrRenderTarget* rt) { |
94 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages()); | 54 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages()); |
95 | 55 |
96 fColorStages.reset(); | 56 fColorStages.reset(); |
97 fCoverageStages.reset(); | 57 fCoverageStages.reset(); |
98 | 58 |
99 for (int i = 0; i < paint.numColorStages(); ++i) { | 59 for (int i = 0; i < paint.numColorStages(); ++i) { |
100 fColorStages.push_back(paint.getColorStage(i)); | 60 fColorStages.push_back(paint.getColorStage(i)); |
101 } | 61 } |
102 | 62 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 if (caps.dualSourceBlendingSupport()) { | 95 if (caps.dualSourceBlendingSupport()) { |
136 return true; | 96 return true; |
137 } | 97 } |
138 | 98 |
139 this->calcColorInvariantOutput(color); | 99 this->calcColorInvariantOutput(color); |
140 | 100 |
141 // The coverage isn't actually white, its unknown, but this will produce the
same effect | 101 // The coverage isn't actually white, its unknown, but this will produce the
same effect |
142 // TODO we want to cache the result of this call, but we can probably clean
up the interface | 102 // TODO we want to cache the result of this call, but we can probably clean
up the interface |
143 // so we don't have to pass in a seemingly known coverage | 103 // so we don't have to pass in a seemingly known coverage |
144 this->calcCoverageInvariantOutput(GrColor_WHITE); | 104 this->calcCoverageInvariantOutput(GrColor_WHITE); |
145 return fXPFactory->canApplyCoverage(fColorProcInfo, fCoverageProcInfo); | 105 return this->getXPFactory()->canApplyCoverage(fColorProcInfo, fCoverageProcI
nfo); |
146 } | 106 } |
147 | 107 |
148 //////////////////////////////////////////////////////////////////////////////s | 108 //////////////////////////////////////////////////////////////////////////////s |
149 | 109 |
150 bool GrDrawState::willEffectReadDstColor() const { | 110 bool GrDrawState::willEffectReadDstColor() const { |
151 return fXPFactory->willReadDst(); | 111 return this->getXPFactory()->willReadDst(); |
152 } | 112 } |
153 | 113 |
154 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { | 114 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { |
155 if (fDrawState) { | 115 if (fDrawState) { |
156 int m = fDrawState->numColorStages() - fColorEffectCnt; | 116 int m = fDrawState->numColorStages() - fColorEffectCnt; |
157 SkASSERT(m >= 0); | 117 SkASSERT(m >= 0); |
158 fDrawState->fColorStages.pop_back_n(m); | 118 fDrawState->fColorStages.pop_back_n(m); |
159 | 119 |
160 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt; | 120 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt; |
161 SkASSERT(n >= 0); | 121 SkASSERT(n >= 0); |
(...skipping 10 matching lines...) Expand all Loading... |
172 fCoverageEffectCnt = ds->numCoverageStages(); | 132 fCoverageEffectCnt = ds->numCoverageStages(); |
173 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;) | 133 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;) |
174 } | 134 } |
175 } | 135 } |
176 | 136 |
177 //////////////////////////////////////////////////////////////////////////////// | 137 //////////////////////////////////////////////////////////////////////////////// |
178 | 138 |
179 // Some blend modes allow folding a fractional coverage value into the color's a
lpha channel, while | 139 // Some blend modes allow folding a fractional coverage value into the color's a
lpha channel, while |
180 // others will blend incorrectly. | 140 // others will blend incorrectly. |
181 bool GrDrawState::canTweakAlphaForCoverage() const { | 141 bool GrDrawState::canTweakAlphaForCoverage() const { |
182 return fXPFactory->canTweakAlphaForCoverage(); | 142 return this->getXPFactory()->canTweakAlphaForCoverage(); |
183 } | 143 } |
184 | 144 |
185 //////////////////////////////////////////////////////////////////////////////// | 145 //////////////////////////////////////////////////////////////////////////////// |
186 | 146 |
187 GrDrawState::~GrDrawState() { | 147 GrDrawState::~GrDrawState() { |
188 SkASSERT(0 == fBlockEffectRemovalCnt); | 148 SkASSERT(0 == fBlockEffectRemovalCnt); |
189 } | 149 } |
190 | 150 |
191 //////////////////////////////////////////////////////////////////////////////// | 151 //////////////////////////////////////////////////////////////////////////////// |
192 | 152 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const { | 189 void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const { |
230 if (!fCoverageProcInfoValid || coverage != fCoverageCache) { | 190 if (!fCoverageProcInfoValid || coverage != fCoverageCache) { |
231 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; | 191 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; |
232 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), | 192 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), |
233 this->numCoverageStages(), cover
age, flags, | 193 this->numCoverageStages(), cover
age, flags, |
234 true); | 194 true); |
235 fCoverageProcInfoValid = true; | 195 fCoverageProcInfoValid = true; |
236 fCoverageCache = coverage; | 196 fCoverageCache = coverage; |
237 } | 197 } |
238 } | 198 } |
OLD | NEW |