commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | |
| 8 | // This test only works with the GPU backend. |
| 9 | |
| 10 | #include "gm.h" |
Chris Dalton | 1d4af54 | 2018-04-16 14:23:00 -0600 | [diff] [blame] | 11 | #include "sk_tool_utils.h" |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 12 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 13 | #if SK_SUPPORT_GPU |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 14 | |
| 15 | #include "GrContext.h" |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 16 | #include "GrOpFlushState.h" |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 17 | #include "GrPathUtils.h" |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 18 | #include "GrRenderTargetContextPriv.h" |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 19 | #include "GrTest.h" |
| 20 | #include "SkColorPriv.h" |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 21 | #include "SkGeometry.h" |
Cary Clark | e4442cb | 2017-10-18 11:46:18 -0400 | [diff] [blame] | 22 | #include "SkPoint3.h" |
Cary Clark | 74f623d | 2017-11-06 20:02:02 -0500 | [diff] [blame] | 23 | #include "SkPointPriv.h" |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 24 | #include "effects/GrBezierEffect.h" |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 25 | #include "ops/GrMeshDrawOp.h" |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 26 | |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 27 | namespace skiagm { |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 28 | |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 29 | class BezierTestOp : public GrMeshDrawOp { |
| 30 | public: |
| 31 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
| 32 | |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 33 | RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip, |
| 34 | GrPixelConfigIsClamped dstIsClamped) override { |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 35 | auto analysis = fProcessorSet.finalize(fColor, GrProcessorAnalysisCoverage::kSingleChannel, |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 36 | clip, false, caps, dstIsClamped, &fColor); |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 37 | return analysis.requiresDstTexture() ? RequiresDstTexture::kYes : RequiresDstTexture::kNo; |
| 38 | } |
| 39 | |
Robert Phillips | f1748f5 | 2017-09-14 14:11:24 -0400 | [diff] [blame] | 40 | void visitProxies(const VisitProxyFunc& func) const override { |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 41 | fProcessorSet.visitProxies(func); |
| 42 | } |
| 43 | |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 44 | protected: |
| 45 | BezierTestOp(sk_sp<GrGeometryProcessor> gp, const SkRect& rect, GrColor color, int32_t classID) |
| 46 | : INHERITED(classID) |
| 47 | , fRect(rect) |
| 48 | , fColor(color) |
| 49 | , fGeometryProcessor(std::move(gp)) |
| 50 | , fProcessorSet(SkBlendMode::kSrc) { |
| 51 | this->setBounds(rect, HasAABloat::kYes, IsZeroArea::kNo); |
| 52 | } |
| 53 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 54 | const GrPipeline* makePipeline(Target* target) { |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 55 | return target->makePipeline(0, std::move(fProcessorSet), target->detachAppliedClip()); |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | const GrGeometryProcessor* gp() const { return fGeometryProcessor.get(); } |
| 59 | |
| 60 | const SkRect& rect() const { return fRect; } |
| 61 | GrColor color() const { return fColor; } |
| 62 | |
| 63 | private: |
| 64 | bool onCombineIfPossible(GrOp* op, const GrCaps& caps) override { return false; } |
| 65 | |
| 66 | SkRect fRect; |
| 67 | GrColor fColor; |
| 68 | sk_sp<GrGeometryProcessor> fGeometryProcessor; |
| 69 | GrProcessorSet fProcessorSet; |
| 70 | |
| 71 | typedef GrMeshDrawOp INHERITED; |
| 72 | }; |
| 73 | |
| 74 | class BezierCubicTestOp : public BezierTestOp { |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 75 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 76 | DEFINE_OP_CLASS_ID |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 77 | |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 78 | const char* name() const override { return "BezierCubicTestOp"; } |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 79 | |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 80 | static std::unique_ptr<GrDrawOp> Make(sk_sp<GrGeometryProcessor> gp, const SkRect& rect, |
| 81 | GrColor color) { |
| 82 | return std::unique_ptr<GrDrawOp>(new BezierCubicTestOp(std::move(gp), rect, color)); |
Brian Salomon | 6b316e9 | 2016-12-16 09:35:49 -0500 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | private: |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 86 | BezierCubicTestOp(sk_sp<GrGeometryProcessor> gp, const SkRect& rect, GrColor color) |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 87 | : INHERITED(std::move(gp), rect, color, ClassID()) {} |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 88 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 89 | void onPrepareDraws(Target* target) override { |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 90 | QuadHelper helper; |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 91 | size_t vertexStride = this->gp()->getVertexStride(); |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 92 | SkASSERT(vertexStride == sizeof(SkPoint)); |
| 93 | SkPoint* pts = reinterpret_cast<SkPoint*>(helper.init(target, vertexStride, 1)); |
| 94 | if (!pts) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 95 | return; |
| 96 | } |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 97 | SkRect rect = this->rect(); |
Brian Salomon | ec42e15 | 2018-05-18 12:52:22 -0400 | [diff] [blame] | 98 | SkPointPriv::SetRectTriStrip(pts, rect, vertexStride); |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 99 | helper.recordDraw(target, this->gp(), this->makePipeline(target)); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 100 | } |
| 101 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 102 | static constexpr int kVertsPerCubic = 4; |
| 103 | static constexpr int kIndicesPerCubic = 6; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 104 | |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 105 | typedef BezierTestOp INHERITED; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 106 | }; |
| 107 | |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 108 | /** |
| 109 | * This GM directly exercises effects that draw Bezier curves in the GPU backend. |
| 110 | */ |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 111 | class BezierCubicEffects : public GM { |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 112 | public: |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 113 | BezierCubicEffects() { |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 114 | this->setBGColor(0xFFFFFFFF); |
| 115 | } |
| 116 | |
| 117 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 118 | SkString onShortName() override { |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 119 | return SkString("bezier_cubic_effects"); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 120 | } |
| 121 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 122 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 123 | return SkISize::Make(800, 800); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 124 | } |
| 125 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 126 | void onDraw(SkCanvas* canvas) override { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 127 | GrRenderTargetContext* renderTargetContext = |
| 128 | canvas->internal_private_accessTopLayerRenderTargetContext(); |
| 129 | if (!renderTargetContext) { |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 130 | skiagm::GM::DrawGpuOnlyMessage(canvas); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 131 | return; |
| 132 | } |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 133 | |
robertphillips | 175dd9b | 2016-04-28 14:32:04 -0700 | [diff] [blame] | 134 | GrContext* context = canvas->getGrContext(); |
| 135 | if (!context) { |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 136 | return; |
| 137 | } |
| 138 | |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 139 | if (!context->contextPriv().caps()->shaderCaps()->floatIs32Bits()) { |
Chris Dalton | 1d4af54 | 2018-04-16 14:23:00 -0600 | [diff] [blame] | 140 | SkPaint paint; |
| 141 | sk_tool_utils::set_portable_typeface(&paint); |
| 142 | paint.setAntiAlias(true); |
| 143 | paint.setTextSize(20); |
| 144 | |
| 145 | canvas->clear(SK_ColorWHITE); |
| 146 | canvas->drawString("float != fp32", 20, 40, paint); |
| 147 | return; |
| 148 | } |
| 149 | |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 150 | struct Vertex { |
| 151 | SkPoint fPosition; |
| 152 | float fKLM[4]; // The last value is ignored. The effect expects a vec4f. |
| 153 | }; |
| 154 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 155 | constexpr int kNumCubics = 15; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 156 | SkRandom rand; |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 157 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 158 | // Mult by 3 for each edge effect type |
| 159 | int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumCubics*3))); |
| 160 | int numRows = SkScalarCeilToInt(SkIntToScalar(kNumCubics*3) / numCols); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 161 | SkScalar w = SkIntToScalar(renderTargetContext->width()) / numCols; |
| 162 | SkScalar h = SkIntToScalar(renderTargetContext->height()) / numRows; |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 163 | int row = 0; |
| 164 | int col = 0; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 165 | constexpr GrColor color = 0xff000000; |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 166 | |
| 167 | for (int i = 0; i < kNumCubics; ++i) { |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 168 | SkPoint baseControlPts[] = { |
| 169 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
| 170 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
| 171 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
| 172 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 173 | }; |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 174 | for(GrClipEdgeType edgeType : {GrClipEdgeType::kFillBW, |
| 175 | GrClipEdgeType::kFillAA, |
| 176 | GrClipEdgeType::kHairlineAA}) { |
Mike Reed | df85c38 | 2017-02-14 10:59:19 -0500 | [diff] [blame] | 177 | SkScalar x = col * w; |
| 178 | SkScalar y = row * h; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 179 | SkPoint controlPts[] = { |
| 180 | {x + baseControlPts[0].fX, y + baseControlPts[0].fY}, |
| 181 | {x + baseControlPts[1].fX, y + baseControlPts[1].fY}, |
| 182 | {x + baseControlPts[2].fX, y + baseControlPts[2].fY}, |
| 183 | {x + baseControlPts[3].fX, y + baseControlPts[3].fY} |
| 184 | }; |
| 185 | SkPoint chopped[10]; |
csmartdalton | cc26127 | 2017-03-23 13:38:45 -0600 | [diff] [blame] | 186 | SkMatrix klm; |
Greg Daniel | 8199d94 | 2017-03-14 10:20:24 -0400 | [diff] [blame] | 187 | int loopIndex; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 188 | int cnt = GrPathUtils::chopCubicAtLoopIntersection(controlPts, |
| 189 | chopped, |
csmartdalton | cc26127 | 2017-03-23 13:38:45 -0600 | [diff] [blame] | 190 | &klm, |
Greg Daniel | 8199d94 | 2017-03-14 10:20:24 -0400 | [diff] [blame] | 191 | &loopIndex); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 192 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 193 | SkPaint ctrlPtPaint; |
| 194 | ctrlPtPaint.setColor(rand.nextU() | 0xFF000000); |
Hal Canary | 23e474c | 2017-05-15 13:35:35 -0400 | [diff] [blame] | 195 | canvas->drawCircle(controlPts[0], 8.f, ctrlPtPaint); |
Greg Daniel | 8199d94 | 2017-03-14 10:20:24 -0400 | [diff] [blame] | 196 | for (int i = 1; i < 4; ++i) { |
Hal Canary | 23e474c | 2017-05-15 13:35:35 -0400 | [diff] [blame] | 197 | canvas->drawCircle(controlPts[i], 6.f, ctrlPtPaint); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 198 | } |
| 199 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 200 | SkPaint polyPaint; |
| 201 | polyPaint.setColor(0xffA0A0A0); |
| 202 | polyPaint.setStrokeWidth(0); |
| 203 | polyPaint.setStyle(SkPaint::kStroke_Style); |
| 204 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 4, controlPts, polyPaint); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 205 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 206 | SkPaint choppedPtPaint; |
| 207 | choppedPtPaint.setColor(~ctrlPtPaint.getColor() | 0xFF000000); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 208 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 209 | for (int c = 0; c < cnt; ++c) { |
| 210 | SkPoint* pts = chopped + 3 * c; |
| 211 | |
| 212 | for (int i = 0; i < 4; ++i) { |
Hal Canary | 23e474c | 2017-05-15 13:35:35 -0400 | [diff] [blame] | 213 | canvas->drawCircle(pts[i], 3.f, choppedPtPaint); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | SkRect bounds; |
| 217 | bounds.set(pts, 4); |
| 218 | |
| 219 | SkPaint boundsPaint; |
| 220 | boundsPaint.setColor(0xff808080); |
| 221 | boundsPaint.setStrokeWidth(0); |
| 222 | boundsPaint.setStyle(SkPaint::kStroke_Style); |
| 223 | canvas->drawRect(bounds, boundsPaint); |
| 224 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 225 | |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 226 | bool flipKL = (c == loopIndex && cnt != 3); |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 227 | sk_sp<GrGeometryProcessor> gp = |
| 228 | GrCubicEffect::Make(color, SkMatrix::I(), klm, flipKL, edgeType, |
| 229 | *context->contextPriv().caps()); |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 230 | if (!gp) { |
| 231 | break; |
Greg Daniel | 8199d94 | 2017-03-14 10:20:24 -0400 | [diff] [blame] | 232 | } |
| 233 | |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 234 | std::unique_ptr<GrDrawOp> op = |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 235 | BezierCubicTestOp::Make(std::move(gp), bounds, color); |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 236 | renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 237 | } |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 238 | ++col; |
| 239 | if (numCols == col) { |
| 240 | col = 0; |
| 241 | ++row; |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 242 | } |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | private: |
| 248 | typedef GM INHERITED; |
| 249 | }; |
| 250 | |
| 251 | ////////////////////////////////////////////////////////////////////////////// |
| 252 | |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 253 | class BezierConicTestOp : public BezierTestOp { |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 254 | public: |
| 255 | DEFINE_OP_CLASS_ID |
| 256 | |
| 257 | const char* name() const override { return "BezierConicTestOp"; } |
| 258 | |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 259 | static std::unique_ptr<GrDrawOp> Make(sk_sp<GrGeometryProcessor> gp, const SkRect& rect, |
| 260 | GrColor color, const SkMatrix& klm) { |
| 261 | return std::unique_ptr<GrMeshDrawOp>( |
| 262 | new BezierConicTestOp(std::move(gp), rect, color, klm)); |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | private: |
| 266 | BezierConicTestOp(sk_sp<GrGeometryProcessor> gp, const SkRect& rect, GrColor color, |
| 267 | const SkMatrix& klm) |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 268 | : INHERITED(std::move(gp), rect, color, ClassID()), fKLM(klm) {} |
| 269 | |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 270 | struct Vertex { |
| 271 | SkPoint fPosition; |
| 272 | float fKLM[4]; // The last value is ignored. The effect expects a vec4f. |
| 273 | }; |
| 274 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 275 | void onPrepareDraws(Target* target) override { |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 276 | QuadHelper helper; |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 277 | size_t vertexStride = this->gp()->getVertexStride(); |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 278 | SkASSERT(vertexStride == sizeof(Vertex)); |
| 279 | Vertex* verts = reinterpret_cast<Vertex*>(helper.init(target, vertexStride, 1)); |
| 280 | if (!verts) { |
| 281 | return; |
| 282 | } |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 283 | SkRect rect = this->rect(); |
Cary Clark | 74f623d | 2017-11-06 20:02:02 -0500 | [diff] [blame] | 284 | SkPointPriv::SetRectTriStrip(&verts[0].fPosition, rect.fLeft, rect.fTop, rect.fRight, |
| 285 | rect.fBottom, sizeof(Vertex)); |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 286 | for (int v = 0; v < 4; ++v) { |
Cary Clark | e4442cb | 2017-10-18 11:46:18 -0400 | [diff] [blame] | 287 | SkPoint3 pt3 = {verts[v].fPosition.x(), verts[v].fPosition.y(), 1.f}; |
| 288 | fKLM.mapHomogeneousPoints((SkPoint3* ) verts[v].fKLM, &pt3, 1); |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 289 | } |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 290 | helper.recordDraw(target, this->gp(), this->makePipeline(target)); |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | SkMatrix fKLM; |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 294 | |
| 295 | static constexpr int kVertsPerCubic = 4; |
| 296 | static constexpr int kIndicesPerCubic = 6; |
| 297 | |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 298 | typedef BezierTestOp INHERITED; |
Chris Dalton | febbffa | 2017-06-08 13:12:02 -0600 | [diff] [blame] | 299 | }; |
| 300 | |
| 301 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 302 | /** |
| 303 | * This GM directly exercises effects that draw Bezier curves in the GPU backend. |
| 304 | */ |
| 305 | class BezierConicEffects : public GM { |
| 306 | public: |
| 307 | BezierConicEffects() { |
| 308 | this->setBGColor(0xFFFFFFFF); |
| 309 | } |
| 310 | |
| 311 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 312 | SkString onShortName() override { |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 313 | return SkString("bezier_conic_effects"); |
| 314 | } |
| 315 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 316 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 317 | return SkISize::Make(800, 800); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 318 | } |
| 319 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 320 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 321 | void onDraw(SkCanvas* canvas) override { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 322 | GrRenderTargetContext* renderTargetContext = |
| 323 | canvas->internal_private_accessTopLayerRenderTargetContext(); |
| 324 | if (!renderTargetContext) { |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 325 | skiagm::GM::DrawGpuOnlyMessage(canvas); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 326 | return; |
| 327 | } |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 328 | |
robertphillips | 175dd9b | 2016-04-28 14:32:04 -0700 | [diff] [blame] | 329 | GrContext* context = canvas->getGrContext(); |
| 330 | if (!context) { |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 331 | return; |
| 332 | } |
| 333 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 334 | struct Vertex { |
| 335 | SkPoint fPosition; |
| 336 | float fKLM[4]; // The last value is ignored. The effect expects a vec4f. |
| 337 | }; |
| 338 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 339 | constexpr int kNumConics = 10; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 340 | SkRandom rand; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 341 | |
| 342 | // Mult by 3 for each edge effect type |
| 343 | int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumConics*3))); |
| 344 | int numRows = SkScalarCeilToInt(SkIntToScalar(kNumConics*3) / numCols); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 345 | SkScalar w = SkIntToScalar(renderTargetContext->width()) / numCols; |
| 346 | SkScalar h = SkIntToScalar(renderTargetContext->height()) / numRows; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 347 | int row = 0; |
| 348 | int col = 0; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 349 | constexpr GrColor color = 0xff000000; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 350 | |
| 351 | for (int i = 0; i < kNumConics; ++i) { |
| 352 | SkPoint baseControlPts[] = { |
| 353 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
| 354 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
| 355 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} |
| 356 | }; |
| 357 | SkScalar weight = rand.nextRangeF(0.f, 2.f); |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 358 | for(int edgeType = 0; edgeType < kGrClipEdgeTypeCnt; ++edgeType) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 359 | sk_sp<GrGeometryProcessor> gp; |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 360 | GrClipEdgeType et = (GrClipEdgeType)edgeType; |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 361 | gp = GrConicEffect::Make(color, SkMatrix::I(), et, *context->contextPriv().caps(), |
| 362 | SkMatrix::I(), false); |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 363 | if (!gp) { |
| 364 | continue; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Mike Reed | df85c38 | 2017-02-14 10:59:19 -0500 | [diff] [blame] | 367 | SkScalar x = col * w; |
| 368 | SkScalar y = row * h; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 369 | SkPoint controlPts[] = { |
| 370 | {x + baseControlPts[0].fX, y + baseControlPts[0].fY}, |
| 371 | {x + baseControlPts[1].fX, y + baseControlPts[1].fY}, |
| 372 | {x + baseControlPts[2].fX, y + baseControlPts[2].fY} |
| 373 | }; |
| 374 | SkConic dst[4]; |
csmartdalton | cc26127 | 2017-03-23 13:38:45 -0600 | [diff] [blame] | 375 | SkMatrix klm; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 376 | int cnt = chop_conic(controlPts, dst, weight); |
csmartdalton | cc26127 | 2017-03-23 13:38:45 -0600 | [diff] [blame] | 377 | GrPathUtils::getConicKLM(controlPts, weight, &klm); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 378 | |
| 379 | SkPaint ctrlPtPaint; |
| 380 | ctrlPtPaint.setColor(rand.nextU() | 0xFF000000); |
| 381 | for (int i = 0; i < 3; ++i) { |
Hal Canary | 23e474c | 2017-05-15 13:35:35 -0400 | [diff] [blame] | 382 | canvas->drawCircle(controlPts[i], 6.f, ctrlPtPaint); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | SkPaint polyPaint; |
| 386 | polyPaint.setColor(0xffA0A0A0); |
| 387 | polyPaint.setStrokeWidth(0); |
| 388 | polyPaint.setStyle(SkPaint::kStroke_Style); |
| 389 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, controlPts, polyPaint); |
| 390 | |
| 391 | SkPaint choppedPtPaint; |
| 392 | choppedPtPaint.setColor(~ctrlPtPaint.getColor() | 0xFF000000); |
| 393 | |
| 394 | for (int c = 0; c < cnt; ++c) { |
| 395 | SkPoint* pts = dst[c].fPts; |
| 396 | for (int i = 0; i < 3; ++i) { |
Hal Canary | 23e474c | 2017-05-15 13:35:35 -0400 | [diff] [blame] | 397 | canvas->drawCircle(pts[i], 3.f, choppedPtPaint); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | SkRect bounds; |
| 401 | //SkPoint bPts[] = {{0.f, 0.f}, {800.f, 800.f}}; |
| 402 | //bounds.set(bPts, 2); |
| 403 | bounds.set(pts, 3); |
| 404 | |
| 405 | SkPaint boundsPaint; |
| 406 | boundsPaint.setColor(0xff808080); |
| 407 | boundsPaint.setStrokeWidth(0); |
| 408 | boundsPaint.setStyle(SkPaint::kStroke_Style); |
| 409 | canvas->drawRect(bounds, boundsPaint); |
| 410 | |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 411 | std::unique_ptr<GrDrawOp> op = BezierConicTestOp::Make(gp, bounds, color, klm); |
| 412 | renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 413 | } |
| 414 | ++col; |
| 415 | if (numCols == col) { |
| 416 | col = 0; |
| 417 | ++row; |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | private: |
| 424 | // Uses the max curvature function for quads to estimate |
| 425 | // where to chop the conic. If the max curvature is not |
| 426 | // found along the curve segment it will return 1 and |
| 427 | // dst[0] is the original conic. If it returns 2 the dst[0] |
| 428 | // and dst[1] are the two new conics. |
| 429 | int split_conic(const SkPoint src[3], SkConic dst[2], const SkScalar weight) { |
| 430 | SkScalar t = SkFindQuadMaxCurvature(src); |
| 431 | if (t == 0) { |
| 432 | if (dst) { |
| 433 | dst[0].set(src, weight); |
| 434 | } |
| 435 | return 1; |
| 436 | } else { |
| 437 | if (dst) { |
| 438 | SkConic conic; |
| 439 | conic.set(src, weight); |
caryclark | 414c429 | 2016-09-26 11:03:54 -0700 | [diff] [blame] | 440 | if (!conic.chopAt(t, dst)) { |
| 441 | dst[0].set(src, weight); |
| 442 | return 1; |
| 443 | } |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 444 | } |
| 445 | return 2; |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | // Calls split_conic on the entire conic and then once more on each subsection. |
| 450 | // Most cases will result in either 1 conic (chop point is not within t range) |
| 451 | // or 3 points (split once and then one subsection is split again). |
| 452 | int chop_conic(const SkPoint src[3], SkConic dst[4], const SkScalar weight) { |
| 453 | SkConic dstTemp[2]; |
| 454 | int conicCnt = split_conic(src, dstTemp, weight); |
| 455 | if (2 == conicCnt) { |
| 456 | int conicCnt2 = split_conic(dstTemp[0].fPts, dst, dstTemp[0].fW); |
| 457 | conicCnt = conicCnt2 + split_conic(dstTemp[1].fPts, &dst[conicCnt2], dstTemp[1].fW); |
| 458 | } else { |
| 459 | dst[0] = dstTemp[0]; |
| 460 | } |
| 461 | return conicCnt; |
| 462 | } |
| 463 | |
| 464 | typedef GM INHERITED; |
| 465 | }; |
| 466 | |
| 467 | ////////////////////////////////////////////////////////////////////////////// |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 468 | |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 469 | class BezierQuadTestOp : public BezierTestOp { |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 470 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 471 | DEFINE_OP_CLASS_ID |
Brian Salomon | 6b316e9 | 2016-12-16 09:35:49 -0500 | [diff] [blame] | 472 | const char* name() const override { return "BezierQuadTestOp"; } |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 473 | |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 474 | static std::unique_ptr<GrDrawOp> Make(sk_sp<GrGeometryProcessor> gp, const SkRect& rect, |
| 475 | GrColor color, const GrPathUtils::QuadUVMatrix& devToUV) { |
| 476 | return std::unique_ptr<GrDrawOp>(new BezierQuadTestOp(std::move(gp), rect, color, devToUV)); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | private: |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 480 | BezierQuadTestOp(sk_sp<GrGeometryProcessor> gp, const SkRect& rect, GrColor color, |
Brian Salomon | 6b316e9 | 2016-12-16 09:35:49 -0500 | [diff] [blame] | 481 | const GrPathUtils::QuadUVMatrix& devToUV) |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 482 | : INHERITED(std::move(gp), rect, color, ClassID()), fDevToUV(devToUV) {} |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 483 | |
| 484 | struct Vertex { |
| 485 | SkPoint fPosition; |
| 486 | float fKLM[4]; // The last value is ignored. The effect expects a vec4f. |
| 487 | }; |
| 488 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 489 | void onPrepareDraws(Target* target) override { |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 490 | QuadHelper helper; |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 491 | size_t vertexStride = this->gp()->getVertexStride(); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 492 | SkASSERT(vertexStride == sizeof(Vertex)); |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 493 | Vertex* verts = reinterpret_cast<Vertex*>(helper.init(target, vertexStride, 1)); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 494 | if (!verts) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 495 | return; |
| 496 | } |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 497 | SkRect rect = this->rect(); |
Brian Salomon | ec42e15 | 2018-05-18 12:52:22 -0400 | [diff] [blame] | 498 | SkPointPriv::SetRectTriStrip(&verts[0].fPosition, rect, sizeof(Vertex)); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 499 | fDevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts); |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 500 | helper.recordDraw(target, this->gp(), this->makePipeline(target)); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 501 | } |
| 502 | |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 503 | GrPathUtils::QuadUVMatrix fDevToUV; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 504 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 505 | static constexpr int kVertsPerCubic = 4; |
| 506 | static constexpr int kIndicesPerCubic = 6; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 507 | |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 508 | typedef BezierTestOp INHERITED; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 509 | }; |
| 510 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 511 | /** |
| 512 | * This GM directly exercises effects that draw Bezier quad curves in the GPU backend. |
| 513 | */ |
| 514 | class BezierQuadEffects : public GM { |
| 515 | public: |
| 516 | BezierQuadEffects() { |
| 517 | this->setBGColor(0xFFFFFFFF); |
| 518 | } |
| 519 | |
| 520 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 521 | SkString onShortName() override { |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 522 | return SkString("bezier_quad_effects"); |
| 523 | } |
| 524 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 525 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 526 | return SkISize::Make(800, 800); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 527 | } |
| 528 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 529 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 530 | void onDraw(SkCanvas* canvas) override { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 531 | GrRenderTargetContext* renderTargetContext = |
| 532 | canvas->internal_private_accessTopLayerRenderTargetContext(); |
| 533 | if (!renderTargetContext) { |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 534 | skiagm::GM::DrawGpuOnlyMessage(canvas); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 535 | return; |
| 536 | } |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 537 | |
robertphillips | 175dd9b | 2016-04-28 14:32:04 -0700 | [diff] [blame] | 538 | GrContext* context = canvas->getGrContext(); |
| 539 | if (!context) { |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 540 | return; |
| 541 | } |
| 542 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 543 | struct Vertex { |
| 544 | SkPoint fPosition; |
| 545 | float fUV[4]; // The last two values are ignored. The effect expects a vec4f. |
| 546 | }; |
| 547 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 548 | constexpr int kNumQuads = 5; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 549 | SkRandom rand; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 550 | |
| 551 | int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumQuads*3))); |
| 552 | int numRows = SkScalarCeilToInt(SkIntToScalar(kNumQuads*3) / numCols); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 553 | SkScalar w = SkIntToScalar(renderTargetContext->width()) / numCols; |
| 554 | SkScalar h = SkIntToScalar(renderTargetContext->height()) / numRows; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 555 | int row = 0; |
| 556 | int col = 0; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 557 | constexpr GrColor color = 0xff000000; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 558 | |
| 559 | for (int i = 0; i < kNumQuads; ++i) { |
| 560 | SkPoint baseControlPts[] = { |
| 561 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
| 562 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
| 563 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} |
| 564 | }; |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 565 | for(int edgeType = 0; edgeType < kGrClipEdgeTypeCnt; ++edgeType) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 566 | sk_sp<GrGeometryProcessor> gp; |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 567 | GrClipEdgeType et = (GrClipEdgeType)edgeType; |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 568 | gp = GrQuadEffect::Make(color, SkMatrix::I(), et, *context->contextPriv().caps(), |
| 569 | SkMatrix::I(), false); |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 570 | if (!gp) { |
| 571 | continue; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Mike Reed | df85c38 | 2017-02-14 10:59:19 -0500 | [diff] [blame] | 574 | SkScalar x = col * w; |
| 575 | SkScalar y = row * h; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 576 | SkPoint controlPts[] = { |
| 577 | {x + baseControlPts[0].fX, y + baseControlPts[0].fY}, |
| 578 | {x + baseControlPts[1].fX, y + baseControlPts[1].fY}, |
| 579 | {x + baseControlPts[2].fX, y + baseControlPts[2].fY} |
| 580 | }; |
| 581 | SkPoint chopped[5]; |
| 582 | int cnt = SkChopQuadAtMaxCurvature(controlPts, chopped); |
| 583 | |
| 584 | SkPaint ctrlPtPaint; |
| 585 | ctrlPtPaint.setColor(rand.nextU() | 0xFF000000); |
| 586 | for (int i = 0; i < 3; ++i) { |
Hal Canary | 23e474c | 2017-05-15 13:35:35 -0400 | [diff] [blame] | 587 | canvas->drawCircle(controlPts[i], 6.f, ctrlPtPaint); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | SkPaint polyPaint; |
| 591 | polyPaint.setColor(0xffA0A0A0); |
| 592 | polyPaint.setStrokeWidth(0); |
| 593 | polyPaint.setStyle(SkPaint::kStroke_Style); |
| 594 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, controlPts, polyPaint); |
| 595 | |
| 596 | SkPaint choppedPtPaint; |
| 597 | choppedPtPaint.setColor(~ctrlPtPaint.getColor() | 0xFF000000); |
| 598 | |
| 599 | for (int c = 0; c < cnt; ++c) { |
| 600 | SkPoint* pts = chopped + 2 * c; |
| 601 | |
| 602 | for (int i = 0; i < 3; ++i) { |
Hal Canary | 23e474c | 2017-05-15 13:35:35 -0400 | [diff] [blame] | 603 | canvas->drawCircle(pts[i], 3.f, choppedPtPaint); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | SkRect bounds; |
| 607 | bounds.set(pts, 3); |
| 608 | |
| 609 | SkPaint boundsPaint; |
| 610 | boundsPaint.setColor(0xff808080); |
| 611 | boundsPaint.setStrokeWidth(0); |
| 612 | boundsPaint.setStyle(SkPaint::kStroke_Style); |
| 613 | canvas->drawRect(bounds, boundsPaint); |
| 614 | |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 615 | GrPaint grPaint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 616 | grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); |
joshualitt | 3f284d7 | 2015-02-11 11:34:58 -0800 | [diff] [blame] | 617 | |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 618 | GrPathUtils::QuadUVMatrix DevToUV(pts); |
| 619 | |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 620 | std::unique_ptr<GrDrawOp> op = |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 621 | BezierQuadTestOp::Make(gp, bounds, color, DevToUV); |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 622 | renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 623 | } |
| 624 | ++col; |
| 625 | if (numCols == col) { |
| 626 | col = 0; |
| 627 | ++row; |
| 628 | } |
| 629 | } |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | private: |
| 634 | typedef GM INHERITED; |
| 635 | }; |
| 636 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 637 | DEF_GM(return new BezierCubicEffects;) |
| 638 | DEF_GM(return new BezierConicEffects;) |
| 639 | DEF_GM(return new BezierQuadEffects;) |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | #endif |