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

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

Issue 385713005: Allow GrGLEffects to produce variable length keys. (Closed) Base URL: https://skia.googlesource.com/skia.git@key
Patch Set: rebase Created 6 years, 5 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 /* 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 typedef GrGradientEffect INHERITED; 132 typedef GrGradientEffect INHERITED;
133 }; 133 };
134 134
135 class GLEdge2PtConicalEffect : public GrGLGradientEffect { 135 class GLEdge2PtConicalEffect : public GrGLGradientEffect {
136 public: 136 public:
137 GLEdge2PtConicalEffect(const GrBackendEffectFactory& factory, const GrDrawEf fect&); 137 GLEdge2PtConicalEffect(const GrBackendEffectFactory& factory, const GrDrawEf fect&);
138 virtual ~GLEdge2PtConicalEffect() { } 138 virtual ~GLEdge2PtConicalEffect() { }
139 139
140 virtual void emitCode(GrGLShaderBuilder*, 140 virtual void emitCode(GrGLShaderBuilder*,
141 const GrDrawEffect&, 141 const GrDrawEffect&,
142 EffectKey, 142 const GrEffectKey&,
143 const char* outputColor, 143 const char* outputColor,
144 const char* inputColor, 144 const char* inputColor,
145 const TransformedCoordsArray&, 145 const TransformedCoordsArray&,
146 const TextureSamplerArray&) SK_OVERRIDE; 146 const TextureSamplerArray&) SK_OVERRIDE;
147 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE; 147 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE;
148 148
149 static EffectKey GenKey(const GrDrawEffect&, const GrGLCaps& caps); 149 static void GenKey(const GrDrawEffect&, const GrGLCaps& caps, GrEffectKeyBui lder* b);
150 150
151 protected: 151 protected:
152 UniformHandle fParamUni; 152 UniformHandle fParamUni;
153 153
154 const char* fVSVaryingName; 154 const char* fVSVaryingName;
155 const char* fFSVaryingName; 155 const char* fFSVaryingName;
156 156
157 // @{ 157 // @{
158 /// Values last uploaded as uniforms 158 /// Values last uploaded as uniforms
159 159
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrBackendEffectFactory& fac tory, 212 GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrBackendEffectFactory& fac tory,
213 const GrDrawEffect& drawEffect) 213 const GrDrawEffect& drawEffect)
214 : INHERITED(factory) 214 : INHERITED(factory)
215 , fVSVaryingName(NULL) 215 , fVSVaryingName(NULL)
216 , fFSVaryingName(NULL) 216 , fFSVaryingName(NULL)
217 , fCachedRadius(-SK_ScalarMax) 217 , fCachedRadius(-SK_ScalarMax)
218 , fCachedDiffRadius(-SK_ScalarMax) {} 218 , fCachedDiffRadius(-SK_ScalarMax) {}
219 219
220 void GLEdge2PtConicalEffect::emitCode(GrGLShaderBuilder* builder, 220 void GLEdge2PtConicalEffect::emitCode(GrGLShaderBuilder* builder,
221 const GrDrawEffect&, 221 const GrDrawEffect&,
222 EffectKey key, 222 const GrEffectKey& key,
223 const char* outputColor, 223 const char* outputColor,
224 const char* inputColor, 224 const char* inputColor,
225 const TransformedCoordsArray& coords, 225 const TransformedCoordsArray& coords,
226 const TextureSamplerArray& samplers) { 226 const TextureSamplerArray& samplers) {
227 this->emitUniforms(builder, key); 227 uint32_t baseKey = key.get32(0);
228 this->emitUniforms(builder, baseKey);
228 fParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibility , 229 fParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibility ,
229 kFloat_GrSLType, "Conical2FSParams", 3) ; 230 kFloat_GrSLType, "Conical2FSParams", 3) ;
230 231
231 SkString cName("c"); 232 SkString cName("c");
232 SkString tName("t"); 233 SkString tName("t");
233 SkString p0; // start radius 234 SkString p0; // start radius
234 SkString p1; // start radius squared 235 SkString p1; // start radius squared
235 SkString p2; // difference in radii (r1 - r0) 236 SkString p2; // difference in radii (r1 - r0)
236 237
237 builder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); 238 builder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0);
(...skipping 23 matching lines...) Expand all
261 cName.c_str(), coords2D, coords2D, p1.c_str()); 262 cName.c_str(), coords2D, coords2D, p1.c_str());
262 263
263 // linear case: t = -c/b 264 // linear case: t = -c/b
264 builder->fsCodeAppendf("\tfloat %s = -(%s / %s);\n", tName.c_str(), 265 builder->fsCodeAppendf("\tfloat %s = -(%s / %s);\n", tName.c_str(),
265 cName.c_str(), bVar.c_str()); 266 cName.c_str(), bVar.c_str());
266 267
267 // if r(t) > 0, then t will be the x coordinate 268 // if r(t) > 0, then t will be the x coordinate
268 builder->fsCodeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(), 269 builder->fsCodeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(),
269 p2.c_str(), p0.c_str()); 270 p2.c_str(), p0.c_str());
270 builder->fsCodeAppend("\t"); 271 builder->fsCodeAppend("\t");
271 this->emitColor(builder, tName.c_str(), key, outputColor, inputColor, sample rs); 272 this->emitColor(builder, tName.c_str(), baseKey, outputColor, inputColor, sa mplers);
272 builder->fsCodeAppend("\t}\n"); 273 builder->fsCodeAppend("\t}\n");
273 } 274 }
274 275
275 void GLEdge2PtConicalEffect::setData(const GrGLUniformManager& uman, 276 void GLEdge2PtConicalEffect::setData(const GrGLUniformManager& uman,
276 const GrDrawEffect& drawEffect) { 277 const GrDrawEffect& drawEffect) {
277 INHERITED::setData(uman, drawEffect); 278 INHERITED::setData(uman, drawEffect);
278 const Edge2PtConicalEffect& data = drawEffect.castEffect<Edge2PtConicalEffec t>(); 279 const Edge2PtConicalEffect& data = drawEffect.castEffect<Edge2PtConicalEffec t>();
279 SkScalar radius0 = data.radius(); 280 SkScalar radius0 = data.radius();
280 SkScalar diffRadius = data.diffRadius(); 281 SkScalar diffRadius = data.diffRadius();
281 282
282 if (fCachedRadius != radius0 || 283 if (fCachedRadius != radius0 ||
283 fCachedDiffRadius != diffRadius) { 284 fCachedDiffRadius != diffRadius) {
284 285
285 float values[3] = { 286 float values[3] = {
286 SkScalarToFloat(radius0), 287 SkScalarToFloat(radius0),
287 SkScalarToFloat(SkScalarMul(radius0, radius0)), 288 SkScalarToFloat(SkScalarMul(radius0, radius0)),
288 SkScalarToFloat(diffRadius) 289 SkScalarToFloat(diffRadius)
289 }; 290 };
290 291
291 uman.set1fv(fParamUni, 3, values); 292 uman.set1fv(fParamUni, 3, values);
292 fCachedRadius = radius0; 293 fCachedRadius = radius0;
293 fCachedDiffRadius = diffRadius; 294 fCachedDiffRadius = diffRadius;
294 } 295 }
295 } 296 }
296 297
297 GrGLEffect::EffectKey GLEdge2PtConicalEffect::GenKey(const GrDrawEffect& drawEff ect, 298 void GLEdge2PtConicalEffect::GenKey(const GrDrawEffect& drawEffect,
298 const GrGLCaps&) { 299 const GrGLCaps&, GrEffectKeyBuilder* b) {
299 return GenBaseGradientKey(drawEffect); 300 b->add32(GenBaseGradientKey(drawEffect));
300 } 301 }
301 302
302 ////////////////////////////////////////////////////////////////////////////// 303 //////////////////////////////////////////////////////////////////////////////
303 // Focal Conical Gradients 304 // Focal Conical Gradients
304 ////////////////////////////////////////////////////////////////////////////// 305 //////////////////////////////////////////////////////////////////////////////
305 306
306 static ConicalType set_matrix_focal_conical(const SkTwoPointConicalGradient& sha der, 307 static ConicalType set_matrix_focal_conical(const SkTwoPointConicalGradient& sha der,
307 SkMatrix* invLMatrix, SkScalar* foca lX) { 308 SkMatrix* invLMatrix, SkScalar* foca lX) {
308 // Inverse of the current local matrix is passed in then, 309 // Inverse of the current local matrix is passed in then,
309 // translate, scale, and rotate such that endCircle is unit circle on x-axis , 310 // translate, scale, and rotate such that endCircle is unit circle on x-axis ,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 typedef GrGradientEffect INHERITED; 408 typedef GrGradientEffect INHERITED;
408 }; 409 };
409 410
410 class GLFocalOutside2PtConicalEffect : public GrGLGradientEffect { 411 class GLFocalOutside2PtConicalEffect : public GrGLGradientEffect {
411 public: 412 public:
412 GLFocalOutside2PtConicalEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&); 413 GLFocalOutside2PtConicalEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&);
413 virtual ~GLFocalOutside2PtConicalEffect() { } 414 virtual ~GLFocalOutside2PtConicalEffect() { }
414 415
415 virtual void emitCode(GrGLShaderBuilder*, 416 virtual void emitCode(GrGLShaderBuilder*,
416 const GrDrawEffect&, 417 const GrDrawEffect&,
417 EffectKey, 418 const GrEffectKey&,
418 const char* outputColor, 419 const char* outputColor,
419 const char* inputColor, 420 const char* inputColor,
420 const TransformedCoordsArray&, 421 const TransformedCoordsArray&,
421 const TextureSamplerArray&) SK_OVERRIDE; 422 const TextureSamplerArray&) SK_OVERRIDE;
422 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE; 423 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE;
423 424
424 static EffectKey GenKey(const GrDrawEffect&, const GrGLCaps& caps); 425 static void GenKey(const GrDrawEffect&, const GrGLCaps& caps, GrEffectKeyBui lder* b);
425 426
426 protected: 427 protected:
427 UniformHandle fParamUni; 428 UniformHandle fParamUni;
428 429
429 const char* fVSVaryingName; 430 const char* fVSVaryingName;
430 const char* fFSVaryingName; 431 const char* fFSVaryingName;
431 432
432 bool fIsFlipped; 433 bool fIsFlipped;
433 434
434 // @{ 435 // @{
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 : INHERITED(factory) 488 : INHERITED(factory)
488 , fVSVaryingName(NULL) 489 , fVSVaryingName(NULL)
489 , fFSVaryingName(NULL) 490 , fFSVaryingName(NULL)
490 , fCachedFocal(SK_ScalarMax) { 491 , fCachedFocal(SK_ScalarMax) {
491 const FocalOutside2PtConicalEffect& data = drawEffect.castEffect<FocalOutsid e2PtConicalEffect>(); 492 const FocalOutside2PtConicalEffect& data = drawEffect.castEffect<FocalOutsid e2PtConicalEffect>();
492 fIsFlipped = data.isFlipped(); 493 fIsFlipped = data.isFlipped();
493 } 494 }
494 495
495 void GLFocalOutside2PtConicalEffect::emitCode(GrGLShaderBuilder* builder, 496 void GLFocalOutside2PtConicalEffect::emitCode(GrGLShaderBuilder* builder,
496 const GrDrawEffect&, 497 const GrDrawEffect&,
497 EffectKey key, 498 const GrEffectKey& key,
498 const char* outputColor, 499 const char* outputColor,
499 const char* inputColor, 500 const char* inputColor,
500 const TransformedCoordsArray& coor ds, 501 const TransformedCoordsArray& coor ds,
501 const TextureSamplerArray& sampler s) { 502 const TextureSamplerArray& sampler s) {
502 this->emitUniforms(builder, key); 503 uint32_t baseKey = key.get32(0);
504 this->emitUniforms(builder, baseKey);
503 fParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibility , 505 fParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibility ,
504 kFloat_GrSLType, "Conical2FSParams", 2) ; 506 kFloat_GrSLType, "Conical2FSParams", 2) ;
505 SkString tName("t"); 507 SkString tName("t");
506 SkString p0; // focalX 508 SkString p0; // focalX
507 SkString p1; // 1 - focalX * focalX 509 SkString p1; // 1 - focalX * focalX
508 510
509 builder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); 511 builder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0);
510 builder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); 512 builder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1);
511 513
512 // if we have a vec3 from being in perspective, convert it to a vec2 first 514 // if we have a vec3 from being in perspective, convert it to a vec2 first
(...skipping 15 matching lines...) Expand all
528 if (!fIsFlipped) { 530 if (!fIsFlipped) {
529 builder->fsCodeAppendf("\tfloat %s = %s.x * %s + sqrt(d);\n", tName.c_s tr(), 531 builder->fsCodeAppendf("\tfloat %s = %s.x * %s + sqrt(d);\n", tName.c_s tr(),
530 coords2D, p0.c_str()); 532 coords2D, p0.c_str());
531 } else { 533 } else {
532 builder->fsCodeAppendf("\tfloat %s = %s.x * %s - sqrt(d);\n", tName.c_s tr(), 534 builder->fsCodeAppendf("\tfloat %s = %s.x * %s - sqrt(d);\n", tName.c_s tr(),
533 coords2D, p0.c_str()); 535 coords2D, p0.c_str());
534 } 536 }
535 537
536 builder->fsCodeAppendf("\tif (%s >= 0.0 && d >= 0.0) {\n", tName.c_str()); 538 builder->fsCodeAppendf("\tif (%s >= 0.0 && d >= 0.0) {\n", tName.c_str());
537 builder->fsCodeAppend("\t\t"); 539 builder->fsCodeAppend("\t\t");
538 this->emitColor(builder, tName.c_str(), key, outputColor, inputColor, sample rs); 540 this->emitColor(builder, tName.c_str(), baseKey, outputColor, inputColor, sa mplers);
539 builder->fsCodeAppend("\t}\n"); 541 builder->fsCodeAppend("\t}\n");
540 } 542 }
541 543
542 void GLFocalOutside2PtConicalEffect::setData(const GrGLUniformManager& uman, 544 void GLFocalOutside2PtConicalEffect::setData(const GrGLUniformManager& uman,
543 const GrDrawEffect& drawEffect) { 545 const GrDrawEffect& drawEffect) {
544 INHERITED::setData(uman, drawEffect); 546 INHERITED::setData(uman, drawEffect);
545 const FocalOutside2PtConicalEffect& data = drawEffect.castEffect<FocalOutsid e2PtConicalEffect>(); 547 const FocalOutside2PtConicalEffect& data = drawEffect.castEffect<FocalOutsid e2PtConicalEffect>();
546 SkASSERT(data.isFlipped() == fIsFlipped); 548 SkASSERT(data.isFlipped() == fIsFlipped);
547 SkScalar focal = data.focal(); 549 SkScalar focal = data.focal();
548 550
549 if (fCachedFocal != focal) { 551 if (fCachedFocal != focal) {
550 SkScalar oneMinus2F = 1.f - SkScalarMul(focal, focal); 552 SkScalar oneMinus2F = 1.f - SkScalarMul(focal, focal);
551 553
552 float values[2] = { 554 float values[2] = {
553 SkScalarToFloat(focal), 555 SkScalarToFloat(focal),
554 SkScalarToFloat(oneMinus2F), 556 SkScalarToFloat(oneMinus2F),
555 }; 557 };
556 558
557 uman.set1fv(fParamUni, 2, values); 559 uman.set1fv(fParamUni, 2, values);
558 fCachedFocal = focal; 560 fCachedFocal = focal;
559 } 561 }
560 } 562 }
561 563
562 GrGLEffect::EffectKey GLFocalOutside2PtConicalEffect::GenKey(const GrDrawEffect& drawEffect, 564 void GLFocalOutside2PtConicalEffect::GenKey(const GrDrawEffect& drawEffect,
563 const GrGLCaps&) { 565 const GrGLCaps&, GrEffectKeyBuilder* b) {
564 enum { 566 uint32_t* key = b->add32n(2);
565 kIsFlipped = 1 << kBaseKeyBitCnt, 567 key[0] = GenBaseGradientKey(drawEffect);
566 }; 568 key[1] = drawEffect.castEffect<FocalOutside2PtConicalEffect>().isFlipped();
567
568 EffectKey key = GenBaseGradientKey(drawEffect);
569
570 if (drawEffect.castEffect<FocalOutside2PtConicalEffect>().isFlipped()) {
571 key |= kIsFlipped;
572 }
573 return key;
574 } 569 }
575 570
576 ////////////////////////////////////////////////////////////////////////////// 571 //////////////////////////////////////////////////////////////////////////////
577 572
578 class GLFocalInside2PtConicalEffect; 573 class GLFocalInside2PtConicalEffect;
579 574
580 class FocalInside2PtConicalEffect : public GrGradientEffect { 575 class FocalInside2PtConicalEffect : public GrGradientEffect {
581 public: 576 public:
582 577
583 static GrEffect* Create(GrContext* ctx, 578 static GrEffect* Create(GrContext* ctx,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 typedef GrGradientEffect INHERITED; 613 typedef GrGradientEffect INHERITED;
619 }; 614 };
620 615
621 class GLFocalInside2PtConicalEffect : public GrGLGradientEffect { 616 class GLFocalInside2PtConicalEffect : public GrGLGradientEffect {
622 public: 617 public:
623 GLFocalInside2PtConicalEffect(const GrBackendEffectFactory& factory, const G rDrawEffect&); 618 GLFocalInside2PtConicalEffect(const GrBackendEffectFactory& factory, const G rDrawEffect&);
624 virtual ~GLFocalInside2PtConicalEffect() {} 619 virtual ~GLFocalInside2PtConicalEffect() {}
625 620
626 virtual void emitCode(GrGLShaderBuilder*, 621 virtual void emitCode(GrGLShaderBuilder*,
627 const GrDrawEffect&, 622 const GrDrawEffect&,
628 EffectKey, 623 const GrEffectKey&,
629 const char* outputColor, 624 const char* outputColor,
630 const char* inputColor, 625 const char* inputColor,
631 const TransformedCoordsArray&, 626 const TransformedCoordsArray&,
632 const TextureSamplerArray&) SK_OVERRIDE; 627 const TextureSamplerArray&) SK_OVERRIDE;
633 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE; 628 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE;
634 629
635 static EffectKey GenKey(const GrDrawEffect&, const GrGLCaps& caps); 630 static void GenKey(const GrDrawEffect&, const GrGLCaps& caps, GrEffectKeyBui lder* b);
636 631
637 protected: 632 protected:
638 UniformHandle fFocalUni; 633 UniformHandle fFocalUni;
639 634
640 const char* fVSVaryingName; 635 const char* fVSVaryingName;
641 const char* fFSVaryingName; 636 const char* fFSVaryingName;
642 637
643 // @{ 638 // @{
644 /// Values last uploaded as uniforms 639 /// Values last uploaded as uniforms
645 640
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 690
696 GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrBackendEffe ctFactory& factory, 691 GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrBackendEffe ctFactory& factory,
697 const GrDrawEffect& drawEffect) 692 const GrDrawEffect& drawEffect)
698 : INHERITED(factory) 693 : INHERITED(factory)
699 , fVSVaryingName(NULL) 694 , fVSVaryingName(NULL)
700 , fFSVaryingName(NULL) 695 , fFSVaryingName(NULL)
701 , fCachedFocal(SK_ScalarMax) {} 696 , fCachedFocal(SK_ScalarMax) {}
702 697
703 void GLFocalInside2PtConicalEffect::emitCode(GrGLShaderBuilder* builder, 698 void GLFocalInside2PtConicalEffect::emitCode(GrGLShaderBuilder* builder,
704 const GrDrawEffect&, 699 const GrDrawEffect&,
705 EffectKey key, 700 const GrEffectKey& key,
706 const char* outputColor, 701 const char* outputColor,
707 const char* inputColor, 702 const char* inputColor,
708 const TransformedCoordsArray& coord s, 703 const TransformedCoordsArray& coord s,
709 const TextureSamplerArray& samplers ) { 704 const TextureSamplerArray& samplers ) {
710 this->emitUniforms(builder, key); 705 uint32_t baseKey = key.get32(0);
706 this->emitUniforms(builder, baseKey);
711 fFocalUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, 707 fFocalUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
712 kFloat_GrSLType, "Conical2FSParams"); 708 kFloat_GrSLType, "Conical2FSParams");
713 SkString tName("t"); 709 SkString tName("t");
714 710
715 // this is the distance along x-axis from the end center to focal point in 711 // this is the distance along x-axis from the end center to focal point in
716 // transformed coordinates 712 // transformed coordinates
717 GrGLShaderVar focal = builder->getUniformVariable(fFocalUni); 713 GrGLShaderVar focal = builder->getUniformVariable(fFocalUni);
718 714
719 // if we have a vec3 from being in perspective, convert it to a vec2 first 715 // if we have a vec3 from being in perspective, convert it to a vec2 first
720 SkString coords2DString = builder->ensureFSCoords2D(coords, 0); 716 SkString coords2DString = builder->ensureFSCoords2D(coords, 0);
721 const char* coords2D = coords2DString.c_str(); 717 const char* coords2D = coords2DString.c_str();
722 718
723 // t = p.x * focalX + length(p) 719 // t = p.x * focalX + length(p)
724 builder->fsCodeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_st r(), 720 builder->fsCodeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_st r(),
725 coords2D, focal.c_str(), coords2D); 721 coords2D, focal.c_str(), coords2D);
726 722
727 this->emitColor(builder, tName.c_str(), key, outputColor, inputColor, sample rs); 723 this->emitColor(builder, tName.c_str(), baseKey, outputColor, inputColor, sa mplers);
728 } 724 }
729 725
730 void GLFocalInside2PtConicalEffect::setData(const GrGLUniformManager& uman, 726 void GLFocalInside2PtConicalEffect::setData(const GrGLUniformManager& uman,
731 const GrDrawEffect& drawEffect) { 727 const GrDrawEffect& drawEffect) {
732 INHERITED::setData(uman, drawEffect); 728 INHERITED::setData(uman, drawEffect);
733 const FocalInside2PtConicalEffect& data = drawEffect.castEffect<FocalInside2 PtConicalEffect>(); 729 const FocalInside2PtConicalEffect& data = drawEffect.castEffect<FocalInside2 PtConicalEffect>();
734 SkScalar focal = data.focal(); 730 SkScalar focal = data.focal();
735 731
736 if (fCachedFocal != focal) { 732 if (fCachedFocal != focal) {
737 uman.set1f(fFocalUni, SkScalarToFloat(focal)); 733 uman.set1f(fFocalUni, SkScalarToFloat(focal));
738 fCachedFocal = focal; 734 fCachedFocal = focal;
739 } 735 }
740 } 736 }
741 737
742 GrGLEffect::EffectKey GLFocalInside2PtConicalEffect::GenKey(const GrDrawEffect& drawEffect, 738 void GLFocalInside2PtConicalEffect::GenKey(const GrDrawEffect& drawEffect,
743 const GrGLCaps&) { 739 const GrGLCaps&, GrEffectKeyBuilder* b) {
744 return GenBaseGradientKey(drawEffect); 740 b->add32(GenBaseGradientKey(drawEffect));
745 } 741 }
746 742
747 ////////////////////////////////////////////////////////////////////////////// 743 //////////////////////////////////////////////////////////////////////////////
748 // Circle Conical Gradients 744 // Circle Conical Gradients
749 ////////////////////////////////////////////////////////////////////////////// 745 //////////////////////////////////////////////////////////////////////////////
750 746
751 struct CircleConicalInfo { 747 struct CircleConicalInfo {
752 SkPoint fCenterEnd; 748 SkPoint fCenterEnd;
753 SkScalar fA; 749 SkScalar fA;
754 SkScalar fB; 750 SkScalar fB;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 typedef GrGradientEffect INHERITED; 854 typedef GrGradientEffect INHERITED;
859 }; 855 };
860 856
861 class GLCircleInside2PtConicalEffect : public GrGLGradientEffect { 857 class GLCircleInside2PtConicalEffect : public GrGLGradientEffect {
862 public: 858 public:
863 GLCircleInside2PtConicalEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&); 859 GLCircleInside2PtConicalEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&);
864 virtual ~GLCircleInside2PtConicalEffect() {} 860 virtual ~GLCircleInside2PtConicalEffect() {}
865 861
866 virtual void emitCode(GrGLShaderBuilder*, 862 virtual void emitCode(GrGLShaderBuilder*,
867 const GrDrawEffect&, 863 const GrDrawEffect&,
868 EffectKey, 864 const GrEffectKey&,
869 const char* outputColor, 865 const char* outputColor,
870 const char* inputColor, 866 const char* inputColor,
871 const TransformedCoordsArray&, 867 const TransformedCoordsArray&,
872 const TextureSamplerArray&) SK_OVERRIDE; 868 const TextureSamplerArray&) SK_OVERRIDE;
873 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE; 869 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE;
874 870
875 static EffectKey GenKey(const GrDrawEffect&, const GrGLCaps& caps); 871 static void GenKey(const GrDrawEffect&, const GrGLCaps& caps, GrEffectKeyBui lder* b);
876 872
877 protected: 873 protected:
878 UniformHandle fCenterUni; 874 UniformHandle fCenterUni;
879 UniformHandle fParamUni; 875 UniformHandle fParamUni;
880 876
881 const char* fVSVaryingName; 877 const char* fVSVaryingName;
882 const char* fFSVaryingName; 878 const char* fFSVaryingName;
883 879
884 // @{ 880 // @{
885 /// Values last uploaded as uniforms 881 /// Values last uploaded as uniforms
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 , fVSVaryingName(NULL) 939 , fVSVaryingName(NULL)
944 , fFSVaryingName(NULL) 940 , fFSVaryingName(NULL)
945 , fCachedCenterX(SK_ScalarMax) 941 , fCachedCenterX(SK_ScalarMax)
946 , fCachedCenterY(SK_ScalarMax) 942 , fCachedCenterY(SK_ScalarMax)
947 , fCachedA(SK_ScalarMax) 943 , fCachedA(SK_ScalarMax)
948 , fCachedB(SK_ScalarMax) 944 , fCachedB(SK_ScalarMax)
949 , fCachedC(SK_ScalarMax) {} 945 , fCachedC(SK_ScalarMax) {}
950 946
951 void GLCircleInside2PtConicalEffect::emitCode(GrGLShaderBuilder* builder, 947 void GLCircleInside2PtConicalEffect::emitCode(GrGLShaderBuilder* builder,
952 const GrDrawEffect&, 948 const GrDrawEffect&,
953 EffectKey key, 949 const GrEffectKey& key,
954 const char* outputColor, 950 const char* outputColor,
955 const char* inputColor, 951 const char* inputColor,
956 const TransformedCoordsArray& coor ds, 952 const TransformedCoordsArray& coor ds,
957 const TextureSamplerArray& sampler s) { 953 const TextureSamplerArray& sampler s) {
958 this->emitUniforms(builder, key); 954 uint32_t baseKey = key.get32(0);
955 this->emitUniforms(builder, baseKey);
959 fCenterUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, 956 fCenterUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
960 kVec2f_GrSLType, "Conical2FSCenter"); 957 kVec2f_GrSLType, "Conical2FSCenter");
961 fParamUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, 958 fParamUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
962 kVec3f_GrSLType, "Conical2FSParams"); 959 kVec3f_GrSLType, "Conical2FSParams");
963 SkString tName("t"); 960 SkString tName("t");
964 961
965 GrGLShaderVar center = builder->getUniformVariable(fCenterUni); 962 GrGLShaderVar center = builder->getUniformVariable(fCenterUni);
966 // params.x = A 963 // params.x = A
967 // params.y = B 964 // params.y = B
968 // params.z = C 965 // params.z = C
969 GrGLShaderVar params = builder->getUniformVariable(fParamUni); 966 GrGLShaderVar params = builder->getUniformVariable(fParamUni);
970 967
971 // if we have a vec3 from being in perspective, convert it to a vec2 first 968 // if we have a vec3 from being in perspective, convert it to a vec2 first
972 SkString coords2DString = builder->ensureFSCoords2D(coords, 0); 969 SkString coords2DString = builder->ensureFSCoords2D(coords, 0);
973 const char* coords2D = coords2DString.c_str(); 970 const char* coords2D = coords2DString.c_str();
974 971
975 // p = coords2D 972 // p = coords2D
976 // e = center end 973 // e = center end
977 // r = radius end 974 // r = radius end
978 // A = dot(e, e) - r^2 + 2 * r - 1 975 // A = dot(e, e) - r^2 + 2 * r - 1
979 // B = (r -1) / A 976 // B = (r -1) / A
980 // C = 1 / A 977 // C = 1 / A
981 // d = dot(e, p) + B 978 // d = dot(e, p) + B
982 // t = d +/- sqrt(d^2 - A * dot(p, p) + C) 979 // t = d +/- sqrt(d^2 - A * dot(p, p) + C)
983 builder->fsCodeAppendf("\tfloat pDotp = dot(%s, %s);\n", coords2D, coords2D ); 980 builder->fsCodeAppendf("\tfloat pDotp = dot(%s, %s);\n", coords2D, coords2D );
984 builder->fsCodeAppendf("\tfloat d = dot(%s, %s) + %s.y;\n", coords2D, cente r.c_str(), params.c_str()); 981 builder->fsCodeAppendf("\tfloat d = dot(%s, %s) + %s.y;\n", coords2D, cente r.c_str(), params.c_str());
985 builder->fsCodeAppendf("\tfloat %s = d + sqrt(d * d - %s.x * pDotp + %s.z);\ n", 982 builder->fsCodeAppendf("\tfloat %s = d + sqrt(d * d - %s.x * pDotp + %s.z);\ n",
986 tName.c_str(), params.c_str(), params.c_str()); 983 tName.c_str(), params.c_str(), params.c_str());
987 984
988 this->emitColor(builder, tName.c_str(), key, outputColor, inputColor, sample rs); 985 this->emitColor(builder, tName.c_str(), baseKey, outputColor, inputColor, sa mplers);
989 } 986 }
990 987
991 void GLCircleInside2PtConicalEffect::setData(const GrGLUniformManager& uman, 988 void GLCircleInside2PtConicalEffect::setData(const GrGLUniformManager& uman,
992 const GrDrawEffect& drawEffect) { 989 const GrDrawEffect& drawEffect) {
993 INHERITED::setData(uman, drawEffect); 990 INHERITED::setData(uman, drawEffect);
994 const CircleInside2PtConicalEffect& data = drawEffect.castEffect<CircleInsid e2PtConicalEffect>(); 991 const CircleInside2PtConicalEffect& data = drawEffect.castEffect<CircleInsid e2PtConicalEffect>();
995 SkScalar centerX = data.centerX(); 992 SkScalar centerX = data.centerX();
996 SkScalar centerY = data.centerY(); 993 SkScalar centerY = data.centerY();
997 SkScalar A = data.A(); 994 SkScalar A = data.A();
998 SkScalar B = data.B(); 995 SkScalar B = data.B();
999 SkScalar C = data.C(); 996 SkScalar C = data.C();
1000 997
1001 if (fCachedCenterX != centerX || fCachedCenterY != centerY || 998 if (fCachedCenterX != centerX || fCachedCenterY != centerY ||
1002 fCachedA != A || fCachedB != B || fCachedC != C) { 999 fCachedA != A || fCachedB != B || fCachedC != C) {
1003 1000
1004 uman.set2f(fCenterUni, SkScalarToFloat(centerX), SkScalarToFloat(centerY )); 1001 uman.set2f(fCenterUni, SkScalarToFloat(centerX), SkScalarToFloat(centerY ));
1005 uman.set3f(fParamUni, SkScalarToFloat(A), SkScalarToFloat(B), SkScalarTo Float(C)); 1002 uman.set3f(fParamUni, SkScalarToFloat(A), SkScalarToFloat(B), SkScalarTo Float(C));
1006 1003
1007 fCachedCenterX = centerX; 1004 fCachedCenterX = centerX;
1008 fCachedCenterY = centerY; 1005 fCachedCenterY = centerY;
1009 fCachedA = A; 1006 fCachedA = A;
1010 fCachedB = B; 1007 fCachedB = B;
1011 fCachedC = C; 1008 fCachedC = C;
1012 } 1009 }
1013 } 1010 }
1014 1011
1015 GrGLEffect::EffectKey GLCircleInside2PtConicalEffect::GenKey(const GrDrawEffect& drawEffect, 1012 void GLCircleInside2PtConicalEffect::GenKey(const GrDrawEffect& drawEffect,
1016 const GrGLCaps&) { 1013 const GrGLCaps&, GrEffectKeyBuilder* b) {
1017 EffectKey key = GenBaseGradientKey(drawEffect); 1014 b->add32(GenBaseGradientKey(drawEffect));
1018 return key;
1019 } 1015 }
1020 1016
1021 ////////////////////////////////////////////////////////////////////////////// 1017 //////////////////////////////////////////////////////////////////////////////
1022 1018
1023 class GLCircleOutside2PtConicalEffect; 1019 class GLCircleOutside2PtConicalEffect;
1024 1020
1025 class CircleOutside2PtConicalEffect : public GrGradientEffect { 1021 class CircleOutside2PtConicalEffect : public GrGradientEffect {
1026 public: 1022 public:
1027 1023
1028 static GrEffect* Create(GrContext* ctx, 1024 static GrEffect* Create(GrContext* ctx,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 typedef GrGradientEffect INHERITED; 1080 typedef GrGradientEffect INHERITED;
1085 }; 1081 };
1086 1082
1087 class GLCircleOutside2PtConicalEffect : public GrGLGradientEffect { 1083 class GLCircleOutside2PtConicalEffect : public GrGLGradientEffect {
1088 public: 1084 public:
1089 GLCircleOutside2PtConicalEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&); 1085 GLCircleOutside2PtConicalEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&);
1090 virtual ~GLCircleOutside2PtConicalEffect() {} 1086 virtual ~GLCircleOutside2PtConicalEffect() {}
1091 1087
1092 virtual void emitCode(GrGLShaderBuilder*, 1088 virtual void emitCode(GrGLShaderBuilder*,
1093 const GrDrawEffect&, 1089 const GrDrawEffect&,
1094 EffectKey, 1090 const GrEffectKey&,
1095 const char* outputColor, 1091 const char* outputColor,
1096 const char* inputColor, 1092 const char* inputColor,
1097 const TransformedCoordsArray&, 1093 const TransformedCoordsArray&,
1098 const TextureSamplerArray&) SK_OVERRIDE; 1094 const TextureSamplerArray&) SK_OVERRIDE;
1099 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE; 1095 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE;
1100 1096
1101 static EffectKey GenKey(const GrDrawEffect&, const GrGLCaps& caps); 1097 static void GenKey(const GrDrawEffect&, const GrGLCaps& caps, GrEffectKeyBui lder* b);
1102 1098
1103 protected: 1099 protected:
1104 UniformHandle fCenterUni; 1100 UniformHandle fCenterUni;
1105 UniformHandle fParamUni; 1101 UniformHandle fParamUni;
1106 1102
1107 const char* fVSVaryingName; 1103 const char* fVSVaryingName;
1108 const char* fFSVaryingName; 1104 const char* fFSVaryingName;
1109 1105
1110 bool fIsFlipped; 1106 bool fIsFlipped;
1111 1107
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 , fCachedA(SK_ScalarMax) 1173 , fCachedA(SK_ScalarMax)
1178 , fCachedB(SK_ScalarMax) 1174 , fCachedB(SK_ScalarMax)
1179 , fCachedC(SK_ScalarMax) 1175 , fCachedC(SK_ScalarMax)
1180 , fCachedTLimit(SK_ScalarMax) { 1176 , fCachedTLimit(SK_ScalarMax) {
1181 const CircleOutside2PtConicalEffect& data = drawEffect.castEffect<CircleOuts ide2PtConicalEffect>(); 1177 const CircleOutside2PtConicalEffect& data = drawEffect.castEffect<CircleOuts ide2PtConicalEffect>();
1182 fIsFlipped = data.isFlipped(); 1178 fIsFlipped = data.isFlipped();
1183 } 1179 }
1184 1180
1185 void GLCircleOutside2PtConicalEffect::emitCode(GrGLShaderBuilder* builder, 1181 void GLCircleOutside2PtConicalEffect::emitCode(GrGLShaderBuilder* builder,
1186 const GrDrawEffect&, 1182 const GrDrawEffect&,
1187 EffectKey key, 1183 const GrEffectKey& key,
1188 const char* outputColor, 1184 const char* outputColor,
1189 const char* inputColor, 1185 const char* inputColor,
1190 const TransformedCoordsArray& coo rds, 1186 const TransformedCoordsArray& coo rds,
1191 const TextureSamplerArray& sample rs) { 1187 const TextureSamplerArray& sample rs) {
1192 this->emitUniforms(builder, key); 1188 uint32_t baseKey = key.get32(0);
1189 this->emitUniforms(builder, baseKey);
1193 fCenterUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, 1190 fCenterUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
1194 kVec2f_GrSLType, "Conical2FSCenter"); 1191 kVec2f_GrSLType, "Conical2FSCenter");
1195 fParamUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, 1192 fParamUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
1196 kVec4f_GrSLType, "Conical2FSParams"); 1193 kVec4f_GrSLType, "Conical2FSParams");
1197 SkString tName("t"); 1194 SkString tName("t");
1198 1195
1199 GrGLShaderVar center = builder->getUniformVariable(fCenterUni); 1196 GrGLShaderVar center = builder->getUniformVariable(fCenterUni);
1200 // params.x = A 1197 // params.x = A
1201 // params.y = B 1198 // params.y = B
1202 // params.z = C 1199 // params.z = C
(...skipping 23 matching lines...) Expand all
1226 // Must check to see if we flipped the circle order (to make sure start radi us < end radius) 1223 // Must check to see if we flipped the circle order (to make sure start radi us < end radius)
1227 // If so we must also flip sign on sqrt 1224 // If so we must also flip sign on sqrt
1228 if (!fIsFlipped) { 1225 if (!fIsFlipped) {
1229 builder->fsCodeAppendf("\tfloat %s = d + sqrt(deter);\n", tName.c_str()) ; 1226 builder->fsCodeAppendf("\tfloat %s = d + sqrt(deter);\n", tName.c_str()) ;
1230 } else { 1227 } else {
1231 builder->fsCodeAppendf("\tfloat %s = d - sqrt(deter);\n", tName.c_str()) ; 1228 builder->fsCodeAppendf("\tfloat %s = d - sqrt(deter);\n", tName.c_str()) ;
1232 } 1229 }
1233 1230
1234 builder->fsCodeAppendf("\tif (%s >= %s.w && deter >= 0.0) {\n", tName.c_str( ), params.c_str()); 1231 builder->fsCodeAppendf("\tif (%s >= %s.w && deter >= 0.0) {\n", tName.c_str( ), params.c_str());
1235 builder->fsCodeAppend("\t\t"); 1232 builder->fsCodeAppend("\t\t");
1236 this->emitColor(builder, tName.c_str(), key, outputColor, inputColor, sample rs); 1233 this->emitColor(builder, tName.c_str(), baseKey, outputColor, inputColor, sa mplers);
1237 builder->fsCodeAppend("\t}\n"); 1234 builder->fsCodeAppend("\t}\n");
1238 } 1235 }
1239 1236
1240 void GLCircleOutside2PtConicalEffect::setData(const GrGLUniformManager& uman, 1237 void GLCircleOutside2PtConicalEffect::setData(const GrGLUniformManager& uman,
1241 const GrDrawEffect& drawEffect) { 1238 const GrDrawEffect& drawEffect) {
1242 INHERITED::setData(uman, drawEffect); 1239 INHERITED::setData(uman, drawEffect);
1243 const CircleOutside2PtConicalEffect& data = drawEffect.castEffect<CircleOuts ide2PtConicalEffect>(); 1240 const CircleOutside2PtConicalEffect& data = drawEffect.castEffect<CircleOuts ide2PtConicalEffect>();
1244 SkASSERT(data.isFlipped() == fIsFlipped); 1241 SkASSERT(data.isFlipped() == fIsFlipped);
1245 SkScalar centerX = data.centerX(); 1242 SkScalar centerX = data.centerX();
1246 SkScalar centerY = data.centerY(); 1243 SkScalar centerY = data.centerY();
(...skipping 11 matching lines...) Expand all
1258 1255
1259 fCachedCenterX = centerX; 1256 fCachedCenterX = centerX;
1260 fCachedCenterY = centerY; 1257 fCachedCenterY = centerY;
1261 fCachedA = A; 1258 fCachedA = A;
1262 fCachedB = B; 1259 fCachedB = B;
1263 fCachedC = C; 1260 fCachedC = C;
1264 fCachedTLimit = tLimit; 1261 fCachedTLimit = tLimit;
1265 } 1262 }
1266 } 1263 }
1267 1264
1268 GrGLEffect::EffectKey GLCircleOutside2PtConicalEffect::GenKey(const GrDrawEffect & drawEffect, 1265 void GLCircleOutside2PtConicalEffect::GenKey(const GrDrawEffect& drawEffect,
1269 const GrGLCaps&) { 1266 const GrGLCaps&, GrEffectKeyBuilder * b) {
1270 enum { 1267 uint32_t* key = b->add32n(2);
1271 kIsFlipped = 1 << kBaseKeyBitCnt, 1268 key[0] = GenBaseGradientKey(drawEffect);
1272 }; 1269 key[1] = drawEffect.castEffect<CircleOutside2PtConicalEffect>().isFlipped();
1273
1274 EffectKey key = GenBaseGradientKey(drawEffect);
1275
1276 if (drawEffect.castEffect<CircleOutside2PtConicalEffect>().isFlipped()) {
1277 key |= kIsFlipped;
1278 }
1279 return key;
1280 } 1270 }
1281 1271
1282 ////////////////////////////////////////////////////////////////////////////// 1272 //////////////////////////////////////////////////////////////////////////////
1283 1273
1284 GrEffect* Gr2PtConicalGradientEffect::Create(GrContext* ctx, 1274 GrEffect* Gr2PtConicalGradientEffect::Create(GrContext* ctx,
1285 const SkTwoPointConicalGradient& sh ader, 1275 const SkTwoPointConicalGradient& sh ader,
1286 SkShader::TileMode tm, 1276 SkShader::TileMode tm,
1287 const SkMatrix* localMatrix) { 1277 const SkMatrix* localMatrix) {
1288 SkMatrix matrix; 1278 SkMatrix matrix;
1289 if (!shader.getLocalMatrix().invert(&matrix)) { 1279 if (!shader.getLocalMatrix().invert(&matrix)) {
(...skipping 27 matching lines...) Expand all
1317 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf o); 1307 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf o);
1318 } else if (type == kEdge_ConicalType) { 1308 } else if (type == kEdge_ConicalType) {
1319 set_matrix_edge_conical(shader, &matrix); 1309 set_matrix_edge_conical(shader, &matrix);
1320 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); 1310 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm);
1321 } else { 1311 } else {
1322 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in fo); 1312 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in fo);
1323 } 1313 }
1324 } 1314 }
1325 1315
1326 #endif 1316 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkSweepGradient.cpp ('k') | src/effects/gradients/SkTwoPointRadialGradient.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698