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