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

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

Issue 635533005: Revert of Cleanup of shader building system (Closed) Base URL: https://skia.googlesource.com/skia.git@solo_gp
Patch Set: Created 6 years, 2 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/GrOvalRenderer.cpp ('k') | src/gpu/effects/GrCustomCoordsTextureEffect.cpp » ('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/builders/GrGLProgramBuilder.h" 10 #include "gl/builders/GrGLFullProgramBuilder.h"
11 #include "gl/GrGLProcessor.h" 11 #include "gl/GrGLProcessor.h"
12 #include "gl/GrGLSL.h" 12 #include "gl/GrGLSL.h"
13 #include "gl/GrGLGeometryProcessor.h" 13 #include "gl/GrGLGeometryProcessor.h"
14 #include "GrTBackendProcessorFactory.h" 14 #include "GrTBackendProcessorFactory.h"
15 15
16 class GrGLConicEffect : public GrGLGeometryProcessor { 16 class GrGLConicEffect : public GrGLGeometryProcessor {
17 public: 17 public:
18 GrGLConicEffect(const GrBackendProcessorFactory&, const GrProcessor&); 18 GrGLConicEffect(const GrBackendProcessorFactory&, const GrProcessor&);
19 19
20 virtual void emitCode(GrGLGPBuilder* builder, 20 virtual void emitCode(GrGLFullProgramBuilder* builder,
21 const GrGeometryProcessor& geometryProcessor, 21 const GrGeometryProcessor& geometryProcessor,
22 const GrProcessorKey& key, 22 const GrProcessorKey& key,
23 const char* outputColor, 23 const char* outputColor,
24 const char* inputColor, 24 const char* inputColor,
25 const TransformedCoordsArray&, 25 const TransformedCoordsArray&,
26 const TextureSamplerArray&) SK_OVERRIDE; 26 const TextureSamplerArray&) SK_OVERRIDE;
27 27
28 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder*); 28 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder*);
29 29
30 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE {} 30 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE {}
31 31
32 private: 32 private:
33 GrPrimitiveEdgeType fEdgeType; 33 GrPrimitiveEdgeType fEdgeType;
34 34
35 typedef GrGLGeometryProcessor INHERITED; 35 typedef GrGLGeometryProcessor INHERITED;
36 }; 36 };
37 37
38 GrGLConicEffect::GrGLConicEffect(const GrBackendProcessorFactory& factory, 38 GrGLConicEffect::GrGLConicEffect(const GrBackendProcessorFactory& factory,
39 const GrProcessor& effect) 39 const GrProcessor& effect)
40 : INHERITED (factory) { 40 : INHERITED (factory) {
41 const GrConicEffect& ce = effect.cast<GrConicEffect>(); 41 const GrConicEffect& ce = effect.cast<GrConicEffect>();
42 fEdgeType = ce.getEdgeType(); 42 fEdgeType = ce.getEdgeType();
43 } 43 }
44 44
45 void GrGLConicEffect::emitCode(GrGLGPBuilder* builder, 45 void GrGLConicEffect::emitCode(GrGLFullProgramBuilder* builder,
46 const GrGeometryProcessor& geometryProcessor, 46 const GrGeometryProcessor& geometryProcessor,
47 const GrProcessorKey& key, 47 const GrProcessorKey& key,
48 const char* outputColor, 48 const char* outputColor,
49 const char* inputColor, 49 const char* inputColor,
50 const TransformedCoordsArray&, 50 const TransformedCoordsArray&,
51 const TextureSamplerArray& samplers) { 51 const TextureSamplerArray& samplers) {
52 const char *vsName, *fsName; 52 const char *vsName, *fsName;
53 53
54 builder->addVarying(kVec4f_GrSLType, "ConicCoeffs", 54 builder->addVarying(kVec4f_GrSLType, "ConicCoeffs",
55 &vsName, &fsName); 55 &vsName, &fsName);
56 56
57 const GrShaderVar& inConicCoeffs = geometryProcessor.cast<GrConicEffect>().i nConicCoeffs(); 57 const GrShaderVar& inConicCoeffs = geometryProcessor.cast<GrConicEffect>().i nConicCoeffs();
58 GrGLVertexBuilder* vsBuilder = builder->getVertexShaderBuilder(); 58 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder();
59 vsBuilder->codeAppendf("%s = %s;", vsName, inConicCoeffs.c_str()); 59 vsBuilder->codeAppendf("%s = %s;", vsName, inConicCoeffs.c_str());
60 60
61 GrGLGPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 61 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBu ilder();
62 fsBuilder->codeAppend("float edgeAlpha;"); 62 fsBuilder->codeAppend("float edgeAlpha;");
63 63
64 switch (fEdgeType) { 64 switch (fEdgeType) {
65 case kHairlineAA_GrProcessorEdgeType: { 65 case kHairlineAA_GrProcessorEdgeType: {
66 SkAssertResult(fsBuilder->enableFeature( 66 SkAssertResult(fsBuilder->enableFeature(
67 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature) ); 67 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature) );
68 fsBuilder->codeAppendf("vec3 dklmdx = dFdx(%s.xyz);", fsName); 68 fsBuilder->codeAppendf("vec3 dklmdx = dFdx(%s.xyz);", fsName);
69 fsBuilder->codeAppendf("vec3 dklmdy = dFdy(%s.xyz);", fsName); 69 fsBuilder->codeAppendf("vec3 dklmdy = dFdy(%s.xyz);", fsName);
70 fsBuilder->codeAppendf("float dfdx =" 70 fsBuilder->codeAppendf("float dfdx ="
71 "2.0 * %s.x * dklmdx.x - %s.y * dklmdx.z - %s .z * dklmdx.y;", 71 "2.0 * %s.x * dklmdx.x - %s.y * dklmdx.z - %s .z * dklmdx.y;",
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 164 }
165 165
166 ////////////////////////////////////////////////////////////////////////////// 166 //////////////////////////////////////////////////////////////////////////////
167 // Quad 167 // Quad
168 ////////////////////////////////////////////////////////////////////////////// 168 //////////////////////////////////////////////////////////////////////////////
169 169
170 class GrGLQuadEffect : public GrGLGeometryProcessor { 170 class GrGLQuadEffect : public GrGLGeometryProcessor {
171 public: 171 public:
172 GrGLQuadEffect(const GrBackendProcessorFactory&, const GrProcessor&); 172 GrGLQuadEffect(const GrBackendProcessorFactory&, const GrProcessor&);
173 173
174 virtual void emitCode(GrGLGPBuilder* builder, 174 virtual void emitCode(GrGLFullProgramBuilder* builder,
175 const GrGeometryProcessor& geometryProcessor, 175 const GrGeometryProcessor& geometryProcessor,
176 const GrProcessorKey& key, 176 const GrProcessorKey& key,
177 const char* outputColor, 177 const char* outputColor,
178 const char* inputColor, 178 const char* inputColor,
179 const TransformedCoordsArray&, 179 const TransformedCoordsArray&,
180 const TextureSamplerArray&) SK_OVERRIDE; 180 const TextureSamplerArray&) SK_OVERRIDE;
181 181
182 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder*); 182 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder*);
183 183
184 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE {} 184 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE {}
185 185
186 private: 186 private:
187 GrPrimitiveEdgeType fEdgeType; 187 GrPrimitiveEdgeType fEdgeType;
188 188
189 typedef GrGLGeometryProcessor INHERITED; 189 typedef GrGLGeometryProcessor INHERITED;
190 }; 190 };
191 191
192 GrGLQuadEffect::GrGLQuadEffect(const GrBackendProcessorFactory& factory, 192 GrGLQuadEffect::GrGLQuadEffect(const GrBackendProcessorFactory& factory,
193 const GrProcessor& effect) 193 const GrProcessor& effect)
194 : INHERITED (factory) { 194 : INHERITED (factory) {
195 const GrQuadEffect& ce = effect.cast<GrQuadEffect>(); 195 const GrQuadEffect& ce = effect.cast<GrQuadEffect>();
196 fEdgeType = ce.getEdgeType(); 196 fEdgeType = ce.getEdgeType();
197 } 197 }
198 198
199 void GrGLQuadEffect::emitCode(GrGLGPBuilder* builder, 199 void GrGLQuadEffect::emitCode(GrGLFullProgramBuilder* builder,
200 const GrGeometryProcessor& geometryProcessor, 200 const GrGeometryProcessor& geometryProcessor,
201 const GrProcessorKey& key, 201 const GrProcessorKey& key,
202 const char* outputColor, 202 const char* outputColor,
203 const char* inputColor, 203 const char* inputColor,
204 const TransformedCoordsArray&, 204 const TransformedCoordsArray&,
205 const TextureSamplerArray& samplers) { 205 const TextureSamplerArray& samplers) {
206 const char *vsName, *fsName; 206 const char *vsName, *fsName;
207 builder->addVarying(kVec4f_GrSLType, "HairQuadEdge", &vsName, &fsName); 207 builder->addVarying(kVec4f_GrSLType, "HairQuadEdge", &vsName, &fsName);
208 208
209 GrGLVertexBuilder* vsBuilder = builder->getVertexShaderBuilder(); 209 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder();
210 const GrShaderVar& inHairQuadEdge = geometryProcessor.cast<GrQuadEffect>().i nHairQuadEdge(); 210 const GrShaderVar& inHairQuadEdge = geometryProcessor.cast<GrQuadEffect>().i nHairQuadEdge();
211 vsBuilder->codeAppendf("%s = %s;", vsName, inHairQuadEdge.c_str()); 211 vsBuilder->codeAppendf("%s = %s;", vsName, inHairQuadEdge.c_str());
212 212
213 GrGLGPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 213 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBu ilder();
214 fsBuilder->codeAppendf("float edgeAlpha;"); 214 fsBuilder->codeAppendf("float edgeAlpha;");
215 215
216 switch (fEdgeType) { 216 switch (fEdgeType) {
217 case kHairlineAA_GrProcessorEdgeType: { 217 case kHairlineAA_GrProcessorEdgeType: {
218 SkAssertResult(fsBuilder->enableFeature( 218 SkAssertResult(fsBuilder->enableFeature(
219 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature) ); 219 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature) );
220 fsBuilder->codeAppendf("vec2 duvdx = dFdx(%s.xy);", fsName); 220 fsBuilder->codeAppendf("vec2 duvdx = dFdx(%s.xy);", fsName);
221 fsBuilder->codeAppendf("vec2 duvdy = dFdy(%s.xy);", fsName); 221 fsBuilder->codeAppendf("vec2 duvdy = dFdy(%s.xy);", fsName);
222 fsBuilder->codeAppendf("vec2 gF = vec2(2.0 * %s.x * duvdx.x - duvdx. y," 222 fsBuilder->codeAppendf("vec2 gF = vec2(2.0 * %s.x * duvdx.x - duvdx. y,"
223 " 2.0 * %s.x * duvdy.x - duvdy. y);", 223 " 2.0 * %s.x * duvdy.x - duvdy. y);",
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 } 302 }
303 303
304 ////////////////////////////////////////////////////////////////////////////// 304 //////////////////////////////////////////////////////////////////////////////
305 // Cubic 305 // Cubic
306 ////////////////////////////////////////////////////////////////////////////// 306 //////////////////////////////////////////////////////////////////////////////
307 307
308 class GrGLCubicEffect : public GrGLGeometryProcessor { 308 class GrGLCubicEffect : public GrGLGeometryProcessor {
309 public: 309 public:
310 GrGLCubicEffect(const GrBackendProcessorFactory&, const GrProcessor&); 310 GrGLCubicEffect(const GrBackendProcessorFactory&, const GrProcessor&);
311 311
312 virtual void emitCode(GrGLGPBuilder* builder, 312 virtual void emitCode(GrGLFullProgramBuilder* builder,
313 const GrGeometryProcessor& geometryProcessor, 313 const GrGeometryProcessor& geometryProcessor,
314 const GrProcessorKey& key, 314 const GrProcessorKey& key,
315 const char* outputColor, 315 const char* outputColor,
316 const char* inputColor, 316 const char* inputColor,
317 const TransformedCoordsArray&, 317 const TransformedCoordsArray&,
318 const TextureSamplerArray&) SK_OVERRIDE; 318 const TextureSamplerArray&) SK_OVERRIDE;
319 319
320 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder*); 320 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder*);
321 321
322 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE {} 322 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE {}
323 323
324 private: 324 private:
325 GrPrimitiveEdgeType fEdgeType; 325 GrPrimitiveEdgeType fEdgeType;
326 326
327 typedef GrGLGeometryProcessor INHERITED; 327 typedef GrGLGeometryProcessor INHERITED;
328 }; 328 };
329 329
330 GrGLCubicEffect::GrGLCubicEffect(const GrBackendProcessorFactory& factory, 330 GrGLCubicEffect::GrGLCubicEffect(const GrBackendProcessorFactory& factory,
331 const GrProcessor& processor) 331 const GrProcessor& processor)
332 : INHERITED (factory) { 332 : INHERITED (factory) {
333 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); 333 const GrCubicEffect& ce = processor.cast<GrCubicEffect>();
334 fEdgeType = ce.getEdgeType(); 334 fEdgeType = ce.getEdgeType();
335 } 335 }
336 336
337 void GrGLCubicEffect::emitCode(GrGLGPBuilder* builder, 337 void GrGLCubicEffect::emitCode(GrGLFullProgramBuilder* builder,
338 const GrGeometryProcessor& geometryProcessor, 338 const GrGeometryProcessor& geometryProcessor,
339 const GrProcessorKey& key, 339 const GrProcessorKey& key,
340 const char* outputColor, 340 const char* outputColor,
341 const char* inputColor, 341 const char* inputColor,
342 const TransformedCoordsArray&, 342 const TransformedCoordsArray&,
343 const TextureSamplerArray& samplers) { 343 const TextureSamplerArray& samplers) {
344 const char *vsName, *fsName; 344 const char *vsName, *fsName;
345 345
346 builder->addVarying(kVec4f_GrSLType, "CubicCoeffs", 346 builder->addVarying(kVec4f_GrSLType, "CubicCoeffs",
347 &vsName, &fsName, GrGLShaderVar::kHigh_Precision); 347 &vsName, &fsName, GrGLShaderVar::kHigh_Precision);
348 348
349 GrGLVertexBuilder* vsBuilder = builder->getVertexShaderBuilder(); 349 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder();
350 const GrShaderVar& inCubicCoeffs = geometryProcessor.cast<GrCubicEffect>().i nCubicCoeffs(); 350 const GrShaderVar& inCubicCoeffs = geometryProcessor.cast<GrCubicEffect>().i nCubicCoeffs();
351 vsBuilder->codeAppendf("%s = %s;", vsName, inCubicCoeffs.c_str()); 351 vsBuilder->codeAppendf("%s = %s;", vsName, inCubicCoeffs.c_str());
352 352
353 GrGLGPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 353 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBu ilder();
354 354
355 GrGLShaderVar edgeAlpha("edgeAlpha", kFloat_GrSLType, 0, GrGLShaderVar::kHig h_Precision); 355 GrGLShaderVar edgeAlpha("edgeAlpha", kFloat_GrSLType, 0, GrGLShaderVar::kHig h_Precision);
356 GrGLShaderVar dklmdx("dklmdx", kVec3f_GrSLType, 0, GrGLShaderVar::kHigh_Prec ision); 356 GrGLShaderVar dklmdx("dklmdx", kVec3f_GrSLType, 0, GrGLShaderVar::kHigh_Prec ision);
357 GrGLShaderVar dklmdy("dklmdy", kVec3f_GrSLType, 0, GrGLShaderVar::kHigh_Prec ision); 357 GrGLShaderVar dklmdy("dklmdy", kVec3f_GrSLType, 0, GrGLShaderVar::kHigh_Prec ision);
358 GrGLShaderVar dfdx("dfdx", kFloat_GrSLType, 0, GrGLShaderVar::kHigh_Precisio n); 358 GrGLShaderVar dfdx("dfdx", kFloat_GrSLType, 0, GrGLShaderVar::kHigh_Precisio n);
359 GrGLShaderVar dfdy("dfdy", kFloat_GrSLType, 0, GrGLShaderVar::kHigh_Precisio n); 359 GrGLShaderVar dfdy("dfdy", kFloat_GrSLType, 0, GrGLShaderVar::kHigh_Precisio n);
360 GrGLShaderVar gF("gF", kVec2f_GrSLType, 0, GrGLShaderVar::kHigh_Precision); 360 GrGLShaderVar gF("gF", kVec2f_GrSLType, 0, GrGLShaderVar::kHigh_Precision);
361 GrGLShaderVar gFM("gFM", kFloat_GrSLType, 0, GrGLShaderVar::kHigh_Precision) ; 361 GrGLShaderVar gFM("gFM", kFloat_GrSLType, 0, GrGLShaderVar::kHigh_Precision) ;
362 GrGLShaderVar func("func", kFloat_GrSLType, 0, GrGLShaderVar::kHigh_Precisio n); 362 GrGLShaderVar func("func", kFloat_GrSLType, 0, GrGLShaderVar::kHigh_Precisio n);
363 363
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 GrTexture*[]) { 474 GrTexture*[]) {
475 GrGeometryProcessor* gp; 475 GrGeometryProcessor* gp;
476 do { 476 do {
477 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( 477 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(
478 random->nextULessThan(kGrPro cessorEdgeTypeCnt)); 478 random->nextULessThan(kGrPro cessorEdgeTypeCnt));
479 gp = GrCubicEffect::Create(edgeType, caps); 479 gp = GrCubicEffect::Create(edgeType, caps);
480 } while (NULL == gp); 480 } while (NULL == gp);
481 return gp; 481 return gp;
482 } 482 }
483 483
OLDNEW
« no previous file with comments | « src/gpu/GrOvalRenderer.cpp ('k') | src/gpu/effects/GrCustomCoordsTextureEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698