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