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