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

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

Issue 788733003: Make addUniform take a precision (Closed) Base URL: https://skia.googlesource.com/skia.git@move_prec
Patch Set: rebase Created 6 years 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/GrOvalEffect.cpp ('k') | src/gpu/effects/GrTextureDomain.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 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 "GrRRectEffect.h" 8 #include "GrRRectEffect.h"
9 9
10 #include "GrConvexPolyEffect.h" 10 #include "GrConvexPolyEffect.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 const TransformedCoordsArray&, 161 const TransformedCoordsArray&,
162 const TextureSamplerArray& samplers) { 162 const TextureSamplerArray& samplers) {
163 const CircularRRectEffect& crre = fp.cast<CircularRRectEffect>(); 163 const CircularRRectEffect& crre = fp.cast<CircularRRectEffect>();
164 const char *rectName; 164 const char *rectName;
165 const char *radiusPlusHalfName; 165 const char *radiusPlusHalfName;
166 // The inner rect is the rrect bounds inset by the radius. Its left, top, ri ght, and bottom 166 // The inner rect is the rrect bounds inset by the radius. Its left, top, ri ght, and bottom
167 // edges correspond to components x, y, z, and w, respectively. When a side of the rrect has 167 // edges correspond to components x, y, z, and w, respectively. When a side of the rrect has
168 // only rectangular corners, that side's value corresponds to the rect edge' s value outset by 168 // only rectangular corners, that side's value corresponds to the rect edge' s value outset by
169 // half a pixel. 169 // half a pixel.
170 fInnerRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibi lity, 170 fInnerRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibi lity,
171 kVec4f_GrSLType, 171 kVec4f_GrSLType, kDefault_GrSLPrecis ion,
172 "innerRect", 172 "innerRect",
173 &rectName); 173 &rectName);
174 fRadiusPlusHalfUniform = builder->addUniform(GrGLProgramBuilder::kFragment_V isibility, 174 fRadiusPlusHalfUniform = builder->addUniform(GrGLProgramBuilder::kFragment_V isibility,
175 kFloat_GrSLType, 175 kFloat_GrSLType, kDefault_GrSLP recision,
176 "radiusPlusHalf", 176 "radiusPlusHalf",
177 &radiusPlusHalfName); 177 &radiusPlusHalfName);
178 178
179 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 179 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
180 const char* fragmentPos = fsBuilder->fragmentPosition(); 180 const char* fragmentPos = fsBuilder->fragmentPosition();
181 // At each quarter-circle corner we compute a vector that is the offset of t he fragment position 181 // At each quarter-circle corner we compute a vector that is the offset of t he fragment position
182 // from the circle center. The vector is pinned in x and y to be in the quar ter-plane relevant 182 // from the circle center. The vector is pinned in x and y to be in the quar ter-plane relevant
183 // to that corner. This means that points near the interior near the rrect t op edge will have 183 // to that corner. This means that points near the interior near the rrect t op edge will have
184 // a vector that points straight up for both the TL left and TR corners. Com puting an 184 // a vector that points straight up for both the TL left and TR corners. Com puting an
185 // alpha from this vector at either the TR or TL corner will give the correc t result. Similarly, 185 // alpha from this vector at either the TR or TL corner will give the correc t result. Similarly,
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 void GLEllipticalRRectEffect::emitCode(GrGLFPBuilder* builder, 514 void GLEllipticalRRectEffect::emitCode(GrGLFPBuilder* builder,
515 const GrFragmentProcessor& effect, 515 const GrFragmentProcessor& effect,
516 const char* outputColor, 516 const char* outputColor,
517 const char* inputColor, 517 const char* inputColor,
518 const TransformedCoordsArray&, 518 const TransformedCoordsArray&,
519 const TextureSamplerArray& samplers) { 519 const TextureSamplerArray& samplers) {
520 const EllipticalRRectEffect& erre = effect.cast<EllipticalRRectEffect>(); 520 const EllipticalRRectEffect& erre = effect.cast<EllipticalRRectEffect>();
521 const char *rectName; 521 const char *rectName;
522 // The inner rect is the rrect bounds inset by the x/y radii 522 // The inner rect is the rrect bounds inset by the x/y radii
523 fInnerRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibi lity, 523 fInnerRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibi lity,
524 kVec4f_GrSLType, 524 kVec4f_GrSLType, kDefault_GrSLPrecis ion,
525 "innerRect", 525 "innerRect",
526 &rectName); 526 &rectName);
527 527
528 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 528 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
529 const char* fragmentPos = fsBuilder->fragmentPosition(); 529 const char* fragmentPos = fsBuilder->fragmentPosition();
530 // At each quarter-ellipse corner we compute a vector that is the offset of the fragment pos 530 // At each quarter-ellipse corner we compute a vector that is the offset of the fragment pos
531 // to the ellipse center. The vector is pinned in x and y to be in the quart er-plane relevant 531 // to the ellipse center. The vector is pinned in x and y to be in the quart er-plane relevant
532 // to that corner. This means that points near the interior near the rrect t op edge will have 532 // to that corner. This means that points near the interior near the rrect t op edge will have
533 // a vector that points straight up for both the TL left and TR corners. Com puting an 533 // a vector that points straight up for both the TL left and TR corners. Com puting an
534 // alpha from this vector at either the TR or TL corner will give the correc t result. Similarly, 534 // alpha from this vector at either the TR or TL corner will give the correc t result. Similarly,
535 // fragments near the other three edges will get the correct AA. Fragments i n the interior of 535 // fragments near the other three edges will get the correct AA. Fragments i n the interior of
536 // the rrect will have a (0,0) vector at all four corners. So long as the ra dii > 0.5 they will 536 // the rrect will have a (0,0) vector at all four corners. So long as the ra dii > 0.5 they will
537 // correctly produce an alpha value of 1 at all four corners. We take the mi n of all the alphas. 537 // correctly produce an alpha value of 1 at all four corners. We take the mi n of all the alphas.
538 // The code below is a simplified version of the above that performs maxs on the vector 538 // The code below is a simplified version of the above that performs maxs on the vector
539 // components before computing distances and alpha values so that only one d istance computation 539 // components before computing distances and alpha values so that only one d istance computation
540 // need be computed to determine the min alpha. 540 // need be computed to determine the min alpha.
541 fsBuilder->codeAppendf("\t\tvec2 dxy0 = %s.xy - %s.xy;\n", rectName, fragmen tPos); 541 fsBuilder->codeAppendf("\t\tvec2 dxy0 = %s.xy - %s.xy;\n", rectName, fragmen tPos);
542 fsBuilder->codeAppendf("\t\tvec2 dxy1 = %s.xy - %s.zw;\n", fragmentPos, rect Name); 542 fsBuilder->codeAppendf("\t\tvec2 dxy1 = %s.xy - %s.zw;\n", fragmentPos, rect Name);
543 switch (erre.getRRect().getType()) { 543 switch (erre.getRRect().getType()) {
544 case SkRRect::kSimple_Type: { 544 case SkRRect::kSimple_Type: {
545 const char *invRadiiXYSqdName; 545 const char *invRadiiXYSqdName;
546 fInvRadiiSqdUniform = builder->addUniform(GrGLProgramBuilder::kFragm ent_Visibility, 546 fInvRadiiSqdUniform = builder->addUniform(GrGLProgramBuilder::kFragm ent_Visibility,
547 kVec2f_GrSLType, 547 kVec2f_GrSLType, kDefault_ GrSLPrecision,
548 "invRadiiXY", 548 "invRadiiXY",
549 &invRadiiXYSqdName); 549 &invRadiiXYSqdName);
550 fsBuilder->codeAppend("\t\tvec2 dxy = max(max(dxy0, dxy1), 0.0);\n") ; 550 fsBuilder->codeAppend("\t\tvec2 dxy = max(max(dxy0, dxy1), 0.0);\n") ;
551 // Z is the x/y offsets divided by squared radii. 551 // Z is the x/y offsets divided by squared radii.
552 fsBuilder->codeAppendf("\t\tvec2 Z = dxy * %s;\n", invRadiiXYSqdName ); 552 fsBuilder->codeAppendf("\t\tvec2 Z = dxy * %s;\n", invRadiiXYSqdName );
553 break; 553 break;
554 } 554 }
555 case SkRRect::kNinePatch_Type: { 555 case SkRRect::kNinePatch_Type: {
556 const char *invRadiiLTRBSqdName; 556 const char *invRadiiLTRBSqdName;
557 fInvRadiiSqdUniform = builder->addUniform(GrGLProgramBuilder::kFragm ent_Visibility, 557 fInvRadiiSqdUniform = builder->addUniform(GrGLProgramBuilder::kFragm ent_Visibility,
558 kVec4f_GrSLType, 558 kVec4f_GrSLType, kDefault_ GrSLPrecision,
559 "invRadiiLTRB", 559 "invRadiiLTRB",
560 &invRadiiLTRBSqdName); 560 &invRadiiLTRBSqdName);
561 fsBuilder->codeAppend("\t\tvec2 dxy = max(max(dxy0, dxy1), 0.0);\n") ; 561 fsBuilder->codeAppend("\t\tvec2 dxy = max(max(dxy0, dxy1), 0.0);\n") ;
562 // Z is the x/y offsets divided by squared radii. We only care about the (at most) one 562 // Z is the x/y offsets divided by squared radii. We only care about the (at most) one
563 // corner where both the x and y offsets are positive, hence the max es. (The inverse 563 // corner where both the x and y offsets are positive, hence the max es. (The inverse
564 // squared radii will always be positive.) 564 // squared radii will always be positive.)
565 fsBuilder->codeAppendf("\t\tvec2 Z = max(max(dxy0 * %s.xy, dxy1 * %s .zw), 0.0);\n", 565 fsBuilder->codeAppendf("\t\tvec2 Z = max(max(dxy0 * %s.xy, dxy1 * %s .zw), 0.0);\n",
566 invRadiiLTRBSqdName, invRadiiLTRBSqdName); 566 invRadiiLTRBSqdName, invRadiiLTRBSqdName);
567 break; 567 break;
568 } 568 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 if (rrect.isNinePatch()) { 733 if (rrect.isNinePatch()) {
734 return EllipticalRRectEffect::Create(edgeType, rrect); 734 return EllipticalRRectEffect::Create(edgeType, rrect);
735 } 735 }
736 return NULL; 736 return NULL;
737 } 737 }
738 } 738 }
739 } 739 }
740 740
741 return NULL; 741 return NULL;
742 } 742 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrOvalEffect.cpp ('k') | src/gpu/effects/GrTextureDomain.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698