OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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.h" | 9 #include "SkTwoPointConicalGradient.h" |
10 | 10 |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 329 |
330 #include "GrTBackendEffectFactory.h" | 330 #include "GrTBackendEffectFactory.h" |
331 | 331 |
332 // For brevity | 332 // For brevity |
333 typedef GrGLUniformManager::UniformHandle UniformHandle; | 333 typedef GrGLUniformManager::UniformHandle UniformHandle; |
334 static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidU
niformHandle; | 334 static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidU
niformHandle; |
335 | 335 |
336 class GrGLConical2Gradient : public GrGLGradientEffect { | 336 class GrGLConical2Gradient : public GrGLGradientEffect { |
337 public: | 337 public: |
338 | 338 |
339 GrGLConical2Gradient(const GrBackendEffectFactory& factory, | 339 GrGLConical2Gradient(const GrBackendEffectFactory& factory, const GrDrawEffe
ct&); |
340 const GrEffectRef&); | |
341 virtual ~GrGLConical2Gradient() { } | 340 virtual ~GrGLConical2Gradient() { } |
342 | 341 |
343 virtual void emitCode(GrGLShaderBuilder*, | 342 virtual void emitCode(GrGLShaderBuilder*, |
344 const GrEffectStage&, | 343 const GrDrawEffect&, |
345 EffectKey, | 344 EffectKey, |
346 const char* vertexCoords, | |
347 const char* outputColor, | 345 const char* outputColor, |
348 const char* inputColor, | 346 const char* inputColor, |
349 const TextureSamplerArray&) SK_OVERRIDE; | 347 const TextureSamplerArray&) SK_OVERRIDE; |
350 virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVE
RRIDE; | 348 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; |
351 | 349 |
352 static EffectKey GenKey(const GrEffectStage&, const GrGLCaps& caps); | 350 static EffectKey GenKey(const GrDrawEffect&, const GrGLCaps& caps); |
353 | 351 |
354 protected: | 352 protected: |
355 | 353 |
356 UniformHandle fVSParamUni; | 354 UniformHandle fVSParamUni; |
357 UniformHandle fFSParamUni; | 355 UniformHandle fFSParamUni; |
358 | 356 |
359 const char* fVSVaryingName; | 357 const char* fVSVaryingName; |
360 const char* fFSVaryingName; | 358 const char* fFSVaryingName; |
361 | 359 |
362 bool fIsDegenerate; | 360 bool fIsDegenerate; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 colors
, stops, colorCount, | 460 colors
, stops, colorCount, |
463 tm)); | 461 tm)); |
464 SkPaint paint; | 462 SkPaint paint; |
465 return shader->asNewEffect(context, paint); | 463 return shader->asNewEffect(context, paint); |
466 } | 464 } |
467 | 465 |
468 | 466 |
469 ///////////////////////////////////////////////////////////////////// | 467 ///////////////////////////////////////////////////////////////////// |
470 | 468 |
471 GrGLConical2Gradient::GrGLConical2Gradient(const GrBackendEffectFactory& factory
, | 469 GrGLConical2Gradient::GrGLConical2Gradient(const GrBackendEffectFactory& factory
, |
472 const GrEffectRef& baseData) | 470 const GrDrawEffect& drawEffect) |
473 : INHERITED(factory) | 471 : INHERITED(factory) |
474 , fVSParamUni(kInvalidUniformHandle) | 472 , fVSParamUni(kInvalidUniformHandle) |
475 , fFSParamUni(kInvalidUniformHandle) | 473 , fFSParamUni(kInvalidUniformHandle) |
476 , fVSVaryingName(NULL) | 474 , fVSVaryingName(NULL) |
477 , fFSVaryingName(NULL) | 475 , fFSVaryingName(NULL) |
478 , fCachedCenter(SK_ScalarMax) | 476 , fCachedCenter(SK_ScalarMax) |
479 , fCachedRadius(-SK_ScalarMax) | 477 , fCachedRadius(-SK_ScalarMax) |
480 , fCachedDiffRadius(-SK_ScalarMax) { | 478 , fCachedDiffRadius(-SK_ScalarMax) { |
481 | 479 |
482 const GrConical2Gradient& data = CastEffect<GrConical2Gradient>(baseData); | 480 const GrConical2Gradient& data = drawEffect.castEffect<GrConical2Gradient>()
; |
483 fIsDegenerate = data.isDegenerate(); | 481 fIsDegenerate = data.isDegenerate(); |
484 } | 482 } |
485 | 483 |
486 void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder, | 484 void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder, |
487 const GrEffectStage&, | 485 const GrDrawEffect&, |
488 EffectKey key, | 486 EffectKey key, |
489 const char* vertexCoords, | |
490 const char* outputColor, | 487 const char* outputColor, |
491 const char* inputColor, | 488 const char* inputColor, |
492 const TextureSamplerArray& samplers) { | 489 const TextureSamplerArray& samplers) { |
493 const char* fsCoords; | 490 const char* fsCoords; |
494 const char* vsCoordsVarying; | 491 const char* vsCoordsVarying; |
495 GrSLType coordsVaryingType; | 492 GrSLType coordsVaryingType; |
496 this->setupMatrix(builder, key, vertexCoords, &fsCoords, &vsCoordsVarying, &
coordsVaryingType); | 493 this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingT
ype); |
497 | 494 |
498 this->emitYCoordUniform(builder); | 495 this->emitYCoordUniform(builder); |
499 // 2 copies of uniform array, 1 for each of vertex & fragment shader, | 496 // 2 copies of uniform array, 1 for each of vertex & fragment shader, |
500 // to work around Xoom bug. Doesn't seem to cause performance decrease | 497 // to work around Xoom bug. Doesn't seem to cause performance decrease |
501 // in test apps, but need to keep an eye on it. | 498 // in test apps, but need to keep an eye on it. |
502 fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_ShaderType
, | 499 fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_ShaderType
, |
503 kFloat_GrSLType, "Conical2VSParams",
6); | 500 kFloat_GrSLType, "Conical2VSParams",
6); |
504 fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderTy
pe, | 501 fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderTy
pe, |
505 kFloat_GrSLType, "Conical2FSParams",
6); | 502 kFloat_GrSLType, "Conical2FSParams",
6); |
506 | 503 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 // if r(t) > 0, then t will be the x coordinate | 641 // if r(t) > 0, then t will be the x coordinate |
645 builder->fsCodeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(
), | 642 builder->fsCodeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(
), |
646 p5.c_str(), p3.c_str()); | 643 p5.c_str(), p3.c_str()); |
647 builder->fsCodeAppend("\t"); | 644 builder->fsCodeAppend("\t"); |
648 this->emitColorLookup(builder, tName.c_str(), outputColor, inputColo
r, samplers[0]); | 645 this->emitColorLookup(builder, tName.c_str(), outputColor, inputColo
r, samplers[0]); |
649 builder->fsCodeAppend("\t}\n"); | 646 builder->fsCodeAppend("\t}\n"); |
650 } | 647 } |
651 } | 648 } |
652 } | 649 } |
653 | 650 |
654 void GrGLConical2Gradient::setData(const GrGLUniformManager& uman, const GrEffec
tStage& stage) { | 651 void GrGLConical2Gradient::setData(const GrGLUniformManager& uman, |
655 INHERITED::setData(uman, stage); | 652 const GrDrawEffect& drawEffect) { |
656 const GrConical2Gradient& data = GetEffectFromStage<GrConical2Gradient>(stag
e); | 653 INHERITED::setData(uman, drawEffect); |
| 654 const GrConical2Gradient& data = drawEffect.castEffect<GrConical2Gradient>()
; |
657 GrAssert(data.isDegenerate() == fIsDegenerate); | 655 GrAssert(data.isDegenerate() == fIsDegenerate); |
658 SkScalar centerX1 = data.center(); | 656 SkScalar centerX1 = data.center(); |
659 SkScalar radius0 = data.radius(); | 657 SkScalar radius0 = data.radius(); |
660 SkScalar diffRadius = data.diffRadius(); | 658 SkScalar diffRadius = data.diffRadius(); |
661 | 659 |
662 if (fCachedCenter != centerX1 || | 660 if (fCachedCenter != centerX1 || |
663 fCachedRadius != radius0 || | 661 fCachedRadius != radius0 || |
664 fCachedDiffRadius != diffRadius) { | 662 fCachedDiffRadius != diffRadius) { |
665 | 663 |
666 SkScalar a = SkScalarMul(centerX1, centerX1) - diffRadius * diffRadius; | 664 SkScalar a = SkScalarMul(centerX1, centerX1) - diffRadius * diffRadius; |
(...skipping 13 matching lines...) Expand all Loading... |
680 }; | 678 }; |
681 | 679 |
682 uman.set1fv(fVSParamUni, 0, 6, values); | 680 uman.set1fv(fVSParamUni, 0, 6, values); |
683 uman.set1fv(fFSParamUni, 0, 6, values); | 681 uman.set1fv(fFSParamUni, 0, 6, values); |
684 fCachedCenter = centerX1; | 682 fCachedCenter = centerX1; |
685 fCachedRadius = radius0; | 683 fCachedRadius = radius0; |
686 fCachedDiffRadius = diffRadius; | 684 fCachedDiffRadius = diffRadius; |
687 } | 685 } |
688 } | 686 } |
689 | 687 |
690 GrGLEffect::EffectKey GrGLConical2Gradient::GenKey(const GrEffectStage& s, const
GrGLCaps&) { | 688 GrGLEffect::EffectKey GrGLConical2Gradient::GenKey(const GrDrawEffect& drawEffec
t, |
| 689 const GrGLCaps&) { |
691 enum { | 690 enum { |
692 kIsDegenerate = 1 << kMatrixKeyBitCnt, | 691 kIsDegenerate = 1 << kMatrixKeyBitCnt, |
693 }; | 692 }; |
694 | 693 |
695 EffectKey key = GenMatrixKey(s); | 694 EffectKey key = GenMatrixKey(drawEffect); |
696 if (GetEffectFromStage<GrConical2Gradient>(s).isDegenerate()) { | 695 if (drawEffect.castEffect<GrConical2Gradient>().isDegenerate()) { |
697 key |= kIsDegenerate; | 696 key |= kIsDegenerate; |
698 } | 697 } |
699 return key; | 698 return key; |
700 } | 699 } |
701 | 700 |
702 ///////////////////////////////////////////////////////////////////// | 701 ///////////////////////////////////////////////////////////////////// |
703 | 702 |
704 GrEffectRef* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const Sk
Paint&) const { | 703 GrEffectRef* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const Sk
Paint&) const { |
705 SkASSERT(NULL != context); | 704 SkASSERT(NULL != context); |
706 SkASSERT(fPtsToUnit.isIdentity()); | 705 SkASSERT(fPtsToUnit.isIdentity()); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 str->appendScalar(fCenter2.fY); | 750 str->appendScalar(fCenter2.fY); |
752 str->append(") radius2: "); | 751 str->append(") radius2: "); |
753 str->appendScalar(fRadius2); | 752 str->appendScalar(fRadius2); |
754 str->append(" "); | 753 str->append(" "); |
755 | 754 |
756 this->INHERITED::toString(str); | 755 this->INHERITED::toString(str); |
757 | 756 |
758 str->append(")"); | 757 str->append(")"); |
759 } | 758 } |
760 #endif | 759 #endif |
OLD | NEW |