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