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" |
| 10 | #include "src/gpu/effects/generated/GrAARectEffect.h" |
| 11 | #include "src/gpu/effects/generated/GrConstColorProcessor.h" |
| 12 | #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" |
| 13 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| 14 | #include "src/gpu/glsl/GrGLSLProgramDataManager.h" |
| 15 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 16 | |
commit-bot@chromium.org | f053980 | 2014-02-08 19:31:05 +0000 | [diff] [blame] | 17 | ////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | f053980 | 2014-02-08 19:31:05 +0000 | [diff] [blame] | 18 | |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 19 | class GrGLConvexPolyEffect : public GrGLSLFragmentProcessor { |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 20 | public: |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 21 | GrGLConvexPolyEffect() { |
Brian Salomon | 73a850f | 2017-03-27 10:17:38 -0400 | [diff] [blame] | 22 | for (size_t i = 0; i < SK_ARRAY_COUNT(fPrevEdges); ++i) { |
| 23 | fPrevEdges[i] = SK_ScalarNaN; |
| 24 | } |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 25 | } |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 26 | |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 27 | void emitCode(EmitArgs&) override; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 28 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 29 | static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 30 | |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 31 | protected: |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 32 | void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 33 | |
| 34 | private: |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 35 | GrGLSLProgramDataManager::UniformHandle fEdgeUniform; |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 36 | SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMaxEdges]; |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 37 | typedef GrGLSLFragmentProcessor INHERITED; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
wangyix | 7c157a9 | 2015-07-22 15:08:53 -0700 | [diff] [blame] | 40 | void GrGLConvexPolyEffect::emitCode(EmitArgs& args) { |
| 41 | const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>(); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 42 | |
| 43 | const char *edgeArrayName; |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 44 | fEdgeUniform = args.fUniformHandler->addUniformArray(kFragment_GrShaderFlag, |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 45 | kHalf3_GrSLType, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 46 | "edges", |
| 47 | cpe.getEdgeCount(), |
| 48 | &edgeArrayName); |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 49 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 50 | fragBuilder->codeAppend("\t\thalf alpha = 1.0;\n"); |
| 51 | fragBuilder->codeAppend("\t\thalf edge;\n"); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 52 | for (int i = 0; i < cpe.getEdgeCount(); ++i) { |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 53 | fragBuilder->codeAppendf("\t\tedge = dot(%s[%d], half3(half(sk_FragCoord.x), " |
| 54 | "half(sk_FragCoord.y), " |
| 55 | "1));\n", |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 56 | edgeArrayName, i); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 57 | if (GrProcessorEdgeTypeIsAA(cpe.getEdgeType())) { |
Ethan Nicholas | 12fb9cf | 2018-08-03 16:16:57 -0400 | [diff] [blame] | 58 | fragBuilder->codeAppend("\t\tedge = saturate(edge);\n"); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 59 | } else { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 60 | fragBuilder->codeAppend("\t\tedge = edge >= 0.5 ? 1.0 : 0.0;\n"); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 61 | } |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 62 | fragBuilder->codeAppend("\t\talpha *= edge;\n"); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 63 | } |
| 64 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 65 | if (GrProcessorEdgeTypeIsInverseFill(cpe.getEdgeType())) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 66 | fragBuilder->codeAppend("\talpha = 1.0 - alpha;\n"); |
commit-bot@chromium.org | d85f32c | 2014-02-28 14:43:26 +0000 | [diff] [blame] | 67 | } |
Ethan Nicholas | 2983f40 | 2017-05-08 09:36:08 -0400 | [diff] [blame] | 68 | fragBuilder->codeAppendf("\t%s = %s * alpha;\n", args.fOutputColor, args.fInputColor); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 69 | } |
| 70 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 71 | void GrGLConvexPolyEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 72 | const GrFragmentProcessor& effect) { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 73 | const GrConvexPolyEffect& cpe = effect.cast<GrConvexPolyEffect>(); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 74 | size_t byteSize = 3 * cpe.getEdgeCount() * sizeof(SkScalar); |
| 75 | if (0 != memcmp(fPrevEdges, cpe.getEdges(), byteSize)) { |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 76 | pdman.set3fv(fEdgeUniform, cpe.getEdgeCount(), cpe.getEdges()); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 77 | memcpy(fPrevEdges, cpe.getEdges(), byteSize); |
| 78 | } |
| 79 | } |
| 80 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 81 | void GrGLConvexPolyEffect::GenKey(const GrProcessor& processor, const GrShaderCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 82 | GrProcessorKeyBuilder* b) { |
| 83 | const GrConvexPolyEffect& cpe = processor.cast<GrConvexPolyEffect>(); |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 84 | GR_STATIC_ASSERT(kGrClipEdgeTypeCnt <= 8); |
| 85 | uint32_t key = (cpe.getEdgeCount() << 3) | (int) cpe.getEdgeType(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 86 | b->add32(key); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | ////////////////////////////////////////////////////////////////////////////// |
| 90 | |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 91 | std::unique_ptr<GrFragmentProcessor> GrConvexPolyEffect::Make(GrClipEdgeType type, |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 92 | const SkPath& path) { |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 93 | if (GrClipEdgeType::kHairlineAA == type) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 94 | return nullptr; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 95 | } |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 96 | if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 97 | !path.isConvex()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 98 | return nullptr; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 99 | } |
| 100 | |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 101 | SkPathPriv::FirstDirection dir; |
bsalomon | 7888de0 | 2016-03-28 15:04:45 -0700 | [diff] [blame] | 102 | // The only way this should fail is if the clip is effectively a infinitely thin line. In that |
| 103 | // case nothing is inside the clip. It'd be nice to detect this at a higher level and either |
| 104 | // skip the draw or omit the clip element. |
| 105 | if (!SkPathPriv::CheapComputeFirstDirection(path, &dir)) { |
| 106 | if (GrProcessorEdgeTypeIsInverseFill(type)) { |
Brian Osman | f28e55d | 2018-10-03 16:35:54 -0400 | [diff] [blame] | 107 | return GrConstColorProcessor::Make(SK_PMColor4fWHITE, |
Ethan Nicholas | e9d172a | 2017-11-20 12:12:24 -0500 | [diff] [blame] | 108 | GrConstColorProcessor::InputMode::kModulateRGBA); |
bsalomon | 7888de0 | 2016-03-28 15:04:45 -0700 | [diff] [blame] | 109 | } |
Brian Salomon | eb62829 | 2017-02-15 14:12:26 -0500 | [diff] [blame] | 110 | // This could use kIgnore instead of kModulateRGBA but it would trigger a debug print |
| 111 | // about a coverage processor not being compatible with the alpha-as-coverage optimization. |
| 112 | // We don't really care about this unlikely case so we just use kModulateRGBA to suppress |
| 113 | // the print. |
Brian Osman | f28e55d | 2018-10-03 16:35:54 -0400 | [diff] [blame] | 114 | return GrConstColorProcessor::Make(SK_PMColor4fTRANSPARENT, |
Ethan Nicholas | e9d172a | 2017-11-20 12:12:24 -0500 | [diff] [blame] | 115 | GrConstColorProcessor::InputMode::kModulateRGBA); |
bsalomon | 7888de0 | 2016-03-28 15:04:45 -0700 | [diff] [blame] | 116 | } |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 117 | |
lsalzman | d15947e | 2016-05-31 09:46:00 -0700 | [diff] [blame] | 118 | SkScalar edges[3 * kMaxEdges]; |
| 119 | SkPoint pts[4]; |
| 120 | SkPath::Verb verb; |
| 121 | SkPath::Iter iter(path, true); |
| 122 | |
| 123 | // SkPath considers itself convex so long as there is a convex contour within it, |
| 124 | // regardless of any degenerate contours such as a string of moveTos before it. |
| 125 | // Iterate here to consume any degenerate contours and only process the points |
| 126 | // on the actual convex contour. |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 127 | int n = 0; |
Mike Reed | ba7e9a6 | 2019-08-16 13:30:34 -0400 | [diff] [blame] | 128 | while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
lsalzman | d15947e | 2016-05-31 09:46:00 -0700 | [diff] [blame] | 129 | switch (verb) { |
| 130 | case SkPath::kMove_Verb: |
| 131 | SkASSERT(n == 0); |
| 132 | case SkPath::kClose_Verb: |
| 133 | break; |
| 134 | case SkPath::kLine_Verb: { |
| 135 | if (n >= kMaxEdges) { |
| 136 | return nullptr; |
| 137 | } |
Mike Reed | ba7e9a6 | 2019-08-16 13:30:34 -0400 | [diff] [blame] | 138 | if (pts[0] != pts[1]) { |
| 139 | SkVector v = pts[1] - pts[0]; |
| 140 | v.normalize(); |
| 141 | if (SkPathPriv::kCCW_FirstDirection == dir) { |
| 142 | edges[3 * n] = v.fY; |
| 143 | edges[3 * n + 1] = -v.fX; |
| 144 | } else { |
| 145 | edges[3 * n] = -v.fY; |
| 146 | edges[3 * n + 1] = v.fX; |
| 147 | } |
| 148 | edges[3 * n + 2] = -(edges[3 * n] * pts[1].fX + edges[3 * n + 1] * pts[1].fY); |
| 149 | ++n; |
lsalzman | d15947e | 2016-05-31 09:46:00 -0700 | [diff] [blame] | 150 | } |
lsalzman | d15947e | 2016-05-31 09:46:00 -0700 | [diff] [blame] | 151 | break; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 152 | } |
lsalzman | d15947e | 2016-05-31 09:46:00 -0700 | [diff] [blame] | 153 | default: |
| 154 | return nullptr; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 155 | } |
| 156 | } |
lsalzman | d15947e | 2016-05-31 09:46:00 -0700 | [diff] [blame] | 157 | |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 158 | if (path.isInverseFillType()) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 159 | type = GrInvertProcessorEdgeType(type); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 160 | } |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 161 | return Make(type, n, edges); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 164 | std::unique_ptr<GrFragmentProcessor> GrConvexPolyEffect::Make(GrClipEdgeType edgeType, |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 165 | const SkRect& rect) { |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 166 | if (GrClipEdgeType::kHairlineAA == edgeType){ |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 167 | return nullptr; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 168 | } |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 169 | return GrAARectEffect::Make(edgeType, rect); |
commit-bot@chromium.org | f053980 | 2014-02-08 19:31:05 +0000 | [diff] [blame] | 170 | } |
| 171 | |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 172 | GrConvexPolyEffect::~GrConvexPolyEffect() {} |
| 173 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 174 | void GrConvexPolyEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 175 | GrProcessorKeyBuilder* b) const { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 176 | GrGLConvexPolyEffect::GenKey(*this, caps, b); |
| 177 | } |
| 178 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 179 | GrGLSLFragmentProcessor* GrConvexPolyEffect::onCreateGLSLInstance() const { |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 180 | return new GrGLConvexPolyEffect; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 183 | GrConvexPolyEffect::GrConvexPolyEffect(GrClipEdgeType edgeType, int n, const SkScalar edges[]) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 184 | : INHERITED(kGrConvexPolyEffect_ClassID, kCompatibleWithCoverageAsAlpha_OptimizationFlag) |
Brian Salomon | f3b995b | 2017-02-15 10:22:23 -0500 | [diff] [blame] | 185 | , fEdgeType(edgeType) |
| 186 | , fEdgeCount(n) { |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 187 | // Factory function should have already ensured this. |
| 188 | SkASSERT(n <= kMaxEdges); |
| 189 | memcpy(fEdges, edges, 3 * n * sizeof(SkScalar)); |
| 190 | // Outset the edges by 0.5 so that a pixel with center on an edge is 50% covered in the AA case |
| 191 | // and 100% covered in the non-AA case. |
| 192 | for (int i = 0; i < n; ++i) { |
| 193 | fEdges[3 * i + 2] += SK_ScalarHalf; |
| 194 | } |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Brian Salomon | fcc527b | 2017-07-26 12:21:21 -0400 | [diff] [blame] | 197 | GrConvexPolyEffect::GrConvexPolyEffect(const GrConvexPolyEffect& that) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 198 | : INHERITED(kGrConvexPolyEffect_ClassID, kCompatibleWithCoverageAsAlpha_OptimizationFlag) |
Brian Salomon | fcc527b | 2017-07-26 12:21:21 -0400 | [diff] [blame] | 199 | , fEdgeType(that.fEdgeType) |
| 200 | , fEdgeCount(that.fEdgeCount) { |
Brian Salomon | fcc527b | 2017-07-26 12:21:21 -0400 | [diff] [blame] | 201 | memcpy(fEdges, that.fEdges, 3 * that.fEdgeCount * sizeof(SkScalar)); |
| 202 | } |
| 203 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 204 | std::unique_ptr<GrFragmentProcessor> GrConvexPolyEffect::clone() const { |
| 205 | return std::unique_ptr<GrFragmentProcessor>(new GrConvexPolyEffect(*this)); |
Brian Salomon | fcc527b | 2017-07-26 12:21:21 -0400 | [diff] [blame] | 206 | } |
| 207 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 208 | bool GrConvexPolyEffect::onIsEqual(const GrFragmentProcessor& other) const { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 209 | const GrConvexPolyEffect& cpe = other.cast<GrConvexPolyEffect>(); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 210 | // ignore the fact that 0 == -0 and just use memcmp. |
| 211 | return (cpe.fEdgeType == fEdgeType && cpe.fEdgeCount == fEdgeCount && |
| 212 | 0 == memcmp(cpe.fEdges, fEdges, 3 * fEdgeCount * sizeof(SkScalar))); |
| 213 | } |
| 214 | |
| 215 | ////////////////////////////////////////////////////////////////////////////// |
| 216 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 217 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConvexPolyEffect); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 218 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 219 | #if GR_TEST_UTILS |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 220 | std::unique_ptr<GrFragmentProcessor> GrConvexPolyEffect::TestCreate(GrProcessorTestData* d) { |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 221 | int count = d->fRandom->nextULessThan(kMaxEdges) + 1; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 222 | SkScalar edges[kMaxEdges * 3]; |
| 223 | for (int i = 0; i < 3 * count; ++i) { |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 224 | edges[i] = d->fRandom->nextSScalar1(); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 227 | std::unique_ptr<GrFragmentProcessor> fp; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 228 | do { |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 229 | GrClipEdgeType edgeType = static_cast<GrClipEdgeType>( |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 230 | d->fRandom->nextULessThan(kGrClipEdgeTypeCnt)); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 231 | fp = GrConvexPolyEffect::Make(edgeType, count, edges); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 232 | } while (nullptr == fp); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 233 | return fp; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 234 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 235 | #endif |