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