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

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

Issue 827973002: ViewMatrix uniform upload moved to GeometryProcessor (Closed) Base URL: https://skia.googlesource.com/skia.git@vm-on-gp
Patch Set: more cleanup Created 5 years, 11 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 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 args.fPB->addVarying("Coord", &v); 578 args.fPB->addVarying("Coord", &v);
579 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dce.inCoord()->fName); 579 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dce.inCoord()->fName);
580 580
581 // Setup pass through color 581 // Setup pass through color
582 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NU LL, &fColorUniform); 582 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NU LL, &fColorUniform);
583 583
584 // setup coord outputs 584 // setup coord outputs
585 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), dce.inPositi on()->fName); 585 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), dce.inPositi on()->fName);
586 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), dce.inPosition( )->fName); 586 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), dce.inPosition( )->fName);
587 587
588 // setup uniform viewMatrix
589 this->setupUniformViewMatrix(pb);
590
588 // setup position varying 591 // setup position varying
589 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs Builder->uViewM(), 592 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), th is->uViewM(),
590 dce.inPosition()->fName); 593 dce.inPosition()->fName);
591 594
592 // transforms all points so that we can compare them to our test circle 595 // transforms all points so that we can compare them to our test circle
593 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 596 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
594 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s. z;\n", 597 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s. z;\n",
595 v.fsIn(), v.fsIn(), paramName, paramName); 598 v.fsIn(), v.fsIn(), paramName, paramName);
596 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n", v.fsIn()); 599 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n", v.fsIn());
597 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName); 600 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName);
598 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n") ; 601 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n") ;
599 if (GrProcessorEdgeTypeIsAA(dce.getEdgeType())) { 602 if (GrProcessorEdgeTypeIsAA(dce.getEdgeType())) {
600 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName); 603 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName);
601 fsBuilder->codeAppend("\t\tdiff = 1.0 - diff;\n"); 604 fsBuilder->codeAppend("\t\tdiff = 1.0 - diff;\n");
602 fsBuilder->codeAppend("\t\tfloat alpha = clamp(diff, 0.0, 1.0);\n"); 605 fsBuilder->codeAppend("\t\tfloat alpha = clamp(diff, 0.0, 1.0);\n");
603 } else { 606 } else {
604 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); 607 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n");
605 fsBuilder->codeAppendf("\t\talpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;\n", paramName); 608 fsBuilder->codeAppendf("\t\talpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;\n", paramName);
606 } 609 }
607 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); 610 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage);
608 } 611 }
609 612
610 void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman, 613 void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman,
611 const GrPrimitiveProcessor& processor, 614 const GrPrimitiveProcessor& processor,
612 const GrBatchTracker& bt) { 615 const GrBatchTracker& bt) {
616 this->setUniformViewMatrix(pdman, processor.viewMatrix());
617
613 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); 618 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>();
614 SkScalar radius = dce.getRadius(); 619 SkScalar radius = dce.getRadius();
615 SkScalar centerX = dce.getCenterX(); 620 SkScalar centerX = dce.getCenterX();
616 SkScalar intervalLength = dce.getIntervalLength(); 621 SkScalar intervalLength = dce.getIntervalLength();
617 if (radius != fPrevRadius || centerX != fPrevCenterX || intervalLength != fP revIntervalLength) { 622 if (radius != fPrevRadius || centerX != fPrevCenterX || intervalLength != fP revIntervalLength) {
618 pdman.set3f(fParamUniform, radius - 0.5f, centerX, intervalLength); 623 pdman.set3f(fParamUniform, radius - 0.5f, centerX, intervalLength);
619 fPrevRadius = radius; 624 fPrevRadius = radius;
620 fPrevCenterX = centerX; 625 fPrevCenterX = centerX;
621 fPrevIntervalLength = intervalLength; 626 fPrevIntervalLength = intervalLength;
622 } 627 }
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 args.fPB->addVarying("Coord", &v); 876 args.fPB->addVarying("Coord", &v);
872 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), de.inCoord()->fName); 877 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), de.inCoord()->fName);
873 878
874 // Setup pass through color 879 // Setup pass through color
875 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NU LL, &fColorUniform); 880 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NU LL, &fColorUniform);
876 881
877 // setup coord outputs 882 // setup coord outputs
878 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), de.inPositio n()->fName); 883 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), de.inPositio n()->fName);
879 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), de.inPosition() ->fName); 884 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), de.inPosition() ->fName);
880 885
886 // setup uniform viewMatrix
887 this->setupUniformViewMatrix(pb);
888
881 // setup position varying 889 // setup position varying
882 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs Builder->uViewM(), 890 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), th is->uViewM(),
883 de.inPosition()->fName); 891 de.inPosition()->fName);
884 892
885 // transforms all points so that we can compare them to our test rect 893 // transforms all points so that we can compare them to our test rect
886 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 894 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
887 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s) * %s;\n ", 895 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s) * %s;\n ",
888 v.fsIn(), v.fsIn(), intervalName, intervalName); 896 v.fsIn(), v.fsIn(), intervalName, intervalName);
889 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n", v.fsIn()); 897 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n", v.fsIn());
890 if (GrProcessorEdgeTypeIsAA(de.getEdgeType())) { 898 if (GrProcessorEdgeTypeIsAA(de.getEdgeType())) {
891 // The amount of coverage removed in x and y by the edges is computed as a pair of negative 899 // The amount of coverage removed in x and y by the edges is computed as a pair of negative
892 // numbers, xSub and ySub. 900 // numbers, xSub and ySub.
(...skipping 10 matching lines...) Expand all
903 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); 911 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n");
904 fsBuilder->codeAppendf("\t\talpha *= (fragPosShifted.x - %s.x) > -0.5 ? 1.0 : 0.0;\n", rectName); 912 fsBuilder->codeAppendf("\t\talpha *= (fragPosShifted.x - %s.x) > -0.5 ? 1.0 : 0.0;\n", rectName);
905 fsBuilder->codeAppendf("\t\talpha *= (%s.z - fragPosShifted.x) >= -0.5 ? 1.0 : 0.0;\n", rectName); 913 fsBuilder->codeAppendf("\t\talpha *= (%s.z - fragPosShifted.x) >= -0.5 ? 1.0 : 0.0;\n", rectName);
906 } 914 }
907 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); 915 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage);
908 } 916 }
909 917
910 void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman, 918 void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman,
911 const GrPrimitiveProcessor& processor, 919 const GrPrimitiveProcessor& processor,
912 const GrBatchTracker& bt) { 920 const GrBatchTracker& bt) {
921 this->setUniformViewMatrix(pdman, processor.viewMatrix());
922
913 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); 923 const DashingLineEffect& de = processor.cast<DashingLineEffect>();
914 const SkRect& rect = de.getRect(); 924 const SkRect& rect = de.getRect();
915 SkScalar intervalLength = de.getIntervalLength(); 925 SkScalar intervalLength = de.getIntervalLength();
916 if (rect != fPrevRect || intervalLength != fPrevIntervalLength) { 926 if (rect != fPrevRect || intervalLength != fPrevIntervalLength) {
917 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, 927 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f,
918 rect.fRight - 0.5f, rect.fBottom - 0.5f); 928 rect.fRight - 0.5f, rect.fBottom - 0.5f);
919 pdman.set1f(fIntervalUniform, intervalLength); 929 pdman.set1f(fIntervalUniform, intervalLength);
920 fPrevRect = rect; 930 fPrevRect = rect;
921 fPrevIntervalLength = intervalLength; 931 fPrevIntervalLength = intervalLength;
922 } 932 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 SkScalarHalf(strokeWidth), 1062 SkScalarHalf(strokeWidth),
1053 localMatrix); 1063 localMatrix);
1054 case GrDashingEffect::kNonRound_DashCap: 1064 case GrDashingEffect::kNonRound_DashCap:
1055 return DashingLineEffect::Create(color, viewMatrix, edgeType, info, strokeWidth, 1065 return DashingLineEffect::Create(color, viewMatrix, edgeType, info, strokeWidth,
1056 localMatrix); 1066 localMatrix);
1057 default: 1067 default:
1058 SkFAIL("Unexpected dashed cap."); 1068 SkFAIL("Unexpected dashed cap.");
1059 } 1069 }
1060 return NULL; 1070 return NULL;
1061 } 1071 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698