OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrBezierEffect.h" | 8 #include "GrBezierEffect.h" |
9 | 9 |
10 #include "gl/GrGLProcessor.h" | 10 #include "gl/GrGLProcessor.h" |
11 #include "gl/GrGLSL.h" | 11 #include "gl/GrGLSL.h" |
12 #include "gl/GrGLGeometryProcessor.h" | 12 #include "gl/GrGLGeometryProcessor.h" |
13 #include "gl/builders/GrGLProgramBuilder.h" | 13 #include "gl/builders/GrGLProgramBuilder.h" |
14 | 14 |
| 15 struct ConicBatchTracker { |
| 16 GrGPInput fInputColorType; |
| 17 GrColor fColor; |
| 18 uint8_t fCoverageScale; |
| 19 }; |
| 20 |
15 class GrGLConicEffect : public GrGLGeometryProcessor { | 21 class GrGLConicEffect : public GrGLGeometryProcessor { |
16 public: | 22 public: |
17 GrGLConicEffect(const GrGeometryProcessor&, | 23 GrGLConicEffect(const GrGeometryProcessor&, |
18 const GrBatchTracker&); | 24 const GrBatchTracker&); |
19 | 25 |
20 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 26 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
21 | 27 |
22 static inline void GenKey(const GrGeometryProcessor&, | 28 static inline void GenKey(const GrGeometryProcessor&, |
23 const GrBatchTracker&, | 29 const GrBatchTracker&, |
24 const GrGLCaps&, | 30 const GrGLCaps&, |
25 GrProcessorKeyBuilder*); | 31 GrProcessorKeyBuilder*); |
26 | 32 |
27 virtual void setData(const GrGLProgramDataManager&, | 33 virtual void setData(const GrGLProgramDataManager& pdman, |
28 const GrGeometryProcessor&, | 34 const GrPrimitiveProcessor&, |
29 const GrBatchTracker&) SK_OVERRIDE {} | 35 const GrBatchTracker& bt) SK_OVERRIDE { |
| 36 const ConicBatchTracker& local = bt.cast<ConicBatchTracker>(); |
| 37 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
| 38 GrGLfloat c[4]; |
| 39 GrColorToRGBAFloat(local.fColor, c); |
| 40 pdman.set4fv(fColorUniform, 1, c); |
| 41 fColor = local.fColor; |
| 42 } |
| 43 if (0xff != local.fCoverageScale && fCoverageScale != local.fCoverageSca
le) { |
| 44 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(local.fCov
erageScale)); |
| 45 fCoverageScale = local.fCoverageScale; |
| 46 } |
| 47 } |
30 | 48 |
31 private: | 49 private: |
| 50 GrColor fColor; |
| 51 uint8_t fCoverageScale; |
32 GrPrimitiveEdgeType fEdgeType; | 52 GrPrimitiveEdgeType fEdgeType; |
| 53 UniformHandle fColorUniform; |
| 54 UniformHandle fCoverageScaleUniform; |
33 | 55 |
34 typedef GrGLGeometryProcessor INHERITED; | 56 typedef GrGLGeometryProcessor INHERITED; |
35 }; | 57 }; |
36 | 58 |
37 GrGLConicEffect::GrGLConicEffect(const GrGeometryProcessor& processor, | 59 GrGLConicEffect::GrGLConicEffect(const GrGeometryProcessor& processor, |
38 const GrBatchTracker& bt) { | 60 const GrBatchTracker& bt) |
| 61 : fColor(GrColor_ILLEGAL), fCoverageScale(0xff) { |
39 const GrConicEffect& ce = processor.cast<GrConicEffect>(); | 62 const GrConicEffect& ce = processor.cast<GrConicEffect>(); |
40 fEdgeType = ce.getEdgeType(); | 63 fEdgeType = ce.getEdgeType(); |
41 } | 64 } |
42 | 65 |
43 void GrGLConicEffect::emitCode(const EmitArgs& args) { | 66 void GrGLConicEffect::emitCode(const EmitArgs& args) { |
| 67 GrGLGPBuilder* pb = args.fPB; |
44 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 68 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
45 const GrConicEffect& gp = args.fGP.cast<GrConicEffect>(); | 69 const GrConicEffect& gp = args.fGP.cast<GrConicEffect>(); |
| 70 const ConicBatchTracker& local = args.fBT.cast<ConicBatchTracker>(); |
46 | 71 |
47 GrGLVertToFrag v(kVec4f_GrSLType); | 72 GrGLVertToFrag v(kVec4f_GrSLType); |
48 args.fPB->addVarying("ConicCoeffs", &v); | 73 args.fPB->addVarying("ConicCoeffs", &v); |
49 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inConicCoeffs()->fName); | 74 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inConicCoeffs()->fName); |
50 | 75 |
| 76 // Setup pass through color |
| 77 this->setupColorPassThrough(args.fPB, local.fInputColorType, args.fOutputCol
or, NULL, |
| 78 &fColorUniform); |
| 79 |
51 // setup coord outputs | 80 // setup coord outputs |
52 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), gp.inPositio
n()->fName); | 81 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), gp.inPositio
n()->fName); |
53 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), gp.inPosition()
->fName); | 82 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), gp.inPosition()
->fName); |
54 | 83 |
55 // setup position varying | 84 // setup position varying |
56 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), | 85 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), |
57 gp.inPosition()->fName); | 86 gp.inPosition()->fName); |
58 | 87 |
59 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 88 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
60 fsBuilder->codeAppend("float edgeAlpha;"); | 89 fsBuilder->codeAppend("float edgeAlpha;"); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 case kFillBW_GrProcessorEdgeType: { | 135 case kFillBW_GrProcessorEdgeType: { |
107 fsBuilder->codeAppendf("edgeAlpha = %s.x * %s.x - %s.y * %s.z;", v.f
sIn(), v.fsIn(), | 136 fsBuilder->codeAppendf("edgeAlpha = %s.x * %s.x - %s.y * %s.z;", v.f
sIn(), v.fsIn(), |
108 v.fsIn(), v.fsIn()); | 137 v.fsIn(), v.fsIn()); |
109 fsBuilder->codeAppend("edgeAlpha = float(edgeAlpha < 0.0);"); | 138 fsBuilder->codeAppend("edgeAlpha = float(edgeAlpha < 0.0);"); |
110 break; | 139 break; |
111 } | 140 } |
112 default: | 141 default: |
113 SkFAIL("Shouldn't get here"); | 142 SkFAIL("Shouldn't get here"); |
114 } | 143 } |
115 | 144 |
116 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); | 145 if (0xff != local.fCoverageScale) { |
| 146 const char* coverageScale; |
| 147 fCoverageScaleUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Vis
ibility, |
| 148 kFloat_GrSLType, |
| 149 kDefault_GrSLPrecision, |
| 150 "Coverage", |
| 151 &coverageScale); |
| 152 fsBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverag
e, coverageScale); |
| 153 } else { |
| 154 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
| 155 } |
117 } | 156 } |
118 | 157 |
119 void GrGLConicEffect::GenKey(const GrGeometryProcessor& processor, | 158 void GrGLConicEffect::GenKey(const GrGeometryProcessor& processor, |
120 const GrBatchTracker&, | 159 const GrBatchTracker& bt, |
121 const GrGLCaps&, | 160 const GrGLCaps&, |
122 GrProcessorKeyBuilder* b) { | 161 GrProcessorKeyBuilder* b) { |
123 const GrConicEffect& ce = processor.cast<GrConicEffect>(); | 162 const GrConicEffect& ce = processor.cast<GrConicEffect>(); |
| 163 const ConicBatchTracker& local = bt.cast<ConicBatchTracker>(); |
124 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 164 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
| 165 key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x0; |
| 166 key |= 0xff != local.fCoverageScale ? 0x8 : 0x0; |
125 b->add32(key); | 167 b->add32(key); |
126 } | 168 } |
127 | 169 |
128 ////////////////////////////////////////////////////////////////////////////// | 170 ////////////////////////////////////////////////////////////////////////////// |
129 | 171 |
130 GrConicEffect::~GrConicEffect() {} | 172 GrConicEffect::~GrConicEffect() {} |
131 | 173 |
132 void GrConicEffect::getGLProcessorKey(const GrBatchTracker& bt, | 174 void GrConicEffect::getGLProcessorKey(const GrBatchTracker& bt, |
133 const GrGLCaps& caps, | 175 const GrGLCaps& caps, |
134 GrProcessorKeyBuilder* b) const { | 176 GrProcessorKeyBuilder* b) const { |
135 GrGLConicEffect::GenKey(*this, bt, caps, b); | 177 GrGLConicEffect::GenKey(*this, bt, caps, b); |
136 } | 178 } |
137 | 179 |
138 GrGLGeometryProcessor* GrConicEffect::createGLInstance(const GrBatchTracker& bt)
const { | 180 GrGLGeometryProcessor* GrConicEffect::createGLInstance(const GrBatchTracker& bt)
const { |
139 return SkNEW_ARGS(GrGLConicEffect, (*this, bt)); | 181 return SkNEW_ARGS(GrGLConicEffect, (*this, bt)); |
140 } | 182 } |
141 | 183 |
142 GrConicEffect::GrConicEffect(GrColor color, uint8_t coverage, GrPrimitiveEdgeTyp
e edgeType) | 184 GrConicEffect::GrConicEffect(GrColor color, uint8_t coverage, GrPrimitiveEdgeTyp
e edgeType) |
143 : INHERITED(color, false, coverage), fEdgeType(edgeType) { | 185 : INHERITED(color, false), fCoverageScale(coverage), fEdgeType(edgeType) { |
144 this->initClassID<GrConicEffect>(); | 186 this->initClassID<GrConicEffect>(); |
145 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 187 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
146 fInConicCoeffs = &this->addVertexAttrib(GrAttribute("inConicCoeffs", | 188 fInConicCoeffs = &this->addVertexAttrib(GrAttribute("inConicCoeffs", |
147 kVec4f_GrVertexAttribTyp
e)); | 189 kVec4f_GrVertexAttribTyp
e)); |
148 } | 190 } |
149 | 191 |
150 bool GrConicEffect::onIsEqual(const GrGeometryProcessor& other) const { | 192 bool GrConicEffect::onIsEqual(const GrGeometryProcessor& other) const { |
151 const GrConicEffect& ce = other.cast<GrConicEffect>(); | 193 const GrConicEffect& ce = other.cast<GrConicEffect>(); |
152 return (ce.fEdgeType == fEdgeType); | 194 return (ce.fEdgeType == fEdgeType); |
153 } | 195 } |
154 | 196 |
| 197 void GrConicEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& init) con
st { |
| 198 ConicBatchTracker* local = bt->cast<ConicBatchTracker>(); |
| 199 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, false); |
| 200 local->fCoverageScale = fCoverageScale; |
| 201 } |
| 202 |
| 203 bool GrConicEffect::onCanMakeEqual(const GrBatchTracker& m, const GrBatchTracker
& t) const { |
| 204 const ConicBatchTracker& mine = m.cast<ConicBatchTracker>(); |
| 205 const ConicBatchTracker& theirs = t.cast<ConicBatchTracker>(); |
| 206 return CanCombineOutput(mine.fInputColorType, mine.fColor, |
| 207 theirs.fInputColorType, theirs.fColor) && |
| 208 mine.fCoverageScale == theirs.fCoverageScale; |
| 209 } |
| 210 |
155 ////////////////////////////////////////////////////////////////////////////// | 211 ////////////////////////////////////////////////////////////////////////////// |
156 | 212 |
157 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrConicEffect); | 213 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrConicEffect); |
158 | 214 |
159 GrGeometryProcessor* GrConicEffect::TestCreate(SkRandom* random, | 215 GrGeometryProcessor* GrConicEffect::TestCreate(SkRandom* random, |
160 GrContext*, | 216 GrContext*, |
161 const GrDrawTargetCaps& caps, | 217 const GrDrawTargetCaps& caps, |
162 GrTexture*[]) { | 218 GrTexture*[]) { |
163 GrGeometryProcessor* gp; | 219 GrGeometryProcessor* gp; |
164 do { | 220 do { |
165 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 221 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
166 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); | 222 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); |
167 gp = GrConicEffect::Create(GrRandomColor(random), edgeType, caps); | 223 gp = GrConicEffect::Create(GrRandomColor(random), edgeType, caps); |
168 } while (NULL == gp); | 224 } while (NULL == gp); |
169 return gp; | 225 return gp; |
170 } | 226 } |
171 | 227 |
172 ////////////////////////////////////////////////////////////////////////////// | 228 ////////////////////////////////////////////////////////////////////////////// |
173 // Quad | 229 // Quad |
174 ////////////////////////////////////////////////////////////////////////////// | 230 ////////////////////////////////////////////////////////////////////////////// |
175 | 231 |
| 232 struct QuadBatchTracker { |
| 233 GrGPInput fInputColorType; |
| 234 GrColor fColor; |
| 235 uint8_t fCoverageScale; |
| 236 }; |
| 237 |
176 class GrGLQuadEffect : public GrGLGeometryProcessor { | 238 class GrGLQuadEffect : public GrGLGeometryProcessor { |
177 public: | 239 public: |
178 GrGLQuadEffect(const GrGeometryProcessor&, | 240 GrGLQuadEffect(const GrGeometryProcessor&, |
179 const GrBatchTracker&); | 241 const GrBatchTracker&); |
180 | 242 |
181 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 243 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
182 | 244 |
183 static inline void GenKey(const GrGeometryProcessor&, | 245 static inline void GenKey(const GrGeometryProcessor&, |
184 const GrBatchTracker&, | 246 const GrBatchTracker&, |
185 const GrGLCaps&, | 247 const GrGLCaps&, |
186 GrProcessorKeyBuilder*); | 248 GrProcessorKeyBuilder*); |
187 | 249 |
188 virtual void setData(const GrGLProgramDataManager&, | 250 virtual void setData(const GrGLProgramDataManager& pdman, |
189 const GrGeometryProcessor&, | 251 const GrPrimitiveProcessor&, |
190 const GrBatchTracker&) SK_OVERRIDE {} | 252 const GrBatchTracker& bt) SK_OVERRIDE { |
| 253 const QuadBatchTracker& local = bt.cast<QuadBatchTracker>(); |
| 254 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
| 255 GrGLfloat c[4]; |
| 256 GrColorToRGBAFloat(local.fColor, c); |
| 257 pdman.set4fv(fColorUniform, 1, c); |
| 258 fColor = local.fColor; |
| 259 } |
| 260 if (0xff != local.fCoverageScale && local.fCoverageScale != fCoverageSca
le) { |
| 261 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(local.fCov
erageScale)); |
| 262 fCoverageScale = local.fCoverageScale; |
| 263 } |
| 264 } |
191 | 265 |
192 private: | 266 private: |
| 267 GrColor fColor; |
| 268 uint8_t fCoverageScale; |
193 GrPrimitiveEdgeType fEdgeType; | 269 GrPrimitiveEdgeType fEdgeType; |
| 270 UniformHandle fColorUniform; |
| 271 UniformHandle fCoverageScaleUniform; |
194 | 272 |
195 typedef GrGLGeometryProcessor INHERITED; | 273 typedef GrGLGeometryProcessor INHERITED; |
196 }; | 274 }; |
197 | 275 |
198 GrGLQuadEffect::GrGLQuadEffect(const GrGeometryProcessor& processor, | 276 GrGLQuadEffect::GrGLQuadEffect(const GrGeometryProcessor& processor, |
199 const GrBatchTracker& bt) { | 277 const GrBatchTracker& bt) |
| 278 : fColor(GrColor_ILLEGAL), fCoverageScale(0xff) { |
200 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); | 279 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); |
201 fEdgeType = ce.getEdgeType(); | 280 fEdgeType = ce.getEdgeType(); |
202 } | 281 } |
203 | 282 |
204 void GrGLQuadEffect::emitCode(const EmitArgs& args) { | 283 void GrGLQuadEffect::emitCode(const EmitArgs& args) { |
| 284 GrGLGPBuilder* pb = args.fPB; |
205 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 285 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
206 const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>(); | 286 const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>(); |
| 287 const QuadBatchTracker& local = args.fBT.cast<QuadBatchTracker>(); |
207 | 288 |
208 GrGLVertToFrag v(kVec4f_GrSLType); | 289 GrGLVertToFrag v(kVec4f_GrSLType); |
209 args.fPB->addVarying("HairQuadEdge", &v); | 290 args.fPB->addVarying("HairQuadEdge", &v); |
210 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inHairQuadEdge()->fName); | 291 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inHairQuadEdge()->fName); |
211 | 292 |
| 293 // Setup pass through color |
| 294 this->setupColorPassThrough(args.fPB, local.fInputColorType, args.fOutputCol
or, NULL, |
| 295 &fColorUniform); |
| 296 |
212 // setup coord outputs | 297 // setup coord outputs |
213 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), gp.inPositio
n()->fName); | 298 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), gp.inPositio
n()->fName); |
214 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), gp.inPosition()
->fName); | 299 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), gp.inPosition()
->fName); |
215 | 300 |
216 // setup position varying | 301 // setup position varying |
217 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), | 302 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), |
218 gp.inPosition()->fName); | 303 gp.inPosition()->fName); |
219 | 304 |
220 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 305 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
221 fsBuilder->codeAppendf("float edgeAlpha;"); | 306 fsBuilder->codeAppendf("float edgeAlpha;"); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 } | 338 } |
254 case kFillBW_GrProcessorEdgeType: { | 339 case kFillBW_GrProcessorEdgeType: { |
255 fsBuilder->codeAppendf("edgeAlpha = (%s.x * %s.x - %s.y);", v.fsIn()
, v.fsIn(), v.fsIn()); | 340 fsBuilder->codeAppendf("edgeAlpha = (%s.x * %s.x - %s.y);", v.fsIn()
, v.fsIn(), v.fsIn()); |
256 fsBuilder->codeAppend("edgeAlpha = float(edgeAlpha < 0.0);"); | 341 fsBuilder->codeAppend("edgeAlpha = float(edgeAlpha < 0.0);"); |
257 break; | 342 break; |
258 } | 343 } |
259 default: | 344 default: |
260 SkFAIL("Shouldn't get here"); | 345 SkFAIL("Shouldn't get here"); |
261 } | 346 } |
262 | 347 |
263 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); | 348 if (0xff != local.fCoverageScale) { |
| 349 const char* coverageScale; |
| 350 fCoverageScaleUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Vis
ibility, |
| 351 kFloat_GrSLType, |
| 352 kDefault_GrSLPrecision, |
| 353 "Coverage", |
| 354 &coverageScale); |
| 355 fsBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverag
e, coverageScale); |
| 356 } else { |
| 357 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
| 358 } |
264 } | 359 } |
265 | 360 |
266 void GrGLQuadEffect::GenKey(const GrGeometryProcessor& processor, | 361 void GrGLQuadEffect::GenKey(const GrGeometryProcessor& processor, |
267 const GrBatchTracker&, | 362 const GrBatchTracker& bt, |
268 const GrGLCaps&, | 363 const GrGLCaps&, |
269 GrProcessorKeyBuilder* b) { | 364 GrProcessorKeyBuilder* b) { |
270 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); | 365 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); |
| 366 const QuadBatchTracker& local = bt.cast<QuadBatchTracker>(); |
271 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 367 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
| 368 key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x0; |
| 369 key |= 0xff != local.fCoverageScale ? 0x8 : 0x0; |
272 b->add32(key); | 370 b->add32(key); |
273 } | 371 } |
274 | 372 |
275 ////////////////////////////////////////////////////////////////////////////// | 373 ////////////////////////////////////////////////////////////////////////////// |
276 | 374 |
277 GrQuadEffect::~GrQuadEffect() {} | 375 GrQuadEffect::~GrQuadEffect() {} |
278 | 376 |
279 void GrQuadEffect::getGLProcessorKey(const GrBatchTracker& bt, | 377 void GrQuadEffect::getGLProcessorKey(const GrBatchTracker& bt, |
280 const GrGLCaps& caps, | 378 const GrGLCaps& caps, |
281 GrProcessorKeyBuilder* b) const { | 379 GrProcessorKeyBuilder* b) const { |
282 GrGLQuadEffect::GenKey(*this, bt, caps, b); | 380 GrGLQuadEffect::GenKey(*this, bt, caps, b); |
283 } | 381 } |
284 | 382 |
285 GrGLGeometryProcessor* GrQuadEffect::createGLInstance(const GrBatchTracker& bt)
const { | 383 GrGLGeometryProcessor* GrQuadEffect::createGLInstance(const GrBatchTracker& bt)
const { |
286 return SkNEW_ARGS(GrGLQuadEffect, (*this, bt)); | 384 return SkNEW_ARGS(GrGLQuadEffect, (*this, bt)); |
287 } | 385 } |
288 | 386 |
289 GrQuadEffect::GrQuadEffect(GrColor color, uint8_t coverage, GrPrimitiveEdgeType
edgeType) | 387 GrQuadEffect::GrQuadEffect(GrColor color, uint8_t coverage, GrPrimitiveEdgeType
edgeType) |
290 : INHERITED(color, false, coverage), fEdgeType(edgeType) { | 388 : INHERITED(color, false), fCoverageScale(coverage), fEdgeType(edgeType) { |
291 this->initClassID<GrQuadEffect>(); | 389 this->initClassID<GrQuadEffect>(); |
292 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 390 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
293 fInHairQuadEdge = &this->addVertexAttrib(GrAttribute("inHairQuadEdge", | 391 fInHairQuadEdge = &this->addVertexAttrib(GrAttribute("inHairQuadEdge", |
294 kVec4f_GrVertexAttribTyp
e)); | 392 kVec4f_GrVertexAttribTyp
e)); |
295 } | 393 } |
296 | 394 |
297 bool GrQuadEffect::onIsEqual(const GrGeometryProcessor& other) const { | 395 bool GrQuadEffect::onIsEqual(const GrGeometryProcessor& other) const { |
298 const GrQuadEffect& ce = other.cast<GrQuadEffect>(); | 396 const GrQuadEffect& ce = other.cast<GrQuadEffect>(); |
299 return (ce.fEdgeType == fEdgeType); | 397 return (ce.fEdgeType == fEdgeType); |
300 } | 398 } |
301 | 399 |
| 400 void GrQuadEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& init) cons
t { |
| 401 QuadBatchTracker* local = bt->cast<QuadBatchTracker>(); |
| 402 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, false); |
| 403 local->fCoverageScale = fCoverageScale; |
| 404 } |
| 405 |
| 406 bool GrQuadEffect::onCanMakeEqual(const GrBatchTracker& m, const GrBatchTracker&
t) const { |
| 407 const QuadBatchTracker& mine = m.cast<QuadBatchTracker>(); |
| 408 const QuadBatchTracker& theirs = t.cast<QuadBatchTracker>(); |
| 409 return CanCombineOutput(mine.fInputColorType, mine.fColor, |
| 410 theirs.fInputColorType, theirs.fColor) && |
| 411 mine.fCoverageScale == theirs.fCoverageScale; |
| 412 } |
| 413 |
302 ////////////////////////////////////////////////////////////////////////////// | 414 ////////////////////////////////////////////////////////////////////////////// |
303 | 415 |
304 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrQuadEffect); | 416 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrQuadEffect); |
305 | 417 |
306 GrGeometryProcessor* GrQuadEffect::TestCreate(SkRandom* random, | 418 GrGeometryProcessor* GrQuadEffect::TestCreate(SkRandom* random, |
307 GrContext*, | 419 GrContext*, |
308 const GrDrawTargetCaps& caps, | 420 const GrDrawTargetCaps& caps, |
309 GrTexture*[]) { | 421 GrTexture*[]) { |
310 GrGeometryProcessor* gp; | 422 GrGeometryProcessor* gp; |
311 do { | 423 do { |
312 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 424 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
313 random->nextULessThan(kGrProcessorEdgeTypeCnt)); | 425 random->nextULessThan(kGrProcessorEdgeTypeCnt)); |
314 gp = GrQuadEffect::Create(GrRandomColor(random), edgeType, caps); | 426 gp = GrQuadEffect::Create(GrRandomColor(random), edgeType, caps); |
315 } while (NULL == gp); | 427 } while (NULL == gp); |
316 return gp; | 428 return gp; |
317 } | 429 } |
318 | 430 |
319 ////////////////////////////////////////////////////////////////////////////// | 431 ////////////////////////////////////////////////////////////////////////////// |
320 // Cubic | 432 // Cubic |
321 ////////////////////////////////////////////////////////////////////////////// | 433 ////////////////////////////////////////////////////////////////////////////// |
322 | 434 |
| 435 struct CubicBatchTracker { |
| 436 GrGPInput fInputColorType; |
| 437 GrColor fColor; |
| 438 }; |
| 439 |
323 class GrGLCubicEffect : public GrGLGeometryProcessor { | 440 class GrGLCubicEffect : public GrGLGeometryProcessor { |
324 public: | 441 public: |
325 GrGLCubicEffect(const GrGeometryProcessor&, | 442 GrGLCubicEffect(const GrGeometryProcessor&, |
326 const GrBatchTracker&); | 443 const GrBatchTracker&); |
327 | 444 |
328 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 445 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
329 | 446 |
330 static inline void GenKey(const GrGeometryProcessor&, | 447 static inline void GenKey(const GrGeometryProcessor&, |
331 const GrBatchTracker&, | 448 const GrBatchTracker&, |
332 const GrGLCaps&, | 449 const GrGLCaps&, |
333 GrProcessorKeyBuilder*); | 450 GrProcessorKeyBuilder*); |
334 | 451 |
335 virtual void setData(const GrGLProgramDataManager&, | 452 virtual void setData(const GrGLProgramDataManager& pdman, |
336 const GrGeometryProcessor&, | 453 const GrPrimitiveProcessor&, |
337 const GrBatchTracker&) SK_OVERRIDE {} | 454 const GrBatchTracker& bt) SK_OVERRIDE { |
| 455 const CubicBatchTracker& local = bt.cast<CubicBatchTracker>(); |
| 456 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
| 457 GrGLfloat c[4]; |
| 458 GrColorToRGBAFloat(local.fColor, c); |
| 459 pdman.set4fv(fColorUniform, 1, c); |
| 460 fColor = local.fColor; |
| 461 } |
| 462 } |
338 | 463 |
339 private: | 464 private: |
| 465 GrColor fColor; |
340 GrPrimitiveEdgeType fEdgeType; | 466 GrPrimitiveEdgeType fEdgeType; |
| 467 UniformHandle fColorUniform; |
341 | 468 |
342 typedef GrGLGeometryProcessor INHERITED; | 469 typedef GrGLGeometryProcessor INHERITED; |
343 }; | 470 }; |
344 | 471 |
345 GrGLCubicEffect::GrGLCubicEffect(const GrGeometryProcessor& processor, | 472 GrGLCubicEffect::GrGLCubicEffect(const GrGeometryProcessor& processor, |
346 const GrBatchTracker&) { | 473 const GrBatchTracker&) |
| 474 : fColor(GrColor_ILLEGAL) { |
347 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); | 475 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); |
348 fEdgeType = ce.getEdgeType(); | 476 fEdgeType = ce.getEdgeType(); |
349 } | 477 } |
350 | 478 |
351 void GrGLCubicEffect::emitCode(const EmitArgs& args) { | 479 void GrGLCubicEffect::emitCode(const EmitArgs& args) { |
352 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 480 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
353 const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>(); | 481 const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>(); |
| 482 const CubicBatchTracker& local = args.fBT.cast<CubicBatchTracker>(); |
354 | 483 |
355 GrGLVertToFrag v(kVec4f_GrSLType); | 484 GrGLVertToFrag v(kVec4f_GrSLType); |
356 args.fPB->addVarying("CubicCoeffs", &v, kHigh_GrSLPrecision); | 485 args.fPB->addVarying("CubicCoeffs", &v, kHigh_GrSLPrecision); |
357 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inCubicCoeffs()->fName); | 486 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inCubicCoeffs()->fName); |
358 | 487 |
| 488 // Setup pass through color |
| 489 this->setupColorPassThrough(args.fPB, local.fInputColorType, args.fOutputCol
or, NULL, |
| 490 &fColorUniform); |
| 491 |
359 // setup coord outputs | 492 // setup coord outputs |
360 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), gp.inPositio
n()->fName); | 493 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), gp.inPositio
n()->fName); |
361 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), gp.inPosition()
->fName); | 494 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), gp.inPosition()
->fName); |
362 | 495 |
363 // setup position varying | 496 // setup position varying |
364 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), | 497 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), |
365 gp.inPosition()->fName); | 498 gp.inPosition()->fName); |
366 | 499 |
367 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 500 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
368 | 501 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 } | 578 } |
446 default: | 579 default: |
447 SkFAIL("Shouldn't get here"); | 580 SkFAIL("Shouldn't get here"); |
448 } | 581 } |
449 | 582 |
450 | 583 |
451 fsBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, edgeAlpha.c_s
tr()); | 584 fsBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, edgeAlpha.c_s
tr()); |
452 } | 585 } |
453 | 586 |
454 void GrGLCubicEffect::GenKey(const GrGeometryProcessor& processor, | 587 void GrGLCubicEffect::GenKey(const GrGeometryProcessor& processor, |
455 const GrBatchTracker&, | 588 const GrBatchTracker& bt, |
456 const GrGLCaps&, | 589 const GrGLCaps&, |
457 GrProcessorKeyBuilder* b) { | 590 GrProcessorKeyBuilder* b) { |
458 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); | 591 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); |
| 592 const CubicBatchTracker& local = bt.cast<CubicBatchTracker>(); |
459 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 593 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
| 594 key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x8; |
460 b->add32(key); | 595 b->add32(key); |
461 } | 596 } |
462 | 597 |
463 ////////////////////////////////////////////////////////////////////////////// | 598 ////////////////////////////////////////////////////////////////////////////// |
464 | 599 |
465 GrCubicEffect::~GrCubicEffect() {} | 600 GrCubicEffect::~GrCubicEffect() {} |
466 | 601 |
467 void GrCubicEffect::getGLProcessorKey(const GrBatchTracker& bt, | 602 void GrCubicEffect::getGLProcessorKey(const GrBatchTracker& bt, |
468 const GrGLCaps& caps, | 603 const GrGLCaps& caps, |
469 GrProcessorKeyBuilder* b) const { | 604 GrProcessorKeyBuilder* b) const { |
(...skipping 10 matching lines...) Expand all Loading... |
480 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 615 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
481 fInCubicCoeffs = &this->addVertexAttrib(GrAttribute("inCubicCoeffs", | 616 fInCubicCoeffs = &this->addVertexAttrib(GrAttribute("inCubicCoeffs", |
482 kVec4f_GrVertexAttribTyp
e)); | 617 kVec4f_GrVertexAttribTyp
e)); |
483 } | 618 } |
484 | 619 |
485 bool GrCubicEffect::onIsEqual(const GrGeometryProcessor& other) const { | 620 bool GrCubicEffect::onIsEqual(const GrGeometryProcessor& other) const { |
486 const GrCubicEffect& ce = other.cast<GrCubicEffect>(); | 621 const GrCubicEffect& ce = other.cast<GrCubicEffect>(); |
487 return (ce.fEdgeType == fEdgeType); | 622 return (ce.fEdgeType == fEdgeType); |
488 } | 623 } |
489 | 624 |
| 625 void GrCubicEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& init) con
st { |
| 626 CubicBatchTracker* local = bt->cast<CubicBatchTracker>(); |
| 627 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, false); |
| 628 } |
| 629 |
| 630 bool GrCubicEffect::onCanMakeEqual(const GrBatchTracker& m, const GrBatchTracker
& t) const { |
| 631 const CubicBatchTracker& mine = m.cast<CubicBatchTracker>(); |
| 632 const CubicBatchTracker& theirs = t.cast<CubicBatchTracker>(); |
| 633 return CanCombineOutput(mine.fInputColorType, mine.fColor, |
| 634 theirs.fInputColorType, theirs.fColor); |
| 635 } |
| 636 |
490 ////////////////////////////////////////////////////////////////////////////// | 637 ////////////////////////////////////////////////////////////////////////////// |
491 | 638 |
492 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCubicEffect); | 639 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCubicEffect); |
493 | 640 |
494 GrGeometryProcessor* GrCubicEffect::TestCreate(SkRandom* random, | 641 GrGeometryProcessor* GrCubicEffect::TestCreate(SkRandom* random, |
495 GrContext*, | 642 GrContext*, |
496 const GrDrawTargetCaps& caps, | 643 const GrDrawTargetCaps& caps, |
497 GrTexture*[]) { | 644 GrTexture*[]) { |
498 GrGeometryProcessor* gp; | 645 GrGeometryProcessor* gp; |
499 do { | 646 do { |
500 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 647 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
501 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); | 648 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); |
502 gp = GrCubicEffect::Create(GrRandomColor(random), edgeType, caps); | 649 gp = GrCubicEffect::Create(GrRandomColor(random), edgeType, caps); |
503 } while (NULL == gp); | 650 } while (NULL == gp); |
504 return gp; | 651 return gp; |
505 } | 652 } |
506 | 653 |
OLD | NEW |