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