commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +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/core/SkPathPriv.h" |
| 9 | #include "src/gpu/effects/GrConvexPolyEffect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" |
| 11 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| 12 | #include "src/gpu/glsl/GrGLSLProgramDataManager.h" |
| 13 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
Ethan Nicholas | 9f8e9ec | 2021-02-17 14:47:52 -0500 | [diff] [blame] | 14 | #include "src/sksl/dsl/priv/DSLFPs.h" |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 15 | |
commit-bot@chromium.org | f053980 | 2014-02-08 19:31:05 +0000 | [diff] [blame] | 16 | ////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | f053980 | 2014-02-08 19:31:05 +0000 | [diff] [blame] | 17 | |
Brian Salomon | 3176e86 | 2021-08-09 11:23:04 -0400 | [diff] [blame] | 18 | class GrGLConvexPolyEffect : public GrFragmentProcessor::ProgramImpl { |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 19 | public: |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 20 | GrGLConvexPolyEffect() { |
Brian Salomon | 73a850f | 2017-03-27 10:17:38 -0400 | [diff] [blame] | 21 | for (size_t i = 0; i < SK_ARRAY_COUNT(fPrevEdges); ++i) { |
| 22 | fPrevEdges[i] = SK_ScalarNaN; |
| 23 | } |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 24 | } |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 25 | |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 26 | void emitCode(EmitArgs&) override; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 27 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 28 | static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 29 | |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 30 | protected: |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 31 | void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 32 | |
| 33 | private: |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 34 | GrGLSLProgramDataManager::UniformHandle fEdgeUniform; |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 35 | SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMaxEdges]; |
Brian Salomon | 3176e86 | 2021-08-09 11:23:04 -0400 | [diff] [blame] | 36 | using INHERITED = ProgramImpl; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
wangyix | 7c157a9 | 2015-07-22 15:08:53 -0700 | [diff] [blame] | 39 | void GrGLConvexPolyEffect::emitCode(EmitArgs& args) { |
| 40 | const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>(); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 41 | |
Ethan Nicholas | 9f8e9ec | 2021-02-17 14:47:52 -0500 | [diff] [blame] | 42 | using namespace SkSL::dsl; |
| 43 | StartFragmentProcessor(this, &args); |
Ethan Nicholas | a2d22b2 | 2021-07-15 10:35:54 -0400 | [diff] [blame] | 44 | GlobalVar edgeArray(kUniform_Modifier, Array(kHalf3_Type, cpe.getEdgeCount()), "edgeArray"); |
| 45 | Declare(edgeArray); |
Ethan Nicholas | 9f8e9ec | 2021-02-17 14:47:52 -0500 | [diff] [blame] | 46 | fEdgeUniform = VarUniformHandle(edgeArray); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 47 | Var alpha(kHalf_Type, "alpha", 1); |
Ethan Nicholas | fe5d692 | 2021-03-05 14:23:48 -0500 | [diff] [blame] | 48 | Declare(alpha); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 49 | Var edge(kHalf_Type, "edge"); |
Ethan Nicholas | 9f8e9ec | 2021-02-17 14:47:52 -0500 | [diff] [blame] | 50 | Declare(edge); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 51 | for (int i = 0; i < cpe.getEdgeCount(); ++i) { |
Ethan Nicholas | 9f8e9ec | 2021-02-17 14:47:52 -0500 | [diff] [blame] | 52 | edge = Dot(edgeArray[i], Half3(Swizzle(sk_FragCoord(), X, Y, ONE))); |
Brian Osman | 50f0dad | 2021-07-08 13:47:25 -0400 | [diff] [blame] | 53 | if (GrClipEdgeTypeIsAA(cpe.getEdgeType())) { |
Ethan Nicholas | 9f8e9ec | 2021-02-17 14:47:52 -0500 | [diff] [blame] | 54 | edge = Saturate(edge); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 55 | } else { |
Ethan Nicholas | 9f8e9ec | 2021-02-17 14:47:52 -0500 | [diff] [blame] | 56 | edge = Select(edge >= 0.5, 1.0, 0.0); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 57 | } |
Ethan Nicholas | 9f8e9ec | 2021-02-17 14:47:52 -0500 | [diff] [blame] | 58 | alpha *= edge; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Brian Osman | 50f0dad | 2021-07-08 13:47:25 -0400 | [diff] [blame] | 61 | if (GrClipEdgeTypeIsInverseFill(cpe.getEdgeType())) { |
Ethan Nicholas | 9f8e9ec | 2021-02-17 14:47:52 -0500 | [diff] [blame] | 62 | alpha = 1.0 - alpha; |
commit-bot@chromium.org | d85f32c | 2014-02-28 14:43:26 +0000 | [diff] [blame] | 63 | } |
John Stiles | ec9269b | 2020-06-15 16:05:14 -0400 | [diff] [blame] | 64 | |
Ethan Nicholas | 9f8e9ec | 2021-02-17 14:47:52 -0500 | [diff] [blame] | 65 | Return(SampleChild(0) * alpha); |
| 66 | EndFragmentProcessor(); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 67 | } |
| 68 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 69 | void GrGLConvexPolyEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 70 | const GrFragmentProcessor& effect) { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 71 | const GrConvexPolyEffect& cpe = effect.cast<GrConvexPolyEffect>(); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 72 | size_t byteSize = 3 * cpe.getEdgeCount() * sizeof(SkScalar); |
| 73 | if (0 != memcmp(fPrevEdges, cpe.getEdges(), byteSize)) { |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 74 | pdman.set3fv(fEdgeUniform, cpe.getEdgeCount(), cpe.getEdges()); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 75 | memcpy(fPrevEdges, cpe.getEdges(), byteSize); |
| 76 | } |
| 77 | } |
| 78 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 79 | void GrGLConvexPolyEffect::GenKey(const GrProcessor& processor, const GrShaderCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 80 | GrProcessorKeyBuilder* b) { |
| 81 | const GrConvexPolyEffect& cpe = processor.cast<GrConvexPolyEffect>(); |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 82 | static_assert(kGrClipEdgeTypeCnt <= 8); |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 83 | uint32_t key = (cpe.getEdgeCount() << 3) | (int) cpe.getEdgeType(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 84 | b->add32(key); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | ////////////////////////////////////////////////////////////////////////////// |
| 88 | |
John Stiles | 72e5764 | 2020-06-24 10:42:35 -0400 | [diff] [blame] | 89 | GrFPResult GrConvexPolyEffect::Make(std::unique_ptr<GrFragmentProcessor> inputFP, |
| 90 | GrClipEdgeType type, const SkPath& path) { |
John Stiles | f08a82b | 2020-06-16 16:34:12 -0400 | [diff] [blame] | 91 | if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || !path.isConvex()) { |
John Stiles | 72e5764 | 2020-06-24 10:42:35 -0400 | [diff] [blame] | 92 | return GrFPFailure(std::move(inputFP)); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Mike Reed | 85f51b2 | 2020-08-30 10:32:06 -0400 | [diff] [blame] | 95 | SkPathFirstDirection dir = SkPathPriv::ComputeFirstDirection(path); |
bsalomon | 7888de0 | 2016-03-28 15:04:45 -0700 | [diff] [blame] | 96 | // The only way this should fail is if the clip is effectively a infinitely thin line. In that |
| 97 | // case nothing is inside the clip. It'd be nice to detect this at a higher level and either |
| 98 | // skip the draw or omit the clip element. |
Mike Reed | 85f51b2 | 2020-08-30 10:32:06 -0400 | [diff] [blame] | 99 | if (dir == SkPathFirstDirection::kUnknown) { |
Brian Osman | 50f0dad | 2021-07-08 13:47:25 -0400 | [diff] [blame] | 100 | if (GrClipEdgeTypeIsInverseFill(type)) { |
John Stiles | 8589430 | 2020-07-13 11:39:52 -0400 | [diff] [blame] | 101 | return GrFPSuccess( |
| 102 | GrFragmentProcessor::ModulateRGBA(std::move(inputFP), SK_PMColor4fWHITE)); |
bsalomon | 7888de0 | 2016-03-28 15:04:45 -0700 | [diff] [blame] | 103 | } |
John Stiles | 7c19677 | 2020-07-13 10:00:16 -0400 | [diff] [blame] | 104 | // This could use ConstColor instead of ModulateRGBA but it would trigger a debug print |
Brian Salomon | eb62829 | 2017-02-15 14:12:26 -0500 | [diff] [blame] | 105 | // about a coverage processor not being compatible with the alpha-as-coverage optimization. |
John Stiles | 7c19677 | 2020-07-13 10:00:16 -0400 | [diff] [blame] | 106 | // We don't really care about this unlikely case so we just use ModulateRGBA to suppress |
Brian Salomon | eb62829 | 2017-02-15 14:12:26 -0500 | [diff] [blame] | 107 | // the print. |
John Stiles | 8589430 | 2020-07-13 11:39:52 -0400 | [diff] [blame] | 108 | return GrFPSuccess( |
| 109 | GrFragmentProcessor::ModulateRGBA(std::move(inputFP), SK_PMColor4fTRANSPARENT)); |
bsalomon | 7888de0 | 2016-03-28 15:04:45 -0700 | [diff] [blame] | 110 | } |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 111 | |
lsalzman | d15947e | 2016-05-31 09:46:00 -0700 | [diff] [blame] | 112 | SkScalar edges[3 * kMaxEdges]; |
| 113 | SkPoint pts[4]; |
| 114 | SkPath::Verb verb; |
| 115 | SkPath::Iter iter(path, true); |
| 116 | |
| 117 | // SkPath considers itself convex so long as there is a convex contour within it, |
| 118 | // regardless of any degenerate contours such as a string of moveTos before it. |
| 119 | // Iterate here to consume any degenerate contours and only process the points |
| 120 | // on the actual convex contour. |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 121 | int n = 0; |
Mike Reed | ba7e9a6 | 2019-08-16 13:30:34 -0400 | [diff] [blame] | 122 | while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
lsalzman | d15947e | 2016-05-31 09:46:00 -0700 | [diff] [blame] | 123 | switch (verb) { |
| 124 | case SkPath::kMove_Verb: |
lsalzman | d15947e | 2016-05-31 09:46:00 -0700 | [diff] [blame] | 125 | case SkPath::kClose_Verb: |
| 126 | break; |
| 127 | case SkPath::kLine_Verb: { |
| 128 | if (n >= kMaxEdges) { |
John Stiles | 72e5764 | 2020-06-24 10:42:35 -0400 | [diff] [blame] | 129 | return GrFPFailure(std::move(inputFP)); |
lsalzman | d15947e | 2016-05-31 09:46:00 -0700 | [diff] [blame] | 130 | } |
Mike Reed | ba7e9a6 | 2019-08-16 13:30:34 -0400 | [diff] [blame] | 131 | if (pts[0] != pts[1]) { |
| 132 | SkVector v = pts[1] - pts[0]; |
| 133 | v.normalize(); |
Mike Reed | 3872c98 | 2020-08-29 17:46:51 -0400 | [diff] [blame] | 134 | if (SkPathFirstDirection::kCCW == dir) { |
Mike Reed | ba7e9a6 | 2019-08-16 13:30:34 -0400 | [diff] [blame] | 135 | edges[3 * n] = v.fY; |
| 136 | edges[3 * n + 1] = -v.fX; |
| 137 | } else { |
| 138 | edges[3 * n] = -v.fY; |
| 139 | edges[3 * n + 1] = v.fX; |
| 140 | } |
| 141 | edges[3 * n + 2] = -(edges[3 * n] * pts[1].fX + edges[3 * n + 1] * pts[1].fY); |
| 142 | ++n; |
lsalzman | d15947e | 2016-05-31 09:46:00 -0700 | [diff] [blame] | 143 | } |
lsalzman | d15947e | 2016-05-31 09:46:00 -0700 | [diff] [blame] | 144 | break; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 145 | } |
lsalzman | d15947e | 2016-05-31 09:46:00 -0700 | [diff] [blame] | 146 | default: |
Brian Salomon | 6b5b7e7 | 2021-05-17 10:37:04 -0400 | [diff] [blame] | 147 | // Non-linear segment so not a polygon. |
John Stiles | 72e5764 | 2020-06-24 10:42:35 -0400 | [diff] [blame] | 148 | return GrFPFailure(std::move(inputFP)); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 149 | } |
| 150 | } |
lsalzman | d15947e | 2016-05-31 09:46:00 -0700 | [diff] [blame] | 151 | |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 152 | if (path.isInverseFillType()) { |
Brian Osman | 50f0dad | 2021-07-08 13:47:25 -0400 | [diff] [blame] | 153 | type = GrInvertClipEdgeType(type); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 154 | } |
John Stiles | f08a82b | 2020-06-16 16:34:12 -0400 | [diff] [blame] | 155 | return GrConvexPolyEffect::Make(std::move(inputFP), type, n, edges); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | GrConvexPolyEffect::~GrConvexPolyEffect() {} |
| 159 | |
Brian Salomon | 13b2873 | 2021-08-06 15:33:58 -0400 | [diff] [blame] | 160 | void GrConvexPolyEffect::onAddToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 161 | GrGLConvexPolyEffect::GenKey(*this, caps, b); |
| 162 | } |
| 163 | |
Brian Salomon | 3176e86 | 2021-08-09 11:23:04 -0400 | [diff] [blame] | 164 | std::unique_ptr<GrFragmentProcessor::ProgramImpl> GrConvexPolyEffect::onMakeProgramImpl() const { |
Brian Salomon | 18ab203 | 2021-02-23 10:07:05 -0500 | [diff] [blame] | 165 | return std::make_unique<GrGLConvexPolyEffect>(); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 166 | } |
| 167 | |
John Stiles | ec9269b | 2020-06-15 16:05:14 -0400 | [diff] [blame] | 168 | GrConvexPolyEffect::GrConvexPolyEffect(std::unique_ptr<GrFragmentProcessor> inputFP, |
Brian Osman | 8c281fb | 2021-04-29 15:16:11 -0400 | [diff] [blame] | 169 | GrClipEdgeType edgeType, |
| 170 | int n, |
| 171 | const SkScalar edges[]) |
| 172 | : INHERITED(kGrConvexPolyEffect_ClassID, |
| 173 | ProcessorOptimizationFlags(inputFP.get()) & |
| 174 | kCompatibleWithCoverageAsAlpha_OptimizationFlag) |
Brian Salomon | f3b995b | 2017-02-15 10:22:23 -0500 | [diff] [blame] | 175 | , fEdgeType(edgeType) |
| 176 | , fEdgeCount(n) { |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 177 | // Factory function should have already ensured this. |
| 178 | SkASSERT(n <= kMaxEdges); |
| 179 | memcpy(fEdges, edges, 3 * n * sizeof(SkScalar)); |
| 180 | // Outset the edges by 0.5 so that a pixel with center on an edge is 50% covered in the AA case |
| 181 | // and 100% covered in the non-AA case. |
| 182 | for (int i = 0; i < n; ++i) { |
| 183 | fEdges[3 * i + 2] += SK_ScalarHalf; |
| 184 | } |
John Stiles | ec9269b | 2020-06-15 16:05:14 -0400 | [diff] [blame] | 185 | |
Brian Osman | 54867de | 2020-07-10 14:22:57 -0400 | [diff] [blame] | 186 | this->registerChild(std::move(inputFP)); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Brian Salomon | fcc527b | 2017-07-26 12:21:21 -0400 | [diff] [blame] | 189 | GrConvexPolyEffect::GrConvexPolyEffect(const GrConvexPolyEffect& that) |
John Stiles | 307f8f5 | 2021-08-09 15:36:59 -0400 | [diff] [blame] | 190 | : INHERITED(that) |
Brian Salomon | fcc527b | 2017-07-26 12:21:21 -0400 | [diff] [blame] | 191 | , fEdgeType(that.fEdgeType) |
| 192 | , fEdgeCount(that.fEdgeCount) { |
Brian Salomon | fcc527b | 2017-07-26 12:21:21 -0400 | [diff] [blame] | 193 | memcpy(fEdges, that.fEdges, 3 * that.fEdgeCount * sizeof(SkScalar)); |
| 194 | } |
| 195 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 196 | std::unique_ptr<GrFragmentProcessor> GrConvexPolyEffect::clone() const { |
| 197 | return std::unique_ptr<GrFragmentProcessor>(new GrConvexPolyEffect(*this)); |
Brian Salomon | fcc527b | 2017-07-26 12:21:21 -0400 | [diff] [blame] | 198 | } |
| 199 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 200 | bool GrConvexPolyEffect::onIsEqual(const GrFragmentProcessor& other) const { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 201 | const GrConvexPolyEffect& cpe = other.cast<GrConvexPolyEffect>(); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 202 | // ignore the fact that 0 == -0 and just use memcmp. |
| 203 | return (cpe.fEdgeType == fEdgeType && cpe.fEdgeCount == fEdgeCount && |
| 204 | 0 == memcmp(cpe.fEdges, fEdges, 3 * fEdgeCount * sizeof(SkScalar))); |
| 205 | } |
| 206 | |
| 207 | ////////////////////////////////////////////////////////////////////////////// |
| 208 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 209 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConvexPolyEffect); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 210 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 211 | #if GR_TEST_UTILS |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 212 | std::unique_ptr<GrFragmentProcessor> GrConvexPolyEffect::TestCreate(GrProcessorTestData* d) { |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 213 | int count = d->fRandom->nextULessThan(kMaxEdges) + 1; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 214 | SkScalar edges[kMaxEdges * 3]; |
| 215 | for (int i = 0; i < 3 * count; ++i) { |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 216 | edges[i] = d->fRandom->nextSScalar1(); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 217 | } |
| 218 | |
John Stiles | 6609cb6 | 2020-07-17 14:52:12 -0400 | [diff] [blame] | 219 | bool success; |
| 220 | std::unique_ptr<GrFragmentProcessor> fp = d->inputFP(); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 221 | do { |
John Stiles | 6609cb6 | 2020-07-17 14:52:12 -0400 | [diff] [blame] | 222 | GrClipEdgeType edgeType = |
| 223 | static_cast<GrClipEdgeType>(d->fRandom->nextULessThan(kGrClipEdgeTypeCnt)); |
| 224 | std::tie(success, fp) = GrConvexPolyEffect::Make(std::move(fp), edgeType, count, edges); |
| 225 | } while (!success); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 226 | return fp; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 227 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 228 | #endif |