commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/effects/GrRRectEffect.h" |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "src/core/SkRRectPriv.h" |
| 11 | #include "src/core/SkTLazy.h" |
| 12 | #include "src/gpu/GrFragmentProcessor.h" |
| 13 | #include "src/gpu/GrShaderCaps.h" |
| 14 | #include "src/gpu/effects/GrConvexPolyEffect.h" |
| 15 | #include "src/gpu/effects/GrOvalEffect.h" |
| 16 | #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" |
| 17 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| 18 | #include "src/gpu/glsl/GrGLSLProgramDataManager.h" |
| 19 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 20 | |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 21 | // The effects defined here only handle rrect radii >= kRadiusMin. |
| 22 | static const SkScalar kRadiusMin = SK_ScalarHalf; |
| 23 | |
| 24 | ////////////////////////////////////////////////////////////////////////////// |
| 25 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 26 | class CircularRRectEffect : public GrFragmentProcessor { |
commit-bot@chromium.org | e528089 | 2014-02-21 17:52:29 +0000 | [diff] [blame] | 27 | public: |
skia.committer@gmail.com | f1f66c0 | 2014-03-05 03:02:06 +0000 | [diff] [blame] | 28 | |
commit-bot@chromium.org | dd58422 | 2014-03-10 16:08:22 +0000 | [diff] [blame] | 29 | enum CornerFlags { |
| 30 | kTopLeft_CornerFlag = (1 << SkRRect::kUpperLeft_Corner), |
| 31 | kTopRight_CornerFlag = (1 << SkRRect::kUpperRight_Corner), |
| 32 | kBottomRight_CornerFlag = (1 << SkRRect::kLowerRight_Corner), |
| 33 | kBottomLeft_CornerFlag = (1 << SkRRect::kLowerLeft_Corner), |
| 34 | |
| 35 | kLeft_CornerFlags = kTopLeft_CornerFlag | kBottomLeft_CornerFlag, |
| 36 | kTop_CornerFlags = kTopLeft_CornerFlag | kTopRight_CornerFlag, |
| 37 | kRight_CornerFlags = kTopRight_CornerFlag | kBottomRight_CornerFlag, |
| 38 | kBottom_CornerFlags = kBottomLeft_CornerFlag | kBottomRight_CornerFlag, |
| 39 | |
| 40 | kAll_CornerFlags = kTopLeft_CornerFlag | kTopRight_CornerFlag | |
| 41 | kBottomLeft_CornerFlag | kBottomRight_CornerFlag, |
| 42 | |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 43 | kNone_CornerFlags = 0 |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
commit-bot@chromium.org | dd58422 | 2014-03-10 16:08:22 +0000 | [diff] [blame] | 46 | // The flags are used to indicate which corners are circluar (unflagged corners are assumed to |
| 47 | // be square). |
John Stiles | 72e5764 | 2020-06-24 10:42:35 -0400 | [diff] [blame] | 48 | static GrFPResult Make(std::unique_ptr<GrFragmentProcessor>, GrClipEdgeType, |
John Stiles | 851b90e | 2020-06-17 13:53:37 -0400 | [diff] [blame] | 49 | uint32_t circularCornerFlags, const SkRRect&); |
commit-bot@chromium.org | e528089 | 2014-02-21 17:52:29 +0000 | [diff] [blame] | 50 | |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 51 | ~CircularRRectEffect() override {} |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 52 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 53 | const char* name() const override { return "CircularRRect"; } |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 54 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 55 | std::unique_ptr<GrFragmentProcessor> clone() const override; |
Brian Salomon | 1a2a7ab | 2017-07-26 13:11:51 -0400 | [diff] [blame] | 56 | |
commit-bot@chromium.org | e528089 | 2014-02-21 17:52:29 +0000 | [diff] [blame] | 57 | const SkRRect& getRRect() const { return fRRect; } |
| 58 | |
commit-bot@chromium.org | dd58422 | 2014-03-10 16:08:22 +0000 | [diff] [blame] | 59 | uint32_t getCircularCornerFlags() const { return fCircularCornerFlags; } |
skia.committer@gmail.com | 06acb58 | 2014-03-06 03:02:32 +0000 | [diff] [blame] | 60 | |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 61 | GrClipEdgeType getEdgeType() const { return fEdgeType; } |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 62 | |
commit-bot@chromium.org | e528089 | 2014-02-21 17:52:29 +0000 | [diff] [blame] | 63 | private: |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 64 | CircularRRectEffect(std::unique_ptr<GrFragmentProcessor> inputFP, |
| 65 | GrClipEdgeType, uint32_t circularCornerFlags, const SkRRect&); |
John Stiles | c0d5d9c | 2020-06-15 15:57:25 -0400 | [diff] [blame] | 66 | CircularRRectEffect(const CircularRRectEffect& that); |
commit-bot@chromium.org | e528089 | 2014-02-21 17:52:29 +0000 | [diff] [blame] | 67 | |
Brian Salomon | 3176e86 | 2021-08-09 11:23:04 -0400 | [diff] [blame] | 68 | std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 69 | |
Brian Salomon | 13b2873 | 2021-08-06 15:33:58 -0400 | [diff] [blame] | 70 | void onAddToKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 71 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 72 | bool onIsEqual(const GrFragmentProcessor& other) const override; |
commit-bot@chromium.org | e528089 | 2014-02-21 17:52:29 +0000 | [diff] [blame] | 73 | |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 74 | SkRRect fRRect; |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 75 | GrClipEdgeType fEdgeType; |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 76 | uint32_t fCircularCornerFlags; |
commit-bot@chromium.org | e528089 | 2014-02-21 17:52:29 +0000 | [diff] [blame] | 77 | |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 78 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
commit-bot@chromium.org | e528089 | 2014-02-21 17:52:29 +0000 | [diff] [blame] | 79 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 80 | using INHERITED = GrFragmentProcessor; |
commit-bot@chromium.org | e528089 | 2014-02-21 17:52:29 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
John Stiles | 72e5764 | 2020-06-24 10:42:35 -0400 | [diff] [blame] | 83 | GrFPResult CircularRRectEffect::Make(std::unique_ptr<GrFragmentProcessor> inputFP, |
| 84 | GrClipEdgeType edgeType, |
| 85 | uint32_t circularCornerFlags, const SkRRect& rrect) { |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 86 | if (GrClipEdgeType::kFillAA != edgeType && GrClipEdgeType::kInverseFillAA != edgeType) { |
John Stiles | 72e5764 | 2020-06-24 10:42:35 -0400 | [diff] [blame] | 87 | return GrFPFailure(std::move(inputFP)); |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 88 | } |
John Stiles | 72e5764 | 2020-06-24 10:42:35 -0400 | [diff] [blame] | 89 | return GrFPSuccess(std::unique_ptr<GrFragmentProcessor>( |
John Stiles | 851b90e | 2020-06-17 13:53:37 -0400 | [diff] [blame] | 90 | new CircularRRectEffect(std::move(inputFP), edgeType, circularCornerFlags, rrect))); |
commit-bot@chromium.org | e528089 | 2014-02-21 17:52:29 +0000 | [diff] [blame] | 91 | } |
| 92 | |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 93 | CircularRRectEffect::CircularRRectEffect(std::unique_ptr<GrFragmentProcessor> inputFP, |
Brian Osman | 8f39137 | 2021-04-29 15:27:34 -0400 | [diff] [blame] | 94 | GrClipEdgeType edgeType, |
| 95 | uint32_t circularCornerFlags, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 96 | const SkRRect& rrect) |
Brian Osman | 8f39137 | 2021-04-29 15:27:34 -0400 | [diff] [blame] | 97 | : INHERITED(kCircularRRectEffect_ClassID, |
| 98 | ProcessorOptimizationFlags(inputFP.get()) & |
| 99 | kCompatibleWithCoverageAsAlpha_OptimizationFlag) |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 100 | , fRRect(rrect) |
| 101 | , fEdgeType(edgeType) |
| 102 | , fCircularCornerFlags(circularCornerFlags) { |
Brian Osman | 54867de | 2020-07-10 14:22:57 -0400 | [diff] [blame] | 103 | this->registerChild(std::move(inputFP)); |
John Stiles | c0d5d9c | 2020-06-15 15:57:25 -0400 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | CircularRRectEffect::CircularRRectEffect(const CircularRRectEffect& that) |
John Stiles | 307f8f5 | 2021-08-09 15:36:59 -0400 | [diff] [blame^] | 107 | : INHERITED(that) |
John Stiles | c0d5d9c | 2020-06-15 15:57:25 -0400 | [diff] [blame] | 108 | , fRRect(that.fRRect) |
| 109 | , fEdgeType(that.fEdgeType) |
John Stiles | 307f8f5 | 2021-08-09 15:36:59 -0400 | [diff] [blame^] | 110 | , fCircularCornerFlags(that.fCircularCornerFlags) {} |
commit-bot@chromium.org | e528089 | 2014-02-21 17:52:29 +0000 | [diff] [blame] | 111 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 112 | std::unique_ptr<GrFragmentProcessor> CircularRRectEffect::clone() const { |
John Stiles | c0d5d9c | 2020-06-15 15:57:25 -0400 | [diff] [blame] | 113 | return std::unique_ptr<GrFragmentProcessor>(new CircularRRectEffect(*this)); |
Brian Salomon | 1a2a7ab | 2017-07-26 13:11:51 -0400 | [diff] [blame] | 114 | } |
| 115 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 116 | bool CircularRRectEffect::onIsEqual(const GrFragmentProcessor& other) const { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 117 | const CircularRRectEffect& crre = other.cast<CircularRRectEffect>(); |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 118 | // The corner flags are derived from fRRect, so no need to check them. |
| 119 | return fEdgeType == crre.fEdgeType && fRRect == crre.fRRect; |
commit-bot@chromium.org | e528089 | 2014-02-21 17:52:29 +0000 | [diff] [blame] | 120 | } |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 121 | |
| 122 | ////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | e528089 | 2014-02-21 17:52:29 +0000 | [diff] [blame] | 123 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 124 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircularRRectEffect); |
commit-bot@chromium.org | e528089 | 2014-02-21 17:52:29 +0000 | [diff] [blame] | 125 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 126 | #if GR_TEST_UTILS |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 127 | std::unique_ptr<GrFragmentProcessor> CircularRRectEffect::TestCreate(GrProcessorTestData* d) { |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 128 | SkScalar w = d->fRandom->nextRangeScalar(20.f, 1000.f); |
| 129 | SkScalar h = d->fRandom->nextRangeScalar(20.f, 1000.f); |
| 130 | SkScalar r = d->fRandom->nextRangeF(kRadiusMin, 9.f); |
commit-bot@chromium.org | e528089 | 2014-02-21 17:52:29 +0000 | [diff] [blame] | 131 | SkRRect rrect; |
| 132 | rrect.setRectXY(SkRect::MakeWH(w, h), r, r); |
John Stiles | 6609cb6 | 2020-07-17 14:52:12 -0400 | [diff] [blame] | 133 | std::unique_ptr<GrFragmentProcessor> fp = d->inputFP(); |
John Stiles | 851b90e | 2020-06-17 13:53:37 -0400 | [diff] [blame] | 134 | bool success; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 135 | do { |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 136 | GrClipEdgeType et = |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 137 | (GrClipEdgeType)d->fRandom->nextULessThan(kGrClipEdgeTypeCnt); |
John Stiles | 6609cb6 | 2020-07-17 14:52:12 -0400 | [diff] [blame] | 138 | std::tie(success, fp) = GrRRectEffect::Make(std::move(fp), et, rrect, |
John Stiles | 851b90e | 2020-06-17 13:53:37 -0400 | [diff] [blame] | 139 | *d->caps()->shaderCaps()); |
| 140 | } while (!success); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 141 | return fp; |
commit-bot@chromium.org | e528089 | 2014-02-21 17:52:29 +0000 | [diff] [blame] | 142 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 143 | #endif |
commit-bot@chromium.org | e528089 | 2014-02-21 17:52:29 +0000 | [diff] [blame] | 144 | |
| 145 | ////////////////////////////////////////////////////////////////////////////// |
| 146 | |
Brian Salomon | 3176e86 | 2021-08-09 11:23:04 -0400 | [diff] [blame] | 147 | class GLCircularRRectEffect : public GrFragmentProcessor::ProgramImpl { |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 148 | public: |
Brian Salomon | 0a241ce | 2017-12-15 11:31:05 -0500 | [diff] [blame] | 149 | GLCircularRRectEffect() = default; |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 150 | |
John Stiles | 1cf2c8d | 2020-08-13 22:58:04 -0400 | [diff] [blame] | 151 | void emitCode(EmitArgs&) override; |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 152 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 153 | static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*); |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 154 | |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 155 | protected: |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 156 | void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override; |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 157 | |
| 158 | private: |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 159 | GrGLSLProgramDataManager::UniformHandle fInnerRectUniform; |
| 160 | GrGLSLProgramDataManager::UniformHandle fRadiusPlusHalfUniform; |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 161 | SkRRect fPrevRRect; |
Brian Salomon | 3176e86 | 2021-08-09 11:23:04 -0400 | [diff] [blame] | 162 | using INHERITED = ProgramImpl; |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 163 | }; |
| 164 | |
wangyix | 7c157a9 | 2015-07-22 15:08:53 -0700 | [diff] [blame] | 165 | void GLCircularRRectEffect::emitCode(EmitArgs& args) { |
| 166 | const CircularRRectEffect& crre = args.fFp.cast<CircularRRectEffect>(); |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 167 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 168 | const char *rectName; |
| 169 | const char *radiusPlusHalfName; |
commit-bot@chromium.org | c5c748c | 2014-03-11 15:54:51 +0000 | [diff] [blame] | 170 | // The inner rect is the rrect bounds inset by the radius. Its left, top, right, and bottom |
| 171 | // edges correspond to components x, y, z, and w, respectively. When a side of the rrect has |
| 172 | // only rectangular corners, that side's value corresponds to the rect edge's value outset by |
| 173 | // half a pixel. |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 174 | fInnerRectUniform = uniformHandler->addUniform(&crre, kFragment_GrShaderFlag, kFloat4_GrSLType, |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 175 | "innerRect", &rectName); |
bsalomon | cd07491 | 2015-12-09 10:33:51 -0800 | [diff] [blame] | 176 | // x is (r + .5) and y is 1/(r + .5) |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 177 | fRadiusPlusHalfUniform = uniformHandler->addUniform(&crre, kFragment_GrShaderFlag, |
| 178 | kHalf2_GrSLType, "radiusPlusHalf", |
| 179 | &radiusPlusHalfName); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 180 | |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 181 | // If we're on a device where float != fp32 then the length calculation could overflow. |
bsalomon | cd07491 | 2015-12-09 10:33:51 -0800 | [diff] [blame] | 182 | SkString clampedCircleDistance; |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 183 | if (!args.fShaderCaps->floatIs32Bits()) { |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 184 | clampedCircleDistance.printf("saturate(%s.x * (1.0 - length(dxy * %s.y)))", |
bsalomon | cd07491 | 2015-12-09 10:33:51 -0800 | [diff] [blame] | 185 | radiusPlusHalfName, radiusPlusHalfName); |
| 186 | } else { |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 187 | clampedCircleDistance.printf("saturate(%s.x - length(dxy))", radiusPlusHalfName); |
bsalomon | cd07491 | 2015-12-09 10:33:51 -0800 | [diff] [blame] | 188 | } |
| 189 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 190 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 191 | // At each quarter-circle corner we compute a vector that is the offset of the fragment position |
| 192 | // from the circle center. The vector is pinned in x and y to be in the quarter-plane relevant |
| 193 | // to that corner. This means that points near the interior near the rrect top edge will have |
| 194 | // a vector that points straight up for both the TL left and TR corners. Computing an |
| 195 | // alpha from this vector at either the TR or TL corner will give the correct result. Similarly, |
| 196 | // fragments near the other three edges will get the correct AA. Fragments in the interior of |
| 197 | // the rrect will have a (0,0) vector at all four corners. So long as the radius > 0.5 they will |
| 198 | // correctly produce an alpha value of 1 at all four corners. We take the min of all the alphas. |
| 199 | // The code below is a simplified version of the above that performs maxs on the vector |
| 200 | // components before computing distances and alpha values so that only one distance computation |
| 201 | // need be computed to determine the min alpha. |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 202 | // |
| 203 | // For the cases where one half of the rrect is rectangular we drop one of the x or y |
| 204 | // computations, compute a separate rect edge alpha for the rect side, and mul the two computed |
| 205 | // alphas together. |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 206 | switch (crre.getCircularCornerFlags()) { |
| 207 | case CircularRRectEffect::kAll_CornerFlags: |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 208 | fragBuilder->codeAppendf("float2 dxy0 = %s.LT - sk_FragCoord.xy;", rectName); |
| 209 | fragBuilder->codeAppendf("float2 dxy1 = sk_FragCoord.xy - %s.RB;", rectName); |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 210 | fragBuilder->codeAppend("float2 dxy = max(max(dxy0, dxy1), 0.0);"); |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 211 | fragBuilder->codeAppendf("half alpha = half(%s);", clampedCircleDistance.c_str()); |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 212 | break; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 213 | case CircularRRectEffect::kTopLeft_CornerFlag: |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 214 | fragBuilder->codeAppendf("float2 dxy = max(%s.LT - sk_FragCoord.xy, 0.0);", |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 215 | rectName); |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 216 | fragBuilder->codeAppendf("half rightAlpha = half(saturate(%s.R - sk_FragCoord.x));", |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 217 | rectName); |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 218 | fragBuilder->codeAppendf("half bottomAlpha = half(saturate(%s.B - sk_FragCoord.y));", |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 219 | rectName); |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 220 | fragBuilder->codeAppendf("half alpha = bottomAlpha * rightAlpha * half(%s);", |
bsalomon | cd07491 | 2015-12-09 10:33:51 -0800 | [diff] [blame] | 221 | clampedCircleDistance.c_str()); |
commit-bot@chromium.org | c5c748c | 2014-03-11 15:54:51 +0000 | [diff] [blame] | 222 | break; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 223 | case CircularRRectEffect::kTopRight_CornerFlag: |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 224 | fragBuilder->codeAppendf("float2 dxy = max(float2(sk_FragCoord.x - %s.R, " |
| 225 | "%s.T - sk_FragCoord.y), 0.0);", |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 226 | rectName, rectName); |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 227 | fragBuilder->codeAppendf("half leftAlpha = half(saturate(sk_FragCoord.x - %s.L));", |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 228 | rectName); |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 229 | fragBuilder->codeAppendf("half bottomAlpha = half(saturate(%s.B - sk_FragCoord.y));", |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 230 | rectName); |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 231 | fragBuilder->codeAppendf("half alpha = bottomAlpha * leftAlpha * half(%s);", |
bsalomon | cd07491 | 2015-12-09 10:33:51 -0800 | [diff] [blame] | 232 | clampedCircleDistance.c_str()); |
commit-bot@chromium.org | c5c748c | 2014-03-11 15:54:51 +0000 | [diff] [blame] | 233 | break; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 234 | case CircularRRectEffect::kBottomRight_CornerFlag: |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 235 | fragBuilder->codeAppendf("float2 dxy = max(sk_FragCoord.xy - %s.RB, 0.0);", |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 236 | rectName); |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 237 | fragBuilder->codeAppendf("half leftAlpha = half(saturate(sk_FragCoord.x - %s.L));", |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 238 | rectName); |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 239 | fragBuilder->codeAppendf("half topAlpha = half(saturate(sk_FragCoord.y - %s.T));", |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 240 | rectName); |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 241 | fragBuilder->codeAppendf("half alpha = topAlpha * leftAlpha * half(%s);", |
bsalomon | cd07491 | 2015-12-09 10:33:51 -0800 | [diff] [blame] | 242 | clampedCircleDistance.c_str()); |
commit-bot@chromium.org | c5c748c | 2014-03-11 15:54:51 +0000 | [diff] [blame] | 243 | break; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 244 | case CircularRRectEffect::kBottomLeft_CornerFlag: |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 245 | fragBuilder->codeAppendf("float2 dxy = max(float2(%s.L - sk_FragCoord.x, " |
| 246 | "sk_FragCoord.y - %s.B), 0.0);", |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 247 | rectName, rectName); |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 248 | fragBuilder->codeAppendf("half rightAlpha = half(saturate(%s.R - sk_FragCoord.x));", |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 249 | rectName); |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 250 | fragBuilder->codeAppendf("half topAlpha = half(saturate(sk_FragCoord.y - %s.T));", |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 251 | rectName); |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 252 | fragBuilder->codeAppendf("half alpha = topAlpha * rightAlpha * half(%s);", |
bsalomon | cd07491 | 2015-12-09 10:33:51 -0800 | [diff] [blame] | 253 | clampedCircleDistance.c_str()); |
commit-bot@chromium.org | c5c748c | 2014-03-11 15:54:51 +0000 | [diff] [blame] | 254 | break; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 255 | case CircularRRectEffect::kLeft_CornerFlags: |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 256 | fragBuilder->codeAppendf("float2 dxy0 = %s.LT - sk_FragCoord.xy;", rectName); |
| 257 | fragBuilder->codeAppendf("float dy1 = sk_FragCoord.y - %s.B;", rectName); |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 258 | fragBuilder->codeAppend("float2 dxy = max(float2(dxy0.x, max(dxy0.y, dy1)), 0.0);"); |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 259 | fragBuilder->codeAppendf("half rightAlpha = half(saturate(%s.R - sk_FragCoord.x));", |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 260 | rectName); |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 261 | fragBuilder->codeAppendf("half alpha = rightAlpha * half(%s);", |
bsalomon | cd07491 | 2015-12-09 10:33:51 -0800 | [diff] [blame] | 262 | clampedCircleDistance.c_str()); |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 263 | break; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 264 | case CircularRRectEffect::kTop_CornerFlags: |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 265 | fragBuilder->codeAppendf("float2 dxy0 = %s.LT - sk_FragCoord.xy;", rectName); |
| 266 | fragBuilder->codeAppendf("float dx1 = sk_FragCoord.x - %s.R;", rectName); |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 267 | fragBuilder->codeAppend("float2 dxy = max(float2(max(dxy0.x, dx1), dxy0.y), 0.0);"); |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 268 | fragBuilder->codeAppendf("half bottomAlpha = half(saturate(%s.B - sk_FragCoord.y));", |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 269 | rectName); |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 270 | fragBuilder->codeAppendf("half alpha = bottomAlpha * half(%s);", |
bsalomon | cd07491 | 2015-12-09 10:33:51 -0800 | [diff] [blame] | 271 | clampedCircleDistance.c_str()); |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 272 | break; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 273 | case CircularRRectEffect::kRight_CornerFlags: |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 274 | fragBuilder->codeAppendf("float dy0 = %s.T - sk_FragCoord.y;", rectName); |
| 275 | fragBuilder->codeAppendf("float2 dxy1 = sk_FragCoord.xy - %s.RB;", rectName); |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 276 | fragBuilder->codeAppend("float2 dxy = max(float2(dxy1.x, max(dy0, dxy1.y)), 0.0);"); |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 277 | fragBuilder->codeAppendf("half leftAlpha = half(saturate(sk_FragCoord.x - %s.L));", |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 278 | rectName); |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 279 | fragBuilder->codeAppendf("half alpha = leftAlpha * half(%s);", |
bsalomon | cd07491 | 2015-12-09 10:33:51 -0800 | [diff] [blame] | 280 | clampedCircleDistance.c_str()); |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 281 | break; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 282 | case CircularRRectEffect::kBottom_CornerFlags: |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 283 | fragBuilder->codeAppendf("float dx0 = %s.L - sk_FragCoord.x;", rectName); |
| 284 | fragBuilder->codeAppendf("float2 dxy1 = sk_FragCoord.xy - %s.RB;", rectName); |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 285 | fragBuilder->codeAppend("float2 dxy = max(float2(max(dx0, dxy1.x), dxy1.y), 0.0);"); |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 286 | fragBuilder->codeAppendf("half topAlpha = half(saturate(sk_FragCoord.y - %s.T));", |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 287 | rectName); |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 288 | fragBuilder->codeAppendf("half alpha = topAlpha * half(%s);", |
bsalomon | cd07491 | 2015-12-09 10:33:51 -0800 | [diff] [blame] | 289 | clampedCircleDistance.c_str()); |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 290 | break; |
| 291 | } |
skia.committer@gmail.com | 06acb58 | 2014-03-06 03:02:32 +0000 | [diff] [blame] | 292 | |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 293 | if (GrClipEdgeType::kInverseFillAA == crre.getEdgeType()) { |
bsalomon | cd07491 | 2015-12-09 10:33:51 -0800 | [diff] [blame] | 294 | fragBuilder->codeAppend("alpha = 1.0 - alpha;"); |
commit-bot@chromium.org | fbde87f | 2014-03-04 16:25:34 +0000 | [diff] [blame] | 295 | } |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 296 | |
Brian Osman | 6b5dbb4 | 2020-07-15 15:31:05 -0400 | [diff] [blame] | 297 | SkString inputSample = this->invokeChild(/*childIndex=*/0, args); |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 298 | |
John Stiles | 4bdc121 | 2020-12-14 18:04:13 -0500 | [diff] [blame] | 299 | fragBuilder->codeAppendf("return %s * alpha;", inputSample.c_str()); |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 302 | void GLCircularRRectEffect::GenKey(const GrProcessor& processor, const GrShaderCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 303 | GrProcessorKeyBuilder* b) { |
| 304 | const CircularRRectEffect& crre = processor.cast<CircularRRectEffect>(); |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 305 | static_assert(kGrClipEdgeTypeCnt <= 8); |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 306 | b->add32((crre.getCircularCornerFlags() << 3) | (int) crre.getEdgeType()); |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 307 | } |
| 308 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 309 | void GLCircularRRectEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 310 | const GrFragmentProcessor& processor) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 311 | const CircularRRectEffect& crre = processor.cast<CircularRRectEffect>(); |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 312 | const SkRRect& rrect = crre.getRRect(); |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 313 | if (rrect != fPrevRRect) { |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 314 | SkRect rect = rrect.getBounds(); |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 315 | SkScalar radius = 0; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 316 | switch (crre.getCircularCornerFlags()) { |
| 317 | case CircularRRectEffect::kAll_CornerFlags: |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 318 | SkASSERT(SkRRectPriv::IsSimpleCircular(rrect)); |
| 319 | radius = SkRRectPriv::GetSimpleRadii(rrect).fX; |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 320 | SkASSERT(radius >= kRadiusMin); |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 321 | rect.inset(radius, radius); |
| 322 | break; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 323 | case CircularRRectEffect::kTopLeft_CornerFlag: |
commit-bot@chromium.org | c5c748c | 2014-03-11 15:54:51 +0000 | [diff] [blame] | 324 | radius = rrect.radii(SkRRect::kUpperLeft_Corner).fX; |
| 325 | rect.fLeft += radius; |
| 326 | rect.fTop += radius; |
| 327 | rect.fRight += 0.5f; |
| 328 | rect.fBottom += 0.5f; |
| 329 | break; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 330 | case CircularRRectEffect::kTopRight_CornerFlag: |
commit-bot@chromium.org | c5c748c | 2014-03-11 15:54:51 +0000 | [diff] [blame] | 331 | radius = rrect.radii(SkRRect::kUpperRight_Corner).fX; |
bsalomon@google.com | de9f251 | 2014-03-11 17:09:17 +0000 | [diff] [blame] | 332 | rect.fLeft -= 0.5f; |
commit-bot@chromium.org | c5c748c | 2014-03-11 15:54:51 +0000 | [diff] [blame] | 333 | rect.fTop += radius; |
| 334 | rect.fRight -= radius; |
| 335 | rect.fBottom += 0.5f; |
| 336 | break; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 337 | case CircularRRectEffect::kBottomRight_CornerFlag: |
commit-bot@chromium.org | c5c748c | 2014-03-11 15:54:51 +0000 | [diff] [blame] | 338 | radius = rrect.radii(SkRRect::kLowerRight_Corner).fX; |
bsalomon@google.com | de9f251 | 2014-03-11 17:09:17 +0000 | [diff] [blame] | 339 | rect.fLeft -= 0.5f; |
| 340 | rect.fTop -= 0.5f; |
commit-bot@chromium.org | c5c748c | 2014-03-11 15:54:51 +0000 | [diff] [blame] | 341 | rect.fRight -= radius; |
| 342 | rect.fBottom -= radius; |
| 343 | break; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 344 | case CircularRRectEffect::kBottomLeft_CornerFlag: |
commit-bot@chromium.org | c5c748c | 2014-03-11 15:54:51 +0000 | [diff] [blame] | 345 | radius = rrect.radii(SkRRect::kLowerLeft_Corner).fX; |
| 346 | rect.fLeft += radius; |
bsalomon@google.com | de9f251 | 2014-03-11 17:09:17 +0000 | [diff] [blame] | 347 | rect.fTop -= 0.5f; |
| 348 | rect.fRight += 0.5f; |
commit-bot@chromium.org | c5c748c | 2014-03-11 15:54:51 +0000 | [diff] [blame] | 349 | rect.fBottom -= radius; |
| 350 | break; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 351 | case CircularRRectEffect::kLeft_CornerFlags: |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 352 | radius = rrect.radii(SkRRect::kUpperLeft_Corner).fX; |
| 353 | rect.fLeft += radius; |
| 354 | rect.fTop += radius; |
| 355 | rect.fRight += 0.5f; |
| 356 | rect.fBottom -= radius; |
| 357 | break; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 358 | case CircularRRectEffect::kTop_CornerFlags: |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 359 | radius = rrect.radii(SkRRect::kUpperLeft_Corner).fX; |
| 360 | rect.fLeft += radius; |
| 361 | rect.fTop += radius; |
| 362 | rect.fRight -= radius; |
| 363 | rect.fBottom += 0.5f; |
| 364 | break; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 365 | case CircularRRectEffect::kRight_CornerFlags: |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 366 | radius = rrect.radii(SkRRect::kUpperRight_Corner).fX; |
| 367 | rect.fLeft -= 0.5f; |
| 368 | rect.fTop += radius; |
| 369 | rect.fRight -= radius; |
| 370 | rect.fBottom -= radius; |
| 371 | break; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 372 | case CircularRRectEffect::kBottom_CornerFlags: |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 373 | radius = rrect.radii(SkRRect::kLowerLeft_Corner).fX; |
| 374 | rect.fLeft += radius; |
| 375 | rect.fTop -= 0.5f; |
| 376 | rect.fRight -= radius; |
| 377 | rect.fBottom -= radius; |
| 378 | break; |
commit-bot@chromium.org | dd58422 | 2014-03-10 16:08:22 +0000 | [diff] [blame] | 379 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 380 | SK_ABORT("Should have been one of the above cases."); |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 381 | } |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 382 | pdman.set4f(fInnerRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); |
bsalomon | cd07491 | 2015-12-09 10:33:51 -0800 | [diff] [blame] | 383 | radius += 0.5f; |
| 384 | pdman.set2f(fRadiusPlusHalfUniform, radius, 1.f / radius); |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 385 | fPrevRRect = rrect; |
| 386 | } |
| 387 | } |
| 388 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 389 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 390 | |
Brian Salomon | 13b2873 | 2021-08-06 15:33:58 -0400 | [diff] [blame] | 391 | void CircularRRectEffect::onAddToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 392 | GLCircularRRectEffect::GenKey(*this, caps, b); |
| 393 | } |
| 394 | |
Brian Salomon | 3176e86 | 2021-08-09 11:23:04 -0400 | [diff] [blame] | 395 | std::unique_ptr<GrFragmentProcessor::ProgramImpl> CircularRRectEffect::onMakeProgramImpl() const { |
Brian Salomon | 18ab203 | 2021-02-23 10:07:05 -0500 | [diff] [blame] | 396 | return std::make_unique<GLCircularRRectEffect>(); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | ////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 400 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 401 | class EllipticalRRectEffect : public GrFragmentProcessor { |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 402 | public: |
John Stiles | 72e5764 | 2020-06-24 10:42:35 -0400 | [diff] [blame] | 403 | static GrFPResult Make(std::unique_ptr<GrFragmentProcessor>, GrClipEdgeType, const SkRRect&); |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 404 | |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 405 | ~EllipticalRRectEffect() override {} |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 406 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 407 | const char* name() const override { return "EllipticalRRect"; } |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 408 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 409 | std::unique_ptr<GrFragmentProcessor> clone() const override; |
Brian Salomon | 1a2a7ab | 2017-07-26 13:11:51 -0400 | [diff] [blame] | 410 | |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 411 | const SkRRect& getRRect() const { return fRRect; } |
| 412 | |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 413 | GrClipEdgeType getEdgeType() const { return fEdgeType; } |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 414 | |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 415 | private: |
John Stiles | c0d5d9c | 2020-06-15 15:57:25 -0400 | [diff] [blame] | 416 | EllipticalRRectEffect(std::unique_ptr<GrFragmentProcessor>, GrClipEdgeType, const SkRRect&); |
| 417 | EllipticalRRectEffect(const EllipticalRRectEffect& that); |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 418 | |
Brian Salomon | 3176e86 | 2021-08-09 11:23:04 -0400 | [diff] [blame] | 419 | std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 420 | |
Brian Salomon | 13b2873 | 2021-08-06 15:33:58 -0400 | [diff] [blame] | 421 | void onAddToKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 422 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 423 | bool onIsEqual(const GrFragmentProcessor& other) const override; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 424 | |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 425 | SkRRect fRRect; |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 426 | GrClipEdgeType fEdgeType; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 427 | |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 428 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 429 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 430 | using INHERITED = GrFragmentProcessor; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 431 | }; |
| 432 | |
John Stiles | 72e5764 | 2020-06-24 10:42:35 -0400 | [diff] [blame] | 433 | GrFPResult EllipticalRRectEffect::Make(std::unique_ptr<GrFragmentProcessor> inputFP, |
| 434 | GrClipEdgeType edgeType, const SkRRect& rrect) { |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 435 | if (GrClipEdgeType::kFillAA != edgeType && GrClipEdgeType::kInverseFillAA != edgeType) { |
John Stiles | 72e5764 | 2020-06-24 10:42:35 -0400 | [diff] [blame] | 436 | return GrFPFailure(std::move(inputFP)); |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 437 | } |
John Stiles | 72e5764 | 2020-06-24 10:42:35 -0400 | [diff] [blame] | 438 | return GrFPSuccess(std::unique_ptr<GrFragmentProcessor>( |
John Stiles | 851b90e | 2020-06-17 13:53:37 -0400 | [diff] [blame] | 439 | new EllipticalRRectEffect(std::move(inputFP), edgeType, rrect))); |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 440 | } |
| 441 | |
John Stiles | c0d5d9c | 2020-06-15 15:57:25 -0400 | [diff] [blame] | 442 | EllipticalRRectEffect::EllipticalRRectEffect(std::unique_ptr<GrFragmentProcessor> inputFP, |
Brian Osman | 8f39137 | 2021-04-29 15:27:34 -0400 | [diff] [blame] | 443 | GrClipEdgeType edgeType, |
| 444 | const SkRRect& rrect) |
| 445 | : INHERITED(kEllipticalRRectEffect_ClassID, |
| 446 | ProcessorOptimizationFlags(inputFP.get()) & |
| 447 | kCompatibleWithCoverageAsAlpha_OptimizationFlag) |
Brian Salomon | f3b995b | 2017-02-15 10:22:23 -0500 | [diff] [blame] | 448 | , fRRect(rrect) |
| 449 | , fEdgeType(edgeType) { |
Brian Osman | 54867de | 2020-07-10 14:22:57 -0400 | [diff] [blame] | 450 | this->registerChild(std::move(inputFP)); |
John Stiles | c0d5d9c | 2020-06-15 15:57:25 -0400 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | EllipticalRRectEffect::EllipticalRRectEffect(const EllipticalRRectEffect& that) |
John Stiles | 307f8f5 | 2021-08-09 15:36:59 -0400 | [diff] [blame^] | 454 | : INHERITED(that) |
John Stiles | c0d5d9c | 2020-06-15 15:57:25 -0400 | [diff] [blame] | 455 | , fRRect(that.fRRect) |
John Stiles | 307f8f5 | 2021-08-09 15:36:59 -0400 | [diff] [blame^] | 456 | , fEdgeType(that.fEdgeType) {} |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 457 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 458 | std::unique_ptr<GrFragmentProcessor> EllipticalRRectEffect::clone() const { |
John Stiles | c0d5d9c | 2020-06-15 15:57:25 -0400 | [diff] [blame] | 459 | return std::unique_ptr<GrFragmentProcessor>(new EllipticalRRectEffect(*this)); |
Brian Salomon | 1a2a7ab | 2017-07-26 13:11:51 -0400 | [diff] [blame] | 460 | } |
| 461 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 462 | bool EllipticalRRectEffect::onIsEqual(const GrFragmentProcessor& other) const { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 463 | const EllipticalRRectEffect& erre = other.cast<EllipticalRRectEffect>(); |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 464 | return fEdgeType == erre.fEdgeType && fRRect == erre.fRRect; |
| 465 | } |
| 466 | |
| 467 | ////////////////////////////////////////////////////////////////////////////// |
| 468 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 469 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(EllipticalRRectEffect); |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 470 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 471 | #if GR_TEST_UTILS |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 472 | std::unique_ptr<GrFragmentProcessor> EllipticalRRectEffect::TestCreate(GrProcessorTestData* d) { |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 473 | SkScalar w = d->fRandom->nextRangeScalar(20.f, 1000.f); |
| 474 | SkScalar h = d->fRandom->nextRangeScalar(20.f, 1000.f); |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 475 | SkVector r[4]; |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 476 | r[SkRRect::kUpperLeft_Corner].fX = d->fRandom->nextRangeF(kRadiusMin, 9.f); |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 477 | // ensure at least one corner really is elliptical |
| 478 | do { |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 479 | r[SkRRect::kUpperLeft_Corner].fY = d->fRandom->nextRangeF(kRadiusMin, 9.f); |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 480 | } while (r[SkRRect::kUpperLeft_Corner].fY == r[SkRRect::kUpperLeft_Corner].fX); |
| 481 | |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 482 | SkRRect rrect; |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 483 | if (d->fRandom->nextBool()) { |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 484 | // half the time create a four-radii rrect. |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 485 | r[SkRRect::kLowerRight_Corner].fX = d->fRandom->nextRangeF(kRadiusMin, 9.f); |
| 486 | r[SkRRect::kLowerRight_Corner].fY = d->fRandom->nextRangeF(kRadiusMin, 9.f); |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 487 | |
| 488 | r[SkRRect::kUpperRight_Corner].fX = r[SkRRect::kLowerRight_Corner].fX; |
| 489 | r[SkRRect::kUpperRight_Corner].fY = r[SkRRect::kUpperLeft_Corner].fY; |
| 490 | |
| 491 | r[SkRRect::kLowerLeft_Corner].fX = r[SkRRect::kUpperLeft_Corner].fX; |
| 492 | r[SkRRect::kLowerLeft_Corner].fY = r[SkRRect::kLowerRight_Corner].fY; |
| 493 | |
| 494 | rrect.setRectRadii(SkRect::MakeWH(w, h), r); |
| 495 | } else { |
| 496 | rrect.setRectXY(SkRect::MakeWH(w, h), r[SkRRect::kUpperLeft_Corner].fX, |
| 497 | r[SkRRect::kUpperLeft_Corner].fY); |
| 498 | } |
John Stiles | 6609cb6 | 2020-07-17 14:52:12 -0400 | [diff] [blame] | 499 | std::unique_ptr<GrFragmentProcessor> fp = d->inputFP(); |
John Stiles | 851b90e | 2020-06-17 13:53:37 -0400 | [diff] [blame] | 500 | bool success; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 501 | do { |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 502 | GrClipEdgeType et = (GrClipEdgeType)d->fRandom->nextULessThan(kGrClipEdgeTypeCnt); |
John Stiles | 6609cb6 | 2020-07-17 14:52:12 -0400 | [diff] [blame] | 503 | std::tie(success, fp) = GrRRectEffect::Make(std::move(fp), et, rrect, |
John Stiles | 851b90e | 2020-06-17 13:53:37 -0400 | [diff] [blame] | 504 | *d->caps()->shaderCaps()); |
| 505 | } while (!success); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 506 | return fp; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 507 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 508 | #endif |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 509 | |
| 510 | ////////////////////////////////////////////////////////////////////////////// |
| 511 | |
Brian Salomon | 3176e86 | 2021-08-09 11:23:04 -0400 | [diff] [blame] | 512 | class GLEllipticalRRectEffect : public GrFragmentProcessor::ProgramImpl { |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 513 | public: |
Brian Salomon | 0a241ce | 2017-12-15 11:31:05 -0500 | [diff] [blame] | 514 | GLEllipticalRRectEffect() = default; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 515 | |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 516 | void emitCode(EmitArgs&) override; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 517 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 518 | static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*); |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 519 | |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 520 | protected: |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 521 | void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 522 | |
| 523 | private: |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 524 | GrGLSLProgramDataManager::UniformHandle fInnerRectUniform; |
| 525 | GrGLSLProgramDataManager::UniformHandle fInvRadiiSqdUniform; |
bsalomon | e87256c4 | 2015-12-09 17:14:40 -0800 | [diff] [blame] | 526 | GrGLSLProgramDataManager::UniformHandle fScaleUniform; |
| 527 | SkRRect fPrevRRect; |
Brian Salomon | 3176e86 | 2021-08-09 11:23:04 -0400 | [diff] [blame] | 528 | using INHERITED = ProgramImpl; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 529 | }; |
| 530 | |
wangyix | 7c157a9 | 2015-07-22 15:08:53 -0700 | [diff] [blame] | 531 | void GLEllipticalRRectEffect::emitCode(EmitArgs& args) { |
| 532 | const EllipticalRRectEffect& erre = args.fFp.cast<EllipticalRRectEffect>(); |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 533 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 534 | const char *rectName; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 535 | // The inner rect is the rrect bounds inset by the x/y radii |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 536 | fInnerRectUniform = uniformHandler->addUniform(&erre, kFragment_GrShaderFlag, kFloat4_GrSLType, |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 537 | "innerRect", &rectName); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 538 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 539 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 540 | // At each quarter-ellipse corner we compute a vector that is the offset of the fragment pos |
| 541 | // to the ellipse center. The vector is pinned in x and y to be in the quarter-plane relevant |
| 542 | // to that corner. This means that points near the interior near the rrect top edge will have |
| 543 | // a vector that points straight up for both the TL left and TR corners. Computing an |
| 544 | // alpha from this vector at either the TR or TL corner will give the correct result. Similarly, |
| 545 | // fragments near the other three edges will get the correct AA. Fragments in the interior of |
| 546 | // the rrect will have a (0,0) vector at all four corners. So long as the radii > 0.5 they will |
| 547 | // correctly produce an alpha value of 1 at all four corners. We take the min of all the alphas. |
bsalomon | c41f4d6 | 2015-08-03 14:23:03 -0700 | [diff] [blame] | 548 | // |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 549 | // The code below is a simplified version of the above that performs maxs on the vector |
| 550 | // components before computing distances and alpha values so that only one distance computation |
| 551 | // need be computed to determine the min alpha. |
John Stiles | c0d5d9c | 2020-06-15 15:57:25 -0400 | [diff] [blame] | 552 | fragBuilder->codeAppendf("float2 dxy0 = %s.LT - sk_FragCoord.xy;", rectName); |
| 553 | fragBuilder->codeAppendf("float2 dxy1 = sk_FragCoord.xy - %s.RB;", rectName); |
bsalomon | e87256c4 | 2015-12-09 17:14:40 -0800 | [diff] [blame] | 554 | |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 555 | // If we're on a device where float != fp32 then we'll do the distance computation in a space |
bsalomon | e87256c4 | 2015-12-09 17:14:40 -0800 | [diff] [blame] | 556 | // that is normalized by the largest radius. The scale uniform will be scale, 1/scale. The |
| 557 | // radii uniform values are already in this normalized space. |
| 558 | const char* scaleName = nullptr; |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 559 | if (!args.fShaderCaps->floatIs32Bits()) { |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 560 | fScaleUniform = uniformHandler->addUniform(&erre, kFragment_GrShaderFlag, kHalf2_GrSLType, |
| 561 | "scale", &scaleName); |
bsalomon | e87256c4 | 2015-12-09 17:14:40 -0800 | [diff] [blame] | 562 | } |
| 563 | |
bsalomon | c41f4d6 | 2015-08-03 14:23:03 -0700 | [diff] [blame] | 564 | // The uniforms with the inv squared radii are highp to prevent underflow. |
commit-bot@chromium.org | 9615d5f | 2014-03-20 21:39:03 +0000 | [diff] [blame] | 565 | switch (erre.getRRect().getType()) { |
| 566 | case SkRRect::kSimple_Type: { |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 567 | const char *invRadiiXYSqdName; |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 568 | fInvRadiiSqdUniform = uniformHandler->addUniform(&erre, |
| 569 | kFragment_GrShaderFlag, |
Ethan Nicholas | 10e93b6 | 2019-03-20 10:46:14 -0400 | [diff] [blame] | 570 | kFloat2_GrSLType, |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 571 | "invRadiiXY", |
| 572 | &invRadiiXYSqdName); |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 573 | fragBuilder->codeAppend("float2 dxy = max(max(dxy0, dxy1), 0.0);"); |
bsalomon | e87256c4 | 2015-12-09 17:14:40 -0800 | [diff] [blame] | 574 | if (scaleName) { |
| 575 | fragBuilder->codeAppendf("dxy *= %s.y;", scaleName); |
| 576 | } |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 577 | // Z is the x/y offsets divided by squared radii. |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 578 | fragBuilder->codeAppendf("float2 Z = dxy * %s.xy;", invRadiiXYSqdName); |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 579 | break; |
| 580 | } |
commit-bot@chromium.org | 9615d5f | 2014-03-20 21:39:03 +0000 | [diff] [blame] | 581 | case SkRRect::kNinePatch_Type: { |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 582 | const char *invRadiiLTRBSqdName; |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 583 | fInvRadiiSqdUniform = uniformHandler->addUniform(&erre, |
| 584 | kFragment_GrShaderFlag, |
Ethan Nicholas | 10e93b6 | 2019-03-20 10:46:14 -0400 | [diff] [blame] | 585 | kFloat4_GrSLType, |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 586 | "invRadiiLTRB", |
| 587 | &invRadiiLTRBSqdName); |
bsalomon | e87256c4 | 2015-12-09 17:14:40 -0800 | [diff] [blame] | 588 | if (scaleName) { |
| 589 | fragBuilder->codeAppendf("dxy0 *= %s.y;", scaleName); |
| 590 | fragBuilder->codeAppendf("dxy1 *= %s.y;", scaleName); |
| 591 | } |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 592 | fragBuilder->codeAppend("float2 dxy = max(max(dxy0, dxy1), 0.0);"); |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 593 | // Z is the x/y offsets divided by squared radii. We only care about the (at most) one |
| 594 | // corner where both the x and y offsets are positive, hence the maxes. (The inverse |
| 595 | // squared radii will always be positive.) |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 596 | fragBuilder->codeAppendf("float2 Z = max(max(dxy0 * %s.xy, dxy1 * %s.zw), 0.0);", |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 597 | invRadiiLTRBSqdName, invRadiiLTRBSqdName); |
bsalomon | e87256c4 | 2015-12-09 17:14:40 -0800 | [diff] [blame] | 598 | |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 599 | break; |
commit-bot@chromium.org | 9615d5f | 2014-03-20 21:39:03 +0000 | [diff] [blame] | 600 | } |
| 601 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 602 | SK_ABORT("RRect should always be simple or nine-patch."); |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 603 | } |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 604 | // implicit is the evaluation of (x/a)^2 + (y/b)^2 - 1. |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 605 | fragBuilder->codeAppend("half implicit = half(dot(Z, dxy) - 1.0);"); |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 606 | // grad_dot is the squared length of the gradient of the implicit. |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 607 | fragBuilder->codeAppend("half grad_dot = half(4.0 * dot(Z, Z));"); |
commit-bot@chromium.org | 1b035d8 | 2014-04-09 17:11:09 +0000 | [diff] [blame] | 608 | // avoid calling inversesqrt on zero. |
bsalomon | e87256c4 | 2015-12-09 17:14:40 -0800 | [diff] [blame] | 609 | fragBuilder->codeAppend("grad_dot = max(grad_dot, 1.0e-4);"); |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 610 | fragBuilder->codeAppend("half approx_dist = implicit * half(inversesqrt(grad_dot));"); |
bsalomon | e87256c4 | 2015-12-09 17:14:40 -0800 | [diff] [blame] | 611 | if (scaleName) { |
| 612 | fragBuilder->codeAppendf("approx_dist *= %s.x;", scaleName); |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 613 | } |
| 614 | |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 615 | if (GrClipEdgeType::kFillAA == erre.getEdgeType()) { |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 616 | fragBuilder->codeAppend("half alpha = clamp(0.5 - approx_dist, 0.0, 1.0);"); |
bsalomon | e87256c4 | 2015-12-09 17:14:40 -0800 | [diff] [blame] | 617 | } else { |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 618 | fragBuilder->codeAppend("half alpha = clamp(0.5 + approx_dist, 0.0, 1.0);"); |
bsalomon | e87256c4 | 2015-12-09 17:14:40 -0800 | [diff] [blame] | 619 | } |
| 620 | |
Brian Osman | 6b5dbb4 | 2020-07-15 15:31:05 -0400 | [diff] [blame] | 621 | SkString inputSample = this->invokeChild(/*childIndex=*/0, args); |
John Stiles | c0d5d9c | 2020-06-15 15:57:25 -0400 | [diff] [blame] | 622 | |
John Stiles | 4bdc121 | 2020-12-14 18:04:13 -0500 | [diff] [blame] | 623 | fragBuilder->codeAppendf("return %s * alpha;", inputSample.c_str()); |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 624 | } |
| 625 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 626 | void GLEllipticalRRectEffect::GenKey(const GrProcessor& effect, const GrShaderCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 627 | GrProcessorKeyBuilder* b) { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 628 | const EllipticalRRectEffect& erre = effect.cast<EllipticalRRectEffect>(); |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 629 | static_assert((int)GrClipEdgeType::kLast < (1 << 3)); |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 630 | b->add32(erre.getRRect().getType() | (int) erre.getEdgeType() << 3); |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 631 | } |
| 632 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 633 | void GLEllipticalRRectEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 634 | const GrFragmentProcessor& effect) { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 635 | const EllipticalRRectEffect& erre = effect.cast<EllipticalRRectEffect>(); |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 636 | const SkRRect& rrect = erre.getRRect(); |
bsalomon | e87256c4 | 2015-12-09 17:14:40 -0800 | [diff] [blame] | 637 | // If we're using a scale factor to work around precision issues, choose the largest radius |
| 638 | // as the scale factor. The inv radii need to be pre-adjusted by the scale factor. |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 639 | if (rrect != fPrevRRect) { |
| 640 | SkRect rect = rrect.getBounds(); |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 641 | const SkVector& r0 = rrect.radii(SkRRect::kUpperLeft_Corner); |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 642 | SkASSERT(r0.fX >= kRadiusMin); |
| 643 | SkASSERT(r0.fY >= kRadiusMin); |
commit-bot@chromium.org | 9615d5f | 2014-03-20 21:39:03 +0000 | [diff] [blame] | 644 | switch (erre.getRRect().getType()) { |
| 645 | case SkRRect::kSimple_Type: |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 646 | rect.inset(r0.fX, r0.fY); |
bsalomon | e87256c4 | 2015-12-09 17:14:40 -0800 | [diff] [blame] | 647 | if (fScaleUniform.isValid()) { |
| 648 | if (r0.fX > r0.fY) { |
| 649 | pdman.set2f(fInvRadiiSqdUniform, 1.f, (r0.fX * r0.fX) / (r0.fY * r0.fY)); |
| 650 | pdman.set2f(fScaleUniform, r0.fX, 1.f / r0.fX); |
| 651 | } else { |
| 652 | pdman.set2f(fInvRadiiSqdUniform, (r0.fY * r0.fY) / (r0.fX * r0.fX), 1.f); |
| 653 | pdman.set2f(fScaleUniform, r0.fY, 1.f / r0.fY); |
| 654 | } |
| 655 | } else { |
| 656 | pdman.set2f(fInvRadiiSqdUniform, 1.f / (r0.fX * r0.fX), |
| 657 | 1.f / (r0.fY * r0.fY)); |
| 658 | } |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 659 | break; |
commit-bot@chromium.org | 9615d5f | 2014-03-20 21:39:03 +0000 | [diff] [blame] | 660 | case SkRRect::kNinePatch_Type: { |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 661 | const SkVector& r1 = rrect.radii(SkRRect::kLowerRight_Corner); |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 662 | SkASSERT(r1.fX >= kRadiusMin); |
| 663 | SkASSERT(r1.fY >= kRadiusMin); |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 664 | rect.fLeft += r0.fX; |
| 665 | rect.fTop += r0.fY; |
| 666 | rect.fRight -= r1.fX; |
| 667 | rect.fBottom -= r1.fY; |
bsalomon | e87256c4 | 2015-12-09 17:14:40 -0800 | [diff] [blame] | 668 | if (fScaleUniform.isValid()) { |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 669 | float scale = std::max(std::max(r0.fX, r0.fY), std::max(r1.fX, r1.fY)); |
bsalomon | e87256c4 | 2015-12-09 17:14:40 -0800 | [diff] [blame] | 670 | float scaleSqd = scale * scale; |
| 671 | pdman.set4f(fInvRadiiSqdUniform, scaleSqd / (r0.fX * r0.fX), |
| 672 | scaleSqd / (r0.fY * r0.fY), |
| 673 | scaleSqd / (r1.fX * r1.fX), |
| 674 | scaleSqd / (r1.fY * r1.fY)); |
| 675 | pdman.set2f(fScaleUniform, scale, 1.f / scale); |
| 676 | } else { |
| 677 | pdman.set4f(fInvRadiiSqdUniform, 1.f / (r0.fX * r0.fX), |
| 678 | 1.f / (r0.fY * r0.fY), |
| 679 | 1.f / (r1.fX * r1.fX), |
| 680 | 1.f / (r1.fY * r1.fY)); |
| 681 | } |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 682 | break; |
| 683 | } |
commit-bot@chromium.org | 9615d5f | 2014-03-20 21:39:03 +0000 | [diff] [blame] | 684 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 685 | SK_ABORT("RRect should always be simple or nine-patch."); |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 686 | } |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 687 | pdman.set4f(fInnerRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 688 | fPrevRRect = rrect; |
| 689 | } |
| 690 | } |
| 691 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 692 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 693 | |
Brian Salomon | 13b2873 | 2021-08-06 15:33:58 -0400 | [diff] [blame] | 694 | void EllipticalRRectEffect::onAddToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 695 | GLEllipticalRRectEffect::GenKey(*this, caps, b); |
| 696 | } |
| 697 | |
Brian Salomon | 3176e86 | 2021-08-09 11:23:04 -0400 | [diff] [blame] | 698 | std::unique_ptr<GrFragmentProcessor::ProgramImpl> EllipticalRRectEffect::onMakeProgramImpl() const { |
Brian Salomon | 18ab203 | 2021-02-23 10:07:05 -0500 | [diff] [blame] | 699 | return std::make_unique<GLEllipticalRRectEffect>(); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 700 | } |
| 701 | |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 702 | ////////////////////////////////////////////////////////////////////////////// |
| 703 | |
John Stiles | 72e5764 | 2020-06-24 10:42:35 -0400 | [diff] [blame] | 704 | GrFPResult GrRRectEffect::Make(std::unique_ptr<GrFragmentProcessor> inputFP, |
| 705 | GrClipEdgeType edgeType, const SkRRect& rrect, |
| 706 | const GrShaderCaps& caps) { |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 707 | if (rrect.isRect()) { |
Brian Osman | b384eb2 | 2021-06-24 15:34:08 -0400 | [diff] [blame] | 708 | auto fp = GrFragmentProcessor::Rect(std::move(inputFP), edgeType, rrect.getBounds()); |
Brian Salomon | 066f411 | 2021-02-23 10:55:22 -0500 | [diff] [blame] | 709 | return GrFPSuccess(std::move(fp)); |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 710 | } |
| 711 | |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 712 | if (rrect.isOval()) { |
John Stiles | 851b90e | 2020-06-17 13:53:37 -0400 | [diff] [blame] | 713 | return GrOvalEffect::Make(std::move(inputFP), edgeType, rrect.getBounds(), caps); |
commit-bot@chromium.org | 3eedb80 | 2014-03-28 15:58:31 +0000 | [diff] [blame] | 714 | } |
| 715 | |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 716 | if (rrect.isSimple()) { |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 717 | if (SkRRectPriv::GetSimpleRadii(rrect).fX < kRadiusMin || |
| 718 | SkRRectPriv::GetSimpleRadii(rrect).fY < kRadiusMin) { |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 719 | // In this case the corners are extremely close to rectangular and we collapse the |
| 720 | // clip to a rectangular clip. |
Brian Osman | b384eb2 | 2021-06-24 15:34:08 -0400 | [diff] [blame] | 721 | auto fp = GrFragmentProcessor::Rect(std::move(inputFP), edgeType, rrect.getBounds()); |
Brian Salomon | 066f411 | 2021-02-23 10:55:22 -0500 | [diff] [blame] | 722 | return GrFPSuccess(std::move(fp)); |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 723 | } |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 724 | if (SkRRectPriv::GetSimpleRadii(rrect).fX == SkRRectPriv::GetSimpleRadii(rrect).fY) { |
John Stiles | 851b90e | 2020-06-17 13:53:37 -0400 | [diff] [blame] | 725 | return CircularRRectEffect::Make(std::move(inputFP), edgeType, |
John Stiles | 56bf90b | 2020-06-10 17:25:58 -0400 | [diff] [blame] | 726 | CircularRRectEffect::kAll_CornerFlags, rrect); |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 727 | } else { |
John Stiles | 851b90e | 2020-06-17 13:53:37 -0400 | [diff] [blame] | 728 | return EllipticalRRectEffect::Make(std::move(inputFP), edgeType, rrect); |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 729 | } |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | if (rrect.isComplex() || rrect.isNinePatch()) { |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 733 | // Check for the "tab" cases - two adjacent circular corners and two square corners. |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 734 | SkScalar circularRadius = 0; |
| 735 | uint32_t cornerFlags = 0; |
| 736 | |
| 737 | SkVector radii[4]; |
| 738 | bool squashedRadii = false; |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 739 | for (int c = 0; c < 4; ++c) { |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 740 | radii[c] = rrect.radii((SkRRect::Corner)c); |
| 741 | SkASSERT((0 == radii[c].fX) == (0 == radii[c].fY)); |
| 742 | if (0 == radii[c].fX) { |
| 743 | // The corner is square, so no need to squash or flag as circular. |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 744 | continue; |
| 745 | } |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 746 | if (radii[c].fX < kRadiusMin || radii[c].fY < kRadiusMin) { |
| 747 | radii[c].set(0, 0); |
| 748 | squashedRadii = true; |
| 749 | continue; |
| 750 | } |
| 751 | if (radii[c].fX != radii[c].fY) { |
bsalomon@google.com | 44a435b | 2014-03-13 19:20:32 +0000 | [diff] [blame] | 752 | cornerFlags = ~0U; |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 753 | break; |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 754 | } |
commit-bot@chromium.org | dd58422 | 2014-03-10 16:08:22 +0000 | [diff] [blame] | 755 | if (!cornerFlags) { |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 756 | circularRadius = radii[c].fX; |
commit-bot@chromium.org | dd58422 | 2014-03-10 16:08:22 +0000 | [diff] [blame] | 757 | cornerFlags = 1 << c; |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 758 | } else { |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 759 | if (radii[c].fX != circularRadius) { |
bsalomon@google.com | 44a435b | 2014-03-13 19:20:32 +0000 | [diff] [blame] | 760 | cornerFlags = ~0U; |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 761 | break; |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 762 | } |
commit-bot@chromium.org | dd58422 | 2014-03-10 16:08:22 +0000 | [diff] [blame] | 763 | cornerFlags |= 1 << c; |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | |
commit-bot@chromium.org | dd58422 | 2014-03-10 16:08:22 +0000 | [diff] [blame] | 767 | switch (cornerFlags) { |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 768 | case CircularRRectEffect::kAll_CornerFlags: |
| 769 | // This rrect should have been caught in the simple case above. Though, it would |
| 770 | // be correctly handled in the fallthrough code. |
| 771 | SkASSERT(false); |
John Stiles | 30212b7 | 2020-06-11 17:55:07 -0400 | [diff] [blame] | 772 | [[fallthrough]]; |
commit-bot@chromium.org | 4355f21 | 2014-03-12 15:32:50 +0000 | [diff] [blame] | 773 | case CircularRRectEffect::kTopLeft_CornerFlag: |
| 774 | case CircularRRectEffect::kTopRight_CornerFlag: |
| 775 | case CircularRRectEffect::kBottomRight_CornerFlag: |
| 776 | case CircularRRectEffect::kBottomLeft_CornerFlag: |
| 777 | case CircularRRectEffect::kLeft_CornerFlags: |
| 778 | case CircularRRectEffect::kTop_CornerFlags: |
| 779 | case CircularRRectEffect::kRight_CornerFlags: |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 780 | case CircularRRectEffect::kBottom_CornerFlags: { |
| 781 | SkTCopyOnFirstWrite<SkRRect> rr(rrect); |
| 782 | if (squashedRadii) { |
| 783 | rr.writable()->setRectRadii(rrect.getBounds(), radii); |
| 784 | } |
John Stiles | 851b90e | 2020-06-17 13:53:37 -0400 | [diff] [blame] | 785 | return CircularRRectEffect::Make(std::move(inputFP), edgeType, cornerFlags, *rr); |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 786 | } |
John Stiles | f08a82b | 2020-06-16 16:34:12 -0400 | [diff] [blame] | 787 | case CircularRRectEffect::kNone_CornerFlags: { |
Brian Osman | b384eb2 | 2021-06-24 15:34:08 -0400 | [diff] [blame] | 788 | auto fp = |
| 789 | GrFragmentProcessor::Rect(std::move(inputFP), edgeType, rrect.getBounds()); |
Brian Salomon | 066f411 | 2021-02-23 10:55:22 -0500 | [diff] [blame] | 790 | return GrFPSuccess(std::move(fp)); |
John Stiles | f08a82b | 2020-06-16 16:34:12 -0400 | [diff] [blame] | 791 | } |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 792 | default: { |
Brian Salomon | 3465365 | 2021-07-26 13:30:06 -0400 | [diff] [blame] | 793 | const SkVector ul = rrect.radii(SkRRect::kUpperLeft_Corner); |
| 794 | const SkVector lr = rrect.radii(SkRRect::kLowerRight_Corner); |
| 795 | if (rrect.isNinePatch() && |
| 796 | ul.fX >= kRadiusMin && |
| 797 | ul.fY >= kRadiusMin && |
| 798 | lr.fX >= kRadiusMin && |
| 799 | lr.fY >= kRadiusMin) { |
John Stiles | 851b90e | 2020-06-17 13:53:37 -0400 | [diff] [blame] | 800 | return EllipticalRRectEffect::Make(std::move(inputFP), edgeType, rrect); |
commit-bot@chromium.org | fa5edbe | 2014-03-13 18:01:05 +0000 | [diff] [blame] | 801 | } |
John Stiles | 72e5764 | 2020-06-24 10:42:35 -0400 | [diff] [blame] | 802 | return GrFPFailure(std::move(inputFP)); |
commit-bot@chromium.org | 2a8be90 | 2014-03-24 19:24:59 +0000 | [diff] [blame] | 803 | } |
commit-bot@chromium.org | cb3672e | 2014-02-21 22:41:56 +0000 | [diff] [blame] | 804 | } |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 805 | } |
John Stiles | 72e5764 | 2020-06-24 10:42:35 -0400 | [diff] [blame] | 806 | return GrFPFailure(std::move(inputFP)); |
commit-bot@chromium.org | c2f7824 | 2014-02-19 15:18:05 +0000 | [diff] [blame] | 807 | } |