| OLD | NEW |
| 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 "SkTwoPointConicalGradient_gpu.h" | |
| 9 | 8 |
| 10 #include "SkTwoPointConicalGradient.h" | 9 #include "SkTwoPointConicalGradient.h" |
| 11 | 10 |
| 12 #if SK_SUPPORT_GPU | 11 #if SK_SUPPORT_GPU |
| 13 #include "GrCoordTransform.h" | 12 #include "GrCoordTransform.h" |
| 14 #include "GrInvariantOutput.h" | 13 #include "GrInvariantOutput.h" |
| 15 #include "GrPaint.h" | 14 #include "GrPaint.h" |
| 16 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 15 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 17 #include "glsl/GrGLSLProgramDataManager.h" | 16 #include "glsl/GrGLSLProgramDataManager.h" |
| 18 #include "glsl/GrGLSLUniformHandler.h" | 17 #include "glsl/GrGLSLUniformHandler.h" |
| 18 #include "SkTwoPointConicalGradient_gpu.h" |
| 19 |
| 19 // For brevity | 20 // For brevity |
| 20 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | 21 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
| 21 | 22 |
| 22 static const SkScalar kErrorTol = 0.00001f; | 23 static const SkScalar kErrorTol = 0.00001f; |
| 23 static const SkScalar kEdgeErrorTol = 5.f * kErrorTol; | 24 static const SkScalar kEdgeErrorTol = 5.f * kErrorTol; |
| 24 | 25 |
| 25 /** | 26 /** |
| 26 * We have three general cases for 2pt conical gradients. First we always assume
that | 27 * We have three general cases for 2pt conical gradients. First we always assume
that |
| 27 * the start radius <= end radius. Our first case (kInside_) is when the start c
ircle | 28 * the start radius <= end radius. Our first case (kInside_) is when the start c
ircle |
| 28 * is completely enclosed by the end circle. The second case (kOutside_) is the
case | 29 * is completely enclosed by the end circle. The second case (kOutside_) is the
case |
| (...skipping 26 matching lines...) Expand all Loading... |
| 55 rot.setSinCos(-SkScalarMul(invDiffLen, diff.fY), | 56 rot.setSinCos(-SkScalarMul(invDiffLen, diff.fY), |
| 56 SkScalarMul(invDiffLen, diff.fX)); | 57 SkScalarMul(invDiffLen, diff.fX)); |
| 57 invLMatrix->postConcat(rot); | 58 invLMatrix->postConcat(rot); |
| 58 } | 59 } |
| 59 } | 60 } |
| 60 | 61 |
| 61 class Edge2PtConicalEffect : public GrGradientEffect { | 62 class Edge2PtConicalEffect : public GrGradientEffect { |
| 62 public: | 63 public: |
| 63 class GLSLEdge2PtConicalProcessor; | 64 class GLSLEdge2PtConicalProcessor; |
| 64 | 65 |
| 65 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx, | 66 static sk_sp<GrFragmentProcessor> Make(const CreateArgs& args) { |
| 66 const SkTwoPointConicalGradient& shad
er, | 67 return sk_sp<GrFragmentProcessor>(new Edge2PtConicalEffect(args)); |
| 67 const SkMatrix& matrix, | |
| 68 SkShader::TileMode tm) { | |
| 69 return sk_sp<GrFragmentProcessor>(new Edge2PtConicalEffect(ctx, shader,
matrix, tm)); | |
| 70 } | 68 } |
| 71 | 69 |
| 72 virtual ~Edge2PtConicalEffect() {} | 70 virtual ~Edge2PtConicalEffect() {} |
| 73 | 71 |
| 74 const char* name() const override { | 72 const char* name() const override { |
| 75 return "Two-Point Conical Gradient Edge Touching"; | 73 return "Two-Point Conical Gradient Edge Touching"; |
| 76 } | 74 } |
| 77 | 75 |
| 78 // The radial gradient parameters can collapse to a linear (instead of quadr
atic) equation. | 76 // The radial gradient parameters can collapse to a linear (instead of quadr
atic) equation. |
| 79 SkScalar center() const { return fCenterX1; } | 77 SkScalar center() const { return fCenterX1; } |
| 80 SkScalar diffRadius() const { return fDiffRadius; } | 78 SkScalar diffRadius() const { return fDiffRadius; } |
| 81 SkScalar radius() const { return fRadius0; } | 79 SkScalar radius() const { return fRadius0; } |
| 82 | 80 |
| 83 private: | 81 private: |
| 84 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; | 82 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 85 | 83 |
| 86 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const
override; | 84 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const
override; |
| 87 | 85 |
| 88 bool onIsEqual(const GrFragmentProcessor& sBase) const override { | 86 bool onIsEqual(const GrFragmentProcessor& sBase) const override { |
| 89 const Edge2PtConicalEffect& s = sBase.cast<Edge2PtConicalEffect>(); | 87 const Edge2PtConicalEffect& s = sBase.cast<Edge2PtConicalEffect>(); |
| 90 return (INHERITED::onIsEqual(sBase) && | 88 return (INHERITED::onIsEqual(sBase) && |
| 91 this->fCenterX1 == s.fCenterX1 && | 89 this->fCenterX1 == s.fCenterX1 && |
| 92 this->fRadius0 == s.fRadius0 && | 90 this->fRadius0 == s.fRadius0 && |
| 93 this->fDiffRadius == s.fDiffRadius); | 91 this->fDiffRadius == s.fDiffRadius); |
| 94 } | 92 } |
| 95 | 93 |
| 96 Edge2PtConicalEffect(GrContext* ctx, | 94 Edge2PtConicalEffect(const CreateArgs& args) |
| 97 const SkTwoPointConicalGradient& shader, | 95 : INHERITED(args) { |
| 98 const SkMatrix& matrix, | 96 const SkTwoPointConicalGradient& shader = |
| 99 SkShader::TileMode tm) | 97 *static_cast<const SkTwoPointConicalGradient*>(args.fShader); |
| 100 : INHERITED(ctx, shader, matrix, tm), | 98 fCenterX1 = shader.getCenterX1(); |
| 101 fCenterX1(shader.getCenterX1()), | 99 fRadius0 = shader.getStartRadius(); |
| 102 fRadius0(shader.getStartRadius()), | 100 fDiffRadius = shader.getDiffRadius(); |
| 103 fDiffRadius(shader.getDiffRadius()){ | |
| 104 this->initClassID<Edge2PtConicalEffect>(); | 101 this->initClassID<Edge2PtConicalEffect>(); |
| 105 // We should only be calling this shader if we are degenerate case with
touching circles | 102 // We should only be calling this shader if we are degenerate case with
touching circles |
| 106 // When deciding if we are in edge case, we scaled by the end radius for
cases when the | 103 // When deciding if we are in edge case, we scaled by the end radius for
cases when the |
| 107 // start radius was close to zero, otherwise we scaled by the start radi
us. In addition | 104 // start radius was close to zero, otherwise we scaled by the start radi
us. In addition |
| 108 // Our test for the edge case in set_matrix_circle_conical has a higher
tolerance so we | 105 // Our test for the edge case in set_matrix_circle_conical has a higher
tolerance so we |
| 109 // need the sqrt value below | 106 // need the sqrt value below |
| 110 SkASSERT(SkScalarAbs(SkScalarAbs(fDiffRadius) - fCenterX1) < | 107 SkASSERT(SkScalarAbs(SkScalarAbs(fDiffRadius) - fCenterX1) < |
| 111 (fRadius0 < kErrorTol ? shader.getEndRadius() * kEdgeErrorTol : | 108 (fRadius0 < kErrorTol ? shader.getEndRadius() * kEdgeErrorTol : |
| 112 fRadius0 * sqrt(kEdgeErrorTol))); | 109 fRadius0 * sqrt(kEdgeErrorTol))); |
| 113 | 110 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 | 366 |
| 370 return conicalType; | 367 return conicalType; |
| 371 } | 368 } |
| 372 | 369 |
| 373 ////////////////////////////////////////////////////////////////////////////// | 370 ////////////////////////////////////////////////////////////////////////////// |
| 374 | 371 |
| 375 class FocalOutside2PtConicalEffect : public GrGradientEffect { | 372 class FocalOutside2PtConicalEffect : public GrGradientEffect { |
| 376 public: | 373 public: |
| 377 class GLSLFocalOutside2PtConicalProcessor; | 374 class GLSLFocalOutside2PtConicalProcessor; |
| 378 | 375 |
| 379 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx, | 376 static sk_sp<GrFragmentProcessor> Make(const CreateArgs& args, SkScalar foca
lX) { |
| 380 const SkTwoPointConicalGradient& shad
er, | |
| 381 const SkMatrix& matrix, | |
| 382 SkShader::TileMode tm, | |
| 383 SkScalar focalX) { | |
| 384 return sk_sp<GrFragmentProcessor>( | 377 return sk_sp<GrFragmentProcessor>( |
| 385 new FocalOutside2PtConicalEffect(ctx, shader, matrix, tm, focalX)); | 378 new FocalOutside2PtConicalEffect(args, focalX)); |
| 386 } | 379 } |
| 387 | 380 |
| 388 virtual ~FocalOutside2PtConicalEffect() { } | 381 virtual ~FocalOutside2PtConicalEffect() { } |
| 389 | 382 |
| 390 const char* name() const override { | 383 const char* name() const override { |
| 391 return "Two-Point Conical Gradient Focal Outside"; | 384 return "Two-Point Conical Gradient Focal Outside"; |
| 392 } | 385 } |
| 393 | 386 |
| 394 bool isFlipped() const { return fIsFlipped; } | 387 bool isFlipped() const { return fIsFlipped; } |
| 395 SkScalar focal() const { return fFocalX; } | 388 SkScalar focal() const { return fFocalX; } |
| 396 | 389 |
| 397 private: | 390 private: |
| 398 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; | 391 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 399 | 392 |
| 400 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const
override; | 393 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const
override; |
| 401 | 394 |
| 402 bool onIsEqual(const GrFragmentProcessor& sBase) const override { | 395 bool onIsEqual(const GrFragmentProcessor& sBase) const override { |
| 403 const FocalOutside2PtConicalEffect& s = sBase.cast<FocalOutside2PtConica
lEffect>(); | 396 const FocalOutside2PtConicalEffect& s = sBase.cast<FocalOutside2PtConica
lEffect>(); |
| 404 return (INHERITED::onIsEqual(sBase) && | 397 return (INHERITED::onIsEqual(sBase) && |
| 405 this->fFocalX == s.fFocalX && | 398 this->fFocalX == s.fFocalX && |
| 406 this->fIsFlipped == s.fIsFlipped); | 399 this->fIsFlipped == s.fIsFlipped); |
| 407 } | 400 } |
| 408 | 401 |
| 409 FocalOutside2PtConicalEffect(GrContext* ctx, | 402 FocalOutside2PtConicalEffect(const CreateArgs& args, SkScalar focalX) |
| 410 const SkTwoPointConicalGradient& shader, | 403 : INHERITED(args) |
| 411 const SkMatrix& matrix, | |
| 412 SkShader::TileMode tm, | |
| 413 SkScalar focalX) | |
| 414 : INHERITED(ctx, shader, matrix, tm) | |
| 415 , fFocalX(focalX) | 404 , fFocalX(focalX) |
| 416 , fIsFlipped(shader.isFlippedGrad()) { | 405 , fIsFlipped(static_cast<const SkTwoPointConicalGradient*>(args.fShader)->is
FlippedGrad()) { |
| 417 this->initClassID<FocalOutside2PtConicalEffect>(); | 406 this->initClassID<FocalOutside2PtConicalEffect>(); |
| 418 } | 407 } |
| 419 | 408 |
| 420 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 409 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 421 | 410 |
| 422 SkScalar fFocalX; | 411 SkScalar fFocalX; |
| 423 bool fIsFlipped; | 412 bool fIsFlipped; |
| 424 | 413 |
| 425 typedef GrGradientEffect INHERITED; | 414 typedef GrGradientEffect INHERITED; |
| 426 }; | 415 }; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 key[0] = GenBaseGradientKey(processor); | 573 key[0] = GenBaseGradientKey(processor); |
| 585 key[1] = processor.cast<FocalOutside2PtConicalEffect>().isFlipped(); | 574 key[1] = processor.cast<FocalOutside2PtConicalEffect>().isFlipped(); |
| 586 } | 575 } |
| 587 | 576 |
| 588 ////////////////////////////////////////////////////////////////////////////// | 577 ////////////////////////////////////////////////////////////////////////////// |
| 589 | 578 |
| 590 class FocalInside2PtConicalEffect : public GrGradientEffect { | 579 class FocalInside2PtConicalEffect : public GrGradientEffect { |
| 591 public: | 580 public: |
| 592 class GLSLFocalInside2PtConicalProcessor; | 581 class GLSLFocalInside2PtConicalProcessor; |
| 593 | 582 |
| 594 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx, | 583 static sk_sp<GrFragmentProcessor> Make(const CreateArgs& args, SkScalar foca
lX) { |
| 595 const SkTwoPointConicalGradient& shad
er, | |
| 596 const SkMatrix& matrix, | |
| 597 SkShader::TileMode tm, | |
| 598 SkScalar focalX) { | |
| 599 return sk_sp<GrFragmentProcessor>( | 584 return sk_sp<GrFragmentProcessor>( |
| 600 new FocalInside2PtConicalEffect(ctx, shader, matrix, tm, focalX)); | 585 new FocalInside2PtConicalEffect(args, focalX)); |
| 601 } | 586 } |
| 602 | 587 |
| 603 virtual ~FocalInside2PtConicalEffect() {} | 588 virtual ~FocalInside2PtConicalEffect() {} |
| 604 | 589 |
| 605 const char* name() const override { | 590 const char* name() const override { |
| 606 return "Two-Point Conical Gradient Focal Inside"; | 591 return "Two-Point Conical Gradient Focal Inside"; |
| 607 } | 592 } |
| 608 | 593 |
| 609 SkScalar focal() const { return fFocalX; } | 594 SkScalar focal() const { return fFocalX; } |
| 610 | 595 |
| 611 typedef FocalInside2PtConicalEffect::GLSLFocalInside2PtConicalProcessor GLSL
Processor; | 596 typedef FocalInside2PtConicalEffect::GLSLFocalInside2PtConicalProcessor GLSL
Processor; |
| 612 | 597 |
| 613 private: | 598 private: |
| 614 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; | 599 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 615 | 600 |
| 616 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const
override; | 601 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const
override; |
| 617 | 602 |
| 618 bool onIsEqual(const GrFragmentProcessor& sBase) const override { | 603 bool onIsEqual(const GrFragmentProcessor& sBase) const override { |
| 619 const FocalInside2PtConicalEffect& s = sBase.cast<FocalInside2PtConicalE
ffect>(); | 604 const FocalInside2PtConicalEffect& s = sBase.cast<FocalInside2PtConicalE
ffect>(); |
| 620 return (INHERITED::onIsEqual(sBase) && | 605 return (INHERITED::onIsEqual(sBase) && |
| 621 this->fFocalX == s.fFocalX); | 606 this->fFocalX == s.fFocalX); |
| 622 } | 607 } |
| 623 | 608 |
| 624 FocalInside2PtConicalEffect(GrContext* ctx, | 609 FocalInside2PtConicalEffect(const CreateArgs& args, SkScalar focalX) |
| 625 const SkTwoPointConicalGradient& shader, | 610 : INHERITED(args), fFocalX(focalX) { |
| 626 const SkMatrix& matrix, | |
| 627 SkShader::TileMode tm, | |
| 628 SkScalar focalX) | |
| 629 : INHERITED(ctx, shader, matrix, tm), fFocalX(focalX) { | |
| 630 this->initClassID<FocalInside2PtConicalEffect>(); | 611 this->initClassID<FocalInside2PtConicalEffect>(); |
| 631 } | 612 } |
| 632 | 613 |
| 633 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 614 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 634 | 615 |
| 635 SkScalar fFocalX; | 616 SkScalar fFocalX; |
| 636 | 617 |
| 637 typedef GrGradientEffect INHERITED; | 618 typedef GrGradientEffect INHERITED; |
| 638 }; | 619 }; |
| 639 | 620 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 if (A < 0.f) { | 811 if (A < 0.f) { |
| 831 return kInside_ConicalType; | 812 return kInside_ConicalType; |
| 832 } | 813 } |
| 833 return kOutside_ConicalType; | 814 return kOutside_ConicalType; |
| 834 } | 815 } |
| 835 | 816 |
| 836 class CircleInside2PtConicalEffect : public GrGradientEffect { | 817 class CircleInside2PtConicalEffect : public GrGradientEffect { |
| 837 public: | 818 public: |
| 838 class GLSLCircleInside2PtConicalProcessor; | 819 class GLSLCircleInside2PtConicalProcessor; |
| 839 | 820 |
| 840 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx, | 821 static sk_sp<GrFragmentProcessor> Make(const CreateArgs& args, const CircleC
onicalInfo& info) { |
| 841 const SkTwoPointConicalGradient& shad
er, | |
| 842 const SkMatrix& matrix, | |
| 843 SkShader::TileMode tm, | |
| 844 const CircleConicalInfo& info) { | |
| 845 return sk_sp<GrFragmentProcessor>( | 822 return sk_sp<GrFragmentProcessor>( |
| 846 new CircleInside2PtConicalEffect(ctx, shader, matrix, tm, info)); | 823 new CircleInside2PtConicalEffect(args, info)); |
| 847 } | 824 } |
| 848 | 825 |
| 849 virtual ~CircleInside2PtConicalEffect() {} | 826 virtual ~CircleInside2PtConicalEffect() {} |
| 850 | 827 |
| 851 const char* name() const override { return "Two-Point Conical Gradient Insid
e"; } | 828 const char* name() const override { return "Two-Point Conical Gradient Insid
e"; } |
| 852 | 829 |
| 853 SkScalar centerX() const { return fInfo.fCenterEnd.fX; } | 830 SkScalar centerX() const { return fInfo.fCenterEnd.fX; } |
| 854 SkScalar centerY() const { return fInfo.fCenterEnd.fY; } | 831 SkScalar centerY() const { return fInfo.fCenterEnd.fY; } |
| 855 SkScalar A() const { return fInfo.fA; } | 832 SkScalar A() const { return fInfo.fA; } |
| 856 SkScalar B() const { return fInfo.fB; } | 833 SkScalar B() const { return fInfo.fB; } |
| 857 SkScalar C() const { return fInfo.fC; } | 834 SkScalar C() const { return fInfo.fC; } |
| 858 | 835 |
| 859 private: | 836 private: |
| 860 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; | 837 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 861 | 838 |
| 862 virtual void onGetGLSLProcessorKey(const GrGLSLCaps& caps, | 839 virtual void onGetGLSLProcessorKey(const GrGLSLCaps& caps, |
| 863 GrProcessorKeyBuilder* b) const override; | 840 GrProcessorKeyBuilder* b) const override; |
| 864 | 841 |
| 865 bool onIsEqual(const GrFragmentProcessor& sBase) const override { | 842 bool onIsEqual(const GrFragmentProcessor& sBase) const override { |
| 866 const CircleInside2PtConicalEffect& s = sBase.cast<CircleInside2PtConica
lEffect>(); | 843 const CircleInside2PtConicalEffect& s = sBase.cast<CircleInside2PtConica
lEffect>(); |
| 867 return (INHERITED::onIsEqual(sBase) && | 844 return (INHERITED::onIsEqual(sBase) && |
| 868 this->fInfo.fCenterEnd == s.fInfo.fCenterEnd && | 845 this->fInfo.fCenterEnd == s.fInfo.fCenterEnd && |
| 869 this->fInfo.fA == s.fInfo.fA && | 846 this->fInfo.fA == s.fInfo.fA && |
| 870 this->fInfo.fB == s.fInfo.fB && | 847 this->fInfo.fB == s.fInfo.fB && |
| 871 this->fInfo.fC == s.fInfo.fC); | 848 this->fInfo.fC == s.fInfo.fC); |
| 872 } | 849 } |
| 873 | 850 |
| 874 CircleInside2PtConicalEffect(GrContext* ctx, | 851 CircleInside2PtConicalEffect(const CreateArgs& args, const CircleConicalInfo
& info) |
| 875 const SkTwoPointConicalGradient& shader, | 852 : INHERITED(args), fInfo(info) { |
| 876 const SkMatrix& matrix, | |
| 877 SkShader::TileMode tm, | |
| 878 const CircleConicalInfo& info) | |
| 879 : INHERITED(ctx, shader, matrix, tm), fInfo(info) { | |
| 880 this->initClassID<CircleInside2PtConicalEffect>(); | 853 this->initClassID<CircleInside2PtConicalEffect>(); |
| 881 } | 854 } |
| 882 | 855 |
| 883 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 856 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 884 | 857 |
| 885 const CircleConicalInfo fInfo; | 858 const CircleConicalInfo fInfo; |
| 886 | 859 |
| 887 typedef GrGradientEffect INHERITED; | 860 typedef GrGradientEffect INHERITED; |
| 888 }; | 861 }; |
| 889 | 862 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 const GrGLSLCaps&, GrProcessorKeyBui
lder* b) { | 1026 const GrGLSLCaps&, GrProcessorKeyBui
lder* b) { |
| 1054 b->add32(GenBaseGradientKey(processor)); | 1027 b->add32(GenBaseGradientKey(processor)); |
| 1055 } | 1028 } |
| 1056 | 1029 |
| 1057 ////////////////////////////////////////////////////////////////////////////// | 1030 ////////////////////////////////////////////////////////////////////////////// |
| 1058 | 1031 |
| 1059 class CircleOutside2PtConicalEffect : public GrGradientEffect { | 1032 class CircleOutside2PtConicalEffect : public GrGradientEffect { |
| 1060 public: | 1033 public: |
| 1061 class GLSLCircleOutside2PtConicalProcessor; | 1034 class GLSLCircleOutside2PtConicalProcessor; |
| 1062 | 1035 |
| 1063 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx, | 1036 static sk_sp<GrFragmentProcessor> Make(const CreateArgs& args, const CircleC
onicalInfo& info) { |
| 1064 const SkTwoPointConicalGradient& shad
er, | |
| 1065 const SkMatrix& matrix, | |
| 1066 SkShader::TileMode tm, | |
| 1067 const CircleConicalInfo& info) { | |
| 1068 return sk_sp<GrFragmentProcessor>( | 1037 return sk_sp<GrFragmentProcessor>( |
| 1069 new CircleOutside2PtConicalEffect(ctx, shader, matrix, tm, info)); | 1038 new CircleOutside2PtConicalEffect(args, info)); |
| 1070 } | 1039 } |
| 1071 | 1040 |
| 1072 virtual ~CircleOutside2PtConicalEffect() {} | 1041 virtual ~CircleOutside2PtConicalEffect() {} |
| 1073 | 1042 |
| 1074 const char* name() const override { return "Two-Point Conical Gradient Outsi
de"; } | 1043 const char* name() const override { return "Two-Point Conical Gradient Outsi
de"; } |
| 1075 | 1044 |
| 1076 SkScalar centerX() const { return fInfo.fCenterEnd.fX; } | 1045 SkScalar centerX() const { return fInfo.fCenterEnd.fX; } |
| 1077 SkScalar centerY() const { return fInfo.fCenterEnd.fY; } | 1046 SkScalar centerY() const { return fInfo.fCenterEnd.fY; } |
| 1078 SkScalar A() const { return fInfo.fA; } | 1047 SkScalar A() const { return fInfo.fA; } |
| 1079 SkScalar B() const { return fInfo.fB; } | 1048 SkScalar B() const { return fInfo.fB; } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1090 const CircleOutside2PtConicalEffect& s = sBase.cast<CircleOutside2PtConi
calEffect>(); | 1059 const CircleOutside2PtConicalEffect& s = sBase.cast<CircleOutside2PtConi
calEffect>(); |
| 1091 return (INHERITED::onIsEqual(sBase) && | 1060 return (INHERITED::onIsEqual(sBase) && |
| 1092 this->fInfo.fCenterEnd == s.fInfo.fCenterEnd && | 1061 this->fInfo.fCenterEnd == s.fInfo.fCenterEnd && |
| 1093 this->fInfo.fA == s.fInfo.fA && | 1062 this->fInfo.fA == s.fInfo.fA && |
| 1094 this->fInfo.fB == s.fInfo.fB && | 1063 this->fInfo.fB == s.fInfo.fB && |
| 1095 this->fInfo.fC == s.fInfo.fC && | 1064 this->fInfo.fC == s.fInfo.fC && |
| 1096 this->fTLimit == s.fTLimit && | 1065 this->fTLimit == s.fTLimit && |
| 1097 this->fIsFlipped == s.fIsFlipped); | 1066 this->fIsFlipped == s.fIsFlipped); |
| 1098 } | 1067 } |
| 1099 | 1068 |
| 1100 CircleOutside2PtConicalEffect(GrContext* ctx, | 1069 CircleOutside2PtConicalEffect(const CreateArgs& args, const CircleConicalInf
o& info) |
| 1101 const SkTwoPointConicalGradient& shader, | 1070 : INHERITED(args), fInfo(info) { |
| 1102 const SkMatrix& matrix, | |
| 1103 SkShader::TileMode tm, | |
| 1104 const CircleConicalInfo& info) | |
| 1105 : INHERITED(ctx, shader, matrix, tm), fInfo(info) { | |
| 1106 this->initClassID<CircleOutside2PtConicalEffect>(); | 1071 this->initClassID<CircleOutside2PtConicalEffect>(); |
| 1072 const SkTwoPointConicalGradient& shader = |
| 1073 *static_cast<const SkTwoPointConicalGradient*>(args.fShader); |
| 1107 if (shader.getStartRadius() != shader.getEndRadius()) { | 1074 if (shader.getStartRadius() != shader.getEndRadius()) { |
| 1108 fTLimit = shader.getStartRadius() / (shader.getStartRadius() - shade
r.getEndRadius()); | 1075 fTLimit = shader.getStartRadius() / (shader.getStartRadius() - shade
r.getEndRadius()); |
| 1109 } else { | 1076 } else { |
| 1110 fTLimit = SK_ScalarMin; | 1077 fTLimit = SK_ScalarMin; |
| 1111 } | 1078 } |
| 1112 | 1079 |
| 1113 fIsFlipped = shader.isFlippedGrad(); | 1080 fIsFlipped = shader.isFlippedGrad(); |
| 1114 } | 1081 } |
| 1115 | 1082 |
| 1116 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 1083 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1315 void CircleOutside2PtConicalEffect::GLSLCircleOutside2PtConicalProcessor::GenKey
( | 1282 void CircleOutside2PtConicalEffect::GLSLCircleOutside2PtConicalProcessor::GenKey
( |
| 1316 const GrProcessor& processor, | 1283 const GrProcessor& processor, |
| 1317 const GrGLSLCaps&, GrProcessorKeyBui
lder* b) { | 1284 const GrGLSLCaps&, GrProcessorKeyBui
lder* b) { |
| 1318 uint32_t* key = b->add32n(2); | 1285 uint32_t* key = b->add32n(2); |
| 1319 key[0] = GenBaseGradientKey(processor); | 1286 key[0] = GenBaseGradientKey(processor); |
| 1320 key[1] = processor.cast<CircleOutside2PtConicalEffect>().isFlipped(); | 1287 key[1] = processor.cast<CircleOutside2PtConicalEffect>().isFlipped(); |
| 1321 } | 1288 } |
| 1322 | 1289 |
| 1323 ////////////////////////////////////////////////////////////////////////////// | 1290 ////////////////////////////////////////////////////////////////////////////// |
| 1324 | 1291 |
| 1325 sk_sp<GrFragmentProcessor> Gr2PtConicalGradientEffect::Make(GrContext* ctx, | 1292 sk_sp<GrFragmentProcessor> Gr2PtConicalGradientEffect::Make( |
| 1326 const SkTwoPointConi
calGradient& shader, | 1293 const GrGradientEffect:
:CreateArgs& args) { |
| 1327 SkShader::TileMode t
m, | 1294 const SkTwoPointConicalGradient& shader = |
| 1328 const SkMatrix* loca
lMatrix) { | 1295 *static_cast<const SkTwoPointConicalGradient*>(args.fShader); |
| 1296 |
| 1329 SkMatrix matrix; | 1297 SkMatrix matrix; |
| 1330 if (!shader.getLocalMatrix().invert(&matrix)) { | 1298 if (!shader.getLocalMatrix().invert(&matrix)) { |
| 1331 return nullptr; | 1299 return nullptr; |
| 1332 } | 1300 } |
| 1333 if (localMatrix) { | 1301 if (args.fMatrix) { |
| 1334 SkMatrix inv; | 1302 SkMatrix inv; |
| 1335 if (!localMatrix->invert(&inv)) { | 1303 if (!args.fMatrix->invert(&inv)) { |
| 1336 return nullptr; | 1304 return nullptr; |
| 1337 } | 1305 } |
| 1338 matrix.postConcat(inv); | 1306 matrix.postConcat(inv); |
| 1339 } | 1307 } |
| 1340 | 1308 |
| 1309 GrGradientEffect::CreateArgs newArgs(args.fContext, args.fShader, &matrix, a
rgs.fTileMode); |
| 1310 |
| 1341 if (shader.getStartRadius() < kErrorTol) { | 1311 if (shader.getStartRadius() < kErrorTol) { |
| 1342 SkScalar focalX; | 1312 SkScalar focalX; |
| 1343 ConicalType type = set_matrix_focal_conical(shader, &matrix, &focalX); | 1313 ConicalType type = set_matrix_focal_conical(shader, &matrix, &focalX); |
| 1344 if (type == kInside_ConicalType) { | 1314 if (type == kInside_ConicalType) { |
| 1345 return FocalInside2PtConicalEffect::Make(ctx, shader, matrix, tm, fo
calX); | 1315 return FocalInside2PtConicalEffect::Make(newArgs, focalX); |
| 1346 } else if(type == kEdge_ConicalType) { | 1316 } else if(type == kEdge_ConicalType) { |
| 1347 set_matrix_edge_conical(shader, &matrix); | 1317 set_matrix_edge_conical(shader, &matrix); |
| 1348 return Edge2PtConicalEffect::Make(ctx, shader, matrix, tm); | 1318 return Edge2PtConicalEffect::Make(newArgs); |
| 1349 } else { | 1319 } else { |
| 1350 return FocalOutside2PtConicalEffect::Make(ctx, shader, matrix, tm, f
ocalX); | 1320 return FocalOutside2PtConicalEffect::Make(newArgs, focalX); |
| 1351 } | 1321 } |
| 1352 } | 1322 } |
| 1353 | 1323 |
| 1354 CircleConicalInfo info; | 1324 CircleConicalInfo info; |
| 1355 ConicalType type = set_matrix_circle_conical(shader, &matrix, &info); | 1325 ConicalType type = set_matrix_circle_conical(shader, &matrix, &info); |
| 1356 | 1326 |
| 1357 if (type == kInside_ConicalType) { | 1327 if (type == kInside_ConicalType) { |
| 1358 return CircleInside2PtConicalEffect::Make(ctx, shader, matrix, tm, info)
; | 1328 return CircleInside2PtConicalEffect::Make(newArgs, info); |
| 1359 } else if (type == kEdge_ConicalType) { | 1329 } else if (type == kEdge_ConicalType) { |
| 1360 set_matrix_edge_conical(shader, &matrix); | 1330 set_matrix_edge_conical(shader, &matrix); |
| 1361 return Edge2PtConicalEffect::Make(ctx, shader, matrix, tm); | 1331 return Edge2PtConicalEffect::Make(newArgs); |
| 1362 } else { | 1332 } else { |
| 1363 return CircleOutside2PtConicalEffect::Make(ctx, shader, matrix, tm, info
); | 1333 return CircleOutside2PtConicalEffect::Make(newArgs, info); |
| 1364 } | 1334 } |
| 1365 } | 1335 } |
| 1366 | 1336 |
| 1367 #endif | 1337 #endif |
| OLD | NEW |