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