OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2015 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 "GrPipelineBuilder.h" |
9 | 9 |
10 #include "GrBlend.h" | 10 #include "GrBlend.h" |
11 #include "GrOptDrawState.h" | |
12 #include "GrPaint.h" | 11 #include "GrPaint.h" |
12 #include "GrPipeline.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 GrDrawState::GrDrawState() | 17 GrPipelineBuilder::GrPipelineBuilder() |
18 : fFlagBits(0x0) | 18 : fFlagBits(0x0) |
19 , fDrawFace(kBoth_DrawFace) | 19 , fDrawFace(kBoth_DrawFace) |
20 , fColorProcInfoValid(false) | 20 , fColorProcInfoValid(false) |
21 , fCoverageProcInfoValid(false) | 21 , fCoverageProcInfoValid(false) |
22 , fColorCache(GrColor_ILLEGAL) | 22 , fColorCache(GrColor_ILLEGAL) |
23 , fCoverageCache(GrColor_ILLEGAL) | 23 , fCoverageCache(GrColor_ILLEGAL) |
24 , fColorPrimProc(NULL) | 24 , fColorPrimProc(NULL) |
25 , fCoveragePrimProc(NULL) { | 25 , fCoveragePrimProc(NULL) { |
26 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 26 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
27 } | 27 } |
28 | 28 |
29 GrDrawState& GrDrawState::operator=(const GrDrawState& that) { | 29 bool GrPipelineBuilder::isEqual(const GrPipelineBuilder& that, bool explicitLoca lCoords) const { |
30 if (this->getRenderTarget() != that.getRenderTarget() || | |
31 this->fColorStages.count() != that.fColorStages.count() || | |
32 this->fCoverageStages.count() != that.fCoverageStages.count() || | |
33 this->fFlagBits != that.fFlagBits || | |
34 this->fStencilSettings != that.fStencilSettings || | |
35 this->fDrawFace != that.fDrawFace) { | |
36 return false; | |
37 } | |
38 | |
39 if (!this->getXPFactory()->isEqual(*that.getXPFactory())) { | |
40 return false; | |
41 } | |
42 | |
43 for (int i = 0; i < this->numColorStages(); i++) { | |
44 if (this->getColorStage(i) != that.getColorStage(i)) { | |
45 return false; | |
46 } | |
47 } | |
48 for (int i = 0; i < this->numCoverageStages(); i++) { | |
49 if (this->getCoverageStage(i) != that.getCoverageStage(i)) { | |
50 return false; | |
51 } | |
52 } | |
53 | |
54 return true; | |
55 } | |
56 | |
57 ////////////////////////////////////////////////////////////////////////////// | |
58 | |
59 GrPipelineBuilder& GrPipelineBuilder::operator=(const GrPipelineBuilder& that) { | |
60 >>>>>>> Rename GrOptDrawState to GrPipeline and GrDrawState to GrPipelineBuilder :src/gpu/GrPipelineBuilder.cpp | |
joshualitt
2015/01/22 15:55:08
Delete
egdaniel
2015/01/22 16:28:56
Done.
| |
30 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get())); | 61 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get())); |
31 fFlagBits = that.fFlagBits; | 62 fFlagBits = that.fFlagBits; |
32 fStencilSettings = that.fStencilSettings; | 63 fStencilSettings = that.fStencilSettings; |
33 fDrawFace = that.fDrawFace; | 64 fDrawFace = that.fDrawFace; |
34 fXPFactory.reset(SkRef(that.getXPFactory())); | 65 fXPFactory.reset(SkRef(that.getXPFactory())); |
35 fColorStages = that.fColorStages; | 66 fColorStages = that.fColorStages; |
36 fCoverageStages = that.fCoverageStages; | 67 fCoverageStages = that.fCoverageStages; |
37 | 68 |
38 fColorProcInfoValid = that.fColorProcInfoValid; | 69 fColorProcInfoValid = that.fColorProcInfoValid; |
39 fCoverageProcInfoValid = that.fCoverageProcInfoValid; | 70 fCoverageProcInfoValid = that.fCoverageProcInfoValid; |
40 fColorCache = that.fColorCache; | 71 fColorCache = that.fColorCache; |
41 fCoverageCache = that.fCoverageCache; | 72 fCoverageCache = that.fCoverageCache; |
42 fColorPrimProc = that.fColorPrimProc; | 73 fColorPrimProc = that.fColorPrimProc; |
43 fCoveragePrimProc = that.fCoveragePrimProc; | 74 fCoveragePrimProc = that.fCoveragePrimProc; |
44 if (fColorProcInfoValid) { | 75 if (fColorProcInfoValid) { |
45 fColorProcInfo = that.fColorProcInfo; | 76 fColorProcInfo = that.fColorProcInfo; |
46 } | 77 } |
47 if (fCoverageProcInfoValid) { | 78 if (fCoverageProcInfoValid) { |
48 fCoverageProcInfo = that.fCoverageProcInfo; | 79 fCoverageProcInfo = that.fCoverageProcInfo; |
49 } | 80 } |
50 return *this; | 81 return *this; |
51 } | 82 } |
52 | 83 |
53 void GrDrawState::setFromPaint(const GrPaint& paint, GrRenderTarget* rt) { | 84 void GrPipelineBuilder::setFromPaint(const GrPaint& paint, GrRenderTarget* rt) { |
54 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages()); | 85 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages()); |
55 | 86 |
56 fColorStages.reset(); | 87 fColorStages.reset(); |
57 fCoverageStages.reset(); | 88 fCoverageStages.reset(); |
58 | 89 |
59 for (int i = 0; i < paint.numColorStages(); ++i) { | 90 for (int i = 0; i < paint.numColorStages(); ++i) { |
60 fColorStages.push_back(paint.getColorStage(i)); | 91 fColorStages.push_back(paint.getColorStage(i)); |
61 } | 92 } |
62 | 93 |
63 for (int i = 0; i < paint.numCoverageStages(); ++i) { | 94 for (int i = 0; i < paint.numCoverageStages(); ++i) { |
64 fCoverageStages.push_back(paint.getCoverageStage(i)); | 95 fCoverageStages.push_back(paint.getCoverageStage(i)); |
65 } | 96 } |
66 | 97 |
67 fXPFactory.reset(SkRef(paint.getXPFactory())); | 98 fXPFactory.reset(SkRef(paint.getXPFactory())); |
68 | 99 |
69 this->setRenderTarget(rt); | 100 this->setRenderTarget(rt); |
70 | 101 |
71 // These have no equivalent in GrPaint, set them to defaults | 102 // These have no equivalent in GrPaint, set them to defaults |
72 fDrawFace = kBoth_DrawFace; | 103 fDrawFace = kBoth_DrawFace; |
73 fStencilSettings.setDisabled(); | 104 fStencilSettings.setDisabled(); |
74 fFlagBits = 0; | 105 fFlagBits = 0; |
75 | 106 |
76 // Enable the clip bit | 107 // Enable the clip bit |
77 this->enableState(GrDrawState::kClip_StateBit); | 108 this->enableState(GrPipelineBuilder::kClip_StateBit); |
78 | 109 |
79 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); | 110 this->setState(GrPipelineBuilder::kDither_StateBit, paint.isDither()); |
80 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); | 111 this->setState(GrPipelineBuilder::kHWAntialias_StateBit, paint.isAntiAlias() ); |
81 | 112 |
82 fColorProcInfoValid = false; | 113 fColorProcInfoValid = false; |
83 fCoverageProcInfoValid = false; | 114 fCoverageProcInfoValid = false; |
84 | 115 |
85 fColorCache = GrColor_ILLEGAL; | 116 fColorCache = GrColor_ILLEGAL; |
86 fCoverageCache = GrColor_ILLEGAL; | 117 fCoverageCache = GrColor_ILLEGAL; |
87 | 118 |
88 fColorPrimProc = NULL; | 119 fColorPrimProc = NULL; |
89 fCoveragePrimProc = NULL; | 120 fCoveragePrimProc = NULL; |
90 } | 121 } |
91 | 122 |
92 //////////////////////////////////////////////////////////////////////////////// | 123 //////////////////////////////////////////////////////////////////////////////// |
93 | 124 |
94 bool GrDrawState::canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCa ps& caps) const { | 125 bool GrPipelineBuilder::canUseFracCoveragePrimProc(GrColor color, |
126 const GrDrawTargetCaps& caps) const { | |
95 if (caps.dualSourceBlendingSupport()) { | 127 if (caps.dualSourceBlendingSupport()) { |
96 return true; | 128 return true; |
97 } | 129 } |
98 | 130 |
99 this->calcColorInvariantOutput(color); | 131 this->calcColorInvariantOutput(color); |
100 | 132 |
101 // The coverage isn't actually white, its unknown, but this will produce the same effect | 133 // The coverage isn't actually white, its unknown, but this will produce the same effect |
102 // TODO we want to cache the result of this call, but we can probably clean up the interface | 134 // TODO we want to cache the result of this call, but we can probably clean up the interface |
103 // so we don't have to pass in a seemingly known coverage | 135 // so we don't have to pass in a seemingly known coverage |
104 this->calcCoverageInvariantOutput(GrColor_WHITE); | 136 this->calcCoverageInvariantOutput(GrColor_WHITE); |
105 return this->getXPFactory()->canApplyCoverage(fColorProcInfo, fCoverageProcI nfo); | 137 return this->getXPFactory()->canApplyCoverage(fColorProcInfo, fCoverageProcI nfo); |
106 } | 138 } |
107 | 139 |
108 //////////////////////////////////////////////////////////////////////////////s | 140 //////////////////////////////////////////////////////////////////////////////s |
109 | 141 |
110 bool GrDrawState::willEffectReadDstColor() const { | 142 bool GrPipelineBuilder::willEffectReadDstColor() const { |
111 return this->getXPFactory()->willReadDst(); | 143 return this->getXPFactory()->willReadDst(); |
112 } | 144 } |
113 | 145 |
114 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { | 146 void GrPipelineBuilder::AutoRestoreEffects::set(GrPipelineBuilder* pipelineBuild er) { |
115 if (fDrawState) { | 147 if (fPipelineBuilder) { |
116 int m = fDrawState->numColorStages() - fColorEffectCnt; | 148 int m = fPipelineBuilder->numColorStages() - fColorEffectCnt; |
117 SkASSERT(m >= 0); | 149 SkASSERT(m >= 0); |
118 fDrawState->fColorStages.pop_back_n(m); | 150 fPipelineBuilder->fColorStages.pop_back_n(m); |
119 | 151 |
120 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt; | 152 int n = fPipelineBuilder->numCoverageStages() - fCoverageEffectCnt; |
121 SkASSERT(n >= 0); | 153 SkASSERT(n >= 0); |
122 fDrawState->fCoverageStages.pop_back_n(n); | 154 fPipelineBuilder->fCoverageStages.pop_back_n(n); |
123 if (m + n > 0) { | 155 if (m + n > 0) { |
124 fDrawState->fColorProcInfoValid = false; | 156 fPipelineBuilder->fColorProcInfoValid = false; |
125 fDrawState->fCoverageProcInfoValid = false; | 157 fPipelineBuilder->fCoverageProcInfoValid = false; |
126 } | 158 } |
127 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) | 159 SkDEBUGCODE(--fPipelineBuilder->fBlockEffectRemovalCnt;) |
128 } | 160 } |
129 fDrawState = ds; | 161 fPipelineBuilder = pipelineBuilder; |
130 if (NULL != ds) { | 162 if (NULL != pipelineBuilder) { |
131 fColorEffectCnt = ds->numColorStages(); | 163 fColorEffectCnt = pipelineBuilder->numColorStages(); |
132 fCoverageEffectCnt = ds->numCoverageStages(); | 164 fCoverageEffectCnt = pipelineBuilder->numCoverageStages(); |
133 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;) | 165 SkDEBUGCODE(++pipelineBuilder->fBlockEffectRemovalCnt;) |
134 } | 166 } |
135 } | 167 } |
136 | 168 |
137 //////////////////////////////////////////////////////////////////////////////// | 169 //////////////////////////////////////////////////////////////////////////////// |
138 | 170 |
139 // Some blend modes allow folding a fractional coverage value into the color's a lpha channel, while | 171 // Some blend modes allow folding a fractional coverage value into the color's a lpha channel, while |
140 // others will blend incorrectly. | 172 // others will blend incorrectly. |
141 bool GrDrawState::canTweakAlphaForCoverage() const { | 173 bool GrPipelineBuilder::canTweakAlphaForCoverage() const { |
142 return this->getXPFactory()->canTweakAlphaForCoverage(); | 174 return this->getXPFactory()->canTweakAlphaForCoverage(); |
143 } | 175 } |
144 | 176 |
145 //////////////////////////////////////////////////////////////////////////////// | 177 //////////////////////////////////////////////////////////////////////////////// |
146 | 178 |
147 GrDrawState::~GrDrawState() { | 179 GrPipelineBuilder::~GrPipelineBuilder() { |
148 SkASSERT(0 == fBlockEffectRemovalCnt); | 180 SkASSERT(0 == fBlockEffectRemovalCnt); |
149 } | 181 } |
150 | 182 |
151 //////////////////////////////////////////////////////////////////////////////// | 183 //////////////////////////////////////////////////////////////////////////////// |
152 | 184 |
153 bool GrDrawState::willBlendWithDst(const GrPrimitiveProcessor* pp) const { | 185 bool GrPipelineBuilder::willBlendWithDst(const GrPrimitiveProcessor* pp) const { |
154 this->calcColorInvariantOutput(pp); | 186 this->calcColorInvariantOutput(pp); |
155 this->calcCoverageInvariantOutput(pp); | 187 this->calcCoverageInvariantOutput(pp); |
156 | 188 |
157 GrXPFactory::InvariantOutput output; | 189 GrXPFactory::InvariantOutput output; |
158 fXPFactory->getInvariantOutput(fColorProcInfo, fCoverageProcInfo, &output); | 190 fXPFactory->getInvariantOutput(fColorProcInfo, fCoverageProcInfo, &output); |
159 return output.fWillBlendWithDst; | 191 return output.fWillBlendWithDst; |
160 } | 192 } |
161 | 193 |
162 void GrDrawState::calcColorInvariantOutput(const GrPrimitiveProcessor* pp) const { | 194 void GrPipelineBuilder::calcColorInvariantOutput(const GrPrimitiveProcessor* pp) const { |
163 if (!fColorProcInfoValid || fColorPrimProc != pp) { | 195 if (!fColorProcInfoValid || fColorPrimProc != pp) { |
164 fColorProcInfo.calcColorWithPrimProc(pp, fColorStages.begin(), this->num ColorStages()); | 196 fColorProcInfo.calcColorWithPrimProc(pp, fColorStages.begin(), this->num ColorStages()); |
165 fColorProcInfoValid = true; | 197 fColorProcInfoValid = true; |
166 fColorPrimProc = pp; | 198 fColorPrimProc = pp; |
167 } | 199 } |
168 } | 200 } |
169 | 201 |
170 void GrDrawState::calcCoverageInvariantOutput(const GrPrimitiveProcessor* pp) co nst { | 202 void GrPipelineBuilder::calcCoverageInvariantOutput(const GrPrimitiveProcessor* pp) const { |
171 if (!fCoverageProcInfoValid || fCoveragePrimProc != pp) { | 203 if (!fCoverageProcInfoValid || fCoveragePrimProc != pp) { |
172 fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageStages.begin(), | 204 fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageStages.begin(), |
173 this->numCoverageStages()); | 205 this->numCoverageStages()); |
174 fCoverageProcInfoValid = true; | 206 fCoverageProcInfoValid = true; |
175 fCoveragePrimProc = pp; | 207 fCoveragePrimProc = pp; |
176 } | 208 } |
177 } | 209 } |
178 | 210 |
179 void GrDrawState::calcColorInvariantOutput(GrColor color) const { | 211 void GrPipelineBuilder::calcColorInvariantOutput(GrColor color) const { |
180 if (!fColorProcInfoValid || color != fColorCache) { | 212 if (!fColorProcInfoValid || color != fColorCache) { |
181 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; | 213 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; |
182 fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColo rStages(), color, | 214 fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColo rStages(), color, |
183 flags, false); | 215 flags, false); |
184 fColorProcInfoValid = true; | 216 fColorProcInfoValid = true; |
185 fColorCache = color; | 217 fColorCache = color; |
186 } | 218 } |
187 } | 219 } |
188 | 220 |
189 void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const { | 221 void GrPipelineBuilder::calcCoverageInvariantOutput(GrColor coverage) const { |
190 if (!fCoverageProcInfoValid || coverage != fCoverageCache) { | 222 if (!fCoverageProcInfoValid || coverage != fCoverageCache) { |
191 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; | 223 GrColorComponentFlags flags = kRGBA_GrColorComponentFlags; |
192 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), | 224 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), |
193 this->numCoverageStages(), cover age, flags, | 225 this->numCoverageStages(), cover age, flags, |
194 true); | 226 true); |
195 fCoverageProcInfoValid = true; | 227 fCoverageProcInfoValid = true; |
196 fCoverageCache = coverage; | 228 fCoverageCache = coverage; |
197 } | 229 } |
198 } | 230 } |
OLD | NEW |