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

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

Issue 671023002: Added varying struct (Closed) Base URL: https://skia.googlesource.com/skia.git@gp_emit_struct
Patch Set: cleanup 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
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 "GrDashingEffect.h" 8 #include "GrDashingEffect.h"
9 9
10 #include "../GrAARectRenderer.h" 10 #include "../GrAARectRenderer.h"
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 void GLDashingCircleEffect::emitCode(const EmitArgs& args) { 507 void GLDashingCircleEffect::emitCode(const EmitArgs& args) {
508 const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>(); 508 const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>();
509 const char *paramName; 509 const char *paramName;
510 // The param uniforms, xyz, refer to circle radius - 0.5, cicles center x co ord, and 510 // The param uniforms, xyz, refer to circle radius - 0.5, cicles center x co ord, and
511 // the total interval length of the dash. 511 // the total interval length of the dash.
512 fParamUniform = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibilit y, 512 fParamUniform = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibilit y,
513 kVec3f_GrSLType, 513 kVec3f_GrSLType,
514 "params", 514 "params",
515 &paramName); 515 &paramName);
516 516
517 const char *vsCoordName, *fsCoordName; 517 GrGLVertToFrag v(kVec2f_GrSLType);
518 args.fPB->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName); 518 args.fPB->addVarying("Coord", &v);
519 519
520 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); 520 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
521 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, dce.inCoord().c_str()); 521 vsBuilder->codeAppendf("\t%s = %s;\n", v.vsOut(), dce.inCoord().c_str());
522 522
523 // transforms all points so that we can compare them to our test circle 523 // transforms all points so that we can compare them to our test circle
524 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 524 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
525 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s. z;\n", 525 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s. z;\n",
526 fsCoordName, fsCoordName, paramName, paramName); 526 v.fsIn(), v.fsIn(), paramName, paramName);
527 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n", fsCoordName); 527 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n", v.fsIn());
528 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName); 528 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName);
529 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n") ; 529 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n") ;
530 if (GrProcessorEdgeTypeIsAA(dce.getEdgeType())) { 530 if (GrProcessorEdgeTypeIsAA(dce.getEdgeType())) {
531 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName); 531 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName);
532 fsBuilder->codeAppend("\t\tdiff = 1.0 - diff;\n"); 532 fsBuilder->codeAppend("\t\tdiff = 1.0 - diff;\n");
533 fsBuilder->codeAppend("\t\tfloat alpha = clamp(diff, 0.0, 1.0);\n"); 533 fsBuilder->codeAppend("\t\tfloat alpha = clamp(diff, 0.0, 1.0);\n");
534 } else { 534 } else {
535 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); 535 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n");
536 fsBuilder->codeAppendf("\t\talpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;\n", paramName); 536 fsBuilder->codeAppendf("\t\talpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;\n", paramName);
537 } 537 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 kVec4f_GrSLType, 711 kVec4f_GrSLType,
712 "rect", 712 "rect",
713 &rectName); 713 &rectName);
714 const char *intervalName; 714 const char *intervalName;
715 // The interval uniform's refers to the total length of the interval (on + o ff) 715 // The interval uniform's refers to the total length of the interval (on + o ff)
716 fIntervalUniform = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibi lity, 716 fIntervalUniform = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibi lity,
717 kFloat_GrSLType, 717 kFloat_GrSLType,
718 "interval", 718 "interval",
719 &intervalName); 719 &intervalName);
720 720
721 const char *vsCoordName, *fsCoordName; 721 GrGLVertToFrag v(kVec2f_GrSLType);
722 args.fPB->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName); 722 args.fPB->addVarying("Coord", &v);
723 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); 723 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
724 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, de.inCoord().c_str()); 724 vsBuilder->codeAppendf("\t%s = %s;\n", v.vsOut(), de.inCoord().c_str());
725 725
726 // transforms all points so that we can compare them to our test rect 726 // transforms all points so that we can compare them to our test rect
727 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 727 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
728 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s) * %s;\n ", 728 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s) * %s;\n ",
729 fsCoordName, fsCoordName, intervalName, intervalName) ; 729 v.fsIn(), v.fsIn(), intervalName, intervalName);
730 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n", fsCoordName); 730 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n", v.fsIn());
731 if (GrProcessorEdgeTypeIsAA(de.getEdgeType())) { 731 if (GrProcessorEdgeTypeIsAA(de.getEdgeType())) {
732 // The amount of coverage removed in x and y by the edges is computed as a pair of negative 732 // The amount of coverage removed in x and y by the edges is computed as a pair of negative
733 // numbers, xSub and ySub. 733 // numbers, xSub and ySub.
734 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); 734 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n");
735 fsBuilder->codeAppendf("\t\txSub = min(fragPosShifted.x - %s.x, 0.0);\n" , rectName); 735 fsBuilder->codeAppendf("\t\txSub = min(fragPosShifted.x - %s.x, 0.0);\n" , rectName);
736 fsBuilder->codeAppendf("\t\txSub += min(%s.z - fragPosShifted.x, 0.0);\n ", rectName); 736 fsBuilder->codeAppendf("\t\txSub += min(%s.z - fragPosShifted.x, 0.0);\n ", rectName);
737 fsBuilder->codeAppendf("\t\tySub = min(fragPosShifted.y - %s.y, 0.0);\n" , rectName); 737 fsBuilder->codeAppendf("\t\tySub = min(fragPosShifted.y - %s.y, 0.0);\n" , rectName);
738 fsBuilder->codeAppendf("\t\tySub += min(%s.w - fragPosShifted.y, 0.0);\n ", rectName); 738 fsBuilder->codeAppendf("\t\tySub += min(%s.w - fragPosShifted.y, 0.0);\n ", rectName);
739 // Now compute coverage in x and y and multiply them to get the fraction of the pixel 739 // Now compute coverage in x and y and multiply them to get the fraction of the pixel
740 // covered. 740 // covered.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 switch (cap) { 841 switch (cap) {
842 case GrDashingEffect::kRound_DashCap: 842 case GrDashingEffect::kRound_DashCap:
843 return DashingCircleEffect::Create(edgeType, info, SkScalarHalf(stro keWidth)); 843 return DashingCircleEffect::Create(edgeType, info, SkScalarHalf(stro keWidth));
844 case GrDashingEffect::kNonRound_DashCap: 844 case GrDashingEffect::kNonRound_DashCap:
845 return DashingLineEffect::Create(edgeType, info, strokeWidth); 845 return DashingLineEffect::Create(edgeType, info, strokeWidth);
846 default: 846 default:
847 SkFAIL("Unexpected dashed cap."); 847 SkFAIL("Unexpected dashed cap.");
848 } 848 }
849 return NULL; 849 return NULL;
850 } 850 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrCustomCoordsTextureEffect.cpp ('k') | src/gpu/effects/GrDistanceFieldTextureEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698