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

Side by Side Diff: src/gpu/effects/GrBezierEffect.cpp

Issue 1139723004: Preliminary attempt to remove batch tracker (Closed) Base URL: https://skia.googlesource.com/skia.git@cleanup5
Patch Set: tweaks Created 5 years, 7 months 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/effects/GrBezierEffect.h ('k') | src/gpu/effects/GrBitmapTextGeoProc.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 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 bool fUsesLocalCoords;
20 };
21
22 class GrGLConicEffect : public GrGLGeometryProcessor { 15 class GrGLConicEffect : public GrGLGeometryProcessor {
23 public: 16 public:
24 GrGLConicEffect(const GrGeometryProcessor&, 17 GrGLConicEffect(const GrGeometryProcessor&,
25 const GrBatchTracker&); 18 const GrBatchTracker&);
26 19
27 void onEmitCode(EmitArgs&, GrGPArgs*) override; 20 void onEmitCode(EmitArgs&, GrGPArgs*) override;
28 21
29 static inline void GenKey(const GrGeometryProcessor&, 22 static inline void GenKey(const GrGeometryProcessor&,
30 const GrBatchTracker&, 23 const GrBatchTracker&,
31 const GrGLSLCaps&, 24 const GrGLSLCaps&,
32 GrProcessorKeyBuilder*); 25 GrProcessorKeyBuilder*);
33 26
34 virtual void setData(const GrGLProgramDataManager& pdman, 27 virtual void setData(const GrGLProgramDataManager& pdman,
35 const GrPrimitiveProcessor& primProc, 28 const GrPrimitiveProcessor& primProc,
36 const GrBatchTracker& bt) override { 29 const GrBatchTracker& bt) override {
37 const GrConicEffect& ce = primProc.cast<GrConicEffect>(); 30 const GrConicEffect& ce = primProc.cast<GrConicEffect>();
38 this->setUniformViewMatrix(pdman, ce.viewMatrix()); 31 this->setUniformViewMatrix(pdman, ce.viewMatrix());
39 32
40 const ConicBatchTracker& local = bt.cast<ConicBatchTracker>(); 33 if (ce.color() != fColor) {
41 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo r) {
42 GrGLfloat c[4]; 34 GrGLfloat c[4];
43 GrColorToRGBAFloat(local.fColor, c); 35 GrColorToRGBAFloat(ce.color(), c);
44 pdman.set4fv(fColorUniform, 1, c); 36 pdman.set4fv(fColorUniform, 1, c);
45 fColor = local.fColor; 37 fColor = ce.color();
46 } 38 }
47 if (0xff != local.fCoverageScale && fCoverageScale != local.fCoverageSca le) { 39
48 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(local.fCov erageScale)); 40 if (ce.coverageScale() != 0xff && ce.coverageScale() != fCoverageScale) {
49 fCoverageScale = local.fCoverageScale; 41 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(ce.coverag eScale()));
42 fCoverageScale = ce.coverageScale();
50 } 43 }
51 } 44 }
52 45
53 void setTransformData(const GrPrimitiveProcessor& primProc, 46 void setTransformData(const GrPrimitiveProcessor& primProc,
54 const GrGLProgramDataManager& pdman, 47 const GrGLProgramDataManager& pdman,
55 int index, 48 int index,
56 const SkTArray<const GrCoordTransform*, true>& transfo rms) override { 49 const SkTArray<const GrCoordTransform*, true>& transfo rms) override {
57 this->setTransformDataHelper<GrConicEffect>(primProc, pdman, index, tran sforms); 50 this->setTransformDataHelper<GrConicEffect>(primProc, pdman, index, tran sforms);
58 } 51 }
59 52
(...skipping 11 matching lines...) Expand all
71 const GrBatchTracker& bt) 64 const GrBatchTracker& bt)
72 : fColor(GrColor_ILLEGAL), fCoverageScale(0xff) { 65 : fColor(GrColor_ILLEGAL), fCoverageScale(0xff) {
73 const GrConicEffect& ce = processor.cast<GrConicEffect>(); 66 const GrConicEffect& ce = processor.cast<GrConicEffect>();
74 fEdgeType = ce.getEdgeType(); 67 fEdgeType = ce.getEdgeType();
75 } 68 }
76 69
77 void GrGLConicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { 70 void GrGLConicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
78 GrGLGPBuilder* pb = args.fPB; 71 GrGLGPBuilder* pb = args.fPB;
79 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); 72 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
80 const GrConicEffect& gp = args.fGP.cast<GrConicEffect>(); 73 const GrConicEffect& gp = args.fGP.cast<GrConicEffect>();
81 const ConicBatchTracker& local = args.fBT.cast<ConicBatchTracker>();
82 74
83 // emit attributes 75 // emit attributes
84 vsBuilder->emitAttributes(gp); 76 vsBuilder->emitAttributes(gp);
85 77
86 GrGLVertToFrag v(kVec4f_GrSLType); 78 GrGLVertToFrag v(kVec4f_GrSLType);
87 args.fPB->addVarying("ConicCoeffs", &v); 79 args.fPB->addVarying("ConicCoeffs", &v);
88 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inConicCoeffs()->fName); 80 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inConicCoeffs()->fName);
89 81
90 // Setup pass through color 82 // Setup pass through color
91 this->setupColorPassThrough(args.fPB, local.fInputColorType, args.fOutputCol or, NULL, 83 if (!gp.colorIgnored()) {
92 &fColorUniform); 84 this->setupUniformColor(args.fPB, args.fOutputColor, &fColorUniform);
85 }
93 86
94 // Setup position 87 // Setup position
95 this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatrix()); 88 this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatrix());
96 89
97 // emit transforms with position 90 // emit transforms with position
98 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()->fName, gp.lo calMatrix(), 91 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()->fName, gp.lo calMatrix(),
99 args.fTransformsIn, args.fTransformsOut); 92 args.fTransformsIn, args.fTransformsOut);
100 93
101 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 94 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
102 fsBuilder->codeAppend("float edgeAlpha;"); 95 fsBuilder->codeAppend("float edgeAlpha;");
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 case kFillBW_GrProcessorEdgeType: { 141 case kFillBW_GrProcessorEdgeType: {
149 fsBuilder->codeAppendf("edgeAlpha = %s.x * %s.x - %s.y * %s.z;", v.f sIn(), v.fsIn(), 142 fsBuilder->codeAppendf("edgeAlpha = %s.x * %s.x - %s.y * %s.z;", v.f sIn(), v.fsIn(),
150 v.fsIn(), v.fsIn()); 143 v.fsIn(), v.fsIn());
151 fsBuilder->codeAppend("edgeAlpha = float(edgeAlpha < 0.0);"); 144 fsBuilder->codeAppend("edgeAlpha = float(edgeAlpha < 0.0);");
152 break; 145 break;
153 } 146 }
154 default: 147 default:
155 SkFAIL("Shouldn't get here"); 148 SkFAIL("Shouldn't get here");
156 } 149 }
157 150
158 if (0xff != local.fCoverageScale) { 151 // TODO should we really be doing this?
152 if (gp.coverageScale() != 0xff) {
159 const char* coverageScale; 153 const char* coverageScale;
160 fCoverageScaleUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Vis ibility, 154 fCoverageScaleUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Vis ibility,
161 kFloat_GrSLType, 155 kFloat_GrSLType,
162 kDefault_GrSLPrecision, 156 kDefault_GrSLPrecision,
163 "Coverage", 157 "Coverage",
164 &coverageScale); 158 &coverageScale);
165 fsBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverag e, coverageScale); 159 fsBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverag e, coverageScale);
166 } else { 160 } else {
167 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); 161 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
168 } 162 }
169 } 163 }
170 164
171 void GrGLConicEffect::GenKey(const GrGeometryProcessor& gp, 165 void GrGLConicEffect::GenKey(const GrGeometryProcessor& gp,
172 const GrBatchTracker& bt, 166 const GrBatchTracker& bt,
173 const GrGLSLCaps&, 167 const GrGLSLCaps&,
174 GrProcessorKeyBuilder* b) { 168 GrProcessorKeyBuilder* b) {
175 const GrConicEffect& ce = gp.cast<GrConicEffect>(); 169 const GrConicEffect& ce = gp.cast<GrConicEffect>();
176 const ConicBatchTracker& local = bt.cast<ConicBatchTracker>();
177 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; 170 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2;
178 key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x0; 171 key |= GrColor_ILLEGAL != ce.color() ? 0x4 : 0x0;
179 key |= 0xff != local.fCoverageScale ? 0x8 : 0x0; 172 key |= 0xff != ce.coverageScale() ? 0x8 : 0x0;
180 key |= local.fUsesLocalCoords && ce.localMatrix().hasPerspective() ? 0x10 : 0x0; 173 key |= ce.usesLocalCoords() && ce.localMatrix().hasPerspective() ? 0x10 : 0x 0;
181 key |= ComputePosKey(ce.viewMatrix()) << 5; 174 key |= ComputePosKey(ce.viewMatrix()) << 5;
182 b->add32(key); 175 b->add32(key);
183 } 176 }
184 177
185 ////////////////////////////////////////////////////////////////////////////// 178 //////////////////////////////////////////////////////////////////////////////
186 179
187 GrConicEffect::~GrConicEffect() {} 180 GrConicEffect::~GrConicEffect() {}
188 181
189 void GrConicEffect::getGLProcessorKey(const GrBatchTracker& bt, 182 void GrConicEffect::getGLProcessorKey(const GrBatchTracker& bt,
190 const GrGLSLCaps& caps, 183 const GrGLSLCaps& caps,
191 GrProcessorKeyBuilder* b) const { 184 GrProcessorKeyBuilder* b) const {
192 GrGLConicEffect::GenKey(*this, bt, caps, b); 185 GrGLConicEffect::GenKey(*this, bt, caps, b);
193 } 186 }
194 187
195 GrGLPrimitiveProcessor* GrConicEffect::createGLInstance(const GrBatchTracker& bt , 188 GrGLPrimitiveProcessor* GrConicEffect::createGLInstance(const GrBatchTracker& bt ,
196 const GrGLSLCaps&) const { 189 const GrGLSLCaps&) const {
197 return SkNEW_ARGS(GrGLConicEffect, (*this, bt)); 190 return SkNEW_ARGS(GrGLConicEffect, (*this, bt));
198 } 191 }
199 192
200 GrConicEffect::GrConicEffect(GrColor color, const SkMatrix& viewMatrix, uint8_t coverage, 193 GrConicEffect::GrConicEffect(GrColor color, const SkMatrix& viewMatrix, uint8_t coverage,
201 GrPrimitiveEdgeType edgeType, const SkMatrix& local Matrix) 194 GrPrimitiveEdgeType edgeType, const SkMatrix& local Matrix,
195 bool usesLocalCoords)
202 : fColor(color) 196 : fColor(color)
203 , fViewMatrix(viewMatrix) 197 , fViewMatrix(viewMatrix)
204 , fLocalMatrix(viewMatrix) 198 , fLocalMatrix(viewMatrix)
199 , fUsesLocalCoords(usesLocalCoords)
205 , fCoverageScale(coverage) 200 , fCoverageScale(coverage)
206 , fEdgeType(edgeType) { 201 , fEdgeType(edgeType) {
207 this->initClassID<GrConicEffect>(); 202 this->initClassID<GrConicEffect>();
208 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); 203 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType));
209 fInConicCoeffs = &this->addVertexAttrib(Attribute("inConicCoeffs", 204 fInConicCoeffs = &this->addVertexAttrib(Attribute("inConicCoeffs",
210 kVec4f_GrVertexAttribTyp e)); 205 kVec4f_GrVertexAttribType) );
211 }
212
213 void GrConicEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& i nit) const {
214 ConicBatchTracker* local = bt->cast<ConicBatchTracker>();
215 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in it, false);
216 local->fCoverageScale = fCoverageScale;
217 local->fUsesLocalCoords = init.fUsesLocalCoords;
218 } 206 }
219 207
220 ////////////////////////////////////////////////////////////////////////////// 208 //////////////////////////////////////////////////////////////////////////////
221 209
222 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrConicEffect); 210 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrConicEffect);
223 211
224 GrGeometryProcessor* GrConicEffect::TestCreate(SkRandom* random, 212 GrGeometryProcessor* GrConicEffect::TestCreate(SkRandom* random,
225 GrContext*, 213 GrContext*,
226 const GrDrawTargetCaps& caps, 214 const GrDrawTargetCaps& caps,
227 GrTexture*[]) { 215 GrTexture*[]) {
228 GrGeometryProcessor* gp; 216 GrGeometryProcessor* gp;
229 do { 217 do {
230 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( 218 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(
231 random->nextULessThan(kGrPro cessorEdgeTypeCnt)); 219 random->nextULessThan(kGrPro cessorEdgeTypeCnt));
232 gp = GrConicEffect::Create(GrRandomColor(random), GrTest::TestMatrix(ran dom), 220 gp = GrConicEffect::Create(GrRandomColor(random), GrTest::TestMatrix(ran dom),
233 edgeType, caps, 221 edgeType, caps,
234 GrTest::TestMatrix(random)); 222 GrTest::TestMatrix(random), random->nextBool( ));
235 } while (NULL == gp); 223 } while (NULL == gp);
236 return gp; 224 return gp;
237 } 225 }
238 226
239 ////////////////////////////////////////////////////////////////////////////// 227 //////////////////////////////////////////////////////////////////////////////
240 // Quad 228 // Quad
241 ////////////////////////////////////////////////////////////////////////////// 229 //////////////////////////////////////////////////////////////////////////////
242 230
243 struct QuadBatchTracker {
244 GrGPInput fInputColorType;
245 GrColor fColor;
246 uint8_t fCoverageScale;
247 bool fUsesLocalCoords;
248 };
249
250 class GrGLQuadEffect : public GrGLGeometryProcessor { 231 class GrGLQuadEffect : public GrGLGeometryProcessor {
251 public: 232 public:
252 GrGLQuadEffect(const GrGeometryProcessor&, 233 GrGLQuadEffect(const GrGeometryProcessor&,
253 const GrBatchTracker&); 234 const GrBatchTracker&);
254 235
255 void onEmitCode(EmitArgs&, GrGPArgs*) override; 236 void onEmitCode(EmitArgs&, GrGPArgs*) override;
256 237
257 static inline void GenKey(const GrGeometryProcessor&, 238 static inline void GenKey(const GrGeometryProcessor&,
258 const GrBatchTracker&, 239 const GrBatchTracker&,
259 const GrGLSLCaps&, 240 const GrGLSLCaps&,
260 GrProcessorKeyBuilder*); 241 GrProcessorKeyBuilder*);
261 242
262 virtual void setData(const GrGLProgramDataManager& pdman, 243 virtual void setData(const GrGLProgramDataManager& pdman,
263 const GrPrimitiveProcessor& primProc, 244 const GrPrimitiveProcessor& primProc,
264 const GrBatchTracker& bt) override { 245 const GrBatchTracker& bt) override {
265 const GrQuadEffect& qe = primProc.cast<GrQuadEffect>(); 246 const GrQuadEffect& qe = primProc.cast<GrQuadEffect>();
266 this->setUniformViewMatrix(pdman, qe.viewMatrix()); 247 this->setUniformViewMatrix(pdman, qe.viewMatrix());
267 248
268 const QuadBatchTracker& local = bt.cast<QuadBatchTracker>(); 249 if (qe.color() != fColor) {
269 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo r) {
270 GrGLfloat c[4]; 250 GrGLfloat c[4];
271 GrColorToRGBAFloat(local.fColor, c); 251 GrColorToRGBAFloat(qe.color(), c);
272 pdman.set4fv(fColorUniform, 1, c); 252 pdman.set4fv(fColorUniform, 1, c);
273 fColor = local.fColor; 253 fColor = qe.color();
274 } 254 }
275 if (0xff != local.fCoverageScale && local.fCoverageScale != fCoverageSca le) { 255
276 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(local.fCov erageScale)); 256 if (qe.coverageScale() != 0xff && qe.coverageScale() != fCoverageScale) {
277 fCoverageScale = local.fCoverageScale; 257 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(qe.coverag eScale()));
258 fCoverageScale = qe.coverageScale();
278 } 259 }
279 } 260 }
280 261
281 void setTransformData(const GrPrimitiveProcessor& primProc, 262 void setTransformData(const GrPrimitiveProcessor& primProc,
282 const GrGLProgramDataManager& pdman, 263 const GrGLProgramDataManager& pdman,
283 int index, 264 int index,
284 const SkTArray<const GrCoordTransform*, true>& transfo rms) override { 265 const SkTArray<const GrCoordTransform*, true>& transfo rms) override {
285 this->setTransformDataHelper<GrQuadEffect>(primProc, pdman, index, trans forms); 266 this->setTransformDataHelper<GrQuadEffect>(primProc, pdman, index, trans forms);
286 } 267 }
287 268
(...skipping 11 matching lines...) Expand all
299 const GrBatchTracker& bt) 280 const GrBatchTracker& bt)
300 : fColor(GrColor_ILLEGAL), fCoverageScale(0xff) { 281 : fColor(GrColor_ILLEGAL), fCoverageScale(0xff) {
301 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); 282 const GrQuadEffect& ce = processor.cast<GrQuadEffect>();
302 fEdgeType = ce.getEdgeType(); 283 fEdgeType = ce.getEdgeType();
303 } 284 }
304 285
305 void GrGLQuadEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { 286 void GrGLQuadEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
306 GrGLGPBuilder* pb = args.fPB; 287 GrGLGPBuilder* pb = args.fPB;
307 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); 288 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
308 const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>(); 289 const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>();
309 const QuadBatchTracker& local = args.fBT.cast<QuadBatchTracker>();
310 290
311 // emit attributes 291 // emit attributes
312 vsBuilder->emitAttributes(gp); 292 vsBuilder->emitAttributes(gp);
313 293
314 GrGLVertToFrag v(kVec4f_GrSLType); 294 GrGLVertToFrag v(kVec4f_GrSLType);
315 args.fPB->addVarying("HairQuadEdge", &v); 295 args.fPB->addVarying("HairQuadEdge", &v);
316 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inHairQuadEdge()->fName); 296 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inHairQuadEdge()->fName);
317 297
318 // Setup pass through color 298 // Setup pass through color
319 this->setupColorPassThrough(args.fPB, local.fInputColorType, args.fOutputCol or, NULL, 299 if (!gp.colorIgnored()) {
320 &fColorUniform); 300 this->setupUniformColor(args.fPB, args.fOutputColor, &fColorUniform);
301 }
321 302
322 // Setup position 303 // Setup position
323 this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatrix()); 304 this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatrix());
324 305
325 // emit transforms with position 306 // emit transforms with position
326 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()->fName, gp.lo calMatrix(), 307 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()->fName, gp.lo calMatrix(),
327 args.fTransformsIn, args.fTransformsOut); 308 args.fTransformsIn, args.fTransformsOut);
328 309
329 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 310 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
330 fsBuilder->codeAppendf("float edgeAlpha;"); 311 fsBuilder->codeAppendf("float edgeAlpha;");
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 } 343 }
363 case kFillBW_GrProcessorEdgeType: { 344 case kFillBW_GrProcessorEdgeType: {
364 fsBuilder->codeAppendf("edgeAlpha = (%s.x * %s.x - %s.y);", v.fsIn() , v.fsIn(), v.fsIn()); 345 fsBuilder->codeAppendf("edgeAlpha = (%s.x * %s.x - %s.y);", v.fsIn() , v.fsIn(), v.fsIn());
365 fsBuilder->codeAppend("edgeAlpha = float(edgeAlpha < 0.0);"); 346 fsBuilder->codeAppend("edgeAlpha = float(edgeAlpha < 0.0);");
366 break; 347 break;
367 } 348 }
368 default: 349 default:
369 SkFAIL("Shouldn't get here"); 350 SkFAIL("Shouldn't get here");
370 } 351 }
371 352
372 if (0xff != local.fCoverageScale) { 353 if (0xff != gp.coverageScale()) {
373 const char* coverageScale; 354 const char* coverageScale;
374 fCoverageScaleUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Vis ibility, 355 fCoverageScaleUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Vis ibility,
375 kFloat_GrSLType, 356 kFloat_GrSLType,
376 kDefault_GrSLPrecision, 357 kDefault_GrSLPrecision,
377 "Coverage", 358 "Coverage",
378 &coverageScale); 359 &coverageScale);
379 fsBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverag e, coverageScale); 360 fsBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverag e, coverageScale);
380 } else { 361 } else {
381 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); 362 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
382 } 363 }
383 } 364 }
384 365
385 void GrGLQuadEffect::GenKey(const GrGeometryProcessor& gp, 366 void GrGLQuadEffect::GenKey(const GrGeometryProcessor& gp,
386 const GrBatchTracker& bt, 367 const GrBatchTracker& bt,
387 const GrGLSLCaps&, 368 const GrGLSLCaps&,
388 GrProcessorKeyBuilder* b) { 369 GrProcessorKeyBuilder* b) {
389 const GrQuadEffect& ce = gp.cast<GrQuadEffect>(); 370 const GrQuadEffect& ce = gp.cast<GrQuadEffect>();
390 const QuadBatchTracker& local = bt.cast<QuadBatchTracker>();
391 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; 371 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2;
392 key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x0; 372 key |= ce.color() != GrColor_ILLEGAL ? 0x4 : 0x0;
393 key |= 0xff != local.fCoverageScale ? 0x8 : 0x0; 373 key |= ce.coverageScale() != 0xff ? 0x8 : 0x0;
394 key |= local.fUsesLocalCoords && ce.localMatrix().hasPerspective() ? 0x10 : 0x0; 374 key |= ce.usesLocalCoords() && ce.localMatrix().hasPerspective() ? 0x10 : 0x 0;
395 key |= ComputePosKey(ce.viewMatrix()) << 5; 375 key |= ComputePosKey(ce.viewMatrix()) << 5;
396 b->add32(key); 376 b->add32(key);
397 } 377 }
398 378
399 ////////////////////////////////////////////////////////////////////////////// 379 //////////////////////////////////////////////////////////////////////////////
400 380
401 GrQuadEffect::~GrQuadEffect() {} 381 GrQuadEffect::~GrQuadEffect() {}
402 382
403 void GrQuadEffect::getGLProcessorKey(const GrBatchTracker& bt, 383 void GrQuadEffect::getGLProcessorKey(const GrBatchTracker& bt,
404 const GrGLSLCaps& caps, 384 const GrGLSLCaps& caps,
405 GrProcessorKeyBuilder* b) const { 385 GrProcessorKeyBuilder* b) const {
406 GrGLQuadEffect::GenKey(*this, bt, caps, b); 386 GrGLQuadEffect::GenKey(*this, bt, caps, b);
407 } 387 }
408 388
409 GrGLPrimitiveProcessor* GrQuadEffect::createGLInstance(const GrBatchTracker& bt, 389 GrGLPrimitiveProcessor* GrQuadEffect::createGLInstance(const GrBatchTracker& bt,
410 const GrGLSLCaps&) const { 390 const GrGLSLCaps&) const {
411 return SkNEW_ARGS(GrGLQuadEffect, (*this, bt)); 391 return SkNEW_ARGS(GrGLQuadEffect, (*this, bt));
412 } 392 }
413 393
414 GrQuadEffect::GrQuadEffect(GrColor color, const SkMatrix& viewMatrix, uint8_t co verage, 394 GrQuadEffect::GrQuadEffect(GrColor color, const SkMatrix& viewMatrix, uint8_t co verage,
415 GrPrimitiveEdgeType edgeType, const SkMatrix& localMa trix) 395 GrPrimitiveEdgeType edgeType, const SkMatrix& localMa trix,
396 bool usesLocalCoords)
416 : fColor(color) 397 : fColor(color)
417 , fViewMatrix(viewMatrix) 398 , fViewMatrix(viewMatrix)
418 , fLocalMatrix(localMatrix) 399 , fLocalMatrix(localMatrix)
400 , fUsesLocalCoords(usesLocalCoords)
419 , fCoverageScale(coverage) 401 , fCoverageScale(coverage)
420 , fEdgeType(edgeType) { 402 , fEdgeType(edgeType) {
421 this->initClassID<GrQuadEffect>(); 403 this->initClassID<GrQuadEffect>();
422 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); 404 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType));
423 fInHairQuadEdge = &this->addVertexAttrib(Attribute("inHairQuadEdge", 405 fInHairQuadEdge = &this->addVertexAttrib(Attribute("inHairQuadEdge",
424 kVec4f_GrVertexAttribTyp e)); 406 kVec4f_GrVertexAttribTyp e));
425 } 407 }
426 408
427 void GrQuadEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& in it) const {
428 QuadBatchTracker* local = bt->cast<QuadBatchTracker>();
429 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in it, false);
430 local->fCoverageScale = fCoverageScale;
431 local->fUsesLocalCoords = init.fUsesLocalCoords;
432 }
433
434 ////////////////////////////////////////////////////////////////////////////// 409 //////////////////////////////////////////////////////////////////////////////
435 410
436 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrQuadEffect); 411 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrQuadEffect);
437 412
438 GrGeometryProcessor* GrQuadEffect::TestCreate(SkRandom* random, 413 GrGeometryProcessor* GrQuadEffect::TestCreate(SkRandom* random,
439 GrContext*, 414 GrContext*,
440 const GrDrawTargetCaps& caps, 415 const GrDrawTargetCaps& caps,
441 GrTexture*[]) { 416 GrTexture*[]) {
442 GrGeometryProcessor* gp; 417 GrGeometryProcessor* gp;
443 do { 418 do {
444 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( 419 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(
445 random->nextULessThan(kGrProcessorEdgeTypeCnt)); 420 random->nextULessThan(kGrProcessorEdgeTypeCnt));
446 gp = GrQuadEffect::Create(GrRandomColor(random), 421 gp = GrQuadEffect::Create(GrRandomColor(random),
447 GrTest::TestMatrix(random), 422 GrTest::TestMatrix(random),
448 edgeType, caps, 423 edgeType, caps,
449 GrTest::TestMatrix(random)); 424 GrTest::TestMatrix(random),
425 random->nextBool());
450 } while (NULL == gp); 426 } while (NULL == gp);
451 return gp; 427 return gp;
452 } 428 }
453 429
454 ////////////////////////////////////////////////////////////////////////////// 430 //////////////////////////////////////////////////////////////////////////////
455 // Cubic 431 // Cubic
456 ////////////////////////////////////////////////////////////////////////////// 432 //////////////////////////////////////////////////////////////////////////////
457 433
458 struct CubicBatchTracker {
459 GrGPInput fInputColorType;
460 GrColor fColor;
461 bool fUsesLocalCoords;
462 };
463
464 class GrGLCubicEffect : public GrGLGeometryProcessor { 434 class GrGLCubicEffect : public GrGLGeometryProcessor {
465 public: 435 public:
466 GrGLCubicEffect(const GrGeometryProcessor&, 436 GrGLCubicEffect(const GrGeometryProcessor&,
467 const GrBatchTracker&); 437 const GrBatchTracker&);
468 438
469 void onEmitCode(EmitArgs&, GrGPArgs*) override; 439 void onEmitCode(EmitArgs&, GrGPArgs*) override;
470 440
471 static inline void GenKey(const GrGeometryProcessor&, 441 static inline void GenKey(const GrGeometryProcessor&,
472 const GrBatchTracker&, 442 const GrBatchTracker&,
473 const GrGLSLCaps&, 443 const GrGLSLCaps&,
474 GrProcessorKeyBuilder*); 444 GrProcessorKeyBuilder*);
475 445
476 virtual void setData(const GrGLProgramDataManager& pdman, 446 virtual void setData(const GrGLProgramDataManager& pdman,
477 const GrPrimitiveProcessor& primProc, 447 const GrPrimitiveProcessor& primProc,
478 const GrBatchTracker& bt) override { 448 const GrBatchTracker& bt) override {
479 const GrCubicEffect& ce = primProc.cast<GrCubicEffect>(); 449 const GrCubicEffect& ce = primProc.cast<GrCubicEffect>();
480 this->setUniformViewMatrix(pdman, ce.viewMatrix()); 450 this->setUniformViewMatrix(pdman, ce.viewMatrix());
481 451
482 const CubicBatchTracker& local = bt.cast<CubicBatchTracker>(); 452 if (ce.color() != fColor) {
483 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo r) {
484 GrGLfloat c[4]; 453 GrGLfloat c[4];
485 GrColorToRGBAFloat(local.fColor, c); 454 GrColorToRGBAFloat(ce.color(), c);
486 pdman.set4fv(fColorUniform, 1, c); 455 pdman.set4fv(fColorUniform, 1, c);
487 fColor = local.fColor; 456 fColor = ce.color();
488 } 457 }
489 } 458 }
490 459
491 private: 460 private:
492 GrColor fColor; 461 GrColor fColor;
493 GrPrimitiveEdgeType fEdgeType; 462 GrPrimitiveEdgeType fEdgeType;
494 UniformHandle fColorUniform; 463 UniformHandle fColorUniform;
495 464
496 typedef GrGLGeometryProcessor INHERITED; 465 typedef GrGLGeometryProcessor INHERITED;
497 }; 466 };
498 467
499 GrGLCubicEffect::GrGLCubicEffect(const GrGeometryProcessor& processor, 468 GrGLCubicEffect::GrGLCubicEffect(const GrGeometryProcessor& processor,
500 const GrBatchTracker&) 469 const GrBatchTracker&)
501 : fColor(GrColor_ILLEGAL) { 470 : fColor(GrColor_ILLEGAL) {
502 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); 471 const GrCubicEffect& ce = processor.cast<GrCubicEffect>();
503 fEdgeType = ce.getEdgeType(); 472 fEdgeType = ce.getEdgeType();
504 } 473 }
505 474
506 void GrGLCubicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { 475 void GrGLCubicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
507 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); 476 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
508 const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>(); 477 const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>();
509 const CubicBatchTracker& local = args.fBT.cast<CubicBatchTracker>();
510 478
511 // emit attributes 479 // emit attributes
512 vsBuilder->emitAttributes(gp); 480 vsBuilder->emitAttributes(gp);
513 481
514 GrGLVertToFrag v(kVec4f_GrSLType); 482 GrGLVertToFrag v(kVec4f_GrSLType);
515 args.fPB->addVarying("CubicCoeffs", &v, kHigh_GrSLPrecision); 483 args.fPB->addVarying("CubicCoeffs", &v, kHigh_GrSLPrecision);
516 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inCubicCoeffs()->fName); 484 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inCubicCoeffs()->fName);
517 485
518 // Setup pass through color 486 // Setup pass through color
519 this->setupColorPassThrough(args.fPB, local.fInputColorType, args.fOutputCol or, NULL, 487 if (!gp.colorIgnored()) {
520 &fColorUniform); 488 this->setupUniformColor(args.fPB, args.fOutputColor, &fColorUniform);
489 }
521 490
522 // Setup position 491 // Setup position
523 this->setupPosition(args.fPB, gpArgs, gp.inPosition()->fName, gp.viewMatrix( )); 492 this->setupPosition(args.fPB, gpArgs, gp.inPosition()->fName, gp.viewMatrix( ));
524 493
525 // emit transforms with position 494 // emit transforms with position
526 this->emitTransforms(args.fPB, gpArgs->fPositionVar, gp.inPosition()->fName, args.fTransformsIn, 495 this->emitTransforms(args.fPB, gpArgs->fPositionVar, gp.inPosition()->fName, args.fTransformsIn,
527 args.fTransformsOut); 496 args.fTransformsOut);
528 497
529 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 498 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
530 499
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 580
612 581
613 fsBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, edgeAlpha.c_s tr()); 582 fsBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, edgeAlpha.c_s tr());
614 } 583 }
615 584
616 void GrGLCubicEffect::GenKey(const GrGeometryProcessor& gp, 585 void GrGLCubicEffect::GenKey(const GrGeometryProcessor& gp,
617 const GrBatchTracker& bt, 586 const GrBatchTracker& bt,
618 const GrGLSLCaps&, 587 const GrGLSLCaps&,
619 GrProcessorKeyBuilder* b) { 588 GrProcessorKeyBuilder* b) {
620 const GrCubicEffect& ce = gp.cast<GrCubicEffect>(); 589 const GrCubicEffect& ce = gp.cast<GrCubicEffect>();
621 const CubicBatchTracker& local = bt.cast<CubicBatchTracker>();
622 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; 590 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2;
623 key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x8; 591 key |= ce.color() != GrColor_ILLEGAL ? 0x4 : 0x8;
624 key |= ComputePosKey(ce.viewMatrix()) << 5; 592 key |= ComputePosKey(ce.viewMatrix()) << 5;
625 b->add32(key); 593 b->add32(key);
626 } 594 }
627 595
628 ////////////////////////////////////////////////////////////////////////////// 596 //////////////////////////////////////////////////////////////////////////////
629 597
630 GrCubicEffect::~GrCubicEffect() {} 598 GrCubicEffect::~GrCubicEffect() {}
631 599
632 void GrCubicEffect::getGLProcessorKey(const GrBatchTracker& bt, 600 void GrCubicEffect::getGLProcessorKey(const GrBatchTracker& bt,
633 const GrGLSLCaps& caps, 601 const GrGLSLCaps& caps,
(...skipping 10 matching lines...) Expand all
644 GrPrimitiveEdgeType edgeType) 612 GrPrimitiveEdgeType edgeType)
645 : fColor(color) 613 : fColor(color)
646 , fViewMatrix(viewMatrix) 614 , fViewMatrix(viewMatrix)
647 , fEdgeType(edgeType) { 615 , fEdgeType(edgeType) {
648 this->initClassID<GrCubicEffect>(); 616 this->initClassID<GrCubicEffect>();
649 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); 617 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType));
650 fInCubicCoeffs = &this->addVertexAttrib(Attribute("inCubicCoeffs", 618 fInCubicCoeffs = &this->addVertexAttrib(Attribute("inCubicCoeffs",
651 kVec4f_GrVertexAttribTyp e)); 619 kVec4f_GrVertexAttribTyp e));
652 } 620 }
653 621
654 void GrCubicEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& i nit) const {
655 CubicBatchTracker* local = bt->cast<CubicBatchTracker>();
656 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in it, false);
657 local->fUsesLocalCoords = init.fUsesLocalCoords;
658 }
659
660 ////////////////////////////////////////////////////////////////////////////// 622 //////////////////////////////////////////////////////////////////////////////
661 623
662 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCubicEffect); 624 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCubicEffect);
663 625
664 GrGeometryProcessor* GrCubicEffect::TestCreate(SkRandom* random, 626 GrGeometryProcessor* GrCubicEffect::TestCreate(SkRandom* random,
665 GrContext*, 627 GrContext*,
666 const GrDrawTargetCaps& caps, 628 const GrDrawTargetCaps& caps,
667 GrTexture*[]) { 629 GrTexture*[]) {
668 GrGeometryProcessor* gp; 630 GrGeometryProcessor* gp;
669 do { 631 do {
670 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( 632 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(
671 random->nextULessThan(kGrPro cessorEdgeTypeCnt)); 633 random->nextULessThan(kGrPro cessorEdgeTypeCnt));
672 gp = GrCubicEffect::Create(GrRandomColor(random), 634 gp = GrCubicEffect::Create(GrRandomColor(random),
673 GrTest::TestMatrix(random), edgeType, caps); 635 GrTest::TestMatrix(random), edgeType, caps);
674 } while (NULL == gp); 636 } while (NULL == gp);
675 return gp; 637 return gp;
676 } 638 }
677 639
OLDNEW
« no previous file with comments | « src/gpu/effects/GrBezierEffect.h ('k') | src/gpu/effects/GrBitmapTextGeoProc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698