| OLD | NEW |
| 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrProcessor&) | 220 GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrProcessor&) |
| 221 : fVSVaryingName(nullptr) | 221 : fVSVaryingName(nullptr) |
| 222 , fFSVaryingName(nullptr) | 222 , fFSVaryingName(nullptr) |
| 223 , fCachedRadius(-SK_ScalarMax) | 223 , fCachedRadius(-SK_ScalarMax) |
| 224 , fCachedDiffRadius(-SK_ScalarMax) {} | 224 , fCachedDiffRadius(-SK_ScalarMax) {} |
| 225 | 225 |
| 226 void GLEdge2PtConicalEffect::emitCode(EmitArgs& args) { | 226 void GLEdge2PtConicalEffect::emitCode(EmitArgs& args) { |
| 227 const Edge2PtConicalEffect& ge = args.fFp.cast<Edge2PtConicalEffect>(); | 227 const Edge2PtConicalEffect& ge = args.fFp.cast<Edge2PtConicalEffect>(); |
| 228 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 228 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
| 229 this->emitUniforms(uniformHandler, ge); | 229 this->emitUniforms(uniformHandler, ge); |
| 230 fParamUni = uniformHandler->addUniformArray(kFragment_GrShaderFlag, | 230 fParamUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
| 231 kFloat_GrSLType, kDefault_GrSLPr
ecision, | 231 kVec3f_GrSLType, kDefault_GrSLPrecisi
on, |
| 232 "Conical2FSParams", 3); | 232 "Conical2FSParams"); |
| 233 | 233 |
| 234 SkString cName("c"); | 234 SkString cName("c"); |
| 235 SkString tName("t"); | 235 SkString tName("t"); |
| 236 SkString p0; // start radius | 236 SkString p0; // start radius |
| 237 SkString p1; // start radius squared | 237 SkString p1; // start radius squared |
| 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 |
| 241 uniformHandler->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); | 241 p0.appendf("%s.x", uniformHandler->getUniformVariable(fParamUni).getName().c
_str()); |
| 242 uniformHandler->getUniformVariable(fParamUni).appendArrayAccess(2, &p2); | 242 p1.appendf("%s.y", uniformHandler->getUniformVariable(fParamUni).getName().c
_str()); |
| 243 p2.appendf("%s.z", uniformHandler->getUniformVariable(fParamUni).getName().c
_str()); |
| 243 | 244 |
| 244 // We interpolate the linear component in coords[1]. | 245 // We interpolate the linear component in coords[1]. |
| 245 SkASSERT(args.fCoords[0].getType() == args.fCoords[1].getType()); | 246 SkASSERT(args.fCoords[0].getType() == args.fCoords[1].getType()); |
| 246 const char* coords2D; | 247 const char* coords2D; |
| 247 SkString bVar; | 248 SkString bVar; |
| 248 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; | 249 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 249 if (kVec3f_GrSLType == args.fCoords[0].getType()) { | 250 if (kVec3f_GrSLType == args.fCoords[0].getType()) { |
| 250 fragBuilder->codeAppendf("\tvec3 interpolants = vec3(%s.xy / %s.z, %s.x
/ %s.z);\n", | 251 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(), | 252 args.fCoords[0].c_str(), args.fCoords[0].c_str(), |
| 252 args.fCoords[1].c_str(), args.fCoords[1].c_str())
; | 253 args.fCoords[1].c_str(), args.fCoords[1].c_str())
; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 void GLEdge2PtConicalEffect::onSetData(const GrGLSLProgramDataManager& pdman, | 288 void GLEdge2PtConicalEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
| 288 const GrProcessor& processor) { | 289 const GrProcessor& processor) { |
| 289 INHERITED::onSetData(pdman, processor); | 290 INHERITED::onSetData(pdman, processor); |
| 290 const Edge2PtConicalEffect& data = processor.cast<Edge2PtConicalEffect>(); | 291 const Edge2PtConicalEffect& data = processor.cast<Edge2PtConicalEffect>(); |
| 291 SkScalar radius0 = data.radius(); | 292 SkScalar radius0 = data.radius(); |
| 292 SkScalar diffRadius = data.diffRadius(); | 293 SkScalar diffRadius = data.diffRadius(); |
| 293 | 294 |
| 294 if (fCachedRadius != radius0 || | 295 if (fCachedRadius != radius0 || |
| 295 fCachedDiffRadius != diffRadius) { | 296 fCachedDiffRadius != diffRadius) { |
| 296 | 297 |
| 297 float values[3] = { | 298 pdman.set3f(fParamUni, SkScalarToFloat(radius0), |
| 298 SkScalarToFloat(radius0), | 299 SkScalarToFloat(SkScalarMul(radius0, radius0)), SkScalarToFl
oat(diffRadius)); |
| 299 SkScalarToFloat(SkScalarMul(radius0, radius0)), | |
| 300 SkScalarToFloat(diffRadius) | |
| 301 }; | |
| 302 | |
| 303 pdman.set1fv(fParamUni, 3, values); | |
| 304 fCachedRadius = radius0; | 300 fCachedRadius = radius0; |
| 305 fCachedDiffRadius = diffRadius; | 301 fCachedDiffRadius = diffRadius; |
| 306 } | 302 } |
| 307 } | 303 } |
| 308 | 304 |
| 309 void GLEdge2PtConicalEffect::GenKey(const GrProcessor& processor, | 305 void GLEdge2PtConicalEffect::GenKey(const GrProcessor& processor, |
| 310 const GrGLSLCaps&, GrProcessorKeyBuilder* b)
{ | 306 const GrGLSLCaps&, GrProcessorKeyBuilder* b)
{ |
| 311 b->add32(GenBaseGradientKey(processor)); | 307 b->add32(GenBaseGradientKey(processor)); |
| 312 } | 308 } |
| 313 | 309 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 , fFSVaryingName(nullptr) | 499 , fFSVaryingName(nullptr) |
| 504 , fCachedFocal(SK_ScalarMax) { | 500 , fCachedFocal(SK_ScalarMax) { |
| 505 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon
icalEffect>(); | 501 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon
icalEffect>(); |
| 506 fIsFlipped = data.isFlipped(); | 502 fIsFlipped = data.isFlipped(); |
| 507 } | 503 } |
| 508 | 504 |
| 509 void GLFocalOutside2PtConicalEffect::emitCode(EmitArgs& args) { | 505 void GLFocalOutside2PtConicalEffect::emitCode(EmitArgs& args) { |
| 510 const FocalOutside2PtConicalEffect& ge = args.fFp.cast<FocalOutside2PtConica
lEffect>(); | 506 const FocalOutside2PtConicalEffect& ge = args.fFp.cast<FocalOutside2PtConica
lEffect>(); |
| 511 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 507 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
| 512 this->emitUniforms(uniformHandler, ge); | 508 this->emitUniforms(uniformHandler, ge); |
| 513 fParamUni = uniformHandler->addUniformArray(kFragment_GrShaderFlag, | 509 fParamUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
| 514 kFloat_GrSLType, kDefault_GrSLPr
ecision, | 510 kVec2f_GrSLType, kDefault_GrSLPrecisi
on, |
| 515 "Conical2FSParams", 2); | 511 "Conical2FSParams"); |
| 516 SkString tName("t"); | 512 SkString tName("t"); |
| 517 SkString p0; // focalX | 513 SkString p0; // focalX |
| 518 SkString p1; // 1 - focalX * focalX | 514 SkString p1; // 1 - focalX * focalX |
| 519 | 515 |
| 520 uniformHandler->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); | 516 p0.appendf("%s.x", uniformHandler->getUniformVariable(fParamUni).getName().c
_str()); |
| 521 uniformHandler->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); | 517 p1.appendf("%s.y", uniformHandler->getUniformVariable(fParamUni).getName().c
_str()); |
| 522 | 518 |
| 523 // if we have a vec3 from being in perspective, convert it to a vec2 first | 519 // if we have a vec3 from being in perspective, convert it to a vec2 first |
| 524 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; | 520 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 525 SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0); | 521 SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0); |
| 526 const char* coords2D = coords2DString.c_str(); | 522 const char* coords2D = coords2DString.c_str(); |
| 527 | 523 |
| 528 // t = p.x * focal.x +/- sqrt(p.x^2 + (1 - focal.x^2) * p.y^2) | 524 // t = p.x * focal.x +/- sqrt(p.x^2 + (1 - focal.x^2) * p.y^2) |
| 529 | 525 |
| 530 // output will default to transparent black (we simply won't write anything | 526 // output will default to transparent black (we simply won't write anything |
| 531 // else to it if invalid, instead of discarding or returning prematurely) | 527 // else to it if invalid, instead of discarding or returning prematurely) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 561 void GLFocalOutside2PtConicalEffect::onSetData(const GrGLSLProgramDataManager& p
dman, | 557 void GLFocalOutside2PtConicalEffect::onSetData(const GrGLSLProgramDataManager& p
dman, |
| 562 const GrProcessor& processor) { | 558 const GrProcessor& processor) { |
| 563 INHERITED::onSetData(pdman, processor); | 559 INHERITED::onSetData(pdman, processor); |
| 564 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon
icalEffect>(); | 560 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon
icalEffect>(); |
| 565 SkASSERT(data.isFlipped() == fIsFlipped); | 561 SkASSERT(data.isFlipped() == fIsFlipped); |
| 566 SkScalar focal = data.focal(); | 562 SkScalar focal = data.focal(); |
| 567 | 563 |
| 568 if (fCachedFocal != focal) { | 564 if (fCachedFocal != focal) { |
| 569 SkScalar oneMinus2F = 1.f - SkScalarMul(focal, focal); | 565 SkScalar oneMinus2F = 1.f - SkScalarMul(focal, focal); |
| 570 | 566 |
| 571 float values[2] = { | 567 pdman.set2f(fParamUni, SkScalarToFloat(focal), SkScalarToFloat(oneMinus2
F)); |
| 572 SkScalarToFloat(focal), | |
| 573 SkScalarToFloat(oneMinus2F), | |
| 574 }; | |
| 575 | |
| 576 pdman.set1fv(fParamUni, 2, values); | |
| 577 fCachedFocal = focal; | 568 fCachedFocal = focal; |
| 578 } | 569 } |
| 579 } | 570 } |
| 580 | 571 |
| 581 void GLFocalOutside2PtConicalEffect::GenKey(const GrProcessor& processor, | 572 void GLFocalOutside2PtConicalEffect::GenKey(const GrProcessor& processor, |
| 582 const GrGLSLCaps&, GrProcessorKeyBui
lder* b) { | 573 const GrGLSLCaps&, GrProcessorKeyBui
lder* b) { |
| 583 uint32_t* key = b->add32n(2); | 574 uint32_t* key = b->add32n(2); |
| 584 key[0] = GenBaseGradientKey(processor); | 575 key[0] = GenBaseGradientKey(processor); |
| 585 key[1] = processor.cast<FocalOutside2PtConicalEffect>().isFlipped(); | 576 key[1] = processor.cast<FocalOutside2PtConicalEffect>().isFlipped(); |
| 586 } | 577 } |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1342 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf
o); | 1333 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf
o); |
| 1343 } else if (type == kEdge_ConicalType) { | 1334 } else if (type == kEdge_ConicalType) { |
| 1344 set_matrix_edge_conical(shader, &matrix); | 1335 set_matrix_edge_conical(shader, &matrix); |
| 1345 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); | 1336 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); |
| 1346 } else { | 1337 } else { |
| 1347 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in
fo); | 1338 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in
fo); |
| 1348 } | 1339 } |
| 1349 } | 1340 } |
| 1350 | 1341 |
| 1351 #endif | 1342 #endif |
| OLD | NEW |