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

Side by Side Diff: src/gpu/effects/GrDistanceFieldTextureEffect.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/effects/GrDashingEffect.cpp ('k') | src/gpu/gl/GrGLGeometryProcessor.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 "GrDistanceFieldTextureEffect.h" 8 #include "GrDistanceFieldTextureEffect.h"
9 #include "gl/builders/GrGLProgramBuilder.h" 9 #include "gl/builders/GrGLFullProgramBuilder.h"
10 #include "gl/GrGLProcessor.h" 10 #include "gl/GrGLProcessor.h"
11 #include "gl/GrGLSL.h" 11 #include "gl/GrGLSL.h"
12 #include "gl/GrGLTexture.h" 12 #include "gl/GrGLTexture.h"
13 #include "gl/GrGLGeometryProcessor.h" 13 #include "gl/GrGLGeometryProcessor.h"
14 #include "GrTBackendProcessorFactory.h" 14 #include "GrTBackendProcessorFactory.h"
15 #include "GrTexture.h" 15 #include "GrTexture.h"
16 16
17 #include "SkDistanceFieldGen.h" 17 #include "SkDistanceFieldGen.h"
18 18
19 // To get optical sizes people don't complain about when we blit correctly, 19 // To get optical sizes people don't complain about when we blit correctly,
(...skipping 13 matching lines...) Expand all
33 public: 33 public:
34 GrGLDistanceFieldTextureEffect(const GrBackendProcessorFactory& factory, 34 GrGLDistanceFieldTextureEffect(const GrBackendProcessorFactory& factory,
35 const GrProcessor&) 35 const GrProcessor&)
36 : INHERITED (factory) 36 : INHERITED (factory)
37 , fTextureSize(SkISize::Make(-1,-1)) 37 , fTextureSize(SkISize::Make(-1,-1))
38 #ifdef SK_GAMMA_APPLY_TO_A8 38 #ifdef SK_GAMMA_APPLY_TO_A8
39 , fLuminance(-1.0f) 39 , fLuminance(-1.0f)
40 #endif 40 #endif
41 {} 41 {}
42 42
43 virtual void emitCode(GrGLGPBuilder* builder, 43 virtual void emitCode(GrGLFullProgramBuilder* builder,
44 const GrGeometryProcessor& geometryProcessor, 44 const GrGeometryProcessor& geometryProcessor,
45 const GrProcessorKey& key, 45 const GrProcessorKey& key,
46 const char* outputColor, 46 const char* outputColor,
47 const char* inputColor, 47 const char* inputColor,
48 const TransformedCoordsArray&, 48 const TransformedCoordsArray&,
49 const TextureSamplerArray& samplers) SK_OVERRIDE { 49 const TextureSamplerArray& samplers) SK_OVERRIDE {
50 const GrDistanceFieldTextureEffect& dfTexEffect = 50 const GrDistanceFieldTextureEffect& dfTexEffect =
51 geometryProcessor.cast<GrDistanceFieldTextureEffect>(); 51 geometryProcessor.cast<GrDistanceFieldTextureEffect>();
52 SkASSERT(1 == dfTexEffect.getVertexAttribs().count()); 52 SkASSERT(1 == dfTexEffect.getVertexAttribs().count());
53 53
54 GrGLGPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 54 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragmentShad erBuilder();
55 SkAssertResult(fsBuilder->enableFeature( 55 SkAssertResult(fsBuilder->enableFeature(
56 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); 56 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
57 57
58 SkString fsCoordName; 58 SkString fsCoordName;
59 const char* vsCoordName; 59 const char* vsCoordName;
60 const char* fsCoordNamePtr; 60 const char* fsCoordNamePtr;
61 builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsCoordName, &fsC oordNamePtr); 61 builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsCoordName, &fsC oordNamePtr);
62 fsCoordName = fsCoordNamePtr; 62 fsCoordName = fsCoordNamePtr;
63 63
64 GrGLVertexBuilder* vsBuilder = builder->getVertexShaderBuilder(); 64 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder();
65 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, dfTexEffect.inTextur eCoords().c_str()); 65 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, dfTexEffect.inTextur eCoords().c_str());
66 66
67 const char* textureSizeUniName = NULL; 67 const char* textureSizeUniName = NULL;
68 fTextureSizeUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visi bility, 68 fTextureSizeUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visi bility,
69 kVec2f_GrSLType, "TextureSize", 69 kVec2f_GrSLType, "TextureSize",
70 &textureSizeUniName); 70 &textureSizeUniName);
71 71
72 fsBuilder->codeAppend("\tvec4 texColor = "); 72 fsBuilder->codeAppend("\tvec4 texColor = ");
73 fsBuilder->appendTextureLookup(samplers[0], 73 fsBuilder->appendTextureLookup(samplers[0],
74 fsCoordName.c_str(), 74 fsCoordName.c_str(),
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 260
261 /////////////////////////////////////////////////////////////////////////////// 261 ///////////////////////////////////////////////////////////////////////////////
262 262
263 class GrGLDistanceFieldNoGammaTextureEffect : public GrGLGeometryProcessor { 263 class GrGLDistanceFieldNoGammaTextureEffect : public GrGLGeometryProcessor {
264 public: 264 public:
265 GrGLDistanceFieldNoGammaTextureEffect(const GrBackendProcessorFactory& facto ry, 265 GrGLDistanceFieldNoGammaTextureEffect(const GrBackendProcessorFactory& facto ry,
266 const GrProcessor& effect) 266 const GrProcessor& effect)
267 : INHERITED(factory) 267 : INHERITED(factory)
268 , fTextureSize(SkISize::Make(-1, -1)) {} 268 , fTextureSize(SkISize::Make(-1, -1)) {}
269 269
270 virtual void emitCode(GrGLGPBuilder* builder, 270 virtual void emitCode(GrGLFullProgramBuilder* builder,
271 const GrGeometryProcessor& effect, 271 const GrGeometryProcessor& effect,
272 const GrProcessorKey& key, 272 const GrProcessorKey& key,
273 const char* outputColor, 273 const char* outputColor,
274 const char* inputColor, 274 const char* inputColor,
275 const TransformedCoordsArray&, 275 const TransformedCoordsArray&,
276 const TextureSamplerArray& samplers) SK_OVERRIDE { 276 const TextureSamplerArray& samplers) SK_OVERRIDE {
277 const GrDistanceFieldNoGammaTextureEffect& dfTexEffect = 277 const GrDistanceFieldNoGammaTextureEffect& dfTexEffect =
278 effect.cast<GrDistanceFieldNoGam maTextureEffect>(); 278 effect.cast<GrDistanceFieldNoGam maTextureEffect>();
279 SkASSERT(1 == dfTexEffect.getVertexAttribs().count()); 279 SkASSERT(1 == dfTexEffect.getVertexAttribs().count());
280 280
281 GrGLGPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 281 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragmentShad erBuilder();
282 SkAssertResult(fsBuilder->enableFeature( 282 SkAssertResult(fsBuilder->enableFeature(
283 GrGLFragmentShaderBuilder::kStandardDerivat ives_GLSLFeature)); 283 GrGLFragmentShaderBuilder::kStandardDerivat ives_GLSLFeature));
284 284
285 SkString fsCoordName; 285 SkString fsCoordName;
286 const char* vsCoordName; 286 const char* vsCoordName;
287 const char* fsCoordNamePtr; 287 const char* fsCoordNamePtr;
288 builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsCoordName, &fsC oordNamePtr); 288 builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsCoordName, &fsC oordNamePtr);
289 fsCoordName = fsCoordNamePtr; 289 fsCoordName = fsCoordNamePtr;
290 290
291 GrGLVertexBuilder* vsBuilder = builder->getVertexShaderBuilder(); 291 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder();
292 vsBuilder->codeAppendf("%s = %s;", vsCoordName, dfTexEffect.inTextureCoo rds().c_str()); 292 vsBuilder->codeAppendf("%s = %s;", vsCoordName, dfTexEffect.inTextureCoo rds().c_str());
293 293
294 const char* textureSizeUniName = NULL; 294 const char* textureSizeUniName = NULL;
295 fTextureSizeUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visi bility, 295 fTextureSizeUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visi bility,
296 kVec2f_GrSLType, "TextureSize", 296 kVec2f_GrSLType, "TextureSize",
297 &textureSizeUniName); 297 &textureSizeUniName);
298 298
299 fsBuilder->codeAppend("vec4 texColor = "); 299 fsBuilder->codeAppend("vec4 texColor = ");
300 fsBuilder->appendTextureLookup(samplers[0], 300 fsBuilder->appendTextureLookup(samplers[0],
301 fsCoordName.c_str(), 301 fsCoordName.c_str(),
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 /////////////////////////////////////////////////////////////////////////////// 432 ///////////////////////////////////////////////////////////////////////////////
433 433
434 class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor { 434 class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor {
435 public: 435 public:
436 GrGLDistanceFieldLCDTextureEffect(const GrBackendProcessorFactory& factory, 436 GrGLDistanceFieldLCDTextureEffect(const GrBackendProcessorFactory& factory,
437 const GrProcessor&) 437 const GrProcessor&)
438 : INHERITED (factory) 438 : INHERITED (factory)
439 , fTextureSize(SkISize::Make(-1,-1)) 439 , fTextureSize(SkISize::Make(-1,-1))
440 , fTextColor(GrColor_ILLEGAL) {} 440 , fTextColor(GrColor_ILLEGAL) {}
441 441
442 virtual void emitCode(GrGLGPBuilder* builder, 442 virtual void emitCode(GrGLFullProgramBuilder* builder,
443 const GrGeometryProcessor& geometryProcessor, 443 const GrGeometryProcessor& geometryProcessor,
444 const GrProcessorKey& key, 444 const GrProcessorKey& key,
445 const char* outputColor, 445 const char* outputColor,
446 const char* inputColor, 446 const char* inputColor,
447 const TransformedCoordsArray&, 447 const TransformedCoordsArray&,
448 const TextureSamplerArray& samplers) SK_OVERRIDE { 448 const TextureSamplerArray& samplers) SK_OVERRIDE {
449 const GrDistanceFieldLCDTextureEffect& dfTexEffect = 449 const GrDistanceFieldLCDTextureEffect& dfTexEffect =
450 geometryProcessor.cast<GrDistanceFieldLCDTextureEffect>(); 450 geometryProcessor.cast<GrDistanceFieldLCDTextureEffect>();
451 SkASSERT(1 == dfTexEffect.getVertexAttribs().count()); 451 SkASSERT(1 == dfTexEffect.getVertexAttribs().count());
452 452
453 SkString fsCoordName; 453 SkString fsCoordName;
454 const char* vsCoordName; 454 const char* vsCoordName;
455 const char* fsCoordNamePtr; 455 const char* fsCoordNamePtr;
456 builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsCoordName, &fsC oordNamePtr); 456 builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsCoordName, &fsC oordNamePtr);
457 fsCoordName = fsCoordNamePtr; 457 fsCoordName = fsCoordNamePtr;
458 458
459 GrGLVertexBuilder* vsBuilder = builder->getVertexShaderBuilder(); 459 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder();
460 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, dfTexEffect.inTextur eCoords().c_str()); 460 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, dfTexEffect.inTextur eCoords().c_str());
461 461
462 const char* textureSizeUniName = NULL; 462 const char* textureSizeUniName = NULL;
463 // width, height, 1/(3*width) 463 // width, height, 1/(3*width)
464 fTextureSizeUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visi bility, 464 fTextureSizeUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visi bility,
465 kVec3f_GrSLType, "TextureSize", 465 kVec3f_GrSLType, "TextureSize",
466 &textureSizeUniName); 466 &textureSizeUniName);
467 467
468 GrGLGPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 468 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragmentShad erBuilder();
469 469
470 SkAssertResult(fsBuilder->enableFeature( 470 SkAssertResult(fsBuilder->enableFeature(
471 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); 471 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
472 472
473 // create LCD offset adjusted by inverse of transform 473 // create LCD offset adjusted by inverse of transform
474 fsBuilder->codeAppendf("\tvec2 uv = %s;\n", fsCoordName.c_str()); 474 fsBuilder->codeAppendf("\tvec2 uv = %s;\n", fsCoordName.c_str());
475 fsBuilder->codeAppendf("\tvec2 st = uv*%s.xy;\n", textureSizeUniName); 475 fsBuilder->codeAppendf("\tvec2 st = uv*%s.xy;\n", textureSizeUniName);
476 bool isUniformScale = !!(dfTexEffect.getFlags() & kUniformScale_Distance FieldEffectMask); 476 bool isUniformScale = !!(dfTexEffect.getFlags() & kUniformScale_Distance FieldEffectMask);
477 if (isUniformScale) { 477 if (isUniformScale) {
478 fsBuilder->codeAppend("\tfloat dx = dFdx(st.x);\n"); 478 fsBuilder->codeAppend("\tfloat dx = dFdx(st.x);\n");
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 random->nextULessThan(256), 689 random->nextULessThan(256),
690 random->nextULessThan(256)); 690 random->nextULessThan(256));
691 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; 691 uint32_t flags = kUseLCD_DistanceFieldEffectFlag;
692 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; 692 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0;
693 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; 693 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0;
694 return GrDistanceFieldLCDTextureEffect::Create(textures[texIdx], params, 694 return GrDistanceFieldLCDTextureEffect::Create(textures[texIdx], params,
695 textures[texIdx2], params2, 695 textures[texIdx2], params2,
696 textColor, 696 textColor,
697 flags); 697 flags);
698 } 698 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrDashingEffect.cpp ('k') | src/gpu/gl/GrGLGeometryProcessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698