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

Side by Side Diff: src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp

Issue 1709153002: Add more specialized fragment builders (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Make MSVC happy Created 4 years, 10 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/effects/gradients/SkGradientShaderPriv.h ('k') | src/gpu/GrDefaultGeoProcFactory.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 /* 2 /*
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkTwoPointConicalGradient_gpu.h" 9 #include "SkTwoPointConicalGradient_gpu.h"
10 10
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 SkString p2; // difference in radii (r1 - r0) 238 SkString p2; // difference in radii (r1 - r0)
239 239
240 uniformHandler->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); 240 uniformHandler->getUniformVariable(fParamUni).appendArrayAccess(0, &p0);
241 uniformHandler->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); 241 uniformHandler->getUniformVariable(fParamUni).appendArrayAccess(1, &p1);
242 uniformHandler->getUniformVariable(fParamUni).appendArrayAccess(2, &p2); 242 uniformHandler->getUniformVariable(fParamUni).appendArrayAccess(2, &p2);
243 243
244 // We interpolate the linear component in coords[1]. 244 // We interpolate the linear component in coords[1].
245 SkASSERT(args.fCoords[0].getType() == args.fCoords[1].getType()); 245 SkASSERT(args.fCoords[0].getType() == args.fCoords[1].getType());
246 const char* coords2D; 246 const char* coords2D;
247 SkString bVar; 247 SkString bVar;
248 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 248 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
249 if (kVec3f_GrSLType == args.fCoords[0].getType()) { 249 if (kVec3f_GrSLType == args.fCoords[0].getType()) {
250 fragBuilder->codeAppendf("\tvec3 interpolants = vec3(%s.xy / %s.z, %s.x / %s.z);\n", 250 fragBuilder->codeAppendf("\tvec3 interpolants = vec3(%s.xy / %s.z, %s.x / %s.z);\n",
251 args.fCoords[0].c_str(), args.fCoords[0].c_str(), 251 args.fCoords[0].c_str(), args.fCoords[0].c_str(),
252 args.fCoords[1].c_str(), args.fCoords[1].c_str()) ; 252 args.fCoords[1].c_str(), args.fCoords[1].c_str()) ;
253 coords2D = "interpolants.xy"; 253 coords2D = "interpolants.xy";
254 bVar = "interpolants.z"; 254 bVar = "interpolants.z";
255 } else { 255 } else {
256 coords2D = args.fCoords[0].c_str(); 256 coords2D = args.fCoords[0].c_str();
257 bVar.printf("%s.x", args.fCoords[1].c_str()); 257 bVar.printf("%s.x", args.fCoords[1].c_str());
258 } 258 }
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 kFloat_GrSLType, kDefault_GrSLPr ecision, 514 kFloat_GrSLType, kDefault_GrSLPr ecision,
515 "Conical2FSParams", 2); 515 "Conical2FSParams", 2);
516 SkString tName("t"); 516 SkString tName("t");
517 SkString p0; // focalX 517 SkString p0; // focalX
518 SkString p1; // 1 - focalX * focalX 518 SkString p1; // 1 - focalX * focalX
519 519
520 uniformHandler->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); 520 uniformHandler->getUniformVariable(fParamUni).appendArrayAccess(0, &p0);
521 uniformHandler->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); 521 uniformHandler->getUniformVariable(fParamUni).appendArrayAccess(1, &p1);
522 522
523 // if we have a vec3 from being in perspective, convert it to a vec2 first 523 // if we have a vec3 from being in perspective, convert it to a vec2 first
524 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 524 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
525 SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0); 525 SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
526 const char* coords2D = coords2DString.c_str(); 526 const char* coords2D = coords2DString.c_str();
527 527
528 // t = p.x * focal.x +/- sqrt(p.x^2 + (1 - focal.x^2) * p.y^2) 528 // t = p.x * focal.x +/- sqrt(p.x^2 + (1 - focal.x^2) * p.y^2)
529 529
530 // output will default to transparent black (we simply won't write anything 530 // output will default to transparent black (we simply won't write anything
531 // else to it if invalid, instead of discarding or returning prematurely) 531 // else to it if invalid, instead of discarding or returning prematurely)
532 fragBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColo r); 532 fragBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColo r);
533 533
534 fragBuilder->codeAppendf("\tfloat xs = %s.x * %s.x;\n", coords2D, coords2D); 534 fragBuilder->codeAppendf("\tfloat xs = %s.x * %s.x;\n", coords2D, coords2D);
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 fFocalUni = uniformHandler->addUniform(kFragment_GrShaderFlag, 723 fFocalUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
724 kFloat_GrSLType, kDefault_GrSLPrecisi on, 724 kFloat_GrSLType, kDefault_GrSLPrecisi on,
725 "Conical2FSParams"); 725 "Conical2FSParams");
726 SkString tName("t"); 726 SkString tName("t");
727 727
728 // this is the distance along x-axis from the end center to focal point in 728 // this is the distance along x-axis from the end center to focal point in
729 // transformed coordinates 729 // transformed coordinates
730 GrGLSLShaderVar focal = uniformHandler->getUniformVariable(fFocalUni); 730 GrGLSLShaderVar focal = uniformHandler->getUniformVariable(fFocalUni);
731 731
732 // if we have a vec3 from being in perspective, convert it to a vec2 first 732 // if we have a vec3 from being in perspective, convert it to a vec2 first
733 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 733 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
734 SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0); 734 SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
735 const char* coords2D = coords2DString.c_str(); 735 const char* coords2D = coords2DString.c_str();
736 736
737 // t = p.x * focalX + length(p) 737 // t = p.x * focalX + length(p)
738 fragBuilder->codeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_ str(), 738 fragBuilder->codeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_ str(),
739 coords2D, focal.c_str(), coords2D); 739 coords2D, focal.c_str(), coords2D);
740 740
741 this->emitColor(fragBuilder, 741 this->emitColor(fragBuilder,
742 uniformHandler, 742 uniformHandler,
743 args.fGLSLCaps, 743 args.fGLSLCaps,
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 "Conical2FSParams"); 980 "Conical2FSParams");
981 SkString tName("t"); 981 SkString tName("t");
982 982
983 GrGLSLShaderVar center = uniformHandler->getUniformVariable(fCenterUni); 983 GrGLSLShaderVar center = uniformHandler->getUniformVariable(fCenterUni);
984 // params.x = A 984 // params.x = A
985 // params.y = B 985 // params.y = B
986 // params.z = C 986 // params.z = C
987 GrGLSLShaderVar params = uniformHandler->getUniformVariable(fParamUni); 987 GrGLSLShaderVar params = uniformHandler->getUniformVariable(fParamUni);
988 988
989 // if we have a vec3 from being in perspective, convert it to a vec2 first 989 // if we have a vec3 from being in perspective, convert it to a vec2 first
990 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 990 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
991 SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0); 991 SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
992 const char* coords2D = coords2DString.c_str(); 992 const char* coords2D = coords2DString.c_str();
993 993
994 // p = coords2D 994 // p = coords2D
995 // e = center end 995 // e = center end
996 // r = radius end 996 // r = radius end
997 // A = dot(e, e) - r^2 + 2 * r - 1 997 // A = dot(e, e) - r^2 + 2 * r - 1
998 // B = (r -1) / A 998 // B = (r -1) / A
999 // C = 1 / A 999 // C = 1 / A
1000 // d = dot(e, p) + B 1000 // d = dot(e, p) + B
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 "Conical2FSParams"); 1217 "Conical2FSParams");
1218 SkString tName("t"); 1218 SkString tName("t");
1219 1219
1220 GrGLSLShaderVar center = uniformHandler->getUniformVariable(fCenterUni); 1220 GrGLSLShaderVar center = uniformHandler->getUniformVariable(fCenterUni);
1221 // params.x = A 1221 // params.x = A
1222 // params.y = B 1222 // params.y = B
1223 // params.z = C 1223 // params.z = C
1224 GrGLSLShaderVar params = uniformHandler->getUniformVariable(fParamUni); 1224 GrGLSLShaderVar params = uniformHandler->getUniformVariable(fParamUni);
1225 1225
1226 // if we have a vec3 from being in perspective, convert it to a vec2 first 1226 // if we have a vec3 from being in perspective, convert it to a vec2 first
1227 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 1227 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
1228 SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0); 1228 SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
1229 const char* coords2D = coords2DString.c_str(); 1229 const char* coords2D = coords2DString.c_str();
1230 1230
1231 // output will default to transparent black (we simply won't write anything 1231 // output will default to transparent black (we simply won't write anything
1232 // else to it if invalid, instead of discarding or returning prematurely) 1232 // else to it if invalid, instead of discarding or returning prematurely)
1233 fragBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColo r); 1233 fragBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColo r);
1234 1234
1235 // p = coords2D 1235 // p = coords2D
1236 // e = center end 1236 // e = center end
1237 // r = radius end 1237 // r = radius end
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf o); 1342 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf o);
1343 } else if (type == kEdge_ConicalType) { 1343 } else if (type == kEdge_ConicalType) {
1344 set_matrix_edge_conical(shader, &matrix); 1344 set_matrix_edge_conical(shader, &matrix);
1345 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); 1345 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm);
1346 } else { 1346 } else {
1347 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in fo); 1347 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in fo);
1348 } 1348 }
1349 } 1349 }
1350 1350
1351 #endif 1351 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkGradientShaderPriv.h ('k') | src/gpu/GrDefaultGeoProcFactory.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698